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] 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 {