mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-11-02 20:23:56 +08:00
update 2026-08-15 04:24:58
This commit is contained in:
1 parent
a59171002f
commit
c9ba9e3a54
1983 files changed
+619
-1523517
No files matched your search
@@ -6,8 +6,7 @@ module("luci.controller.passwall", package.seeall)
|
||||
local api = require "luci.passwall.api"
|
||||
local appname = api.appname -- not available
|
||||
local c_config = api.c_config -- not available
|
||||
local s_config = api.s_config -- not available
|
||||
local uci = api.uci -- in funtion index()
|
||||
local uci, uci_get, uci_set, uci_del, uci_foreach, uci_save = api.uci, api.uci_get_c, api.uci_set_c, api.uci_del_c, api.uci_foreach_c, api.uci_save_c
|
||||
local fs = api.fs
|
||||
local http = require "luci.http"
|
||||
local util = require "luci.util"
|
||||
@@ -23,15 +22,12 @@ function index()
|
||||
end
|
||||
local api = require "luci.passwall.api"
|
||||
local appname = api.appname -- global definitions not available
|
||||
local c_config = api.c_config -- not available
|
||||
local s_config = api.s_config -- not available
|
||||
local uci = api.uci -- in function index()
|
||||
local fs = api.fs
|
||||
entry({"admin", "services", appname}).dependent = true
|
||||
entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true
|
||||
entry({"admin", "services", appname, "hide"}, call("hide_menu")).leaf = true
|
||||
local e
|
||||
if uci:get(c_config, "@global[0]", "hide_from_luci") ~= "1" then
|
||||
if api.uci_get_c("@global[0]", "hide_from_luci") ~= "1" then
|
||||
e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), _("Pass Wall"), -1)
|
||||
else
|
||||
e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), nil, -1)
|
||||
@@ -199,10 +195,10 @@ function socks_autoswitch_add_node()
|
||||
local id = http.formvalue("id")
|
||||
local key = http.formvalue("key")
|
||||
if id and id ~= "" and key and key ~= "" then
|
||||
uci:set(c_config, id, "enable_autoswitch", "1")
|
||||
local new_list = uci:get(c_config, id, "autoswitch_backup_node") or {}
|
||||
uci_set(id, "enable_autoswitch", "1")
|
||||
local new_list = uci_get(id, "autoswitch_backup_node") or {}
|
||||
for i = #new_list, 1, -1 do
|
||||
if (uci:get(c_config, new_list[i], "remarks") or ""):find(key) then
|
||||
if (uci_get(new_list[i], "remarks") or ""):find(key) then
|
||||
table.remove(new_list, i)
|
||||
end
|
||||
end
|
||||
@@ -211,8 +207,8 @@ function socks_autoswitch_add_node()
|
||||
table.insert(new_list, e.id)
|
||||
end
|
||||
end
|
||||
uci:set_list(c_config, id, "autoswitch_backup_node", new_list)
|
||||
api.uci_save(uci, c_config)
|
||||
uci_set(id, "autoswitch_backup_node", new_list)
|
||||
uci_save()
|
||||
end
|
||||
http.redirect(api.url("socks_config", id))
|
||||
end
|
||||
@@ -221,15 +217,15 @@ function socks_autoswitch_remove_node()
|
||||
local id = http.formvalue("id")
|
||||
local key = http.formvalue("key")
|
||||
if id and id ~= "" and key and key ~= "" then
|
||||
uci:set(c_config, id, "enable_autoswitch", "1")
|
||||
local new_list = uci:get(c_config, id, "autoswitch_backup_node") or {}
|
||||
uci_set(id, "enable_autoswitch", "1")
|
||||
local new_list = uci_get(id, "autoswitch_backup_node") or {}
|
||||
for i = #new_list, 1, -1 do
|
||||
if (uci:get(c_config, new_list[i], "remarks") or ""):find(key) then
|
||||
if (uci_get(new_list[i], "remarks") or ""):find(key) then
|
||||
table.remove(new_list, i)
|
||||
end
|
||||
end
|
||||
uci:set_list(c_config, id, "autoswitch_backup_node", new_list)
|
||||
api.uci_save(uci, c_config)
|
||||
uci_set(id, "autoswitch_backup_node", new_list)
|
||||
uci_save()
|
||||
end
|
||||
http.redirect(api.url("socks_config", id))
|
||||
end
|
||||
@@ -272,25 +268,25 @@ function get_redir_log()
|
||||
end
|
||||
|
||||
if name == "default" then
|
||||
if proto == "UDP" and (uci:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" and not fs.access(path .. "/" .. proto .. ".log") then
|
||||
if proto == "UDP" and (uci_get("@global[0]", "udp_node") or "nil") == "tcp" and not fs.access(path .. "/" .. proto .. ".log") then
|
||||
proto = "TCP"
|
||||
end
|
||||
else
|
||||
local global_tcp = uci:get(appname, "@global[0]", "tcp_node") or "nil"
|
||||
local global_udp = uci:get(appname, "@global[0]", "udp_node") or "nil"
|
||||
local acl_tcp = uci:get(appname, name, "tcp_node") or "nil"
|
||||
local acl_udp = uci:get(appname, name, "udp_node") or "nil"
|
||||
local global_enabled = uci:get(appname, "@global[0]", "enabled") == "1"
|
||||
local global_tcp = uci_get("@global[0]", "tcp_node") or "nil"
|
||||
local global_udp = uci_get("@global[0]", "udp_node") or "nil"
|
||||
local acl_tcp = uci_get(name, "tcp_node") or "nil"
|
||||
local acl_udp = uci_get(name, "udp_node") or "nil"
|
||||
local global_enabled = uci_get("@global[0]", "enabled") == "1"
|
||||
if proto == "TCP" and acl_tcp == global_tcp and global_enabled then
|
||||
path = "/tmp/etc/passwall/acl/default"
|
||||
if uci:get(appname, "@global[0]", "log_tcp") ~= "1" then
|
||||
if uci_get("@global[0]", "log_tcp") ~= "1" then
|
||||
alert("The access control node is the same as the global node. Please enable global logging.")
|
||||
return
|
||||
end
|
||||
end
|
||||
if proto == "UDP" and acl_udp == global_udp and global_enabled then
|
||||
path = "/tmp/etc/passwall/acl/default"
|
||||
if uci:get(appname, "@global[0]", "log_udp") ~= "1" then
|
||||
if uci_get("@global[0]", "log_udp") ~= "1" then
|
||||
alert("The access control node is the same as the global node. Please enable global logging.")
|
||||
return
|
||||
end
|
||||
@@ -325,11 +321,11 @@ function get_chinadns_log()
|
||||
local flag = http.formvalue("flag")
|
||||
local path = "/tmp/etc/passwall/acl/" .. flag .. "/chinadns_ng.log"
|
||||
if flag ~= "default" then
|
||||
local global_tcp = uci:get(appname, "@global[0]", "tcp_node") or "nil"
|
||||
local acl_tcp = uci:get(appname, flag, "tcp_node") or "nil"
|
||||
if acl_tcp == global_tcp and uci:get(appname, "@global[0]", "enabled") == "1" then
|
||||
local global_tcp = uci_get("@global[0]", "tcp_node") or "nil"
|
||||
local acl_tcp = uci_get(flag, "tcp_node") or "nil"
|
||||
if acl_tcp == global_tcp and uci_get("@global[0]", "enabled") == "1" then
|
||||
path = "/tmp/etc/passwall/acl/default/chinadns_ng.log"
|
||||
if uci:get(appname, "@global[0]", "log_chinadns_ng") ~= "1" then
|
||||
if uci_get("@global[0]", "log_chinadns_ng") ~= "1" then
|
||||
http.write(string.format("<script>alert('%s');window.close();</script>", i18n.translate("The access control node is the same as the global node. Please enable global logging.")))
|
||||
return
|
||||
end
|
||||
@@ -356,7 +352,7 @@ end
|
||||
|
||||
function index_status()
|
||||
local e = {}
|
||||
local dns_shunt = uci:get(appname, "@global[0]", "dns_shunt") or "dnsmasq"
|
||||
local dns_shunt = uci_get("@global[0]", "dns_shunt") or "dnsmasq"
|
||||
if dns_shunt == "smartdns" then
|
||||
local port = api.get_cache_var("SMARTDNS_LOCAL_PORT") or 0
|
||||
e.dns_mode_status = (port ~= 0) and luci.sys.call(string.format("netstat -apn | grep ':%s ' >/dev/null", port)) == 0 or false
|
||||
@@ -373,7 +369,7 @@ function index_status()
|
||||
|
||||
e["tcp_node_status"] = luci.sys.call("/bin/busybox top -bn1 | grep -v 'grep' | grep '/tmp/etc/passwall/bin/' | grep 'default' | grep 'TCP' >/dev/null") == 0
|
||||
|
||||
if (uci:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" then
|
||||
if (uci_get("@global[0]", "udp_node") or "nil") == "tcp" then
|
||||
e["udp_node_status"] = e["tcp_node_status"]
|
||||
else
|
||||
e["udp_node_status"] = luci.sys.call("/bin/busybox top -bn1 | grep -v 'grep' | grep '/tmp/etc/passwall/bin/' | grep 'default' | grep 'UDP' >/dev/null") == 0
|
||||
@@ -393,7 +389,7 @@ function socks_status()
|
||||
local id = http.formvalue("id")
|
||||
e.index = index
|
||||
e.socks_status = luci.sys.call(string.format("/bin/busybox top -bn1 | grep -v -E 'grep|acl/|acl_' | grep '%s/bin/' | grep '%s' > /dev/null", appname, id)) == 0
|
||||
local use_http = uci:get(c_config, id, "http_port") or 0
|
||||
local use_http = uci_get(id, "http_port") or 0
|
||||
e.use_http = 0
|
||||
if tonumber(use_http) > 0 then
|
||||
e.use_http = 1
|
||||
@@ -407,10 +403,10 @@ function connect_status()
|
||||
e.use_time = ""
|
||||
local url = http.formvalue("url")
|
||||
local aliyun = string.find(url, "aliyun")
|
||||
local chn_list = uci:get(appname, "@global[0]", "chn_list") or "direct"
|
||||
local gfw_list = uci:get(appname, "@global[0]", "use_gfw_list") or "1"
|
||||
local proxy_mode = uci:get(appname, "@global[0]", "tcp_proxy_mode") or "proxy"
|
||||
local localhost_proxy = uci:get(appname, "@global[0]", "localhost_proxy") or "1"
|
||||
local chn_list = uci_get("@global[0]", "chn_list") or "direct"
|
||||
local gfw_list = uci_get("@global[0]", "use_gfw_list") or "1"
|
||||
local proxy_mode = uci_get("@global[0]", "tcp_proxy_mode") or "proxy"
|
||||
local localhost_proxy = uci_get("@global[0]", "localhost_proxy") or "1"
|
||||
local socks_server = (localhost_proxy == "0") and api.get_cache_var("GLOBAL_TCP_SOCKS_server") or ""
|
||||
url = "-w %{http_code}:%{time_pretransfer} " .. url
|
||||
if socks_server and socks_server ~= "" then
|
||||
@@ -485,9 +481,9 @@ function update_config()
|
||||
local data_t = jsonParse(data) or {}
|
||||
if next(data_t) then
|
||||
for k, v in pairs(data_t) do
|
||||
uci:set(c_config, id, k, v)
|
||||
uci_set(id, k, v)
|
||||
end
|
||||
api.uci_save(uci, c_config)
|
||||
uci_save()
|
||||
http_write_json_ok()
|
||||
return
|
||||
end
|
||||
@@ -503,16 +499,16 @@ function add_node()
|
||||
|
||||
local group = http.formvalue("group")
|
||||
if group and group ~= "default" then
|
||||
uci:set(c_config, uid, "group", group)
|
||||
uci_set(uid, "group", group)
|
||||
end
|
||||
|
||||
uci:set(c_config, uid, "type", "Socks")
|
||||
uci_set(uid, "type", "Socks")
|
||||
|
||||
if redirect == "1" then
|
||||
api.uci_save(uci, c_config)
|
||||
uci_save()
|
||||
http.redirect(api.url("node_config", uid))
|
||||
else
|
||||
api.uci_save(uci, c_config, true, true)
|
||||
uci_save(true, true)
|
||||
http_write_json({result = uid})
|
||||
end
|
||||
end
|
||||
@@ -520,22 +516,22 @@ end
|
||||
function set_node()
|
||||
local protocol = http.formvalue("protocol")
|
||||
local section = http.formvalue("section")
|
||||
uci:set(c_config, "@global[0]", protocol .. "_node", section)
|
||||
uci_set("@global[0]", protocol .. "_node", section)
|
||||
if protocol == "tcp" then
|
||||
local node_protocol = uci:get(c_config, section, "protocol")
|
||||
local node_protocol = uci_get(section, "protocol")
|
||||
if node_protocol == "_shunt" then
|
||||
local type = uci:get(c_config, section, "type")
|
||||
local dns_shunt = uci:get(c_config, "@global[0]", "dns_shunt")
|
||||
local type = uci_get(section, "type")
|
||||
local dns_shunt = uci_get("@global[0]", "dns_shunt")
|
||||
local dns_key = (dns_shunt == "smartdns") and "smartdns_dns_mode" or "dns_mode"
|
||||
local dns_mode = uci:get(c_config, "@global[0]", dns_key)
|
||||
local dns_mode = uci_get("@global[0]", dns_key)
|
||||
local new_dns_mode = (type == "Xray") and "xray" or "sing-box"
|
||||
if dns_mode ~= new_dns_mode then
|
||||
uci:set(c_config, "@global[0]", dns_key, new_dns_mode)
|
||||
uci:set(c_config, "@global[0]", "v2ray_dns_mode", "tcp")
|
||||
uci_set("@global[0]", dns_key, new_dns_mode)
|
||||
uci_set("@global[0]", "v2ray_dns_mode", "tcp")
|
||||
end
|
||||
end
|
||||
end
|
||||
api.uci_save(uci, c_config, true, true)
|
||||
uci_save(true, true)
|
||||
http.redirect(api.url("log"))
|
||||
end
|
||||
|
||||
@@ -543,57 +539,57 @@ function copy_node()
|
||||
local section = http.formvalue("section")
|
||||
local uid = api.gen_random_char()
|
||||
uci:section(c_config, "nodes", uid)
|
||||
for k, v in pairs(uci:get_all(c_config, section)) do
|
||||
for k, v in pairs(uci_get(section)) do
|
||||
if not k:match("^%.") and k ~= "group" then
|
||||
if k == "remarks" then v = (v or "") .. "(1)" end
|
||||
uci:set(c_config, uid, k, v)
|
||||
uci_set(uid, k, v)
|
||||
end
|
||||
end
|
||||
uci:set(c_config, uid, "add_mode", 1)
|
||||
api.uci_save(uci, c_config)
|
||||
uci_set(uid, "add_mode", 1)
|
||||
uci_save()
|
||||
http.redirect(api.url("node_config", uid))
|
||||
end
|
||||
|
||||
function clear_all_nodes()
|
||||
uci:set(c_config, '@global[0]', "enabled", "0")
|
||||
uci:set(c_config, '@global[0]', "socks_enabled", "0")
|
||||
uci:set(c_config, '@global_haproxy[0]', "balancing_enable", "0")
|
||||
uci:delete(c_config, '@global[0]', "tcp_node")
|
||||
uci:delete(c_config, '@global[0]', "udp_node")
|
||||
uci:foreach(c_config, "socks", function(t)
|
||||
uci:delete(c_config, t[".name"])
|
||||
uci:set_list(c_config, t[".name"], "autoswitch_backup_node", {})
|
||||
uci_set('@global[0]', "enabled", "0")
|
||||
uci_set('@global[0]', "socks_enabled", "0")
|
||||
uci_set('@global_haproxy[0]', "balancing_enable", "0")
|
||||
uci_del('@global[0]', "tcp_node")
|
||||
uci_del('@global[0]', "udp_node")
|
||||
uci_foreach("socks", function(t)
|
||||
uci_del(t[".name"])
|
||||
uci_set(t[".name"], "autoswitch_backup_node", {})
|
||||
end)
|
||||
uci:foreach(c_config, "haproxy_config", function(t)
|
||||
uci:delete(c_config, t[".name"])
|
||||
uci_foreach("haproxy_config", function(t)
|
||||
uci_del(t[".name"])
|
||||
end)
|
||||
uci:foreach(appname, "acl_rule", function(t)
|
||||
uci:delete(c_config, t[".name"], "tcp_node")
|
||||
uci:delete(c_config, t[".name"], "udp_node")
|
||||
uci_foreach("acl_rule", function(t)
|
||||
uci_del(t[".name"], "tcp_node")
|
||||
uci_del(t[".name"], "udp_node")
|
||||
end)
|
||||
uci:foreach(c_config, "nodes", function(node)
|
||||
uci:delete(c_config, node['.name'])
|
||||
uci_foreach("nodes", function(node)
|
||||
uci_del(node['.name'])
|
||||
end)
|
||||
uci:foreach(c_config, "subscribe_list", function(t)
|
||||
uci:delete(c_config, t[".name"], "md5")
|
||||
uci:delete(c_config, t[".name"], "chain_proxy")
|
||||
uci:delete(c_config, t[".name"], "preproxy_node")
|
||||
uci:delete(c_config, t[".name"], "to_node")
|
||||
uci_foreach("subscribe_list", function(t)
|
||||
uci_del(t[".name"], "md5")
|
||||
uci_del(t[".name"], "chain_proxy")
|
||||
uci_del(t[".name"], "preproxy_node")
|
||||
uci_del(t[".name"], "to_node")
|
||||
end)
|
||||
|
||||
api.uci_save(uci, c_config, true, true)
|
||||
uci_save(true, true)
|
||||
end
|
||||
|
||||
function delete_select_nodes()
|
||||
local ids = http.formvalue("ids")
|
||||
local redirect = http.formvalue("redirect")
|
||||
string.gsub(ids, '[^' .. "," .. ']+', function(w)
|
||||
uci:foreach(c_config, "socks", function(t)
|
||||
uci_foreach("socks", function(t)
|
||||
if t["node"] == w then
|
||||
uci:delete(c_config, t[".name"])
|
||||
uci_del(t[".name"])
|
||||
end
|
||||
local changed = false
|
||||
local auto_switch_node_list = uci:get(c_config, t[".name"], "autoswitch_backup_node") or {}
|
||||
local auto_switch_node_list = uci_get(t[".name"], "autoswitch_backup_node") or {}
|
||||
for i = #auto_switch_node_list, 1, -1 do
|
||||
if w == auto_switch_node_list[i] then
|
||||
table.remove(auto_switch_node_list, i)
|
||||
@@ -601,36 +597,36 @@ function delete_select_nodes()
|
||||
end
|
||||
end
|
||||
if changed then
|
||||
uci:set_list(c_config, t[".name"], "autoswitch_backup_node", auto_switch_node_list)
|
||||
uci_set(t[".name"], "autoswitch_backup_node", auto_switch_node_list)
|
||||
end
|
||||
end)
|
||||
if (uci:get(c_config, "@global[0]", "tcp_node") or "") == w then
|
||||
uci:delete(c_config, '@global[0]', "tcp_node")
|
||||
if (uci_get("@global[0]", "tcp_node") or "") == w then
|
||||
uci_del('@global[0]', "tcp_node")
|
||||
end
|
||||
if (uci:get(c_config, "@global[0]", "udp_node") or "") == w then
|
||||
uci:delete(c_config, '@global[0]', "udp_node")
|
||||
if (uci_get("@global[0]", "udp_node") or "") == w then
|
||||
uci_del('@global[0]', "udp_node")
|
||||
end
|
||||
uci:foreach(c_config, "haproxy_config", function(t)
|
||||
uci_foreach("haproxy_config", function(t)
|
||||
if t["lbss"] == w then
|
||||
uci:delete(c_config, t[".name"])
|
||||
uci_del(t[".name"])
|
||||
end
|
||||
end)
|
||||
uci:foreach(c_config, "acl_rule", function(t)
|
||||
uci_foreach("acl_rule", function(t)
|
||||
if t["tcp_node"] == w then
|
||||
uci:delete(c_config, t[".name"], "tcp_node")
|
||||
uci_del(t[".name"], "tcp_node")
|
||||
end
|
||||
if t["udp_node"] == w then
|
||||
uci:delete(c_config, t[".name"], "udp_node")
|
||||
uci_del(t[".name"], "udp_node")
|
||||
end
|
||||
end)
|
||||
uci:foreach(c_config, "nodes", function(t)
|
||||
uci_foreach("nodes", function(t)
|
||||
if t["preproxy_node"] == w then
|
||||
uci:delete(c_config, t[".name"], "preproxy_node")
|
||||
uci:delete(c_config, t[".name"], "chain_proxy")
|
||||
uci_del(t[".name"], "preproxy_node")
|
||||
uci_del(t[".name"], "chain_proxy")
|
||||
end
|
||||
if t["to_node"] == w then
|
||||
uci:delete(c_config, t[".name"], "to_node")
|
||||
uci:delete(c_config, t[".name"], "chain_proxy")
|
||||
uci_del(t[".name"], "to_node")
|
||||
uci_del(t[".name"], "chain_proxy")
|
||||
end
|
||||
local list_name = t["urltest_node"] and "urltest_node" or (t["balancing_node"] and "balancing_node")
|
||||
if list_name then
|
||||
@@ -646,48 +642,48 @@ function delete_select_nodes()
|
||||
end
|
||||
end
|
||||
if changed then
|
||||
uci:set_list(c_config, t[".name"], list_name, new_nodes)
|
||||
uci_set(t[".name"], list_name, new_nodes)
|
||||
end
|
||||
end
|
||||
end
|
||||
if t["fallback_node"] == w then
|
||||
uci:delete(c_config, t[".name"], "fallback_node")
|
||||
uci_del(t[".name"], "fallback_node")
|
||||
end
|
||||
end)
|
||||
uci:foreach(c_config, "subscribe_list", function(t)
|
||||
uci_foreach("subscribe_list", function(t)
|
||||
if t["preproxy_node"] == w then
|
||||
uci:delete(c_config, t[".name"], "preproxy_node")
|
||||
uci:delete(c_config, t[".name"], "chain_proxy")
|
||||
uci_del(t[".name"], "preproxy_node")
|
||||
uci_del(t[".name"], "chain_proxy")
|
||||
end
|
||||
if t["to_node"] == w then
|
||||
uci:delete(c_config, t[".name"], "to_node")
|
||||
uci:delete(c_config, t[".name"], "chain_proxy")
|
||||
uci_del(t[".name"], "to_node")
|
||||
uci_del(t[".name"], "chain_proxy")
|
||||
end
|
||||
end)
|
||||
if (uci:get(c_config, w, "add_mode") or "0") == "2" then
|
||||
local group = uci:get(c_config, w, "group") or ""
|
||||
if (uci_get(w, "add_mode") or "0") == "2" then
|
||||
local group = uci_get(w, "group") or ""
|
||||
if group ~= "" then
|
||||
uci:foreach(c_config, "subscribe_list", function(t)
|
||||
uci_foreach("subscribe_list", function(t)
|
||||
if t["remark"] == group then
|
||||
uci:delete(c_config, t[".name"], "md5")
|
||||
uci_del(t[".name"], "md5")
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
uci:delete(c_config, w)
|
||||
uci_del(w)
|
||||
end)
|
||||
if redirect == "1" then
|
||||
api.uci_save(uci, c_config)
|
||||
uci_save()
|
||||
http.redirect(api.url("node_list"))
|
||||
else
|
||||
api.uci_save(uci, c_config, true, true)
|
||||
uci_save(true, true)
|
||||
end
|
||||
end
|
||||
|
||||
function get_node()
|
||||
local id = http.formvalue("id")
|
||||
local result = {}
|
||||
local show_node_info = uci:get(c_config, "@global_other[0]", "show_node_info") or "0"
|
||||
local show_node_info = uci_get("@global_other[0]", "show_node_info") or "0"
|
||||
|
||||
local function add_is_ipv6_key(o)
|
||||
if o and o.address and show_node_info == "1" then
|
||||
@@ -700,12 +696,12 @@ function get_node()
|
||||
end
|
||||
|
||||
if id then
|
||||
result = uci:get_all(c_config, id)
|
||||
result = uci_get(id)
|
||||
add_is_ipv6_key(result)
|
||||
else
|
||||
local default_nodes = {}
|
||||
local other_nodes = {}
|
||||
uci:foreach(c_config, "nodes", function(t)
|
||||
uci_foreach("nodes", function(t)
|
||||
add_is_ipv6_key(t)
|
||||
if not t.group or t.group == "" then
|
||||
default_nodes[#default_nodes + 1] = t
|
||||
@@ -760,8 +756,8 @@ function rollback_rules()
|
||||
return
|
||||
end
|
||||
local bak_dir = "/tmp/bak_v2ray/"
|
||||
local geo_dir = (uci:get(c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/")
|
||||
local geo2rule = uci:get(c_config, "@global_rules[0]", "geo2rule") or "0"
|
||||
local geo_dir = (uci_get("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/")
|
||||
local geo2rule = uci_get("@global_rules[0]", "geo2rule") or "0"
|
||||
fs.move(bak_dir .. arg_type .. ".dat", geo_dir .. arg_type .. ".dat")
|
||||
fs.rmdir(bak_dir)
|
||||
if geo2rule == "1" and rules ~= "" then
|
||||
@@ -777,9 +773,9 @@ function server_update_config()
|
||||
local data_t = jsonParse(data) or {}
|
||||
if next(data_t) then
|
||||
for k, v in pairs(data_t) do
|
||||
uci:set(c_config .. "_server", id, k, v)
|
||||
api.uci_set_s(id, k, v)
|
||||
end
|
||||
api.uci_save(uci, c_config .. "_server")
|
||||
api.uci_save_s()
|
||||
http_write_json_ok()
|
||||
return
|
||||
end
|
||||
@@ -957,7 +953,7 @@ function geo_view()
|
||||
end
|
||||
local function get_rules(str, type)
|
||||
local rules_id = {}
|
||||
uci:foreach(c_config, "shunt_rules", function(s)
|
||||
uci_foreach("shunt_rules", function(s)
|
||||
local list
|
||||
if type == "geoip" then list = s.ip_list else list = s.domain_list end
|
||||
for line in string.gmatch((list or ""), "[^\r\n]+") do
|
||||
@@ -974,7 +970,7 @@ function geo_view()
|
||||
end)
|
||||
return rules_id
|
||||
end
|
||||
local geo_dir = (uci:get(c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
|
||||
local geo_dir = (uci_get("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
|
||||
local geosite_path = geo_dir .. "/geosite.dat"
|
||||
local geoip_path = geo_dir .. "/geoip.dat"
|
||||
local geo_type, file_path, cmd
|
||||
@@ -1091,8 +1087,8 @@ function flush_set()
|
||||
local redirect = http.formvalue("redirect") or "0"
|
||||
local reload = http.formvalue("reload") or "0"
|
||||
if reload == "1" then
|
||||
uci:set(c_config, '@global[0]', "flush_set", "1")
|
||||
api.uci_save(uci, c_config, true, true)
|
||||
uci_set('@global[0]', "flush_set", "1")
|
||||
uci_save(true, true)
|
||||
else
|
||||
api.sh_uci_set(c_config, "@global[0]", "flush_set", "1", true)
|
||||
end
|
||||
@@ -1103,17 +1099,17 @@ end
|
||||
|
||||
function fetch_certsha256()
|
||||
local id = http.formvalue("id") or ""
|
||||
local address = (id ~= "") and uci:get(c_config, id, "address") or ""
|
||||
local port = (id ~= "") and uci:get(c_config, id, "port") or 0
|
||||
local sni = (id ~= "") and uci:get(c_config, id, "tls_serverName") or ""
|
||||
local address = (id ~= "") and uci_get(id, "address") or ""
|
||||
local port = (id ~= "") and uci_get(id, "port") or 0
|
||||
local sni = (id ~= "") and uci_get(id, "tls_serverName") or ""
|
||||
sni = (sni ~= "") and sni or address
|
||||
local protocol = uci:get(appname, id, "protocol")
|
||||
local protocol = uci_get(id, "protocol")
|
||||
local h3, timeout = false, 10
|
||||
if protocol == "hysteria2" then
|
||||
h3 = true
|
||||
timeout = 60
|
||||
if port == 0 then
|
||||
local hop = uci:get(appname, id, "hysteria2_hop") or "0"
|
||||
local hop = uci_get(id, "hysteria2_hop") or "0"
|
||||
port = tonumber(hop:match("^%s*(%d+)"))
|
||||
end
|
||||
end
|
||||
@@ -1130,11 +1126,11 @@ function get_shunt_rules()
|
||||
local result = {}
|
||||
|
||||
if id then
|
||||
result = uci:get_all(c_config, id)
|
||||
result = uci_get(id)
|
||||
else
|
||||
local default_items = {}
|
||||
local other_items = {}
|
||||
uci:foreach(c_config, "shunt_rules", function(t)
|
||||
uci_foreach("shunt_rules", function(t)
|
||||
if not t.group or t.group == "" then
|
||||
default_items[#default_items + 1] = t
|
||||
else
|
||||
@@ -1153,7 +1149,7 @@ function add_shunt_rule()
|
||||
|
||||
local uid = add_name
|
||||
if add_name then
|
||||
local has = uci:get(c_config, uid)
|
||||
local has = uci_get(uid)
|
||||
if has then
|
||||
http_write_json_error({ message = i18n.translate("This ID already exists.") })
|
||||
return
|
||||
@@ -1165,14 +1161,14 @@ function add_shunt_rule()
|
||||
|
||||
local group = http.formvalue("group")
|
||||
if group and group ~= "default" then
|
||||
uci:set(c_config, uid, "group", group)
|
||||
uci_set(uid, "group", group)
|
||||
end
|
||||
|
||||
if redirect == "1" then
|
||||
api.uci_save(uci, c_config)
|
||||
uci_save()
|
||||
http.redirect(api.url("shunt_rules", uid))
|
||||
else
|
||||
api.uci_save(uci, c_config)
|
||||
uci_save()
|
||||
http_write_json_ok({uid = uid, redirect_url = api.url("shunt_rules", uid)})
|
||||
end
|
||||
end
|
||||
@@ -1181,17 +1177,17 @@ function delete_select_shunt_rules()
|
||||
local ids = http.formvalue("ids")
|
||||
local redirect = http.formvalue("redirect")
|
||||
string.gsub(ids, '[^' .. "," .. ']+', function(w)
|
||||
uci:foreach(c_config, "nodes", function(s)
|
||||
uci_foreach("nodes", function(s)
|
||||
if s["protocol"] and s["protocol"] == "_shunt" then
|
||||
uci:delete(c_config, s[".name"], w)
|
||||
uci_del(s[".name"], w)
|
||||
end
|
||||
end)
|
||||
uci:delete(c_config, w)
|
||||
uci_del(w)
|
||||
end)
|
||||
if redirect == "1" then
|
||||
api.uci_save(uci, c_config)
|
||||
uci_save()
|
||||
http.redirect(api.url("rule"))
|
||||
else
|
||||
api.uci_save(uci, c_config, true, true)
|
||||
uci_save(true, true)
|
||||
end
|
||||
end
|
||||
@@ -700,7 +700,7 @@ function s2.remove(e, t)
|
||||
m:foreach("nodes", function(s)
|
||||
local list_name = s["urltest_node"] and "urltest_node" or (s["balancing_node"] and "balancing_node")
|
||||
if list_name then
|
||||
local nodes = m.uci:get_list(appname, s[".name"], list_name)
|
||||
local nodes = m.uci:get_list(api.c_config, s[".name"], list_name)
|
||||
if nodes then
|
||||
local changed = false
|
||||
local new_nodes = {}
|
||||
@@ -712,7 +712,7 @@ function s2.remove(e, t)
|
||||
end
|
||||
end
|
||||
if changed then
|
||||
m.uci:set_list(appname, s[".name"], list_name, new_nodes)
|
||||
api.uci_set_c(s[".name"], list_name, new_nodes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -319,7 +319,7 @@ end
|
||||
|
||||
m:appendTemplate("/rule_list/js")
|
||||
|
||||
local geo_dir = (uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
|
||||
local geo_dir = (api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
|
||||
local geosite_path = geo_dir .. "/geosite.dat"
|
||||
local geoip_path = geo_dir .. "/geoip.dat"
|
||||
if api.finded_com("geoview") and fs.access(geosite_path) and fs.access(geoip_path) then
|
||||
|
||||
@@ -19,9 +19,10 @@ OPENWRT_ARCH = nil
|
||||
DISTRIB_ARCH = nil
|
||||
OPENWRT_BOARD = nil
|
||||
|
||||
CACHE_PATH = "/tmp/etc/" .. appname .. "_tmp"
|
||||
LOG_FILE = "/tmp/log/" .. appname .. ".log"
|
||||
TMP_PATH = "/tmp/etc/" .. appname
|
||||
LOCK_PREFIX = "/tmp/lock/passwall"
|
||||
LOG_FILE = "/tmp/log/passwall.log"
|
||||
TMP_PATH = "/tmp/etc/passwall"
|
||||
CACHE_PATH = TMP_PATH .. "_tmp"
|
||||
TMP_IFACE_PATH = TMP_PATH .. "/iface"
|
||||
|
||||
function log(...)
|
||||
@@ -37,7 +38,85 @@ function is_old_uci()
|
||||
return sys.call("grep -E 'require[ \t]*\"uci\"' /usr/lib/lua/luci/model/uci.lua >/dev/null 2>&1") == 0
|
||||
end
|
||||
|
||||
function uci_del(config, section, option)
|
||||
if option then
|
||||
return uci:delete(config, section, option)
|
||||
else
|
||||
return uci:delete(config, section)
|
||||
end
|
||||
end
|
||||
|
||||
function uci_get(config, section, option)
|
||||
if not section then
|
||||
return uci:get_all(config)
|
||||
elseif option then
|
||||
return uci:get(config, section, option) or nil
|
||||
else
|
||||
return uci:get_all(config, section)
|
||||
end
|
||||
end
|
||||
|
||||
function uci_set(config, section, option, value)
|
||||
if type(value) == "number" then
|
||||
value = value .. ""
|
||||
end
|
||||
if #value > 0 then
|
||||
if option then
|
||||
if type(value) == "table" then
|
||||
return uci:set_list(config, section, option, value)
|
||||
else
|
||||
return uci:set(config, section, option, value)
|
||||
end
|
||||
else
|
||||
return uci:set(config, section, value)
|
||||
end
|
||||
else
|
||||
return uci_del(config, section, option)
|
||||
end
|
||||
end
|
||||
|
||||
function uci_del_c(section, option)
|
||||
return uci_del(c_config, section, option)
|
||||
end
|
||||
|
||||
function uci_foreach_c(stype, func)
|
||||
uci:foreach(c_config, stype, func)
|
||||
end
|
||||
|
||||
function uci_get_c(section, option)
|
||||
return uci_get(c_config, section, option)
|
||||
end
|
||||
|
||||
function uci_set_c(section, option, value)
|
||||
return uci_set(c_config, section, option, value)
|
||||
end
|
||||
|
||||
function uci_save_c(commit, apply)
|
||||
return uci_save(uci, c_config, commit, apply)
|
||||
end
|
||||
|
||||
function uci_del_s(section, option)
|
||||
return uci_del(s_config, section, option)
|
||||
end
|
||||
|
||||
function uci_foreach_s(stype, func)
|
||||
uci:foreach(s_config, stype, func)
|
||||
end
|
||||
|
||||
function uci_get_s(section, option)
|
||||
return uci_get(s_config, section, option)
|
||||
end
|
||||
|
||||
function uci_set_s(section, option, value)
|
||||
return uci_set(s_config, section, option, value)
|
||||
end
|
||||
|
||||
function uci_save_s(commit, apply)
|
||||
return uci_save(uci, s_config, commit, apply)
|
||||
end
|
||||
|
||||
function uci_save(cursor, config, commit, apply)
|
||||
if not cursor then cursor = uci end
|
||||
if is_old_uci() then
|
||||
cursor:save(config)
|
||||
if commit then
|
||||
@@ -198,7 +277,7 @@ end
|
||||
|
||||
function curl_direct(url, file, args)
|
||||
--直连访问
|
||||
local chn_list = uci:get(appname, "@global[0]", "chn_list") or "direct"
|
||||
local chn_list = uci_get_c("@global[0]", "chn_list") or "direct"
|
||||
local Dns = (chn_list == "proxy") and "1.1.1.1" or "223.5.5.5"
|
||||
if not args then args = {} end
|
||||
local tmp_args = clone(args)
|
||||
@@ -213,7 +292,7 @@ function curl_direct(url, file, args)
|
||||
end
|
||||
|
||||
function curl_auto(url, file, args)
|
||||
local localhost_proxy = uci:get(c_config, "@global[0]", "localhost_proxy") or "1"
|
||||
local localhost_proxy = uci_get_c("@global[0]", "localhost_proxy") or "1"
|
||||
if localhost_proxy == "1" then
|
||||
return curl_base(url, file, args) -- 当路由器本机开启代理时,采用passwall规则进行访问
|
||||
else
|
||||
@@ -481,7 +560,7 @@ function get_domain_from_url(url)
|
||||
end
|
||||
|
||||
function get_valid_nodes()
|
||||
local show_node_info = uci:get(c_config, "@global_other[0]", "show_node_info") or "0"
|
||||
local show_node_info = uci_get_c("@global_other[0]", "show_node_info") or "0"
|
||||
local nodes = {}
|
||||
local default_nodes = {}
|
||||
local other_nodes = {}
|
||||
@@ -666,7 +745,7 @@ function chmod_755(file)
|
||||
end
|
||||
|
||||
function get_customed_path(e)
|
||||
return uci:get(c_config, "@global_app[0]", e .. "_file")
|
||||
return uci_get_c("@global_app[0]", e .. "_file")
|
||||
end
|
||||
|
||||
function finded_com(e)
|
||||
@@ -725,7 +804,7 @@ end
|
||||
function get_app_path(app_name)
|
||||
if com[app_name] then
|
||||
local def_path = com[app_name].default_path
|
||||
local path = uci:get(c_config, "@global_app[0]", app_name:gsub("%-","_") .. "_file")
|
||||
local path = uci_get_c("@global_app[0]", app_name:gsub("%-","_") .. "_file")
|
||||
path = path and (#path>0 and path or def_path) or def_path
|
||||
return path
|
||||
end
|
||||
@@ -1003,7 +1082,7 @@ local default_file_tree = {
|
||||
}
|
||||
|
||||
local function get_api_json(url)
|
||||
local gh_proxy = uci:get(c_config, "@global_app[0]", "github_proxy") or "0"
|
||||
local gh_proxy = uci_get_c("@global_app[0]", "github_proxy") or "0"
|
||||
local return_code, content
|
||||
if gh_proxy == "1" then
|
||||
url = "https://gh-proxy.org/" .. url
|
||||
@@ -1127,7 +1206,7 @@ function to_download(app_name, url, size)
|
||||
local _curl_args = clone(curl_args)
|
||||
table.insert(_curl_args, "--speed-limit 51200 --speed-time 15 --max-time 300")
|
||||
|
||||
local gh_proxy = uci:get(c_config, "@global_app[0]", "github_proxy") or "0"
|
||||
local gh_proxy = uci_get_c("@global_app[0]", "github_proxy") or "0"
|
||||
local return_code, result
|
||||
if gh_proxy == "1" then
|
||||
url = "https://gh-proxy.org/" .. url
|
||||
@@ -1285,7 +1364,7 @@ end
|
||||
function to_check_self()
|
||||
local url = "https://raw.githubusercontent.com/Openwrt-Passwall/openwrt-passwall/main/luci-app-passwall/Makefile"
|
||||
local tmp_file = "/tmp/passwall_makefile"
|
||||
local gh_proxy = uci:get(c_config, "@global_app[0]", "github_proxy") or "0"
|
||||
local gh_proxy = uci_get_c("@global_app[0]", "github_proxy") or "0"
|
||||
local return_code, result
|
||||
if gh_proxy == "1" then
|
||||
url = "https://gh-proxy.org/" .. url
|
||||
@@ -1741,7 +1820,7 @@ end
|
||||
function get_socks_backup_nodes(id)
|
||||
id = trim(id)
|
||||
if id == "" then return "" end
|
||||
local socks = uci:get_all(c_config, id)
|
||||
local socks = uci_get_c(id)
|
||||
local nodes
|
||||
if socks.backup_node_add_mode and socks.backup_node_add_mode == "batch" then
|
||||
local node = {}
|
||||
@@ -1762,7 +1841,7 @@ function get_socks_backup_nodes(id)
|
||||
end
|
||||
|
||||
function get_core(field, candidates)
|
||||
local v = uci:get(c_config, "@global_subscribe[0]", field)
|
||||
local v = uci_get_c("@global_subscribe[0]", field)
|
||||
if v and v ~= "" then
|
||||
for _, c in ipairs(candidates) do
|
||||
if c[2] == v and c[1] then
|
||||
|
||||
@@ -84,7 +84,7 @@ local function gen_include()
|
||||
end
|
||||
|
||||
local function start()
|
||||
local enabled = tonumber(uci:get(CONFIG, "@global[0]", "enable") or 0)
|
||||
local enabled = tonumber(api.uci_get_s("@global[0]", "enable") or 0)
|
||||
if enabled == nil or enabled == 0 then
|
||||
return
|
||||
end
|
||||
@@ -102,7 +102,7 @@ local function start()
|
||||
nft_file:write('flush chain inet fw4 PSW-SERVER\n')
|
||||
nft_file:write('insert rule inet fw4 input position 0 jump PSW-SERVER comment "PSW-SERVER"\n')
|
||||
end
|
||||
uci:foreach(CONFIG, "server", function(server)
|
||||
api.uci_foreach_s("server", function(server)
|
||||
local id = server[".name"]
|
||||
local enable = server.enable
|
||||
if enable and tonumber(enable) == 1 then
|
||||
@@ -125,7 +125,7 @@ local function start()
|
||||
if server.auth and server.auth == "1" then
|
||||
local user = nil
|
||||
if server.user then
|
||||
user = uci:get_all("passwall_server", server.user)
|
||||
user = api.uci_get_s(server.user)
|
||||
end
|
||||
local username = user and user.username or ""
|
||||
local password = user and user.password or ""
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
module("luci.passwall.util_hysteria2", package.seeall)
|
||||
local api = require "luci.passwall.api"
|
||||
local uci = api.uci
|
||||
local jsonc = api.jsonc
|
||||
|
||||
function gen_config_server(node)
|
||||
local users = node.users or {}
|
||||
local users = nil
|
||||
if node.users and #node.users > 0 then
|
||||
users = {}
|
||||
for i, v in ipairs(node.users) do
|
||||
local user = uci:get_all(api.s_config, v) or {}
|
||||
local user = api.uci_get_s(v) or {}
|
||||
if user[".type"] == "user" then
|
||||
users[user.username] = user.password
|
||||
end
|
||||
@@ -74,7 +72,7 @@ function gen_config(var)
|
||||
print("node 不能为空")
|
||||
return
|
||||
end
|
||||
local node = uci:get_all(api.c_config, node_id)
|
||||
local node = api.uci_get_c(node_id)
|
||||
local local_tcp_redir_port = var["local_tcp_redir_port"]
|
||||
local local_udp_redir_port = var["local_udp_redir_port"]
|
||||
local local_socks_address = var["local_socks_address"] or "0.0.0.0"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
module("luci.passwall.util_naiveproxy", package.seeall)
|
||||
local api = require "luci.passwall.api"
|
||||
local uci = api.uci
|
||||
local jsonc = api.jsonc
|
||||
|
||||
function gen_config(var)
|
||||
@@ -9,7 +8,7 @@ function gen_config(var)
|
||||
print("node 不能为空")
|
||||
return
|
||||
end
|
||||
local node = uci:get_all(api.c_config, node_id)
|
||||
local node = api.uci_get_c(node_id)
|
||||
local run_type = var["run_type"]
|
||||
local local_addr = var["local_addr"]
|
||||
local local_port = var["local_port"]
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
module("luci.passwall.util_shadowsocks", package.seeall)
|
||||
local api = require "luci.passwall.api"
|
||||
local uci = api.uci
|
||||
local jsonc = api.jsonc
|
||||
|
||||
function gen_config_server(node)
|
||||
local user = nil
|
||||
if node.user then
|
||||
user = uci:get_all(api.s_config, node.user)
|
||||
user = api.uci_get_s(node.user)
|
||||
end
|
||||
local config = {}
|
||||
config.server_port = tonumber(node.port)
|
||||
@@ -40,7 +39,7 @@ function gen_config(var)
|
||||
print("node 不能为空")
|
||||
return
|
||||
end
|
||||
local node = uci:get_all(api.c_config, node_id)
|
||||
local node = api.uci_get_c(node_id)
|
||||
local server_host = var["server_host"] or (node.address or ""):lower()
|
||||
local server_port = var["server_port"] or node.port
|
||||
local local_addr = var["local_addr"]
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
module("luci.passwall.util_sing-box", package.seeall)
|
||||
local api = require "luci.passwall.api"
|
||||
local uci = api.uci
|
||||
local sys = api.sys
|
||||
local jsonc = api.jsonc
|
||||
local appname = api.appname
|
||||
local fs = api.fs
|
||||
local CACHE_PATH = api.CACHE_PATH
|
||||
local ech_domain = {}
|
||||
|
||||
local local_version = api.get_app_version("sing-box"):match("[^v]+")
|
||||
@@ -23,7 +22,7 @@ local GEO_VAR = {
|
||||
IP_PATH = nil,
|
||||
SITE_TAGS = {},
|
||||
IP_TAGS = {},
|
||||
TO_SRS_PATH = "/tmp/etc/" .. appname .."_tmp/singbox_srss/"
|
||||
TO_SRS_PATH = CACHE_PATH .."/singbox_srss/"
|
||||
}
|
||||
|
||||
function check_geoview()
|
||||
@@ -34,7 +33,7 @@ function check_geoview()
|
||||
if GEO_VAR.OK == 0 then
|
||||
api.log("!!!注意:缺少 Geoview 组件或版本过低,Sing-Box 分流无法启用!")
|
||||
else
|
||||
GEO_VAR.DIR = GEO_VAR.DIR or (uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
|
||||
GEO_VAR.DIR = GEO_VAR.DIR or (api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
|
||||
GEO_VAR.SITE_PATH = GEO_VAR.SITE_PATH or (GEO_VAR.DIR .. "/geosite.dat")
|
||||
GEO_VAR.IP_PATH = GEO_VAR.IP_PATH or (GEO_VAR.DIR .. "/geoip.dat")
|
||||
if not fs.access(GEO_VAR.TO_SRS_PATH) then
|
||||
@@ -120,8 +119,7 @@ function gen_outbound(flag, node, tag, proxy_table)
|
||||
config_file = string.format("%s_%s_%s_%s.json", flag, tag, node_id, new_port)
|
||||
end
|
||||
if run_socks_instance then
|
||||
sys.call(string.format('/usr/share/%s/app.sh run_socks "%s"> /dev/null',
|
||||
appname,
|
||||
sys.call(string.format('/usr/share/passwall/app.sh run_socks "%s"> /dev/null',
|
||||
string.format("flag=%s node=%s bind=%s socks_port=%s config_file=%s relay_port=%s",
|
||||
new_port, --flag
|
||||
node_id, --node
|
||||
@@ -771,7 +769,7 @@ function gen_config_server(node)
|
||||
if node.users and #node.users > 0 then
|
||||
users = {}
|
||||
for i, v in ipairs(node.users) do
|
||||
local user = uci:get_all(api.s_config, v) or {}
|
||||
local user = api.uci_get_s(v) or {}
|
||||
if user[".type"] == "user" then
|
||||
local u = {}
|
||||
if node.protocol == "mixed" or node.protocol == "socks" or node.protocol == "http" or node.protocol == "naive" then
|
||||
@@ -1008,7 +1006,7 @@ function gen_config_server(node)
|
||||
}
|
||||
sys.call(string.format("mkdir -p %s && touch %s/%s", api.TMP_IFACE_PATH, api.TMP_IFACE_PATH, node.outbound_node_iface))
|
||||
else
|
||||
local outbound_node_t = uci:get_all(api.c_config, node.outbound_node)
|
||||
local outbound_node_t = api.uci_get_c(node.outbound_node)
|
||||
if node.outbound_node == "_socks" or node.outbound_node == "_http" then
|
||||
outbound_node_t = {
|
||||
type = node.type,
|
||||
@@ -1104,7 +1102,7 @@ function gen_config(var)
|
||||
local rule_set_table = {}
|
||||
local COMMON = {}
|
||||
|
||||
local singbox_settings = uci:get_all(api.c_config, "@global_singbox[0]") or {}
|
||||
local singbox_settings = api.uci_get_c("@global_singbox[0]") or {}
|
||||
|
||||
local route = {
|
||||
rules = {}
|
||||
@@ -1166,7 +1164,7 @@ function gen_config(var)
|
||||
end
|
||||
|
||||
if node_id then
|
||||
local node = uci:get_all(api.c_config, node_id)
|
||||
local node = api.uci_get_c(node_id)
|
||||
if node then
|
||||
if server_host and server_port then
|
||||
node.address = server_host
|
||||
@@ -1256,7 +1254,7 @@ function gen_config(var)
|
||||
|
||||
function get_node_by_id(node_id)
|
||||
if not node_id or node_id == "" or node_id == "nil" then return nil end
|
||||
local section = uci:get_all(api.c_config, node_id) or {}
|
||||
local section = api.uci_get_c(node_id) or {}
|
||||
if section[".type"] == "socks" then
|
||||
local result = {
|
||||
[".name"] = node_id,
|
||||
@@ -1533,7 +1531,7 @@ function gen_config(var)
|
||||
|
||||
--shunt rule
|
||||
local function foreach_shunt_rule(callback)
|
||||
uci:foreach(api.c_config, "shunt_rules", callback)
|
||||
api.uci_foreach_c("shunt_rules", callback)
|
||||
|
||||
if use_gfw_list ~= "1" or chn_list ~= "0" then return end
|
||||
|
||||
@@ -1559,7 +1557,7 @@ function gen_config(var)
|
||||
|
||||
local bin = api.finded_com("geoview")
|
||||
if bin then
|
||||
local geo_file = (uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") .. "/geosite.dat"
|
||||
local geo_file = (api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") .. "/geosite.dat"
|
||||
if luci.sys.call('"' .. bin .. '" -type geosite -input "' .. geo_file .. '" | grep -q "^GFW$"') == 0 then
|
||||
domain_list = (domain_list == "") and "geosite:gfw" or domain_list .. "\ngeosite:gfw"
|
||||
end
|
||||
@@ -1975,7 +1973,7 @@ function gen_config(var)
|
||||
end
|
||||
end
|
||||
dns.final = default_dns_flag
|
||||
dns.strategy = default_dns_flag == "remote" and remote_strategy or direct_strategy
|
||||
dns.strategy = "prefer_ipv6"
|
||||
|
||||
--按分流顺序DNS
|
||||
if dns_domain_rules and #dns_domain_rules > 0 then
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
module("luci.passwall.util_xray", package.seeall)
|
||||
local api = require "luci.passwall.api"
|
||||
local uci = api.uci
|
||||
local sys = api.sys
|
||||
local jsonc = api.jsonc
|
||||
local appname = api.appname
|
||||
local fs = api.fs
|
||||
|
||||
local GLOBAL = {
|
||||
@@ -17,7 +15,7 @@ local xray_version = api.get_app_version("xray")
|
||||
local xray_min_version = "26.3.27"
|
||||
|
||||
local function get_domain_excluded()
|
||||
local path = string.format("/usr/share/%s/rules/domains_excluded", appname)
|
||||
local path = "/usr/share/passwall/domains_excluded"
|
||||
local content = fs.readfile(path)
|
||||
if not content then return nil end
|
||||
local hosts = {}
|
||||
@@ -68,8 +66,7 @@ function gen_outbound(flag, node, tag, proxy_table)
|
||||
config_file = string.format("%s_%s_%s_%s.json", flag, tag, node_id, new_port)
|
||||
end
|
||||
if run_socks_instance then
|
||||
sys.call(string.format('/usr/share/%s/app.sh run_socks "%s"> /dev/null',
|
||||
appname,
|
||||
sys.call(string.format('/usr/share/passwall/app.sh run_socks "%s"> /dev/null',
|
||||
string.format("flag=%s node=%s bind=%s socks_port=%s config_file=%s relay_port=%s",
|
||||
new_port, --flag
|
||||
node_id, --node
|
||||
@@ -493,7 +490,7 @@ function gen_config_server(node)
|
||||
if node.users and #node.users > 0 then
|
||||
users = {}
|
||||
for i, v in ipairs(node.users) do
|
||||
local user = uci:get_all(api.s_config, v) or {}
|
||||
local user = api.uci_get_s(v) or {}
|
||||
if user[".type"] == "user" then
|
||||
local u = {}
|
||||
if node.protocol == "socks" or node.protocol == "http" then
|
||||
@@ -625,7 +622,7 @@ function gen_config_server(node)
|
||||
}
|
||||
sys.call(string.format("mkdir -p %s && touch %s/%s", api.TMP_IFACE_PATH, api.TMP_IFACE_PATH, node.outbound_node_iface))
|
||||
else
|
||||
local outbound_node_t = uci:get_all(api.c_config, node.outbound_node)
|
||||
local outbound_node_t = api.uci_get_c(node.outbound_node)
|
||||
if node.outbound_node == "_socks" or node.outbound_node == "_http" then
|
||||
outbound_node_t = {
|
||||
type = node.type,
|
||||
@@ -901,7 +898,7 @@ function gen_config(var)
|
||||
local outbounds = {}
|
||||
local COMMON = {}
|
||||
|
||||
local xray_settings = uci:get_all(api.c_config, "@global_xray[0]") or {}
|
||||
local xray_settings = api.uci_get_c("@global_xray[0]") or {}
|
||||
|
||||
if xray_settings.fragment == "1" then
|
||||
local lengths, delays = {}, {}
|
||||
@@ -926,7 +923,7 @@ function gen_config(var)
|
||||
|
||||
if xray_settings.noise == "1" then
|
||||
local noises = {}
|
||||
uci:foreach(api.c_config, "xray_noise_packets", function(n)
|
||||
api.uci_foreach_c("xray_noise_packets", function(n)
|
||||
if n.enabled == "1" then
|
||||
local noise = {
|
||||
rand = (n.type == "rand" and n.packet) and (n.packet:find("-", 1, true) and n.packet or tonumber(n.packet)) or nil,
|
||||
@@ -944,7 +941,7 @@ function gen_config(var)
|
||||
end
|
||||
|
||||
if node_id then
|
||||
local node = uci:get_all(api.c_config, node_id)
|
||||
local node = api.uci_get_c(node_id)
|
||||
local balancers = {}
|
||||
local rules = {}
|
||||
if node then
|
||||
@@ -1001,7 +998,7 @@ function gen_config(var)
|
||||
|
||||
function get_node_by_id(node_id)
|
||||
if not node_id or node_id == "" or node_id == "nil" then return nil end
|
||||
local section = uci:get_all(api.c_config, node_id) or {}
|
||||
local section = api.uci_get_c(node_id) or {}
|
||||
if section[".type"] == "socks" then
|
||||
local result = {
|
||||
[".name"] = node_id,
|
||||
@@ -1374,7 +1371,7 @@ function gen_config(var)
|
||||
|
||||
--shunt rule
|
||||
local function foreach_shunt_rule(callback)
|
||||
uci:foreach(api.c_config, "shunt_rules", callback)
|
||||
api.uci_foreach_c("shunt_rules", callback)
|
||||
|
||||
if use_gfw_list ~= "1" or chn_list ~= "0" then return end
|
||||
|
||||
@@ -1400,7 +1397,7 @@ function gen_config(var)
|
||||
|
||||
local bin = api.finded_com("geoview")
|
||||
if bin then
|
||||
local geo_file = (uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") .. "/geosite.dat"
|
||||
local geo_file = (api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") .. "/geosite.dat"
|
||||
if luci.sys.call('"' .. bin .. '" -type geosite -input "' .. geo_file .. '" | grep -q "^GFW$"') == 0 then
|
||||
domain_list = (domain_list == "") and "geosite:gfw" or domain_list .. "\ngeosite:gfw"
|
||||
end
|
||||
@@ -1788,7 +1785,7 @@ function gen_config(var)
|
||||
})
|
||||
|
||||
-- remote dns outbound
|
||||
local chn_list = uci:get(api.c_config, "@global[0]", "chn_list") or "direct"
|
||||
local chn_list = api.uci_get_c("@global[0]", "chn_list") or "direct"
|
||||
remote_dns_outbound = {
|
||||
tag = "dns-out",
|
||||
protocol = "dns",
|
||||
@@ -1979,11 +1976,11 @@ function gen_config(var)
|
||||
if inbounds or outbounds then
|
||||
local config = {
|
||||
env = (function()
|
||||
local asset_location = uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
local asset_location = api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
return { XRAY_LOCATION_ASSET = asset_location }
|
||||
end)(),
|
||||
log = {
|
||||
-- error = string.format("/tmp/etc/%s/%s.log", appname, node[".name"]),
|
||||
-- error = string.format("/tmp/etc/passwall/%s.log", node[".name"]),
|
||||
loglevel = get_log_level(loglevel)
|
||||
},
|
||||
-- DNS
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
local api = require ("luci.passwall.api")
|
||||
local appname = api.appname
|
||||
local fs = api.fs
|
||||
local jsonc = api.jsonc
|
||||
local uci = api.uci
|
||||
local sys = api.sys
|
||||
|
||||
@@ -23,11 +22,11 @@ local haproxy_conf = var["-conf"]
|
||||
local haproxy_dns = var["-dns"] or "119.29.29.29:53,223.5.5.5:53"
|
||||
|
||||
local cpu_thread = sys.exec('echo -n $(cat /proc/cpuinfo | grep "processor" | wc -l)') or "1"
|
||||
local health_check_type = uci:get(api.c_config, "@global_haproxy[0]", "health_check_type") or "tcp"
|
||||
local health_check_inter = uci:get(api.c_config, "@global_haproxy[0]", "health_check_inter") or "20"
|
||||
local balancingStrategy = uci:get(api.c_config, "@global_haproxy[0]", "balancingStrategy") or "roundrobin"
|
||||
local console_port = uci:get(api.c_config, "@global_haproxy[0]", "console_port")
|
||||
local bind_local = uci:get(api.c_config, "@global_haproxy[0]", "bind_local") or "0"
|
||||
local health_check_type = api.uci_get_c("@global_haproxy[0]", "health_check_type") or "tcp"
|
||||
local health_check_inter = api.uci_get_c("@global_haproxy[0]", "health_check_inter") or "20"
|
||||
local balancingStrategy = api.uci_get_c("@global_haproxy[0]", "balancingStrategy") or "roundrobin"
|
||||
local console_port = api.uci_get_c("@global_haproxy[0]", "console_port")
|
||||
local bind_local = api.uci_get_c("@global_haproxy[0]", "bind_local") or "0"
|
||||
local bind_address = "0.0.0.0"
|
||||
if bind_local == "1" then bind_address = "127.0.0.1" end
|
||||
|
||||
@@ -94,14 +93,14 @@ f_out:write(haproxy_config)
|
||||
|
||||
local listens = {}
|
||||
|
||||
uci:foreach(api.c_config, "haproxy_config", function(t)
|
||||
api.uci_foreach_c("haproxy_config", function(t)
|
||||
if t.enabled == "1" then
|
||||
local server_remark
|
||||
local server_address
|
||||
local server_port
|
||||
local lbss = t.lbss
|
||||
local listen_port = tonumber(t.haproxy_port) or 0
|
||||
local server_node = uci:get_all(api.c_config, lbss)
|
||||
local server_node = api.uci_get_c(lbss)
|
||||
local hop = (health_check_type == "script_logic") and (server_node.hysteria_hop or server_node.hysteria2_hop) or nil
|
||||
hop = hop and hop:gsub(":", "-") or nil
|
||||
if server_node and server_node.address and (server_node.port or hop) then
|
||||
@@ -214,8 +213,8 @@ listen %s
|
||||
end
|
||||
|
||||
--控制台配置
|
||||
local console_user = uci:get(api.c_config, "@global_haproxy[0]", "console_user")
|
||||
local console_password = uci:get(api.c_config, "@global_haproxy[0]", "console_password")
|
||||
local console_user = api.uci_get_c("@global_haproxy[0]", "console_user")
|
||||
local console_password = api.uci_get_c("@global_haproxy[0]", "console_password")
|
||||
local str = [[
|
||||
listen console
|
||||
bind 0.0.0.0:%s
|
||||
@@ -231,7 +230,7 @@ f_out:close()
|
||||
|
||||
--passwall内置健康检查URL
|
||||
if health_check_type == "script_logic" then
|
||||
local probeUrl = uci:get(api.c_config, "@global_haproxy[0]", "health_probe_url") or "https://www.google.com/generate_204"
|
||||
local probeUrl = api.uci_get_c("@global_haproxy[0]", "health_probe_url") or "https://www.google.com/generate_204"
|
||||
local f_url = io.open(haproxy_path .. "/Probe_URL", "w")
|
||||
f_url:write(probeUrl)
|
||||
f_url:close()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
local api = require "luci.passwall.api"
|
||||
local appname = api.appname
|
||||
|
||||
local var = api.get_args(arg)
|
||||
local FLAG = var["-FLAG"]
|
||||
@@ -20,19 +19,18 @@ local NFTFLAG = var["-NFTFLAG"]
|
||||
local FILTER_HTTPS = var["-FILTER_HTTPS"]
|
||||
local LOG_FILE = var["-LOG_FILE"]
|
||||
|
||||
local uci = api.uci
|
||||
local sys = api.sys
|
||||
local fs = api.fs
|
||||
local datatypes = api.datatypes
|
||||
|
||||
local TMP_PATH = "/tmp/etc/" .. appname
|
||||
local TMP_PATH = api.TMP_PATH
|
||||
local TMP_ACL_PATH = TMP_PATH .. "/acl"
|
||||
local RULES_PATH = "/usr/share/" .. appname .. "/rules"
|
||||
local RULES_PATH = "/usr/share/passwall/rules"
|
||||
local FLAG_PATH = TMP_ACL_PATH .. "/" .. FLAG
|
||||
local config_lines = {}
|
||||
local tmp_lines = {}
|
||||
local USE_GEOVIEW = uci:get(api.c_config, "@global_rules[0]", "enable_geoview")
|
||||
local IS_SHUNT_NODE = uci:get(api.c_config, TCP_NODE, "protocol") == "_shunt"
|
||||
local USE_GEOVIEW = api.uci_get_c("@global_rules[0]", "enable_geoview")
|
||||
local IS_SHUNT_NODE = api.uci_get_c(TCP_NODE, "protocol") == "_shunt"
|
||||
|
||||
if not api.is_finded("geoview") then
|
||||
USE_GEOVIEW = "0"
|
||||
@@ -92,7 +90,7 @@ local function insert_array_after(array1, array2, target) --将array2插入到ar
|
||||
end
|
||||
|
||||
local function get_geosite(list_arg, out_path)
|
||||
local geosite_path = uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
local geosite_path = api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
geosite_path = geosite_path:match("^(.*)/") .. "/geosite.dat"
|
||||
if not is_file_nonzero(geosite_path) then return 1 end
|
||||
local bin = api.finded_com("geoview")
|
||||
@@ -183,7 +181,7 @@ if not is_file_nonzero(file_vpslist) then
|
||||
written_domains[address] = true
|
||||
end
|
||||
end
|
||||
uci:foreach(api.c_config, "nodes", function(t)
|
||||
api.uci_foreach_c("nodes", function(t)
|
||||
process_address(t.address)
|
||||
process_address(t.download_address)
|
||||
local dns, _ = api.get_domain_port_from_url(t.domain_resolver_dns or t.domain_resolver_dns_https or "")
|
||||
@@ -191,7 +189,7 @@ if not is_file_nonzero(file_vpslist) then
|
||||
process_address(dns)
|
||||
end
|
||||
end)
|
||||
uci:foreach(api.c_config, "subscribe_list", function(t) --订阅链接
|
||||
api.uci_foreach_c("subscribe_list", function(t) --订阅链接
|
||||
local url, _ = api.get_domain_port_from_url(t.url or "")
|
||||
if url and url ~= "" then
|
||||
process_address(url)
|
||||
@@ -387,9 +385,9 @@ if IS_SHUNT_NODE then
|
||||
local file_shunt_host = FLAG_PATH .. "/shunt_proxy_host"
|
||||
local geosite_white_arg, geosite_shunt_arg = "", ""
|
||||
|
||||
local t = uci:get_all(api.c_config, TCP_NODE)
|
||||
local t = api.uci_get_c(TCP_NODE)
|
||||
local default_node_id = t["default_node"] or "_direct"
|
||||
uci:foreach(api.c_config, "shunt_rules", function(s)
|
||||
api.uci_foreach_c("shunt_rules", function(s)
|
||||
local _node_id = t[s[".name"]]
|
||||
if _node_id and _node_id ~= "_blackhole" and t["shunt_group"] == s.group then
|
||||
if _node_id == "_default" then
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
local api = require "luci.passwall.api"
|
||||
local appname = "passwall"
|
||||
local uci = api.uci
|
||||
local sys = api.sys
|
||||
local fs = api.fs
|
||||
local datatypes = api.datatypes
|
||||
@@ -22,38 +20,38 @@ local function tinsert(table_name, val)
|
||||
end
|
||||
|
||||
local function backup_servers()
|
||||
local DNSMASQ_DNS = uci:get("dhcp", "@dnsmasq[0]", "server")
|
||||
local DNSMASQ_DNS = api.uci_get("dhcp", "@dnsmasq[0]", "server")
|
||||
if DNSMASQ_DNS and #DNSMASQ_DNS > 0 then
|
||||
uci:set(api.c_config, "@global[0]", "dnsmasq_servers", DNSMASQ_DNS)
|
||||
api.uci_save(uci, api.c_config, true)
|
||||
api.uci_set_c("@global[0]", "dnsmasq_servers", DNSMASQ_DNS)
|
||||
api.uci_save_c(true)
|
||||
end
|
||||
end
|
||||
|
||||
local function restore_servers()
|
||||
local dns_table = {}
|
||||
local DNSMASQ_DNS = uci:get("dhcp", "@dnsmasq[0]", "server")
|
||||
local DNSMASQ_DNS = api.uci_get("dhcp", "@dnsmasq[0]", "server")
|
||||
if DNSMASQ_DNS and #DNSMASQ_DNS > 0 then
|
||||
for k, v in ipairs(DNSMASQ_DNS) do
|
||||
tinsert(dns_table, v)
|
||||
end
|
||||
end
|
||||
local OLD_SERVER = uci:get(api.c_config, "@global[0]", "dnsmasq_servers")
|
||||
local OLD_SERVER = api.uci_get(api.c_config, "@global[0]", "dnsmasq_servers")
|
||||
if OLD_SERVER and #OLD_SERVER > 0 then
|
||||
for k, v in ipairs(OLD_SERVER) do
|
||||
tinsert(dns_table, v)
|
||||
end
|
||||
uci:delete(api.c_config, "@global[0]", "dnsmasq_servers")
|
||||
api.uci_save(uci, api.c_config, true)
|
||||
api.uci_del_c("@global[0]", "dnsmasq_servers")
|
||||
api.uci_save_c(true)
|
||||
end
|
||||
if dns_table and #dns_table > 0 then
|
||||
uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table)
|
||||
api.uci_save(uci, "dhcp", true)
|
||||
api.uci_set("dhcp", "@dnsmasq[0]", "server", dns_table)
|
||||
api.uci_save(nil, "dhcp", true)
|
||||
end
|
||||
end
|
||||
|
||||
function stretch()
|
||||
local dnsmasq_server = uci:get("dhcp", "@dnsmasq[0]", "server")
|
||||
local dnsmasq_noresolv = uci:get("dhcp", "@dnsmasq[0]", "noresolv")
|
||||
local dnsmasq_server = api.uci_get("dhcp", "@dnsmasq[0]", "server")
|
||||
local dnsmasq_noresolv = api.uci_get("dhcp", "@dnsmasq[0]", "noresolv")
|
||||
local _flag
|
||||
if dnsmasq_server and #dnsmasq_server > 0 then
|
||||
for k, v in ipairs(dnsmasq_server) do
|
||||
@@ -63,7 +61,7 @@ function stretch()
|
||||
end
|
||||
end
|
||||
if not _flag and dnsmasq_noresolv == "1" then
|
||||
uci:delete("dhcp", "@dnsmasq[0]", "noresolv")
|
||||
api.uci_del("dhcp", "@dnsmasq[0]", "noresolv")
|
||||
local RESOLVFILE = "/tmp/resolv.conf.d/resolv.conf.auto"
|
||||
local file = io.open(RESOLVFILE, "r")
|
||||
if not file then
|
||||
@@ -75,8 +73,8 @@ function stretch()
|
||||
RESOLVFILE = "/tmp/resolv.conf.auto"
|
||||
end
|
||||
end
|
||||
uci:set("dhcp", "@dnsmasq[0]", "resolvfile", RESOLVFILE)
|
||||
api.uci_save(uci, "dhcp", true)
|
||||
api.uci_set("dhcp", "@dnsmasq[0]", "resolvfile", RESOLVFILE)
|
||||
api.uci_save(nil, "dhcp", true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -95,15 +93,15 @@ function logic_restart(var)
|
||||
backup_servers()
|
||||
--sys.call("sed -i '/list server/d' /etc/config/dhcp >/dev/null 2>&1")
|
||||
local dns_table = {}
|
||||
local dnsmasq_server = uci:get("dhcp", "@dnsmasq[0]", "server")
|
||||
local dnsmasq_server = api.uci_get("dhcp", "@dnsmasq[0]", "server")
|
||||
if dnsmasq_server and #dnsmasq_server > 0 then
|
||||
for k, v in ipairs(dnsmasq_server) do
|
||||
if v:find("/") then
|
||||
tinsert(dns_table, v)
|
||||
end
|
||||
end
|
||||
uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table)
|
||||
api.uci_save(uci, "dhcp", true)
|
||||
api.uci_set("dhcp", "@dnsmasq[0]", "server", dns_table)
|
||||
api.uci_save(nil, "dhcp", true)
|
||||
end
|
||||
sys.call("/etc/init.d/dnsmasq restart >/dev/null 2>&1")
|
||||
restore_servers()
|
||||
@@ -180,8 +178,8 @@ function add_rule(var)
|
||||
local CACHE_DNS_PATH = CACHE_PATH .. "/" .. CACHE_FLAG
|
||||
local CACHE_TEXT_FILE = CACHE_DNS_PATH .. ".txt"
|
||||
local USE_CHINADNS_NG = "0"
|
||||
local IS_SHUNT_NODE = uci:get(api.c_config, TCP_NODE, "protocol") == "_shunt"
|
||||
local USE_GEOVIEW = uci:get(api.c_config, "@global_rules[0]", "enable_geoview")
|
||||
local IS_SHUNT_NODE = api.uci_get_c(TCP_NODE, "protocol") == "_shunt"
|
||||
local USE_GEOVIEW = api.uci_get_c("@global_rules[0]", "enable_geoview")
|
||||
|
||||
local list1 = {}
|
||||
local excluded_domain = {}
|
||||
@@ -307,7 +305,7 @@ function add_rule(var)
|
||||
end
|
||||
|
||||
local function foreach_geosite(list_arg, callback)
|
||||
local geosite_path = uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
local geosite_path = api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
geosite_path = geosite_path:match("^(.*)/") .. "/geosite.dat"
|
||||
if not fs.access(geosite_path) then return end
|
||||
local bin = api.finded_com("geoview")
|
||||
@@ -412,7 +410,7 @@ function add_rule(var)
|
||||
set_domain_ipset(address, table.concat(sets, ","))
|
||||
end
|
||||
end
|
||||
uci:foreach(api.c_config, "nodes", function(t)
|
||||
api.uci_foreach_c("nodes", function(t)
|
||||
process_address(t.address)
|
||||
process_address(t.download_address)
|
||||
local dns, _ = api.get_domain_port_from_url(t.domain_resolver_dns or t.domain_resolver_dns_https or "")
|
||||
@@ -420,7 +418,7 @@ function add_rule(var)
|
||||
process_address(dns)
|
||||
end
|
||||
end)
|
||||
uci:foreach(api.c_config, "subscribe_list", function(t) --订阅链接
|
||||
api.uci_foreach_c("subscribe_list", function(t) --订阅链接
|
||||
local url, _ = api.get_domain_port_from_url(t.url or "")
|
||||
if url and url ~= "" then
|
||||
process_address(url)
|
||||
@@ -615,9 +613,9 @@ function add_rule(var)
|
||||
|
||||
--分流规则
|
||||
if IS_SHUNT_NODE and USE_CHINADNS_NG == "0" then
|
||||
local t = uci:get_all(api.c_config, TCP_NODE)
|
||||
local t = api.uci_get_c(TCP_NODE)
|
||||
local default_node_id = t["default_node"] or "_direct"
|
||||
uci:foreach(api.c_config, "shunt_rules", function(s)
|
||||
api.uci_foreach_c("shunt_rules", function(s)
|
||||
local _node_id = t[s[".name"]]
|
||||
if _node_id and _node_id ~= "_blackhole" and t["shunt_group"] == s.group then
|
||||
if _node_id == "_default" then
|
||||
@@ -763,7 +761,7 @@ function add_rule(var)
|
||||
--Copy dnsmasq instance
|
||||
conf_lines = copy_instance({["-LISTEN_PORT"] = LISTEN_PORT, ["-TMP_DNSMASQ_PATH"] = TMP_DNSMASQ_PATH, ["-return"] = "1"})
|
||||
--dhcp.leases to hosts
|
||||
local hosts = "/tmp/etc/" .. appname .. "_tmp/dhcp-hosts"
|
||||
local hosts = api.CACHE_PATH .. "/dhcp-hosts"
|
||||
sys.call("touch " .. hosts)
|
||||
tinsert(conf_lines, "addn-hosts=" .. hosts)
|
||||
else
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
local api = require "luci.passwall.api"
|
||||
local appname = api.appname
|
||||
|
||||
local var = api.get_args(arg)
|
||||
local FLAG = var["-FLAG"]
|
||||
@@ -25,20 +24,19 @@ local SUBNET = var["-SUBNET"]
|
||||
local LISTEN_PORT = var["-LISTEN_PORT"]
|
||||
local LOCAL_PORT = var["-LOCAL_PORT"]
|
||||
|
||||
local uci = api.uci
|
||||
local sys = api.sys
|
||||
local fs = api.fs
|
||||
local datatypes = api.datatypes
|
||||
|
||||
local TMP_PATH = "/tmp/etc/" .. appname
|
||||
local TMP_PATH = api.TMP_PATH
|
||||
local TMP_ACL_PATH = TMP_PATH .. "/acl"
|
||||
local RULES_PATH = "/usr/share/" .. appname .. "/rules"
|
||||
local RULES_PATH = "/usr/share/passwall/rules"
|
||||
local FLAG_PATH = TMP_ACL_PATH .. "/" .. FLAG
|
||||
local TMP_CONF_FILE = FLAG_PATH .. "/smartdns.conf"
|
||||
local config_lines = {}
|
||||
local tmp_lines = {}
|
||||
local USE_GEOVIEW = uci:get(api.c_config, "@global_rules[0]", "enable_geoview")
|
||||
local IS_SHUNT_NODE = uci:get(api.c_config, TCP_NODE, "protocol") == "_shunt"
|
||||
local USE_GEOVIEW = api.uci_get_c("@global_rules[0]", "enable_geoview")
|
||||
local IS_SHUNT_NODE = api.uci_get_c(TCP_NODE, "protocol") == "_shunt"
|
||||
|
||||
if not api.is_finded("geoview") then
|
||||
USE_GEOVIEW = "0"
|
||||
@@ -98,7 +96,7 @@ local function insert_array_after(array1, array2, target) --将array2插入到ar
|
||||
end
|
||||
|
||||
local function get_geosite(list_arg, out_path)
|
||||
local geosite_path = uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
local geosite_path = api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
geosite_path = geosite_path:match("^(.*)/") .. "/geosite.dat"
|
||||
if not is_file_nonzero(geosite_path) then return 1 end
|
||||
local bin = api.finded_com("geoview")
|
||||
@@ -139,7 +137,7 @@ else
|
||||
local soa = custom_config["force-qtype-SOA"]
|
||||
return ((soa and soa:match("(^|%s)28(%s|$)"))
|
||||
or custom_config["force-AAAA-SOA"] == "yes"
|
||||
or uci:get("smartdns", "@smartdns[0]", "force_aaaa_soa") == "1")
|
||||
or api.uci_get("smartdns", "@smartdns[0]", "force_aaaa_soa") == "1")
|
||||
and "#6" or "-6"
|
||||
end
|
||||
}
|
||||
@@ -163,7 +161,7 @@ else
|
||||
if opt.get_value then
|
||||
val = opt.get_value(custom_config)
|
||||
else
|
||||
val = custom_config[opt.config_key] or uci:get("smartdns", "@smartdns[0]", opt.key) or opt.default
|
||||
val = custom_config[opt.config_key] or api.uci_get("smartdns", "@smartdns[0]", opt.key) or opt.default
|
||||
end
|
||||
if val == "yes" then val = "1" elseif val == "no" then val = "0" end
|
||||
if opt.yes_no then
|
||||
@@ -187,7 +185,7 @@ if not REMOTE_GROUP or REMOTE_GROUP == "nil" then
|
||||
sys.call('sed -i "/passwall/d" /etc/smartdns/custom.conf >/dev/null 2>&1')
|
||||
end
|
||||
|
||||
local force_https_soa = uci:get(api.c_config, "@global[0]", "force_https_soa") or 0
|
||||
local force_https_soa = api.uci_get_c("@global[0]", "force_https_soa") or 0
|
||||
local proxy_server_name = "passwall-proxy-server"
|
||||
config_lines = {
|
||||
tonumber(LISTEN_PORT) ~= 0 and "bind [::]:" .. LISTEN_PORT .. "@lo" or "",
|
||||
@@ -342,7 +340,7 @@ if not is_file_nonzero(file_vpslist) then
|
||||
written_domains[address] = true
|
||||
end
|
||||
end
|
||||
uci:foreach(api.c_config, "nodes", function(t)
|
||||
api.uci_foreach_c("nodes", function(t)
|
||||
process_address(t.address)
|
||||
process_address(t.download_address)
|
||||
local dns, _ = api.get_domain_port_from_url(t.domain_resolver_dns or t.domain_resolver_dns_https or "")
|
||||
@@ -350,7 +348,7 @@ if not is_file_nonzero(file_vpslist) then
|
||||
process_address(dns)
|
||||
end
|
||||
end)
|
||||
uci:foreach(api.c_config, "subscribe_list", function(t) --订阅链接
|
||||
api.uci_foreach_c("subscribe_list", function(t) --订阅链接
|
||||
local url, _ = api.get_domain_port_from_url(t.url or "")
|
||||
if url and url ~= "" then
|
||||
process_address(url)
|
||||
@@ -555,9 +553,9 @@ if IS_SHUNT_NODE then
|
||||
local file_shunt_host = FLAG_PATH .. "/shunt_proxy_host"
|
||||
local geosite_white_arg, geosite_shunt_arg = "", ""
|
||||
|
||||
local t = uci:get_all(api.c_config, TCP_NODE)
|
||||
local t = api.uci_get_c(TCP_NODE)
|
||||
local default_node_id = t["default_node"] or "_direct"
|
||||
uci:foreach(api.c_config, "shunt_rules", function(s)
|
||||
api.uci_foreach_c("shunt_rules", function(s)
|
||||
local _node_id = t[s[".name"]]
|
||||
if _node_id and _node_id ~= "_blackhole" and t["shunt_group"] == s.group then
|
||||
if _node_id == "_default" then
|
||||
@@ -694,5 +692,5 @@ if DEFAULT_DNS_GROUP then
|
||||
end
|
||||
|
||||
fs.symlink(TMP_CONF_FILE, SMARTDNS_CONF)
|
||||
sys.call(string.format('echo "conf-file %s" >> /etc/smartdns/custom.conf', string.gsub(SMARTDNS_CONF, appname, appname .. "*")))
|
||||
sys.call(string.format('echo "conf-file %s" >> /etc/smartdns/custom.conf', string.gsub(SMARTDNS_CONF, "passwall", "passwall*")))
|
||||
log(" - SmartDNS已作为Dnsmasq上游,如果你自行配置了错误的DNS流程,将会导致域名(直连/代理域名)分流失效!!!")
|
||||
@@ -1,19 +1,18 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local api = require ("luci.passwall.api")
|
||||
local name = api.appname
|
||||
local c_config = api.c_config
|
||||
local uci = api.uci
|
||||
local appname = api.appname
|
||||
local sys = api.sys
|
||||
local jsonc = api.jsonc
|
||||
local fs = api.fs
|
||||
local uci, uci_get, uci_set, uci_del, uci_foreach, uci_save = api.uci, api.uci_get_c, api.uci_set_c, api.uci_del_c, api.uci_foreach_c, api.uci_save_c
|
||||
|
||||
local arg1 = arg[1]
|
||||
local arg2 = arg[2]
|
||||
local arg3 = arg[3]
|
||||
|
||||
local nftable_name = "inet passwall"
|
||||
local rule_path = "/usr/share/" .. name .. "/rules"
|
||||
local rule_path = "/usr/share/passwall/rules"
|
||||
local reboot = 0
|
||||
local gfwlist_update = "0"
|
||||
local chnroute_update = "0"
|
||||
@@ -24,14 +23,14 @@ local geosite_update = "0"
|
||||
|
||||
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 = uci:get(c_config, "@global_rules[0]", "gfwlist_url") or {"https://fastly.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/gfw.txt"}
|
||||
local chnroute_url = uci:get(c_config, "@global_rules[0]", "chnroute_url") or {"https://ispip.clang.cn/all_cn.txt"}
|
||||
local chnroute6_url = uci:get(c_config, "@global_rules[0]", "chnroute6_url") or {"https://ispip.clang.cn/all_cn_ipv6.txt"}
|
||||
local chnlist_url = uci:get(c_config, "@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_url = uci:get(c_config, "@global_rules[0]", "geoip_url") or "https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip.dat"
|
||||
local geosite_url = uci:get(c_config, "@global_rules[0]", "geosite_url") or "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
|
||||
local asset_location = uci:get(c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
local geo2rule = uci:get(c_config, "@global_rules[0]", "geo2rule") or "0"
|
||||
local gfwlist_url = uci_get("@global_rules[0]", "gfwlist_url") or {"https://fastly.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/gfw.txt"}
|
||||
local chnroute_url = uci_get("@global_rules[0]", "chnroute_url") or {"https://ispip.clang.cn/all_cn.txt"}
|
||||
local chnroute6_url = uci_get("@global_rules[0]", "chnroute6_url") or {"https://ispip.clang.cn/all_cn_ipv6.txt"}
|
||||
local chnlist_url = uci_get("@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_url = uci_get("@global_rules[0]", "geoip_url") or "https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip.dat"
|
||||
local geosite_url = uci_get("@global_rules[0]", "geosite_url") or "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
|
||||
local asset_location = uci_get("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
local geo2rule = uci_get("@global_rules[0]", "geo2rule") or "0"
|
||||
local geoip_update_ok, geosite_update_ok = false, false
|
||||
asset_location = asset_location:match("/$") and asset_location or (asset_location .. "/")
|
||||
local backup_path = "/tmp/bak_v2ray/"
|
||||
@@ -660,20 +659,20 @@ if arg2 then
|
||||
end)
|
||||
if rollback then arg2 = nil end
|
||||
else
|
||||
gfwlist_update = uci:get(c_config, "@global_rules[0]", "gfwlist_update") or "1"
|
||||
chnroute_update = uci:get(c_config, "@global_rules[0]", "chnroute_update") or "1"
|
||||
chnroute6_update = uci:get(c_config, "@global_rules[0]", "chnroute6_update") or "1"
|
||||
chnlist_update = uci:get(c_config, "@global_rules[0]", "chnlist_update") or "1"
|
||||
geoip_update = uci:get(c_config, "@global_rules[0]", "geoip_update") or "1"
|
||||
geosite_update = uci:get(c_config, "@global_rules[0]", "geosite_update") or "1"
|
||||
gfwlist_update = uci_get("@global_rules[0]", "gfwlist_update") or "1"
|
||||
chnroute_update = uci_get("@global_rules[0]", "chnroute_update") or "1"
|
||||
chnroute6_update = uci_get("@global_rules[0]", "chnroute6_update") or "1"
|
||||
chnlist_update = uci_get("@global_rules[0]", "chnlist_update") or "1"
|
||||
geoip_update = uci_get("@global_rules[0]", "geoip_update") or "1"
|
||||
geosite_update = uci_get("@global_rules[0]", "geosite_update") or "1"
|
||||
end
|
||||
if geo2rule ~= "1" and 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)
|
||||
end
|
||||
|
||||
local function check_instance(action)
|
||||
local rule_lock = "/var/lock/" .. name .. "_rule_update.lock"
|
||||
local sub_lock = "/var/lock/" .. name .. "_subscribe.lock"
|
||||
local rule_lock = api.LOCK_PREFIX .. "_rule_update.lock"
|
||||
local sub_lock = api.LOCK_PREFIX .. "_subscribe.lock"
|
||||
|
||||
if action == "start" then
|
||||
math.randomseed(os.time() + math.floor(os.clock() * 1000))
|
||||
@@ -778,25 +777,25 @@ else
|
||||
end
|
||||
|
||||
if not rollback then
|
||||
uci:set(c_config, "@global_rules[0]", "gfwlist_update", gfwlist_update)
|
||||
uci:set(c_config, "@global_rules[0]", "chnroute_update", chnroute_update)
|
||||
uci:set(c_config, "@global_rules[0]", "chnroute6_update", chnroute6_update)
|
||||
uci:set(c_config, "@global_rules[0]", "chnlist_update", chnlist_update)
|
||||
uci:set(c_config, "@global_rules[0]", "geoip_update", geoip_update)
|
||||
uci:set(c_config, "@global_rules[0]", "geosite_update", geosite_update)
|
||||
api.uci_save(uci, c_config, true)
|
||||
uci_set("@global_rules[0]", "gfwlist_update", gfwlist_update)
|
||||
uci_set("@global_rules[0]", "chnroute_update", chnroute_update)
|
||||
uci_set("@global_rules[0]", "chnroute6_update", chnroute6_update)
|
||||
uci_set("@global_rules[0]", "chnlist_update", chnlist_update)
|
||||
uci_set("@global_rules[0]", "geoip_update", geoip_update)
|
||||
uci_set("@global_rules[0]", "geosite_update", geosite_update)
|
||||
uci_save(true)
|
||||
end
|
||||
|
||||
if reboot == 1 then
|
||||
if arg3 == "cron" then
|
||||
if not fs.access("/var/lock/" .. name .. ".lock") then
|
||||
sys.call("touch /tmp/lock/" .. name .. "_cron.lock")
|
||||
if not fs.access(api.LOCK_PREFIX .. ".lock") then
|
||||
luci.sys.call("touch %s_cron.lock" % api.LOCK_PREFIX)
|
||||
end
|
||||
end
|
||||
|
||||
log("重启服务,应用新的规则。")
|
||||
uci:set(c_config, "@global[0]", "flush_set", "1")
|
||||
api.uci_save(uci, c_config, true, true)
|
||||
uci_set("@global[0]", "flush_set", "1")
|
||||
uci_save(true, true)
|
||||
end
|
||||
log("规则更新完毕...\n")
|
||||
|
||||
|
||||
@@ -7,23 +7,22 @@ require 'luci.util'
|
||||
require 'luci.jsonc'
|
||||
require 'luci.sys'
|
||||
local api = require "luci.passwall.api"
|
||||
local appname = api.appname
|
||||
local c_config = api.c_config
|
||||
local datatypes = require "luci.cbi.datatypes"
|
||||
local datatypes = api.datatypes
|
||||
|
||||
loadfile("/usr/share/" .. appname .. "/clash_subconverter.lua")()
|
||||
loadfile("/usr/share/passwall/clash_subconverter.lua")()
|
||||
|
||||
local split = api.split
|
||||
local base64Decode = api.base64Decode
|
||||
local jsonParse, jsonStringify = api.jsonc.parse, api.jsonc.stringify
|
||||
local UrlEncode, UrlDecode = api.UrlEncode, api.UrlDecode
|
||||
local fs = api.fs
|
||||
local uci, uci_get, uci_set, uci_del, uci_foreach, uci_save = api.uci, api.uci_get_c, api.uci_set_c, api.uci_del_c, api.uci_foreach_c, api.uci_save_c
|
||||
|
||||
-- these global functions are accessed all the time by the event handler
|
||||
-- so caching them is worth the effort
|
||||
local tinsert = table.insert
|
||||
local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub
|
||||
local split = api.split
|
||||
local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify
|
||||
local base64Decode = api.base64Decode
|
||||
local UrlEncode = api.UrlEncode
|
||||
local UrlDecode = api.UrlDecode
|
||||
local uci = api.uci
|
||||
local fs = api.fs
|
||||
|
||||
local has_ss_rust = api.is_finded("sslocal")
|
||||
local has_ssr = api.is_finded("ssr-local") and api.is_finded("ssr-redir")
|
||||
@@ -31,9 +30,9 @@ local has_singbox = api.finded_com("sing-box")
|
||||
local has_xray = api.finded_com("xray")
|
||||
local has_hysteria2 = api.finded_com("hysteria")
|
||||
local DEFAULT_ALLOWINSECURE = true
|
||||
local DEFAULT_FILTER_KEYWORD_MODE = uci:get(c_config, "@global_subscribe[0]", "filter_keyword_mode") or "0"
|
||||
local DEFAULT_FILTER_KEYWORD_DISCARD_LIST = uci:get(c_config, "@global_subscribe[0]", "filter_discard_list") or {}
|
||||
local DEFAULT_FILTER_KEYWORD_KEEP_LIST = uci:get(c_config, "@global_subscribe[0]", "filter_keep_list") or {}
|
||||
local DEFAULT_FILTER_KEYWORD_MODE = uci_get("@global_subscribe[0]", "filter_keyword_mode") or "0"
|
||||
local DEFAULT_FILTER_KEYWORD_DISCARD_LIST = uci_get("@global_subscribe[0]", "filter_discard_list") or {}
|
||||
local DEFAULT_FILTER_KEYWORD_KEEP_LIST = uci_get("@global_subscribe[0]", "filter_keep_list") or {}
|
||||
-- 取节点使用core类型(节点订阅页面未设置时,自动取默认)
|
||||
local DEFAULT_SS_TYPE = api.get_core("ss_type", {{has_ss_rust,"shadowsocks-rust"},{has_singbox,"sing-box"},{has_xray,"xray"}})
|
||||
local DEFAULT_TROJAN_TYPE = api.get_core("trojan_type", {{has_singbox,"sing-box"},{has_xray,"xray"}})
|
||||
@@ -142,13 +141,13 @@ do
|
||||
local szType = "@global[0]"
|
||||
local option = protocol .. "_node"
|
||||
|
||||
local node_id = uci:get(c_config, szType, option)
|
||||
local node_id = uci_get(szType, option)
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
remarks = name .. "节点",
|
||||
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
|
||||
currentNode = node_id and uci_get(node_id) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(c_config, szType, option, server)
|
||||
uci_set(szType, option, server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
@@ -159,7 +158,7 @@ do
|
||||
if true then
|
||||
local i = 0
|
||||
local option = "node"
|
||||
uci:foreach(c_config, "socks", function(t)
|
||||
uci_foreach("socks", function(t)
|
||||
i = i + 1
|
||||
local id = t[".name"]
|
||||
local node_id = t[option]
|
||||
@@ -167,14 +166,14 @@ do
|
||||
log = true,
|
||||
id = id,
|
||||
remarks = "Socks节点列表[" .. i .. "]",
|
||||
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
|
||||
currentNode = node_id and uci_get(node_id) or nil,
|
||||
set = function(o, server)
|
||||
if not server or server == "" then
|
||||
if #nodes_table > 0 then
|
||||
server = nodes_table[1][".name"]
|
||||
end
|
||||
end
|
||||
uci:set(c_config, t[".name"], option, server)
|
||||
uci_set(t[".name"], option, server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
@@ -184,7 +183,7 @@ do
|
||||
local newNodes = {}
|
||||
for k, asb_node_id in ipairs(t.autoswitch_backup_node) do
|
||||
if asb_node_id then
|
||||
local currentNode = uci:get_all(c_config, asb_node_id) or {}
|
||||
local currentNode = uci_get(asb_node_id) or {}
|
||||
if currentNode[".type"] == "nodes" then
|
||||
currentNodes[#currentNodes + 1] = {
|
||||
log = true,
|
||||
@@ -206,7 +205,7 @@ do
|
||||
set = function(o, newNodes)
|
||||
if o then
|
||||
if not newNodes then newNodes = o.newNodes end
|
||||
uci:set_list(c_config, id, "autoswitch_backup_node", newNodes or {})
|
||||
uci_set(id, "autoswitch_backup_node", newNodes or {})
|
||||
end
|
||||
end
|
||||
}
|
||||
@@ -222,25 +221,25 @@ do
|
||||
local ip, port = str:match("^([%d%.]+):(%d+)$")
|
||||
return ip and datatypes.ipaddr(ip) and tonumber(port) and tonumber(port) <= 65535
|
||||
end
|
||||
uci:foreach(c_config, "haproxy_config", function(t)
|
||||
uci_foreach("haproxy_config", function(t)
|
||||
i = i + 1
|
||||
local node_id = t[option]
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = t[".name"],
|
||||
remarks = "HAProxy负载均衡节点列表[" .. i .. "]",
|
||||
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
|
||||
currentNode = node_id and uci_get(node_id) or nil,
|
||||
set = function(o, server)
|
||||
-- 如果当前 lbss 值不是 ip:port 格式,才进行修改
|
||||
if not is_ip_port(t[option]) then
|
||||
uci:set(c_config, t[".name"], option, server)
|
||||
uci_set(t[".name"], option, server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
end,
|
||||
delete = function(o)
|
||||
-- 如果当前 lbss 值不是 ip:port 格式,才进行删除
|
||||
if not is_ip_port(t[option]) then
|
||||
uci:delete(c_config, t[".name"])
|
||||
uci_del(t[".name"])
|
||||
end
|
||||
end
|
||||
}
|
||||
@@ -250,7 +249,7 @@ do
|
||||
if true then
|
||||
local i = 0
|
||||
local options = {"tcp", "udp"}
|
||||
uci:foreach(c_config, "acl_rule", function(t)
|
||||
uci_foreach("acl_rule", function(t)
|
||||
i = i + 1
|
||||
for index, value in ipairs(options) do
|
||||
local option = value .. "_node"
|
||||
@@ -259,9 +258,9 @@ do
|
||||
log = true,
|
||||
id = t[".name"],
|
||||
remarks = "访问控制列表[" .. i .. "]",
|
||||
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
|
||||
currentNode = node_id and uci_get(node_id) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(c_config, t[".name"], option, server)
|
||||
uci_set(t[".name"], option, server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
@@ -269,11 +268,11 @@ do
|
||||
end)
|
||||
end
|
||||
|
||||
uci:foreach(c_config, "nodes", function(node)
|
||||
uci_foreach("nodes", function(node)
|
||||
local node_id = node[".name"]
|
||||
if node.protocol and node.protocol == '_shunt' then
|
||||
local rules = {}
|
||||
uci:foreach(c_config, "shunt_rules", function(e)
|
||||
uci_foreach("shunt_rules", function(e)
|
||||
if e[".name"] and e.remarks then
|
||||
table.insert(rules, e)
|
||||
table.insert(rules, {
|
||||
@@ -294,7 +293,7 @@ do
|
||||
for k, e in pairs(rules) do
|
||||
local _node_id = node[e[".name"]] or nil
|
||||
if _node_id then
|
||||
local section = uci:get_all(c_config, _node_id) or {}
|
||||
local section = uci_get(_node_id) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = false,
|
||||
@@ -302,7 +301,7 @@ do
|
||||
remarks = "分流" .. e.remarks .. "节点",
|
||||
set = function(o, server)
|
||||
if not server then server = "" end
|
||||
uci:set(c_config, node_id, e[".name"], server)
|
||||
uci_set(node_id, e[".name"], server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
@@ -319,7 +318,7 @@ do
|
||||
log = true,
|
||||
node = b_node_id,
|
||||
currentNode = (function()
|
||||
local section = uci:get_all(c_config, b_node_id) or {}
|
||||
local section = uci_get(b_node_id) or {}
|
||||
if section[".type"] == "socks" then
|
||||
return { Socks = b_node_id }
|
||||
end
|
||||
@@ -341,15 +340,15 @@ do
|
||||
set = function(o, newNodes)
|
||||
if o then
|
||||
if not newNodes then newNodes = o.newNodes end
|
||||
uci:set_list(c_config, node_id, "balancing_node", newNodes or {})
|
||||
uci_set(node_id, "balancing_node", newNodes or {})
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
--后备节点
|
||||
local currentNode = uci:get_all(c_config, node_id) or nil
|
||||
local currentNode = uci_get(node_id) or nil
|
||||
if currentNode and currentNode.fallback_node then
|
||||
local section = uci:get_all(c_config, currentNode.fallback_node) or {}
|
||||
local section = uci_get(currentNode.fallback_node) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
@@ -357,11 +356,11 @@ do
|
||||
remarks = "Xray负载均衡节点[" .. node_id .. "]后备节点",
|
||||
currentNode = section,
|
||||
set = function(o, server)
|
||||
uci:set(c_config, node_id, "fallback_node", server)
|
||||
uci_set(node_id, "fallback_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(c_config, node_id, "fallback_node")
|
||||
uci_del(node_id, "fallback_node")
|
||||
end
|
||||
}
|
||||
end
|
||||
@@ -376,7 +375,7 @@ do
|
||||
log = true,
|
||||
node = u_node_id,
|
||||
currentNode = (function()
|
||||
local section = uci:get_all(c_config, u_node_id) or {}
|
||||
local section = uci_get(u_node_id) or {}
|
||||
if section[".type"] == "socks" then
|
||||
return { Socks = u_node_id }
|
||||
end
|
||||
@@ -398,47 +397,47 @@ do
|
||||
set = function(o, newNodes)
|
||||
if o then
|
||||
if not newNodes then newNodes = o.newNodes end
|
||||
uci:set_list(c_config, node_id, "urltest_node", newNodes or {})
|
||||
uci_set(node_id, "urltest_node", newNodes or {})
|
||||
end
|
||||
end
|
||||
}
|
||||
else
|
||||
--前置代理节点
|
||||
local currentNode = uci:get_all(c_config, node_id) or nil
|
||||
local currentNode = uci_get(node_id) or nil
|
||||
if currentNode and currentNode.preproxy_node then
|
||||
local section = uci:get_all(c_config, currentNode.preproxy_node) or {}
|
||||
local section = uci_get(currentNode.preproxy_node) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = "节点[" .. node_id .. "]前置代理节点",
|
||||
currentNode = uci:get_all(c_config, currentNode.preproxy_node) or nil,
|
||||
currentNode = uci_get(currentNode.preproxy_node) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(c_config, node_id, "preproxy_node", server)
|
||||
uci_set(node_id, "preproxy_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(c_config, node_id, "preproxy_node")
|
||||
uci_del(node_id, "preproxy_node")
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
--落地节点
|
||||
local currentNode = uci:get_all(c_config, node_id) or nil
|
||||
local currentNode = uci_get(node_id) or nil
|
||||
if currentNode and currentNode.to_node then
|
||||
local section = uci:get_all(c_config, currentNode.to_node) or {}
|
||||
local section = uci_get(currentNode.to_node) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = "节点[" .. node_id .. "]落地节点",
|
||||
currentNode = uci:get_all(c_config, currentNode.to_node) or nil,
|
||||
currentNode = uci_get(currentNode.to_node) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(c_config, node_id, "to_node", server)
|
||||
uci_set(node_id, "to_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(c_config, node_id, "to_node")
|
||||
uci_del(node_id, "to_node")
|
||||
end
|
||||
}
|
||||
end
|
||||
@@ -1757,19 +1756,19 @@ local function truncate_nodes(group)
|
||||
end
|
||||
end
|
||||
end
|
||||
uci:foreach(c_config, "nodes", function(node)
|
||||
uci_foreach("nodes", function(node)
|
||||
if node.add_mode == "2" then
|
||||
if (not group) or (group:lower() == (node.group or ""):lower()) then
|
||||
uci:delete(c_config, node['.name'])
|
||||
uci_del(node['.name'])
|
||||
end
|
||||
end
|
||||
end)
|
||||
uci:foreach(c_config, "subscribe_list", function(o)
|
||||
uci_foreach("subscribe_list", function(o)
|
||||
if (not group) or (group:lower() == (o.remark or ""):lower()) then
|
||||
uci:delete(c_config, o['.name'], "md5")
|
||||
uci_del(o['.name'], "md5")
|
||||
end
|
||||
end)
|
||||
api.uci_save(uci, c_config, true)
|
||||
uci_save(true)
|
||||
end
|
||||
|
||||
local function select_node(nodes, config, parentConfig)
|
||||
@@ -1908,10 +1907,10 @@ local function update_node(manual)
|
||||
end
|
||||
|
||||
if manual == 0 and next(group) then
|
||||
uci:foreach(c_config, "nodes", function(node)
|
||||
uci_foreach("nodes", function(node)
|
||||
-- 如果未发现新节点或手动导入的节点就不要删除了...
|
||||
if node.add_mode == "2" and (node.group and group[node.group:lower()] == true) then
|
||||
uci:delete(c_config, node['.name'])
|
||||
uci_del(node['.name'])
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -1924,9 +1923,9 @@ local function update_node(manual)
|
||||
-- Subscription Group Chain Agent
|
||||
local function valid_chain_node(node)
|
||||
if not node then return "" end
|
||||
local cp = uci:get(c_config, node, "chain_proxy") or ""
|
||||
local am = uci:get(c_config, node, "add_mode") or "0"
|
||||
chain_node_type = (cp == "" and am ~= "2") and (uci:get(c_config, node, "type") or "") or ""
|
||||
local cp = uci_get(node, "chain_proxy") or ""
|
||||
local am = uci_get(node, "add_mode") or "0"
|
||||
chain_node_type = (cp == "" and am ~= "2") and (uci_get(node, "type") or "") or ""
|
||||
if chain_node_type ~= "Xray" and chain_node_type ~= "sing-box" then
|
||||
chain_node_type = ""
|
||||
return ""
|
||||
@@ -1948,19 +1947,19 @@ local function update_node(manual)
|
||||
local cfgid = uci:section(c_config, "nodes", api.gen_random_char())
|
||||
for kkk, vvv in pairs(vv) do
|
||||
if type(vvv) == "table" and next(vvv) ~= nil then
|
||||
uci:set_list(c_config, cfgid, kkk, vvv)
|
||||
uci_set(cfgid, kkk, vvv)
|
||||
else
|
||||
if kkk ~= "group" or vvv ~= "default" then
|
||||
uci:set(c_config, cfgid, kkk, vvv)
|
||||
uci_set(cfgid, kkk, vvv)
|
||||
end
|
||||
-- sing-box/xray 节点域名解析
|
||||
if kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then
|
||||
if domain_resolver then
|
||||
uci:set(c_config, cfgid, "domain_resolver", domain_resolver)
|
||||
uci_set(cfgid, "domain_resolver", domain_resolver)
|
||||
if domain_resolver_dns then
|
||||
uci:set(c_config, cfgid, "domain_resolver_dns", domain_resolver_dns)
|
||||
uci_set(cfgid, "domain_resolver_dns", domain_resolver_dns)
|
||||
elseif domain_resolver_dns_https then
|
||||
uci:set(c_config, cfgid, "domain_resolver_dns_https", domain_resolver_dns_https)
|
||||
uci_set(cfgid, "domain_resolver_dns_https", domain_resolver_dns_https)
|
||||
end
|
||||
end
|
||||
if domain_strategy then
|
||||
@@ -1969,20 +1968,20 @@ local function update_node(manual)
|
||||
local map = { UseIPv4v6 = "prefer_ipv4", UseIPv6v4 = "prefer_ipv6", UseIPv4 = "ipv4_only", UseIPv6 = "ipv6_only" }
|
||||
ds = map[ds] or ""
|
||||
end
|
||||
uci:set(c_config, cfgid, "domain_strategy", ds)
|
||||
uci_set(cfgid, "domain_strategy", ds)
|
||||
end
|
||||
end
|
||||
-- 订阅组链式代理
|
||||
if chain_node_type ~= "" and kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then
|
||||
if preproxy_node_group ~="" then
|
||||
uci:set(c_config, cfgid, "chain_proxy", "1")
|
||||
uci:set(c_config, cfgid, "preproxy_node", preproxy_node_group)
|
||||
uci_set(cfgid, "chain_proxy", "1")
|
||||
uci_set(cfgid, "preproxy_node", preproxy_node_group)
|
||||
elseif to_node_group ~= "" then
|
||||
uci:set(c_config, cfgid, "chain_proxy", "2")
|
||||
uci:set(c_config, cfgid, "to_node", to_node_group)
|
||||
uci_set(cfgid, "chain_proxy", "2")
|
||||
uci_set(cfgid, "to_node", to_node_group)
|
||||
elseif outbound_iface_group ~= "" then
|
||||
uci:set(c_config, cfgid, "chain_proxy", "3")
|
||||
uci:set(c_config, cfgid, "outbound_iface", outbound_iface_group)
|
||||
uci_set(cfgid, "chain_proxy", "3")
|
||||
uci_set(cfgid, "outbound_iface", outbound_iface_group)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1993,16 +1992,16 @@ local function update_node(manual)
|
||||
for cfgid, info in pairs(subscribe_info) do
|
||||
for key, value in pairs(info) do
|
||||
if value ~= "" then
|
||||
uci:set(c_config, cfgid, key, value)
|
||||
uci_set(cfgid, key, value)
|
||||
else
|
||||
uci:delete(c_config, cfgid, key)
|
||||
uci_del(cfgid, key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if next(CONFIG) then
|
||||
local nodes = {}
|
||||
uci:foreach(c_config, "nodes", function(node)
|
||||
uci_foreach("nodes", function(node)
|
||||
nodes[#nodes + 1] = node
|
||||
end)
|
||||
|
||||
@@ -2021,16 +2020,16 @@ local function update_node(manual)
|
||||
end
|
||||
end
|
||||
|
||||
api.uci_save(uci, c_config, true)
|
||||
uci_save(true)
|
||||
|
||||
if arg[3] == "cron" then
|
||||
if not fs.access("/var/lock/" .. c_config .. ".lock") then
|
||||
luci.sys.call("touch /tmp/lock/" .. c_config .. "_cron.lock")
|
||||
if not fs.access(api.LOCK_PREFIX .. ".lock") then
|
||||
luci.sys.call("touch %s_cron.lock" % api.LOCK_PREFIX)
|
||||
end
|
||||
end
|
||||
|
||||
if manual ~= 1 then
|
||||
luci.sys.call("/etc/init.d/" .. appname .. " restart > /dev/null 2>&1 &")
|
||||
luci.sys.call("/etc/init.d/passwall restart > /dev/null 2>&1 &")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2134,10 +2133,10 @@ local execute = function()
|
||||
local fail_list = {}
|
||||
if arg[2] ~= "all" then
|
||||
string.gsub(arg[2], '[^' .. "," .. ']+', function(w)
|
||||
subscribe_list[#subscribe_list + 1] = uci:get_all(c_config, w) or {}
|
||||
subscribe_list[#subscribe_list + 1] = uci_get(w) or {}
|
||||
end)
|
||||
else
|
||||
uci:foreach(c_config, "subscribe_list", function(o)
|
||||
uci_foreach("subscribe_list", function(o)
|
||||
subscribe_list[#subscribe_list + 1] = o
|
||||
end)
|
||||
end
|
||||
@@ -2183,7 +2182,7 @@ local execute = function()
|
||||
raw_data = parseClashNode(raw_data)
|
||||
subscribe_info[cfgid] = parse_clash_sub_info(headers)
|
||||
parse_link(raw_data, "2", remark, value)
|
||||
uci:set(c_config, cfgid, "md5", new_md5)
|
||||
uci_set(cfgid, "md5", new_md5)
|
||||
end
|
||||
else
|
||||
fail_list[#fail_list + 1] = value
|
||||
@@ -2206,8 +2205,8 @@ local execute = function()
|
||||
end
|
||||
|
||||
local function check_instance(action)
|
||||
local sub_lock = "/var/lock/" .. appname .. "_subscribe.lock"
|
||||
local rule_lock = "/var/lock/" .. appname .. "_rule_update.lock"
|
||||
local sub_lock = api.LOCK_PREFIX .. "_subscribe.lock"
|
||||
local rule_lock = api.LOCK_PREFIX .. "_rule_update.lock"
|
||||
|
||||
if action == "start" then
|
||||
math.randomseed(os.time() + math.floor(os.clock() * 1000))
|
||||
|
||||
Reference in new issue
Block a user