mirror of
https://github.com/RaspAP/raspap-webgui.git
synced 2024-11-21 23:20:22 +00:00
4623060f08
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.
30 lines
1.3 KiB
PHP
30 lines
1.3 KiB
PHP
<?php
|
|
|
|
$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}\.){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);
|
|
$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].' '.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);
|
|
$rInfo[$i]["access-dns"] = empty($okdns) ? false : true;
|
|
}
|
|
}
|
|
} else {
|
|
$rInfo = array("error"=>"No route to the internet found");
|
|
}
|
|
$rInfo_json = json_encode($rInfo);
|
|
?>
|