Wireless: add wifi info to dashboard and info button

This commit is contained in:
bergware
2025-02-23 13:16:17 +01:00
parent 57079c206a
commit c1ecb1b2de
2 changed files with 61 additions and 16 deletions
+31 -8
View File
@@ -1,7 +1,7 @@
#!/usr/bin/php -q
<?PHP
/* Copyright 2005-2023, Lime Technology
* Copyright 2012-2023, Bergware International.
/* Copyright 2005-2025, Lime Technology
* Copyright 2012-2025, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -101,19 +101,42 @@ while (true) {
// interface general information
$mtu = port_get_contents("$net/$port/mtu");
$link = port_get_contents("$net/$port/carrier")==1;
if (substr($port,0,4)=='bond') {
switch (substr($port,0,4)) {
case 'bond':
if ($link) {
$bond_mode = file_exists("$bond/$port") ? str_replace('Bonding Mode: ','',@file("$bond/$port",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)[1]) : '---';
$echo['mode'][] = "$bond_mode, mtu $mtu";
} else $echo['mode'][] = "bond down";
} elseif ($port=='lo') {
$echo['mode'][] = $link ? "loopback" : "not set";
} else {
} else {
$echo['mode'][] = "bond down";
}
break;
case 'wlan':
if ($link) {
unset($speed);
exec("iw $port link | awk '/^\s+[rt]x bitrate: /{print $1,$2,$3,$4}'",$speed);
if (count($speed)==2) {
[$rxrate, $rxunit] = explode(' ',explode(': ',$speed[0])[1]);
[$txrate, $txunit] = explode(' ',explode(': ',$speed[1])[1]);
$echo['mode'][] = _('Rx').": ".round($rxrate)." ".str_replace('Bit/s','bps',$rxunit).", "._('Tx').": ".round($txrate)." ".str_replace('Bit/s','bps',$txunit).", mtu $mtu";
} else {
$echo['mode'][] = _('not connected');
}
} else {
$echo['mode'][] = _('interface down');
}
break;
case 'lo':
$echo['mode'][] = $link ? _('loopback') : _('not set');
break;
default:
if ($link) {
$speed = port_get_contents("$net/$port/speed");
$duplex = port_get_contents("$net/$port/duplex");
$echo['mode'][] = "$speed Mbps, $duplex duplex, mtu $mtu";
} else $echo['mode'][] = "interface down";
} else {
$echo['mode'][] = _('interface down');
}
break;
}
// interface counters
$echo['rxtx'][] = $rx;
@@ -1,7 +1,7 @@
#!/usr/bin/php -q
<?PHP
/* Copyright 2005-2024, Lime Technology
* Copyright 2012-2024, Bergware International.
/* Copyright 2005-2025, Lime Technology
* Copyright 2012-2025, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -35,6 +35,10 @@ function dmidecode($key, $n, $all=true) {
return $all ? $properties : $properties[0]??null;
}
function port_get_contents($port) {
return file_exists($port) ? @file_get_contents($port) : 0;
}
$var = (array)@parse_ini_file('state/var.ini');
$model = _var($var,'SYS_MODEL',_('N/A'));
$board = dmidecode('Base Board Information',2,0);
@@ -160,23 +164,40 @@ foreach ($memory_devices as $device) {
echo "<tr class='ram'><td></td><td>",$device['Locator'],": ",_var($device,'Manufacturer')," ",_var($device,'Part Number'),", $size ",_var($device,'Type')," @ ",_var($device,'Configured Memory Speed'),"</td></tr>";
}
exec("ls --indicator-style=none /sys/class/net|grep -Po '^(bond|eth)\d+$'",$sPorts);
exec("ls --indicator-style=none /sys/class/net|grep -Po '^(bond|eth|wlan)\d+$'",$sPorts);
$i = 0;
$network = count($sPorts) > 1 ? "<span class='link blue-text' onclick=\"$('tr.port').toggle()\">"._('Network').":</span>" : _('Network').':';
foreach ($sPorts as $port) {
$int = "/sys/class/net/$port";
$mtu = file_get_contents("$int/mtu");
$link = @file_get_contents("$int/carrier")==1;
$int = "/sys/class/net/$port";
$mtu = port_get_contents("$int/mtu");
$link = port_get_contents("$int/carrier")==1;
$name = $i ? "" : $network;
$more = $i++ ? "port" : "";
if (substr($port,0,4)=='bond') {
switch (substr($port,0,4)) {
case 'bond':
if ($link) {
$bond_mode = str_replace('Bonding Mode: ','',file("/proc/net/bonding/$port",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)[1]);
echo "<tr class='$more'><td>$name</td><td>$port: $bond_mode, mtu $mtu</td></tr>";
} else {
echo "<tr class='$more'><td>$name</td><td>$port: ",_('bond down'),"</td></tr>";
}
} else {
break;
case 'wlan':
if ($link) {
unset($speed);
exec("iw $port link | awk '/^\s+[rt]x bitrate: /{print $1,$2,$3,$4}'",$speed);
if (count($speed)==2) {
[$rxrate, $rxunit] = explode(' ',explode(': ',$speed[0])[1]);
[$txrate, $txunit] = explode(' ',explode(': ',$speed[1])[1]);
echo "<tr class='$more'><td>$name</td><td>$port: ",_('Rx'),": ",round($rxrate)," ",str_replace('Bit/s','bps',$rxunit),", ",_('Tx').": ",round($txrate)," ",str_replace('Bit/s','bps',$txunit),", mtu $mtu</td></tr>";
} else {
echo "<tr class='$more'><td>$name</td><td>$port: ",_('not connected'),"</td></tr>";
}
} else {
echo "<tr class='$more'><td>$name</td><td>$port: ",_('interface down'),"</td></tr>";
}
break;
default:
if ($link) {
$speed = file_get_contents("$int/speed");
$duplex = file_get_contents("$int/duplex");
@@ -184,6 +205,7 @@ foreach ($sPorts as $port) {
} else {
echo "<tr class='$more'><td>$name</td><td>$port: ",_('interface down'),"</td></tr>";
}
break;
}
}
?>