1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-12 18:41:51 +00:00

Changes for WAN IPv6 support in status page

This commit is contained in:
Ycarus (Yannick Chabanois) 2021-01-16 08:11:03 +01:00
parent 57debb6681
commit 0be1a3b119
5 changed files with 309 additions and 41 deletions

View file

@ -231,14 +231,25 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
if ((mArray.openmptcprouter.wan_addr == mArray.openmptcprouter.service_addr || mArray.openmptcprouter.wan_addr == mArray.openmptcprouter.service_addr_ip) && mArray.openmptcprouter.wan_addr != "")
{
var title = String.format("%s (%s)", mArray.openmptcprouter.vps_hostname, mArray.openmptcprouter.wan_addr);
} else if ((mArray.openmptcprouter.wan_addr6 == mArray.openmptcprouter.service_addr || mArray.openmptcprouter.wan_addr6 == mArray.openmptcprouter.service_addr_ip) && mArray.openmptcprouter.wan_addr6 != "")
{
var title = String.format("%s (%s)", mArray.openmptcprouter.vps_hostname, mArray.openmptcprouter.wan_6addr);
} else if (mArray.openmptcprouter.wan_addr != "" && mArray.openmptcprouter.service_addr == "127.0.0.1")
{
var title = String.format("%s (%s)", mArray.openmptcprouter.vps_hostname, mArray.openmptcprouter.wan_addr);
} else if (mArray.openmptcprouter.wan_addr6 != "" && mArray.openmptcprouter.service_addr == "127.0.0.1")
{
var title = String.format("%s (%s)", mArray.openmptcprouter.vps_hostname, mArray.openmptcprouter.wan_addr6);
} else if (mArray.openmptcprouter.wan_addr != "")
{
var title = String.format("%s (%s)", _('Direct output'), mArray.openmptcprouter.wan_addr);
statusMessageClass = "warning";
statusIcon = "<%=resource%>/openmptcprouter/images/statusWarning.png";
} else if (mArray.openmptcprouter.wan_addr6 != "")
{
var title = String.format("%s (%s)", _('Direct output'), mArray.openmptcprouter.wan_addr6);
statusMessageClass = "warning";
statusIcon = "<%=resource%>/openmptcprouter/images/statusWarning.png";
} else if (mArray.openmptcprouter.ss_addr != "" && mArray.openmptcprouter.vps_status != "DOWN")
{
var title = String.format("%s (%s)", mArray.openmptcprouter.vps_hostname, mArray.openmptcprouter.ss_addr);
@ -248,11 +259,11 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
var title = '<%:No output%>';
statusMessage += '<%:No output%>' + '<br/>';
}
if (mArray.openmptcprouter.wan_addr == "" && mArray.openmptcprouter.ss_addr == "" && mArray.openmptcprouter.external_check == true)
if (mArray.openmptcprouter.wan_addr == "" && mArray.openmptcprouter.wan_addr6 == "" && mArray.openmptcprouter.ss_addr == "" && mArray.openmptcprouter.external_check == true)
{
statusMessage += '<%:No server IP address, No WAN IP address%>' + '<br/>';
}
if (mArray.openmptcprouter.service_addr !== "" && mArray.openmptcprouter.wan_addr !== "" && mArray.openmptcprouter.vps_status == "DOWN")
if (mArray.openmptcprouter.service_addr !== "" && (mArray.openmptcprouter.wan_addr !== "" || mArray.openmptcprouter.wan_addr6 !== "") && mArray.openmptcprouter.vps_status == "DOWN")
{
statusMessage += '<%:Can\'t access and use server part%>' + '<br/>';
}
@ -274,7 +285,10 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
} else if (mArray.openmptcprouter.v2ray_enabled == true && mArray.openmptcprouter.ss_addr == "" && mArray.openmptcprouter.external_check == true)
{
statusMessage += '<%:Can\'t get public IP address from V2Ray%>' + '<br/>';
} else if (mArray.openmptcprouter.wan_addr == "" && mArray.openmptcprouter.external_check == true)
} else if (mArray.openmptcprouter.wan_addr == "" && mArray.openmptcprouter.wan_addr6 !== "" && mArray.openmptcprouter.external_check == true)
{
statusMessage += '<%:No WAN IP address detected in less than 1 second%>' + '<br/>';
} else if (mArray.openmptcprouter.wan_addr6 == "" && mArray.openmptcprouter.wan_addr !== "" && mArray.openmptcprouter.external_check == true)
{
statusMessage += '<%:No WAN IP address detected in less than 1 second%>' + '<br/>';
}
@ -392,18 +406,21 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
statusMessage = "";
}
// Populate info
var wanip = mArray.wans[i].wanip;
var wanip = mArray.wans[i].wanip;
var wanip6 = mArray.wans[i].wanip6;
if (anonymize == "true" && testPrivateIP(wanip) == false)
{
wanip=replaceLastNChars(wanip,"x",6);
}
var ipaddr = mArray.wans[i].ipaddr;
var ipaddr = mArray.wans[i].ipaddr;
var ip6addr = mArray.wans[i].ip6addr;
if (anonymize == "true" && testPrivateIP(ipaddr) == false)
{
ipaddr=replaceLastNChars(ipaddr,"x",6);
}
var whois = mArray.wans[i].whois;
var signal = mArray.wans[i].signal;
var whois = mArray.wans[i].whois;
var whois6 = mArray.wans[i].whois6;
var signal = mArray.wans[i].signal;
var multipath = mArray.wans[i].multipath;
if(multipath == 'master')
{
@ -420,7 +437,13 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
{
gateway=replaceLastNChars(gateway,"x",6);
}
var gateway6 = mArray.wans[i].gateway6;
if (anonymize == "true" && testPrivateIP(gateway6) == false)
{
gateway6=replaceLastNChars(gateway6,"x",10);
}
var gw_ping = mArray.wans[i].gw_ping;
var gw_ping6 = mArray.wans[i].gw_ping6;
var server_ping = mArray.wans[i].server_ping;
var ipv6_discover = mArray.wans[i].ipv6_discover;
var multipath_available = mArray.wans[i].multipath_available;
@ -438,6 +461,9 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
if (mArray.wans[i].gateway !== "")
{
var title = mArray.wans[i].label + " (" + gateway + ")";
} else if (mArray.wans[i].gateway6 !== "")
{
var title = mArray.wans[i].label + " (" + gateway6 + ")";
} else {
var title = mArray.wans[i].label;
}
@ -446,14 +472,26 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
{
content += String.format('%s <strong>%s</strong><br />','<%:ip address:%>', ipaddr);
}
if(ip6addr !== '')
{
content += String.format('%s <strong>%s</strong><br />','<%:ipv6 address:%>', ip6addr);
}
if(wanip !== '')
{
content += String.format('%s <strong>%s</strong><br />','<%:wan address:%>', wanip);
}
if(wanip6 !== '')
{
content += String.format('%s <strong>%s</strong><br />','<%:wan ipv6 address:%>', wanip6);
}
if(whois !== '')
{
content += String.format('%s %s<br />','<%:whois:%>', whois);
}
if(whois6 !== '')
{
content += String.format('%s %s<br />','<%:whois:%>', whois6);
}
if(latency !== '')
{
content += String.format('%s %s ms<br />','<%:latency:%>', latency);
@ -492,14 +530,17 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
{
title += String.format(' <i>%s</i>',networktype);
}
if(ipaddr == '')
if(ipaddr == '' && ip6addr == '')
{
statusMessage += '<%:No IP defined%>' + '<br />';
}
if(gateway == '')
if(gateway == '' && gateway6 == '')
{
statusMessage += '<%:No gateway defined%>' + '<br />';
} else if(gw_ping == 'DOWN')
{
statusMessage += '<%:Gateway DOWN%>' + '<br />';
} else if(gw_ping6 == 'DOWN')
{
statusMessage += '<%:Gateway DOWN%>' + '<br />';
} else if(multipath_available == 'ERROR')
@ -515,6 +556,11 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
statusMessage += '<%:Wan IP and gateway are identical%>' + '<br />';
statusMessageClass = "error";
}
if (stat == 'Offline' && ip6addr != '' && ipaddr == mArray.wans[i].gateway6)
{
statusMessage += '<%:Wan IP and gateway are identical%>' + '<br />';
statusMessageClass = "error";
}
if(multipath == 'master')
{
if (master > 1)
@ -557,6 +603,12 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
temp += '</a></li>';
}
if (mArray.wans.length == 0)
{
temp += '<li>';
temp += '<%:No WAN with multipath enabled:%>';
temp += '</li>';
}
for( var i = 0; i < mArray.tunnels.length; i++ )
{
// Get link color

View file

@ -28,8 +28,10 @@ get_ip_from_website() {
}
[ -z "$intf" ] && return
ip=""
config_load openmptcprouter
config_foreach get_ip_from_server server
[ -z "$ip" ] && get_ip_from_website
echo $ip
if [ -n "$(ip -4 a show dev $intf)" ]; then
ip=""
config_load openmptcprouter
config_foreach get_ip_from_server server
[ -z "$ip" ] && get_ip_from_website
echo $ip
fi

View file

@ -0,0 +1,37 @@
#!/bin/sh
. /lib/functions.sh
intf=$1
get_ip_from_server() {
serverip=$(uci -q get openmptcprouter.$1.ip)
serverport=$(uci -q get openmptcprouter.$1.port)
getip="$(curl -s -k -6 -m 2 --interface $intf https://$serverip:$serverport/clienthost)"
[ -n "$getip" ] && getip=$(echo $getip | jsonfilter -e '@.client_host')
if [ -n "$(echo "$getip" | grep :)" ]; then
ip=$getip
break
fi
}
get_ip_from_website() {
check_ipv6_website="$(uci -q get openmptcprouter.settings.check_ipv6_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)"
ipset del ss_rules6_dst_bypass_all $checkip > /dev/null 2>&1
if [ -n "$(echo "$getip" | grep :)" ]; then
ip=$getip
break
fi
}
[ -z "$intf" ] && return
if [ -n "$(ip -6 a show dev $intf)" ]; then
ip=""
config_load openmptcprouter
config_foreach get_ip_from_server server
[ -z "$ip" ] && get_ip_from_website
echo $ip
fi

View file

@ -1,7 +1,16 @@
#!/bin/sh
INTERFACE=$2
if [ -z "$INTERFACE" ]; then
tracebox -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" $1
SERVER=$1
if [ -n "$(resolveip -4 $SERVER)" ]; then
if [ -z "$INTERFACE" ]; then
tracebox -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" $SERVER
else
tracebox -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" -i $INTERFACE $SERVER
fi
else
tracebox -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" -i $INTERFACE $1
if [ -z "$INTERFACE" ]; then
tracebox -6 -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" $SERVER
else
tracebox -6 -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" -i $INTERFACE $SERVER
fi
fi

View file

@ -545,7 +545,14 @@ function update_vps()
local vpsgettoken = sys.exec("/etc/init.d/openmptcprouter-vps restart >/dev/null 2>/dev/null")
end
function get_rootfs()
local rootfs = {}
rootfs['format'] = ut.trim(sys.exec("mount | awk 'NR==1{print $5}'"))
return rootfs
end
function get_ip(interface)
local ut = require "luci.util"
local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
local ip = ""
if dump and dump['ipv4-address'] then
@ -563,6 +570,42 @@ function get_ip(interface)
end
end
end
if ip == "" then
local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
if dump and dump['l3_device'] then
local ifname = dump['l3_device']
ip = ut.trim(sys.exec("ip -4 -br addr ls dev %s | awk -F'[ /]+' '{print $3}'" % ifname))
end
end
return ip
end
function get_ip6(interface)
local ut = require "luci.util"
local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
local ip = ""
if dump and dump['ipv6-address'] then
local _, ipv6address
for _, ipv6address in ipairs(dump['ipv6-address']) do
ip = dump['ipv6-address'][_].address
end
end
if ip == "" then
local dump = require("luci.util").ubus("network.interface.%s_6" % interface, "status", {})
if dump and dump['ipv6-address'] then
local _, ipv6address
for _, ipv6address in ipairs(dump['ipv6-address']) do
ip = dump['ipv6-address'][_].address
end
end
end
if ip == "" then
local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
if dump and dump['l3_device'] then
local ifname = dump['l3_device']
ip = ut.trim(sys.exec("ip -6 -br addr ls dev %s | awk -F'[ /]+' '{print $3}'" % ifname))
end
end
return ip
end
@ -625,6 +668,56 @@ function get_gateway(interface)
return gateway
end
function get_gateway6(interface)
local gateway = ""
local dump = nil
dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
if dump and dump.route then
local _, route
for _, route in ipairs(dump.route) do
if dump.route[_].target == "::" then
gateway = dump.route[_].nexthop
end
end
end
if gateway == "" then
if dump and dump.inactive and dump.inactive.route then
local _, route
for _, route in ipairs(dump.inactive.route) do
if dump.inactive.route[_].target == "::" then
gateway = dump.inactive.route[_].nexthop
end
end
end
end
if gateway == "" then
dump = require("luci.util").ubus("network.interface.%s_6" % interface, "status", {})
if dump and dump.route then
local _, route
for _, route in ipairs(dump.route) do
if dump.route[_].target == "::" then
gateway = dump.route[_].nexthop
end
end
end
if gateway == "" then
if dump and dump.inactive and dump.inactive.route then
local _, route
for _, route in ipairs(dump.inactive.route) do
if dump.inactive.route[_].target == "::" then
gateway = dump.inactive.route[_].nexthop
end
end
end
end
end
return gateway
end
-- This function come from OverTheBox by OVH with many changes
-- Copyright 2015 OVH <OverTheBox@ovh.net>
-- Simon Lelievre (simon.lelievre@corp.ovh.com)
@ -689,16 +782,25 @@ function interfaces_status()
if mArray.openmptcprouter["dns"] == true then
-- wanaddr
--mArray.openmptcprouter["wan_addr"] = uci:get("openmptcprouter","omr","public_detected_ipv4") or ""
if mArray.openmptcprouter["service_addr"] ~= "" then
mArray.openmptcprouter["service_addr_ip"] = ut.trim(sys.exec("resolveip -4 -t 1 " .. mArray.openmptcprouter["service_addr"] .. " | head -n 1"))
mArray.openmptcprouter["service_addr_ip6"] = ut.trim(sys.exec("resolveip -6 -t 1 " .. mArray.openmptcprouter["service_addr"] .. " | head -n 1"))
end
if uci:get("openmptcprouter","settings","external_check") ~= "0" and mArray.openmptcprouter["dns"] == true then
mArray.openmptcprouter["wan_addr"] = ut.trim(sys.exec("curl -4 -s -m " .. timeout .. " " .. check_ipv4_website))
if mArray.openmptcprouter["wan_addr"] == "" then
mArray.openmptcprouter["wan_addr"] = ut.trim(sys.exec("dig TXT +timeout=" .. timeout .. " +tries=1 +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'\"' '{print $2}'"))
if mArray.openmptcprouter["service_addr_ip"] ~= "" then
mArray.openmptcprouter["wan_addr"] = ut.trim(sys.exec("curl -4 -s -m " .. timeout .. " " .. check_ipv4_website))
if mArray.openmptcprouter["wan_addr"] == "" then
mArray.openmptcprouter["wan_addr"] = ut.trim(sys.exec("dig -4 TXT +timeout=" .. timeout .. " +tries=1 +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'\"' '{print $2}'"))
end
end
if mArray.openmptcprouter["ipv6"] == "enabled" then
if mArray.openmptcprouter["ipv6"] == "enabled" or mArray.openmptcprouter["service_addr_ip6"] ~= "" then
mArray.openmptcprouter["wan_addr6"] = uci:get("openmptcprouter","omr","public_detected_ipv6") or ""
if mArray.openmptcprouter["wan_addr6"] == "" then
mArray.openmptcprouter["wan_addr6"] = ut.trim(sys.exec("curl -6 -s -m " .. timeout .. " " .. check_ipv6_website))
if mArray.openmptcprouter["wan_addr"] == "" then
mArray.openmptcprouter["wan_addr"] = ut.trim(sys.exec("dig -6 TXT +timeout=" .. timeout .. " +tries=1 +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'\"' '{print $2}'"))
end
end
end
mArray.openmptcprouter["external_check"] = true
@ -720,9 +822,6 @@ function interfaces_status()
end
end
end
if mArray.openmptcprouter["service_addr"] ~= "" then
mArray.openmptcprouter["service_addr_ip"] = ut.trim(sys.exec("resolveip -4 -t 1 " .. mArray.openmptcprouter["service_addr"] .. " | head -n 1"))
end
end
if mArray.openmptcprouter["service_addr"] ~= "" and mArray.openmptcprouter["service_addr"] ~= "127.0.0.1" then
@ -751,7 +850,13 @@ function interfaces_status()
local adminport = uci:get("openmptcprouter",s[".name"],"port") or "65500"
local token = uci:get("openmptcprouter",s[".name"],"token") or ""
if token ~= "" then
local vpsinfo_json = sys.exec('curl -4 --max-time ' .. timeout .. ' -s -k -H "Authorization: Bearer ' .. token .. '" https://' .. serverip .. ':' .. adminport .. '/status')
local vpsinfo_json = ""
if mArray.openmptcprouter["service_addr_ip"] ~= "" then
vpsinfo_json = sys.exec('curl --max-time ' .. timeout .. ' -s -k -H "Authorization: Bearer ' .. token .. '" https://' .. serverip .. ':' .. adminport .. '/status')
end
if mArray.openmptcprouter["service_addr_ip6"] ~= "" then
vpsinfo_json = sys.exec('curl --max-time ' .. timeout .. ' -s -k -H "Authorization: Bearer ' .. token .. '" https://[' .. serverip .. ']:' .. adminport .. '/status')
end
if vpsinfo_json ~= "" and vpsinfo_json ~= nil then
local status, vpsinfo = pcall(function()
return json.decode(vpsinfo_json)
@ -821,7 +926,11 @@ function interfaces_status()
mArray.openmptcprouter["vps_admin_error_msg"] = "No token yet available"
end
if mArray.openmptcprouter["vps_admin"] == false then
local vpstest = sys.exec('curl -4 --max-time ' .. timeout .. ' -s -k https://' .. serverip .. ':' .. adminport .. '/')
if mArray.openmptcprouter["service_addr_ip"] ~= "" then
local vpstest = sys.exec('curl --max-time ' .. timeout .. ' -s -k https://' .. serverip .. ':' .. adminport .. '/')
elseif mArray.openmptcprouter["service_addr_ip6"] ~= "" then
local vpstest = sys.exec('curl --max-time ' .. timeout .. ' -s -k https://[' .. serverip .. ']:' .. adminport .. '/')
end
if vpstest == "" then
mArray.openmptcprouter["vps_admin_error_msg"] = mArray.openmptcprouter["vps_admin_error_msg"] .. " - No API script answer"
end
@ -859,7 +968,7 @@ function interfaces_status()
else
mArray.openmptcprouter["tun_state"] = "DOWN"
end
if mArray.openmptcprouter["ipv6"] == "enabled" then
if mArray.openmptcprouter["ipv6"] == "enabled" or mArray.openmptcprouter["service_addr_ip6"] ~= "" then
local tunnel_ipv6_gw = uci:get("network","omr6in4","gateway")
local tunnel_ping6_test = ut.trim(sys.exec("ping6 -w 1 -c 1 " .. tunnel_ipv6_gw .. "%6in4-omr6in4 | grep '100% packet loss'"))
if tunnel_ping6_test == "" then
@ -996,7 +1105,9 @@ function interfaces_status()
local interface = section[".name"]
local net = ntm:get_network(interface)
local ipaddr = net:ipaddr() or ""
local ip6addr = net:ip6addr() or ""
local gateway = section["gateway"] or ""
local gateway6 = section["ip6gw"] or ""
local multipath = section["multipath"]
local enabled = section["auto"]
@ -1034,7 +1145,13 @@ function interfaces_status()
if ipaddr == "" and ifname ~= nil and ifname ~= "" then
ipaddr = ut.trim(sys.exec("ip -4 addr show dev " .. ifname .. " | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1 | tr -d '\n'"))
end
if ipaddr == "" then
if ip6addr == "" and ifname ~= nil and ifname ~= "" then
ip6addr = ut.trim(sys.exec("ip -6 -br addr ls dev " .. ifname .. " | awk -F'[ /]+' '{print $3}' | tr -d '\n'"))
end
if ip6addr == "" and ifname ~= nil and ifname ~= "" then
ip6addr = ut.trim(sys.exec("ip -6 addr show dev " .. ifname .. " | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1 | tr -d '\n'"))
end
if ipaddr == "" and ip6addr == "" then
connectivity = "ERROR"
end
@ -1071,8 +1188,10 @@ function interfaces_status()
-- Detect WAN gateway status
local gw_ping = "UP"
if ifname ~= nil and ifname:match("^tun.*") and interface:match("^ovpn.*") then
local gw_ping6 = "UP"
if ifname ~= nil and not (ifname:match("^tun.*") or interface:match("^ovpn.*")) then
gateway = ut.trim(sys.exec("ip -4 r list dev " .. ifname .. " | grep via | grep -v default | grep -v metric | awk '{print $1}' | tr -d '\n'"))
gateway6 = ut.trim(sys.exec("ip -6 r list dev " .. ifname .. " | grep via | grep -v default | grep -v metric | awk '{print $1}' | tr -d '\n'"))
end
if gateway == "" then
@ -1086,18 +1205,40 @@ function interfaces_status()
end
end
end
if gateway6 == "" then
gateway6 = get_gateway6(interface)
end
if gateway6 == "" and ifname ~= nil and ifname ~= "" then
if fs.access("/sys/class/net/" .. ifname) then
gateway6 = ut.trim(sys.exec("ip -6 r list dev " .. ifname .. " | grep kernel | awk '/proto kernel/ {print $1}' | grep -v / | tr -d '\n'"))
if gateway6 == "" then
gateway6 = ut.trim(sys.exec("ip -6 r list dev " .. ifname .. " | grep default | awk '{print $3}' | tr -d '\n'"))
end
end
end
local signal = ""
local operator = ""
local phonenumber = ""
local donglestate = ""
local networktype = ""
if gateway ~= "" then
if gateway ~= "" or gateway6 ~= "" then
if uci:get("openmptcprouter", "settings", "disablegwping") ~= "1" and connectivity ~= "ERROR" then
local gw_ping_test = ut.trim(sys.exec("ping -w 1 -c 1 " .. gateway .. " | grep '100% packet loss'"))
if gw_ping_test ~= "" then
gw_ping = "DOWN"
if connectivity == "OK" then
connectivity = "WARNING"
if gateway ~= "" then
local gw_ping_test = ut.trim(sys.exec("ping -w 1 -c 1 " .. gateway .. " | grep '100% packet loss'"))
if gw_ping_test ~= "" then
gw_ping = "DOWN"
if connectivity == "OK" then
connectivity = "WARNING"
end
end
end
if gateway6 ~= "" then
local gw_ping6_test = ut.trim(sys.exec("ping -w 1 -c 1 " .. gateway6 .. " | grep '100% packet loss'"))
if gw_ping6_test ~= "" then
gw_ping6 = "DOWN"
if connectivity == "OK" then
connectivity = "WARNING"
end
end
end
end
@ -1111,7 +1252,7 @@ function interfaces_status()
networktype = ut.trim(sys.exec("echo '".. intfdata .. "' | awk -F';' '{print $5}'"))
end
end
elseif gateway == "" then
elseif gateway == "" and gateway6 == "" then
gw_ping = "DOWN"
connectivity = "ERROR"
end
@ -1147,7 +1288,7 @@ function interfaces_status()
local latency = ""
local server_ping = ""
--if connectivity ~= "ERROR" and ifname ~= "" and gateway ~= "" and gw_ping ~= "DOWN" and ifname ~= nil and mArray.openmptcprouter["service_addr"] ~= "" and ipaddr ~= "" then
if ifname ~= "" and gateway ~= "" and gw_ping ~= "DOWN" and ifname ~= nil and mArray.openmptcprouter["service_addr"] ~= "" and ipaddr ~= "" and connectivity ~= "ERROR" then
if ifname ~= "" and (gateway ~= "" or gateway6 ~= "") and gw_ping ~= "DOWN" and ifname ~= nil and mArray.openmptcprouter["service_addr"] ~= "" and (ipaddr ~= "" or ip6addr ~= "") and connectivity ~= "ERROR" then
local serverip = mArray.openmptcprouter["service_addr"]
if serverip == "127.0.0.1" then
serverip = mArray.openmptcprouter["wan_addr"]
@ -1170,7 +1311,7 @@ function interfaces_status()
local multipath_available = ""
local multipath_available_state = ""
if connectivity ~= "ERROR" and mArray.openmptcprouter["dns"] == true and ifname ~= nil and ifname ~= "" and gateway ~= "" and gw_ping == "UP" then
if connectivity ~= "ERROR" and mArray.openmptcprouter["dns"] == true and ifname ~= nil and ifname ~= "" and (gateway ~= "" or gateway6 ~= "") and (gw_ping == "UP" or gw_ping6 == "UP") then
-- Test if multipath can work on the connection
local multipath_available_state = uci:get("openmptcprouter",interface,"mptcp_status") or ""
if multipath_available_state == "" then
@ -1207,7 +1348,9 @@ function interfaces_status()
-- end
local mtu = ""
local whois = ""
local whois6 = ""
local publicIP = ""
local publicIP6 = ""
if connectivity ~= "ERROR" then
if ifname ~= nil and ifname:match("^tun.*") and interface:match("^ovpn.*") then
@ -1215,24 +1358,39 @@ function interfaces_status()
if ifname ~= nil and publicIP == "" and mArray.openmptcprouter["external_check"] ~= false and mArray.openmptcprouter["dns"] == true then
publicIP = ut.trim(sys.exec("omr-ip-intf " .. get_device(interface:sub(5))))
end
publicIP6 = uci:get("openmptcprouter",interface:sub(5),"publicip6") or ""
if ifname ~= nil and publicIP6 == "" and mArray.openmptcprouter["external_check"] ~= false and mArray.openmptcprouter["dns"] == true then
publicIP6 = ut.trim(sys.exec("omr-ip6-intf " .. get_device(interface:sub(5))))
end
else
publicIP = uci:get("openmptcprouter",interface,"publicip") or ""
if ifname ~= nil and publicIP == "" and mArray.openmptcprouter["external_check"] ~= false and mArray.openmptcprouter["dns"] == true then
publicIP = ut.trim(sys.exec("omr-ip-intf " .. ifname))
end
publicIP6 = uci:get("openmptcprouter",interface,"publicip6") or ""
if ifname ~= nil and publicIP6 == "" and mArray.openmptcprouter["external_check"] ~= false and mArray.openmptcprouter["dns"] == true then
publicIP6 = ut.trim(sys.exec("omr-ip6-intf " .. ifname))
end
end
if publicIP ~= "" then
whois = uci:get("openmptcprouter",interface,"asn") or ""
if whois == "" and mArray.openmptcprouter["external_check"] ~= false and mArray.openmptcprouter["dns"] == true then
--whois = ut.trim(sys.exec("whois " .. publicIP .. " | grep -i 'netname' | awk '{print $2}'"))
whois = ut.trim(sys.exec("wget -4 -qO- -T 1 'http://api.iptoasn.com/v1/as/ip/" .. publicIP .. "' | jsonfilter -q -e '@.as_description'"))
whois = ut.trim(sys.exec("whois " .. publicIP .. " | grep -i 'netname' | awk '{print $2}'"))
--whois = ut.trim(sys.exec("wget -4 -qO- -T 1 'http://api.iptoasn.com/v1/as/ip/" .. publicIP .. "' | jsonfilter -q -e '@.as_description'"))
end
end
if publicIP6 ~= "" then
whois6 = uci:get("openmptcprouter",interface,"asn") or ""
if whois6 == "" and mArray.openmptcprouter["external_check"] ~= false and mArray.openmptcprouter["dns"] == true then
whois6 = ut.trim(sys.exec("whois " .. publicIP6 .. " | grep -i 'netname' | awk '{print $2}'"))
--whois6 = ut.trim(sys.exec("wget -6 -qO- -T 1 'http://api.iptoasn.com/v1/as/ip/" .. publicIP6 .. "' | jsonfilter -q -e '@.as_description'"))
end
end
if ifname ~= "" and ifname ~= nil then
if fs.access("/sys/class/net/" .. ifname) then
mtu = ut.trim(sys.exec("cat /sys/class/net/" .. ifname .. "/mtu | tr -d '\n'"))
if mtu == "" and interface ~= nil then
mtu = uci:get("openmptcprouter",interface,"mtu") or ""
mtu = uci:get("openmptcprouter",interface,"mtu") or ""
end
end
end
@ -1249,17 +1407,22 @@ function interfaces_status()
--link = net:adminlink() or "",
ifname = ifname,
ipaddr = ipaddr,
ip6addr = ip6addr,
gateway = gateway,
gateway6 = gateway6,
multipath = section["multipath"],
status = connectivity,
wanip = publicIP,
wanip6 = publicIP6,
latency = latency,
mtu = mtu,
whois = whois or "unknown",
whois6 = whois6 or "unknown",
qos = section["trafficcontrol"],
download = section["download"],
upload = section["upload"],
gw_ping = gw_ping,
gw_ping6 = gw_ping6,
server_ping = server_ping,
ipv6_discover = ipv6_discover,
multipath_available = multipath_available,
@ -1350,6 +1513,11 @@ function _ipv6_discover(interface)
end
local methods = {
getrootfs = {
call = function()
return get_rootfs()
end
},
status = {
call = function()
return interfaces_status()