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.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.write = function(self, section, value) fs.writefile(domains_excluded, value:gsub("\r\n", "\n")) end
o.remove = function(self, section) 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 if not route_only_value or route_only_value == "0" then
fs.writefile(domains_excluded, "") fs.writefile(domains_excluded, "")
end end

View File

@ -34,7 +34,7 @@ o = s:option(Flag, option_name("tls"), translate("TLS"))
o.default = 0 o.default = 0
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value then 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 if value == "0" and type == type_name then
return nil, translate("Original Trojan only supported 'tls', please choose 'tls'.") return nil, translate("Original Trojan only supported 'tls', please choose 'tls'.")
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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