mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-07-09 19:17:42 +02:00
Cleanup interface statistics code (obsolete)
This commit is contained in:
parent
639f7605d1
commit
8a7c954d88
@ -5,24 +5,17 @@ require_once 'includes/wifi_functions.php';
|
|||||||
require_once 'includes/functions.php';
|
require_once 'includes/functions.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show dashboard page.
|
* Displays the dashboard
|
||||||
*/
|
*/
|
||||||
function DisplayDashboard(&$extraFooterScripts)
|
function DisplayDashboard()
|
||||||
{
|
{
|
||||||
getWifiInterface();
|
|
||||||
$status = new \RaspAP\Messages\StatusMessage;
|
$status = new \RaspAP\Messages\StatusMessage;
|
||||||
// Need this check interface name for proper shell execution.
|
$system = new \RaspAP\System\Sysinfo;
|
||||||
if (!preg_match('/^([a-zA-Z0-9]+)$/', $_SESSION['wifi_client_interface'])) {
|
$hostname = $system->hostname();
|
||||||
$status->addMessage(_('Interface name invalid.'), 'danger');
|
$revision = $system->rpiRevision();
|
||||||
$status->showMessages();
|
|
||||||
return;
|
getWifiInterface();
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('exec')) {
|
|
||||||
$status->addMessage(_('Required exec function is disabled. Check if exec is not added to php disable_functions.'), 'danger');
|
|
||||||
$status->showMessages();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp);
|
exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp);
|
||||||
$stdoutIpAllLinesGlued = implode(" ", $stdoutIp);
|
$stdoutIpAllLinesGlued = implode(" ", $stdoutIp);
|
||||||
$stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued);
|
$stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued);
|
||||||
@ -59,43 +52,10 @@ function DisplayDashboard(&$extraFooterScripts)
|
|||||||
preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState) || $matchesState[1] = 'unknown';
|
preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState) || $matchesState[1] = 'unknown';
|
||||||
$interfaceState = $matchesState[1];
|
$interfaceState = $matchesState[1];
|
||||||
|
|
||||||
// Because of table layout used in the ip output we get the interface statistics directly from
|
|
||||||
// the system. One advantage of this is that it could work when interface is disable.
|
|
||||||
exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/rx_packets ', $stdoutCatRxPackets);
|
|
||||||
$strRxPackets = _('No data');
|
|
||||||
if (ctype_digit($stdoutCatRxPackets[0])) {
|
|
||||||
$strRxPackets = $stdoutCatRxPackets[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/tx_packets ', $stdoutCatTxPackets);
|
|
||||||
$strTxPackets = _('No data');
|
|
||||||
if (ctype_digit($stdoutCatTxPackets[0])) {
|
|
||||||
$strTxPackets = $stdoutCatTxPackets[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/rx_bytes ', $stdoutCatRxBytes);
|
|
||||||
$strRxBytes = _('No data');
|
|
||||||
if (ctype_digit($stdoutCatRxBytes[0])) {
|
|
||||||
$strRxBytes = $stdoutCatRxBytes[0];
|
|
||||||
$strRxBytes .= getHumanReadableDatasize($strRxBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/tx_bytes ', $stdoutCatTxBytes);
|
|
||||||
$strTxBytes = _('No data');
|
|
||||||
if (ctype_digit($stdoutCatTxBytes[0])) {
|
|
||||||
$strTxBytes = $stdoutCatTxBytes[0];
|
|
||||||
$strTxBytes .= getHumanReadableDatasize($strTxBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
exec ('vnstat --dbiflist', $stdoutVnStatDB);
|
|
||||||
if (!preg_match('/'.$_SESSION['ap_interface'].'/', $stdoutVnStatDB[0])) {
|
|
||||||
exec('sudo vnstat --add --iface '.$_SESSION['ap_interface'], $return);
|
|
||||||
}
|
|
||||||
|
|
||||||
define('SSIDMAXLEN', 32);
|
define('SSIDMAXLEN', 32);
|
||||||
// Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable."
|
exec('iw dev ' .$_SESSION['ap_interface']. ' info ', $stdoutIw);
|
||||||
exec('iw dev ' .$_SESSION['wifi_client_interface']. ' link ', $stdoutIw);
|
$stdoutIwAllLinesGlued = implode('+', $stdoutIw);
|
||||||
$stdoutIwAllLinesGlued = implode('+', $stdoutIw); // Break lines with character illegal in SSID and MAC addr
|
|
||||||
$stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued);
|
$stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued);
|
||||||
|
|
||||||
preg_match('/Connected to (([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}))/', $stdoutIwWRepSpaces, $matchesBSSID) || $matchesBSSID[1] = '';
|
preg_match('/Connected to (([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}))/', $stdoutIwWRepSpaces, $matchesBSSID) || $matchesBSSID[1] = '';
|
||||||
@ -132,9 +92,6 @@ function DisplayDashboard(&$extraFooterScripts)
|
|||||||
preg_match('/txpower ([0-9\.]+ dBm)/i', $stdoutIpInfoWRepSpaces, $matchesTxPower) || $matchesTxPower[1] = '';
|
preg_match('/txpower ([0-9\.]+ dBm)/i', $stdoutIpInfoWRepSpaces, $matchesTxPower) || $matchesTxPower[1] = '';
|
||||||
$txPower = $matchesTxPower[1];
|
$txPower = $matchesTxPower[1];
|
||||||
|
|
||||||
// iw does not have the "Link Quality". This is a is an aggregate value,
|
|
||||||
// and depends on the driver and hardware.
|
|
||||||
// Display link quality as signal quality for now.
|
|
||||||
$strLinkQuality = 0;
|
$strLinkQuality = 0;
|
||||||
if ($signalLevel > -100 && $wlanHasLink) {
|
if ($signalLevel > -100 && $wlanHasLink) {
|
||||||
if ($signalLevel >= 0) {
|
if ($signalLevel >= 0) {
|
||||||
@ -181,7 +138,6 @@ function DisplayDashboard(&$extraFooterScripts)
|
|||||||
$status->addMessage(sprintf(_('Interface is %s.'), strtolower($interfaceState)), $classMsgDevicestatus);
|
$status->addMessage(sprintf(_('Interface is %s.'), strtolower($interfaceState)), $classMsgDevicestatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// brought in from template
|
|
||||||
$arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
|
$arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
|
||||||
$bridgedEnable = $arrHostapdConf['BridgedEnable'];
|
$bridgedEnable = $arrHostapdConf['BridgedEnable'];
|
||||||
$clientInterface = $_SESSION['wifi_client_interface'];
|
$clientInterface = $_SESSION['wifi_client_interface'];
|
||||||
@ -196,7 +152,6 @@ function DisplayDashboard(&$extraFooterScripts)
|
|||||||
exec('cat ' . RASPI_DNSMASQ_LEASES . '| grep -E $(iw dev ' . $apInterface . ' station dump | grep -oE ' . $MACPattern . ' | paste -sd "|")', $clients);
|
exec('cat ' . RASPI_DNSMASQ_LEASES . '| grep -E $(iw dev ' . $apInterface . ' station dump | grep -oE ' . $MACPattern . ' | paste -sd "|")', $clients);
|
||||||
}
|
}
|
||||||
$ifaceStatus = $wlan0up ? "up" : "down";
|
$ifaceStatus = $wlan0up ? "up" : "down";
|
||||||
|
|
||||||
echo renderTemplate(
|
echo renderTemplate(
|
||||||
"dashboard", compact(
|
"dashboard", compact(
|
||||||
"clients",
|
"clients",
|
||||||
@ -210,21 +165,12 @@ function DisplayDashboard(&$extraFooterScripts)
|
|||||||
"ipv4Netmasks",
|
"ipv4Netmasks",
|
||||||
"ipv6Addrs",
|
"ipv6Addrs",
|
||||||
"macAddr",
|
"macAddr",
|
||||||
"strRxPackets",
|
|
||||||
"strRxBytes",
|
|
||||||
"strTxPackets",
|
|
||||||
"strTxBytes",
|
|
||||||
"connectedSSID",
|
"connectedSSID",
|
||||||
"connectedBSSID",
|
"connectedBSSID",
|
||||||
"bitrate",
|
|
||||||
"signalLevel",
|
|
||||||
"txPower",
|
|
||||||
"frequency",
|
"frequency",
|
||||||
"strLinkQuality",
|
"revision",
|
||||||
"wlan0up"
|
"wlan0up"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$extraFooterScripts[] = array('src'=>'app/js/dashboardchart.js', 'defer'=>false);
|
|
||||||
$extraFooterScripts[] = array('src'=>'app/js/linkquality.js', 'defer'=>false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user