From 850f52e128dbbcab8c208e51941cce9bf4c905d0 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Thu, 25 Jun 2020 15:54:56 +0200 Subject: [PATCH 1/5] Create internetRoute.php --- includes/internetRoute.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 includes/internetRoute.php diff --git a/includes/internetRoute.php b/includes/internetRoute.php new file mode 100644 index 00000000..711d7fff --- /dev/null +++ b/includes/internetRoute.php @@ -0,0 +1,33 @@ + $route) { + $prop=explode(' ',$route); + $rInfo[$i]["interface"]=$prop[0]; + $rInfo[$i]["ip-address"]=$prop[1]; + $rInfo[$i]["gateway"]=$prop[2]; + // resolve the name of the gateway (if possible) + exec('host '.$prop[2].' | sed -rn "s/.*domain name pointer (.*)\./\1/p" | head -n 1',$host); + if (empty($host)) $host[0]="*"; + $rInfo[$i]["gw-name"] = $host[0]; + if (isset($checkAccess) && $checkAccess) { + // check internet connectivity w/ and w/o DNS resolution + exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;$ + if (empty($okip)) $okip[0]="failed"; + $rInfo[$i]["access-ip"] = $okip[0]; + exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\$ + if (empty($okdns)) $okdns[0]="failed"; + $rInfo[$i]["access-dns"] = $okdns[0]; + } + } + } else { + $data = array("error"=>"No route to the internet found"); + } + $rInfo_json = json_encode($rInfo); +?> From 365bb3fa25ccfbe24df652b642b8f8d84dbe9b8e Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Thu, 25 Jun 2020 16:00:41 +0200 Subject: [PATCH 2/5] Add internet connectivity information --- templates/networking.php | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/templates/networking.php b/templates/networking.php index 7723733b..7bf20e94 100755 --- a/templates/networking.php +++ b/templates/networking.php @@ -27,7 +27,47 @@
-
+

+

+
+
+
+
+
+ + + + + + + + + + + "; + } else { + foreach($rInfo as $route) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + } + ?> + +
No route to the internet found
".$route["interface"]."".$route["ip-address"]."".$route["gateway"]."
".$route["gw-name"]."
".$route["access-ip"]."
".ACCESS_CHECK_IP."
".$route["access-dns"]."
".ACCESS_CHECK_DNS."
+
+
+
+
+

From dc790b246b83c10e0ec2d6013cf78a7c2f637990 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Thu, 25 Jun 2020 16:55:25 +0200 Subject: [PATCH 3/5] fix failed copy/paste lines --- includes/internetRoute.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/internetRoute.php b/includes/internetRoute.php index 711d7fff..d3f4cd1b 100644 --- a/includes/internetRoute.php +++ b/includes/internetRoute.php @@ -5,7 +5,7 @@ define("ACCESS_CHECK_DNS","one.one.one.one"); $rInfo=array(); // get all default routes - exec('ip route list | sed -rn "s/default via (([0-9]{1,3}\.){3}[0-9]{1,3}).*dev (\w*).*src (([0-9]{1,3}\.){$ + exec('ip route list | sed -rn "s/default via (([0-9]{1,3}\.){3}[0-9]{1,3}).*dev (\w*).*src (([0-9]{1,3}\.){3}[0-9]{1,3}).*/\3 \4 \1/p"',$routes); if ( !empty($routes) ) { foreach ($routes as $i => $route) { $prop=explode(' ',$route); @@ -18,16 +18,16 @@ define("ACCESS_CHECK_DNS","one.one.one.one"); $rInfo[$i]["gw-name"] = $host[0]; if (isset($checkAccess) && $checkAccess) { // check internet connectivity w/ and w/o DNS resolution - exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;$ + exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"',$okip); if (empty($okip)) $okip[0]="failed"; $rInfo[$i]["access-ip"] = $okip[0]; - exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\$ + exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"',$okdns); if (empty($okdns)) $okdns[0]="failed"; $rInfo[$i]["access-dns"] = $okdns[0]; } } } else { - $data = array("error"=>"No route to the internet found"); + $rInfo = array("error"=>"No route to the internet found"); } $rInfo_json = json_encode($rInfo); ?> From 5a311d24eceee26a235d1b2dc2b68395f2594930 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Thu, 25 Jun 2020 16:56:53 +0200 Subject: [PATCH 4/5] Remove duplicated title --- templates/networking.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/networking.php b/templates/networking.php index 7bf20e94..a08fa884 100755 --- a/templates/networking.php +++ b/templates/networking.php @@ -27,7 +27,7 @@
-

+

From 90e5f50da653bc12e5b568a18396dc86906569f8 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Thu, 25 Jun 2020 17:18:23 +0200 Subject: [PATCH 5/5] reset input vars to exec before call --- includes/internetRoute.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/internetRoute.php b/includes/internetRoute.php index d3f4cd1b..b91e15c2 100644 --- a/includes/internetRoute.php +++ b/includes/internetRoute.php @@ -13,14 +13,17 @@ define("ACCESS_CHECK_DNS","one.one.one.one"); $rInfo[$i]["ip-address"]=$prop[1]; $rInfo[$i]["gateway"]=$prop[2]; // resolve the name of the gateway (if possible) + unset($host); exec('host '.$prop[2].' | sed -rn "s/.*domain name pointer (.*)\./\1/p" | head -n 1',$host); if (empty($host)) $host[0]="*"; $rInfo[$i]["gw-name"] = $host[0]; if (isset($checkAccess) && $checkAccess) { // check internet connectivity w/ and w/o DNS resolution + unset($okip); exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"',$okip); if (empty($okip)) $okip[0]="failed"; $rInfo[$i]["access-ip"] = $okip[0]; + unset($okdns); exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"',$okdns); if (empty($okdns)) $okdns[0]="failed"; $rInfo[$i]["access-dns"] = $okdns[0];