1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Add check on VPS and IP timeout config in web interface and add loop detection

This commit is contained in:
Ycarus (Yannick Chabanois) 2021-05-19 19:37:17 +02:00
parent 6702b125ca
commit 4c56f5402f
10 changed files with 111 additions and 12 deletions

View file

@ -3,11 +3,14 @@
intf=$1
timeout=$(uci -q get openmptcprouter.settings.status_getip_timeout)
[ -z "$timeout" ] && timeout="1"
get_ip_from_server() {
serverport=$(uci -q get openmptcprouter.$1.port)
get_ip() {
serverip=$1
getip="$(curl -s -k -4 -m 2 --interface $intf https://$serverip:$serverport/clienthost)"
getip="$(curl -s -k -4 -m ${timeout} --interface $intf https://$serverip:$serverport/clienthost)"
[ -n "$getip" ] && getip=$(echo $getip | jsonfilter -e '@.client_host')
if expr "$getip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
ip=$getip
@ -23,7 +26,7 @@ get_ip_from_website() {
[ -z "$check_ipv4_website" ] && check_ipv4_website="http://ip.openmptcprouter.com"
checkip=$(echo $check_ipv4_website | sed -e 's/https:\/\///' -e 's/http:\/\///' | xargs dig +short A | tr -d "\n")
ipset add ss_rules_dst_bypass_all $checkip > /dev/null 2>&1
getip="$(curl -s -4 -m 2 --interface $intf $check_ipv4_website)"
getip="$(curl -s -4 -m ${timeout} --interface $intf $check_ipv4_website)"
ipset del ss_rules_dst_bypass_all $checkip > /dev/null 2>&1
if expr "$getip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
ip=$getip

View file

@ -3,10 +3,13 @@
intf=$1
timeout=$(uci -q get openmptcprouter.settings.status_getip_timeout)
[ -z "$timeout" ] && timeout="1"
get_ip_from_server() {
serverport=$(uci -q get openmptcprouter.$1.port)
get_ip() {
getip="$(curl -s -k -6 -m 2 --interface $intf https://$serverip:$serverport/clienthost)"
getip="$(curl -s -k -6 -m ${timeout} --interface $intf https://$serverip:$serverport/clienthost)"
[ -n "$getip" ] && getip=$(echo $getip | jsonfilter -e '@.client_host')
if [ -n "$(echo "$getip" | grep :)" ]; then
ip=$getip
@ -22,7 +25,7 @@ get_ip_from_website() {
[ -z "$check_ipv6_website" ] && check_ipv6_website="http://ipv6.openmptcprouter.com"
checkip=$(echo $check_ipv6_website | sed -e 's/https:\/\///' -e 's/http:\/\///' | xargs dig +short AAAA | tr -d "\n")
ipset add ss_rules6_dst_bypass_all $checkip > /dev/null 2>&1
getip="$(curl -s -6 -m 2 --interface $intf $check_ipv6_website)"
getip="$(curl -s -6 -m ${timeout} --interface $intf $check_ipv6_website)"
ipset del ss_rules6_dst_bypass_all $checkip > /dev/null 2>&1
if [ -n "$(echo "$getip" | grep :)" ]; then
ip=$getip

View file

@ -2,6 +2,8 @@
. /lib/functions.sh
intf=$1
timeout="$(uci -q get openmptcprouter.settings.status_vps_timeout)"
[ -z "$timeout" ] && timeout="1"
[ -z "$intf" ] && return
@ -10,9 +12,9 @@ get_mptcp_from_server() {
get_mptcp() {
serverip=$1
if [ "$(echo $serverip | grep :)" ]; then
support="$(curl -s -k -6 -m 2 --interface $intf https://[$serverip]:$serverport/mptcpsupport)"
support="$(curl -s -k -6 -m ${timeout} --interface $intf https://[$serverip]:$serverport/mptcpsupport)"
else
support="$(curl -s -k -4 -m 2 --interface $intf https://$serverip:$serverport/mptcpsupport)"
support="$(curl -s -k -4 -m ${timeout} --interface $intf https://$serverip:$serverport/mptcpsupport)"
fi
[ -n "$support" ] && {
support=$(echo $support | jsonfilter -e '@.mptcp')
@ -26,7 +28,7 @@ get_mptcp_from_server() {
get_mptcp_from_website() {
multipathip=$(dig +short A multipath-tcp.org | tr -d "\n")
ipset add ss_rules_dst_bypass_all $multipathip > /dev/null 2>&1
support="$(curl -s -4 -m 2 --interface $intf http://www.multipath-tcp.org)"
support="$(curl -s -4 -m ${timeout} --interface $intf http://www.multipath-tcp.org)"
ipset del ss_rules_dst_bypass_all $multipathip > /dev/null 2>&1
[ -n "$support" ] && {
if [ "$support" = "Yay, you are MPTCP-capable! You can now rest in peace." ]; then
@ -40,7 +42,7 @@ get_mptcp_from_website() {
get_mptcp_from_website6() {
multipathip=$(dig +short AAAA multipath-tcp.org | tr -d "\n")
ipset add ss_rules6_dst_bypass_all $multipathip > /dev/null 2>&1
support="$(curl -s -6 -m 2 --interface $intf http://www.multipath-tcp.org)"
support="$(curl -s -6 -m ${timeout} --interface $intf http://www.multipath-tcp.org)"
ipset del ss_rules6_dst_bypass_all $multipathip > /dev/null 2>&1
[ -n "$support" ] && {
if [ "$support" = "Yay, you are MPTCP-capable! You can now rest in peace." ]; then

View file

@ -0,0 +1,9 @@
#!/bin/sh
VPS=$1
LANIP=$2
if [ -n "$(traceroute -q 1 -i eth1 -w 1 -n -m 5 ${VPS} | grep ${LANIP})" ]; then
echo "detected"
else
echo "no loop"
fi

View file

@ -88,13 +88,13 @@ if [ "$(uci -q get openmptcprouter.settings.check_ipv6_website)" = "" ]; then
fi
if [ "$(uci -q get openmptcprouter.settings.status_vps_timeout)" = "" ]; then
uci -q batch <<-EOF >/dev/null
set openmptcprouter.settings.status_vps_timeout=2
set openmptcprouter.settings.status_vps_timeout=1
commit openmptcprouter
EOF
fi
if [ "$(uci -q get openmptcprouter.settings.status_getip_timeout)" = "" ]; then
uci -q batch <<-EOF >/dev/null
set openmptcprouter.settings.status_getip_timeout=2
set openmptcprouter.settings.status_getip_timeout=1
commit openmptcprouter
EOF
fi

View file

@ -763,7 +763,7 @@ function interfaces_status()
mArray.openmptcprouter["omr_time"] = os.time()
-- dns
mArray.openmptcprouter["dns"] = false
local timeout = uci:get("openmptcprouter","settings","status_getip_timeout") or "2"
local timeout = uci:get("openmptcprouter","settings","status_getip_timeout") or "1"
local dns_test = sys.exec("dig +timeout=" .. timeout .. " +tries=1 openmptcprouter.com | grep 'ANSWER: 0'")
if dns_test == "" then
mArray.openmptcprouter["dns"] = true
@ -848,7 +848,7 @@ function interfaces_status()
mArray.openmptcprouter["vps_omr_version"] = uci:get("openmptcprouter", s[".name"], "omr_version") or ""
mArray.openmptcprouter["vps_kernel"] = uci:get("openmptcprouter",s[".name"],"kernel") or ""
mArray.openmptcprouter["vps_machine"] = uci:get("openmptcprouter",s[".name"],"machine") or ""
timeout = uci:get("openmptcprouter","settings","status_vps_timeout") or "2"
timeout = uci:get("openmptcprouter","settings","status_vps_timeout") or "1"
if uci:get("openmptcprouter",s[".name"],"admin_error") == "1" then
mArray.openmptcprouter["vps_admin_error"] = true
end
@ -1484,6 +1484,10 @@ function interfaces_status()
end
end
end
loop = false
if uci:get("openmptcprouter", interface, "loop") == "1" then
loop = true
end
end
local rx = ""
local tx = ""
@ -1536,6 +1540,7 @@ function interfaces_status()
zonewan = zonewan,
iftype = itype,
state = state,
loop = loop,
}
if ifname ~= nil and ifname:match("^tun.*") then
table.insert(mArray.tunnels, data);