luci-app-passwall: sync upstream

last commit: e069ab20cd
This commit is contained in:
gitea-action 2024-12-26 18:00:17 +08:00
parent 4c0f50e76c
commit 4c7683b799
32 changed files with 176 additions and 184 deletions

View File

@ -34,7 +34,7 @@ PKG_CONFIG_DEPENDS:= \
LUCI_TITLE:=LuCI support for PassWall LUCI_TITLE:=LuCI support for PassWall
LUCI_PKGARCH:=all LUCI_PKGARCH:=all
LUCI_DEPENDS:=+coreutils +coreutils-base64 +coreutils-nohup +curl \ LUCI_DEPENDS:=+coreutils +coreutils-base64 +coreutils-nohup +curl \
+chinadns-ng +dns2socks +dns2tcp +dnsmasq-full +ip-full \ +chinadns-ng +dns2socks +dnsmasq-full +ip-full \
+libuci-lua +lua +luci-compat +luci-lib-jsonc \ +libuci-lua +lua +luci-compat +luci-lib-jsonc \
+microsocks +resolveip +tcping +microsocks +resolveip +tcping

View File

@ -5,10 +5,10 @@ module("luci.controller.passwall", package.seeall)
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local appname = "passwall" -- not available local appname = "passwall" -- not available
local uci = api.libuci -- in funtion index() local uci = api.libuci -- in funtion index()
local fs = api.fs
local http = require "luci.http" local http = require "luci.http"
local util = require "luci.util" local util = require "luci.util"
local i18n = require "luci.i18n" local i18n = require "luci.i18n"
local fs = require "nixio.fs"
function index() function index()
if not nixio.fs.access("/etc/config/passwall") then if not nixio.fs.access("/etc/config/passwall") then
@ -19,6 +19,7 @@ function index()
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local appname = "passwall" -- global definitions not available local appname = "passwall" -- global definitions not available
local uci = api.libuci -- in function index() local uci = api.libuci -- in function index()
local fs = api.fs
entry({"admin", "services", appname}).dependent = true entry({"admin", "services", appname}).dependent = true
entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = true entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = true
entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true
@ -36,7 +37,7 @@ function index()
entry({"admin", "services", appname, "node_list"}, cbi(appname .. "/client/node_list"), _("Node List"), 2).dependent = true entry({"admin", "services", appname, "node_list"}, cbi(appname .. "/client/node_list"), _("Node List"), 2).dependent = true
entry({"admin", "services", appname, "node_subscribe"}, cbi(appname .. "/client/node_subscribe"), _("Node Subscribe"), 3).dependent = true entry({"admin", "services", appname, "node_subscribe"}, cbi(appname .. "/client/node_subscribe"), _("Node Subscribe"), 3).dependent = true
entry({"admin", "services", appname, "other"}, cbi(appname .. "/client/other", {autoapply = true}), _("Other Settings"), 92).leaf = true entry({"admin", "services", appname, "other"}, cbi(appname .. "/client/other", {autoapply = true}), _("Other Settings"), 92).leaf = true
if nixio.fs.access("/usr/sbin/haproxy") then if fs.access("/usr/sbin/haproxy") then
entry({"admin", "services", appname, "haproxy"}, cbi(appname .. "/client/haproxy"), _("Load Balancing"), 93).leaf = true entry({"admin", "services", appname, "haproxy"}, cbi(appname .. "/client/haproxy"), _("Load Balancing"), 93).leaf = true
end end
entry({"admin", "services", appname, "app_update"}, cbi(appname .. "/client/app_update"), _("App Update"), 95).leaf = true entry({"admin", "services", appname, "app_update"}, cbi(appname .. "/client/app_update"), _("App Update"), 95).leaf = true
@ -186,10 +187,10 @@ function get_redir_log()
local proto = luci.http.formvalue("proto") local proto = luci.http.formvalue("proto")
local path = "/tmp/etc/passwall/acl/" .. name local path = "/tmp/etc/passwall/acl/" .. name
proto = proto:upper() proto = proto:upper()
if proto == "UDP" and (uci:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" and not nixio.fs.access(path .. "/" .. proto .. ".log") then if proto == "UDP" and (uci:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" and not fs.access(path .. "/" .. proto .. ".log") then
proto = "TCP" proto = "TCP"
end end
if nixio.fs.access(path .. "/" .. proto .. ".log") then if fs.access(path .. "/" .. proto .. ".log") then
local content = luci.sys.exec("cat ".. path .. "/" .. proto .. ".log") local content = luci.sys.exec("cat ".. path .. "/" .. proto .. ".log")
content = content:gsub("\n", "<br />") content = content:gsub("\n", "<br />")
luci.http.write(content) luci.http.write(content)
@ -201,7 +202,7 @@ end
function get_socks_log() function get_socks_log()
local name = luci.http.formvalue("name") local name = luci.http.formvalue("name")
local path = "/tmp/etc/passwall/SOCKS_" .. name .. ".log" local path = "/tmp/etc/passwall/SOCKS_" .. name .. ".log"
if nixio.fs.access(path) then if fs.access(path) then
local content = luci.sys.exec("cat ".. path) local content = luci.sys.exec("cat ".. path)
content = content:gsub("\n", "<br />") content = content:gsub("\n", "<br />")
luci.http.write(content) luci.http.write(content)
@ -453,7 +454,7 @@ end
function server_user_log() function server_user_log()
local id = luci.http.formvalue("id") local id = luci.http.formvalue("id")
if nixio.fs.access("/tmp/etc/passwall_server/" .. id .. ".log") then if fs.access("/tmp/etc/passwall_server/" .. id .. ".log") then
local content = luci.sys.exec("cat /tmp/etc/passwall_server/" .. id .. ".log") local content = luci.sys.exec("cat /tmp/etc/passwall_server/" .. id .. ".log")
content = content:gsub("\n", "<br />") content = content:gsub("\n", "<br />")
luci.http.write(content) luci.http.write(content)

View File

@ -1,6 +1,6 @@
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local appname = "passwall" local appname = "passwall"
local uci = api.uci local uci = api.libuci
local sys = api.sys local sys = api.sys
local has_singbox = api.finded_com("singbox") local has_singbox = api.finded_com("singbox")
local has_xray = api.finded_com("xray") local has_xray = api.finded_com("xray")

View File

@ -1,6 +1,6 @@
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local appname = "passwall" local appname = "passwall"
local uci = api.uci local uci = api.libuci
local datatypes = api.datatypes local datatypes = api.datatypes
local has_singbox = api.finded_com("singbox") local has_singbox = api.finded_com("singbox")
local has_xray = api.finded_com("xray") local has_xray = api.finded_com("xray")

View File

@ -1,7 +1,7 @@
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local appname = "passwall" local appname = "passwall"
local uci = api.uci local uci = api.libuci
local fs = require "nixio.fs" local fs = api.fs
local types_dir = "/usr/lib/lua/luci/model/cbi/passwall/client/type/" local types_dir = "/usr/lib/lua/luci/model/cbi/passwall/client/type/"
if not arg[1] or not uci:get(appname, arg[1]) then if not arg[1] or not uci:get(appname, arg[1]) then

View File

@ -1,6 +1,6 @@
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local appname = "passwall" local appname = "passwall"
local uci = api.uci local uci = api.libuci
local has_singbox = api.finded_com("singbox") local has_singbox = api.finded_com("singbox")
local has_xray = api.finded_com("xray") local has_xray = api.finded_com("xray")

View File

@ -8,7 +8,7 @@ end
local appname = "passwall" local appname = "passwall"
local jsonc = api.jsonc local jsonc = api.jsonc
local uci = api.uci local uci = api.libuci
local type_name = "Xray" local type_name = "Xray"

View File

@ -11,7 +11,7 @@ end
local singbox_tags = luci.sys.exec(singbox_bin .. " version | grep 'Tags:' | awk '{print $2}'") local singbox_tags = luci.sys.exec(singbox_bin .. " version | grep 'Tags:' | awk '{print $2}'")
local appname = "passwall" local appname = "passwall"
local uci = api.uci local uci = api.libuci
local type_name = "sing-box" local type_name = "sing-box"

View File

@ -6,6 +6,8 @@ if not api.finded_com("hysteria") then
return return
end end
local fs = api.fs
local type_name = "Hysteria2" local type_name = "Hysteria2"
local option_prefix = "hysteria2_" local option_prefix = "hysteria2_"
@ -46,7 +48,7 @@ o = s:option(FileUpload, _n("tls_certificateFile"), translate("Public key absolu
o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg[1] .. ".pem" o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg[1] .. ".pem"
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not fs.access(value) then
return nil, translate("Can't find this file!") return nil, translate("Can't find this file!")
else else
return value return value
@ -59,7 +61,7 @@ o = s:option(FileUpload, _n("tls_keyFile"), translate("Private key absolute path
o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. ".key" o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. ".key"
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not fs.access(value) then
return nil, translate("Can't find this file!") return nil, translate("Can't find this file!")
else else
return value return value

View File

@ -6,6 +6,8 @@ if not api.finded_com("xray") then
return return
end end
local fs = api.fs
local type_name = "Xray" local type_name = "Xray"
local option_prefix = "xray_" local option_prefix = "xray_"
@ -174,7 +176,7 @@ o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg
o:depends({ [_n("tls")] = true, [_n("reality")] = false }) o:depends({ [_n("tls")] = true, [_n("reality")] = false })
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not fs.access(value) then
return nil, translate("Can't find this file!") return nil, translate("Can't find this file!")
else else
return value return value
@ -188,7 +190,7 @@ o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. "
o:depends({ [_n("tls")] = true, [_n("reality")] = false }) o:depends({ [_n("tls")] = true, [_n("reality")] = false })
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not fs.access(value) then
return nil, translate("Can't find this file!") return nil, translate("Can't find this file!")
else else
return value return value

View File

@ -8,6 +8,8 @@ if not singbox_bin then
return return
end end
local fs = api.fs
local singbox_tags = luci.sys.exec(singbox_bin .. " version | grep 'Tags:' | awk '{print $2}'") local singbox_tags = luci.sys.exec(singbox_bin .. " version | grep 'Tags:' | awk '{print $2}'")
local type_name = "sing-box" local type_name = "sing-box"
@ -255,7 +257,7 @@ o:depends({ [_n("protocol")] = "tuic" })
o:depends({ [_n("protocol")] = "hysteria2" }) o:depends({ [_n("protocol")] = "hysteria2" })
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not fs.access(value) then
return nil, translate("Can't find this file!") return nil, translate("Can't find this file!")
else else
return value return value
@ -273,7 +275,7 @@ o:depends({ [_n("protocol")] = "tuic" })
o:depends({ [_n("protocol")] = "hysteria2" }) o:depends({ [_n("protocol")] = "hysteria2" })
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not fs.access(value) then
return nil, translate("Can't find this file!") return nil, translate("Can't find this file!")
else else
return value return value

View File

@ -6,6 +6,8 @@ if not api.is_finded("trojan-plus") then
return return
end end
local fs = api.fs
local type_name = "Trojan-Plus" local type_name = "Trojan-Plus"
local option_prefix = "trojan_plus_" local option_prefix = "trojan_plus_"
@ -50,7 +52,7 @@ o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg
o:depends({ [_n("tls")] = true }) o:depends({ [_n("tls")] = true })
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not fs.access(value) then
return nil, translate("Can't find this file!") return nil, translate("Can't find this file!")
else else
return value return value
@ -64,7 +66,7 @@ o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. "
o:depends({ [_n("tls")] = true }) o:depends({ [_n("tls")] = true })
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not fs.access(value) then
return nil, translate("Can't find this file!") return nil, translate("Can't find this file!")
else else
return value return value

View File

@ -1,5 +1,5 @@
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local fs = require "nixio.fs" local fs = api.fs
local types_dir = "/usr/lib/lua/luci/model/cbi/passwall/server/type/" local types_dir = "/usr/lib/lua/luci/model/cbi/passwall/server/type/"
m = Map("passwall_server", translate("Server Config")) m = Map("passwall_server", translate("Server Config"))

View File

@ -4,7 +4,6 @@ bin = require "nixio".bin
fs = require "nixio.fs" fs = require "nixio.fs"
sys = require "luci.sys" sys = require "luci.sys"
libuci = require "uci".cursor() libuci = require "uci".cursor()
uci = require"luci.model.uci".cursor()
util = require "luci.util" util = require "luci.util"
datatypes = require "luci.cbi.datatypes" datatypes = require "luci.cbi.datatypes"
jsonc = require "luci.jsonc" jsonc = require "luci.jsonc"
@ -176,7 +175,7 @@ end
function curl_direct(url, file, args) function curl_direct(url, file, args)
--直连访问 --直连访问
local chn_list = uci:get(appname, "@global[0]", "chn_list") or "direct" local chn_list = libuci:get(appname, "@global[0]", "chn_list") or "direct"
local Dns = (chn_list == "proxy") and "1.1.1.1" or "223.5.5.5" local Dns = (chn_list == "proxy") and "1.1.1.1" or "223.5.5.5"
if not args then args = {} end if not args then args = {} end
local tmp_args = clone(args) local tmp_args = clone(args)
@ -425,7 +424,7 @@ function get_node_name(node_id)
if type(node_id) == "table" then if type(node_id) == "table" then
e = node_id e = node_id
else else
e = uci:get_all(appname, node_id) e = libuci:get_all(appname, node_id)
end end
if e then if e then
if e.type and e.remarks then if e.type and e.remarks then
@ -441,9 +440,9 @@ function get_node_name(node_id)
end end
function get_valid_nodes() function get_valid_nodes()
local show_node_info = uci_get_type("global_other", "show_node_info") or "0" local show_node_info = uci_get_type("@global_other[0]", "show_node_info", "0")
local nodes = {} local nodes = {}
uci:foreach(appname, "nodes", function(e) libuci:foreach(appname, "nodes", function(e)
e.id = e[".name"] e.id = e[".name"]
if e.type and e.remarks then if e.type and e.remarks then
if e.protocol and (e.protocol == "_balancing" or e.protocol == "_shunt" or e.protocol == "_iface") then if e.protocol and (e.protocol == "_balancing" or e.protocol == "_shunt" or e.protocol == "_iface") then
@ -540,15 +539,7 @@ function gen_short_uuid()
end end
function uci_get_type(type, config, default) function uci_get_type(type, config, default)
local value = uci:get_first(appname, type, config, default) or sys.exec("echo -n $(uci -q get " .. appname .. ".@" .. type .."[0]." .. config .. ")") local value = libuci:get(appname, type, config) or default
if (value == nil or value == "") and (default and default ~= "") then
value = default
end
return value
end
function uci_get_type_id(id, config, default)
local value = uci:get(appname, id, config, default) or sys.exec("echo -n $(uci -q get " .. appname .. "." .. id .. "." .. config .. ")")
if (value == nil or value == "") and (default and default ~= "") then if (value == nil or value == "") and (default and default ~= "") then
value = default value = default
end end
@ -564,7 +555,7 @@ local function chmod_755(file)
end end
function get_customed_path(e) function get_customed_path(e)
return uci_get_type("global_app", e .. "_file") return uci_get_type("@global_app[0]", e .. "_file")
end end
function finded_com(e) function finded_com(e)
@ -623,7 +614,7 @@ end
function get_app_path(app_name) function get_app_path(app_name)
if com[app_name] then if com[app_name] then
local def_path = com[app_name].default_path local def_path = com[app_name].default_path
local path = uci_get_type("global_app", app_name:gsub("%-","_") .. "_file") local path = uci_get_type("@global_app[0]", app_name:gsub("%-","_") .. "_file")
path = path and (#path>0 and path or def_path) or def_path path = path and (#path>0 and path or def_path) or def_path
return path return path
end end

View File

@ -3,7 +3,7 @@
local action = arg[1] local action = arg[1]
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local sys = api.sys local sys = api.sys
local uci = api.uci local uci = api.libuci
local jsonc = api.jsonc local jsonc = api.jsonc
local CONFIG = "passwall_server" local CONFIG = "passwall_server"

View File

@ -1,6 +1,6 @@
module("luci.passwall.util_hysteria2", package.seeall) module("luci.passwall.util_hysteria2", package.seeall)
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local uci = api.uci local uci = api.libuci
local jsonc = api.jsonc local jsonc = api.jsonc
function gen_config_server(node) function gen_config_server(node)

View File

@ -1,6 +1,6 @@
module("luci.passwall.util_naiveproxy", package.seeall) module("luci.passwall.util_naiveproxy", package.seeall)
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local uci = api.uci local uci = api.libuci
local jsonc = api.jsonc local jsonc = api.jsonc
function gen_config(var) function gen_config(var)

View File

@ -1,6 +1,6 @@
module("luci.passwall.util_shadowsocks", package.seeall) module("luci.passwall.util_shadowsocks", package.seeall)
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local uci = api.uci local uci = api.libuci
local jsonc = api.jsonc local jsonc = api.jsonc
function gen_config_server(node) function gen_config_server(node)

View File

@ -1,6 +1,6 @@
module("luci.passwall.util_sing-box", package.seeall) module("luci.passwall.util_sing-box", package.seeall)
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local uci = api.uci local uci = api.libuci
local sys = api.sys local sys = api.sys
local jsonc = api.jsonc local jsonc = api.jsonc
local appname = "passwall" local appname = "passwall"

View File

@ -1,6 +1,6 @@
module("luci.passwall.util_trojan", package.seeall) module("luci.passwall.util_trojan", package.seeall)
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local uci = api.uci local uci = api.libuci
local json = api.jsonc local json = api.jsonc
function gen_config_server(node) function gen_config_server(node)

View File

@ -1,6 +1,6 @@
module("luci.passwall.util_tuic", package.seeall) module("luci.passwall.util_tuic", package.seeall)
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local uci = api.uci local uci = api.libuci
local json = api.jsonc local json = api.jsonc
function gen_config(var) function gen_config(var)

View File

@ -1,6 +1,6 @@
module("luci.passwall.util_xray", package.seeall) module("luci.passwall.util_xray", package.seeall)
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local uci = api.uci local uci = api.libuci
local sys = api.sys local sys = api.sys
local jsonc = api.jsonc local jsonc = api.jsonc
local appname = "passwall" local appname = "passwall"

View File

@ -1,6 +1,6 @@
<% <%
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local console_port = api.uci_get_type("global_haproxy", "console_port", "") local console_port = api.uci_get_type("@global_haproxy[0]", "console_port", "")
-%> -%>
<p id="_status"></p> <p id="_status"></p>

View File

@ -36,7 +36,7 @@ table td, .table .td {
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
let auto_detection_time = "<%=api.uci_get_type("global_other", "auto_detection_time", "0")%>" let auto_detection_time = "<%=api.uci_get_type("@global_other[0]", "auto_detection_time", "0")%>"
var node_list = {}; var node_list = {};
var node_count = 0; var node_count = 0;

View File

@ -1,12 +1,12 @@
<% <%
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local gfwlist_update = api.uci_get_type("global_rules", "gfwlist_update", "1") == "1" and "checked='checked'" or "" local gfwlist_update = api.uci_get_type("@global_rules[0]", "gfwlist_update", "1") == "1" and "checked='checked'" or ""
local chnroute_update = api.uci_get_type("global_rules", "chnroute_update", "1") == "1" and "checked='checked'" or "" local chnroute_update = api.uci_get_type("@global_rules[0]", "chnroute_update", "1") == "1" and "checked='checked'" or ""
local chnroute6_update = api.uci_get_type("global_rules", "chnroute6_update", "1") == "1" and "checked='checked'" or "" local chnroute6_update = api.uci_get_type("@global_rules[0]", "chnroute6_update", "1") == "1" and "checked='checked'" or ""
local chnlist_update = api.uci_get_type("global_rules", "chnlist_update", "1") == "1" and "checked='checked'" or "" local chnlist_update = api.uci_get_type("@global_rules[0]", "chnlist_update", "1") == "1" and "checked='checked'" or ""
local geoip_update = api.uci_get_type("global_rules", "geoip_update", "1") == "1" and "checked='checked'" or "" local geoip_update = api.uci_get_type("@global_rules[0]", "geoip_update", "1") == "1" and "checked='checked'" or ""
local geosite_update = api.uci_get_type("global_rules", "geosite_update", "1") == "1" and "checked='checked'" or "" local geosite_update = api.uci_get_type("@global_rules[0]", "geosite_update", "1") == "1" and "checked='checked'" or ""
-%> -%>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -1350,13 +1350,14 @@ start_dns() {
china_ng_local_dns="tcp://${DIRECT_DNS}" china_ng_local_dns="tcp://${DIRECT_DNS}"
sing_box_local_dns="direct_dns_tcp_server=${DIRECT_DNS}" sing_box_local_dns="direct_dns_tcp_server=${DIRECT_DNS}"
#当全局包括访问控制节点开启chinadns-ng时不启用dns2tcp #当全局包括访问控制节点开启chinadns-ng时不启动新进程。
[ "$DNS_SHUNT" != "chinadns-ng" ] || [ "$ACL_RULE_DNSMASQ" = "1" ] && { [ "$DNS_SHUNT" != "chinadns-ng" ] || [ "$ACL_RULE_DNSMASQ" = "1" ] && {
LOCAL_DNS="127.0.0.1#${dns_listen_port}" LOCAL_DNS="127.0.0.1#${dns_listen_port}"
dns_listen_port=$(expr $dns_listen_port + 1) local china_ng_c_dns="tcp://$(get_first_dns DIRECT_DNS 53 | sed 's/:/#/g')"
ln_run "$(first_type dns2tcp)" dns2tcp "/dev/null" -L "${LOCAL_DNS}" -R "$(get_first_dns DIRECT_DNS 53)" -v ln_run "$(first_type chinadns-ng)" chinadns-ng "/dev/null" -b 127.0.0.1 -l ${dns_listen_port} -c ${china_ng_c_dns} -d chn
echolog " - dns2tcp(${LOCAL_DNS}) -> tcp://$(get_first_dns DIRECT_DNS 53 | sed 's/#/:/g')" echolog " - ChinaDNS-NG(${LOCAL_DNS}) -> ${china_ng_c_dns}"
echolog " * 请确保上游直连 DNS 支持 TCP 查询。" echolog " * 请确保上游直连 DNS 支持 TCP 查询。"
dns_listen_port=$(expr $dns_listen_port + 1)
} }
;; ;;
dot) dot)
@ -1364,14 +1365,13 @@ start_dns() {
local DIRECT_DNS=$(config_t_get global direct_dns_dot "tls://dot.pub@1.12.12.12") local DIRECT_DNS=$(config_t_get global direct_dns_dot "tls://dot.pub@1.12.12.12")
china_ng_local_dns=${DIRECT_DNS} china_ng_local_dns=${DIRECT_DNS}
#当全局包括访问控制节点开启chinadns-ng时不启用dns2dot #当全局包括访问控制节点开启chinadns-ng时不启动新进程。
[ "$DNS_SHUNT" != "chinadns-ng" ] || [ "$ACL_RULE_DNSMASQ" = "1" ] && { [ "$DNS_SHUNT" != "chinadns-ng" ] || [ "$ACL_RULE_DNSMASQ" = "1" ] && {
LOCAL_DNS="127.0.0.1#${dns_listen_port}" LOCAL_DNS="127.0.0.1#${dns_listen_port}"
local cdns_listen_port=${dns_listen_port} ln_run "$(first_type chinadns-ng)" chinadns-ng "/dev/null" -b 127.0.0.1 -l ${dns_listen_port} -c ${DIRECT_DNS} -d chn
dns_listen_port=$(expr $dns_listen_port + 1)
ln_run "$(first_type chinadns-ng)" chinadns-ng "/dev/null" -b 127.0.0.1 -l ${cdns_listen_port} -c ${DIRECT_DNS} -d chn
echolog " - ChinaDNS-NG(${LOCAL_DNS}) -> ${DIRECT_DNS}" echolog " - ChinaDNS-NG(${LOCAL_DNS}) -> ${DIRECT_DNS}"
echolog " * 请确保上游直连 DNS 支持 DoT 查询。" echolog " * 请确保上游直连 DNS 支持 DoT 查询。"
dns_listen_port=$(expr $dns_listen_port + 1)
} }
local tmp_dot_ip=$(echo "$DIRECT_DNS" | sed -n 's/.*:\/\/\([^@#]*@\)*\([^@#]*\).*/\2/p') local tmp_dot_ip=$(echo "$DIRECT_DNS" | sed -n 's/.*:\/\/\([^@#]*@\)*\([^@#]*\).*/\2/p')
@ -1481,55 +1481,49 @@ start_dns() {
dot) dot)
use_tcp_node_resolve_dns=1 use_tcp_node_resolve_dns=1
if [ "$chinadns_tls" != "nil" ]; then if [ "$chinadns_tls" != "nil" ]; then
if [ "$DNS_SHUNT" = "chinadns-ng" ] && [ -n "$(first_type chinadns-ng)" ]; then
local china_ng_listen_port=${dns_listen_port} local china_ng_listen_port=${dns_listen_port}
local china_ng_trust_dns=$(config_t_get global remote_dns_dot "tls://dns.google@8.8.4.4") local china_ng_trust_dns=$(config_t_get global remote_dns_dot "tls://dns.google@8.8.4.4")
local tmp_dot_ip=$(echo "$china_ng_trust_dns" | sed -n 's/.*:\/\/\([^@#]*@\)*\([^@#]*\).*/\2/p') local tmp_dot_ip=$(echo "$china_ng_trust_dns" | sed -n 's/.*:\/\/\([^@#]*@\)*\([^@#]*\).*/\2/p')
local tmp_dot_port=$(echo "$china_ng_trust_dns" | sed -n 's/.*#\([0-9]\+\).*/\1/p') local tmp_dot_port=$(echo "$china_ng_trust_dns" | sed -n 's/.*#\([0-9]\+\).*/\1/p')
REMOTE_DNS="$tmp_dot_ip#${tmp_dot_port:-853}" REMOTE_DNS="$tmp_dot_ip#${tmp_dot_port:-853}"
else [ "$DNS_SHUNT" != "chinadns-ng" ] && {
local china_ng_listen_port=${dns_listen_port} [ "$FILTER_PROXY_IPV6" = "1" ] && DNSMASQ_FILTER_PROXY_IPV6=0 && local no_ipv6_trust="-N"
local china_ng_trust_dns=$(config_t_get global remote_dns_dot "tls://dns.google@8.8.4.4") ln_run "$(first_type chinadns-ng)" chinadns-ng "/dev/null" -b 127.0.0.1 -l ${china_ng_listen_port} -t ${china_ng_trust_dns} -d gfw ${no_ipv6_trust}
ln_run "$(first_type chinadns-ng)" chinadns-ng "/dev/null" -b 127.0.0.1 -l ${china_ng_listen_port} -t ${china_ng_trust_dns} -d gfw
echolog " - ChinaDNS-NG(${TUN_DNS}) -> ${china_ng_trust_dns}" echolog " - ChinaDNS-NG(${TUN_DNS}) -> ${china_ng_trust_dns}"
}
local tmp_dot_ip=$(echo "$china_ng_trust_dns" | sed -n 's/.*:\/\/\([^@#]*@\)*\([^@#]*\).*/\2/p')
local tmp_dot_port=$(echo "$china_ng_trust_dns" | sed -n 's/.*#\([0-9]\+\).*/\1/p')
REMOTE_DNS="$tmp_dot_ip#${tmp_dot_port:-853}"
fi
else else
echolog " - 你的ChinaDNS-NG版本不支持DoT远程DNS将默认使用tcp://1.1.1.1" echolog " - 你的ChinaDNS-NG版本不支持DoT远程DNS将默认使用tcp://1.1.1.1"
REMOTE_DNS="1.1.1.1"
if [ "$DNS_SHUNT" = "chinadns-ng" ] && [ -n "$(first_type chinadns-ng)" ]; then
local china_ng_listen_port=${dns_listen_port} local china_ng_listen_port=${dns_listen_port}
local china_ng_trust_dns="tcp://1.1.1.1" local china_ng_trust_dns="tcp://${REMOTE_DNS}"
REMOTE_DNS="1.1.1.1" [ "$DNS_SHUNT" != "chinadns-ng" ] && {
else [ "$FILTER_PROXY_IPV6" = "1" ] && DNSMASQ_FILTER_PROXY_IPV6=0 && local no_ipv6_trust="-N"
REMOTE_DNS="1.1.1.1" ln_run "$(first_type chinadns-ng)" chinadns-ng "/dev/null" -b 127.0.0.1 -l ${china_ng_listen_port} -t ${china_ng_trust_dns} -d gfw ${no_ipv6_trust}
ln_run "$(first_type dns2tcp)" dns2tcp "/dev/null" -L "${TUN_DNS}" -R "$(get_first_dns REMOTE_DNS 53)" -v echolog " - ChinaDNS-NG(${TUN_DNS}) -> ${china_ng_trust_dns}"
echolog " - dns2tcp(${TUN_DNS}) -> tcp://$(get_first_dns REMOTE_DNS 53 | sed 's/#/:/g')" }
fi
fi fi
;; ;;
udp) udp)
use_udp_node_resolve_dns=1 use_udp_node_resolve_dns=1
if [ "$DNS_SHUNT" = "chinadns-ng" ] && [ -n "$(first_type chinadns-ng)" ]; then
local china_ng_listen_port=${dns_listen_port} local china_ng_listen_port=${dns_listen_port}
local china_ng_trust_dns="udp://$(get_first_dns REMOTE_DNS 53 | sed 's/:/#/g')" local china_ng_trust_dns="udp://$(get_first_dns REMOTE_DNS 53 | sed 's/:/#/g')"
else [ "$DNS_SHUNT" != "chinadns-ng" ] && {
TUN_DNS="$(echo ${REMOTE_DNS} | sed 's/#/:/g' | sed -E 's/\:([^:]+)$/#\1/g')" [ "$FILTER_PROXY_IPV6" = "1" ] && DNSMASQ_FILTER_PROXY_IPV6=0 && local no_ipv6_trust="-N"
echolog " - udp://${TUN_DNS}" ln_run "$(first_type chinadns-ng)" chinadns-ng "/dev/null" -b 127.0.0.1 -l ${china_ng_listen_port} -t ${china_ng_trust_dns} -d gfw ${no_ipv6_trust}
fi echolog " - ChinaDNS-NG(${TUN_DNS}) -> ${china_ng_trust_dns}"
#TUN_DNS="$(echo ${REMOTE_DNS} | sed 's/#/:/g' | sed -E 's/\:([^:]+)$/#\1/g')"
#echolog " - udp://${TUN_DNS}"
}
;; ;;
tcp) tcp)
use_tcp_node_resolve_dns=1 use_tcp_node_resolve_dns=1
if [ "$DNS_SHUNT" = "chinadns-ng" ] && [ -n "$(first_type chinadns-ng)" ]; then
local china_ng_listen_port=${dns_listen_port} local china_ng_listen_port=${dns_listen_port}
local china_ng_trust_dns="tcp://$(get_first_dns REMOTE_DNS 53 | sed 's/:/#/g')" local china_ng_trust_dns="tcp://$(get_first_dns REMOTE_DNS 53 | sed 's/:/#/g')"
else [ "$DNS_SHUNT" != "chinadns-ng" ] && {
ln_run "$(first_type dns2tcp)" dns2tcp "/dev/null" -L "${TUN_DNS}" -R "$(get_first_dns REMOTE_DNS 53)" -v [ "$FILTER_PROXY_IPV6" = "1" ] && DNSMASQ_FILTER_PROXY_IPV6=0 && local no_ipv6_trust="-N"
echolog " - dns2tcp(${TUN_DNS}) -> tcp://$(get_first_dns REMOTE_DNS 53 | sed 's/#/:/g')" ln_run "$(first_type chinadns-ng)" chinadns-ng "/dev/null" -b 127.0.0.1 -l ${china_ng_listen_port} -t ${china_ng_trust_dns} -d gfw ${no_ipv6_trust}
fi echolog " - ChinaDNS-NG(${TUN_DNS}) -> ${china_ng_trust_dns}"
}
;; ;;
esac esac

View File

@ -4,7 +4,7 @@ local api = require ("luci.passwall.api")
local appname = "passwall" local appname = "passwall"
local fs = api.fs local fs = api.fs
local jsonc = api.jsonc local jsonc = api.jsonc
local uci = api.uci local uci = api.libuci
local sys = api.sys local sys = api.sys
local log = function(...) local log = function(...)

View File

@ -20,7 +20,7 @@ local TCP_NODE = var["-TCP_NODE"]
local NFTFLAG = var["-NFTFLAG"] local NFTFLAG = var["-NFTFLAG"]
local REMOTE_FAKEDNS = var["-REMOTE_FAKEDNS"] local REMOTE_FAKEDNS = var["-REMOTE_FAKEDNS"]
local uci = api.uci local uci = api.libuci
local sys = api.sys local sys = api.sys
local fs = api.fs local fs = api.fs
local datatypes = api.datatypes local datatypes = api.datatypes

View File

@ -28,7 +28,7 @@ local CACHE_FLAG = "smartdns_" .. FLAG
local CACHE_DNS_PATH = CACHE_PATH .. "/" .. CACHE_FLAG local CACHE_DNS_PATH = CACHE_PATH .. "/" .. CACHE_FLAG
local CACHE_DNS_FILE = CACHE_DNS_PATH .. ".conf" local CACHE_DNS_FILE = CACHE_DNS_PATH .. ".conf"
local uci = api.uci local uci = api.libuci
local sys = api.sys local sys = api.sys
local fs = api.fs local fs = api.fs
local datatypes = api.datatypes local datatypes = api.datatypes

View File

@ -1,12 +1,12 @@
#!/usr/bin/lua #!/usr/bin/lua
require 'nixio'
require 'luci.sys'
local luci = luci
local ucic = luci.model.uci.cursor()
local jsonc = require "luci.jsonc"
local name = 'passwall'
local api = require ("luci.passwall.api") local api = require ("luci.passwall.api")
local name = api.appname
local uci = api.libuci
local sys = api.sys
local jsonc = api.jsonc
local fs = api.fs
local arg1 = arg[1] local arg1 = arg[1]
local arg2 = arg[2] local arg2 = arg[2]
local arg3 = arg[3] local arg3 = arg[3]
@ -14,12 +14,12 @@ local arg3 = arg[3]
local nftable_name = "inet passwall" local nftable_name = "inet passwall"
local rule_path = "/usr/share/" .. name .. "/rules" local rule_path = "/usr/share/" .. name .. "/rules"
local reboot = 0 local reboot = 0
local gfwlist_update = 0 local gfwlist_update = "0"
local chnroute_update = 0 local chnroute_update = "0"
local chnroute6_update = 0 local chnroute6_update = "0"
local chnlist_update = 0 local chnlist_update = "0"
local geoip_update = 0 local geoip_update = "0"
local geosite_update = 0 local geosite_update = "0"
-- match comments/title/whitelist/ip address/excluded_domain -- match comments/title/whitelist/ip address/excluded_domain
local comment_pattern = "^[#!\\[@]+" local comment_pattern = "^[#!\\[@]+"
@ -29,14 +29,14 @@ local ip6_ipset_pattern = ":-[%x]+%:+[%x]-[%/][%d]+$"
local domain_pattern = "([%w%-%_]+%.[%w%.%-%_]+)[%/%*]*" local domain_pattern = "([%w%-%_]+%.[%w%.%-%_]+)[%/%*]*"
local excluded_domain = {"apple.com","sina.cn","sina.com.cn","baidu.com","byr.cn","jlike.com","weibo.com","zhongsou.com","youdao.com","sogou.com","so.com","soso.com","aliyun.com","taobao.com","jd.com","qq.com","bing.com"} local excluded_domain = {"apple.com","sina.cn","sina.com.cn","baidu.com","byr.cn","jlike.com","weibo.com","zhongsou.com","youdao.com","sogou.com","so.com","soso.com","aliyun.com","taobao.com","jd.com","qq.com","bing.com"}
local gfwlist_url = ucic:get(name, "@global_rules[0]", "gfwlist_url") or {"https://fastly.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/gfw.txt"} local gfwlist_url = uci:get(name, "@global_rules[0]", "gfwlist_url") or {"https://fastly.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/gfw.txt"}
local chnroute_url = ucic:get(name, "@global_rules[0]", "chnroute_url") or {"https://ispip.clang.cn/all_cn.txt"} local chnroute_url = uci:get(name, "@global_rules[0]", "chnroute_url") or {"https://ispip.clang.cn/all_cn.txt"}
local chnroute6_url = ucic:get(name, "@global_rules[0]", "chnroute6_url") or {"https://ispip.clang.cn/all_cn_ipv6.txt"} local chnroute6_url = uci:get(name, "@global_rules[0]", "chnroute6_url") or {"https://ispip.clang.cn/all_cn_ipv6.txt"}
local chnlist_url = ucic:get(name, "@global_rules[0]", "chnlist_url") or {"https://fastly.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/accelerated-domains.china.conf","https://fastly.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/apple.china.conf","https://fastly.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/google.china.conf"} local chnlist_url = uci:get(name, "@global_rules[0]", "chnlist_url") or {"https://fastly.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/accelerated-domains.china.conf","https://fastly.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/apple.china.conf","https://fastly.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/google.china.conf"}
local geoip_api = "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest" local geoip_api = "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest"
local geosite_api = "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest" local geosite_api = "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest"
local asset_location = ucic:get_first(name, 'global_rules', "v2ray_location_asset", "/usr/share/v2ray/") local asset_location = uci:get(name, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
local use_nft = ucic:get(name, "@global_forwarding[0]", "use_nft") or "0" local use_nft = uci:get(name, "@global_forwarding[0]", "use_nft") or "0"
if arg3 == "cron" then if arg3 == "cron" then
arg2 = nil arg2 = nil
@ -61,12 +61,12 @@ local function gen_nftset(set_name, ip_type, tmp_file, input_file)
nft_file, err = io.open(tmp_file, "w") nft_file, err = io.open(tmp_file, "w")
nft_file:write('#!/usr/sbin/nft -f\n') nft_file:write('#!/usr/sbin/nft -f\n')
nft_file:write(string.format('define %s = {%s}\n', set_name, string.gsub(element, "%s*%c+", " timeout 3650d, "))) nft_file:write(string.format('define %s = {%s}\n', set_name, string.gsub(element, "%s*%c+", " timeout 3650d, ")))
if luci.sys.call(string.format('nft "list set %s %s" >/dev/null 2>&1', nftable_name, set_name)) ~= 0 then if sys.call(string.format('nft "list set %s %s" >/dev/null 2>&1', nftable_name, set_name)) ~= 0 then
nft_file:write(string.format('add set %s %s { type %s; flags interval, timeout; timeout 2d; gc-interval 2d; auto-merge; }\n', nftable_name, set_name, ip_type)) nft_file:write(string.format('add set %s %s { type %s; flags interval, timeout; timeout 2d; gc-interval 2d; auto-merge; }\n', nftable_name, set_name, ip_type))
end end
nft_file:write(string.format('add element %s %s $%s\n', nftable_name, set_name, set_name)) nft_file:write(string.format('add element %s %s $%s\n', nftable_name, set_name, set_name))
nft_file:close() nft_file:close()
luci.sys.call(string.format('nft -f %s &>/dev/null',tmp_file)) sys.call(string.format('nft -f %s &>/dev/null',tmp_file))
os.remove(tmp_file) os.remove(tmp_file)
end end
@ -76,9 +76,9 @@ local function gen_cache(set_name, ip_type, input_file, output_file)
local tmp_file = output_file .. "_tmp" local tmp_file = output_file .. "_tmp"
local tmp_set_name = set_name .. "_tmp" local tmp_set_name = set_name .. "_tmp"
gen_nftset(tmp_set_name, ip_type, tmp_file, input_file) gen_nftset(tmp_set_name, ip_type, tmp_file, input_file)
luci.sys.call(string.format('nft list set %s %s | sed "s/%s/%s/g" | cat > %s', nftable_name, tmp_set_name, tmp_set_name, set_name, output_file)) sys.call(string.format('nft list set %s %s | sed "s/%s/%s/g" | cat > %s', nftable_name, tmp_set_name, tmp_set_name, set_name, output_file))
luci.sys.call(string.format('nft flush set %s %s', nftable_name, tmp_set_name)) sys.call(string.format('nft flush set %s %s', nftable_name, tmp_set_name))
luci.sys.call(string.format('nft delete set %s %s', nftable_name, tmp_set_name)) sys.call(string.format('nft delete set %s %s', nftable_name, tmp_set_name))
end end
-- curl -- curl
@ -114,9 +114,9 @@ local function line_count(file_path)
end end
local function non_file_check(file_path, vali_file) local function non_file_check(file_path, vali_file)
if nixio.fs.readfile(file_path, 10) then if fs.readfile(file_path, 10) then
local remote_file_size = tonumber(luci.sys.exec("cat " .. vali_file .. " | grep -i 'Content-Length' | awk '{print $2}'")) local remote_file_size = tonumber(sys.exec("cat " .. vali_file .. " | grep -i 'Content-Length' | awk '{print $2}'"))
local local_file_size = tonumber(nixio.fs.stat(file_path, "size")) local local_file_size = tonumber(fs.stat(file_path, "size"))
if remote_file_size and local_file_size then if remote_file_size and local_file_size then
if remote_file_size == local_file_size then if remote_file_size == local_file_size then
return nil; return nil;
@ -227,11 +227,11 @@ local function fetch_rule(rule_name,rule_type,url,exclude_domain)
end end
out:close() out:close()
end end
luci.sys.call("cat " ..unsort_file_tmp.. " | sort -u > "..file_tmp) sys.call("cat " ..unsort_file_tmp.. " | sort -u > "..file_tmp)
os.remove(unsort_file_tmp) os.remove(unsort_file_tmp)
local old_md5 = luci.sys.exec("echo -n $(md5sum " .. rule_path .. "/" ..rule_name.. " | awk '{print $1}')") local old_md5 = sys.exec("echo -n $(md5sum " .. rule_path .. "/" ..rule_name.. " | awk '{print $1}')")
local new_md5 = luci.sys.exec("echo -n $([ -f '" ..file_tmp.. "' ] && md5sum " ..file_tmp.." | awk '{print $1}')") local new_md5 = sys.exec("echo -n $([ -f '" ..file_tmp.. "' ] && md5sum " ..file_tmp.." | awk '{print $1}')")
if old_md5 ~= new_md5 then if old_md5 ~= new_md5 then
local count = line_count(file_tmp) local count = line_count(file_tmp)
if use_nft == "1" and (rule_type == "ip6" or rule_type == "ip4") then if use_nft == "1" and (rule_type == "ip6" or rule_type == "ip4") then
@ -249,10 +249,10 @@ local function fetch_rule(rule_name,rule_type,url,exclude_domain)
end end
gen_cache(set_name, "ipv6_addr", file_tmp, output_file) gen_cache(set_name, "ipv6_addr", file_tmp, output_file)
end end
luci.sys.exec(string.format('mv -f %s %s', output_file, rule_path .. "/" ..rule_name.. ".nft")) sys.exec(string.format('mv -f %s %s', output_file, rule_path .. "/" ..rule_name.. ".nft"))
os.remove(output_file) os.remove(output_file)
end end
luci.sys.exec("mv -f "..file_tmp .. " " ..rule_path .. "/" ..rule_name) sys.exec("mv -f "..file_tmp .. " " ..rule_path .. "/" ..rule_name)
reboot = 1 reboot = 1
log(rule_name.. " 更新成功,总规则数 " ..count.. " 条。") log(rule_name.. " 更新成功,总规则数 " ..count.. " 条。")
else else
@ -299,9 +299,9 @@ local function fetch_geoip()
f:write(content:gsub("geoip.dat", "/tmp/geoip.dat"), "") f:write(content:gsub("geoip.dat", "/tmp/geoip.dat"), "")
f:close() f:close()
if nixio.fs.access(asset_location .. "geoip.dat") then if fs.access(asset_location .. "geoip.dat") then
luci.sys.call(string.format("cp -f %s %s", asset_location .. "geoip.dat", "/tmp/geoip.dat")) sys.call(string.format("cp -f %s %s", asset_location .. "geoip.dat", "/tmp/geoip.dat"))
if luci.sys.call('sha256sum -c /tmp/geoip.dat.sha256sum > /dev/null 2>&1') == 0 then if sys.call('sha256sum -c /tmp/geoip.dat.sha256sum > /dev/null 2>&1') == 0 then
log("geoip 版本一致,无需更新。") log("geoip 版本一致,无需更新。")
return 1 return 1
end end
@ -309,8 +309,8 @@ local function fetch_geoip()
for _2, v2 in ipairs(json.assets) do for _2, v2 in ipairs(json.assets) do
if v2.name and v2.name == "geoip.dat" then if v2.name and v2.name == "geoip.dat" then
sret = curl(v2.browser_download_url, "/tmp/geoip.dat") sret = curl(v2.browser_download_url, "/tmp/geoip.dat")
if luci.sys.call('sha256sum -c /tmp/geoip.dat.sha256sum > /dev/null 2>&1') == 0 then if sys.call('sha256sum -c /tmp/geoip.dat.sha256sum > /dev/null 2>&1') == 0 then
luci.sys.call(string.format("mkdir -p %s && cp -f %s %s", asset_location, "/tmp/geoip.dat", asset_location .. "geoip.dat")) sys.call(string.format("mkdir -p %s && cp -f %s %s", asset_location, "/tmp/geoip.dat", asset_location .. "geoip.dat"))
reboot = 1 reboot = 1
log("geoip 更新成功。") log("geoip 更新成功。")
return 1 return 1
@ -350,9 +350,9 @@ local function fetch_geosite()
f:write(content:gsub("[^%s]+.dat", "/tmp/geosite.dat"), "") f:write(content:gsub("[^%s]+.dat", "/tmp/geosite.dat"), "")
f:close() f:close()
if nixio.fs.access(asset_location .. "geosite.dat") then if fs.access(asset_location .. "geosite.dat") then
luci.sys.call(string.format("cp -f %s %s", asset_location .. "geosite.dat", "/tmp/geosite.dat")) sys.call(string.format("cp -f %s %s", asset_location .. "geosite.dat", "/tmp/geosite.dat"))
if luci.sys.call('sha256sum -c /tmp/geosite.dat.sha256sum > /dev/null 2>&1') == 0 then if sys.call('sha256sum -c /tmp/geosite.dat.sha256sum > /dev/null 2>&1') == 0 then
log("geosite 版本一致,无需更新。") log("geosite 版本一致,无需更新。")
return 1 return 1
end end
@ -360,8 +360,8 @@ local function fetch_geosite()
for _2, v2 in ipairs(json.assets) do for _2, v2 in ipairs(json.assets) do
if v2.name and (v2.name == "geosite.dat" or v2.name == "dlc.dat") then if v2.name and (v2.name == "geosite.dat" or v2.name == "dlc.dat") then
sret = curl(v2.browser_download_url, "/tmp/geosite.dat") sret = curl(v2.browser_download_url, "/tmp/geosite.dat")
if luci.sys.call('sha256sum -c /tmp/geosite.dat.sha256sum > /dev/null 2>&1') == 0 then if sys.call('sha256sum -c /tmp/geosite.dat.sha256sum > /dev/null 2>&1') == 0 then
luci.sys.call(string.format("mkdir -p %s && cp -f %s %s", asset_location, "/tmp/geosite.dat", asset_location .. "geosite.dat")) sys.call(string.format("mkdir -p %s && cp -f %s %s", asset_location, "/tmp/geosite.dat", asset_location .. "geosite.dat"))
reboot = 1 reboot = 1
log("geosite 更新成功。") log("geosite 更新成功。")
return 1 return 1
@ -386,38 +386,38 @@ end
if arg2 then if arg2 then
string.gsub(arg2, '[^' .. "," .. ']+', function(w) string.gsub(arg2, '[^' .. "," .. ']+', function(w)
if w == "gfwlist" then if w == "gfwlist" then
gfwlist_update = 1 gfwlist_update = "1"
end end
if w == "chnroute" then if w == "chnroute" then
chnroute_update = 1 chnroute_update = "1"
end end
if w == "chnroute6" then if w == "chnroute6" then
chnroute6_update = 1 chnroute6_update = "1"
end end
if w == "chnlist" then if w == "chnlist" then
chnlist_update = 1 chnlist_update = "1"
end end
if w == "geoip" then if w == "geoip" then
geoip_update = 1 geoip_update = "1"
end end
if w == "geosite" then if w == "geosite" then
geosite_update = 1 geosite_update = "1"
end end
end) end)
else else
gfwlist_update = ucic:get_first(name, 'global_rules', "gfwlist_update", 1) gfwlist_update = uci:get(name, "@global_rules[0]", "gfwlist_update") or "1"
chnroute_update = ucic:get_first(name, 'global_rules', "chnroute_update", 1) chnroute_update = uci:get(name, "@global_rules[0]", "chnroute_update") or "1"
chnroute6_update = ucic:get_first(name, 'global_rules', "chnroute6_update", 1) chnroute6_update = uci:get(name, "@global_rules[0]", "chnroute6_update") or "1"
chnlist_update = ucic:get_first(name, 'global_rules', "chnlist_update", 1) chnlist_update = uci:get(name, "@global_rules[0]", "chnlist_update") or "1"
geoip_update = ucic:get_first(name, 'global_rules', "geoip_update", 1) geoip_update = uci:get(name, "@global_rules[0]", "geoip_update") or "1"
geosite_update = ucic:get_first(name, 'global_rules', "geosite_update", 1) geosite_update = uci:get(name, "@global_rules[0]", "geosite_update") or "1"
end end
if gfwlist_update == 0 and chnroute_update == 0 and chnroute6_update == 0 and chnlist_update == 0 and geoip_update == 0 and geosite_update == 0 then if gfwlist_update == "0" and chnroute_update == "0" and chnroute6_update == "0" and chnlist_update == "0" and geoip_update == "0" and geosite_update == "0" then
os.exit(0) os.exit(0)
end end
log("开始更新规则...") log("开始更新规则...")
if tonumber(gfwlist_update) == 1 then if gfwlist_update == "1" then
xpcall(fetch_gfwlist,function(e) xpcall(fetch_gfwlist,function(e)
log(e) log(e)
log(debug.traceback()) log(debug.traceback())
@ -425,7 +425,7 @@ if tonumber(gfwlist_update) == 1 then
end) end)
end end
if tonumber(chnroute_update) == 1 then if chnroute_update == "1" then
xpcall(fetch_chnroute,function(e) xpcall(fetch_chnroute,function(e)
log(e) log(e)
log(debug.traceback()) log(debug.traceback())
@ -433,7 +433,7 @@ if tonumber(chnroute_update) == 1 then
end) end)
end end
if tonumber(chnroute6_update) == 1 then if chnroute6_update == "1" then
xpcall(fetch_chnroute6,function(e) xpcall(fetch_chnroute6,function(e)
log(e) log(e)
log(debug.traceback()) log(debug.traceback())
@ -441,7 +441,7 @@ if tonumber(chnroute6_update) == 1 then
end) end)
end end
if tonumber(chnlist_update) == 1 then if chnlist_update == "1" then
xpcall(fetch_chnlist,function(e) xpcall(fetch_chnlist,function(e)
log(e) log(e)
log(debug.traceback()) log(debug.traceback())
@ -449,41 +449,40 @@ if tonumber(chnlist_update) == 1 then
end) end)
end end
if tonumber(geoip_update) == 1 then if geoip_update == "1" then
log("geoip 开始更新...") log("geoip 开始更新...")
local status = fetch_geoip() local status = fetch_geoip()
os.remove("/tmp/geoip.dat") os.remove("/tmp/geoip.dat")
os.remove("/tmp/geoip.dat.sha256sum") os.remove("/tmp/geoip.dat.sha256sum")
end end
if tonumber(geosite_update) == 1 then if geosite_update == "1" then
log("geosite 开始更新...") log("geosite 开始更新...")
local status = fetch_geosite() local status = fetch_geosite()
os.remove("/tmp/geosite.dat") os.remove("/tmp/geosite.dat")
os.remove("/tmp/geosite.dat.sha256sum") os.remove("/tmp/geosite.dat.sha256sum")
end end
ucic:set(name, ucic:get_first(name, 'global_rules'), "gfwlist_update", gfwlist_update) uci:set(name, "@global_rules[0]", "gfwlist_update", gfwlist_update)
ucic:set(name, ucic:get_first(name, 'global_rules'), "chnroute_update", chnroute_update) uci:set(name, "@global_rules[0]", "chnroute_update", chnroute_update)
ucic:set(name, ucic:get_first(name, 'global_rules'), "chnroute6_update", chnroute6_update) uci:set(name, "@global_rules[0]", "chnroute6_update", chnroute6_update)
ucic:set(name, ucic:get_first(name, 'global_rules'), "chnlist_update", chnlist_update) uci:set(name, "@global_rules[0]", "chnlist_update", chnlist_update)
ucic:set(name, ucic:get_first(name, 'global_rules'), "geoip_update", geoip_update) uci:set(name, "@global_rules[0]", "geoip_update", geoip_update)
ucic:set(name, ucic:get_first(name, 'global_rules'), "geosite_update", geosite_update) uci:set(name, "@global_rules[0]", "geosite_update", geosite_update)
ucic:save(name) uci:commit(name)
luci.sys.call("uci commit " .. name)
if reboot == 1 then if reboot == 1 then
if arg3 == "cron" then if arg3 == "cron" then
if not nixio.fs.access("/var/lock/" .. name .. ".lock") then if not fs.access("/var/lock/" .. name .. ".lock") then
luci.sys.call("touch /tmp/lock/" .. name .. "_cron.lock") sys.call("touch /tmp/lock/" .. name .. "_cron.lock")
end end
end end
log("重启服务,应用新的规则。") log("重启服务,应用新的规则。")
if use_nft == "1" then if use_nft == "1" then
luci.sys.call("sh /usr/share/" .. name .. "/nftables.sh flush_nftset_reload > /dev/null 2>&1 &") sys.call("sh /usr/share/" .. name .. "/nftables.sh flush_nftset_reload > /dev/null 2>&1 &")
else else
luci.sys.call("sh /usr/share/" .. name .. "/iptables.sh flush_ipset_reload > /dev/null 2>&1 &") sys.call("sh /usr/share/" .. name .. "/iptables.sh flush_ipset_reload > /dev/null 2>&1 &")
end end
end end
log("规则更新完毕...") log("规则更新完毕...")

View File

@ -3,8 +3,6 @@
------------------------------------------------ ------------------------------------------------
-- @author William Chan <root@williamchan.me> -- @author William Chan <root@williamchan.me>
------------------------------------------------ ------------------------------------------------
require 'nixio'
require 'luci.model.uci'
require 'luci.util' require 'luci.util'
require 'luci.jsonc' require 'luci.jsonc'
require 'luci.sys' require 'luci.sys'
@ -20,6 +18,7 @@ local split = api.split
local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify
local base64Decode = api.base64Decode local base64Decode = api.base64Decode
local uci = api.libuci local uci = api.libuci
local fs = api.fs
uci:revert(appname) uci:revert(appname)
local has_ss = api.is_finded("ss-redir") local has_ss = api.is_finded("ss-redir")
@ -1505,7 +1504,7 @@ local function update_node(manual)
end end
if arg[3] == "cron" then if arg[3] == "cron" then
if not nixio.fs.access("/var/lock/" .. appname .. ".lock") then if not fs.access("/var/lock/" .. appname .. ".lock") then
luci.sys.call("touch /tmp/lock/" .. appname .. "_cron.lock") luci.sys.call("touch /tmp/lock/" .. appname .. "_cron.lock")
end end
end end

View File

@ -1,5 +1,5 @@
diff --git a/luci-app-passwall/Makefile b/luci-app-passwall/Makefile diff --git a/luci-app-passwall/Makefile b/luci-app-passwall/Makefile
index 6397a77..07f4ea6 100644 index 12dc85f..5fff077 100644
--- a/luci-app-passwall/Makefile --- a/luci-app-passwall/Makefile
+++ b/luci-app-passwall/Makefile +++ b/luci-app-passwall/Makefile
@@ -144,7 +144,7 @@ config PACKAGE_$(PKG_NAME)_INCLUDE_V2ray_Geodata @@ -144,7 +144,7 @@ config PACKAGE_$(PKG_NAME)_INCLUDE_V2ray_Geodata
@ -20,10 +20,10 @@ index 6397a77..07f4ea6 100644
define Package/$(PKG_NAME)/postrm define Package/$(PKG_NAME)/postrm
diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua
index b56e7df..446186e 100644 index 99c620f..ba84fc9 100644
--- a/luci-app-passwall/luasrc/controller/passwall.lua --- a/luci-app-passwall/luasrc/controller/passwall.lua
+++ b/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua
@@ -282,7 +282,7 @@ function connect_status() @@ -283,7 +283,7 @@ function connect_status()
url = "-x socks5h://" .. socks_server .. " " .. url url = "-x socks5h://" .. socks_server .. " " .. url
end end
end end
@ -33,7 +33,7 @@ index b56e7df..446186e 100644
if code ~= 0 then if code ~= 0 then
local use_time = luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $2}'") local use_time = luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $2}'")
diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua
index 7c84b2a..1715ccc 100644 index ba3363e..7bd9fb3 100644
--- a/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua
+++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua
@@ -491,6 +491,12 @@ o:value("9.9.9.9", "9.9.9.9 (Quad9)") @@ -491,6 +491,12 @@ o:value("9.9.9.9", "9.9.9.9 (Quad9)")