luci-app-passwall: sync with upstream source

This commit is contained in:
CN_SZTL 2020-03-04 12:18:30 +08:00
parent 766b7c3a60
commit eb76dc2347
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
11 changed files with 166 additions and 198 deletions

View File

@ -7,8 +7,8 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall
PKG_VERSION:=3.6
PKG_RELEASE:=9
PKG_DATE:=20200302
PKG_RELEASE:=10
PKG_DATE:=20200303
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

View File

@ -23,8 +23,8 @@ function index()
_("Basic Settings"), 1).dependent = true
entry({"admin", "vpn", "passwall", "node_list"}, cbi("passwall/node_list"),
_("Node List"), 2).dependent = true
-- entry({"admin", "vpn", "passwall", "auto_switch"},
-- cbi("passwall/auto_switch"), _("Auto Switch"), 3).leaf = true
entry({"admin", "vpn", "passwall", "auto_switch"},
cbi("passwall/auto_switch"), _("Auto Switch"), 3).leaf = true
entry({"admin", "vpn", "passwall", "other"},
cbi("passwall/other", {autoapply = true}), _("Other Settings"), 94).leaf =
true
@ -36,9 +36,6 @@ function index()
_("Rule Update"), 96).leaf = true
entry({"admin", "vpn", "passwall", "acl"}, cbi("passwall/acl"),
_("Access control"), 97).leaf = true
entry({"admin", "vpn", "passwall", "rule_list"},
cbi("passwall/rule_list", {autoapply = true}),
_("Set Blacklist And Whitelist"), 98).leaf = true
entry({"admin", "vpn", "passwall", "log"}, form("passwall/log"),
_("Watch Logs"), 99).leaf = true
entry({"admin", "vpn", "passwall", "node_config"},

View File

@ -1,26 +1,77 @@
local sys = require "luci.sys"
local webadmin = require "luci.tools.webadmin"
local uci = require"luci.model.uci".cursor()
local fs = require "nixio.fs"
local api = require "luci.model.cbi.passwall.api.api"
local appname = "passwall"
local n = {}
uci:foreach(appname, "nodes", function(e)
if e.type and e.address and e.remarks then
if e.use_kcp and e.use_kcp == "1" then
n[e[".name"]] = "%s+%s[%s]" % {e.type, "Kcptun", e.remarks}
else
n[e[".name"]] = "%s[%s]" % {e.type, e.remarks}
end
end
end)
local key_table = {}
for key, _ in pairs(n) do table.insert(key_table, key) end
table.sort(key_table)
m = Map("passwall")
-- [[ Rule List Settings ]]--
s = m:section(TypedSection, "global_rules")
s.anonymous = true
---- Whitelist Hosts
s:tab("w_hosts", translate("Whitelist Hosts"), "<font color='red'>" ..
translate("Join the white list of domain names will not go agent.") ..
"</font>")
local w_host_file = "/usr/share/passwall/rules/whitelist_host"
o = s:taboption("w_hosts", TextValue, "whitelist_host")
o.rows = 8
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(w_host_file) or "" end
o.write = function(self, section, value)
fs.writefile(w_host_file, value:gsub("\r\n", "\n"):gsub("http://", ""):gsub(
"https://", ""))
end
o.remove = function(self, section, value) fs.writefile(w_host_file, "") end
---- Whitelist IP
s:tab("w_ip", translate("Whitelist IP"), "<font color='red'>" .. translate(
"These had been joined ip addresses will not use proxy.Please input the ip address or ip address segment,every line can input only one ip address.For example,192.168.0.0/24 or 223.5.5.5.") ..
"</font>")
local w_ip_file = "/usr/share/passwall/rules/whitelist_ip"
o = s:taboption("w_ip", TextValue, "whitelist_ip")
o.rows = 8
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(w_ip_file) or "" end
o.write = function(self, section, value)
fs.writefile(w_ip_file, value:gsub("\r\n", "\n"):gsub("http://", ""):gsub(
"https://", ""))
end
o.remove = function(self, section, value) fs.writefile(w_ip_file, "") end
---- Blacklist Hosts
s:tab("b_hosts", translate("Blacklist Hosts"),
"<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>")
local b_host_file = "/usr/share/passwall/rules/blacklist_host"
o = s:taboption("b_hosts", TextValue, "blacklist_host")
o.rows = 8
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(b_host_file) or "" end
o.write = function(self, section, value)
fs.writefile(b_host_file, value:gsub("\r\n", "\n"):gsub("http://", ""):gsub(
"https://", ""))
end
o.remove = function(self, section, value) fs.writefile(b_host_file, "") end
---- Blacklist IP
s:tab("b_ip", translate("Blacklist IP"), "<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>")
local b_ip_file = "/usr/share/passwall/rules/blacklist_ip"
o = s:taboption("b_ip", TextValue, "blacklist_ip")
o.rows = 8
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(b_ip_file) or "" end
o.write = function(self, section, value)
fs.writefile(b_ip_file, value:gsub("\r\n", "\n"):gsub("http://", ""):gsub(
"https://", ""))
end
o.remove = function(self, section, value) fs.writefile(b_ip_file, "") end
-- [[ ACLs Settings ]]--
s = m:section(TypedSection, "acl_rule", translate("ACLs"), "<font color='red'>" .. translate(
"ACLs is a tools which used to designate specific IP proxy mode, IP or MAC address can be entered.") .. "</font>")

View File

@ -5,8 +5,9 @@ local appname = "passwall"
local n = {}
uci:foreach(appname, "nodes", function(e)
if e.type and e.remarks and e.address and e.port then
n[e[".name"]] = "%s[%s] %s:%s" %
{e.type, e.remarks, e.address, e.port}
if (e.type == "V2ray_balancing" or e.type == "V2ray_shunt") or (e.address:match("[\u4e00-\u9fa5]") and e.address:find("%.") and e.address:sub(#e.address) ~= ".") then
n[e[".name"]] = "%s[%s] %s:%s" % {e.type, e.remarks, e.address, e.port}
end
end
end)

View File

@ -6,9 +6,11 @@ local appname = "passwall"
local n = {}
uci:foreach(appname, "nodes", function(e)
if e.remarks and e.address and e.port and e.address ~= "127.0.0.1" then
e.remark = "[%s] %s:%s" % {e.remarks, e.address, e.port}
n[e[".name"]] = e
if e.type and e.remarks and e.port and e.address and e.address ~= "127.0.0.1" then
if e.address:match("[\u4e00-\u9fa5]") and e.address:find("%.") and e.address:sub(#e.address) ~= "." then
e.remark = "%s[%s] %s:%s" % {translate(e.type), e.remarks, e.address, e.port}
n[e[".name"]] = e
end
end
end)

View File

@ -17,15 +17,20 @@ end
local n = {}
uci:foreach(appname, "nodes", function(e)
local type = e.type
if type == nil then type = "" end
local address = e.address
if address == nil then address = "" end
if type and address and e.remarks then
if e.use_kcp and e.use_kcp == "1" then
n[e[".name"]] = "%s+%s[%s] %s" %
{translate(type), "Kcptun", e.remarks, address}
else
n[e[".name"]] = "%s[%s] %s" %
{translate(type), e.remarks, address}
if (type == "V2ray_balancing" or type == "V2ray_shunt") or (address:match("[\u4e00-\u9fa5]") and address:find("%.") and address:sub(#address) ~= ".") then
if type and address and e.remarks then
if e.use_kcp and e.use_kcp == "1" then
n[e[".name"]] = "%s+%s[%s] %s" %
{
translate(type), "Kcptun", e.remarks, address
}
else
n[e[".name"]] = "%s[%s] %s" %
{translate(type), e.remarks, address}
end
end
end
end)

View File

@ -97,7 +97,9 @@ brook_tls:depends("brook_protocol", "wsclient")
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}
if e.address:match("[\u4e00-\u9fa5]") and e.address:find("%.") and e.address:sub(#e.address) ~= "." then
n[e[".name"]] = "[%s] %s:%s" % {e.remarks, e.address, e.port}
end
end
end)

View File

@ -1,69 +0,0 @@
local fs = require "nixio.fs"
m = Map("passwall")
-- [[ Rule List Settings ]]--
s = m:section(TypedSection, "global_rules")
s.anonymous = true
---- Whitelist Hosts
s:tab("w_hosts", translate("Whitelist Hosts"), "<font color='red'>" ..
translate("Join the white list of domain names will not go agent.") ..
"</font>")
local w_host_file = "/usr/share/passwall/rules/whitelist_host"
o = s:taboption("w_hosts", TextValue, "whitelist_host")
o.rows = 20
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(w_host_file) or "" end
o.write = function(self, section, value)
fs.writefile(w_host_file, value:gsub("\r\n", "\n"):gsub("http://", ""):gsub(
"https://", ""))
end
o.remove = function(self, section, value) fs.writefile(w_host_file, "") end
---- Whitelist IP
s:tab("w_ip", translate("Whitelist IP"), "<font color='red'>" .. translate(
"These had been joined ip addresses will not use proxy.Please input the ip address or ip address segment,every line can input only one ip address.For example,192.168.0.0/24 or 223.5.5.5.") ..
"</font>")
local w_ip_file = "/usr/share/passwall/rules/whitelist_ip"
o = s:taboption("w_ip", TextValue, "whitelist_ip")
o.rows = 20
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(w_ip_file) or "" end
o.write = function(self, section, value)
fs.writefile(w_ip_file, value:gsub("\r\n", "\n"):gsub("http://", ""):gsub(
"https://", ""))
end
o.remove = function(self, section, value) fs.writefile(w_ip_file, "") end
---- Blacklist Hosts
s:tab("b_hosts", translate("Blacklist Hosts"),
"<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>")
local b_host_file = "/usr/share/passwall/rules/blacklist_host"
o = s:taboption("b_hosts", TextValue, "blacklist_host")
o.rows = 20
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(b_host_file) or "" end
o.write = function(self, section, value)
fs.writefile(b_host_file, value:gsub("\r\n", "\n"):gsub("http://", ""):gsub(
"https://", ""))
end
o.remove = function(self, section, value) fs.writefile(b_host_file, "") end
---- Blacklist IP
s:tab("b_ip", translate("Blacklist IP"), "<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>")
local b_ip_file = "/usr/share/passwall/rules/blacklist_ip"
o = s:taboption("b_ip", TextValue, "blacklist_ip")
o.rows = 20
o.wrap = "off"
o.cfgvalue = function(self, section) return fs.readfile(b_ip_file) or "" end
o.write = function(self, section, value)
fs.writefile(b_ip_file, value:gsub("\r\n", "\n"):gsub("http://", ""):gsub(
"https://", ""))
end
o.remove = function(self, section, value) fs.writefile(b_ip_file, "") end
return m

View File

@ -517,9 +517,6 @@ start_crontab() {
autoupdate=$(config_t_get global_rules auto_update)
weekupdate=$(config_t_get global_rules week_update)
dayupdate=$(config_t_get global_rules time_update)
autoupdatesubscribe=$(config_t_get global_subscribe auto_update_subscribe)
weekupdatesubscribe=$(config_t_get global_subscribe week_update_subscribe)
dayupdatesubscribe=$(config_t_get global_subscribe time_update_subscribe)
#if [ "$autoupdate" = "1" ]; then
# local t="0 $dayupdate * * $weekupdate"
# [ "$weekupdate" = "7" ] && t="0 $dayupdate * * *"
@ -527,8 +524,11 @@ start_crontab() {
# echolog "配置定时任务:自动更新规则。"
#fi
autoupdatesubscribe=$(config_t_get global_subscribe auto_update_subscribe)
weekupdatesubscribe=$(config_t_get global_subscribe week_update_subscribe)
dayupdatesubscribe=$(config_t_get global_subscribe time_update_subscribe)
if [ "$autoupdatesubscribe" = "1" ]; then
local t="0 $dayupdatesubscribe * * $weekupdate"
local t="0 $dayupdatesubscribe * * $weekupdatesubscribe"
[ "$weekupdatesubscribe" = "7" ] && t="0 $dayupdatesubscribe * * *"
echo "$t lua $APP_PATH/subscribe.lua start log > /dev/null 2>&1 &" >>/etc/crontabs/root
echolog "配置定时任务:自动更新节点订阅。"

View File

@ -155,7 +155,7 @@ load_acl() {
fi
}
[ "$UDP_NODE" != "nil" ] && {
[ "$UDP_NO_REDIR_PORTS" != "disable" ] && $ipt_m -A PSW_ACL $(factor $ip "-s") $(factor $mac "-m mac --mac-source") -p udp -m multiport --dport $udp_no_redir_ports -j RETURN
[ "$udp_no_redir_ports" != "disable" ] && $ipt_m -A PSW_ACL $(factor $ip "-s") $(factor $mac "-m mac --mac-source") -p udp -m multiport --dport $udp_no_redir_ports -j RETURN
eval udp_redir_port=\$UDP_REDIR_PORT$udp_node
$ipt_m -A PSW_ACL $(factor $ip "-s") $(factor $mac "-m mac --mac-source") -p udp $(factor $udp_redir_ports "-m multiport --dport") $(comment "$remarks") -$(get_jump_mode $proxy_mode) $(get_action_chain $proxy_mode)$udp_node
$ipt_m -A PSW_ACL $(factor $ip "-s") $(factor $mac "-m mac --mac-source") -p udp $(comment "$remarks") -j RETURN

View File

@ -9,22 +9,32 @@ echolog() {
echo -e "$d: $1" >> $LOG_FILE
}
config_t_get() {
local index=0
[ -n "$4" ] && index=$4
local ret=$(uci -q get $CONFIG.@$1[$index].$2 2>/dev/null)
echo ${ret:=$3}
}
test_url() {
status=$(/usr/bin/curl -I -o /dev/null -s --connect-timeout 2 --retry 1 -w %{http_code} "$1" | grep 200)
[ "$?" != 0 ] && {
status=$(/usr/bin/wget --no-check-certificate --spider --timeout=2 --tries 1 "$1")
[ "$?" == 0 ] && status=200
}
local url=$1
local try=1
[ -n "$2" ] && try=$2
local timeout=2
[ -n "$3" ] && timeout=$3
status=$(/usr/bin/wget --no-check-certificate --spider --timeout=$timeout --tries $try "$url")
[ "$?" == 0 ] && status=200
echo $status
}
test_proxy() {
local try=5
result=0
status=$(test_url "https://www.google.com")
status=$(test_url "https://www.google.com" $try)
if [ "$status" = "200" ]; then
result=0
else
status2=$(test_url "https://www.baidu.com")
status2=$(test_url "https://www.baidu.com" $try)
if [ "$status2" = "200" ]; then
result=1
else
@ -35,85 +45,48 @@ test_proxy() {
}
test_auto_switch() {
if [ -f "/var/etc/$CONFIG/tcp_server_id" ]; then
TCP_NODES1=$(cat /var/etc/$CONFIG/tcp_server_id)
local type=$1
local index=$2
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})
else
rm -f $LOCK_FILE
exit 1
return 1
fi
failcount=1
while [ "$failcount" -le 5 ]; do
status=$(test_proxy)
if [ "$status" == 2 ]; then
echolog "自动切换检测:无法连接到网络,请检查网络是否正常!"
break
elif [ "$status" == 1 ]; then
echolog "自动切换检测:第$failcount次检测异常"
let "failcount++"
[ "$failcount" -ge 5 ] && {
echolog "自动切换检测:检测异常,切换节点"
TCP_NODES=$(uci -q get $CONFIG.@auto_switch[0].tcp_node)
has_backup_server=$(echo $TCP_NODES | grep $TCP_NODES1)
setserver=
if [ -z "$has_backup_server" ]; then
setserver=$(echo $TCP_NODES | awk -F ' ' '{print $1}')
else
setserver=$TCP_NODES1
flag=0
for server in $has_backup_server; do
if [ "$flag" == 0 ]; then
if [ "$TCP_NODES1" == "$server" ]; then
flag=1
continue
fi
fi
if [ "$flag" == 1 ]; then
flag=2
continue
fi
if [ "$flag" == 2 ]; then
setserver=$server
break
fi
done
fi
rm -f $LOCK_FILE
uci set $CONFIG.@global[0].tcp_node=$setserver
uci commit $CONFIG
/etc/init.d/$CONFIG restart
exit 1
}
sleep 5s
elif [ "$status" == 0 ]; then
echolog "自动切换检测:检测正常"
break
status=$(test_proxy)
if [ "$status" == 2 ]; then
echolog "自动切换检测:无法连接到网络,请检查网络是否正常!"
return 1
elif [ "$status" == 1 ]; then
echolog "自动切换检测:${type}_${index}节点异常,开始切换节点!"
new_node=
in_backup_nodes=$(echo $b_tcp_nodes | grep $now_node)
# 判断当前节点是否存在于备用节点列表里
if [ -z "$in_backup_nodes" ]; then
# 如果不存在,设置第一次节点为新的节点
new_node=$(echo $b_tcp_nodes | awk -F ' ' '{print $1}')
else
# 如果存在,设置下一个备用节点为新的节点
local count=$(expr $(echo $b_tcp_nodes | grep -o ' ' | wc -l) + 1)
local next_node=$(echo $b_tcp_nodes | awk -F "$now_node" '{print $2}' | awk -F " " '{print $1}')
if [ -z "$next_node" ]; then
new_node=$(echo $b_tcp_nodes | awk -F ' ' '{print $1}')
else
new_node=$next_node
fi
fi
done
}
test_reconnection() {
failcount=1
while [ "$failcount" -le 5 ]; do
status=$(test_proxy)
if [ "$status" == 2 ]; then
echolog "掉线重连检测:无法连接到网络,请检查网络是否正常!"
break
elif [ "$status" == 1 ]; then
echolog "掉线重连检测:第$failcount次检测异常"
let "failcount++"
[ "$failcount" -ge 5 ] && {
echolog "掉线重连检测:检测异常,重启程序"
rm -f $LOCK_FILE
/etc/init.d/$CONFIG restart
exit 1
}
sleep 5s
elif [ "$status" == 0 ]; then
echolog "掉线重连检测:检测正常"
break
fi
done
rm -f $LOCK_FILE
uci set $CONFIG.@global[0].tcp_node${index}=$new_node
uci commit $CONFIG
/etc/init.d/$CONFIG restart > /dev/null &
echolog "自动切换检测:${type}_${index}节点切换完毕!"
return 0
elif [ "$status" == 0 ]; then
echolog "自动切换检测:${type}_${index}节点正常。"
return 0
fi
}
start() {
@ -123,13 +96,19 @@ start() {
else
touch $LOCK_FILE
fi
is_auto_switch=$(uci show $CONFIG.@auto_switch[0] | grep "tcp_node")
if [ -z "$is_auto_switch" ]; then
test_reconnection
else
test_auto_switch
fi
ENABLED=$(config_t_get global enabled 0)
[ "$ENABLED" != 1 ] && return 1
ENABLED=$(config_t_get auto_switch enable 0)
[ "$ENABLED" != 1 ] && return 1
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 auto_switch tcp_node$i nil)\"
eval tmp=\$TCP_NODE$i
[ -n "$tmp" ] && {
test_auto_switch TCP $i $tmp
}
done
rm -f $LOCK_FILE
exit