Skip to content

Commit 4cb1a11

Browse files
handsomejiLienol
authored andcommitted
passwall : fix kcptun can't run bug (Openwrt-Passwall#178)
1 parent 01c57c7 commit 4cb1a11

File tree

5 files changed

+41
-56
lines changed

5 files changed

+41
-56
lines changed

lienol/luci-app-passwall/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
77

88
PKG_NAME:=luci-app-passwall
99
PKG_VERSION:=3.3
10-
PKG_RELEASE:=36-20200124
10+
PKG_RELEASE:=38-20200128
1111

1212
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
1313

lienol/luci-app-passwall/luasrc/model/cbi/passwall/global.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,14 @@ o:value("208.67.222.222,208.67.220.220",
148148
o:depends("dns_mode", "chinadns-ng")
149149

150150
---- Use TCP Node Resolve DNS
151-
if is_installed("pdnsd") or is_installed("pdnsd-alt") or is_finded("pdnsd") then
151+
--[[ if is_installed("pdnsd") or is_installed("pdnsd-alt") or is_finded("pdnsd") then
152152
o = s:option(Flag, "use_tcp_node_resolve_dns",
153153
translate("Use TCP Node Resolve DNS"),
154154
translate("If checked, DNS is resolved using the TCP node."))
155155
o.default = 1
156156
o:depends("dns_mode", "pdnsd")
157157
end
158+
--]]
158159

159160
o = s:option(Value, "dns2socks_forward", translate("DNS Address"))
160161
o.default = "8.8.4.4"

lienol/luci-app-passwall/luasrc/view/passwall/global/status.htm

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ <h4 id="status_udp_node">UDP<br /><span class="red"><%:NOT RUNNING%></span></h4>
142142
<div class="pure-u-1-4">
143143
<div class="block pure-g">
144144
<div class="pure-u-16-24">
145-
<h4 id="status_socks5_node">SOCKS5<br /><span class="red"><%:NOT RUNNING%></span></h4>
145+
<h4 id="status_socks5_node">Socks5<br /><span class="red"><%:NOT RUNNING%></span></h4>
146146
</div>
147147
<div class="pure-u-8-24">
148148
<div class="img-con">
@@ -165,7 +165,6 @@ <h4 id="status_dns">DNS<br /><span class="red"><%:NOT RUNNING%></span></h4>
165165
</div>
166166
</div>
167167
</div>
168-
<% if ipkg.installed("haproxy") or is_finded("haproxy*") then %>
169168
<div class="pure-u-1-4">
170169
<div class="block pure-g">
171170
<div class="pure-u-16-24">
@@ -179,12 +178,10 @@ <h4 id="status_haproxy"><%:Load Balancing%><br /><span class="red"><%:NOT RUNNIN
179178
</div>
180179
</div>
181180
</div>
182-
<% end %>
183-
<% if ipkg.installed("kcptun") or is_finded("kcptun*") then %>
184181
<div class="pure-u-1-4">
185182
<div class="block pure-g">
186183
<div class="pure-u-16-24">
187-
<h4 id="status_kcptun">KcpTun<br /><span class="red"><%:NOT RUNNING%></span></h4>
184+
<h4 id="status_kcptun">Kcptun<br /><span class="red"><%:NOT RUNNING%></span></h4>
188185
</div>
189186
<div class="pure-u-8-24">
190187
<div class="img-con">
@@ -194,7 +191,6 @@ <h4 id="status_kcptun">KcpTun<br /><span class="red"><%:NOT RUNNING%></span></h4
194191
</div>
195192
</div>
196193
</div>
197-
<% end %>
198194
<div class="pure-u-1-4 check" onclick="check_connect('baidu')">
199195
<div class="block pure-g">
200196
<div class="pure-u-16-24">
@@ -316,7 +312,7 @@ <h4>IP111.cn<br /><span class="red"><%:Touch Check%></span></h4>
316312
if (socks5_node_num >= 1) {
317313
var status_socks5_node = document.getElementById('status_socks5_node');
318314
if (status_socks5_node) {
319-
var text = 'SOCKS5<br />';
315+
var text = 'Socks5<br />';
320316
if (socks5_node_num == 1) {
321317
if (data["socks5_node1_status"])
322318
text += '<span class="green"><%:RUNNING%></span>';
@@ -349,9 +345,9 @@ <h4>IP111.cn<br /><span class="red"><%:Touch Check%></span></h4>
349345
}
350346
if (status_kcptun) {
351347
if (data.kcptun_status) {
352-
status_kcptun.innerHTML = 'KcpTun<br /><span class="green"><%:RUNNING%></span>'
348+
status_kcptun.innerHTML = 'Kcptun<br /><span class="green"><%:RUNNING%></span>'
353349
} else {
354-
status_kcptun.innerHTML = 'KcpTun<br /><span class="red"><%:NOT RUNNING%></span>'
350+
status_kcptun.innerHTML = 'Kcptun<br /><span class="red"><%:NOT RUNNING%></span>'
355351
}
356352
}
357353
}

lienol/luci-app-passwall/root/usr/share/passwall/app.sh

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -527,46 +527,30 @@ gen_start_config() {
527527
kcptun_use=$(config_n_get $node use_kcp 0)
528528
kcptun_server_host=$(config_n_get $node kcp_server)
529529
kcptun_port=$(config_n_get $node kcp_port)
530-
kcptun_config=$(config_n_get $node kcp_opts)
531-
kcptun_path=""
530+
kcptun_config="$(config_n_get $node kcp_opts)"
531+
kcptun_bin=$(config_t_get global_app kcptun_client_file $(find_bin kcptun-client))
532532
lbenabled=$(config_t_get global_haproxy balancing_enable 0)
533-
if [ "$kcptun_use" == "1" ] && ([ -z "$kcptun_port" ] || [ -z "$kcptun_config" ]); then
534-
echolog "【检测到启用KCP,但未配置KCP参数】,跳过~"
535-
fi
536-
if [ "$kcptun_use" == "1" -a -n "$kcptun_port" -a -n "$kcptun_config" -a "$lbenabled" == "1" ]; then
537-
echolog "【检测到启用KCP,但KCP与负载均衡二者不能同时开启】,跳过~"
533+
if [ -z "$kcptun_bin" ]; then
534+
echolog "【未安装Kcptun主程序,请到自动更新下载Kcptun】,跳过~"
535+
force_stop
538536
fi
539-
540-
if [ "$kcptun_use" == "1" ]; then
541-
if [ -f "$(config_t_get global_kcptun kcptun_client_file)" ]; then
542-
kcptun_path=$(config_t_get global_kcptun kcptun_client_file)
543-
else
544-
temp=$(find_bin kcptun_client)
545-
[ -n "$temp" ] && kcptun_path=$temp
546-
fi
547-
fi
548-
549-
if [ "$kcptun_use" == "1" -a -z "$kcptun_path" ] && ([ -n "$kcptun_port" ] || [ -n "$kcptun_config" ]); then
550-
echolog "【检测到启用KCP,但未安装KCP主程序,请自行到自动更新下载KCP】,跳过~"
537+
if [ "$kcptun_use" == "1" ] && ([ -z "$kcptun_port" ] || [ -z "$kcptun_config" ]); then
538+
echolog "【未配置Kcptun参数】,跳过~"
539+
force_stop
551540
fi
552-
553-
if [ "$kcptun_use" == "1" -a -n "$kcptun_port" -a -n "$kcptun_config" -a "$lbenabled" == "0" -a -n "$kcptun_path" ]; then
541+
if [ "$kcptun_use" == "1" -a -n "$kcptun_port" -a -n "$kcptun_config" -a "$lbenabled" == "0" -a -f "$kcptun_bin" ]; then
554542
local run_kcptun_ip=$server_ip
555543
if [ -n "$kcptun_server_host" ]; then
556544
kcptun_use_ipv6=$(config_n_get $node kcp_use_ipv6)
557545
network_type="ipv4"
558546
[ "$kcptun_use_ipv6" == "1" ] && network_type="ipv6"
559547
kcptun_server_ip=$(get_host_ip $network_type $kcptun_server_host)
560-
TCP_NODE1_IP=$kcptun_server_ip
548+
eval TCP_NODE${5}_IP=$kcptun_server_ip
561549
run_kcptun_ip=$kcptun_server_ip
562-
echolog "KCP节点IP地址:$kcptun_server_ip"
563-
fi
564-
if [ -z "$kcptun_path" ]; then
565-
echolog "找不到Kcptun客户端主程序,无法启用!"
566-
else
567-
$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 &
568-
echolog "运行Kcptun..."
550+
echolog "Kcptun节点IP地址:$kcptun_server_ip"
569551
fi
552+
KCPTUN_REDIR_PORT=$(get_not_exists_port_after $KCPTUN_REDIR_PORT udp)
553+
$kcptun_bin --log $CONFIG_PATH/kcptun_${5}.log -l 0.0.0.0:$KCPTUN_REDIR_PORT -r $run_kcptun_ip:$kcptun_port $kcptun_config >/dev/null 2>&1 &
570554
fi
571555

572556
if [ "$type" == "ssr" ]; then
@@ -739,6 +723,7 @@ start_dns() {
739723
pdnsd)
740724
pdnsd_bin=$(find_bin pdnsd)
741725
[ -n "$pdnsd_bin" ] && {
726+
use_tcp_node_resolve_dns=1
742727
gen_pdnsd_config $DNS_PORT "cache"
743728
DNS_FORWARD=$(echo $DNS_FORWARD | sed 's/,/ /g')
744729
nohup $pdnsd_bin --daemon -c $pdnsd_dir/pdnsd.conf -d >/dev/null 2>&1 &
@@ -1154,18 +1139,22 @@ start() {
11541139
}
11551140

11561141
stop() {
1157-
while [ -f "$LOCK_FILE" ]; do
1158-
sleep 1s
1142+
failcount=1
1143+
while [ "$failcount" -le 10 ]; do
1144+
if [ -f "$LOCK_FILE" ]; then
1145+
let "failcount++"
1146+
sleep 1s
1147+
[ "$failcount" -ge 10 ] && rm -f "$LOCK_FILE"
1148+
else
1149+
break
1150+
fi
11591151
done
11601152
clean_log
11611153
source $APP_PATH/iptables.sh stop
11621154
kill_all brook dns2socks haproxy chinadns-ng ipt2socks v2ray-plugin
11631155
ps -w | grep -E "$CONFIG_TCP_FILE|$CONFIG_UDP_FILE|$CONFIG_SOCKS5_FILE" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
11641156
ps -w | grep -E "$CONFIG_PATH" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
1165-
ps -w | grep "kcptun_client" | grep "$KCPTUN_REDIR_PORT" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
1166-
rm -rf /var/pdnsd/pdnsd.cache
1167-
rm -rf $TMP_DNSMASQ_PATH
1168-
rm -rf $CONFIG_PATH
1157+
rm -rf $TMP_DNSMASQ_PATH $CONFIG_PATH
11691158
stop_dnsmasq
11701159
stop_crontab
11711160
echolog "关闭相关程序,清理相关文件和缓存完成。"

lienol/luci-app-passwall/root/usr/share/passwall/monitor.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ use_haproxy=$(config_t_get global_haproxy balancing_enable 0)
3535

3636
#tcp
3737
for i in $(seq 1 $TCP_NODE_NUM); do
38-
eval temp_server=\$TCP_NODE$i
39-
if [ "$temp_server" != "nil" ]; then
38+
eval tmp_node=\$TCP_NODE$i
39+
if [ "$tmp_node" != "nil" ]; then
4040
#kcptun
41-
use_kcp=$(config_n_get $temp_server use_kcp 0)
41+
use_kcp=$(config_n_get $tmp_node use_kcp 0)
4242
if [ $use_kcp -gt 0 ]; then
43-
kcp_port=$(config_t_get global_proxy kcptun_port 11183)
44-
icount=$(ps -w | grep kcptun-client | grep $kcp_port | grep -v grep | wc -l)
43+
icount=$(ps -w | grep kcptun-client | grep $CONFIG_PATH/kcptun_${i} | grep -v grep | wc -l)
4544
if [ $icount = 0 ]; then
4645
/etc/init.d/passwall restart
4746
exit 0
@@ -59,9 +58,9 @@ done
5958

6059
#udp
6160
for i in $(seq 1 $UDP_NODE_NUM); do
62-
eval temp_server=\$UDP_NODE$i
63-
if [ "$temp_server" != "nil" ]; then
64-
[ "$temp_server" == "default" ] && temp_server=$TCP_NODE1
61+
eval tmp_node=\$UDP_NODE$i
62+
if [ "$tmp_node" != "nil" ]; then
63+
[ "$tmp_node" == "default" ] && tmp_node=$TCP_NODE1
6564
[ -f "/var/etc/passwall/port/UDP_$i" ] && listen_port=$(echo -n `cat /var/etc/passwall/port/UDP_$i`)
6665
icount=$(ps -w | grep -v grep | grep -i -E "${CONFIG}/UDP_${i}|brook tproxy -l 0.0.0.0:${listen_port}|ipt2socks -U -l ${listen_port}" | wc -l)
6766
if [ $icount = 0 ]; then
@@ -73,8 +72,8 @@ done
7372

7473
#socks5
7574
for i in $(seq 1 $SOCKS5_NODE_NUM); do
76-
eval temp_server=\$SOCKS5_NODE$i
77-
if [ "$temp_server" != "nil" ]; then
75+
eval tmp_node=\$SOCKS5_NODE$i
76+
if [ "$tmp_node" != "nil" ]; then
7877
[ -f "/var/etc/passwall/port/SOCKS5_$i" ] && listen_port=$(echo -n `cat /var/etc/passwall/port/SOCKS5_$i`)
7978
icount=$(ps -w | grep -v grep | grep -i -E "${CONFIG}/SOCKS5_${i}|brook client -l 0.0.0.0:${listen_port}" | wc -l)
8079
if [ $icount = 0 ]; then

0 commit comments

Comments
 (0)