mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-30 06:35:13 +08:00
update 2026-08-14 04:36:07
This commit is contained in:
1 parent
e716bb6996
commit
5ce413d3a3
74 files changed
+693
-819
No files matched your search
Executable → Regular
-11
@@ -5,9 +5,6 @@ if [ -e "/etc/config/ucitrack" ]; then
|
||||
delete ucitrack.@passwall2[-1]
|
||||
add ucitrack passwall2
|
||||
set ucitrack.@passwall2[-1].init=passwall2
|
||||
delete ucitrack.@passwall2_server[-1]
|
||||
add ucitrack passwall2_server
|
||||
set ucitrack.@passwall2_server[-1].init=passwall2_server
|
||||
commit ucitrack
|
||||
EOF
|
||||
fi
|
||||
@@ -18,11 +15,6 @@ uci -q batch <<-EOF
|
||||
set firewall.passwall2.type='script'
|
||||
set firewall.passwall2.path='/var/etc/passwall2.include'
|
||||
|
||||
delete firewall.passwall2_server
|
||||
set firewall.passwall2_server=include
|
||||
set firewall.passwall2_server.type='script'
|
||||
set firewall.passwall2_server.path='/var/etc/passwall2_server.include'
|
||||
|
||||
set dhcp.@dnsmasq[0].localuse=1
|
||||
commit dhcp
|
||||
|
||||
@@ -32,12 +24,9 @@ EOF
|
||||
|
||||
if [ -x "/sbin/fw3" ]; then
|
||||
uci -q set firewall.passwall2.reload='1'
|
||||
uci -q set firewall.passwall2_server.reload='1'
|
||||
else
|
||||
uci -q delete firewall.passwall2.reload
|
||||
uci -q delete firewall.passwall2.fw4_compatible
|
||||
uci -q delete firewall.passwall2_server.reload
|
||||
uci -q delete firewall.passwall2_server.fw4_compatible
|
||||
fi
|
||||
uci commit firewall
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -e "/etc/config/ucitrack" ]; then
|
||||
uci -q batch <<-EOF
|
||||
delete ucitrack.@passwall2_server[-1]
|
||||
add ucitrack passwall2_server
|
||||
set ucitrack.@passwall2_server[-1].init=passwall2_server
|
||||
commit ucitrack
|
||||
EOF
|
||||
fi
|
||||
|
||||
uci -q batch <<-EOF
|
||||
delete firewall.passwall2_server
|
||||
set firewall.passwall2_server=include
|
||||
set firewall.passwall2_server.type='script'
|
||||
set firewall.passwall2_server.path='/var/etc/passwall2_server.include'
|
||||
EOF
|
||||
|
||||
if [ -x "/sbin/fw3" ]; then
|
||||
uci -q set firewall.passwall2_server.reload='1'
|
||||
else
|
||||
uci -q delete firewall.passwall2_server.reload
|
||||
uci -q delete firewall.passwall2_server.fw4_compatible
|
||||
fi
|
||||
uci commit firewall
|
||||
|
||||
rm -f /tmp/luci-indexcache /tmp/luci-indexcache.*
|
||||
rm -rf /tmp/luci-modulecache/
|
||||
killall -HUP rpcd 2>/dev/null
|
||||
|
||||
exit 0
|
||||
@@ -351,7 +351,7 @@ run_socks() {
|
||||
[ -n "$config_file" ] && [ -z "$(echo ${config_file} | grep $TMP_PATH)" ] && config_file=$TMP_PATH/$config_file
|
||||
[ -n "$http_port" ] || http_port=0
|
||||
[ -n "$http_config_file" ] && [ -z "$(echo ${http_config_file} | grep $TMP_PATH)" ] && http_config_file=$TMP_PATH/$http_config_file
|
||||
if [ -n "$log_file" ] && [ -z "$(echo ${log_file} | grep $TMP_PATH)" ]; then
|
||||
if [ -n "$log_file" ] && [ "$log_file" != "/dev/null" ] && [ -z "$(echo ${log_file} | grep $TMP_PATH)" ]; then
|
||||
log_file=$TMP_PATH/$log_file
|
||||
else
|
||||
log_file="/dev/null"
|
||||
|
||||
@@ -21,11 +21,11 @@ local haproxy_conf = var["-conf"]
|
||||
local haproxy_dns = "127.0.0.1"
|
||||
|
||||
local cpu_thread = sys.exec('echo -n $(cat /proc/cpuinfo | grep "processor" | wc -l)') or "1"
|
||||
local health_check_type = uci:get(appname, "@global_haproxy[0]", "health_check_type") or "tcp"
|
||||
local health_check_inter = uci:get(appname, "@global_haproxy[0]", "health_check_inter") or "20"
|
||||
local balancingStrategy = uci:get(appname, "@global_haproxy[0]", "balancingStrategy") or "roundrobin"
|
||||
local console_port = uci:get(appname, "@global_haproxy[0]", "console_port")
|
||||
local bind_local = uci:get(appname, "@global_haproxy[0]", "bind_local") or "0"
|
||||
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 bind_address = "0.0.0.0"
|
||||
if bind_local == "1" then bind_address = "127.0.0.1" end
|
||||
|
||||
@@ -92,15 +92,15 @@ f_out:write(haproxy_config)
|
||||
|
||||
local listens = {}
|
||||
|
||||
uci:foreach(appname, "haproxy_config", function(t)
|
||||
uci:foreach(api.c_config, "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(appname, lbss)
|
||||
local hop = (health_check_type == "passwall_logic") and (server_node.hysteria_hop or server_node.hysteria2_hop) or nil
|
||||
local server_node = uci:get_all(api.c_config, 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
|
||||
server_remark = server_node.address .. ":" .. (server_node.port or hop)
|
||||
@@ -108,7 +108,7 @@ uci:foreach(appname, "haproxy_config", function(t)
|
||||
server_port = server_node.port or hop
|
||||
t.origin_address = server_address
|
||||
t.origin_port = server_port
|
||||
if health_check_type == "passwall_logic" then
|
||||
if health_check_type == "script_logic" then
|
||||
if server_node.type ~= "Socks" then
|
||||
local relay_port = server_node.port
|
||||
local new_port = api.get_new_port()
|
||||
@@ -170,7 +170,7 @@ listen %s
|
||||
balance %s
|
||||
]], port, bind_address, port, balancingStrategy))
|
||||
|
||||
if health_check_type == "passwall_logic" then
|
||||
if health_check_type == "script_logic" then
|
||||
f_out:write(string.format([[
|
||||
option external-check
|
||||
external-check command "/usr/share/%s/haproxy_check.sh"
|
||||
@@ -212,8 +212,8 @@ listen %s
|
||||
end
|
||||
|
||||
-- Console config
|
||||
local console_user = uci:get(appname, "@global_haproxy[0]", "console_user")
|
||||
local console_password = uci:get(appname, "@global_haproxy[0]", "console_password")
|
||||
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 str = [[
|
||||
listen console
|
||||
bind 0.0.0.0:%s
|
||||
@@ -228,8 +228,8 @@ f_out:write("\n" .. string.format(str, console_port, (console_user and console_u
|
||||
f_out:close()
|
||||
|
||||
-- Built-in health check URL
|
||||
if health_check_type == "passwall_logic" then
|
||||
local probeUrl = uci:get(appname, "@global_haproxy[0]", "health_probe_url") or "https://www.google.com/generate_204"
|
||||
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 f_url = io.open(haproxy_path .. "/Probe_URL", "w")
|
||||
f_url:write(probeUrl)
|
||||
f_url:close()
|
||||
|
||||
@@ -25,7 +25,7 @@ end
|
||||
local function backup_servers()
|
||||
local DNSMASQ_DNS = uci:get("dhcp", "@dnsmasq[0]", "server")
|
||||
if DNSMASQ_DNS and #DNSMASQ_DNS > 0 then
|
||||
uci:set(appname, "@global[0]", "dnsmasq_servers", DNSMASQ_DNS)
|
||||
uci:set(api.c_config, "@global[0]", "dnsmasq_servers", DNSMASQ_DNS)
|
||||
api.uci_save(uci, appname, true)
|
||||
end
|
||||
end
|
||||
@@ -38,12 +38,12 @@ local function restore_servers()
|
||||
tinsert(dns_table, v)
|
||||
end
|
||||
end
|
||||
local OLD_SERVER = uci:get(appname, "@global[0]", "dnsmasq_servers")
|
||||
local OLD_SERVER = 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(appname, "@global[0]", "dnsmasq_servers")
|
||||
uci:delete(api.c_config, "@global[0]", "dnsmasq_servers")
|
||||
api.uci_save(uci, appname, true)
|
||||
end
|
||||
if dns_table and #dns_table > 0 then
|
||||
@@ -268,7 +268,7 @@ function add_rule(var)
|
||||
-- Always use domestic DNS to resolve node domain names
|
||||
if true then
|
||||
fwd_dns = LOCAL_DNS
|
||||
uci:foreach(appname, "nodes", function(t)
|
||||
uci:foreach(api.c_config, "nodes", function(t)
|
||||
local function process_address(address)
|
||||
address = (address or ""):lower()
|
||||
if address == "engage.cloudflareclient.com" then return end
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
local api = require "luci.passwall2.api"
|
||||
local name = api.appname
|
||||
local c_config = api.c_config
|
||||
local fs = api.fs
|
||||
local log = api.log
|
||||
local sys = api.sys
|
||||
local uci = api.uci
|
||||
local jsonc = api.jsonc
|
||||
|
||||
local arg1 = arg[1]
|
||||
local arg2 = arg[2]
|
||||
@@ -16,9 +16,9 @@ local reboot = 0
|
||||
local geoip_update = "0"
|
||||
local geosite_update = "0"
|
||||
|
||||
local geoip_url = uci:get(name, "@global_rules[0]", "geoip_url") or "https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip.dat"
|
||||
local geosite_url = uci:get(name, "@global_rules[0]", "geosite_url") or "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
|
||||
local asset_location = uci:get(name, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
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/"
|
||||
asset_location = asset_location:match("/$") and asset_location or (asset_location .. "/")
|
||||
local backup_path = "/tmp/bak_v2ray/"
|
||||
|
||||
@@ -134,7 +134,7 @@ local function fetch_geofile(geo_name, geo_type, url)
|
||||
reboot = 1
|
||||
log(1, api.i18n.translatef("%s update success.", geo_type))
|
||||
else
|
||||
log(1, api.i18n.translatef("%s update failed, please try again later.", geo_type))
|
||||
log(1, api.i18n.translatef("%s update failed, please try again later or change URL.", geo_type))
|
||||
return 1
|
||||
end
|
||||
else
|
||||
@@ -148,7 +148,7 @@ local function fetch_geofile(geo_name, geo_type, url)
|
||||
log(1, api.i18n.translatef("%s update success.", geo_type))
|
||||
end
|
||||
else
|
||||
log(1, api.i18n.translatef("%s update failed, please try again later.", geo_type))
|
||||
log(1, api.i18n.translatef("%s update failed, please try again later or change URL.", geo_type))
|
||||
return 1
|
||||
end
|
||||
return 0
|
||||
@@ -177,8 +177,8 @@ if arg2 then
|
||||
end
|
||||
end)
|
||||
else
|
||||
geoip_update = uci:get(name, "@global_rules[0]", "geoip_update") or "1"
|
||||
geosite_update = uci:get(name, "@global_rules[0]", "geosite_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"
|
||||
end
|
||||
if geoip_update == "0" and geosite_update == "0" then
|
||||
os.exit(0)
|
||||
@@ -233,9 +233,9 @@ if geosite_update == "1" then
|
||||
remove_tmp_geofile("geosite")
|
||||
end
|
||||
|
||||
uci:set(name, "@global_rules[0]", "geoip_update", geoip_update)
|
||||
uci:set(name, "@global_rules[0]", "geosite_update", geosite_update)
|
||||
api.uci_save(uci, name, true)
|
||||
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)
|
||||
|
||||
if reboot == 1 then
|
||||
if arg3 == "cron" then
|
||||
@@ -245,8 +245,8 @@ if reboot == 1 then
|
||||
end
|
||||
|
||||
log(1, api.i18n.translate("Restart the service and apply the new rules."))
|
||||
uci:set(name, "@global[0]", "flush_set", "1")
|
||||
api.uci_save(uci, name, true, true)
|
||||
uci:set(c_config, "@global[0]", "flush_set", "1")
|
||||
api.uci_save(uci, c_config, true, true)
|
||||
end
|
||||
log(0, api.i18n.translate("The rules have been updated..."))
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
require 'luci.util'
|
||||
require 'luci.jsonc'
|
||||
require 'luci.sys'
|
||||
local appname = 'passwall2'
|
||||
local api = require ("luci.passwall2.api")
|
||||
local api = require "luci.passwall2.api"
|
||||
local appname = api.appname
|
||||
local c_config = api.c_config
|
||||
local datatypes = require "luci.cbi.datatypes"
|
||||
|
||||
-- these global functions are accessed all the time by the event handler
|
||||
@@ -31,9 +32,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(appname, "@global_subscribe[0]", "filter_keyword_mode") or "0"
|
||||
local DEFAULT_FILTER_KEYWORD_DISCARD_LIST = uci:get(appname, "@global_subscribe[0]", "filter_discard_list") or {}
|
||||
local DEFAULT_FILTER_KEYWORD_KEEP_LIST = uci:get(appname, "@global_subscribe[0]", "filter_keep_list") or {}
|
||||
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 {}
|
||||
-- Nodes should be retrieved using the core type (if not set on the node subscription page, the default type will be used automatically).
|
||||
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"}})
|
||||
@@ -130,13 +131,13 @@ do
|
||||
local szType = "@global[0]"
|
||||
local option = "node"
|
||||
|
||||
local node_id = uci:get(appname, szType, option)
|
||||
local node_id = uci:get(c_config, szType, option)
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
remarks = i18n.translatef("Node"),
|
||||
currentNode = node_id and uci:get_all(appname, node_id) or nil,
|
||||
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(appname, szType, option, server)
|
||||
uci:set(c_config, szType, option, server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
@@ -145,7 +146,7 @@ do
|
||||
if true then
|
||||
local i = 0
|
||||
local option = "node"
|
||||
uci:foreach(appname, "socks", function(t)
|
||||
uci:foreach(c_config, "socks", function(t)
|
||||
i = i + 1
|
||||
local id = t[".name"]
|
||||
local node_id = t[option]
|
||||
@@ -153,14 +154,14 @@ do
|
||||
log = true,
|
||||
id = id,
|
||||
remarks = i18n.translatef("Socks node list [%s]", i),
|
||||
currentNode = node_id and uci:get_all(appname, node_id) or nil,
|
||||
currentNode = node_id and uci:get_all(c_config, 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(appname, t[".name"], option, server)
|
||||
uci:set(c_config, t[".name"], option, server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
@@ -170,7 +171,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(appname, asb_node_id) or {}
|
||||
local currentNode = uci:get_all(c_config, asb_node_id) or {}
|
||||
if currentNode[".type"] == "nodes" then
|
||||
currentNodes[#currentNodes + 1] = {
|
||||
log = true,
|
||||
@@ -192,7 +193,7 @@ do
|
||||
set = function(o, newNodes)
|
||||
if o then
|
||||
if not newNodes then newNodes = o.newNodes end
|
||||
uci:set_list(appname, id, "autoswitch_backup_node", newNodes or {})
|
||||
uci:set_list(c_config, id, "autoswitch_backup_node", newNodes or {})
|
||||
end
|
||||
end
|
||||
}
|
||||
@@ -208,25 +209,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(appname, "haproxy_config", function(t)
|
||||
uci:foreach(c_config, "haproxy_config", function(t)
|
||||
i = i + 1
|
||||
local node_id = t[option]
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = t[".name"],
|
||||
remarks = i18n.translatef("HAProxy node list [%s]", i),
|
||||
currentNode = node_id and uci:get_all(appname, node_id) or nil,
|
||||
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
|
||||
set = function(o, server)
|
||||
-- Modify the LBS value only if it is not in IP:Port format.
|
||||
if not is_ip_port(t[option]) then
|
||||
uci:set(appname, t[".name"], option, server)
|
||||
uci:set(c_config, t[".name"], option, server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
end,
|
||||
delete = function(o)
|
||||
-- Deletion is only performed if the current LBS value is not in IP:port format.
|
||||
if not is_ip_port(t[option]) then
|
||||
uci:delete(appname, t[".name"])
|
||||
uci:delete(c_config, t[".name"])
|
||||
end
|
||||
end
|
||||
}
|
||||
@@ -235,7 +236,7 @@ do
|
||||
|
||||
if true then
|
||||
local i = 0
|
||||
uci:foreach(appname, "acl_rule", function(t)
|
||||
uci:foreach(c_config, "acl_rule", function(t)
|
||||
i = i + 1
|
||||
local option = "node"
|
||||
local node_id = t[option]
|
||||
@@ -243,20 +244,20 @@ do
|
||||
log = true,
|
||||
id = t[".name"],
|
||||
remarks = i18n.translatef("ACL list [%s]", i),
|
||||
currentNode = node_id and uci:get_all(appname, node_id) or nil,
|
||||
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(appname, t[".name"], option, server)
|
||||
uci:set(c_config, t[".name"], option, server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
end)
|
||||
end
|
||||
|
||||
uci:foreach(appname, "nodes", function(node)
|
||||
uci:foreach(c_config, "nodes", function(node)
|
||||
local node_id = node[".name"]
|
||||
if node.protocol and node.protocol == '_shunt' then
|
||||
local rules = {}
|
||||
uci:foreach(appname, "shunt_rules", function(e)
|
||||
uci:foreach(c_config, "shunt_rules", function(e)
|
||||
if e[".name"] and e.remarks then
|
||||
table.insert(rules, e)
|
||||
table.insert(rules, {
|
||||
@@ -277,7 +278,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(appname, _node_id) or {}
|
||||
local section = uci:get_all(c_config, _node_id) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = false,
|
||||
@@ -285,7 +286,7 @@ do
|
||||
remarks = i18n.translatef("Shunt [%s] node", e.remarks),
|
||||
set = function(o, server)
|
||||
if not server then server = "" end
|
||||
uci:set(appname, node_id, e[".name"], server)
|
||||
uci:set(c_config, node_id, e[".name"], server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
@@ -302,7 +303,7 @@ do
|
||||
log = true,
|
||||
node = b_node_id,
|
||||
currentNode = (function()
|
||||
local section = uci:get_all(appname, b_node_id) or {}
|
||||
local section = uci:get_all(c_config, b_node_id) or {}
|
||||
if section[".type"] == "socks" then
|
||||
return { Socks = b_node_id }
|
||||
end
|
||||
@@ -324,15 +325,15 @@ do
|
||||
set = function(o, newNodes)
|
||||
if o then
|
||||
if not newNodes then newNodes = o.newNodes end
|
||||
uci:set_list(appname, node_id, "balancing_node", newNodes or {})
|
||||
uci:set_list(c_config, node_id, "balancing_node", newNodes or {})
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
-- Backup Node
|
||||
local currentNode = uci:get_all(appname, node_id) or nil
|
||||
local currentNode = uci:get_all(c_config, node_id) or nil
|
||||
if currentNode and currentNode.fallback_node then
|
||||
local section = uci:get_all(appname, currentNode.fallback_node) or {}
|
||||
local section = uci:get_all(c_config, currentNode.fallback_node) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
@@ -340,11 +341,11 @@ do
|
||||
remarks = i18n.translatef("Xray Load Balancing node [%s] backup node", node_id),
|
||||
currentNode = section,
|
||||
set = function(o, server)
|
||||
uci:set(appname, node_id, "fallback_node", server)
|
||||
uci:set(c_config, node_id, "fallback_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(appname, node_id, "fallback_node")
|
||||
uci:delete(c_config, node_id, "fallback_node")
|
||||
end
|
||||
}
|
||||
end
|
||||
@@ -359,7 +360,7 @@ do
|
||||
log = true,
|
||||
node = u_node_id,
|
||||
currentNode = (function()
|
||||
local section = uci:get_all(appname, u_node_id) or {}
|
||||
local section = uci:get_all(c_config, u_node_id) or {}
|
||||
if section[".type"] == "socks" then
|
||||
return { Socks = u_node_id }
|
||||
end
|
||||
@@ -381,47 +382,47 @@ do
|
||||
set = function(o, newNodes)
|
||||
if o then
|
||||
if not newNodes then newNodes = o.newNodes end
|
||||
uci:set_list(appname, node_id, "urltest_node", newNodes or {})
|
||||
uci:set_list(c_config, node_id, "urltest_node", newNodes or {})
|
||||
end
|
||||
end
|
||||
}
|
||||
else
|
||||
-- Preproxy Node
|
||||
local currentNode = uci:get_all(appname, node_id) or nil
|
||||
local currentNode = uci:get_all(c_config, node_id) or nil
|
||||
if currentNode and currentNode.preproxy_node then
|
||||
local section = uci:get_all(appname, currentNode.preproxy_node) or {}
|
||||
local section = uci:get_all(c_config, currentNode.preproxy_node) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = i18n.translatef("Node [%s] preproxy node", node_id),
|
||||
currentNode = uci:get_all(appname, currentNode.preproxy_node) or nil,
|
||||
currentNode = uci:get_all(c_config, currentNode.preproxy_node) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(appname, node_id, "preproxy_node", server)
|
||||
uci:set(c_config, node_id, "preproxy_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(appname, node_id, "preproxy_node")
|
||||
uci:delete(c_config, node_id, "preproxy_node")
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
-- Landing node
|
||||
local currentNode = uci:get_all(appname, node_id) or nil
|
||||
local currentNode = uci:get_all(c_config, node_id) or nil
|
||||
if currentNode and currentNode.to_node then
|
||||
local section = uci:get_all(appname, currentNode.to_node) or {}
|
||||
local section = uci:get_all(c_config, currentNode.to_node) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = i18n.translatef("Node [%s] landing node", node_id),
|
||||
currentNode = uci:get_all(appname, currentNode.to_node) or nil,
|
||||
currentNode = uci:get_all(c_config, currentNode.to_node) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(appname, node_id, "to_node", server)
|
||||
uci:set(c_config, node_id, "to_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(appname, node_id, "to_node")
|
||||
uci:delete(c_config, node_id, "to_node")
|
||||
end
|
||||
}
|
||||
end
|
||||
@@ -2083,19 +2084,19 @@ local function truncate_nodes(group)
|
||||
end
|
||||
end
|
||||
end
|
||||
uci:foreach(appname, "nodes", function(node)
|
||||
uci:foreach(c_config, "nodes", function(node)
|
||||
if node.add_mode == "2" then
|
||||
if (not group) or (group:lower() == (node.group or ""):lower()) then
|
||||
uci:delete(appname, node['.name'])
|
||||
uci:delete(c_config, node['.name'])
|
||||
end
|
||||
end
|
||||
end)
|
||||
uci:foreach(appname, "subscribe_list", function(o)
|
||||
uci:foreach(c_config, "subscribe_list", function(o)
|
||||
if (not group) or (group:lower() == (o.remark or ""):lower()) then
|
||||
uci:delete(appname, o['.name'], "md5")
|
||||
uci:delete(c_config, o['.name'], "md5")
|
||||
end
|
||||
end)
|
||||
api.uci_save(uci, appname, true)
|
||||
api.uci_save(uci, c_config, true)
|
||||
end
|
||||
|
||||
local function select_node(nodes, config, parentConfig)
|
||||
@@ -2238,10 +2239,10 @@ local function update_node(manual)
|
||||
end
|
||||
|
||||
if manual == 0 and next(group) then
|
||||
uci:foreach(appname, "nodes", function(node)
|
||||
uci:foreach(c_config, "nodes", function(node)
|
||||
-- Do not delete nodes if no new nodes are found or nodes were manually imported...
|
||||
if node.add_mode == "2" and (node.group and group[node.group:lower()] == true) then
|
||||
uci:delete(appname, node['.name'])
|
||||
uci:delete(c_config, node['.name'])
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -2254,9 +2255,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(appname, node, "chain_proxy") or ""
|
||||
local am = uci:get(appname, node, "add_mode") or "0"
|
||||
chain_node_type = (cp == "" and am ~= "2") and (uci:get(appname, node, "type") or "") or ""
|
||||
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 ""
|
||||
if chain_node_type ~= "Xray" and chain_node_type ~= "sing-box" then
|
||||
chain_node_type = ""
|
||||
return ""
|
||||
@@ -2274,42 +2275,42 @@ local function update_node(manual)
|
||||
chain_node_type = (outbound_iface_group ~= "") and "iface" or chain_node_type
|
||||
end
|
||||
for _, vv in ipairs(list) do
|
||||
local cfgid = uci:section(appname, "nodes", api.gen_random_char())
|
||||
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(appname, cfgid, kkk, vvv)
|
||||
uci:set_list(c_config, cfgid, kkk, vvv)
|
||||
else
|
||||
if kkk ~= "group" or vvv ~= "default" then
|
||||
uci:set(appname, cfgid, kkk, vvv)
|
||||
uci:set(c_config, cfgid, kkk, vvv)
|
||||
end
|
||||
-- Sing-Box Node Domain resolver
|
||||
if kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then
|
||||
if domain_resolver then
|
||||
uci:set(appname, cfgid, "domain_resolver", domain_resolver)
|
||||
uci:set(c_config, cfgid, "domain_resolver", domain_resolver)
|
||||
if domain_resolver_dns then
|
||||
uci:set(appname, cfgid, "domain_resolver_dns", domain_resolver_dns)
|
||||
uci:set(c_config, cfgid, "domain_resolver_dns", domain_resolver_dns)
|
||||
elseif domain_resolver_dns_https then
|
||||
uci:set(appname, cfgid, "domain_resolver_dns_https", domain_resolver_dns_https)
|
||||
uci:set(c_config, cfgid, "domain_resolver_dns_https", domain_resolver_dns_https)
|
||||
end
|
||||
end
|
||||
if domain_strategy then
|
||||
if vvv == "sing-box" then
|
||||
domain_strategy = (domain_strategy == "UseIPv4" and "ipv4_only") or (domain_strategy == "UseIPv6" and "ipv6_only") or domain_strategy
|
||||
end
|
||||
uci:set(appname, cfgid, "domain_strategy", domain_strategy)
|
||||
uci:set(c_config, cfgid, "domain_strategy", domain_strategy)
|
||||
end
|
||||
end
|
||||
-- Subscription Group Chain Agent
|
||||
if chain_node_type ~= "" and kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then
|
||||
if preproxy_node_group ~="" then
|
||||
uci:set(appname, cfgid, "chain_proxy", "1")
|
||||
uci:set(appname, cfgid, "preproxy_node", preproxy_node_group)
|
||||
uci:set(c_config, cfgid, "chain_proxy", "1")
|
||||
uci:set(c_config, cfgid, "preproxy_node", preproxy_node_group)
|
||||
elseif to_node_group ~= "" then
|
||||
uci:set(appname, cfgid, "chain_proxy", "2")
|
||||
uci:set(appname, cfgid, "to_node", to_node_group)
|
||||
uci:set(c_config, cfgid, "chain_proxy", "2")
|
||||
uci:set(c_config, cfgid, "to_node", to_node_group)
|
||||
elseif outbound_iface_group ~= "" then
|
||||
uci:set(appname, cfgid, "chain_proxy", "3")
|
||||
uci:set(appname, cfgid, "outbound_iface", outbound_iface_group)
|
||||
uci:set(c_config, cfgid, "chain_proxy", "3")
|
||||
uci:set(c_config, cfgid, "outbound_iface", outbound_iface_group)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2320,16 +2321,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(appname, cfgid, key, value)
|
||||
uci:set(c_config, cfgid, key, value)
|
||||
else
|
||||
uci:delete(appname, cfgid, key)
|
||||
uci:delete(c_config, cfgid, key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if next(CONFIG) then
|
||||
local nodes = {}
|
||||
uci:foreach(appname, "nodes", function(node)
|
||||
uci:foreach(c_config, "nodes", function(node)
|
||||
nodes[#nodes + 1] = node
|
||||
end)
|
||||
|
||||
@@ -2351,7 +2352,7 @@ local function update_node(manual)
|
||||
end
|
||||
end
|
||||
|
||||
api.uci_save(uci, appname, true)
|
||||
api.uci_save(uci, c_config, true)
|
||||
|
||||
if arg[3] == "cron" then
|
||||
if not fs.access("/var/lock/" .. appname .. ".lock") then
|
||||
@@ -2484,10 +2485,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(appname, w) or {}
|
||||
subscribe_list[#subscribe_list + 1] = uci:get_all(c_config, w) or {}
|
||||
end)
|
||||
else
|
||||
uci:foreach(appname, "subscribe_list", function(o)
|
||||
uci:foreach(c_config, "subscribe_list", function(o)
|
||||
subscribe_list[#subscribe_list + 1] = o
|
||||
end)
|
||||
end
|
||||
@@ -2530,7 +2531,7 @@ local execute = function()
|
||||
log(1, i18n.translatef("Subscription: [%s] No changes, no update required.", remark))
|
||||
else
|
||||
parse_link(raw_data, "2", remark, value)
|
||||
uci:set(appname, cfgid, "md5", new_md5)
|
||||
uci:set(c_config, cfgid, "md5", new_md5)
|
||||
end
|
||||
else
|
||||
fail_list[#fail_list + 1] = value
|
||||
@@ -2564,7 +2565,7 @@ local function check_instance(action)
|
||||
os.exit(0)
|
||||
else
|
||||
luci.sys.call("touch " .. sub_lock)
|
||||
uci:revert(appname)
|
||||
uci:revert(c_config)
|
||||
end
|
||||
elseif action == "end" then
|
||||
luci.sys.call("rm -f " .. sub_lock)
|
||||
|
||||
Reference in new issue
Block a user