luci: fix some problems

This commit is contained in:
xiaorouji 2023-09-20 15:22:03 +08:00 committed by sbwml
parent 27850f78fe
commit 8786e06757
9 changed files with 37 additions and 22 deletions

View File

@ -161,7 +161,7 @@ if has_xray then
o.cfgvalue = function(self, section) return fs.readfile(domains_excluded) or "" end
o.write = function(self, section, value) fs.writefile(domains_excluded, value:gsub("\r\n", "\n")) end
o.remove = function(self, section)
local route_only_value = s_xray.fields["route_only"]:formvalue(section)
local route_only_value = s_xray.fields["route_only"] and s_xray.fields["route_only"]:formvalue(section) or nil
if not route_only_value or route_only_value == "0" then
fs.writefile(domains_excluded, "")
end

View File

@ -34,7 +34,7 @@ o = s:option(Flag, option_name("tls"), translate("TLS"))
o.default = 0
o.validate = function(self, value, t)
if value then
local type = s.fields["type"]:formvalue(t) or ""
local type = s.fields["type"] and s.fields["type"]:formvalue(t) or ""
if value == "0" and type == type_name then
return nil, translate("Original Trojan only supported 'tls', please choose 'tls'.")
end

View File

@ -41,8 +41,8 @@ o.datatype = "port"
o = s:option(Flag, option_name("auth"), translate("Auth"))
o.validate = function(self, value, t)
if value and value == "1" then
local user_v = s.fields[option_name("username")]:formvalue(t) or ""
local pass_v = s.fields[option_name("password")]:formvalue(t) or ""
local user_v = s.fields[option_name("username")] and s.fields[option_name("username")]:formvalue(t) or ""
local pass_v = s.fields[option_name("password")] and s.fields[option_name("password")]:formvalue(t) or ""
if user_v == "" or pass_v == "" then
return nil, translate("Username and Password must be used together!")
end
@ -115,11 +115,11 @@ o = s:option(Flag, option_name("tls"), translate("TLS"))
o.default = 0
o.validate = function(self, value, t)
if value then
local reality = s.fields[option_name("reality")]:formvalue(t)
local reality = s.fields[option_name("reality")] and s.fields[option_name("reality")]:formvalue(t) or nil
if reality and reality == "1" then return value end
if value == "1" then
local ca = s.fields[option_name("tls_certificateFile")]:formvalue(t) or ""
local key = s.fields[option_name("tls_keyFile")]:formvalue(t) or ""
local ca = s.fields[option_name("tls_certificateFile")] and s.fields[option_name("tls_certificateFile")]:formvalue(t) or ""
local key = s.fields[option_name("tls_keyFile")] and s.fields[option_name("tls_keyFile")]:formvalue(t) or ""
if ca == "" or key == "" then
return nil, translate("Public key and Private key path can not be empty!")
end

View File

@ -53,8 +53,8 @@ o.datatype = "port"
o = s:option(Flag, option_name("auth"), translate("Auth"))
o.validate = function(self, value, t)
if value and value == "1" then
local user_v = s.fields[option_name("username")]:formvalue(t) or ""
local pass_v = s.fields[option_name("password")]:formvalue(t) or ""
local user_v = s.fields[option_name("username")] and s.fields[option_name("username")]:formvalue(t) or ""
local pass_v = s.fields[option_name("password")] and s.fields[option_name("password")]:formvalue(t) or ""
if user_v == "" or pass_v == "" then
return nil, translate("Username and Password must be used together!")
end
@ -202,11 +202,11 @@ o = s:option(Flag, option_name("tls"), translate("TLS"))
o.default = 0
o.validate = function(self, value, t)
if value then
local reality = s.fields[option_name("reality")]:formvalue(t)
local reality = s.fields[option_name("reality")] and s.fields[option_name("reality")]:formvalue(t) or nil
if reality and reality == "1" then return value end
if value == "1" then
local ca = s.fields[option_name("tls_certificateFile")]:formvalue(t) or ""
local key = s.fields[option_name("tls_keyFile")]:formvalue(t) or ""
local ca = s.fields[option_name("tls_certificateFile")] and s.fields[option_name("tls_certificateFile")]:formvalue(t) or ""
local key = s.fields[option_name("tls_keyFile")] and s.fields[option_name("tls_keyFile")]:formvalue(t) or ""
if ca == "" or key == "" then
return nil, translate("Public key and Private key path can not be empty!")
end

View File

@ -24,8 +24,8 @@ o.datatype = "port"
o = s:option(Flag, option_name("auth"), translate("Auth"))
o.validate = function(self, value, t)
if value and value == "1" then
local user_v = s.fields[option_name("username")]:formvalue(t) or ""
local pass_v = s.fields[option_name("password")]:formvalue(t) or ""
local user_v = s.fields[option_name("username")] and s.fields[option_name("username")]:formvalue(t) or ""
local pass_v = s.fields[option_name("password")] and s.fields[option_name("password")]:formvalue(t) or ""
if user_v == "" or pass_v == "" then
return nil, translate("Username and Password must be used together!")
end

View File

@ -36,13 +36,13 @@ o = s:option(Flag, option_name("tls"), translate("TLS"))
o.default = 0
o.validate = function(self, value, t)
if value then
local type = s.fields["type"]:formvalue(t) or ""
local type = s.fields["type"] and s.fields["type"]:formvalue(t) or ""
if value == "0" and type == type_name then
return nil, translate("Original Trojan only supported 'tls', please choose 'tls'.")
end
if value == "1" then
local ca = s.fields[option_name("tls_certificateFile")]:formvalue(t) or ""
local key = s.fields[option_name("tls_keyFile")]:formvalue(t) or ""
local ca = s.fields[option_name("tls_certificateFile")] and s.fields[option_name("tls_certificateFile")]:formvalue(t) or ""
local key = s.fields[option_name("tls_keyFile")] and s.fields[option_name("tls_keyFile")]:formvalue(t) or ""
if ca == "" or key == "" then
return nil, translate("Public key and Private key path can not be empty!")
end

View File

@ -30,13 +30,13 @@ o = s:option(Flag, option_name("tls"), translate("TLS"))
o.default = 0
o.validate = function(self, value, t)
if value then
local type = s.fields["type"]:formvalue(t) or ""
local type = s.fields["type"] and s.fields["type"]:formvalue(t) or ""
if value == "0" and type == type_name then
return nil, translate("Original Trojan only supported 'tls', please choose 'tls'.")
end
if value == "1" then
local ca = s.fields[option_name("tls_certificateFile")]:formvalue(t) or ""
local key = s.fields[option_name("tls_keyFile")]:formvalue(t) or ""
local ca = s.fields[option_name("tls_certificateFile")] and s.fields[option_name("tls_certificateFile")]:formvalue(t) or ""
local key = s.fields[option_name("tls_keyFile")] and s.fields[option_name("tls_keyFile")]:formvalue(t) or ""
if ca == "" or key == "" then
return nil, translate("Public key and Private key path can not be empty!")
end

View File

@ -974,9 +974,18 @@ function to_check_self()
end
function luci_types(id, m, s, type_name, option_prefix)
local rewrite_option_table = {}
for key, value in pairs(s.fields) do
if key:find(option_prefix) == 1 then
if not s.fields[key].not_rewrite then
if s.fields[key].rewrite_option then
if not rewrite_option_table[s.fields[key].rewrite_option] then
rewrite_option_table[s.fields[key].rewrite_option] = 1
else
rewrite_option_table[s.fields[key].rewrite_option] = rewrite_option_table[s.fields[key].rewrite_option] + 1
end
end
s.fields[key].cfgvalue = function(self, section)
if self.rewrite_option then
return m:get(section, self.rewrite_option)
@ -999,7 +1008,7 @@ function luci_types(id, m, s, type_name, option_prefix)
end
s.fields[key].remove = function(self, section)
if s.fields["type"]:formvalue(id) == type_name then
if self.rewrite_option then
if self.rewrite_option and rewrite_option_table[self.rewrite_option] == 1 then
m:del(section, self.rewrite_option)
else
if self.option:find(option_prefix) == 1 then

View File

@ -22,6 +22,9 @@ msgstr "点我检测"
msgid "Kernel Unsupported"
msgstr "内核不支持"
msgid "Settings"
msgstr "设置"
msgid "Main Settings"
msgstr "节点选择"
@ -172,6 +175,9 @@ msgstr "过滤代理域名 IPv6"
msgid "Experimental feature."
msgstr "实验性功能。"
msgid "Use FakeDNS work in the shunt domain that proxy."
msgstr "需要代理的分流规则域名使用 FakeDNS。"
msgid "Clear IPSET"
msgstr "清空 IPSET"