luci-app-passwall: sync with upstream source

This commit is contained in:
CN_SZTL 2020-01-19 11:50:21 +08:00
parent cfddda1102
commit 646f75f7b2
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
11 changed files with 416 additions and 378 deletions

View File

@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall
PKG_VERSION:=3.3
PKG_RELEASE:=26-20200115
PKG_RELEASE:=30-20200118
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

View File

@ -153,11 +153,11 @@ function status()
for i = 1, socks5_node_num, 1 do
local listen_port = luci.sys.exec(
string.format(
"[ -f '/var/etc/passwall/port/Socks5_%s' ] && echo -n `cat /var/etc/passwall/port/Socks5_%s`",
"[ -f '/var/etc/passwall/port/SOCKS5_%s' ] && echo -n `cat /var/etc/passwall/port/SOCKS5_%s`",
i, i))
e["socks5_node%s_status" % i] = luci.sys.call(
string.format(
"ps -w | grep -v grep | grep -i -E '%s/Socks5_%s|brook client -l 0.0.0.0:%s' >/dev/null",
"ps -w | grep -v grep | grep -i -E '%s/SOCKS5_%s|brook client -l 0.0.0.0:%s' >/dev/null",
appname, i, listen_port)) == 0
end
luci.http.prepare_content("application/json")

View File

@ -60,13 +60,17 @@ sys.net.mac_hints(function(e, t) o:value(e, "%s " % {e}) end)
---- TCP Node
local tcp_node_num = api.uci_get_type("global_other", "tcp_node_num", 1)
o = s:option(ListValue, "tcp_node", translate("TCP Node"))
for i = 1, tcp_node_num, 1 do o:value(i, "TCP_" .. i) end
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 = api.uci_get_type("global_other", "udp_node_num", 1)
o = s:option(ListValue, "udp_node", translate("UDP Node"))
for i = 1, udp_node_num, 1 do o:value(i, "UDP_" .. i) end
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
---- Proxy Mode
o = s:option(ListValue, "proxy_mode", translate("Proxy Mode"))

View File

@ -94,21 +94,6 @@ for i = 1, socks5_node_num, 1 do
for _, key in pairs(key_table) do o:value(key, n[key]) end
end
---- DNS Forward Mode
o = s:option(ListValue, "dns_mode", translate("DNS Mode"), translate(
"if has problem, please try another mode.<br />if you use no patterns are used, DNS of wan will be used by default as upstream of dnsmasq."))
o.rmempty = false
o:reset_values()
if is_finded("chinadns-ng") then o:value("chinadns-ng", "ChinaDNS-NG") end
if is_finded("dns2socks") then
o:value("dns2socks", "dns2socks " .. translate("Need Socks5 server"))
end
if is_installed("pdnsd") or is_installed("pdnsd-alt") or is_finded("pdnsd") then
o:value("pdnsd", "pdnsd")
end
o:value("local_7913", translate("Use local port 7913 as DNS"))
o:value("nonuse", translate("No patterns are used"))
---- China DNS Server
o = s:option(Value, "up_china_dns", translate("China DNS Server") .. "(UDP)",
translate(
@ -125,26 +110,48 @@ o:value("1.2.4.8", "1.2.4.8 (CNNIC DNS)")
o:value("210.2.4.8", "210.2.4.8 (CNNIC DNS)")
o:value("180.76.76.76", "180.76.76.76 (" .. translate("Baidu") .. "DNS)")
---- DNS Forward Mode
o = s:option(ListValue, "dns_mode", translate("DNS Mode"), translate(
"if has problem, please try another mode.<br />if you use no patterns are used, DNS of wan will be used by default as upstream of dnsmasq."))
o.rmempty = false
o:reset_values()
if is_finded("chinadns-ng") then o:value("chinadns-ng", "ChinaDNS-NG") end
if is_finded("dns2socks") then
o:value("dns2socks",
"dns2socks + " .. translate("Use Socks5 Node Resolve DNS"))
end
if is_installed("pdnsd") or is_installed("pdnsd-alt") or is_finded("pdnsd") then
o:value("pdnsd", "pdnsd")
end
o:value("local_7913", translate("Use local port 7913 as DNS"))
o:value("nonuse", translate("No patterns are used"))
---- Upstream trust DNS Server for ChinaDNS-NG
o = s:option(Value, "up_trust_chinadns_ng_dns",
translate("Upstream trust DNS Server for ChinaDNS-NG") .. "(UDP)",
translate(
"Example: 127.0.0.1#5353 ,such as dns2socks,dns-forwarder...<br />Only use two at most, english comma separation, If you do not fill in the # and the following port, you are using port 53."))
o.default = "8.8.4.4,8.8.8.8"
o.default = "pdnsd"
if is_installed("pdnsd") or is_installed("pdnsd-alt") or is_finded("pdnsd") then
o:value("pdnsd", "pdnsd + " .. translate("Use TCP Node Resolve DNS"))
end
if is_finded("dns2socks") then
o:value("dns2socks",
"dns2socks + " .. translate("Use Socks5 Node Resolve DNS"))
end
o:value("8.8.4.4,8.8.8.8", "8.8.4.4, 8.8.8.8 (Google DNS)")
o:value("208.67.222.222,208.67.220.220",
"208.67.222.222, 208.67.220.220 (Open DNS)")
if is_finded("dns2socks") then
o:value("dns2socks", "dns2socks " .. translate("Need Socks5 server"))
end
o:depends("dns_mode", "chinadns-ng")
---- Use TCP Node Resolve DNS
o = s:option(Flag, "use_tcp_node_resolve_dns",
translate("Use TCP Node Resolve DNS"),
translate("If checked, DNS is resolved using the TCP node."))
o.default = 1
o:depends("dns_mode", "pdnsd")
if is_installed("pdnsd") or is_installed("pdnsd-alt") or is_finded("pdnsd") then
o = s:option(Flag, "use_tcp_node_resolve_dns",
translate("Use TCP Node Resolve DNS"),
translate("If checked, DNS is resolved using the TCP node."))
o.default = 1
o:depends("dns_mode", "pdnsd")
end
---- DNS Forward
o = s:option(Value, "dns_forward", translate("DNS Address"))
@ -156,6 +163,7 @@ o:value("208.67.220.220", "208.67.220.220 (Open DNS)")
o:depends("dns_mode", "dns2socks")
o:depends("dns_mode", "pdnsd")
o:depends("up_trust_chinadns_ng_dns", "dns2socks")
o:depends("up_trust_chinadns_ng_dns", "pdnsd")
---- DNS Hijack
o = s:option(Flag, "dns_53", translate("DNS Hijack"))

View File

@ -1,5 +1,6 @@
local d = require "luci.dispatcher"
local ipkg = require("luci.model.ipkg")
local uci = require"luci.model.uci".cursor()
local api = require "luci.model.cbi.passwall.api.api"
local appname = "passwall"
@ -9,12 +10,23 @@ local function get_customed_path(e)
end
local function is_finded(e)
return luci.sys.exec("find /usr/*bin %s -iname %s -type f" % {get_customed_path(e), e}) ~= "" and
true or false
return luci.sys.exec("find /usr/*bin %s -iname %s -type f" %
{get_customed_path(e), e}) ~= "" and true or false
end
local function is_installed(e) return ipkg.installed(e) end
local n = {}
uci:foreach(appname, "nodes", function(e)
if e.type and e.type == "V2ray" and e.remarks and e.port then
n[e[".name"]] = "[%s] %s:%s" % {e.remarks, e.address, e.port}
end
end)
local key_table = {}
for key, _ in pairs(n) do table.insert(key_table, key) end
table.sort(key_table)
local ss_encrypt_method_list = {
"rc4-md5", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-ctr",
"aes-192-ctr", "aes-256-ctr", "bf-cfb", "camellia-128-cfb",
@ -69,6 +81,7 @@ if is_finded("ss-redir") then type:value("SS", translate("Shadowsocks")) end
if is_finded("ssr-redir") then type:value("SSR", translate("ShadowsocksR")) end
if is_installed("v2ray") or is_finded("v2ray") then
type:value("V2ray", translate("V2ray"))
--type:value("V2ray_balancing", translate("V2ray Balancing"))
end
if is_installed("brook") or is_finded("brook") then
type:value("Brook", translate("Brook"))
@ -77,20 +90,45 @@ if is_installed("trojan") or is_finded("trojan") then
type:value("Trojan", translate("Trojan"))
end
v2ray_protocol = s:option(ListValue, "v2ray_protocol",
--[[v2ray_protocol = s:option(ListValue, "v2ray_protocol",
translate("V2ray Protocol"))
v2ray_protocol:value("vmess", translate("Vmess"))
v2ray_protocol:depends("type", "V2ray")
--]]
v2ray_balancing_node = s:option(DynamicList, "v2ray_balancing_node",
translate("List of backup nodes"), translate(
"List of backup nodes, the first of which must be the primary node and the others the standby node."))
for _, key in pairs(key_table) do v2ray_balancing_node:value(key, n[key]) end
v2ray_balancing_node:depends("type", "V2ray_balancing")
address = s:option(Value, "address", translate("Address (Support Domain Name)"))
address.rmempty = false
address:depends("type", "Socks5")
address:depends("type", "SS")
address:depends("type", "SSR")
address:depends("type", "V2ray")
address:depends("type", "Brook")
address:depends("type", "Trojan")
use_ipv6 = s:option(Flag, "use_ipv6", translate("Use IPv6"))
use_ipv6.default = 0
use_ipv6:depends("type", "Socks5")
use_ipv6:depends("type", "SS")
use_ipv6:depends("type", "SSR")
use_ipv6:depends("type", "V2ray")
use_ipv6:depends("type", "Brook")
use_ipv6:depends("type", "Trojan")
port = s:option(Value, "port", translate("Port"))
port.datatype = "port"
port.rmempty = false
port:depends("type", "Socks5")
port:depends("type", "SS")
port:depends("type", "SSR")
port:depends("type", "V2ray")
port:depends("type", "Brook")
port:depends("type", "Trojan")
username = s:option(Value, "username", translate("Username"))
username:depends("type", "Socks5")
@ -151,7 +189,8 @@ ss_plugin:value("none", translate("none"))
if is_finded("v2ray-plugin") then ss_plugin:value("v2ray-plugin") end
ss_plugin:depends("type", "SS")
ss_plugin_v2ray_opts = s:option(Value, "ss_plugin_v2ray_opts", translate("opts"))
ss_plugin_v2ray_opts =
s:option(Value, "ss_plugin_v2ray_opts", translate("opts"))
ss_plugin_v2ray_opts:depends("ss_plugin", "v2ray-plugin")
use_kcp = s:option(Flag, "use_kcp", translate("Use Kcptun"),
@ -184,11 +223,11 @@ kcp_opts:depends("use_kcp", "1")
v2ray_VMess_id = s:option(Value, "v2ray_VMess_id", translate("ID"))
v2ray_VMess_id.password = true
v2ray_VMess_id:depends("v2ray_protocol", "vmess")
v2ray_VMess_id:depends("type", "V2ray")
v2ray_VMess_alterId = s:option(Value, "v2ray_VMess_alterId",
translate("Alter ID"))
v2ray_VMess_alterId:depends("v2ray_protocol", "vmess")
v2ray_VMess_alterId:depends("type", "V2ray")
v2ray_VMess_level =
s:option(Value, "v2ray_VMess_level", translate("User Level"))
@ -202,6 +241,7 @@ v2ray_stream_security = s:option(ListValue, "v2ray_stream_security",
v2ray_stream_security:value("none", "none")
v2ray_stream_security:value("tls", "tls")
v2ray_stream_security:depends("type", "V2ray")
v2ray_stream_security:depends("type", "V2ray_balancing")
-- [[ TLS部分 ]] --
tls_serverName = s:option(Value, "tls_serverName", translate("Domain"))
@ -222,15 +262,16 @@ v2ray_transport:value("h2", "HTTP/2")
v2ray_transport:value("ds", "DomainSocket")
v2ray_transport:value("quic", "QUIC")
v2ray_transport:depends("type", "V2ray")
v2ray_transport:depends("type", "V2ray_balancing")
-- [[ TCP部分 ]]--
-- TCP伪装
v2ray_tcp_guise = s:option(ListValue, "v2ray_tcp_guise",
translate("Camouflage Type"))
v2ray_tcp_guise:depends("v2ray_transport", "tcp")
v2ray_tcp_guise:value("none", "none")
v2ray_tcp_guise:value("http", "http")
v2ray_tcp_guise:depends("v2ray_transport", "tcp")
-- HTTP域名
v2ray_tcp_guise_http_host = s:option(DynamicList, "v2ray_tcp_guise_http_host",
@ -319,6 +360,7 @@ v2ray_quic_guise:depends("v2ray_transport", "quic")
v2ray_mux = s:option(Flag, "v2ray_mux", translate("Mux"))
v2ray_mux:depends("type", "V2ray")
v2ray_mux:depends("type", "V2ray_balancing")
v2ray_mux_concurrency = s:option(Value, "v2ray_mux_concurrency",
translate("Mux Concurrency"))
@ -367,12 +409,15 @@ trojan_cert_path:depends("trojan_verify_cert", "1")
-- v2ray_insecure = s:option(Flag, "v2ray_insecure", translate("allowInsecure"))
-- v2ray_insecure:depends("type", "V2ray")
-- v2ray_insecure:depends("type", "V2ray_balancing")
function rmempty_restore()
address.rmempty = true
port.rmempty = true
password.rmempty = true
timeout.rmempty = true
tcp_fast_open.rmempty = true
v2ray_protocol.rmempty = true
--v2ray_protocol.rmempty = true
v2ray_VMess_id.rmempty = true
v2ray_VMess_alterId.rmempty = true
end
@ -380,20 +425,31 @@ end
type.validate = function(self, value)
rmempty_restore()
if value == "SS" then
address.rmempty = false
port.rmempty = false
password.rmempty = false
timeout.rmempty = false
tcp_fast_open.rmempty = false
elseif value == "SSR" then
address.rmempty = false
port.rmempty = false
password.rmempty = false
timeout.rmempty = false
tcp_fast_open.rmempty = false
elseif value == "V2ray" then
v2ray_protocol.rmempty = false
address.rmempty = false
port.rmempty = false
--v2ray_protocol.rmempty = false
v2ray_VMess_id.rmempty = false
v2ray_VMess_alterId.rmempty = false
elseif value == "V2ray_balancing" then
elseif value == "Brook" then
address.rmempty = false
port.rmempty = false
password.rmempty = false
elseif value == "Trojan" then
address.rmempty = false
port.rmempty = false
password.rmempty = false
tcp_fast_open.rmempty = false
end

View File

@ -114,7 +114,7 @@ o.default = 0
-- [[ Other Settings ]]--
s = m:section(TypedSection, "global_other", translate("Other Settings"),
translatef(
"You can only set up a maximum of %s nodes for the time being",
"You can only set up a maximum of %s nodes for the time being, Used for access control.",
"3"))
s.anonymous = true
s.addremove = false
@ -149,7 +149,8 @@ o.default = "1"
o.rmempty = false
---- 显示节点检测
o = s:option(Flag, "status_show_check_port", translate("Status Show Check Port"))
o =
s:option(Flag, "status_show_check_port", translate("Status Show Check Port"))
o.default = "0"
o.rmempty = false

View File

@ -223,8 +223,8 @@ msgstr "自定义"
msgid "DNS Server"
msgstr "DNS服务器"
msgid "Need Socks5 server"
msgstr "需要Socks5"
msgid "Use Socks5 Node Resolve DNS"
msgstr "使用Socks5节点解析DNS"
msgid "Multi Process Option"
msgstr "多进程并发"
@ -778,8 +778,8 @@ msgstr "账号密码"
msgid "Node Number"
msgstr "节点数量"
msgid "You can only set up a maximum of %s nodes for the time being"
msgstr "目前最多只能设置%s个节点"
msgid "You can only set up a maximum of %s nodes for the time being, Used for access control."
msgstr "目前最多只能设置%s个节点,用于给访问控制使用。"
msgid "Status Use Big Icon"
msgstr "状态信息使用大图标"

View File

@ -22,8 +22,11 @@ RULE_PATH=/etc/config/${CONFIG}_rule
APP_PATH=/usr/share/$CONFIG
TMP_DNSMASQ_PATH=/var/etc/dnsmasq-passwall.d
DNSMASQ_PATH=/etc/dnsmasq.d
RESOLVFILE=/tmp/resolv.conf.d/resolv.conf.auto
lanip=$(uci get network.lan.ipaddr)
DNS_PORT=7913
API_GEN_V2RAY=/usr/lib/lua/luci/model/cbi/passwall/api/gen_v2ray_client_config_file.lua
API_GEN_TROJAN=/usr/lib/lua/luci/model/cbi/passwall/api/gen_trojan_client_config_file.lua
get_date() {
echo "$(date "+%Y-%m-%d %H:%M:%S")"
@ -198,14 +201,15 @@ load_config() {
fi
LOCALHOST_PROXY_MODE=$(config_t_get global localhost_proxy_mode default)
UP_CHINA_DNS=$(config_t_get global up_china_dns 223.5.5.5,114.114.114.114)
[ ! -f "$RESOLVFILE" ] && RESOLVFILE=/tmp/resolv.conf.auto
[ "$UP_CHINA_DNS" == "dnsbyisp" ] && {
local dns1=$(cat /tmp/resolv.conf.auto 2>/dev/null | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | grep -v 0.0.0.0 | grep -v 127.0.0.1 | sed -n '1P')
local dns1=$(cat $RESOLVFILE 2>/dev/null | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | grep -v 0.0.0.0 | grep -v 127.0.0.1 | sed -n '1P')
if [ -n "$dns1" ]; then
UP_CHINA_DNS=$dns1
else
UP_CHINA_DNS="223.5.5.5,114.114.114.114"
fi
local dns2=$(cat /tmp/resolv.conf.auto 2>/dev/null | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | grep -v 0.0.0.0 | grep -v 127.0.0.1 | sed -n '2P')
local dns2=$(cat $RESOLVFILE 2>/dev/null | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | grep -v 0.0.0.0 | grep -v 127.0.0.1 | sed -n '2P')
[ -n "$dns1" -a -n "$dns2" ] && UP_CHINA_DNS="$dns1,$dns2"
}
TCP_REDIR_PORT1=$(config_t_get global_proxy tcp_redir_port 1041)
@ -263,12 +267,12 @@ gen_ss_ssr_config_file() {
echo -e "}" >>$configfile
}
gen_config_file() {
local node local_port redir_type config_file_path server_host server_ip port type use_ipv6 network_type
gen_start_config() {
local node local_port redir_type config_file server_host server_ip port type use_ipv6 network_type
node=$1
local_port=$2
redir_type=$3
config_file_path=$4
config_file=$4
remarks=$(config_n_get $node remarks)
server_host=$(config_n_get $node address)
use_ipv6=$(config_n_get $node use_ipv6)
@ -279,21 +283,53 @@ gen_config_file() {
type=$(echo $(config_n_get $node type) | tr 'A-Z' 'a-z')
echolog "$redir_type节点$remarks,节点地址端口:${server_ip}:${port}"
if [ "$redir_type" == "Socks5" ]; then
if [ "$redir_type" == "SOCKS5" ]; then
if [ "$network_type" == "ipv6" ]; then
eval SOCKS5_NODE${5}_IPV6=$server_ip
else
eval SOCKS5_NODE${5}_IP=$server_ip
fi
eval SOCKS5_NODE${5}_PORT=$port
if [ "$type" == "ss" -o "$type" == "ssr" ]; then
gen_ss_ssr_config_file $type $local_port 0 $node $config_file_path
if [ "$type" == "socks5" ]; then
echolog "Socks5节点不能使用Socks5代理节点"
elif [ "$type" == "v2ray" ]; then
lua /usr/lib/lua/luci/model/cbi/passwall/api/gen_v2ray_client_config_file.lua $node nil nil $local_port >$config_file_path
lua $API_GEN_V2RAY $node nil nil $local_port >$config_file
v2ray_path=$(config_t_get global_app v2ray_file $(find_bin v2ray))
if [ -f "${v2ray_path}/v2ray" ]; then
${v2ray_path}/v2ray -config=$config_file >/dev/null &
else
echolog "找不到V2ray客户端主程序无法启用"
fi
elif [ "$type" == "trojan" ]; then
lua $API_GEN_TROJAN $node client "0.0.0.0" $local_port >$config_file
trojan_bin=$(find_bin trojan)
[ -f "$trojan_bin" ] && $trojan_bin -c $config_file >/dev/null 2>&1 &
elif [ "$type" == "brook" ]; then
BROOK_SOCKS5_CMD="client -l 0.0.0.0:$local_port -i 0.0.0.0 -s $server_ip:$port -p $(config_n_get $node password)"
elif [ "$type" == "trojan" ]; then
lua /usr/lib/lua/luci/model/cbi/passwall/api/gen_trojan_client_config_file.lua $node client "0.0.0.0" $local_port >$config_file_path
brook_bin=$(config_t_get global_app brook_file $(find_bin brook))
if [ -f "$brook_bin" ]; then
$brook_bin $BROOK_SOCKS5_CMD &>/dev/null &
else
echolog "找不到Brook客户端主程序无法启用"
fi
elif [ "$type" == "ssr" ]; then
gen_ss_ssr_config_file ssr $local_port 0 $node $config_file
ssr_bin=$(find_bin ssr-local)
[ -n "$ssr_bin" ] && $ssr_bin -c $config_file -b 0.0.0.0 -u >/dev/null 2>&1 &
elif [ "$type" == "ss" ]; then
gen_ss_ssr_config_file ss $local_port 0 $node $config_file
ss_bin=$(find_bin ss-local)
[ -n "$ss_bin" ] && {
local plugin_params=""
local plugin=$(config_n_get $node ss_plugin)
if [ "$plugin" != "none" ]; then
[ "$plugin" == "v2ray-plugin" ] && {
local opts=$(config_n_get $node ss_plugin_v2ray_opts)
plugin_params="--plugin v2ray-plugin --plugin-opts $opts"
}
fi
$ss_bin -c $config_file -b 0.0.0.0 -u $plugin_params >/dev/null 2>&1 &
}
fi
fi
@ -304,17 +340,82 @@ gen_config_file() {
eval UDP_NODE${5}_IP=$server_ip
fi
eval UDP_NODE${5}_PORT=$port
if [ "$type" == "ss" -o "$type" == "ssr" ]; then
gen_ss_ssr_config_file $type $local_port 0 $node $config_file_path
if [ "$type" == "socks5" ]; then
local node_address=$(config_n_get $node address)
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$5
ipt2socks_bin=$(find_bin ipt2socks)
[ -f "$ipt2socks_bin" ] && $ipt2socks_bin -U -l $port -b 0.0.0.0 -s $node_address -p $node_port -R >/dev/null &
#redsocks_bin=$(find_bin redsocks2)
#[ -n "$redsocks_bin" ] && {
# local redsocks_config_file=$CONFIG_PATH/UDP_$i.conf
# gen_redsocks_config $redsocks_config_file udp $port $node_address $node_port $server_username $server_password
# $redsocks_bin -c $redsocks_config_file >/dev/null &
#}
elif [ "$type" == "v2ray" ]; then
lua /usr/lib/lua/luci/model/cbi/passwall/api/gen_v2ray_client_config_file.lua $node udp $local_port nil >$config_file_path
elif [ "$type" == "brook" ]; then
BROOK_UDP_CMD="tproxy -l 0.0.0.0:$local_port -s $server_ip:$port -p $(config_n_get $node password)"
lua $API_GEN_V2RAY $node udp $local_port nil >$config_file
v2ray_path=$(config_t_get global_app v2ray_file $(find_bin v2ray))
if [ -f "${v2ray_path}/v2ray" ]; then
${v2ray_path}/v2ray -config=$config_file >/dev/null &
else
echolog "找不到V2ray客户端主程序无法启用"
fi
elif [ "$type" == "trojan" ]; then
SOCKS5_PROXY_PORT4=$(expr $SOCKS5_PROXY_PORT3 + 1)
local_port=$(get_not_exists_port_after $SOCKS5_PROXY_PORT4 tcp)
socks5_port=$local_port
lua /usr/lib/lua/luci/model/cbi/passwall/api/gen_trojan_client_config_file.lua $node client "127.0.0.1" $socks5_port >$config_file_path
lua $API_GEN_TROJAN $node client "127.0.0.1" $socks5_port >$config_file
trojan_bin=$(find_bin trojan)
[ -f "$trojan_bin" ] && $trojan_bin -c $config_file >/dev/null 2>&1 &
local node_address=$(config_n_get $node address)
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$5
ipt2socks_bin=$(find_bin ipt2socks)
[ -f "$ipt2socks_bin" ] && $ipt2socks_bin -U -l $port -b 0.0.0.0 -s 127.0.0.1 -p $socks5_port -R >/dev/null &
#redsocks_bin=$(find_bin redsocks2)
#[ -n "$redsocks_bin" ] && {
# local redsocks_config_file=$CONFIG_PATH/redsocks_UDP_$i.conf
# gen_redsocks_config $redsocks_config_file udp $port "127.0.0.1" $socks5_port
# $redsocks_bin -c $redsocks_config_file >/dev/null &
#}
elif [ "$type" == "brook" ]; then
BROOK_UDP_CMD="tproxy -l 0.0.0.0:$local_port -s $server_ip:$port -p $(config_n_get $node password)"
brook_bin=$(config_t_get global_app brook_file $(find_bin brook))
if [ -f "$brook_bin" ]; then
$brook_bin $BROOK_UDP_CMD &>/dev/null &
else
echolog "找不到Brook客户端主程序无法启用"
fi
elif [ "$type" == "ssr" ]; then
gen_ss_ssr_config_file ssr $local_port 0 $node $config_file
ssr_bin=$(find_bin ssr-redir)
if [ -f "$ssr_bin" ]; then
$ssr_bin -c $config_file -f $RUN_PID_PATH/udp_ssr_1_$5 -U >/dev/null 2>&1 &
else
echolog "找不到ssr客户端主程序无法启用"
fi
elif [ "$type" == "ss" ]; then
gen_ss_ssr_config_file ss $local_port 0 $node $config_file
ss_bin=$(find_bin ss-redir)
[ -f "$ss_bin" ] && {
local plugin_params=""
local plugin=$(config_n_get $node ss_plugin)
if [ "$plugin" != "none" ]; then
[ "$plugin" == "v2ray-plugin" ] && {
local opts=$(config_n_get $node ss_plugin_v2ray_opts)
plugin_params="--plugin v2ray-plugin --plugin-opts $opts"
}
fi
$ss_bin -c $config_file -f $RUN_PID_PATH/udp_ss_1_$5 -U $plugin_params >/dev/null 2>&1 &
}
fi
fi
@ -326,13 +427,36 @@ gen_config_file() {
fi
eval TCP_NODE${5}_PORT=$port
if [ "$type" == "v2ray" ]; then
lua /usr/lib/lua/luci/model/cbi/passwall/api/gen_v2ray_client_config_file.lua $node tcp $local_port nil >$config_file_path
if [ "$type" == "socks5" ]; then
local node_address=$(config_n_get $node address)
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=\$TCP_REDIR_PORT$5
ipt2socks_bin=$(find_bin ipt2socks)
[ -f "$ipt2socks_bin" ] && $ipt2socks_bin -l $port -b 0.0.0.0 -s $node_address -p $socks5_port -R >/dev/null &
#redsocks_bin=$(find_bin redsocks2)
#[ -n "$redsocks_bin" ] && {
# local redsocks_config_file=$CONFIG_PATH/TCP_$i.conf
# gen_redsocks_config $redsocks_config_file tcp $port $node_address $socks5_port $server_username $server_password
# $redsocks_bin -c $redsocks_config_file >/dev/null &
#}
elif [ "$type" == "v2ray" ]; then
lua $API_GEN_V2RAY $node tcp $local_port nil >$config_file
v2ray_path=$(config_t_get global_app v2ray_file $(find_bin v2ray))
if [ -f "${v2ray_path}/v2ray" ]; then
${v2ray_path}/v2ray -config=$config_file >/dev/null &
else
echolog "找不到V2ray客户端主程序无法启用"
fi
elif [ "$type" == "trojan" ]; then
lua /usr/lib/lua/luci/model/cbi/passwall/api/gen_trojan_client_config_file.lua $node nat "0.0.0.0" $local_port >$config_file_path
lua $API_GEN_TROJAN $node nat "0.0.0.0" $local_port >$config_file
trojan_bin=$(find_bin trojan)
[ -f "$trojan_bin" ] && $trojan_bin -c $config_file >/dev/null 2>&1 &
else
local kcptun_use kcptun_server_host kcptun_port kcptun_config
kcptun_use=$(config_n_get $node use_kcp)
kcptun_use=$(config_n_get $node use_kcp 0)
kcptun_server_host=$(config_n_get $node kcp_server)
kcptun_port=$(config_n_get $node kcp_port)
kcptun_config=$(config_n_get $node kcp_opts)
@ -370,22 +494,48 @@ gen_config_file() {
echolog "KCP节点IP地址:$kcptun_server_ip"
fi
if [ -z "$kcptun_path" ]; then
echolog "找不到Kcptun客户端主程序无法启用"
echolog "找不到Kcptun客户端主程序无法启用"
else
$kcptun_bin --log $CONFIG_PATH/kcptun -l 0.0.0.0:$KCPTUN_REDIR_PORT -r $run_kcptun_ip:$kcptun_port "$kcptun_config" >/dev/null 2>&1 &
echolog "运行Kcptun..."
fi
if [ "$type" == "ss" -o "$type" == "ssr" ]; then
gen_ss_ssr_config_file $type $local_port 1 $node $config_file_path
fi
if [ "$type" == "brook" ]; then
BROOK_TCP_CMD="tproxy -l 0.0.0.0:$local_port -s 127.0.0.1:$KCPTUN_REDIR_PORT -p $(config_n_get $node password)"
fi
else
if [ "$type" == "ss" -o "$type" == "ssr" ]; then
gen_ss_ssr_config_file $type $local_port 0 $node $config_file_path
elif [ "$type" == "brook" ]; then
BROOK_TCP_CMD="tproxy -l 0.0.0.0:$local_port -s $server_ip:$port -p $(config_n_get $node password)"
fi
if [ "$type" == "ssr" ]; then
gen_ss_ssr_config_file ssr $local_port $kcptun_use $node $config_file
ssr_bin=$(find_bin ssr-redir)
[ -f "$ssr_bin" ] && {
for k in $(seq 1 $process); do
$ssr_bin -c $config_file -f $RUN_PID_PATH/tcp_ssr_${k}_${5} >/dev/null 2>&1 &
done
}
elif [ "$type" == "ss" ]; then
gen_ss_ssr_config_file ss $local_port $kcptun_use $node $config_file
ss_bin=$(find_bin ${type}-redir)
[ -f "$ss_bin" ] && {
local plugin_params=""
local plugin=$(config_n_get $node ss_plugin)
if [ "$plugin" != "none" ]; then
[ "$plugin" == "v2ray-plugin" ] && {
local opts=$(config_n_get $node ss_plugin_v2ray_opts)
plugin_params="--plugin v2ray-plugin --plugin-opts $opts"
}
fi
for k in $(seq 1 $process); do
$ss_bin -c $config_file -f $RUN_PID_PATH/tcp_ss_${k}_${5} $plugin_params >/dev/null 2>&1 &
done
}
elif [ "$type" == "brook" ]; then
[ "$kcptun_use" == "1" ] && {
server_ip=127.0.0.1
port=$KCPTUN_REDIR_PORT
}
BROOK_TCP_CMD="tproxy -l 0.0.0.0:$local_port -s $server_ip:$port -p $(config_n_get $node password)"
brook_bin=$(config_t_get global_app brook_file $(find_bin brook))
if [ -f "$brook_bin" ]; then
$brook_bin $BROOK_TCP_CMD &>/dev/null &
else
echolog "找不到Brook客户端主程序无法启用"
fi
fi
fi
@ -393,222 +543,25 @@ gen_config_file() {
return 0
}
start_tcp_redir() {
for i in $(seq 1 $TCP_NODE_NUM); do
eval temp_server=\$TCP_NODE$i
[ "$temp_server" != "nil" ] && {
TYPE=$(echo $(config_n_get $temp_server type) | tr 'A-Z' 'a-z')
local config_file=$CONFIG_PATH/TCP_$i.json
eval current_port=\$TCP_REDIR_PORT$i
local port=$(echo $(get_not_exists_port_after $current_port tcp))
eval TCP_REDIR_PORT$i=$port
gen_config_file $temp_server $port TCP $config_file $i
if [ "$TYPE" == "v2ray" ]; then
v2ray_path=$(config_t_get global_app v2ray_file)
if [ -f "${v2ray_path}/v2ray" ]; then
${v2ray_path}/v2ray -config=$config_file >/dev/null &
else
v2ray_bin=$(find_bin v2ray)
[ -n "$v2ray_bin" ] && $v2ray_bin -config=$config_file >/dev/null &
fi
elif [ "$TYPE" == "brook" ]; then
brook_bin=$(config_t_get global_app brook_file)
if [ -f "$brook_bin" ]; then
$brook_bin $BROOK_TCP_CMD &>/dev/null &
else
brook_bin=$(find_bin brook)
[ -n "$brook_bin" ] && $brook_bin $BROOK_TCP_CMD &>/dev/null &
fi
elif [ "$TYPE" == "trojan" ]; then
trojan_bin=$(find_bin trojan)
[ -n "$trojan_bin" ] && $trojan_bin -c $config_file >/dev/null 2>&1 &
elif [ "$TYPE" == "socks5" ]; then
local node_address=$(config_n_get $temp_server address)
local node_port=$(config_n_get $temp_server port)
local server_username=$(config_n_get $temp_server username)
local server_password=$(config_n_get $temp_server password)
ipt2socks_bin=$(find_bin ipt2socks)
[ -n "$ipt2socks_bin" ] && {
$ipt2socks_bin -T -l $port -b 0.0.0.0 -s $node_address -p $socks5_port -R >/dev/null &
}
#redsocks_bin=$(find_bin redsocks2)
#[ -n "$redsocks_bin" ] && {
# local redsocks_config_file=$CONFIG_PATH/TCP_$i.conf
# gen_redsocks_config $redsocks_config_file tcp $port $node_address $socks5_port $server_username $server_password
# $redsocks_bin -c $redsocks_config_file >/dev/null &
#}
elif [ "$TYPE" == "ssr" ]; then
ssr_bin=$(find_bin ssr-redir)
[ -n "$ssr_bin" ] && {
for k in $(seq 1 $process); do
$ssr_bin -c $config_file -f $RUN_PID_PATH/tcp_${TYPE}_$k_$i >/dev/null 2>&1 &
done
}
elif [ "$TYPE" == "ss" ]; then
ss_bin=$(find_bin ss-redir)
[ -n "$ss_bin" ] && {
local plugin_params=""
local plugin=$(config_n_get $temp_server ss_plugin)
if [ "$plugin" != "none" ]; then
[ "$plugin" == "v2ray-plugin" ] && {
local opts=$(config_n_get $temp_server ss_plugin_v2ray_opts)
plugin_params="--plugin v2ray-plugin --plugin-opts $opts"
}
fi
for k in $(seq 1 $process); do
$ss_bin -c $config_file -f $RUN_PID_PATH/tcp_${TYPE}_$k_$i $plugin_params >/dev/null 2>&1 &
done
}
fi
echo $port > $RUN_PORT_PATH/TCP_${i}
eval ip=\$TCP_NODE${i}_IP
echo $ip > $RUN_IP_PATH/TCP_${i}
echo $temp_server > $RUN_ID_PATH/TCP_${i}
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=$CONFIG_PATH/${1}_${i}.json
eval current_port=\$${1}_${2}_PORT$i
local port=$(echo $(get_not_exists_port_after $current_port $3))
eval ${1}_${2}$i=$port
gen_start_config $node $port $1 $config_file $i
echo $port > $RUN_PORT_PATH/${1}_${i}
eval ip=\$${1}_NODE${i}_IP
echo $ip > $RUN_IP_PATH/${1}_${i}
echo $node > $RUN_ID_PATH/${1}_${i}
}
done
}
start_udp_redir() {
for i in $(seq 1 $UDP_NODE_NUM); do
eval temp_server=\$UDP_NODE$i
[ "$temp_server" != "nil" ] && {
TYPE=$(echo $(config_n_get $temp_server type) | tr 'A-Z' 'a-z')
local config_file=$CONFIG_PATH/UDP_$i.json
eval current_port=\$UDP_REDIR_PORT$i
local port=$(echo $(get_not_exists_port_after $current_port udp))
eval UDP_REDIR_PORT$i=$port
gen_config_file $temp_server $port UDP $config_file $i
if [ "$TYPE" == "v2ray" ]; then
v2ray_path=$(config_t_get global_app v2ray_file)
if [ -f "${v2ray_path}/v2ray" ]; then
${v2ray_path}/v2ray -config=$config_file >/dev/null &
else
v2ray_bin=$(find_bin v2ray)
[ -n "$v2ray_bin" ] && $v2ray_bin -config=$config_file >/dev/null &
fi
elif [ "$TYPE" == "brook" ]; then
brook_bin=$(config_t_get global_app brook_file)
if [ -f "$brook_bin" ]; then
$brook_bin $BROOK_UDP_CMD >/dev/null &
else
brook_bin=$(find_bin brook)
[ -n "$brook_bin" ] && $brook_bin $BROOK_UDP_CMD >/dev/null &
fi
elif [ "$TYPE" == "trojan" ]; then
trojan_bin=$(find_bin trojan)
[ -n "$trojan_bin" ] && $trojan_bin -c $config_file >/dev/null 2>&1 &
local node_address=$(config_n_get $temp_server address)
local node_port=$(config_n_get $temp_server port)
local server_username=$(config_n_get $temp_server username)
local server_password=$(config_n_get $temp_server password)
ipt2socks_bin=$(find_bin ipt2socks)
[ -n "$ipt2socks_bin" ] && {
$ipt2socks_bin -U -l $port -b 0.0.0.0 -s 127.0.0.1 -p $socks5_port -R >/dev/null &
}
#redsocks_bin=$(find_bin redsocks2)
#[ -n "$redsocks_bin" ] && {
# local redsocks_config_file=$CONFIG_PATH/redsocks_UDP_$i.conf
# gen_redsocks_config $redsocks_config_file udp $port "127.0.0.1" $socks5_port
# $redsocks_bin -c $redsocks_config_file >/dev/null &
#}
elif [ "$TYPE" == "socks5" ]; then
local node_address=$(config_n_get $temp_server address)
local node_port=$(config_n_get $temp_server port)
local server_username=$(config_n_get $temp_server username)
local server_password=$(config_n_get $temp_server password)
ipt2socks_bin=$(find_bin ipt2socks)
[ -n "$ipt2socks_bin" ] && {
$ipt2socks_bin -U -l $port -b 0.0.0.0 -s $node_address -p $node_port -R >/dev/null &
}
#redsocks_bin=$(find_bin redsocks2)
#[ -n "$redsocks_bin" ] && {
# local redsocks_config_file=$CONFIG_PATH/UDP_$i.conf
# gen_redsocks_config $redsocks_config_file udp $port $node_address $node_port $server_username $server_password
# $redsocks_bin -c $redsocks_config_file >/dev/null &
#}
elif [ "$TYPE" == "ssr" ]; then
ssr_bin=$(find_bin ssr-redir)
[ -n "$ssr_bin" ] && $ssr_bin -c $config_file -f $RUN_PID_PATH/udp_${TYPE}_1_$i -U >/dev/null 2>&1 &
elif [ "$TYPE" == "ss" ]; then
ss_bin=$(find_bin ss-redir)
[ -n "$ss_bin" ] && {
local plugin_params=""
local plugin=$(config_n_get $temp_server ss_plugin)
if [ "$plugin" != "none" ]; then
[ "$plugin" == "v2ray-plugin" ] && {
local opts=$(config_n_get $temp_server ss_plugin_v2ray_opts)
plugin_params="--plugin v2ray-plugin --plugin-opts $opts"
}
fi
$ss_bin -c $config_file -f $RUN_PID_PATH/udp_${TYPE}_1_$i -U $plugin_params >/dev/null 2>&1 &
}
fi
echo $port > $RUN_PORT_PATH/UDP_${i}
eval ip=\$UDP_NODE${i}_IP
echo $ip > $RUN_IP_PATH/UDP_${i}
echo $temp_server > $RUN_ID_PATH/UDP_${i}
}
done
}
start_socks5_proxy() {
for i in $(seq 1 $SOCKS5_NODE_NUM); do
eval temp_server=\$SOCKS5_NODE$i
if [ "$temp_server" != "nil" ]; then
TYPE=$(echo $(config_n_get $temp_server type) | tr 'A-Z' 'a-z')
local config_file=$CONFIG_PATH/Socks5_$i.json
eval current_port=\$SOCKS5_PROXY_PORT$i
local port=$(get_not_exists_port_after $current_port tcp)
eval SOCKS5_PROXY_PORT$i=$port
gen_config_file $temp_server $port Socks5 $config_file $i
if [ "$TYPE" == "v2ray" ]; then
v2ray_path=$(config_t_get global_app v2ray_file)
if [ -f "${v2ray_path}/v2ray" ]; then
${v2ray_path}/v2ray -config=$config_file >/dev/null &
else
v2ray_bin=$(find_bin v2ray)
[ -n "$v2ray_bin" ] && $v2ray_bin -config=$config_file >/dev/null &
fi
elif [ "$TYPE" == "brook" ]; then
brook_bin=$(config_t_get global_app brook_file)
if [ -f "$brook_bin" ]; then
$brook_bin $BROOK_SOCKS5_CMD >/dev/null &
else
brook_bin=$(find_bin brook)
[ -n "$brook_bin" ] && $brook_bin $BROOK_SOCKS5_CMD >/dev/null &
fi
elif [ "$TYPE" == "trojan" ]; then
trojan_bin=$(find_bin trojan)
[ -n "$trojan_bin" ] && $trojan_bin -c $config_file >/dev/null 2>&1 &
elif [ "$TYPE" == "socks5" ]; then
echolog "Socks5节点不能使用Socks5代理节点"
elif [ "$TYPE" == "ssr" ]; then
ssr_bin=$(find_bin ssr-local)
[ -n "$ssr_bin" ] && $ssr_bin -c $config_file -b 0.0.0.0 -u >/dev/null 2>&1 &
elif [ "$TYPE" == "ss" ]; then
ss_bin=$(find_bin ss-local)
[ -n "$ss_bin" ] && {
local plugin_params=""
local plugin=$(config_n_get $temp_server ss_plugin)
if [ "$plugin" != "none" ]; then
[ "$plugin" == "v2ray-plugin" ] && {
local opts=$(config_n_get $temp_server ss_plugin_v2ray_opts)
plugin_params="--plugin v2ray-plugin --plugin-opts $opts"
}
fi
$ss_bin -c $config_file -b 0.0.0.0 -u $plugin_params >/dev/null 2>&1 &
}
fi
echo $port > $RUN_PORT_PATH/Socks5_${i}
eval ip=\$SOCKS5_NODE${i}_IP
echo $ip > $RUN_IP_PATH/SOCKS5_${i}
echo $temp_server > $RUN_ID_PATH/SOCKS5_${i}
fi
done
}
clean_log() {
logsnum=$(cat $LOG_FILE 2>/dev/null | wc -l)
if [ "$logsnum" -gt 300 ]; then
@ -711,12 +664,13 @@ start_dns() {
}
else
echolog "dns2socks模式需要使用Socks5代理节点请开启"
force_stop
fi
;;
pdnsd)
pdnsd_bin=$(find_bin pdnsd)
[ -n "$pdnsd_bin" ] && {
gen_pdnsd_config
gen_pdnsd_config $DNS_PORT "cache"
nohup $pdnsd_bin --daemon -c $pdnsd_dir/pdnsd.conf -d >/dev/null 2>&1 &
echolog "运行DNS转发模式pdnsd..."
}
@ -729,8 +683,22 @@ start_dns() {
[ -f "$CONFIG_PATH/gfwlist_chinadns_ng.txt" ] && local gfwlist_param="-g $CONFIG_PATH/gfwlist_chinadns_ng.txt"
[ -f "$RULE_PATH/chnlist" ] && local chnlist_param="-m $RULE_PATH/chnlist"
up_trust_chinadns_ng_dns=$(config_t_get global up_trust_chinadns_ng_dns "8.8.4.4,8.8.8.8")
if [ "$up_trust_chinadns_ng_dns" == "dns2socks" ]; then
up_trust_chinadns_ng_dns=$(config_t_get global up_trust_chinadns_ng_dns "pdnsd")
if [ "$up_trust_chinadns_ng_dns" == "pdnsd" ]; then
if [ -z "$TCP_NODE1" -o "$TCP_NODE1" == "nil" ]; then
echolog "ChinaDNS-NG + pdnsd 模式需要启用TCP节点"
force_stop
else
use_tcp_node_resolve_dns=1
gen_pdnsd_config $other_port
pdnsd_bin=$(find_bin pdnsd)
[ -n "$pdnsd_bin" ] && {
nohup $pdnsd_bin --daemon -c $pdnsd_dir/pdnsd.conf -d >/dev/null 2>&1 &
nohup $chinadns_ng_bin -l $DNS_PORT -c $UP_CHINA_DNS -t 127.0.0.1#$other_port $gfwlist_param $chnlist_param >/dev/null 2>&1 &
echolog "运行DNS转发模式ChinaDNS-NG + pdnsd(${DNS_FORWARD}:53)国内DNS$UP_CHINA_DNS"
}
fi
elif [ "$up_trust_chinadns_ng_dns" == "dns2socks" ]; then
if [ -n "$SOCKS5_NODE1" -a "$SOCKS5_NODE1" != "nil" ]; then
dns2socks_bin=$(find_bin dns2socks)
[ -n "$dns2socks_bin" ] && {
@ -892,74 +860,76 @@ gen_pdnsd_config() {
mkdir -p $pdnsd_dir
touch $pdnsd_dir/pdnsd.cache
chown -R root.nogroup $pdnsd_dir
[ "$2" == "cache" ] && cache_param="perm_cache = 1024;\ncache_dir = \"$pdnsd_dir\";"
cat > $pdnsd_dir/pdnsd.conf <<-EOF
global {
perm_cache = 1024;
cache_dir = "$pdnsd_dir";
pid_file = "$RUN_PID_PATH/pdnsd.pid";
run_as = "root";
server_ip = 127.0.0.1;
server_port = $DNS_PORT;
status_ctl = on;
query_method = tcp_only;
min_ttl = 1d;
max_ttl = 1w;
timeout = 10;
tcp_qtimeout = 1;
par_queries = 2;
neg_domain_pol = on;
udpbufsize = 1024;
$(echo -e $cache_param)
pid_file = "$RUN_PID_PATH/pdnsd.pid";
run_as = "root";
server_ip = 127.0.0.1;
server_port = $1;
status_ctl = on;
query_method = tcp_only;
min_ttl = 1d;
max_ttl = 1w;
timeout = 10;
tcp_qtimeout = 1;
par_queries = 2;
neg_domain_pol = on;
udpbufsize = 1024;
}
EOF
EOF
[ "$use_tcp_node_resolve_dns" == 1 ] && {
cat >> $pdnsd_dir/pdnsd.conf <<-EOF
server {
label = "node";
ip = $DNS_FORWARD;
edns_query = on;
port = 53;
timeout = 4;
interval = 60;
uptest = none;
purge_cache = off;
caching = on;
}
server {
label = "node";
ip = $DNS_FORWARD;
edns_query = on;
port = 53;
timeout = 4;
interval = 60;
uptest = none;
purge_cache = off;
caching = on;
}
EOF
}
[ "$DNS_MODE" != "chinadns-ng" ] && {
cat >> $pdnsd_dir/pdnsd.conf <<-EOF
server {
label = "opendns";
ip = 208.67.222.222, 208.67.220.220;
edns_query = on;
port = 443;
timeout = 4;
interval = 60;
uptest = none;
purge_cache = off;
caching = on;
}
server {
label = "opendns";
ip = 208.67.222.222, 208.67.220.220;
edns_query = on;
port = 5353;
timeout = 4;
interval = 60;
uptest = none;
purge_cache = off;
caching = on;
}
source {
ttl = 86400;
owner = "localhost.";
serve_aliases = on;
file = "/etc/hosts";
}
EOF
}
cat >> $pdnsd_dir/pdnsd.conf <<-EOF
server {
label = "opendns";
ip = 208.67.222.222, 208.67.220.220;
edns_query = on;
port = 443;
timeout = 4;
interval = 60;
uptest = none;
purge_cache = off;
caching = on;
}
server {
label = "opendns";
ip = 208.67.222.222, 208.67.220.220;
edns_query = on;
port = 5353;
timeout = 4;
interval = 60;
uptest = none;
purge_cache = off;
caching = on;
}
source {
ttl = 86400;
owner = "localhost.";
serve_aliases = on;
file = "/etc/hosts";
}
EOF
}
stop_dnsmasq() {
@ -1104,9 +1074,9 @@ start() {
start_dns
add_dnsmasq
start_haproxy
start_socks5_proxy
start_tcp_redir
start_udp_redir
start_redir SOCKS5 PROXY tcp
start_redir TCP REDIR tcp
start_redir UDP REDIR udp
source $APP_PATH/iptables.sh start
/etc/init.d/dnsmasq restart >/dev/null 2>&1 &
start_crontab

View File

@ -127,6 +127,8 @@ load_acl() {
[ -z "$proxy_mode" -o "$proxy_mode" = "default" ] && proxy_mode=$PROXY_MODE
[ -z "$tcp_redir_ports" -o "$tcp_redir_ports" = "default" ] && tcp_redir_ports=$TCP_REDIR_PORTS
[ -z "$udp_redir_ports" -o "$udp_redir_ports" = "default" ] && udp_redir_ports=$UDP_REDIR_PORTS
[ -z "$tcp_node" -o "$TCP_NODE_NUM" == "1" ] && tcp_node=1
[ -z "$udp_node" -o "$UDP_NODE_NUM" == "1" ] && udp_node=1
eval TCP_NODE=\$TCP_NODE$tcp_node
eval UDP_NODE=\$UDP_NODE$udp_node
local ip_mark=$(get_ip_mark $ip)
@ -275,10 +277,10 @@ add_firewall_rule() {
if [ "$SOCKS5_NODE_NUM" -ge 1 ]; then
for i in $(seq 1 $SOCKS5_NODE_NUM); do
local k=$i
eval temp_server=\$SOCKS5_NODE$k
if [ "$temp_server" != "nil" ]; then
local address=$(config_get $temp_server address)
local SOCKS5_NODE_PORT=$(config_get $temp_server port)
eval node=\$SOCKS5_NODE$k
if [ "$node" != "nil" ]; then
local address=$(config_get $node address)
local SOCKS5_NODE_PORT=$(config_get $node port)
local SOCKS5_NODE_IP=$(get_host_ip "ipv4" $address)
[ -n "$SOCKS5_NODE_IP" -a -n "$SOCKS5_NODE_PORT" ] && $iptables_nat -A PSW -p tcp -d $SOCKS5_NODE_IP -m multiport --dports $SOCKS5_NODE_PORT -j RETURN
fi
@ -288,16 +290,15 @@ add_firewall_rule() {
if [ "$TCP_NODE_NUM" -ge 1 ]; then
for i in $(seq 1 $TCP_NODE_NUM); do
local k=$i
local local_port=104$k
local ttl=14$k
eval temp_server=\$TCP_NODE$k
eval node=\$TCP_NODE$k
eval local_port=\$TCP_REDIR_PORT$k
# 生成TCP转发规则
if [ "$temp_server" != "nil" ]; then
local address=$(config_get $temp_server address)
local TCP_NODE_PORT=$(config_get $temp_server port)
if [ "$node" != "nil" ]; then
local address=$(config_get $node address)
local TCP_NODE_PORT=$(config_get $node port)
local TCP_NODE_IP=$(get_host_ip "ipv4" $address)
local TCP_NODE_TYPE=$(echo $(config_get $temp_server type) | tr 'A-Z' 'a-z')
local TCP_NODE_TYPE=$(echo $(config_get $node type) | tr 'A-Z' 'a-z')
[ -n "$TCP_NODE_IP" -a -n "$TCP_NODE_PORT" ] && $iptables_nat -A PSW -p tcp -d $TCP_NODE_IP -m multiport --dports $TCP_NODE_PORT -j RETURN
if [ "$TCP_NODE_TYPE" == "brook" ]; then
$iptables_mangle -A PSW_ACL -p tcp -m socket -j MARK --set-mark 1
@ -422,15 +423,14 @@ add_firewall_rule() {
if [ "$UDP_NODE_NUM" -ge 1 ]; then
for i in $(seq 1 $UDP_NODE_NUM); do
local k=$i
local local_port=104$k
eval temp_server=\$UDP_NODE$k
eval node=\$UDP_NODE$k
eval local_port=\$UDP_REDIR_PORT$k
# 生成UDP转发规则
if [ "$temp_server" != "nil" ]; then
local address=$(config_get $temp_server address)
local UDP_NODE_PORT=$(config_get $temp_server port)
if [ "$node" != "nil" ]; then
local address=$(config_get $node address)
local UDP_NODE_PORT=$(config_get $node port)
local UDP_NODE_IP=$(get_host_ip "ipv4" $address)
local UDP_NODE_TYPE=$(echo $(config_get $temp_server type) | tr 'A-Z' 'a-z')
local UDP_NODE_TYPE=$(echo $(config_get $node type) | tr 'A-Z' 'a-z')
[ -n "$UDP_NODE_IP" -a -n "$UDP_NODE_PORT" ] && $iptables_mangle -A PSW -p udp -d $UDP_NODE_IP -m multiport --dports $UDP_NODE_PORT -j RETURN
[ "$UDP_NODE_TYPE" == "brook" ] && $iptables_mangle -A PSW_ACL -p udp -m socket -j MARK --set-mark 1
# 全局模式

View File

@ -75,8 +75,8 @@ done
for i in $(seq 1 $SOCKS5_NODE_NUM); do
eval temp_server=\$SOCKS5_NODE$i
if [ "$temp_server" != "nil" ]; then
[ -f "/var/etc/passwall/port/Socks5_$i" ] && listen_port=$(echo -n `cat /var/etc/passwall/port/Socks5_$i`)
icount=$(ps -w | grep -v grep | grep -i -E "${CONFIG}/Socks5_${i}|brook client -l 0.0.0.0:${listen_port}" | wc -l)
[ -f "/var/etc/passwall/port/SOCKS5_$i" ] && listen_port=$(echo -n `cat /var/etc/passwall/port/SOCKS5_$i`)
icount=$(ps -w | grep -v grep | grep -i -E "${CONFIG}/SOCKS5_${i}|brook client -l 0.0.0.0:${listen_port}" | wc -l)
if [ $icount = 0 ]; then
/etc/init.d/passwall restart
exit 0

View File

@ -150,16 +150,15 @@ get_remote_config(){
add_mode="$subscrib_remark"
[ -n "$3" ] && add_mode="导入"
new_node_type=$(echo $1 | tr '[a-z]' '[A-Z]')
decode_link="$2"
if [ "$1" == "ss" ]; then
decode_link=$(ss_decode $decode_link)
decode_link=$(ss_decode $2)
ss_encrypt_method=$(echo "$decode_link" | awk -F ':' '{print $1}')
password=$(echo "$decode_link" | awk -F ':' '{print $2}' | awk -F '@' '{print $1}')
node_address=$(echo "$decode_link" | awk -F ':' '{print $2}' | awk -F '@' '{print $2}')
node_port=$(echo "$decode_link" | awk -F '@' '{print $2}' | awk -F '#' '{print $1}' | awk -F ':' '{print $2}')
remarks=$(urldecode $(echo "$decode_link" | awk -F '#' '{print $2}'))
elif [ "$1" == "ssr" ]; then
decode_link=$(decode_url_link $decode_link 1)
decode_link=$(decode_url_link $2 1)
node_address=$(echo "$decode_link" | awk -F ':' '{print $1}')
node_port=$(echo "$decode_link" | awk -F ':' '{print $2}')
protocol=$(echo "$decode_link" | awk -F ':' '{print $3}')