luci-app-passwall: sync upstream

last commit: 0eb890e9e6
This commit is contained in:
actions 2024-07-20 05:00:06 +08:00
parent 65456ed083
commit aaaf475528

View File

@ -38,9 +38,10 @@ 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")
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:find("#") and host:find("#") == 1 then if host:sub(1, 1) == "#" then
return value return value
end end
if not datatypes.hostname(host) then if not datatypes.hostname(host) then
@ -66,9 +67,10 @@ 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")
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("#") and ipmask:find("#") == 1 then if ipmask:sub(1, 1) == "#" then
return value return value
end end
if not ( datatypes.ipmask4(ipmask) or datatypes.ipmask6(ipmask) ) then if not ( datatypes.ipmask4(ipmask) or datatypes.ipmask6(ipmask) ) then
@ -96,9 +98,10 @@ 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")
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:find("#") and host:find("#") == 1 then if host:sub(1, 1) == "#" then
return value return value
end end
if not datatypes.hostname(host) then if not datatypes.hostname(host) then
@ -124,9 +127,10 @@ 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")
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("#") and ipmask:find("#") == 1 then if ipmask:sub(1, 1) == "#" then
return value return value
end end
if not ( datatypes.ipmask4(ipmask) or datatypes.ipmask6(ipmask) ) then if not ( datatypes.ipmask4(ipmask) or datatypes.ipmask6(ipmask) ) then
@ -152,9 +156,10 @@ 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")
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:find("#") and host:find("#") == 1 then if host:sub(1, 1) == "#" then
return value return value
end end
if not datatypes.hostname(host) then if not datatypes.hostname(host) then
@ -180,9 +185,10 @@ 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")
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("#") and ipmask:find("#") == 1 then if ipmask:sub(1, 1) == "#" then
return value return value
end end
if not ( datatypes.ipmask4(ipmask) or datatypes.ipmask6(ipmask) ) then if not ( datatypes.ipmask4(ipmask) or datatypes.ipmask6(ipmask) ) then
@ -208,9 +214,10 @@ 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")
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("#") and ipmask:find("#") == 1 then if ipmask:sub(1, 1) == "#" then
return value return value
end end
if not datatypes.ipmask4(ipmask) then if not datatypes.ipmask4(ipmask) then
@ -236,9 +243,10 @@ 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")
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("#") and ipmask:find("#") == 1 then if ipmask:sub(1, 1) == "#" then
return value return value
end end
if not datatypes.ipmask6(ipmask) then if not datatypes.ipmask6(ipmask) then
@ -257,7 +265,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("\r\n", "\n")) fs.writefile(hosts, value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n"))
end end
o.remove = function(self, section, value) o.remove = function(self, section, value)
fs.writefile(hosts, "") fs.writefile(hosts, "")