luci-app-passwall: bump to 4-6

This commit is contained in:
xiaorouji 2021-01-04 19:35:26 +08:00 committed by CN_SZTL
parent 4bfb7abcbd
commit 6bb37834f0
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
23 changed files with 327 additions and 578 deletions

View File

@ -7,8 +7,8 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall
PKG_VERSION:=4
PKG_RELEASE:=4
PKG_DATE:=20201221
PKG_RELEASE:=6
PKG_DATE:=20210104
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
@ -136,10 +136,6 @@ define Package/$(PKG_NAME)/conffiles
/usr/share/passwall/rules/direct_ip
/usr/share/passwall/rules/proxy_host
/usr/share/passwall/rules/proxy_ip
/usr/share/passwall/rules/proxy_host2
/usr/share/passwall/rules/proxy_ip2
/usr/share/passwall/rules/proxy_host3
/usr/share/passwall/rules/proxy_ip3
endef
define Package/$(PKG_NAME)/install

View File

@ -135,21 +135,13 @@ end
function get_now_use_node()
local e = {}
local tcp_node_num = ucic:get(appname, "@global_other[0]", "tcp_node_num") or 1
e.tcp = tonumber(tcp_node_num)
for i = 1, tcp_node_num, 1 do
local data, code, msg = nixio.fs.readfile("/var/etc/passwall/id/TCP_" .. i)
if data then
e["TCP" .. i] = util.trim(data)
end
local data, code, msg = nixio.fs.readfile("/var/etc/passwall/id/TCP")
if data then
e["TCP"] = util.trim(data)
end
local udp_node_num = ucic:get(appname, "@global_other[0]", "udp_node_num") or 1
e.udp = tonumber(udp_node_num)
for i = 1, udp_node_num, 1 do
local data, code, msg = nixio.fs.readfile("/var/etc/passwall/id/UDP_" .. i)
if data then
e["UDP" .. i] = util.trim(data)
end
local data, code, msg = nixio.fs.readfile("/var/etc/passwall/id/UDP")
if data then
e["UDP"] = util.trim(data)
end
luci.http.prepare_content("application/json")
luci.http.write_json(e)
@ -158,8 +150,7 @@ end
function get_redir_log()
local proto = luci.http.formvalue("proto")
proto = proto:upper()
local index = luci.http.formvalue("index")
local filename = proto .. "_" .. index
local filename = proto
if nixio.fs.access("/var/etc/passwall/" .. filename .. ".log") then
local content = luci.sys.exec("cat /var/etc/passwall/" .. filename .. ".log")
content = content:gsub("\n", "<br />")
@ -183,19 +174,13 @@ function status()
local e = {}
e.dns_mode_status = luci.sys.call("netstat -apn | grep ':7913 ' >/dev/null") == 0
e.haproxy_status = luci.sys.call(string.format("ps -w | grep -v grep | grep '%s/bin/' | grep haproxy >/dev/null", appname)) == 0
local tcp_node_num = ucic:get(appname, "@global_other[0]", "tcp_node_num") or 1
for i = 1, tcp_node_num, 1 do
e["kcptun_tcp_node%s_status" % i] = luci.sys.call(string.format("ps -w | grep -v grep | grep '%s/bin/kcptun' | grep -i 'tcp_%s' >/dev/null", appname, i)) == 0
e["tcp_node%s_status" % i] = luci.sys.call(string.format("ps -w | grep -v -E 'grep|kcptun' | grep '%s/bin/' | grep -i 'TCP_%s' >/dev/null", appname, i)) == 0
end
e["kcptun_tcp_node_status"] = luci.sys.call(string.format("ps -w | grep -v grep | grep '%s/bin/kcptun' | grep -i 'tcp' >/dev/null", appname)) == 0
e["tcp_node_status"] = luci.sys.call(string.format("ps -w | grep -v -E 'grep|kcptun' | grep '%s/bin/' | grep -i 'TCP' >/dev/null", appname)) == 0
local udp_node_num = ucic:get(appname, "@global_other[0]", "udp_node_num") or 1
for i = 1, udp_node_num, 1 do
if (ucic:get(appname, "@global[0]", "udp_node" .. i) or "nil") == "tcp" then
e["udp_node%s_status" % i] = e["tcp_node%s_status" % i]
else
e["udp_node%s_status" % i] = luci.sys.call(string.format("ps -w | grep -v grep | grep '%s/bin/' | grep -i 'UDP_%s' >/dev/null", appname, i)) == 0
end
if (ucic:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" then
e["udp_node_status"] = e["tcp_node_status"]
else
e["udp_node_status"] = luci.sys.call(string.format("ps -w | grep -v grep | grep '%s/bin/' | grep -i 'UDP' >/dev/null", appname)) == 0
end
luci.http.prepare_content("application/json")
luci.http.write_json(e)
@ -255,9 +240,8 @@ end
function set_node()
local protocol = luci.http.formvalue("protocol")
local number = luci.http.formvalue("number")
local section = luci.http.formvalue("section")
ucic:set(appname, "@global[0]", protocol .. "_node" .. number, section)
ucic:set(appname, "@global[0]", protocol .. "_node", section)
ucic:commit(appname)
luci.sys.call("/etc/init.d/passwall restart > /dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", appname, "log"))

View File

@ -155,6 +155,7 @@ function gen_outbound(node, tag, relay_port)
address = node.address,
port = tonumber(node.port),
method = node.method or nil,
flow = node.flow or nil,
password = node.password or "",
users = (node.username and node.password) and
{{user = node.username, pass = node.password}} or nil

View File

@ -40,20 +40,6 @@ o = s:option(Value, "mac", translate("MAC"))
o.rmempty = true
sys.net.mac_hints(function(e, t) o:value(e, "%s (%s)" % {e, t}) end)
---- TCP Node
local tcp_node_num = m:get("@global_other[0]", "tcp_node_num") or 1
if tonumber(tcp_node_num) > 1 then
o = s:option(ListValue, "tcp_node", translate("TCP Node"))
for i = 1, tcp_node_num, 1 do o:value(i, "TCP_" .. i) end
end
---- UDP Node
local udp_node_num = m:get("@global_other[0]", "udp_node_num") or 1
if tonumber(udp_node_num) > 1 then
o = s:option(ListValue, "udp_node", translate("UDP Node"))
for i = 1, udp_node_num, 1 do o:value(i, "UDP_" .. i) end
end
---- TCP Proxy Mode
o = s:option(ListValue, "tcp_proxy_mode", "TCP" .. translate("Proxy Mode"))
o.default = "default"

View File

@ -25,22 +25,16 @@ o.rmempty = false
o = s:option(Value, "testing_time", translate("How often is a diagnosis made"), translate("Units:minutes"))
o.default = "3"
---- TCP Node
-- local tcp_node_num = tonumber(m:get("@global_other[0]", "tcp_node_num") or 1)
-- 暂时只支持TCP1
local tcp_node_num = 1
for i = 1, tcp_node_num, 1 do
o = s:option(ListValue, "tcp_main" .. i, "TCP " .. i .. " " .. translate("Main node"))
for k, v in pairs(nodes_table) do
o:value(v.id, v.remarks)
end
o = s:option(ListValue, "tcp_main", "TCP " .. translate("Main node"))
for k, v in pairs(nodes_table) do
o:value(v.id, v.remarks)
end
o = s:option(DynamicList, "tcp_node" .. i, "TCP " .. i .. " " .. translate("List of backup nodes"))
for k, v in pairs(nodes_table) do
o:value(v.id, v.remarks)
end
o = s:option(Flag, "restore_switch" .. i, "TCP " .. i .. " " .. translate("Restore Switch"), translate("When detects main node is available, switch back to the main node."))
o = s:option(DynamicList, "tcp_node", "TCP " .. translate("List of backup nodes"))
for k, v in pairs(nodes_table) do
o:value(v.id, v.remarks)
end
o = s:option(Flag, "restore_switch", "TCP " .. translate("Restore Switch"), translate("When detects main node is available, switch back to the main node."))
return m

View File

@ -74,62 +74,51 @@ o = s:taboption("Main", Flag, "enabled", translate("Main switch"))
o.rmempty = false
---- TCP Node
local tcp_node_num = tonumber(m:get("@global_other[0]", "tcp_node_num") or 1)
for i = 1, tcp_node_num, 1 do
o = s:taboption("Main", ListValue, "tcp_node" .. i, translate("TCP Node") .. " " .. i)
if i == 1 then
o.title = translate("TCP Node")
o.description = ""
--o.description = translate("For proxy specific list.")
--o.description = o.description .. "<br />"
local current_node = luci.sys.exec(string.format("[ -f '/var/etc/%s/id/TCP_%s' ] && echo -n $(cat /var/etc/%s/id/TCP_%s)", appname, i, appname, i))
if current_node and current_node ~= "" and current_node ~= "nil" then
local n = uci:get_all(appname, current_node)
if n then
if tonumber(m:get("@auto_switch[0]", "enable") or 0) == 1 then
local remarks = api.get_full_node_remarks(n)
local url = d.build_url("admin", "services", appname, "node_config", current_node)
o.description = o.description .. translatef("Current node: %s", string.format('<a href="%s">%s</a>', url, remarks)) .. "<br />"
end
if n.protocol and n.protocol == "_shunt" then
uci:foreach(appname, "shunt_rules", function(e)
local id = e[".name"]
local remarks = translate(e.remarks)
if n[id] and n[id] ~= "nil" then
local url = d.build_url("admin", "services", appname, "node_config", n[id])
local r = api.get_full_node_remarks(uci:get_all(appname, n[id]))
o.description = o.description .. remarks .. "" .. string.format('<a href="%s">%s</a>', url, r) .. "<br />"
end
end)
local id = "default_node"
local remarks = translate("Default")
if n[id] and n[id] ~= "nil" then
local url = d.build_url("admin", "services", appname, "node_config", n[id])
local r = api.get_full_node_remarks(uci:get_all(appname, n[id]))
o.description = o.description .. remarks .. "" .. string.format('<a href="%s">%s</a>', url, r) .. "<br />"
end
o = s:taboption("Main", ListValue, "tcp_node", translate("TCP Node"))
o.title = translate("TCP Node")
o.description = ""
--o.description = translate("For proxy specific list.")
--o.description = o.description .. "<br />"
local current_node = luci.sys.exec(string.format("[ -f '/var/etc/%s/id/TCP' ] && echo -n $(cat /var/etc/%s/id/TCP)", appname, appname))
if current_node and current_node ~= "" and current_node ~= "nil" then
local n = uci:get_all(appname, current_node)
if n then
if tonumber(m:get("@auto_switch[0]", "enable") or 0) == 1 then
local remarks = api.get_full_node_remarks(n)
local url = d.build_url("admin", "services", appname, "node_config", current_node)
o.description = o.description .. translatef("Current node: %s", string.format('<a href="%s">%s</a>', url, remarks)) .. "<br />"
end
if n.protocol and n.protocol == "_shunt" then
uci:foreach(appname, "shunt_rules", function(e)
local id = e[".name"]
local remarks = translate(e.remarks)
if n[id] and n[id] ~= "nil" then
local url = d.build_url("admin", "services", appname, "node_config", n[id])
local r = api.get_full_node_remarks(uci:get_all(appname, n[id]))
o.description = o.description .. remarks .. "" .. string.format('<a href="%s">%s</a>', url, r) .. "<br />"
end
end)
local id = "default_node"
local remarks = translate("Default")
if n[id] and n[id] ~= "nil" then
local url = d.build_url("admin", "services", appname, "node_config", n[id])
local r = api.get_full_node_remarks(uci:get_all(appname, n[id]))
o.description = o.description .. remarks .. "" .. string.format('<a href="%s">%s</a>', url, r) .. "<br />"
end
end
end
o:value("nil", translate("Close"))
for k, v in pairs(nodes_table) do o:value(v.id, v.remarks) end
end
o:value("nil", translate("Close"))
for k, v in pairs(nodes_table) do o:value(v.id, v.remarks) end
---- UDP Node
local udp_node_num = tonumber(m:get("@global_other[0]", "udp_node_num") or 1)
for i = 1, udp_node_num, 1 do
o = s:taboption("Main", ListValue, "udp_node" .. i, translate("UDP Node") .. " " .. i)
o:value("nil", translate("Close"))
if i == 1 then
o.title = translate("UDP Node")
--o.description = translate("For proxy game network, DNS hijack etc.") .. "<br />" .. translate("The selected server will not use Kcptun.")
o:value("tcp_", translate("Same as the tcp node"))
--o:value("tcp", translate("Same as the tcp node"))
--o:value("tcp_", translate("Same as the tcp node") .. "" .. translate("New process") .. "")
end
for k, v in pairs(nodes_table) do o:value(v.id, v.remarks) end
end
o = s:taboption("Main", ListValue, "udp_node", translate("UDP Node"))
o:value("nil", translate("Close"))
o.title = translate("UDP Node")
--o.description = translate("For proxy game network, DNS hijack etc.") .. "<br />" .. translate("The selected server will not use Kcptun.")
o:value("tcp_", translate("Same as the tcp node"))
--o:value("tcp", translate("Same as the tcp node"))
--o:value("tcp_", translate("Same as the tcp node") .. "" .. translate("New process") .. "")
for k, v in pairs(nodes_table) do o:value(v.id, v.remarks) end
s:tab("DNS", translate("DNS"))
@ -306,14 +295,12 @@ o.default = "default"
o.rmempty = false
s:tab("log", translate("Log"))
for i = 1, tcp_node_num, 1 do
o = s:taboption("log", Flag, "close_log_tcp_" .. i , translate("Close") .. translate("Log") .. " " .. translate("TCP Node") .. " " .. i)
o.rmempty = false
end
for i = 1, udp_node_num, 1 do
o = s:taboption("log", Flag, "close_log_udp_" .. i, translate("Close") .. translate("Log") .. " " .. translate("UDP Node") .. " " .. i)
o.rmempty = false
end
o = s:taboption("log", Flag, "close_log_tcp", translate("Close") .. translate("Log") .. " " .. translate("TCP Node"))
o.rmempty = false
o = s:taboption("log", Flag, "close_log_udp", translate("Close") .. translate("Log") .. " " .. translate("UDP Node"))
o.rmempty = false
loglevel = s:taboption("log", ListValue, "loglevel", "X/V2ray" .. translate("Log Level"))
loglevel.default = "warning"
loglevel:value("debug")
@ -355,10 +342,7 @@ o.default = 1
o.rmempty = false
o = s:option(ListValue, "node", translate("Socks Node"))
local tcp_node_num = tonumber(m:get("@global_other[0]", "tcp_node_num") or 1)
for i = 1, tcp_node_num, 1 do
o:value("tcp" .. i, translatef("Same as the tcp %s node", i))
end
o:value("tcp", translate("Same as the tcp node"))
for k, v in pairs(nodes_table) do o:value(v.id, v.remarks) end
o = s:option(Value, "port", "Socks" .. translate("Listen Port"))

View File

@ -454,8 +454,10 @@ tls:depends("type", "Trojan-Go")
xtls = s:option(Flag, "xtls", translate("XTLS"))
xtls.default = 0
xtls:depends({ type = "Xray", protocol = "vless", tls = "1" })
xtls:depends({ type = "Xray", protocol = "trojan", tls = "1" })
flow = s:option(Value, "flow", translate("flow"))
flow.default = "xtls-rprx-direct"
flow:value("xtls-rprx-origin")
flow:value("xtls-rprx-origin-udp443")
flow:value("xtls-rprx-direct")

View File

@ -121,29 +121,10 @@ o.rmempty = true
--]]
-- [[ Other Settings ]]--
s = m:section(TypedSection, "global_other", translate("Other Settings"),
"<font color='red'>" .. translatef(
"You can only set up a maximum of %s nodes for the time being, Used for access control.",
"3") .. "</font>")
s = m:section(TypedSection, "global_other", translate("Other Settings"))
s.anonymous = true
s.addremove = false
---- TCP Node Number Option
o = s:option(ListValue, "tcp_node_num", "TCP" .. translate("Node Number"))
o.default = "1"
o.rmempty = false
o:value("1")
o:value("2")
o:value("3")
---- UDP Node Number Option
o = s:option(ListValue, "udp_node_num", "UDP" .. translate("Node Number"))
o.default = "1"
o.rmempty = false
o:value("1")
o:value("2")
o:value("3")
o = s:option(MultiValue, "status", translate("Status info"))
o:value("big_icon", translate("Big icon")) -- 大图标
o:value("show_check_port", translate("Show node check")) -- 显示节点检测

View File

@ -17,7 +17,7 @@ s:tab("proxy_list3", translate("Proxy List") .. " 3")
---- Direct Hosts
local direct_host = string.format("/usr/share/%s/rules/direct_host", appname)
o = s:taboption("direct_list", TextValue, "direct_hosts", "", "<font color='red'>" .. translate("Join the direct hosts list of domain names will not proxy.") .. "</font>")
o = s:taboption("direct_list", TextValue, "direct_host", "", "<font color='red'>" .. translate("Join the direct hosts list of domain names will not proxy.") .. "</font>")
o.rows = 15
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(direct_host) or "" end
@ -91,80 +91,4 @@ o.validate = function(self, value)
return value
end
---- Proxy Hosts 2
local proxy_host2 = string.format("/usr/share/%s/rules/proxy_host2", appname)
o = s:taboption("proxy_list2", TextValue, "proxy_host2", "", "<font color='red'>" .. translate("These had been joined websites will use proxy. Please input the domain names of websites,every line can input only one website domain. For example: google.com.") .. "</font>")
o.rows = 15
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(proxy_host2) or "" end
o.write = function(self, section, value) fs.writefile(proxy_host2, value:gsub("\r\n", "\n")) end
o.remove = function(self, section, value) fs.writefile(proxy_host2, "") end
o.validate = function(self, value)
local hosts= {}
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
for index, host in ipairs(hosts) do
if not datatypes.hostname(host) then
return nil, host .. " " .. translate("Not valid domain name, please re-enter!")
end
end
return value
end
---- Proxy IP 2
local proxy_ip2 = string.format("/usr/share/%s/rules/proxy_ip2", appname)
o = s:taboption("proxy_list2", TextValue, "blacklist_ip2", "", "<font color='red'>" .. translate("These had been joined ip addresses will use proxy.Please input the ip address or ip address segment,every line can input only one ip address.For example: 35.24.0.0/24 or 8.8.4.4.") .. "</font>")
o.rows = 15
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(proxy_ip2) or "" end
o.write = function(self, section, value) fs.writefile(proxy_ip2, value:gsub("\r\n", "\n")) end
o.remove = function(self, section, value) fs.writefile(proxy_ip2, "") end
o.validate = function(self, value)
local ipmasks= {}
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
for index, ipmask in ipairs(ipmasks) do
if not datatypes.ipmask4(ipmask) then
return nil, ipmask .. " " .. translate("Not valid IP format, please re-enter!")
end
end
return value
end
---- Proxy Hosts 3
local proxy_host3 = string.format("/usr/share/%s/rules/proxy_host3", appname)
o = s:taboption("proxy_list3", TextValue, "proxy_host3", "", "<font color='red'>" .. translate("These had been joined websites will use proxy. Please input the domain names of websites,every line can input only one website domain. For example: google.com.") .. "</font>")
o.rows = 15
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(proxy_host3) or "" end
o.write = function(self, section, value) fs.writefile(proxy_host3, value:gsub("\r\n", "\n")) end
o.remove = function(self, section, value) fs.writefile(proxy_host3, "") end
o.validate = function(self, value)
local hosts= {}
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
for index, host in ipairs(hosts) do
if not datatypes.hostname(host) then
return nil, host .. " " .. translate("Not valid domain name, please re-enter!")
end
end
return value
end
---- Proxy IP 3
local proxy_ip3 = string.format("/usr/share/%s/rules/proxy_ip3", appname)
o = s:taboption("proxy_list3", TextValue, "blacklist_ip3", "", "<font color='red'>" .. translate("These had been joined ip addresses will use proxy.Please input the ip address or ip address segment,every line can input only one ip address.For example: 35.24.0.0/24 or 8.8.4.4.") .. "</font>")
o.rows = 15
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(proxy_ip3) or "" end
o.write = function(self, section, value) fs.writefile(proxy_ip3, value:gsub("\r\n", "\n")) end
o.remove = function(self, section, value) fs.writefile(proxy_ip3, "") end
o.validate = function(self, value)
local ipmasks= {}
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end)
for index, ipmask in ipairs(ipmasks) do
if not datatypes.ipmask4(ipmask) then
return nil, ipmask .. " " .. translate("Not valid IP format, please re-enter!")
end
end
return value
end
return m

View File

@ -58,6 +58,7 @@ function gen_config(user)
local clients = {}
for i = 1, #user.uuid do
clients[i] = {
flow = (user.xtls and user.xtls == "1") and user.flow or nil,
password = user.uuid[i],
level = tonumber(user.level)
}
@ -77,6 +78,31 @@ function gen_config(user)
}
end
if user.fallback and user.fallback == "1" then
local fallbacks = {}
for i = 1, #user.fallback_list do
local fallbackStr = user.fallback_list[i]
if fallbackStr then
local tmp = {}
string.gsub(fallbackStr, '[^' .. "," .. ']+', function(w)
table.insert(tmp, w)
end)
local dest = tmp[1] or ""
local path = tmp[2]
if dest:find("%.") then
else
dest = tonumber(dest)
end
fallbacks[i] = {
path = path,
dest = dest,
xver = 1
}
end
end
settings.fallbacks = fallbacks
end
routing = {
domainStrategy = "IPOnDemand",
rules = {
@ -110,7 +136,7 @@ function gen_config(user)
network = user.transport,
security = "none",
xtlsSettings = (user.tls and user.tls == "1" and user.xtls and user.xtls == "1") and {
--alpn = {"http/1.1"},
alpn = {"http/1.1"},
disableSystemRoot = false,
certificates = {
{
@ -120,6 +146,7 @@ function gen_config(user)
}
} or nil,
tlsSettings = (user.tls and user.tls == "1") and {
alpn = {"http/1.1"},
disableSystemRoot = false,
certificates = {
{
@ -151,7 +178,7 @@ function gen_config(user)
header = {type = user.mkcp_guise}
} or nil,
wsSettings = (user.transport == "ws") and {
acceptProxyProtocol = false,
acceptProxyProtocol = true,
headers = (user.ws_host) and {Host = user.ws_host} or nil,
path = user.ws_path
} or nil,

View File

@ -297,6 +297,7 @@ tls:depends({ type = "Xray", protocol = "vmess" })
tls:depends({ type = "Xray", protocol = "vless" })
tls:depends({ type = "Xray", protocol = "socks" })
tls:depends({ type = "Xray", protocol = "shadowsocks" })
tls:depends({ type = "Xray", protocol = "trojan" })
tls:depends({ type = "V2ray", protocol = "vmess" })
tls:depends({ type = "V2ray", protocol = "vless" })
tls:depends({ type = "V2ray", protocol = "socks" })
@ -308,15 +309,14 @@ tls:depends("type", "Trojan-Go")
xtls = s:option(Flag, "xtls", translate("XTLS"))
xtls.default = 0
xtls:depends({ type = "Xray", protocol = "vless", tls = "1" })
xtls:depends({ type = "Xray", protocol = "trojan", tls = "1" })
flow = s:option(Value, "flow", translate("flow"))
flow.default = "xtls-rprx-origin"
flow.default = "xtls-rprx-direct"
flow:value("xtls-rprx-origin")
flow:value("xtls-rprx-origin-udp443")
flow:value("xtls-rprx-direct")
flow:value("xtls-rprx-direct-udp443")
flow:value("xtls-rprx-splice")
flow:value("xtls-rprx-splice-udp443")
flow:depends("xtls", "1")
-- [[ TLS部分 ]] --
@ -330,7 +330,7 @@ tls_allowInsecure:depends({ type = "Trojan-Go", tls = "1" })
tls_serverName = s:option(Value, "tls_serverName", translate("Domain"))
tls_serverName:depends("tls", "1")
tls_certificateFile = s:option(Value, "tls_certificateFile", translate("Public key absolute path"), translate("as:") .. "/etc/ssl/fullchain.pem")
tls_certificateFile = s:option(FileUpload, "tls_certificateFile", translate("Public key absolute path"), translate("as:") .. "/etc/ssl/fullchain.pem")
tls_certificateFile.validate = function(self, value, t)
if value and value ~= "" then
if not nixio.fs.access(value) then
@ -341,9 +341,10 @@ tls_certificateFile.validate = function(self, value, t)
end
return nil
end
tls_certificateFile.default = "/etc/config/ssl/" .. arg[1] .. ".pem"
tls_certificateFile:depends("tls", "1")
tls_keyFile = s:option(Value, "tls_keyFile", translate("Private key absolute path"), translate("as:") .. "/etc/ssl/private.key")
tls_keyFile = s:option(FileUpload, "tls_keyFile", translate("Private key absolute path"), translate("as:") .. "/etc/ssl/private.key")
tls_keyFile.validate = function(self, value, t)
if value and value ~= "" then
if not nixio.fs.access(value) then
@ -354,6 +355,7 @@ tls_keyFile.validate = function(self, value, t)
end
return nil
end
tls_keyFile.default = "/etc/config/ssl/" .. arg[1] .. ".key"
tls_keyFile:depends("tls", "1")
tls_sessionTicket = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
@ -509,12 +511,14 @@ quic_guise = s:option(ListValue, "quic_guise", translate("Camouflage Type"))
for a, t in ipairs(header_type_list) do quic_guise:value(t) end
quic_guise:depends("transport", "quic")
-- [[ VLESS Fallback部分 ]]--
--[[
-- [[ Fallback部分 ]]--
fallback = s:option(Flag, "fallback", translate("Fallback"))
fallback:depends({ type = "Xray", protocol = "vless", transport = "tcp", tls = "1" })
fallback:depends({ type = "V2ray", protocol = "vless", transport = "tcp", tls = "1" })
fallback:depends({ type = "Xray", protocol = "vless", transport = "tcp" })
fallback:depends({ type = "Xray", protocol = "trojan", transport = "tcp" })
fallback:depends({ type = "V2ray", protocol = "vless", transport = "tcp" })
fallback:depends({ type = "V2ray", protocol = "trojan", transport = "tcp" })
--[[
fallback_alpn = s:option(Value, "fallback_alpn", "Fallback alpn")
fallback_alpn:depends("fallback", "1")
@ -529,6 +533,9 @@ fallback_xver.default = 0
fallback_xver:depends("fallback", "1")
]]--
fallback_list = s:option(DynamicList, "fallback_list", "Fallback", translate("dest,path"))
fallback_list:depends("fallback", "1")
ss_aead = s:option(Flag, "ss_aead", translate("Shadowsocks2"))
ss_aead:depends("type", "Trojan-Go")
ss_aead.default = "0"

View File

@ -1,7 +1,5 @@
<%
local api = require "luci.model.cbi.passwall.api.api"
local tcp_node_num = api.uci_get_type("global_other", "tcp_node_num", 1)
local udp_node_num = api.uci_get_type("global_other", "udp_node_num", 1)
local auto_switch = api.uci_get_type("auto_switch", "enable", 0)
-%>
<script type="text/javascript">
@ -45,36 +43,29 @@ local auto_switch = api.uci_get_type("auto_switch", "enable", 0)
for (var i = 0; i <= 1; i++) {
var proto = "udp";
var num = <%=udp_node_num%>;
if (i == 0) {
proto = "tcp";
num = <%=tcp_node_num%>;
}
if (num >= 1) {
for (var j = 0; j < num; j++) {
var index = j + 1;
var dom_id = node_id + "-" + proto + "_node" + index;
dom_id = dom_id.replace("cbi-", "cbid-").replace(new RegExp("-", 'g'), ".");
var node_select = document.getElementById(dom_id);
var node_select_value = node_select.value;
if (node_select_value && node_select_value != "nil") {
var v = document.getElementById(dom_id + "-" + node_select_value);
node_select.title = v.text;
var new_a = document.createElement("a");
new_a.innerHTML = "<%:Edit%>";
new_a.href = "#";
new_a.setAttribute("onclick", "location.href='" + '<%=url([[admin]], [[services]], [[passwall]], [[node_config]])%>' + "/" + node_select_value + "'");
var log_a = document.createElement("a");
log_a.innerHTML = "<%:Log%>";
log_a.href = "#";
log_a.setAttribute("onclick", "window.open('" + '<%=url([[admin]], [[services]], [[passwall]], [[get_redir_log]])%>' + "?proto=" + proto + "&index=" + index + "', '_blank')");
node_select.outerHTML = node_select.outerHTML + "&nbsp&nbsp" + new_a.outerHTML + "&nbsp&nbsp" + log_a.outerHTML;
//node_select.parentNode.insertBefore(new_a, node_select.nextSibling);
}
}
var dom_id = node_id + "-" + proto + "_node";
dom_id = dom_id.replace("cbi-", "cbid-").replace(new RegExp("-", 'g'), ".");
var node_select = document.getElementById(dom_id);
var node_select_value = node_select.value;
if (node_select_value && node_select_value != "nil") {
var v = document.getElementById(dom_id + "-" + node_select_value);
node_select.title = v.text;
var new_a = document.createElement("a");
new_a.innerHTML = "<%:Edit%>";
new_a.href = "#";
new_a.setAttribute("onclick", "location.href='" + '<%=url([[admin]], [[services]], [[passwall]], [[node_config]])%>' + "/" + node_select_value + "'");
var log_a = document.createElement("a");
log_a.innerHTML = "<%:Log%>";
log_a.href = "#";
log_a.setAttribute("onclick", "window.open('" + '<%=url([[admin]], [[services]], [[passwall]], [[get_redir_log]])%>' + "?proto=" + proto + "', '_blank')");
node_select.outerHTML = node_select.outerHTML + "&nbsp&nbsp" + new_a.outerHTML + "&nbsp&nbsp" + log_a.outerHTML;
//node_select.parentNode.insertBefore(new_a, node_select.nextSibling);
}
}
}
@ -93,7 +84,7 @@ local auto_switch = api.uci_get_type("auto_switch", "enable", 0)
if (node_select_value && node_select_value != "nil") {
if (global_id != null && node_select_value.indexOf("tcp") == 0) {
var num = node_select_value.replace("tcp", "");
var d = global_id + "-tcp_node" + index;
var d = global_id + "-tcp_node";
d = d.replace("cbi-", "cbid-").replace(new RegExp("-", 'g'), ".");
var dom = document.getElementById(d);
var _node_select_value = dom.value;

View File

@ -2,9 +2,6 @@
local dsp = require "luci.dispatcher"
local api = require "luci.model.cbi.passwall.api.api"
local tcp_node_num = api.uci_get_type("global_other", "tcp_node_num", 1)
local udp_node_num = api.uci_get_type("global_other", "udp_node_num", 1)
local status = api.uci_get_type("global_other", "status", "")
-%>
@ -240,13 +237,13 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
var status_haproxy = document.getElementById('status_haproxy');
var status_kcptun = document.getElementById('status_kcptun');
if (data) {
var tcp_node_num = <%=tcp_node_num%>;
var tcp_node_num = 1;
if (tcp_node_num >= 1) {
var status_tcp_node = document.getElementById('status_tcp_node');
if (status_tcp_node) {
var text = 'TCP<br />';
if (tcp_node_num == 1) {
if (data["tcp_node1_status"])
if (data["tcp_node_status"])
text += '<span class="green"><%:RUNNING%></span>';
else
text += '<span class="red"><%:NOT RUNNING%></span>';
@ -265,7 +262,7 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
if (status_kcptun) {
var text = 'Kcptun<br />';
if (tcp_node_num == 1) {
if (data["kcptun_tcp_node1_status"])
if (data["kcptun_tcp_node_status"])
text += '<span class="green"><%:RUNNING%></span>';
else
text += '<span class="red"><%:NOT RUNNING%></span>';
@ -282,13 +279,13 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
}
}
var udp_node_num = <%=udp_node_num%>;
var udp_node_num = 1;
if (udp_node_num >= 1) {
var status_udp_node = document.getElementById('status_udp_node');
if (status_udp_node) {
var text = 'UDP<br />';
if (udp_node_num == 1) {
if (data["udp_node1_status"])
if (data["udp_node_status"])
text += '<span class="green"><%:RUNNING%></span>';
else
text += '<span class="red"><%:NOT RUNNING%></span>';

View File

@ -2,9 +2,6 @@
local dsp = require "luci.dispatcher"
local api = require "luci.model.cbi.passwall.api.api"
local tcp_node_num = api.uci_get_type("global_other", "tcp_node_num", 1)
local udp_node_num = api.uci_get_type("global_other", "udp_node_num", 1)
local status = api.uci_get_type("global_other", "status", "")
-%>
@ -164,11 +161,11 @@ local status = api.uci_get_type("global_other", "status", "")
if (x && x.status == 200) {
var tcp_node_status = document.getElementById('_tcp_node_status');
if (tcp_node_status) {
var tcp_node_num = <%=tcp_node_num%>;
var tcp_node_num = 1;
if (tcp_node_num >= 1) {
var text = '';
if (tcp_node_num == 1) {
if (json["tcp_node1_status"])
if (json["tcp_node_status"])
text += '<font color="green"><%:RUNNING%> ✓</font>';
else
text += '<font color="red"><%:NOT RUNNING%> X</font>';
@ -186,7 +183,7 @@ local status = api.uci_get_type("global_other", "status", "")
var kcptun_tcp_node_status = document.getElementById('_kcptun_tcp_node_status');
text = "";
if (tcp_node_num == 1) {
if (json["kcptun_tcp_node1_status"])
if (json["kcptun_tcp_node_status"])
text += '<font color="green"><%:RUNNING%> ✓</font>';
else
text += '<font color="red"><%:NOT RUNNING%> X</font>';
@ -206,11 +203,11 @@ local status = api.uci_get_type("global_other", "status", "")
var udp_node_status = document.getElementById('_udp_node_status');
if (udp_node_status) {
var udp_node_num = <%=udp_node_num%>;
var udp_node_num = 1;
if (udp_node_num >= 1) {
var text = '';
if (udp_node_num == 1) {
if (json["udp_node1_status"])
if (json["udp_node_status"])
text += '<font color="green"><%:RUNNING%> ✓</font>';
else
text += '<font color="red"><%:NOT RUNNING%> X</font>';

View File

@ -1,6 +1,8 @@
<%+cbi/valueheader%>
<%
local dsp = require "luci.dispatcher"
local api = require "luci.model.cbi.passwall.api.api"
-%>
<script type="text/javascript">//<![CDATA[
function padright(str, cnt, pad) {
@ -555,6 +557,9 @@ local dsp = require "luci.dispatcher"
var sstr = b64DecodeUnicode(ssu[1]);
var ploc = sstr.indexOf("/?");
opt.set('type', "V2ray");
<% if api.is_finded("xray") then -%>
opt.set('type', "Xray");
<% end -%>
opt.get('type').dispatchEvent(event);
var url0, param = "";
if (ploc > 0) {

View File

@ -3,8 +3,6 @@
local api = require "luci.model.cbi.passwall.api.api"
local dsp = require "luci.dispatcher"
local tcp_node_num = api.uci_get_type("global_other", "tcp_node_num", 1)
local udp_node_num = api.uci_get_type("global_other", "udp_node_num", 1)
local nodes_display = api.uci_get_type("global_other", "nodes_display", "")
-%>
@ -202,9 +200,9 @@ table td, .table .td {
}
}
function set_node(protocol,number) {
if (confirm('<%:Are you sure set to%> ' + protocol.toUpperCase() + "_" + number + '<%:the server?%>')==true){
window.location.href = '<%=dsp.build_url("admin/services/passwall/set_node")%>?protocol=' + protocol + '&number=' + number + '&section=' + section;
function set_node(protocol) {
if (confirm('<%:Are you sure set to%> ' + protocol.toUpperCase() + '<%:the server?%>')==true){
window.location.href = '<%=dsp.build_url("admin/services/passwall/set_node")%>?protocol=' + protocol + '&section=' + section;
}
}
@ -434,17 +432,8 @@ table td, .table .td {
<div id="set_node_div">
<div class="cbi-value"><%:You choose node is:%><span id="set_node_name"></span></div>
<div class="cbi-value">
<% if tcp_node_num and tonumber(tcp_node_num) >= 1 then %>
<% for i = 1, tcp_node_num, 1 do %>
<input class="cbi-button cbi-button-edit" type="button" onclick="set_node('tcp',<%=i%>)" value="TCP_<%=i%>" />
<% end %>
<% end %>
<% if udp_node_num and tonumber(udp_node_num) >= 1 then %>
<% for i = 1, udp_node_num, 1 do %>
<input class="cbi-button cbi-button-edit" type="button" onclick="set_node('udp',<%=i%>)" value="UDP_<%=i%>" />
<% end %>
<% end %>
<input class="cbi-button cbi-button-edit" type="button" onclick="set_node('tcp')" value="TCP" />
<input class="cbi-button cbi-button-edit" type="button" onclick="set_node('udp')" value="UDP" />
<input class="cbi-button cbi-button-remove" type="button" onclick="close_set_node_div()" value="<%:Close%>" />
</div>
</div>

View File

@ -130,9 +130,6 @@ msgstr "0为不使用"
msgid "Same as the tcp node"
msgstr "与TCP节点相同"
msgid "Same as the tcp %s node"
msgstr "与TCP%s节点相同"
msgid "New process"
msgstr "另开进程"

View File

@ -1,8 +1,8 @@
config global
option enabled '0'
option tcp_node1 'nil'
option udp_node1 'nil'
option tcp_node 'nil'
option udp_node 'nil'
option dns_mode 'pdnsd'
option up_china_dns 'default'
option dns_forward '8.8.4.4'
@ -13,8 +13,8 @@ config global
option localhost_tcp_proxy_mode 'gfwlist'
option localhost_udp_proxy_mode 'gfwlist'
option socks_server '0.0.0.0:1080'
option close_log_tcp_1 '1'
option close_log_udp_1 '1'
option close_log_tcp '1'
option close_log_udp '1'
option loglevel 'warning'
option trojan_loglevel '2'
@ -35,8 +35,6 @@ config global_forwarding
option proxy_ipv6 '0'
config global_other
option tcp_node_num '1'
option udp_node_num '1'
option status 'big_icon show_check_port show_ip111'
option nodes_ping 'auto_ping tcping'
option nodes_display 'compact_display_nodes show_add_mode'

View File

@ -265,33 +265,14 @@ ln_start_bin() {
ENABLED=$(config_t_get global enabled 0)
TCP_REDIR_PORT1=$(config_t_get global_forwarding tcp_redir_port 1041)
TCP_NODE_NUM=$(config_t_get global_other tcp_node_num 1)
for i in $(seq 1 $TCP_NODE_NUM); do
eval TCP_NODE$i=$(config_t_get global tcp_node$i nil)
[ $i -gt 1 ] && {
_k=$(expr $i - 1)
eval p=\$TCP_REDIR_PORT${_k}
eval TCP_REDIR_PORT$i=$(expr $p + 1)
}
done
TCP_REDIR_PORT=1041
TCP_NODE=$(config_t_get global tcp_node nil)
UDP_REDIR_PORT1=$(config_t_get global_forwarding udp_redir_port 1051)
UDP_NODE_NUM=$(config_t_get global_other udp_node_num 1)
for i in $(seq 1 $UDP_NODE_NUM); do
eval UDP_NODE$i=$(config_t_get global udp_node$i nil)
[ $i -gt 1 ] && {
_k=$(expr $i - 1)
eval p=\$UDP_REDIR_PORT${_k}
eval UDP_REDIR_PORT$i=$(expr $p + 1)
}
done
UDP_REDIR_PORT=1051
UDP_NODE=$(config_t_get global udp_node nil)
[ "$UDP_NODE1" == "tcp_" ] && UDP_NODE1=$TCP_NODE1
[ "$UDP_NODE1" == "tcp" ] && UDP_REDIR_PORT1=$TCP_REDIR_PORT1
# Dynamic variables (Used to record)
# TCP_NODE1_IP="" UDP_NODE1_IP="" TCP_NODE1_PORT="" UDP_NODE1_PORT="" TCP_NODE1_TYPE="" UDP_NODE1_TYPE=""
[ "$UDP_NODE" == "tcp_" ] && UDP_NODE=$TCP_NODE
[ "$UDP_NODE" == "tcp" ] && UDP_REDIR_PORT=$TCP_REDIR_PORT
TCP_REDIR_PORTS=$(config_t_get global_forwarding tcp_redir_ports '80,443')
UDP_REDIR_PORTS=$(config_t_get global_forwarding udp_redir_ports '1:65535')
@ -307,7 +288,7 @@ LOCALHOST_UDP_PROXY_MODE=$(config_t_get global localhost_udp_proxy_mode default)
load_config() {
[ "$ENABLED" != 1 ] && NO_PROXY=1
[ "$TCP_NODE1" == "nil" -a "$UDP_NODE1" == "nil" ] && {
[ "$TCP_NODE" == "nil" -a "$UDP_NODE" == "nil" ] && {
echolog "没有选择节点!"
NO_PROXY=1
}
@ -429,12 +410,11 @@ run_redir() {
local local_port=$3
local config_file=$4
local REDIR_TYPE=$5
local index=$6
local log_file=$7
local log_file=$6
[ -z "$log_file" ] && log_file="/dev/null"
local redir_type=$(echo $REDIR_TYPE | tr 'A-Z' 'a-z')
local type=$(echo $(config_n_get $node type) | tr 'A-Z' 'a-z')
local close_log=$(config_t_get global close_log_${redir_type}_${index} 1)
local close_log=$(config_t_get global close_log_${redir_type} 1)
[ "$close_log" = "1" ] && log_file="/dev/null"
local remarks=$(config_n_get $node remarks)
local server_host=$(config_n_get $node address)
@ -449,9 +429,9 @@ run_redir() {
return 1
}
[ "$server_host" == "127.0.0.1" ] && process=1
[ "$bind" != "127.0.0.1" ] && echolog "${REDIR_TYPE}_${index}节点:$remarks,节点:${server_host}:${port},监听端口:$local_port"
[ "$bind" != "127.0.0.1" ] && echolog "${REDIR_TYPE}节点:$remarks,节点:${server_host}:${port},监听端口:$local_port"
}
eval ${REDIR_TYPE}_NODE${index}_PORT=$port
eval ${REDIR_TYPE}_NODE_PORT=$port
case "$REDIR_TYPE" in
UDP)
@ -461,8 +441,8 @@ run_redir() {
local node_port=$(config_n_get $node port)
local server_username=$(config_n_get $node username)
local server_password=$(config_n_get $node password)
eval port=\$UDP_REDIR_PORT${index}
ln_start_bin "$(first_type ipt2socks)" "ipt2socks_udp_${index}" $log_file -U -l "$port" -b 0.0.0.0 -s "$node_address" -p "$node_port" -R
eval port=\$UDP_REDIR_PORT
ln_start_bin "$(first_type ipt2socks)" "ipt2socks_udp" $log_file -U -l "$port" -b 0.0.0.0 -s "$node_address" -p "$node_port" -R
;;
xray)
local loglevel=$(config_t_get global loglevel "warning")
@ -492,7 +472,7 @@ run_redir() {
if [ "$protocol" == "wsclient" ]; then
echolog "Brook的WebSocket不支持UDP转发"
else
ln_start_bin "$(first_type $(config_t_get global_app brook_file) brook)" "brook_udp_${index}" $log_file tproxy -l ":$local_port" -s "$server_host:$port" -p "$(config_n_get $node password)"
ln_start_bin "$(first_type $(config_t_get global_app brook_file) brook)" "brook_udp" $log_file tproxy -l ":$local_port" -s "$server_host:$port" -p "$(config_n_get $node password)"
fi
;;
ss|ssr)
@ -517,7 +497,7 @@ run_redir() {
[ -n "$kcptun_server_host" ] && run_kcptun_ip=$(get_host_ip $network_type $kcptun_server_host)
KCPTUN_REDIR_PORT=$(get_new_port $KCPTUN_REDIR_PORT tcp)
kcptun_params="-l 0.0.0.0:$KCPTUN_REDIR_PORT -r $run_kcptun_ip:$kcptun_port $kcptun_config"
ln_start_bin "$(first_type $(config_t_get global_app kcptun_client_file) kcptun-client)" "kcptun_tcp_${index}" $log_file $kcptun_params
ln_start_bin "$(first_type $(config_t_get global_app kcptun_client_file) kcptun-client)" "kcptun_tcp" $log_file $kcptun_params
fi
fi
local _socks_flag _socks_address _socks_port _socks_username _socks_password
@ -532,14 +512,14 @@ run_redir() {
xray)
local loglevel=$(config_t_get global loglevel "warning")
local extra_param="tcp"
[ "${index}" == 1 ] && [ "$UDP_NODE1" == "tcp" ] && extra_param="tcp,udp"
[ "$UDP_NODE" == "tcp" ] && extra_param="tcp,udp"
lua $API_GEN_XRAY -node $node -proto $extra_param -redir_port $local_port -loglevel $loglevel > $config_file
ln_start_bin "$(first_type $(config_t_get global_app xray_file) xray)" xray $log_file -config="$config_file"
;;
v2ray)
local loglevel=$(config_t_get global loglevel "warning")
local extra_param="tcp"
[ "${index}" == 1 ] && [ "$UDP_NODE1" == "tcp" ] && extra_param="tcp,udp"
[ "$UDP_NODE" == "tcp" ] && extra_param="tcp,udp"
lua $API_GEN_XRAY -node $node -proto $extra_param -redir_port $local_port -loglevel $loglevel > $config_file
ln_start_bin "$(first_type $(config_t_get global_app v2ray_file) v2ray)" v2ray $log_file -config="$config_file"
;;
@ -566,28 +546,28 @@ run_redir() {
if [ "$protocol" == "wsclient" ]; then
[ "$brook_tls" == "1" ] && server_ip="wss://${server_ip}" || server_ip="ws://${server_ip}"
socks_port=$(get_new_port 2081 tcp)
ln_start_bin "$(first_type $(config_t_get global_app brook_file) brook)" "brook_tcp_${index}" $log_file wsclient --socks5 "127.0.0.1:$socks_port" -s "$server_ip:$port" -p "$(config_n_get $node password)"
ln_start_bin "$(first_type $(config_t_get global_app brook_file) brook)" "brook_tcp" $log_file wsclient --socks5 "127.0.0.1:$socks_port" -s "$server_ip:$port" -p "$(config_n_get $node password)"
_socks_flag=1
_socks_address="127.0.0.1"
_socks_port=$socks_port
echolog "Brook的WebSocket不支持透明代理将使用ipt2socks转换透明代理"
[ "${index}" == 1 ] && [ "$UDP_NODE1" == "tcp" ] && echolog "Brook的WebSocket不支持UDP转发"
[ "$UDP_NODE" == "tcp" ] && echolog "Brook的WebSocket不支持UDP转发"
else
[ "$kcptun_use" == "1" ] && {
server_ip=127.0.0.1
port=$KCPTUN_REDIR_PORT
}
ln_start_bin "$(first_type $(config_t_get global_app brook_file) brook)" "brook_tcp_${index}" $log_file tproxy -l ":$local_port" -s "$server_ip:$port" -p "$(config_n_get $node password)"
ln_start_bin "$(first_type $(config_t_get global_app brook_file) brook)" "brook_tcp" $log_file tproxy -l ":$local_port" -s "$server_ip:$port" -p "$(config_n_get $node password)"
fi
;;
ss|ssr)
if [ "$kcptun_use" == "1" ]; then
lua $API_GEN_SS -node $node -local_addr "0.0.0.0" -local_port $local_port -server_host "127.0.0.1" -server_port $KCPTUN_REDIR_PORT > $config_file
process=1
[ "${index}" == 1 ] && [ "$UDP_NODE1" == "tcp" ] && echolog "Kcptun不支持UDP转发"
[ "$UDP_NODE" == "tcp" ] && echolog "Kcptun不支持UDP转发"
else
lua $API_GEN_SS -node $node -local_addr "0.0.0.0" -local_port $local_port > $config_file
[ "${index}" == 1 ] && [ "$UDP_NODE1" == "tcp" ] && extra_param="-u"
[ "$UDP_NODE" == "tcp" ] && extra_param="-u"
fi
for k in $(seq 1 $process); do
ln_start_bin "$(first_type ${type}-redir)" "${type}-redir" $log_file -c "$config_file" $extra_param
@ -596,8 +576,8 @@ run_redir() {
esac
if [ -n "$_socks_flag" ]; then
local extra_param="-T"
[ "${index}" == 1 ] && [ "$UDP_NODE1" == "tcp" ] && extra_param=""
ln_start_bin "$(first_type ipt2socks)" "ipt2socks_tcp_${index}" $log_file -l "$local_port" -b 0.0.0.0 -s "$_socks_address" -p "$_socks_port" -R $extra_param
[ "$UDP_NODE" == "tcp" ] && extra_param=""
ln_start_bin "$(first_type ipt2socks)" "ipt2socks_tcp" $log_file -l "$local_port" -b 0.0.0.0 -s "$_socks_address" -p "$_socks_port" -R $extra_param
fi
unset _socks_flag _socks_address _socks_port _socks_username _socks_password
;;
@ -606,18 +586,17 @@ run_redir() {
}
node_switch() {
local i=$3
local node=$4
[ -n "$1" -a -n "$2" -a -n "$3" -a -n "$4" ] && {
ps -w | grep -E "$TMP_PATH" | grep -i "${1}_${i}" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
local config_file=$TMP_PATH/${1}_${i}.json
local log_file=$TMP_PATH/${1}_${i}.log
eval current_port=\$${1}_REDIR_PORT${i}
local port=$(cat $TMP_PORT_PATH/${1}_${i})
run_redir $node "0.0.0.0" $port $config_file $1 $i $log_file
echo $node > $TMP_ID_PATH/${1}_${i}
local node=$3
[ -n "$1" -a -n "$2" -a -n "$3" ] && {
ps -w | grep -E "$TMP_PATH" | grep -i "${1}" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
local config_file=$TMP_PATH/${1}.json
local log_file=$TMP_PATH/${1}.log
eval current_port=\$${1}_REDIR_PORT
local port=$(cat $TMP_PORT_PATH/${1})
run_redir $node "0.0.0.0" $port $config_file $1 $log_file
echo $node > $TMP_ID_PATH/${1}
#local node_net=$(echo $1 | tr 'A-Z' 'a-z')
#uci set $CONFIG.@global[0].${node_net}_node${i}=$node
#uci set $CONFIG.@global[0].${node_net}_node=$node
#uci commit $CONFIG
/etc/init.d/dnsmasq restart >/dev/null 2>&1
}
@ -625,21 +604,19 @@ node_switch() {
start_redir() {
eval num=\$${1}_NODE_NUM
for i in $(seq 1 $num); do
eval node=\$${1}_NODE$i
[ "$node" != "nil" ] && {
TYPE=$(echo $(config_n_get $node type) | tr 'A-Z' 'a-z')
local config_file=$TMP_PATH/${1}_${i}.json
local log_file=$TMP_PATH/${1}_${i}.log
eval current_port=\$${1}_REDIR_PORT$i
local port=$(echo $(get_new_port $current_port $2))
eval ${1}_REDIR${i}=$port
run_redir $node "0.0.0.0" $port $config_file $1 $i $log_file
#eval ip=\$${1}_NODE${i}_IP
echo $node > $TMP_ID_PATH/${1}_${i}
echo $port > $TMP_PORT_PATH/${1}_${i}
}
done
eval node=\$${1}_NODE
[ "$node" != "nil" ] && {
TYPE=$(echo $(config_n_get $node type) | tr 'A-Z' 'a-z')
local config_file=$TMP_PATH/${1}.json
local log_file=$TMP_PATH/${1}.log
eval current_port=\$${1}_REDIR_PORT
local port=$(echo $(get_new_port $current_port $2))
eval ${1}_REDIR=$port
run_redir $node "0.0.0.0" $port $config_file $1 $log_file
#eval ip=\$${1}_NODE_IP
echo $node > $TMP_ID_PATH/${1}
echo $port > $TMP_PORT_PATH/${1}
}
}
start_socks() {
@ -650,8 +627,7 @@ start_socks() {
[ "$enabled" == "0" ] && continue
local node=$(config_n_get $id node nil)
if [ "$(echo $node | grep ^tcp)" ]; then
local num=$(echo $node | sed "s/tcp//g")
eval node=\$TCP_NODE$num
eval node=\$TCP_NODE
fi
[ "$node" == "nil" ] && continue
local port=$(config_n_get $id port)
@ -966,8 +942,6 @@ add_dnsmasq() {
#如果使用chnlist直接使用默认DNS
[ "${USE_CHNLIST}" = "1" ] && unset fwd_dns
sort -u "${RULES_PATH}/proxy_host" | gen_dnsmasq_items "blacklist" "${fwd_dns}" "${TMP_DNSMASQ_PATH}/12-proxy_host.conf"
[ "2" -le "$TCP_NODE_NUM" ] && sort -u "${RULES_PATH}/proxy_host2" | gen_dnsmasq_items "blacklist2" "${fwd_dns}" "${TMP_DNSMASQ_PATH}/11-proxy_host2.conf"
[ "3" -le "$TCP_NODE_NUM" ] && sort -u "${RULES_PATH}/proxy_host3" | gen_dnsmasq_items "blacklist3" "${fwd_dns}" "${TMP_DNSMASQ_PATH}/10-proxy_host3.conf"
echolog " - [$?]代理域名表(blacklist)${fwd_dns:-默认}"
#如果没有使用回国模式

View File

@ -125,34 +125,28 @@ load_acl() {
[ -z "${ip}${mac}" ] && continue
tcp_proxy_mode=${tcp_proxy_mode:-default}
udp_proxy_mode=${udp_proxy_mode:-default}
tcp_node=${tcp_node:-1}
udp_node=${udp_node:-1}
tcp_no_redir_ports=${tcp_no_redir_ports:-default}
udp_no_redir_ports=${udp_no_redir_ports:-default}
tcp_redir_ports=${tcp_redir_ports:-default}
udp_redir_ports=${udp_redir_ports:-default}
[ "$tcp_proxy_mode" = "default" ] && tcp_proxy_mode=$TCP_PROXY_MODE
[ "$udp_proxy_mode" = "default" ] && udp_proxy_mode=$UDP_PROXY_MODE
[ "$tcp_node" -gt "$TCP_NODE_NUM" ] && tcp_node=1
[ "$udp_node" -gt "$UDP_NODE_NUM" ] && udp_node=1
[ "$tcp_no_redir_ports" = "default" ] && tcp_no_redir_ports=$TCP_NO_REDIR_PORTS
[ "$udp_no_redir_ports" = "default" ] && udp_no_redir_ports=$UDP_NO_REDIR_PORTS
[ "$tcp_redir_ports" = "default" ] && tcp_redir_ports=$TCP_REDIR_PORTS
[ "$udp_redir_ports" = "default" ] && udp_redir_ports=$UDP_REDIR_PORTS
eval TCP_NODE=\$TCP_NODE$tcp_node
eval UDP_NODE=\$UDP_NODE$udp_node
#echolog "访问控制:${item}..."
[ -n "$ip" ] && msg="IP$ip"
[ -n "$mac" ] && msg="${msg:+${msg}}MAC$mac"
ipt_tmp=$ipt_n
[ "$tcp_proxy_mode" != "disable" ] && {
[ "$TCP_NODE" != "nil" ] && {
eval tcp_port=\$TCP_REDIR_PORT$tcp_node
tcp_port=$TCP_REDIR_PORT
eval TCP_NODE_TYPE=$(echo $(config_n_get $TCP_NODE type) | tr 'A-Z' 'a-z')
[ "$TCP_NODE_TYPE" == "brook" ] && [ "$(config_n_get $TCP_NODE protocol client)" == "client" ] && is_tproxy=1
#[ "$TCP_NODE_TYPE" == "trojan-go" ] && is_tproxy=1
msg2="${msg}使用TCP节点${tcp_node} [$(get_action_chain_name $tcp_proxy_mode)]"
msg2="${msg}使用TCP节点 [$(get_action_chain_name $tcp_proxy_mode)]"
if [ -n "${is_tproxy}" ]; then
msg2="${msg2}(TPROXY:${tcp_port})代理"
ipt_tmp=$ipt_m && is_tproxy="TPROXY"
@ -173,9 +167,9 @@ load_acl() {
$ipt_tmp -A PSW $(comment "$remarks") $(factor $ip "-s") $(factor $mac "-m mac --mac-source") -p tcp -j RETURN
[ "$udp_proxy_mode" != "disable" ] && {
msg2="${msg}使用UDP节点${udp_node} [$(get_action_chain_name $udp_proxy_mode)]"
msg2="${msg}使用UDP节点 [$(get_action_chain_name $udp_proxy_mode)]"
[ "$UDP_NODE" != "nil" ] && {
eval udp_port=\$UDP_REDIR_PORT$udp_node
udp_port=$UDP_REDIR_PORT
msg2="${msg2}(TPROXY:${udp_port})代理"
[ "$udp_no_redir_ports" != "disable" ] && {
$ipt_m -A PSW $(comment "$remarks") $(factor $ip "-s") $(factor $mac "-m mac --mac-source") -p udp -m multiport --dport $udp_no_redir_ports -j RETURN
@ -201,58 +195,22 @@ load_acl() {
[ "$TCP_NO_REDIR_PORTS" != "disable" ] && $ipt_tmp -A PSW $(comment "默认") -p tcp -m multiport --dport $TCP_NO_REDIR_PORTS -j RETURN
ipt_tmp=$ipt_n
unset is_tproxy msg
[ "3" -le "$TCP_NODE_NUM" ] && [ "$TCP_NODE3" != "nil" ] && {
local TCP_NODE3_TYPE=$(echo $(config_n_get $TCP_NODE3 type) | tr 'A-Z' 'a-z')
[ "$TCP_NODE3_TYPE" == "brook" ] && [ "$(config_n_get $TCP_NODE3 protocol client)" == "client" ] && is_tproxy=1
#[ "$TCP_NODE3_TYPE" == "trojan-go" ] && is_tproxy=1
msg="TCP代理列表3使用TCP节点3"
[ "$TCP_NODE" != "nil" ] && {
local TCP_NODE_TYPE=$(echo $(config_n_get $TCP_NODE type) | tr 'A-Z' 'a-z')
[ "$TCP_NODE_TYPE" == "brook" ] && [ "$(config_n_get $TCP_NODE protocol client)" == "client" ] && is_tproxy=1
#[ "$TCP_NODE_TYPE" == "trojan-go" ] && is_tproxy=1
msg="TCP默认代理使用TCP节点 [$(get_action_chain_name $TCP_PROXY_MODE)]"
if [ -n "$is_tproxy" ]; then
ipt_tmp=$ipt_m && is_tproxy="TPROXY"
msg="${msg}(TPROXY:${TCP_REDIR_PORT3})代理"
msg="${msg}(TPROXY:${TCP_REDIR_PORT})代理"
else
msg="${msg}(REDIRECT:${TCP_REDIR_PORT3})代理"
msg="${msg}(REDIRECT:${TCP_REDIR_PORT})代理"
fi
[ "$TCP_NO_REDIR_PORTS" != "disable" ] && msg="${msg}${TCP_NO_REDIR_PORTS}外的"
msg="${msg}所有端口"
$ipt_tmp -A PSW $(comment "列表3") -p tcp $(factor $TCP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_BLACKLIST3) $(REDIRECT $TCP_REDIR_PORT3 $is_tproxy)
echolog "${msg}"
}
ipt_tmp=$ipt_n
unset is_tproxy msg
[ "2" -le "$TCP_NODE_NUM" ] && [ "$TCP_NODE2" != "nil" ] && {
local TCP_NODE2_TYPE=$(echo $(config_n_get $TCP_NODE2 type) | tr 'A-Z' 'a-z')
[ "$TCP_NODE2_TYPE" == "brook" ] && [ "$(config_n_get $TCP_NODE2 protocol client)" == "client" ] && is_tproxy=1
#[ "$TCP_NODE2_TYPE" == "trojan-go" ] && is_tproxy=1
msg="TCP代理列表2使用TCP节点2"
if [ -n "$is_tproxy" ]; then
ipt_tmp=$ipt_m && is_tproxy="TPROXY"
msg="${msg}(TPROXY:${TCP_REDIR_PORT2})代理"
else
msg="${msg}(REDIRECT:${TCP_REDIR_PORT2})代理"
fi
[ "$TCP_NO_REDIR_PORTS" != "disable" ] && msg="${msg}${TCP_NO_REDIR_PORTS}外的"
msg="${msg}所有端口"
$ipt_tmp -A PSW $(comment "列表2") -p tcp $(factor $TCP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_BLACKLIST2) $(REDIRECT $TCP_REDIR_PORT2 $is_tproxy)
echolog "${msg}"
}
ipt_tmp=$ipt_n
unset is_tproxy msg
[ "$TCP_NODE1" != "nil" ] && {
local TCP_NODE1_TYPE=$(echo $(config_n_get $TCP_NODE1 type) | tr 'A-Z' 'a-z')
[ "$TCP_NODE1_TYPE" == "brook" ] && [ "$(config_n_get $TCP_NODE1 protocol client)" == "client" ] && is_tproxy=1
#[ "$TCP_NODE1_TYPE" == "trojan-go" ] && is_tproxy=1
msg="TCP默认代理使用TCP节点1 [$(get_action_chain_name $TCP_PROXY_MODE)]"
if [ -n "$is_tproxy" ]; then
ipt_tmp=$ipt_m && is_tproxy="TPROXY"
msg="${msg}(TPROXY:${TCP_REDIR_PORT1})代理"
else
msg="${msg}(REDIRECT:${TCP_REDIR_PORT1})代理"
fi
[ "$TCP_NO_REDIR_PORTS" != "disable" ] && msg="${msg}${TCP_NO_REDIR_PORTS}外的"
msg="${msg}所有端口"
$ipt_tmp -A PSW $(comment "默认") -p tcp $(factor $TCP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_SHUNTLIST) $(REDIRECT $TCP_REDIR_PORT1 $is_tproxy)
$ipt_tmp -A PSW $(comment "默认") -p tcp $(factor $TCP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_BLACKLIST) $(REDIRECT $TCP_REDIR_PORT1 $is_tproxy)
$ipt_tmp -A PSW $(comment "默认") -p tcp $(factor $TCP_REDIR_PORTS "-m multiport --dport") $(get_redirect_ipt $TCP_PROXY_MODE $TCP_REDIR_PORT1 $is_tproxy)
$ipt_tmp -A PSW $(comment "默认") -p tcp $(factor $TCP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_SHUNTLIST) $(REDIRECT $TCP_REDIR_PORT $is_tproxy)
$ipt_tmp -A PSW $(comment "默认") -p tcp $(factor $TCP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_BLACKLIST) $(REDIRECT $TCP_REDIR_PORT $is_tproxy)
$ipt_tmp -A PSW $(comment "默认") -p tcp $(factor $TCP_REDIR_PORTS "-m multiport --dport") $(get_redirect_ipt $TCP_PROXY_MODE $TCP_REDIR_PORT $is_tproxy)
echolog "${msg}"
}
fi
@ -262,27 +220,13 @@ load_acl() {
# 加载UDP默认代理模式
if [ "$UDP_PROXY_MODE" != "disable" ]; then
[ "$UDP_NO_REDIR_PORTS" != "disable" ] && $ipt_m -A PSW $(comment "默认") -p udp -m multiport --dport $UDP_NO_REDIR_PORTS -j RETURN
[ "3" -le "$UDP_NODE_NUM" ] && [ "$UDP_NODE3" != "nil" ] && {
msg="UDP代理列表3使用UDP节点3 (TPROXY:${UDP_REDIR_PORT3})代理"
[ "$UDP_NODE" != "nil" ] && {
msg="UDP默认代理使用UDP节点 [$(get_action_chain_name $UDP_PROXY_MODE)](TPROXY:${UDP_REDIR_PORT})代理"
[ "$UDP_NO_REDIR_PORTS" != "disable" ] && msg="${msg}${TCP_NO_REDIR_PORTS}外的"
msg="${msg}所有端口"
$ipt_m -A PSW $(comment "列表3") -p udp $(factor $UDP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_BLACKLIST3) $(REDIRECT $UDP_REDIR_PORT3 TPROXY)
echolog "${msg}"
}
[ "2" -le "$UDP_NODE_NUM" ] && [ "$UDP_NODE2" != "nil" ] && {
msg="UDP代理列表2使用UDP节点2 (TPROXY:${UDP_REDIR_PORT2})代理"
[ "$UDP_NO_REDIR_PORTS" != "disable" ] && msg="${msg}${TCP_NO_REDIR_PORTS}外的"
msg="${msg}所有端口"
$ipt_m -A PSW $(comment "列表2") -p udp $(factor $UDP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_BLACKLIST2) $(REDIRECT $UDP_REDIR_PORT2 TPROXY)
echolog "${msg}"
}
[ "$UDP_NODE1" != "nil" ] && {
msg="UDP默认代理使用UDP节点1 [$(get_action_chain_name $UDP_PROXY_MODE)](TPROXY:${UDP_REDIR_PORT1})代理"
[ "$UDP_NO_REDIR_PORTS" != "disable" ] && msg="${msg}${TCP_NO_REDIR_PORTS}外的"
msg="${msg}所有端口"
$ipt_m -A PSW $(comment "默认") -p udp $(factor $UDP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_SHUNTLIST) $(REDIRECT $UDP_REDIR_PORT1 TPROXY)
$ipt_m -A PSW $(comment "默认") -p udp $(factor $UDP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_BLACKLIST) $(REDIRECT $UDP_REDIR_PORT1 TPROXY)
$ipt_m -A PSW $(comment "默认") -p udp $(factor $UDP_REDIR_PORTS "-m multiport --dport") $(get_redirect_ipt $UDP_PROXY_MODE $UDP_REDIR_PORT1 TPROXY)
$ipt_m -A PSW $(comment "默认") -p udp $(factor $UDP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_SHUNTLIST) $(REDIRECT $UDP_REDIR_PORT TPROXY)
$ipt_m -A PSW $(comment "默认") -p udp $(factor $UDP_REDIR_PORTS "-m multiport --dport") $(dst $IPSET_BLACKLIST) $(REDIRECT $UDP_REDIR_PORT TPROXY)
$ipt_m -A PSW $(comment "默认") -p udp $(factor $UDP_REDIR_PORTS "-m multiport --dport") $(get_redirect_ipt $UDP_PROXY_MODE $UDP_REDIR_PORT TPROXY)
echolog "${msg}"
}
fi
@ -477,19 +421,19 @@ add_firewall_rule() {
ip route add local 0.0.0.0/0 dev lo table 100
# 加载路由器自身代理 TCP
if [ "$TCP_NODE1" != "nil" ]; then
if [ "$TCP_NODE" != "nil" ]; then
local ipt_tmp=$ipt_n
local dns_l="PSW_OUTPUT"
local dns_r=$(REDIRECT $TCP_REDIR_PORT1)
local blist_r=$(REDIRECT $TCP_REDIR_PORT1)
local p_r=$(get_redirect_ipt $LOCALHOST_TCP_PROXY_MODE $TCP_REDIR_PORT1)
TCP_NODE1_TYPE=$(echo $(config_n_get $TCP_NODE1 type) | tr 'A-Z' 'a-z')
local dns_r=$(REDIRECT $TCP_REDIR_PORT)
local blist_r=$(REDIRECT $TCP_REDIR_PORT)
local p_r=$(get_redirect_ipt $LOCALHOST_TCP_PROXY_MODE $TCP_REDIR_PORT)
TCP_NODE_TYPE=$(echo $(config_n_get $TCP_NODE type) | tr 'A-Z' 'a-z')
echolog "加载路由器自身 TCP 代理..."
if [ "$TCP_NODE1_TYPE" == "brook" ] && [ "$(config_n_get $TCP_NODE1 protocol client)" == "client" ]; then
if [ "$TCP_NODE_TYPE" == "brook" ] && [ "$(config_n_get $TCP_NODE protocol client)" == "client" ]; then
echolog " - 启用 TPROXY 模式"
ipt_tmp=$ipt_m
dns_l="PSW"
dns_r="$(REDIRECT $TCP_REDIR_PORT1 TPROXY)"
dns_r="$(REDIRECT $TCP_REDIR_PORT TPROXY)"
blist_r=$(REDIRECT 1 MARK)
p_r=$(get_redirect_ipt $LOCALHOST_TCP_PROXY_MODE 1 MARK)
fi
@ -547,9 +491,9 @@ add_firewall_rule() {
if [ "$PROXY_IPV6" == "1" ]; then
local msg="IPv6 配置不当,无法代理"
$ip6t_n -A PSW -p tcp $(REDIRECT $TCP_REDIR_PORT1)
$ip6t_n -A PSW_OUTPUT -p tcp $(REDIRECT $TCP_REDIR_PORT1)
msg="${msg},转发 IPv6 TCP 流量到节点1[$?]"
$ip6t_n -A PSW -p tcp $(REDIRECT $TCP_REDIR_PORT)
$ip6t_n -A PSW_OUTPUT -p tcp $(REDIRECT $TCP_REDIR_PORT)
msg="${msg},转发 IPv6 TCP 流量到节点[$?]"
echolog "$msg"
fi
@ -566,8 +510,7 @@ add_firewall_rule() {
if [ "$node" == "nil" ] || [ "$port" == "0" ]; then
msg="${msg} 未配置完全,略过"
elif [ "$(echo $node | grep ^tcp)" ]; then
num=$(echo $node | sed "s/tcp//g")
eval "node=\${TCP_NODE$num}"
eval "node=\${TCP_NODE}"
msg="${msg} 使用与 TCP 代理自动切换${num} 相同的节点,延后处理"
else
filter_node $node TCP
@ -579,28 +522,25 @@ add_firewall_rule() {
# 处理轮换节点的分流或套娃
local node port stream switch
for stream in TCP UDP; do
for switch in $(eval "seq 1 \${${stream}_NODE_NUM}"); do
eval "node=\${${stream}_NODE$switch}"
eval "port=\${${stream}_REDIR_PORT$switch}"
echolog "分析 $stream 代理自动切换$switch..."
[ "$node" == "tcp" ] && [ "$stream" == "UDP" ] && {
eval "node=\${TCP_NODE$switch}"
eval "port=\${TCP_REDIR_PORT$switch}"
echolog " - 采用 TCP 代理的配置"
}
if [ "$node" != "nil" ]; then
filter_node $node $stream $port
else
echolog " - 忽略无效的 $stream 代理自动切换$switch"
fi
done
eval "node=\${${stream}_NODE}"
eval "port=\${${stream}_REDIR_PORT}"
echolog "分析 $stream 代理自动切换..."
[ "$node" == "tcp" ] && [ "$stream" == "UDP" ] && {
eval "node=\${TCP_NODE}"
eval "port=\${TCP_REDIR_PORT}"
echolog " - 采用 TCP 代理的配置"
}
if [ "$node" != "nil" ]; then
filter_node $node $stream $port
else
echolog " - 忽略无效的 $stream 代理自动切换"
fi
done
# 加载路由器自身代理 UDP
if [ "$UDP_NODE1" != "nil" ]; then
if [ "$UDP_NODE" != "nil" ]; then
echolog "加载路由器自身 UDP 代理..."
local UDP_NODE1_TYPE=$(echo $(config_n_get $UDP_NODE1 type) | tr 'A-Z' 'a-z')
local UDP_NODE_TYPE=$(echo $(config_n_get $UDP_NODE type) | tr 'A-Z' 'a-z')
local ADD_INDEX=$FORCE_INDEX
_proxy_udp_access() {
[ -n "${2}" ] || return 0
@ -609,7 +549,7 @@ add_firewall_rule() {
echolog " - 上游 DNS 服务器 ${2} 已在直接访问的列表中,不强制向 UDP 代理转发对该服务器 UDP/${3} 端口的访问"
return 0
}
$ipt_m -I PSW $ADD_INDEX -p udp -d ${2} --dport ${3} $(REDIRECT $UDP_REDIR_PORT1 TPROXY)
$ipt_m -I PSW $ADD_INDEX -p udp -d ${2} --dport ${3} $(REDIRECT $UDP_REDIR_PORT TPROXY)
$ipt_m -I PSW_OUTPUT $ADD_INDEX -p udp -d ${2} --dport ${3} $(REDIRECT 1 MARK)
echolog " - [$?]将上游 DNS 服务器 ${2}:${3} 加入到路由器自身代理的 UDP 转发链${ADD_INDEX}"
}

View File

@ -26,55 +26,39 @@ ENABLED=$(config_t_get global_delay start_daemon 0)
sleep 1m
while [ "$ENABLED" -eq 1 ]
do
TCP_NODE_NUM=$(config_t_get global_other tcp_node_num 1)
for i in $(seq 1 $TCP_NODE_NUM); do
eval TCP_NODE$i=$(config_t_get global tcp_node$i nil)
done
UDP_NODE_NUM=$(config_t_get global_other udp_node_num 1)
for i in $(seq 1 $UDP_NODE_NUM); do
eval UDP_NODE$i=$(config_t_get global udp_node$i nil)
done
dns_mode=$(config_t_get global dns_mode)
use_haproxy=$(config_t_get global_haproxy balancing_enable 0)
#tcp
for i in $(seq 1 $TCP_NODE_NUM); do
eval tmp_node=\$TCP_NODE$i
if [ "$tmp_node" != "nil" ]; then
#kcptun
use_kcp=$(config_n_get $tmp_node use_kcp 0)
if [ $use_kcp -gt 0 ]; then
icount=$(ps -w | grep -v grep | grep "$RUN_BIN_PATH/kcptun" | grep -i "tcp_${i}" | wc -l)
if [ $icount = 0 ]; then
/etc/init.d/passwall restart
exit 0
fi
fi
icount=$(ps -w | grep -v -E 'grep|kcptun' | grep "$RUN_BIN_PATH" | grep -i "TCP_${i}" | wc -l)
TCP_NODE=$(config_t_get global tcp_node nil)
if [ "$TCP_NODE" != "nil" ]; then
#kcptun
use_kcp=$(config_n_get $TCP_NODE use_kcp 0)
if [ $use_kcp -gt 0 ]; then
icount=$(ps -w | grep -v grep | grep "$RUN_BIN_PATH/kcptun" | grep -i "tcp" | wc -l)
if [ $icount = 0 ]; then
/etc/init.d/passwall restart
exit 0
fi
fi
done
icount=$(ps -w | grep -v -E 'grep|kcptun' | grep "$RUN_BIN_PATH" | grep -i "TCP" | wc -l)
if [ $icount = 0 ]; then
/etc/init.d/passwall restart
exit 0
fi
fi
#udp
for i in $(seq 1 $UDP_NODE_NUM); do
eval tmp_node=\$UDP_NODE$i
if [ "$tmp_node" != "nil" ]; then
[ "$tmp_node" == "tcp" ] && continue
[ "$tmp_node" == "tcp_" ] && tmp_node=$TCP_NODE1
icount=$(ps -w | grep -v grep | grep "$RUN_BIN_PATH" | grep -i "UDP_${i}" | wc -l)
if [ $icount = 0 ]; then
/etc/init.d/passwall restart
exit 0
fi
UDP_NODE=$(config_t_get global udp_node nil)
if [ "$UDP_NODE" != "nil" ]; then
[ "$UDP_NODE" == "tcp" ] && continue
[ "$UDP_NODE" == "tcp_" ] && UDP_NODE=$TCP_NODE1
icount=$(ps -w | grep -v grep | grep "$RUN_BIN_PATH" | grep -i "UDP" | wc -l)
if [ $icount = 0 ]; then
/etc/init.d/passwall restart
exit 0
fi
done
fi
#dns
dns_mode=$(config_t_get global dns_mode)
if [ "$dns_mode" != "nonuse" ] && [ "$dns_mode" != "custom" ]; then
icount=$(netstat -apn | grep 7913 | wc -l)
if [ $icount = 0 ]; then
@ -84,6 +68,7 @@ do
fi
#haproxy
use_haproxy=$(config_t_get global_haproxy balancing_enable 0)
if [ $use_haproxy -gt 0 ]; then
icount=$(ps -w | grep -v grep | grep "$RUN_BIN_PATH/haproxy" | wc -l)
if [ $icount = 0 ]; then

View File

@ -44,27 +44,24 @@ end
local CONFIG = {}
do
local function import_config(protocol)
local node_num = ucic2:get(application, "@global_other[0]", protocol .. "_node_num") or 1
for i = 1, node_num, 1 do
local name = string.upper(protocol)
local szType = "@global[0]"
local option = protocol .. "_node" .. i
local node = ucic2:get(application, szType, option)
local currentNode
if node then
currentNode = ucic2:get_all(application, node)
end
CONFIG[#CONFIG + 1] = {
log = true,
remarks = name .. "节点" .. i,
node = node,
currentNode = currentNode,
set = function(server)
ucic2:set(application, szType, option, server)
end
}
local name = string.upper(protocol)
local szType = "@global[0]"
local option = protocol .. "_node"
local node = ucic2:get(application, szType, option)
local currentNode
if node then
currentNode = ucic2:get_all(application, node)
end
CONFIG[#CONFIG + 1] = {
log = true,
remarks = name .. "节点",
node = node,
currentNode = currentNode,
set = function(server)
ucic2:set(application, szType, option, server)
end
}
end
import_config("tcp")
import_config("udp")
@ -85,21 +82,21 @@ do
}
end)
local tcp_main1 = ucic2:get(application, "@auto_switch[0]", "tcp_main1") or "nil"
local tcp_main = ucic2:get(application, "@auto_switch[0]", "tcp_main") or "nil"
CONFIG[#CONFIG + 1] = {
log = false,
remarks = "自动切换TCP_1主节点",
currentNode = ucic2:get_all(application, tcp_main1),
remarks = "自动切换TCP主节点",
currentNode = ucic2:get_all(application, tcp_main),
set = function(server)
ucic2:set(application, "@auto_switch[0]", "tcp_main1", server)
end
}
local tcp_node1_table = ucic2:get(application, "@auto_switch[0]", "tcp_node1")
if tcp_node1_table then
local tcp_node_table = ucic2:get(application, "@auto_switch[0]", "tcp_node")
if tcp_node_table then
local nodes = {}
local new_nodes = {}
for k,v in ipairs(tcp_node1_table) do
for k,v in ipairs(tcp_node_table) do
local node = v
local currentNode
if node then
@ -120,14 +117,14 @@ do
}
end
CONFIG[#CONFIG + 1] = {
remarks = "自动切换TCP_1节点列表",
remarks = "自动切换TCP节点列表",
nodes = nodes,
new_nodes = new_nodes,
set = function()
for kk, vv in pairs(CONFIG) do
if (vv.remarks == "自动切换TCP_1节点列表") then
log("刷新自动切换列表")
ucic2:set_list(application, "@auto_switch[0]", "tcp_node1", vv.new_nodes)
ucic2:set_list(application, "@auto_switch[0]", "tcp_node", vv.new_nodes)
end
end
end

View File

@ -57,11 +57,10 @@ test_proxy() {
test_auto_switch() {
local type=$1
local index=$3
local b_tcp_nodes=$4
local b_tcp_nodes=$3
local now_node
if [ -f "/var/etc/$CONFIG/id/${type}_${index}" ]; then
now_node=$(cat /var/etc/$CONFIG/id/${type}_${index})
if [ -f "/var/etc/$CONFIG/id/${type}" ]; then
now_node=$(cat /var/etc/$CONFIG/id/${type})
else
return 1
fi
@ -72,10 +71,10 @@ test_auto_switch() {
return 2
fi
local restore_switch=$(config_t_get auto_switch restore_switch${index} 0)
local restore_switch=$(config_t_get auto_switch restore_switch 0)
if [ "$restore_switch" == "1" ]; then
#检测主节点是否能使用
local main_node=$(config_t_get auto_switch tcp_main${index})
local main_node=$(config_t_get auto_switch tcp_main)
if [ "$now_node" != "$main_node" ]; then
local node_type=$(echo $(config_n_get $main_node type) | tr 'A-Z' 'a-z')
if [ "$node_type" == "socks" ]; then
@ -84,26 +83,26 @@ test_auto_switch() {
[ -n "$node_address" ] && [ -n "$node_port" ] && local curlx="socks5h://$node_address:$node_port"
else
local tmp_port=$(/usr/share/passwall/app.sh get_new_port 61080 tcp)
/usr/share/passwall/app.sh run_socks "$main_node" "127.0.0.1" "$tmp_port" "/var/etc/passwall/auto_switch_$index.json" "10"
/usr/share/passwall/app.sh run_socks "$main_node" "127.0.0.1" "$tmp_port" "/var/etc/passwall/auto_switch.json" "10"
local curlx="socks5h://127.0.0.1:$tmp_port"
fi
sleep 10s
proxy_status=$(test_url "https://www.google.com/generate_204" 3 3 "-x $curlx")
ps -w | grep -v "grep" | grep "/var/etc/passwall/auto_switch_$index.json" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1
ps -w | grep -v "grep" | grep "/var/etc/passwall/auto_switch.json" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1
if [ "$proxy_status" -eq 200 ]; then
#主节点正常,切换到主节点
echolog "自动切换检测:${type}_${index}主节点正常,切换到主节点!"
/usr/share/passwall/app.sh node_switch $type $2 $index $main_node
echolog "自动切换检测:${type}主节点正常,切换到主节点!"
/usr/share/passwall/app.sh node_switch $type $2 $main_node
return 0
fi
fi
fi
if [ "$status" == 0 ]; then
echolog "自动切换检测:${type}_${index}节点$(config_n_get $now_node type) $(config_n_get $now_node address) $(config_n_get $now_node port)正常。"
echolog "自动切换检测:${type}节点$(config_n_get $now_node type) $(config_n_get $now_node address) $(config_n_get $now_node port)正常。"
return 0
elif [ "$status" == 1 ]; then
echolog "自动切换检测:${type}_${index}节点异常,开始切换节点!"
echolog "自动切换检测:${type}节点异常,开始切换节点!"
local new_node
in_backup_nodes=$(echo $b_tcp_nodes | grep $now_node)
# 判断当前节点是否存在于备用节点列表里
@ -120,15 +119,15 @@ test_auto_switch() {
new_node=$next_node
fi
fi
/usr/share/passwall/app.sh node_switch $type $2 $index $new_node
/usr/share/passwall/app.sh node_switch $type $2 $new_node
sleep 10s
# 切换节点后等待10秒后再检测一次如果还是不通继续切直到可用为止
status2=$(test_proxy)
if [ "$status2" -eq 0 ]; then
echolog "自动切换检测:${type}_${index}节点切换完毕!"
echolog "自动切换检测:${type}节点切换完毕!"
return 0
elif [ "$status2" -eq 1 ]; then
test_auto_switch $1 $2 $3 "$4"
test_auto_switch $1 $2 "$3"
elif [ "$status2" -eq 2 ]; then
return 2
fi
@ -144,16 +143,10 @@ start() {
sleep ${delay}m
while [ "$ENABLED" -eq 1 ]
do
# TCP_NODE_NUM=$(config_t_get global_other tcp_node_num 1)
# 暂时只能检测TCP1
TCP_NODE_NUM=1
for i in $(seq 1 $TCP_NODE_NUM); do
eval TCP_NODE$i=\"$(config_t_get auto_switch tcp_node$i nil)\"
eval tmp=\$TCP_NODE$i
[ -n "$tmp" -a "$tmp" != "nil" ] && {
test_auto_switch TCP tcp $i "$tmp"
}
done
TCP_NODE=$(config_t_get auto_switch tcp_node nil)
[ -n "$TCP_NODE" -a "$TCP_NODE" != "nil" ] && {
test_auto_switch TCP tcp "$TCP_NODE"
}
delay=$(config_t_get auto_switch testing_time 1)
sleep ${delay}m
done