luci-app-passwall: sync with upstream source

This commit is contained in:
CN_SZTL 2020-03-05 19:03:11 +08:00
parent 30bbab8506
commit 3854416878
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
11 changed files with 369 additions and 145 deletions

View File

@ -7,8 +7,8 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall
PKG_VERSION:=3.6
PKG_RELEASE:=11
PKG_DATE:=20200304
PKG_RELEASE:=13
PKG_DATE:=20200305
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

View File

@ -2,6 +2,7 @@
module("luci.controller.passwall", package.seeall)
local appname = "passwall"
local http = require "luci.http"
local passwall = require "luci.model.cbi.passwall.api.passwall"
local kcptun = require "luci.model.cbi.passwall.api.kcptun"
local brook = require "luci.model.cbi.passwall.api.brook"
local v2ray = require "luci.model.cbi.passwall.api.v2ray"
@ -59,6 +60,10 @@ function index()
true
entry({"admin", "vpn", "passwall", "update_rules"}, call("update_rules")).leaf =
true
entry({"admin", "vpn", "passwall", "luci_check"}, call("luci_check")).leaf =
true
entry({"admin", "vpn", "passwall", "luci_update"}, call("luci_update")).leaf =
true
entry({"admin", "vpn", "passwall", "kcptun_check"}, call("kcptun_check")).leaf =
true
entry({"admin", "vpn", "passwall", "kcptun_update"}, call("kcptun_update")).leaf =
@ -127,8 +132,8 @@ function status()
appname, i)) == 0
e["tcp_node%s_status" % i] = luci.sys.call(
string.format(
"ps -w | grep -v grep | grep '%s/bin/' | grep -i -E 'TCP_%s|brook_tcp_%s|ipt2socks_tcp_%s' >/dev/null",
appname, i, i, i)) == 0
"ps -w | grep -v grep | grep -v kcptun | grep '%s/bin/' | grep -i -E 'TCP_%s' >/dev/null",
appname, i)) == 0
end
local udp_node_num = luci.sys.exec(
@ -137,8 +142,8 @@ function status()
for i = 1, udp_node_num, 1 do
e["udp_node%s_status" % i] = luci.sys.call(
string.format(
"ps -w | grep -v grep | grep '%s/bin/' | grep -i -E 'UDP_%s|brook_udp_%s|ipt2socks_udp_%s' >/dev/null",
appname, i, i, i)) == 0
"ps -w | grep -v grep | grep '%s/bin/' | grep -i -E 'UDP_%s' >/dev/null",
appname, i)) == 0
end
local socks5_node_num = luci.sys.exec(
@ -151,7 +156,7 @@ function status()
appname, i)) == 0
e["socks5_node%s_status" % i] = luci.sys.call(
string.format(
"ps -w | grep -v grep | grep '%s/bin/' | grep -i -E 'SOCKS5_%s|brook_socks_%s' >/dev/null",
"ps -w | grep -v grep | grep -v kcptun | grep '%s/bin/' | grep -i -E 'SOCKS_%s|SOCKS5_%s' >/dev/null",
appname, i, i)) == 0
end
luci.http.prepare_content("application/json")
@ -268,6 +273,16 @@ function update_rules()
"' > /dev/null 2>&1 &")
end
function luci_check()
local json = passwall.to_check("")
http_write_json(json)
end
function luci_update()
local json = passwall.update_luci(http.formvalue("url"), http.formvalue("save"))
http_write_json(json)
end
function kcptun_check()
local json = kcptun.to_check("")
http_write_json(json)

View File

@ -0,0 +1,108 @@
module("luci.model.cbi.passwall.api.passwall", package.seeall)
local fs = require "nixio.fs"
local sys = require "luci.sys"
local util = require "luci.util"
local i18n = require "luci.i18n"
local api = require "luci.model.cbi.passwall.api.api"
local luci_api =
"https://api.github.com/repos/lienol/openwrt-package/releases/latest"
function get_luci_version()
local ipkg = require "luci.model.ipkg"
local package_name = "luci-app-passwall"
local package_info = ipkg.info(package_name) or {}
if next(package_info) ~= nil then
return package_info[package_name]["Version"]
end
return ""
end
function to_check()
local json = api.get_api_json(luci_api)
if json.tag_name == nil then
return {
code = 1,
error = i18n.translate("Get remote version info failed.")
}
end
local remote_version = json.tag_name:match("[^v]+")
local needs_update = api.compare_versions(get_luci_version(client_file),
"<", remote_version)
local html_url, download_url
if needs_update then
html_url = json.html_url
for _, v in ipairs(json.assets) do
local n = v.name
if n then
if n:match("luci%-app%-passwall") then
download_url = v.browser_download_url
end
end
end
end
if needs_update and not download_url then
return {
code = 1,
now_version = get_luci_version(),
version = remote_version,
html_url = html_url,
error = i18n.translate(
"New version found, but failed to get new version download url.")
}
end
return {
code = 0,
update = needs_update,
now_version = get_luci_version(),
version = remote_version,
url = {html = html_url, download = download_url}
}
end
function update_luci(url, save)
if not url or url == "" then
return {code = 1, error = i18n.translate("Download url is required.")}
end
sys.call("/bin/rm -f /tmp/luci_passwall.*.ipk")
local tmp_file =
util.trim(util.exec("mktemp -u -t luci_passwall.XXXXXX")) .. ".ipk"
local result = api.exec(api.wget,
{"-O", tmp_file, url, api._unpack(api.wget_args)},
nil, api.command_timeout) == 0
if not result then
api.exec("/bin/rm", {"-f", tmp_file})
return {
code = 1,
error = i18n.translatef("File download failed or timed out: %s", url)
}
end
local opkg_args = {"--force-downgrade", "--force-reinstall"}
if save ~= "true" then opkg_args[#opkg_args + 1] = "--force-maintainer" end
result =
api.exec("/bin/opkg", {"install", tmp_file, api._unpack(opkg_args)}) ==
0
if not result then
api.exec("/bin/rm", {"-f", tmp_file})
return {code = 1, error = i18n.translate("Package update failed.")}
end
api.exec("/bin/rm", {"-f", tmp_file})
api.exec("/bin/rm", {"-rf", "/tmp/luci-indexcache", "/tmp/luci-modulecache"})
return {code = 0}
end

View File

@ -107,23 +107,20 @@ for i = 1, socks5_node_num, 1 do
for _, key in pairs(key_table) do o:value(key, n[key]) end
end
if api.uci_get_type("global_other", "wangejibadns", "0") == "1" then
o =
s:option(Value, "up_china_dns", translate("China DNS Server") .. "(UDP)")
-- o.description = translate("If you want to work with other DNS acceleration services, use the default.<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 = "default"
o:value("default", translate("default"))
o:value("dnsbyisp", translate("dnsbyisp"))
o:value("223.5.5.5", "223.5.5.5 (" .. translate("Ali") .. "DNS)")
o:value("223.6.6.6", "223.6.6.6 (" .. translate("Ali") .. "DNS)")
o:value("114.114.114.114", "114.114.114.114 (114DNS)")
o:value("114.114.115.115", "114.114.115.115 (114DNS)")
o:value("119.29.29.29", "119.29.29.29 (DNSPOD DNS)")
o:value("182.254.116.116", "182.254.116.116 (DNSPOD DNS)")
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)")
end
o = s:option(Value, "up_china_dns", translate("China DNS Server") .. "(UDP)")
-- o.description = translate("If you want to work with other DNS acceleration services, use the default.<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 = "default"
o:value("default", translate("default"))
o:value("dnsbyisp", translate("dnsbyisp"))
o:value("223.5.5.5", "223.5.5.5 (" .. translate("Ali") .. "DNS)")
o:value("223.6.6.6", "223.6.6.6 (" .. translate("Ali") .. "DNS)")
o:value("114.114.114.114", "114.114.114.114 (114DNS)")
o:value("114.114.115.115", "114.114.115.115 (114DNS)")
o:value("119.29.29.29", "119.29.29.29 (DNSPOD DNS)")
o:value("182.254.116.116", "182.254.116.116 (DNSPOD DNS)")
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"))

View File

@ -106,6 +106,7 @@ s = m:section(TypedSection, "global_app", translate("App Update"),
translate("Please confirm that your firmware supports FPU.") ..
"</font>")
s.anonymous = true
s:append(Template("passwall/rule/passwall_version"))
s:append(Template("passwall/rule/v2ray_version"))
s:append(Template("passwall/rule/kcptun_version"))
s:append(Template("passwall/rule/brook_version"))

View File

@ -0,0 +1,156 @@
<%
local api = require "luci.model.cbi.passwall.api.api"
local dsp = require "luci.dispatcher"
function get_luci_version()
local ipkg = require "luci.model.ipkg"
local package_name = "luci-app-passwall"
local package_info = ipkg.info(package_name) or {}
if next(package_info) ~= nil then
return package_info[package_name]["Version"]
end
return ""
end
local passwall_version = get_luci_version()
-%>
<script type="text/javascript">
//<![CDATA[
var passwallInfo;
var tokenStr = '<%=token%>';
var noUpdateText = '<%:It is the latest version%>';
var updateSuccessText = '<%:Update successful%>';
var clickToUpdateText = '<%:Click to update%>';
var inProgressText = '<%:Updating...%>';
var unexpectedErrorText = '<%:Unexpected error%>';
var updateInProgressNotice = '<%:Updating, are you sure to close?%>';
var downloadingText = '<%:Downloading...%>';
var decompressioningText = '<%:Unpacking...%>';
var movingText = '<%:Moving...%>';
window.onload = function() {
var passwallCheckBtn = document.getElementById('_passwall-check_btn');
var passwallDetailElm = document.getElementById('_passwall-check_btn-detail');
};
function addPageNotice_luci() {
window.onbeforeunload = function(e) {
e.returnValue = updateInProgressNotice;
return updateInProgressNotice;
};
}
function removePageNotice_luci() {
window.onbeforeunload = undefined;
}
function onUpdateSuccess_luci(btn) {
alert(updateSuccessText);
if(btn) {
btn.value = updateSuccessText;
btn.placeholder = updateSuccessText;
btn.disabled = true;
}
window.setTimeout(function() {
window.location.reload();
}, 1000);
}
function onRequestError_luci(btn, errorMessage) {
btn.disabled = false;
btn.value = btn.placeholder;
if(errorMessage) {
alert(errorMessage);
}
}
function onBtnClick_luci(btn) {
if(passwallInfo === undefined) {
checkUpdate_luci(btn);
} else {
doUpdate_luci(btn);
}
}
function checkUpdate_luci(btn) {
btn.disabled = true;
btn.value = inProgressText;
addPageNotice_luci();
var ckeckDetailElm = document.getElementById(btn.id + '-detail');
XHR.get('<%=dsp.build_url("admin/vpn/passwall/luci_check")%>', {
token: tokenStr,
arch: ''
}, function(x,json) {
removePageNotice_luci();
if(json.code) {
passwallInfo = undefined;
onRequestError_luci(btn, json.error);
} else {
if(json.update) {
passwallInfo = json;
btn.disabled = false;
btn.value = clickToUpdateText;
btn.placeholder = clickToUpdateText;
if(ckeckDetailElm) {
var urlNode = '';
if(json.version) {
urlNode = '<em style="color:red;">最新版本号:' + json.version + '</em>';
if(json.url && json.url.html) {
urlNode = '<a href="' + json.url.html + '" target="_blank">' + urlNode + '</a>';
}
}
ckeckDetailElm.innerHTML = urlNode;
}
} else {
btn.disabled = true;
btn.value = noUpdateText;
}
}
},300);
}
function doUpdate_luci(btn) {
btn.disabled = true;
btn.value = downloadingText;
addPageNotice_luci();
var updateUrl = '<%=dsp.build_url("admin/vpn/passwall/luci_update")%>';
// Download file
XHR.get(updateUrl, {
token: tokenStr,
url: passwallInfo ? passwallInfo.url.download : '',
save: true
}, function(x,json) {
removePageNotice_luci();
if(json.code) {
onRequestError_luci(btn, json.error);
} else {
onUpdateSuccess_luci(btn);
}
},300)
}
//]]>
</script>
<div class="cbi-value">
<label class="cbi-value-title">PassWall
<%:Version%>
</label>
<div class="cbi-value-field">
<div class="cbi-value-description">
<span><%=passwall_version%>】</span>
<input class="cbi-button cbi-input-apply" type="button" id="_passwall-check_btn" onclick="onBtnClick_luci(this);" value="<%:Manually update%>" />
<span id="_passwall-check_btn-detail"></span>
</div>
</div>
</div>

View File

@ -43,6 +43,12 @@ config global_other
config global_rules
option auto_update '0'
option chnlist_update '1'
option chnroute_update '1'
option gfwlist_update '1'
option gfwlist_version '2020-02-27'
option chnroute_version '2020-02-27'
option chnlist_version '2020-02-27'
config global_app
option v2ray_file '/usr/bin/v2ray/'
@ -54,5 +60,5 @@ config global_subscribe
option auto_update_subscribe '0'
config auto_switch
option testing_time '3'
option testing_time '1'
option enable '0'

View File

@ -8,6 +8,7 @@ CONFIG=passwall
TMP_PATH=/var/etc/$CONFIG
TMP_BIN_PATH=$TMP_PATH/bin
TMP_ID_PATH=$TMP_PATH/id
TMP_PORT_PATH=$TMP_PATH/port
LOCK_FILE=/var/lock/$CONFIG.lock
LOG_FILE=/var/log/$CONFIG.log
APP_PATH=/usr/share/$CONFIG
@ -151,6 +152,16 @@ for i in $(seq 1 $SOCKS5_NODE_NUM); do
eval SOCKS5_NODE$i=$(config_t_get global socks5_node$i nil)
done
TCP_REDIR_PORT1=$(config_t_get global_forwarding tcp_redir_port 1041)
TCP_REDIR_PORT2=$(expr $TCP_REDIR_PORT1 + 1)
TCP_REDIR_PORT3=$(expr $TCP_REDIR_PORT2 + 1)
UDP_REDIR_PORT1=$(config_t_get global_forwarding udp_redir_port 1051)
UDP_REDIR_PORT2=$(expr $UDP_REDIR_PORT1 + 1)
UDP_REDIR_PORT3=$(expr $UDP_REDIR_PORT2 + 1)
SOCKS5_PROXY_PORT1=$(config_t_get global_forwarding socks5_proxy_port 1081)
SOCKS5_PROXY_PORT2=$(expr $SOCKS5_PROXY_PORT1 + 1)
SOCKS5_PROXY_PORT3=$(expr $SOCKS5_PROXY_PORT2 + 1)
[ "$UDP_NODE1" == "tcp" ] && UDP_NODE1=$TCP_NODE1
[ "$SOCKS5_NODE1" == "tcp" ] && SOCKS5_NODE1=$TCP_NODE1
@ -184,8 +195,6 @@ load_config() {
LOCALHOST_PROXY_MODE=$(config_t_get global localhost_proxy_mode default)
[ "$LOCALHOST_PROXY_MODE" == "default" ] && LOCALHOST_PROXY_MODE=$PROXY_MODE
UP_CHINA_DNS=$(config_t_get global up_china_dns dnsbyisp)
wangejibadns=$(config_t_get global_other wangejibadns 0)
[ "$wangejibadns" == "0" ] && UP_CHINA_DNS="default"
[ "$UP_CHINA_DNS" == "default" ] && IS_DEFAULT_CHINA_DNS=1
[ ! -f "$RESOLVFILE" -o ! -s "$RESOLVFILE" ] && RESOLVFILE=/tmp/resolv.conf.auto
if [ "$UP_CHINA_DNS" == "dnsbyisp" -o "$UP_CHINA_DNS" == "default" ]; then
@ -206,17 +215,8 @@ load_config() {
UP_CHINA_DNS="223.5.5.5"
fi
fi
TCP_REDIR_PORT1=$(config_t_get global_forwarding tcp_redir_port 1041)
TCP_REDIR_PORT2=$(expr $TCP_REDIR_PORT1 + 1)
TCP_REDIR_PORT3=$(expr $TCP_REDIR_PORT2 + 1)
UDP_REDIR_PORT1=$(config_t_get global_forwarding udp_redir_port 1051)
UDP_REDIR_PORT2=$(expr $UDP_REDIR_PORT1 + 1)
UDP_REDIR_PORT3=$(expr $UDP_REDIR_PORT2 + 1)
SOCKS5_PROXY_PORT1=$(config_t_get global_forwarding socks5_proxy_port 1081)
SOCKS5_PROXY_PORT2=$(expr $SOCKS5_PROXY_PORT1 + 1)
SOCKS5_PROXY_PORT3=$(expr $SOCKS5_PROXY_PORT2 + 1)
PROXY_IPV6=$(config_t_get global_forwarding proxy_ipv6 0)
mkdir -p /var/etc $TMP_PATH $TMP_BIN_PATH $TMP_ID_PATH
mkdir -p /var/etc $TMP_PATH $TMP_BIN_PATH $TMP_ID_PATH $TMP_PORT_PATH
return 0
}
@ -270,7 +270,7 @@ gen_start_config() {
port=$(config_n_get $node port)
[ -n "$server_host" -a -n "$port" ] && {
# 判断节点服务器地址是否URL并去掉~
server_host=$(echo $server_host | sed 's/^\(http:\/\/\|https:\/\/\)//g' | awk -F '/' '{print $1}')
server_host=$(echo $server_host | sed 's/^\(https:\/\/\|http:\/\/\)//g' | awk -F '/' '{print $1}')
# 判断节点服务器地址是否包含汉字~
local tmp=$(echo -n $server_host | awk '{print gensub(/[!-~]/,"","g",$0)}')
[ -n "$tmp" ] && {
@ -286,10 +286,10 @@ gen_start_config() {
echolog "Socks5节点不能使用Socks5代理节点"
elif [ "$type" == "v2ray" -o "$type" == "v2ray_balancing" -o "$type" == "v2ray_shunt" ]; then
lua $API_GEN_V2RAY $node nil nil $local_port >$config_file
ln_start_bin $(config_t_get global_app v2ray_file $(find_bin v2ray))/v2ray v2ray "-config=$config_file"
ln_start_bin $(config_t_get global_app v2ray_file $(find_bin v2ray))/v2ray v2ray_socks_$5 "-config=$config_file"
elif [ "$type" == "trojan" ]; then
lua $API_GEN_TROJAN $node client "0.0.0.0" $local_port >$config_file
ln_start_bin $(find_bin trojan) trojan "-c $config_file"
ln_start_bin $(find_bin trojan) trojan_socks_$5 "-c $config_file"
elif [ "$type" == "brook" ]; then
local protocol=$(config_n_get $node brook_protocol client)
local brook_tls=$(config_n_get $node brook_tls 0)
@ -299,7 +299,7 @@ gen_start_config() {
ln_start_bin $(config_t_get global_app brook_file $(find_bin brook)) brook_socks_$5 "$protocol -l 0.0.0.0:$local_port -i 0.0.0.0 -s $server_host:$port -p $(config_n_get $node password)"
elif [ "$type" == "ssr" ]; then
gen_ss_ssr_config_file ssr $local_port 0 $node $config_file
ln_start_bin $(find_bin ssr-local) ssr-local "-c $config_file -b 0.0.0.0 -u"
ln_start_bin $(find_bin ssr-local) ssr-local_socks_$5 "-c $config_file -b 0.0.0.0 -u"
elif [ "$type" == "ss" ]; then
gen_ss_ssr_config_file ss $local_port 0 $node $config_file
local plugin_params=""
@ -310,7 +310,7 @@ gen_start_config() {
plugin_params="--plugin $plugin --plugin-opts $opts"
}
fi
ln_start_bin $(find_bin ss-local) ss-local "-c $config_file -b 0.0.0.0 -u $plugin_params"
ln_start_bin $(find_bin ss-local) ss-local_socks_$5 "-c $config_file -b 0.0.0.0 -u $plugin_params"
fi
fi
@ -324,19 +324,15 @@ gen_start_config() {
local server_password=$(config_n_get $node password)
eval port=\$UDP_REDIR_PORT$5
ln_start_bin $(find_bin ipt2socks) ipt2socks_udp_$5 "-U -l $port -b 0.0.0.0 -s $node_address -p $node_port -R"
# local redsocks_config_file=$TMP_PATH/UDP_$i.conf
# gen_redsocks_config $redsocks_config_file udp $port $node_address $node_port $server_username $server_password
# ln_start_bin $(find_bin redsocks2) redsocks2 "-c $redsocks_config_file"
elif [ "$type" == "v2ray" -o "$type" == "v2ray_balancing" -o "$type" == "v2ray_shunt" ]; then
lua $API_GEN_V2RAY $node udp $local_port nil >$config_file
ln_start_bin $(config_t_get global_app v2ray_file $(find_bin v2ray))/v2ray v2ray "-config=$config_file"
ln_start_bin $(config_t_get global_app v2ray_file $(find_bin v2ray))/v2ray v2ray_udp_$5 "-config=$config_file"
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 $API_GEN_TROJAN $node client "127.0.0.1" $socks5_port >$config_file
ln_start_bin $(find_bin trojan) trojan "-c $config_file"
ln_start_bin $(find_bin trojan) trojan_udp_$5 "-c $config_file"
local node_address=$(config_n_get $node address)
local node_port=$(config_n_get $node port)
@ -344,10 +340,6 @@ gen_start_config() {
local server_password=$(config_n_get $node password)
eval port=\$UDP_REDIR_PORT$5
ln_start_bin $(find_bin ipt2socks) ipt2socks_udp_$5 "-U -l $port -b 0.0.0.0 -s 127.0.0.1 -p $socks5_port -R"
# local redsocks_config_file=$TMP_PATH/redsocks_UDP_$i.conf
# gen_redsocks_config $redsocks_config_file udp $port "127.0.0.1" $socks5_port
# ln_start_bin $(find_bin redsocks2) redsocks2 "-c $redsocks_config_file"
elif [ "$type" == "brook" ]; then
local protocol=$(config_n_get $node brook_protocol client)
if [ "$protocol" == "wsclient" ]; then
@ -357,7 +349,7 @@ gen_start_config() {
fi
elif [ "$type" == "ssr" ]; then
gen_ss_ssr_config_file ssr $local_port 0 $node $config_file
ln_start_bin $(find_bin ssr-redir) ssr-redir "-c $config_file -U"
ln_start_bin $(find_bin ssr-redir) ssr-redir_udp_$5 "-c $config_file -U"
elif [ "$type" == "ss" ]; then
gen_ss_ssr_config_file ss $local_port 0 $node $config_file
local plugin_params=""
@ -368,7 +360,7 @@ gen_start_config() {
plugin_params="--plugin $plugin --plugin-opts $opts"
}
fi
ln_start_bin $(find_bin ss-redir) ss-redir "-c $config_file -U $plugin_params"
ln_start_bin $(find_bin ss-redir) ss-redir_udp_$5 "-c $config_file -U $plugin_params"
fi
fi
@ -382,17 +374,13 @@ gen_start_config() {
local server_password=$(config_n_get $node password)
eval port=\$TCP_REDIR_PORT$5
ln_start_bin $(find_bin ipt2socks) ipt2socks_tcp_$5 "-T -l $port -b 0.0.0.0 -s $node_address -p $node_port -R"
# local redsocks_config_file=$TMP_PATH/TCP_$i.conf
# gen_redsocks_config $redsocks_config_file tcp $port $node_address $socks5_port $server_username $server_password
# ln_start_bin $(find_bin redsocks2) redsocks2 "-c $redsocks_config_file"
elif [ "$type" == "v2ray" -o "$type" == "v2ray_balancing" -o "$type" == "v2ray_shunt" ]; then
lua $API_GEN_V2RAY $node tcp $local_port nil >$config_file
ln_start_bin $(config_t_get global_app v2ray_file $(find_bin v2ray))/v2ray v2ray "-config=$config_file"
ln_start_bin $(config_t_get global_app v2ray_file $(find_bin v2ray))/v2ray v2ray_tcp_$5 "-config=$config_file"
elif [ "$type" == "trojan" ]; then
lua $API_GEN_TROJAN $node nat "0.0.0.0" $local_port >$config_file
for k in $(seq 1 $process); do
ln_start_bin $(find_bin trojan) trojan "-c $config_file"
ln_start_bin $(find_bin trojan) trojan_tcp_$5 "-c $config_file"
done
else
local kcptun_use=$(config_n_get $node use_kcp 0)
@ -414,7 +402,7 @@ gen_start_config() {
if [ "$type" == "ssr" ]; then
gen_ss_ssr_config_file ssr $local_port $kcptun_use $node $config_file
for k in $(seq 1 $process); do
ln_start_bin $(find_bin ssr-redir) ssr-redir "-c $config_file"
ln_start_bin $(find_bin ssr-redir) ssr-redir_tcp_$5 "-c $config_file"
done
elif [ "$type" == "ss" ]; then
gen_ss_ssr_config_file ss $local_port $kcptun_use $node $config_file
@ -427,7 +415,7 @@ gen_start_config() {
}
fi
for k in $(seq 1 $process); do
ln_start_bin $(find_bin ss-redir) ss-redir "-c $config_file $plugin_params"
ln_start_bin $(find_bin ss-redir) ss-redir_tcp_$5 "-c $config_file $plugin_params"
done
elif [ "$type" == "brook" ]; then
local server_ip=$server_host
@ -453,6 +441,23 @@ gen_start_config() {
return 0
}
node_switch() {
local i=$4
local node=$5
[ -n "$1" -a -n "$2" -a "$2" != "nil" -a -n "$3" -a -n "$4" -a -n "$5" ] && {
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
eval current_port=\$${1}_${2}_PORT$i
local port=$(cat $TMP_PORT_PATH/${1}_${i})
gen_start_config $node $port $1 $config_file $i
echo $node > $TMP_ID_PATH/${1}_${i}
local node_net=$(echo $1 | tr 'A-Z' 'a-z')
uci set $CONFIG.@global[0].${node_net}_node${i}=$node
uci commit $CONFIG
/etc/init.d/dnsmasq restart >/dev/null 2>&1 &
}
}
start_redir() {
eval num=\$${1}_NODE_NUM
for i in $(seq 1 $num); do
@ -466,6 +471,7 @@ start_redir() {
gen_start_config $node $port $1 $config_file $i
#eval ip=\$${1}_NODE${i}_IP
echo $node > $TMP_ID_PATH/${1}_${i}
echo $port > $TMP_PORT_PATH/${1}_${i}
}
done
}
@ -667,71 +673,6 @@ add_dnsmasq() {
echolog "dnsmasq生成配置文件。"
}
gen_redsocks_config() {
protocol=$2
local_port=$3
proxy_server=$4
proxy_port=$5
proxy_username=$6
[ -n "$proxy_username" ] && proxy_username="login = $proxy_username;"
proxy_password=$7
[ -n "$proxy_password" ] && proxy_password="password = $proxy_password;"
[ -n "$1" ] && {
cat >$1 <<-EOF
base {
log_debug = off;
log_info = off;
log = "file:/dev/null";
daemon = on;
redirector = iptables;
}
EOF
if [ "$protocol" == "tcp" ]; then
cat >>$1 <<-EOF
redsocks {
local_ip = 0.0.0.0;
local_port = $local_port;
type = socks5;
autoproxy = 0;
ip = $proxy_server;
port = $proxy_port;
$proxy_username
$proxy_password
}
autoproxy {
no_quick_check_seconds = 300;
quick_connect_timeout = 2;
}
ipcache {
cache_size = 4;
stale_time = 7200;
autosave_interval = 3600;
port_check = 0;
}
EOF
elif [ "$protocol" == "udp" ]; then
cat >>$1 <<-EOF
redudp {
local_ip = 0.0.0.0;
local_port = $local_port;
type = socks5;
ip = $proxy_server;
port = $proxy_port;
$proxy_username
$proxy_password
udp_timeout = 60;
udp_timeout_stream = 360;
}
EOF
fi
}
}
gen_pdnsd_config() {
pdnsd_dir=$TMP_PATH/pdnsd
mkdir -p $pdnsd_dir
@ -1008,6 +949,9 @@ stop() {
}
case $1 in
node_switch)
node_switch $2 $3 $4 $5 $6
;;
stop)
[ -n "$2" -a "$2" == "force" ] && force_stop
stop

View File

@ -43,12 +43,12 @@ config global_other
config global_rules
option auto_update '0'
option gfwlist_update '1'
option chnroute_update '1'
option chnlist_update '1'
option gfwlist_version '2019-12-10'
option chnroute_version '2019-12-05'
option chnlist_version '2020-01-06'
option chnroute_update '1'
option gfwlist_update '1'
option gfwlist_version '2020-02-27'
option chnroute_version '2020-02-27'
option chnlist_version '2020-02-27'
config global_app
option v2ray_file '/usr/bin/v2ray/'
@ -60,5 +60,5 @@ config global_subscribe
option auto_update_subscribe '0'
config auto_switch
option testing_time '3'
option testing_time '1'
option enable '0'

View File

@ -48,7 +48,7 @@ ENABLED=$(config_t_get global enabled 0)
exit 0
fi
fi
icount=$(ps -w | grep -v grep | grep $RUN_BIN_PATH | grep -i -E "TCP_${i}|brook_tcp_${i}|ipt2socks_tcp_${i}" | wc -l)
icount=$(ps -w | grep -v grep | grep -v kcptun | grep $RUN_BIN_PATH | grep -i -E "TCP_${i}" | wc -l)
if [ $icount = 0 ]; then
/etc/init.d/passwall restart
exit 0
@ -62,7 +62,7 @@ ENABLED=$(config_t_get global enabled 0)
eval tmp_node=\$UDP_NODE$i
if [ "$tmp_node" != "nil" ]; then
[ "$tmp_node" == "default" ] && tmp_node=$TCP_NODE1
icount=$(ps -w | grep -v grep | grep $RUN_BIN_PATH | grep -i -E "UDP_${i}|brook_udp_${i}|ipt2socks_udp_${i}" | wc -l)
icount=$(ps -w | grep -v grep | grep $RUN_BIN_PATH | grep -i -E "UDP_${i}" | wc -l)
if [ $icount = 0 ]; then
/etc/init.d/passwall restart
exit 0
@ -74,7 +74,7 @@ ENABLED=$(config_t_get global enabled 0)
for i in $(seq 1 $SOCKS5_NODE_NUM); do
eval tmp_node=\$SOCKS5_NODE$i
if [ "$tmp_node" != "nil" ]; then
icount=$(ps -w | grep -v grep | grep $RUN_BIN_PATH | grep -i -E "SOCKS5_${i}|brook_socks_${i}" | wc -l)
icount=$(ps -w | grep -v grep | grep -v kcptun | grep $RUN_BIN_PATH | grep -i -E "SOCKS_${i}|SOCKS5_${i}" | wc -l)
if [ $icount = 0 ]; then
/etc/init.d/passwall restart
exit 0

View File

@ -46,8 +46,8 @@ test_proxy() {
test_auto_switch() {
local type=$1
local index=$2
local b_tcp_nodes=$3
local index=$4
local b_tcp_nodes=$5
local now_node
if [ -f "/var/etc/$CONFIG/id/${type}_${index}" ]; then
now_node=$(cat /var/etc/$CONFIG/id/${type}_${index})
@ -61,7 +61,7 @@ test_auto_switch() {
return 1
elif [ "$status" == 1 ]; then
echolog "自动切换检测:${type}_${index}节点异常,开始切换节点!"
new_node=
local new_node
in_backup_nodes=$(echo $b_tcp_nodes | grep $now_node)
# 判断当前节点是否存在于备用节点列表里
if [ -z "$in_backup_nodes" ]; then
@ -77,14 +77,11 @@ test_auto_switch() {
new_node=$next_node
fi
fi
rm -f $LOCK_FILE
uci set $CONFIG.@global[0].tcp_node${index}=$new_node
uci commit $CONFIG
/etc/init.d/$CONFIG restart > /dev/null &
/usr/share/passwall/app.sh node_switch $type $2 $3 $index $new_node
echolog "自动切换检测:${type}_${index}节点切换完毕!"
return 0
elif [ "$status" == 0 ]; then
echolog "自动切换检测:${type}_${index}节点正常。"
#echolog "自动切换检测:${type}_${index}节点正常。"
return 0
fi
}
@ -106,7 +103,7 @@ start() {
eval TCP_NODE$i=\"$(config_t_get auto_switch tcp_node$i nil)\"
eval tmp=\$TCP_NODE$i
[ -n "$tmp" ] && {
test_auto_switch TCP $i $tmp
test_auto_switch TCP REDIR tcp $i "$tmp"
}
done