Cleanup and fix for udev rules written for clients

Fix device type in client table
This commit is contained in:
Christian Zeitnitz
2021-03-29 15:16:23 +02:00
parent f7cef44b06
commit 300f2c2457
4 changed files with 89 additions and 74 deletions

View File

@@ -20,16 +20,8 @@ function getClients($simple=true)
}
foreach ($rawdevs as $i => $dev) {
$cl["device"][$i]["name"]=$dev;
if (preg_match("/^(\w+)[0-9]$/", $dev, $nam) === 1) {
$nam=$nam[1];
} else {
$nam="none";
}
if (($n = array_search($nam, $_SESSION["net-device-name-prefix"])) === false) {
$n = count($_SESSION["net-device-types"])-1;
}
$ty = $_SESSION["net-device-types"][$n];
$cl["device"][$i]["type"]=$ty;
$nam = (preg_match("/^(\w+)[0-9]$/",$dev,$nam) === 1) ? $nam=$nam[1] : "";
$cl["device"][$i]["type"]=$ty=getClientType($dev);
unset($udevinfo);
exec("udevadm info /sys/class/net/$dev 2> /dev/null", $udevinfo);
if ($nam == "ppp" && isset($devtty)) {
@@ -181,6 +173,27 @@ function getClients($simple=true)
return $cl;
}
function getClientType($dev) {
loadClientConfig();
// check if device type stored in DEVTYPE or raspapType (from UDEV rule) protperty of the device
exec("udevadm info /sys/class/net/$dev 2> /dev/null", $udevadm);
$type="none";
if (!empty($udevadm)) {
$type=preg_only_match("/raspapType=(\w*)/i",$udevadm);
if (empty($type)) {
$type=preg_only_match("/DEVTYPE=(\w*)/i",$udevadm);
}
}
if (empty($type) || array_search($type, $_SESSION["net-device-name-prefix"]) === false) {
// no device type yet -> get device type from device name
if (preg_match("/^(\w+)[0-9]$/",$dev,$nam) === 1) $nam=$nam[1];
else $nam="none";
if (($n = array_search($nam, $_SESSION["net-device-name-prefix"])) === false) $n = count($_SESSION["net-device-types"])-1;
$type = $_SESSION["net-device-types"][$n];
}
return $type;
}
function loadClientConfig()
{
// load network device config file for UDEV rules into $_SESSION

View File

@@ -46,7 +46,7 @@ function getRouteInfo($checkAccess)
$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=.*/OK/p"', $okdns);
$rInfo[$i]["access-dns"] = empty($okdns) ? false : true;
$rInfo[$i]["access-dns"] = empty($okdns) ? false : true;
}
}
} else {