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 01/14] 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 02/14] 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 03/14] 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 04/14] 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 05/14] 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]; From e5f2c218e1f2d05344dc9bae5f99701dae6e9a2d Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 16:58:42 +0100 Subject: [PATCH 06/14] Processed with phpcbf, removed tabs --- includes/internetRoute.php | 55 ++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/includes/internetRoute.php b/includes/internetRoute.php index b91e15c2..715bc3c4 100644 --- a/includes/internetRoute.php +++ b/includes/internetRoute.php @@ -1,36 +1,39 @@ $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) - 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) { +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); + $rInfo[$i]["interface"]=$prop[0]; + $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"; + exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_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"; + exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_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 { - $rInfo = array("error"=>"No route to the internet found"); - } - $rInfo_json = json_encode($rInfo); + } +} else { + $rInfo = array("error"=>"No route to the internet found"); +} +$rInfo_json = json_encode($rInfo); ?> From c4e2faa25ab2f95e629b3c695f179578d454931c Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:01:32 +0100 Subject: [PATCH 07/14] Update networking msg --- locale/en_US/LC_MESSAGES/messages.po | 3 +++ 1 file changed, 3 insertions(+) diff --git a/locale/en_US/LC_MESSAGES/messages.po b/locale/en_US/LC_MESSAGES/messages.po index 70a9b06e..1ce53d99 100644 --- a/locale/en_US/LC_MESSAGES/messages.po +++ b/locale/en_US/LC_MESSAGES/messages.po @@ -451,6 +451,9 @@ msgstr "Configures the max_num_sta option of hostapd. The default and maximum is msgid "Summary" msgstr "Summary" +msgid "Internet connection" +msgstr "Internet connection" + msgid "Current settings" msgstr "Current settings" From 8647673d9a46285be06f5ed16d515b3a147fca4c Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:02:07 +0100 Subject: [PATCH 08/14] Move + rename constants --- config/config.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/config.php b/config/config.php index 2c3c9e8a..4e73ec2b 100755 --- a/config/config.php +++ b/config/config.php @@ -23,6 +23,9 @@ define('RASPI_OPENVPN_CLIENT_LOGIN', '/etc/openvpn/client/login.conf'); define('RASPI_OPENVPN_SERVER_CONFIG', '/etc/openvpn/server/server.conf'); define('RASPI_TORPROXY_CONFIG', '/etc/tor/torrc'); define('RASPI_LIGHTTPD_CONFIG', '/etc/lighttpd/lighttpd.conf'); +define('RASPI_ACCESS_CHECK_IP', '1.1.1.1'); +define('RASPI_ACCESS_CHECK_DNS', 'one.one.one.one'); + // Constant for the 5GHz wireless regulatory domain define('RASPI_5GHZ_ISO_ALPHA2', array('US')); From 9afb773ab3241deb89711f23b672ffd1b768d16a Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:07:38 +0100 Subject: [PATCH 09/14] Minor: remove newline --- config/config.php | 1 - 1 file changed, 1 deletion(-) diff --git a/config/config.php b/config/config.php index 4e73ec2b..bfe464f6 100755 --- a/config/config.php +++ b/config/config.php @@ -26,7 +26,6 @@ define('RASPI_LIGHTTPD_CONFIG', '/etc/lighttpd/lighttpd.conf'); define('RASPI_ACCESS_CHECK_IP', '1.1.1.1'); define('RASPI_ACCESS_CHECK_DNS', 'one.one.one.one'); - // Constant for the 5GHz wireless regulatory domain define('RASPI_5GHZ_ISO_ALPHA2', array('US')); From 36141d1e9cce46280e05d9fec61c6b57e3e279c5 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:08:29 +0100 Subject: [PATCH 10/14] Update defaults w/ new constants --- includes/defaults.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/defaults.php b/includes/defaults.php index 524960f5..e1346112 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -27,6 +27,8 @@ $defaults = [ 'RASPI_OPENVPN_SERVER_CONFIG' => '/etc/openvpn/server/server.conf', 'RASPI_TORPROXY_CONFIG' => '/etc/tor/torrc', 'RASPI_LIGHTTPD_CONFIG' => '/etc/lighttpd/lighttpd.conf', + 'RASPI_ACCESS_CHECK_IP' => '1.1.1.1', + 'RASPI_ACCESS_CHECK_DNS' => 'one.one.one.one', // Optional services, set to true to enable. 'RASPI_WIFICLIENT_ENABLED' => true, From d878cbf356ea9a4f19c5c10c57a503daa920de14 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:12:42 +0100 Subject: [PATCH 11/14] Processed with phpcbf --- templates/networking.php | 49 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/templates/networking.php b/templates/networking.php index a08fa884..455544bd 100755 --- a/templates/networking.php +++ b/templates/networking.php @@ -17,16 +17,15 @@ $arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini'); // defaults to false $bridgedEnabled = $arrHostapdConf['BridgedEnable']; - ?> - - - + ?> + + + - +
-

@@ -45,21 +44,21 @@ No route to the internet found"; - } else { - foreach($rInfo as $route) { - echo ""; - echo "".$route["interface"].""; - echo "".$route["ip-address"].""; - echo "".$route["gateway"]."
".$route["gw-name"].""; - echo "".$route["access-ip"]."
".ACCESS_CHECK_IP.""; - echo "".$route["access-dns"]."
".ACCESS_CHECK_DNS.""; - echo ""; - } - } + } else { + foreach($rInfo as $route) { + echo ""; + echo "".$route["interface"].""; + echo "".$route["ip-address"].""; + echo "".$route["gateway"]."
".$route["gw-name"].""; + echo "".$route["access-ip"]."
".RASPI_ACCESS_CHECK_IP.""; + echo "".$route["access-dns"]."
".RASPI_ACCESS_CHECK_DNS.""; + echo ""; + } + } ?> @@ -71,7 +70,7 @@

- +
@@ -90,7 +89,7 @@
- +
@@ -140,10 +139,10 @@
-
- +
+ - + From 4623060f08b97af2300600d08058272b5274ce65 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Mon, 29 Jun 2020 13:12:29 +0200 Subject: [PATCH 12/14] Simplify and cleanup handling of return values of system calls Handling of return values done in a single line. Determine only, if access is possible not not (true, false). The actual displayed text has to be determined, when displaying the result of the access check. --- includes/internetRoute.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/includes/internetRoute.php b/includes/internetRoute.php index 715bc3c4..db04d685 100644 --- a/includes/internetRoute.php +++ b/includes/internetRoute.php @@ -12,24 +12,15 @@ if (!empty($routes) ) { // 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]; + $rInfo[$i]["gw-name"] = empty($host) ? "*" : $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].' '.RASPI_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_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okip); + $rInfo[$i]["access-ip"] = empty($okip) ? false : true; unset($okdns); - exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_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]; + exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okdns); + $rInfo[$i]["access-dns"] = empty($okdns) ? false : true; } } } else { From 33a099de61eef44c0a639d7b53f2dd2d493ad4a2 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Mon, 29 Jun 2020 13:16:55 +0200 Subject: [PATCH 13/14] Define displayed text for internet access --- templates/networking.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/networking.php b/templates/networking.php index 455544bd..b566a91d 100755 --- a/templates/networking.php +++ b/templates/networking.php @@ -54,8 +54,10 @@ echo "".$route["interface"].""; echo "".$route["ip-address"].""; echo "".$route["gateway"]."
".$route["gw-name"].""; - echo "".$route["access-ip"]."
".RASPI_ACCESS_CHECK_IP.""; - echo "".$route["access-dns"]."
".RASPI_ACCESS_CHECK_DNS.""; + $checkok = $route["access-ip"] ? "✓" : "failed"; + echo "".$checkok."
".RASPI_ACCESS_CHECK_IP.""; + $checkok = $route["access-dns"] ? "✓" : "failed"; + echo "".$checkok."
".RASPI_ACCESS_CHECK_DNS.""; echo ""; } } From 42032e0df0921a53f66326efe13877a172f075cd Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Mon, 29 Jun 2020 13:36:38 +0200 Subject: [PATCH 14/14] Typo corrected --- includes/internetRoute.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/internetRoute.php b/includes/internetRoute.php index db04d685..78207a61 100644 --- a/includes/internetRoute.php +++ b/includes/internetRoute.php @@ -16,10 +16,10 @@ if (!empty($routes) ) { 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=.*/OK/p"',$okip); + exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okip); $rInfo[$i]["access-ip"] = empty($okip) ? false : true; unset($okdns); - exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okdns); + exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okdns); $rInfo[$i]["access-dns"] = empty($okdns) ? false : true; } }