parent
da16645e19
commit
4601aba001
@ -12,6 +12,18 @@ local chnroute_path = "/usr/share/passwall/rules/chnroute"
|
|||||||
m = Map(appname)
|
m = Map(appname)
|
||||||
api.set_apply_on_parse(m)
|
api.set_apply_on_parse(m)
|
||||||
|
|
||||||
|
function clean_text(text)
|
||||||
|
local nbsp = string.char(0xC2, 0xA0) -- 不间断空格(U+00A0)
|
||||||
|
local fullwidth_space = string.char(0xE3, 0x80, 0x80) -- 全角空格(U+3000)
|
||||||
|
return text
|
||||||
|
:gsub(nbsp, " ")
|
||||||
|
:gsub(fullwidth_space, " ")
|
||||||
|
:gsub("^%s+", "")
|
||||||
|
:gsub("%s+$", "\n")
|
||||||
|
:gsub("\r\n", "\n")
|
||||||
|
:gsub("[ \t]*\n[ \t]*", "\n")
|
||||||
|
end
|
||||||
|
|
||||||
-- [[ Rule List Settings ]]--
|
-- [[ Rule List Settings ]]--
|
||||||
s = m:section(TypedSection, "global_rules")
|
s = m:section(TypedSection, "global_rules")
|
||||||
s.anonymous = true
|
s.anonymous = true
|
||||||
@ -40,7 +52,7 @@ o.remove = function(self, section, value)
|
|||||||
end
|
end
|
||||||
o.validate = function(self, value)
|
o.validate = function(self, value)
|
||||||
local hosts= {}
|
local hosts= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
|
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
|
||||||
for index, host in ipairs(hosts) do
|
for index, host in ipairs(hosts) do
|
||||||
if host:sub(1, 1) == "#" or host:sub(1, 8) == "geosite:" then
|
if host:sub(1, 1) == "#" or host:sub(1, 8) == "geosite:" then
|
||||||
@ -69,7 +81,7 @@ o.remove = function(self, section, value)
|
|||||||
end
|
end
|
||||||
o.validate = function(self, value)
|
o.validate = function(self, value)
|
||||||
local ipmasks= {}
|
local ipmasks= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
||||||
for index, ipmask in ipairs(ipmasks) do
|
for index, ipmask in ipairs(ipmasks) do
|
||||||
if ipmask:sub(1, 1) == "#" or ipmask:sub(1, 6) == "geoip:" then
|
if ipmask:sub(1, 1) == "#" or ipmask:sub(1, 6) == "geoip:" then
|
||||||
@ -100,7 +112,7 @@ o.remove = function(self, section, value)
|
|||||||
end
|
end
|
||||||
o.validate = function(self, value)
|
o.validate = function(self, value)
|
||||||
local hosts= {}
|
local hosts= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
|
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
|
||||||
for index, host in ipairs(hosts) do
|
for index, host in ipairs(hosts) do
|
||||||
if host:sub(1, 1) == "#" or host:sub(1, 8) == "geosite:" then
|
if host:sub(1, 1) == "#" or host:sub(1, 8) == "geosite:" then
|
||||||
@ -129,7 +141,7 @@ o.remove = function(self, section, value)
|
|||||||
end
|
end
|
||||||
o.validate = function(self, value)
|
o.validate = function(self, value)
|
||||||
local ipmasks= {}
|
local ipmasks= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
||||||
for index, ipmask in ipairs(ipmasks) do
|
for index, ipmask in ipairs(ipmasks) do
|
||||||
if ipmask:sub(1, 1) == "#" or ipmask:sub(1, 6) == "geoip:" then
|
if ipmask:sub(1, 1) == "#" or ipmask:sub(1, 6) == "geoip:" then
|
||||||
@ -158,7 +170,7 @@ o.remove = function(self, section, value)
|
|||||||
end
|
end
|
||||||
o.validate = function(self, value)
|
o.validate = function(self, value)
|
||||||
local hosts= {}
|
local hosts= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
|
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
|
||||||
for index, host in ipairs(hosts) do
|
for index, host in ipairs(hosts) do
|
||||||
if host:sub(1, 1) == "#" or host:sub(1, 8) == "geosite:" then
|
if host:sub(1, 1) == "#" or host:sub(1, 8) == "geosite:" then
|
||||||
@ -187,7 +199,7 @@ o.remove = function(self, section, value)
|
|||||||
end
|
end
|
||||||
o.validate = function(self, value)
|
o.validate = function(self, value)
|
||||||
local ipmasks= {}
|
local ipmasks= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
||||||
for index, ipmask in ipairs(ipmasks) do
|
for index, ipmask in ipairs(ipmasks) do
|
||||||
if ipmask:sub(1, 1) == "#" or ipmask:sub(1, 6) == "geoip:" then
|
if ipmask:sub(1, 1) == "#" or ipmask:sub(1, 6) == "geoip:" then
|
||||||
@ -216,7 +228,7 @@ o.remove = function(self, section, value)
|
|||||||
end
|
end
|
||||||
o.validate = function(self, value)
|
o.validate = function(self, value)
|
||||||
local ipmasks= {}
|
local ipmasks= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
||||||
for index, ipmask in ipairs(ipmasks) do
|
for index, ipmask in ipairs(ipmasks) do
|
||||||
if ipmask:sub(1, 1) == "#" then
|
if ipmask:sub(1, 1) == "#" then
|
||||||
@ -245,7 +257,7 @@ o.remove = function(self, section, value)
|
|||||||
end
|
end
|
||||||
o.validate = function(self, value)
|
o.validate = function(self, value)
|
||||||
local ipmasks= {}
|
local ipmasks= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
|
||||||
for index, ipmask in ipairs(ipmasks) do
|
for index, ipmask in ipairs(ipmasks) do
|
||||||
if ipmask:sub(1, 1) == "#" then
|
if ipmask:sub(1, 1) == "#" then
|
||||||
@ -267,7 +279,7 @@ o.cfgvalue = function(self, section)
|
|||||||
return fs.readfile(hosts) or ""
|
return fs.readfile(hosts) or ""
|
||||||
end
|
end
|
||||||
o.write = function(self, section, value)
|
o.write = function(self, section, value)
|
||||||
fs.writefile(hosts, value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n"))
|
fs.writefile(hosts, clean_text(value))
|
||||||
end
|
end
|
||||||
o.remove = function(self, section, value)
|
o.remove = function(self, section, value)
|
||||||
fs.writefile(hosts, "")
|
fs.writefile(hosts, "")
|
||||||
|
@ -6,6 +6,18 @@ m = Map(appname, "Sing-Box/Xray " .. translate("Shunt Rule"))
|
|||||||
m.redirect = api.url()
|
m.redirect = api.url()
|
||||||
api.set_apply_on_parse(m)
|
api.set_apply_on_parse(m)
|
||||||
|
|
||||||
|
function clean_text(text)
|
||||||
|
local nbsp = string.char(0xC2, 0xA0) -- 不间断空格(U+00A0)
|
||||||
|
local fullwidth_space = string.char(0xE3, 0x80, 0x80) -- 全角空格(U+3000)
|
||||||
|
return text
|
||||||
|
:gsub(nbsp, " ")
|
||||||
|
:gsub(fullwidth_space, " ")
|
||||||
|
:gsub("^%s+", "")
|
||||||
|
:gsub("%s+$", "\n")
|
||||||
|
:gsub("\r\n", "\n")
|
||||||
|
:gsub("[ \t]*\n[ \t]*", "\n")
|
||||||
|
end
|
||||||
|
|
||||||
s = m:section(NamedSection, arg[1], "shunt_rules", "")
|
s = m:section(NamedSection, arg[1], "shunt_rules", "")
|
||||||
s.addremove = false
|
s.addremove = false
|
||||||
s.dynamic = false
|
s.dynamic = false
|
||||||
@ -107,7 +119,7 @@ domain_list.rows = 10
|
|||||||
domain_list.wrap = "off"
|
domain_list.wrap = "off"
|
||||||
domain_list.validate = function(self, value)
|
domain_list.validate = function(self, value)
|
||||||
local hosts= {}
|
local hosts= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, "[^\r\n]+", function(w) table.insert(hosts, w) end)
|
string.gsub(value, "[^\r\n]+", function(w) table.insert(hosts, w) end)
|
||||||
for index, host in ipairs(hosts) do
|
for index, host in ipairs(hosts) do
|
||||||
local flag = 1
|
local flag = 1
|
||||||
@ -146,7 +158,7 @@ ip_list.rows = 10
|
|||||||
ip_list.wrap = "off"
|
ip_list.wrap = "off"
|
||||||
ip_list.validate = function(self, value)
|
ip_list.validate = function(self, value)
|
||||||
local ipmasks= {}
|
local ipmasks= {}
|
||||||
value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")
|
value = clean_text(value)
|
||||||
string.gsub(value, "[^\r\n]+", function(w) table.insert(ipmasks, w) end)
|
string.gsub(value, "[^\r\n]+", function(w) table.insert(ipmasks, w) end)
|
||||||
for index, ipmask in ipairs(ipmasks) do
|
for index, ipmask in ipairs(ipmasks) do
|
||||||
if ipmask:find("geoip:") and ipmask:find("geoip:") == 1 and not ipmask:find("%s") then
|
if ipmask:find("geoip:") and ipmask:find("geoip:") == 1 and not ipmask:find("%s") then
|
||||||
|
Loading…
Reference in New Issue
Block a user