2016-08-08 14:48:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2018-10-19 23:36:40 +02:00
|
|
|
* Show dashboard page.
|
2016-08-08 14:48:16 +02:00
|
|
|
*/
|
|
|
|
function DisplayDashboard(){
|
|
|
|
|
2016-08-15 14:25:20 +02:00
|
|
|
$status = new StatusMessages();
|
2018-10-19 23:36:40 +02:00
|
|
|
// Need this check interface name for proper shell execution.
|
|
|
|
if (!preg_match('/^([a-zA-Z0-9]+)$/', RASPI_WIFI_CLIENT_INTERFACE)) {
|
|
|
|
$status->addMessage(_('Interface name invalid.'), 'danger');
|
|
|
|
$status->showMessages();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 '.RASPI_WIFI_CLIENT_INTERFACE, $stdoutIp);
|
|
|
|
$stdoutIpAllLinesGlued = implode(" ", $stdoutIp);
|
|
|
|
$stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued);
|
|
|
|
|
2018-10-20 14:38:27 +02:00
|
|
|
preg_match('/link\/ether ([0-9a-f:]+)/i', $stdoutIpWRepeatedSpaces, $matchesMacAddr ) || $matchesMacAddr[1] = _('No MAC Address Found');
|
2018-10-19 23:36:40 +02:00
|
|
|
$macAddr = $matchesMacAddr[1];
|
2016-08-15 14:25:20 +02:00
|
|
|
|
2018-10-23 11:57:55 +02:00
|
|
|
$ipv4Addrs = '';
|
|
|
|
$ipv4Netmasks = '';
|
|
|
|
if (!preg_match_all('/inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/([0-3][0-9])/i', $stdoutIpWRepeatedSpaces, $matchesIpv4AddrAndSubnet)) {
|
|
|
|
$ipv4Addrs = _('No IPv4 Address Found');
|
|
|
|
} else {
|
|
|
|
$numMatchesIpv4AddrAndSubnet = count($matchesIpv4AddrAndSubnet);
|
|
|
|
for ($i = 1; $i < $numMatchesIpv4AddrAndSubnet; $i += 2) {
|
|
|
|
if ($i > 2) {
|
|
|
|
$ipv4Netmasks .= ' ';
|
|
|
|
$ipv4Addrs .= ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
$ipv4Addrs .= $matchesIpv4AddrAndSubnet[$i][0];
|
|
|
|
$ipv4Netmasks .= long2ip(-1 << (32 -(int)$matchesIpv4AddrAndSubnet[$i+1][0]));
|
|
|
|
}
|
|
|
|
}
|
2016-08-08 14:48:16 +02:00
|
|
|
|
2018-10-23 11:57:55 +02:00
|
|
|
$ipv6Addrs = '';
|
|
|
|
if (!preg_match_all('/inet6 ([a-f0-9:]+)/i', $stdoutIpWRepeatedSpaces, $matchesIpv6Addr)) {
|
|
|
|
$ipv6Addrs = _('No IPv6 Address Found');
|
|
|
|
} else {
|
|
|
|
$numMatchesIpv6Addr = count($matchesIpv6Addr);
|
|
|
|
for ($i = 1; $i < $numMatchesIpv6Addr; ++$i) {
|
|
|
|
if ($i > 1) {
|
|
|
|
$ipv6Addrs .= ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
$ipv6Addrs .= $matchesIpv6Addr[$i];
|
|
|
|
}
|
|
|
|
}
|
2016-08-08 14:48:16 +02:00
|
|
|
|
2018-10-19 23:36:40 +02:00
|
|
|
preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState ) || $matchesState[1] = 'unknown';
|
2018-10-20 14:38:27 +02:00
|
|
|
$interfaceState = $matchesState[1];
|
2018-10-19 23:36:40 +02:00
|
|
|
|
|
|
|
// 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/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/rx_packets ', $stdoutCatRxPackets);
|
2018-10-20 14:38:27 +02:00
|
|
|
$strRxPackets = _('No data');
|
2018-10-19 23:36:40 +02:00
|
|
|
if (ctype_digit($stdoutCatRxPackets[0])) {
|
|
|
|
$strRxPackets = $stdoutCatRxPackets[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_packets ', $stdoutCatTxPackets);
|
2018-10-20 14:38:27 +02:00
|
|
|
$strTxPackets = _('No data');
|
2018-10-19 23:36:40 +02:00
|
|
|
if (ctype_digit($stdoutCatTxPackets[0])) {
|
|
|
|
$strTxPackets = $stdoutCatTxPackets[0];
|
2017-10-03 18:09:50 +02:00
|
|
|
}
|
2018-10-19 23:36:40 +02:00
|
|
|
|
|
|
|
exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/rx_bytes ', $stdoutCatRxBytes);
|
2018-10-20 14:38:27 +02:00
|
|
|
$strRxBytes = _('No data');
|
2018-10-19 23:36:40 +02:00
|
|
|
if (ctype_digit($stdoutCatRxBytes[0])) {
|
|
|
|
$strRxBytes = $stdoutCatRxBytes[0];
|
|
|
|
$strRxBytes .= getHumanReadableDatasize($strRxBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_bytes ', $stdoutCatTxBytes);
|
2018-10-20 14:38:27 +02:00
|
|
|
$strTxBytes = _('No data');
|
2018-10-19 23:36:40 +02:00
|
|
|
if (ctype_digit($stdoutCatTxBytes[0])) {
|
|
|
|
$strTxBytes = $stdoutCatTxBytes[0];
|
|
|
|
$strTxBytes .= getHumanReadableDatasize($strTxBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
define('SSIDMAXLEN', 32);
|
|
|
|
// Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable."
|
|
|
|
exec('iw dev '.RASPI_WIFI_CLIENT_INTERFACE.' link ', $stdoutIw);
|
|
|
|
$stdoutIwAllLinesGlued = implode(' ', $stdoutIw);
|
|
|
|
$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] = '';
|
|
|
|
$connectedBSSID = $matchesBSSID[1];
|
|
|
|
|
2018-10-20 14:38:27 +02:00
|
|
|
$wlanHasLink = false;
|
|
|
|
if ($interfaceState === 'UP') {
|
|
|
|
$wlanHasLink = true;
|
|
|
|
}
|
|
|
|
|
2018-10-19 23:36:40 +02:00
|
|
|
if (!preg_match('/SSID: ([^ ]{1,'.SSIDMAXLEN.'})/', $stdoutIwWRepSpaces, $matchesSSID)) {
|
|
|
|
$wlanHasLink = false;
|
|
|
|
$matchesSSID[1] = 'Not connected';
|
|
|
|
}
|
|
|
|
|
|
|
|
$connectedSSID = $matchesSSID[1];
|
|
|
|
|
|
|
|
preg_match('/freq: (\d+)/i', $stdoutIwWRepSpaces, $matchesFrequency) || $matchesFrequency[1] = '';
|
|
|
|
$frequency = $matchesFrequency[1].' MHz';
|
|
|
|
|
|
|
|
preg_match('/signal: (-?[0-9]+ dBm)/i', $stdoutIwWRepSpaces, $matchesSignal) || $matchesSignal[1] = '';
|
|
|
|
$signalLevel = $matchesSignal[1];
|
|
|
|
|
|
|
|
preg_match('/tx bitrate: ([0-9\.]+ [KMGT]?Bit\/s)/', $stdoutIwWRepSpaces, $matchesBitrate) || $matchesBitrate[1] = '';
|
|
|
|
$bitrate = $matchesBitrate[1];
|
|
|
|
|
|
|
|
// txpower is now displayed on iw dev(..) info command, not on link command.
|
|
|
|
exec('iw dev '.RASPI_WIFI_CLIENT_INTERFACE.' info ', $stdoutIwInfo);
|
|
|
|
$stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo);
|
|
|
|
$stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued);
|
|
|
|
|
|
|
|
preg_match('/txpower ([0-9\.]+ dBm)/i', $stdoutIpInfoWRepSpaces, $matchesTxPower ) || $matchesTxPower[1] = '';
|
2018-10-20 14:38:27 +02:00
|
|
|
$txPower = $matchesTxPower[1];
|
2018-10-19 23:36:40 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
if ($signalLevel > -100 && $wlanHasLink) {
|
|
|
|
if ($signalLevel >= 0) {
|
|
|
|
$strLinkQuality = 100;
|
|
|
|
} else {
|
|
|
|
$strLinkQuality = 100 + $signalLevel;
|
|
|
|
}
|
2017-10-03 18:09:50 +02:00
|
|
|
}
|
2018-10-19 23:36:40 +02:00
|
|
|
|
|
|
|
$wlan0up = false;
|
|
|
|
$classMsgDevicestatus = 'warning';
|
2018-10-20 14:38:27 +02:00
|
|
|
if ($interfaceState === 'UP') {
|
2018-10-19 23:36:40 +02:00
|
|
|
$wlan0up = true;
|
|
|
|
$classMsgDevicestatus = 'success';
|
2016-08-08 22:37:44 +02:00
|
|
|
}
|
2016-08-08 14:48:16 +02:00
|
|
|
|
2018-10-19 23:36:40 +02:00
|
|
|
|
2018-10-20 14:38:27 +02:00
|
|
|
if (isset($_POST['ifdown_wlan0'])) {
|
2018-10-19 23:36:40 +02:00
|
|
|
// Pressed stop button
|
2018-10-20 14:38:27 +02:00
|
|
|
if ($interfaceState === 'UP') {
|
|
|
|
$status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning');
|
2018-10-19 23:36:40 +02:00
|
|
|
exec( 'sudo ip link set '.RASPI_WIFI_CLIENT_INTERFACE.' down' );
|
2018-10-20 14:38:27 +02:00
|
|
|
$wlan0up = false;
|
|
|
|
$status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success');
|
|
|
|
} elseif ($interfaceState === 'unknown') {
|
|
|
|
$status->addMessage(_('Interface state unknown.'), 'danger');
|
2016-08-08 22:37:44 +02:00
|
|
|
} else {
|
2018-10-20 14:38:27 +02:00
|
|
|
$status->addMessage(sprintf(_('Interface already %s.'), _('down')), 'warning');
|
2016-08-08 22:37:44 +02:00
|
|
|
}
|
|
|
|
} elseif( isset($_POST['ifup_wlan0']) ) {
|
2018-10-19 23:36:40 +02:00
|
|
|
// Pressed start button
|
2018-10-20 14:38:27 +02:00
|
|
|
if ($interfaceState === 'DOWN') {
|
|
|
|
$status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning');
|
2018-10-19 23:36:40 +02:00
|
|
|
exec('sudo ip link set ' . RASPI_WIFI_CLIENT_INTERFACE . ' up');
|
|
|
|
exec('sudo ip -s a f label ' . RASPI_WIFI_CLIENT_INTERFACE);
|
2018-10-20 14:38:27 +02:00
|
|
|
$wlan0up = true;
|
|
|
|
$status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success');
|
|
|
|
} elseif ($interfaceState === 'unknown') {
|
|
|
|
$status->addMessage(_('Interface state unknown.'), 'danger');
|
2016-08-08 22:37:44 +02:00
|
|
|
} else {
|
2018-10-20 14:38:27 +02:00
|
|
|
$status->addMessage(sprintf(_('Interface already %s.'), _('up')), 'warning');
|
2016-08-08 22:37:44 +02:00
|
|
|
}
|
2018-10-20 14:38:27 +02:00
|
|
|
} else {
|
|
|
|
$status->addMessage(sprintf(_('Interface is %s.'), strtolower($interfaceState)), $classMsgDevicestatus);
|
2016-08-08 22:37:44 +02:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-12">
|
|
|
|
<div class="panel panel-primary">
|
2017-10-23 21:51:34 +02:00
|
|
|
<div class="panel-heading"><i class="fa fa-dashboard fa-fw"></i> <?php echo _("Dashboard"); ?></div>
|
2016-08-08 22:37:44 +02:00
|
|
|
<div class="panel-body">
|
2016-08-15 14:25:20 +02:00
|
|
|
<p><?php $status->showMessages(); ?></p>
|
2016-08-08 22:37:44 +02:00
|
|
|
<div class="row">
|
2018-05-27 10:42:54 +02:00
|
|
|
<div class="col-md-6">
|
2016-08-08 22:37:44 +02:00
|
|
|
<div class="panel panel-default">
|
2018-05-27 10:42:54 +02:00
|
|
|
<div class="panel-body">
|
|
|
|
<h4><?php echo _("Interface Information"); ?></h4>
|
2018-08-04 01:58:34 +02:00
|
|
|
<div class="info-item"><?php echo _("Interface Name"); ?></div> <?php echo RASPI_WIFI_CLIENT_INTERFACE; ?><br />
|
2018-10-23 11:57:55 +02:00
|
|
|
<div class="info-item"><?php echo _("IPv4 Address"); ?></div> <?php echo htmlspecialchars($ipv4Addrs, ENT_QUOTES); ?><br />
|
|
|
|
<div class="info-item"><?php echo _("Subnet Mask"); ?></div> <?php echo htmlspecialchars($ipv4Netmasks, ENT_QUOTES); ?><br />
|
|
|
|
<div class="info-item"><?php echo _("IPv6 Address"); ?></div> <?php echo htmlspecialchars($ipv6Addrs, ENT_QUOTES); ?><br />
|
2018-10-19 23:36:40 +02:00
|
|
|
<div class="info-item"><?php echo _("Mac Address"); ?></div> <?php echo htmlspecialchars($macAddr, ENT_QUOTES); ?><br /><br />
|
2018-05-27 10:42:54 +02:00
|
|
|
<h4><?php echo _("Interface Statistics"); ?></h4>
|
2018-10-19 23:36:40 +02:00
|
|
|
<div class="info-item"><?php echo _("Received Packets"); ?></div> <?php echo htmlspecialchars($strRxPackets, ENT_QUOTES); ?><br />
|
|
|
|
<div class="info-item"><?php echo _("Received Bytes"); ?></div> <?php echo htmlspecialchars($strRxBytes, ENT_QUOTES); ?><br /><br />
|
2018-08-04 01:58:34 +02:00
|
|
|
<div class="info-item"><?php echo _("Transferred Packets"); ?></div> <?php echo htmlspecialchars($strTxPackets, ENT_QUOTES); ?><br />
|
2018-10-19 23:36:40 +02:00
|
|
|
<div class="info-item"><?php echo _("Transferred Bytes"); ?></div> <?php echo htmlspecialchars($strTxBytes, ENT_QUOTES); ?><br />
|
2018-05-27 10:42:54 +02:00
|
|
|
</div><!-- /.panel-body -->
|
|
|
|
</div><!-- /.panel-default -->
|
2016-08-08 22:37:44 +02:00
|
|
|
</div><!-- /.col-md-6 -->
|
2018-05-27 10:42:54 +02:00
|
|
|
<div class="col-md-6">
|
|
|
|
<div class="panel panel-default">
|
|
|
|
<div class="panel-body wireless">
|
2017-10-23 21:51:34 +02:00
|
|
|
<h4><?php echo _("Wireless Information"); ?></h4>
|
2018-10-19 23:36:40 +02:00
|
|
|
<div class="info-item"><?php echo _("Connected To"); ?></div> <?php echo htmlspecialchars($connectedSSID, ENT_QUOTES); ?><br />
|
|
|
|
<div class="info-item"><?php echo _("AP Mac Address"); ?></div> <?php echo htmlspecialchars($connectedBSSID, ENT_QUOTES); ?><br />
|
|
|
|
<div class="info-item"><?php echo _("Bitrate"); ?></div> <?php echo htmlspecialchars($bitrate, ENT_QUOTES); ?><br />
|
|
|
|
<div class="info-item"><?php echo _("Signal Level"); ?></div> <?php echo htmlspecialchars($signalLevel, ENT_QUOTES); ?><br />
|
2018-10-20 14:38:27 +02:00
|
|
|
<div class="info-item"><?php echo _("Transmit Power"); ?></div> <?php echo htmlspecialchars($txPower, ENT_QUOTES); ?><br />
|
2018-10-19 23:36:40 +02:00
|
|
|
<div class="info-item"><?php echo _("Frequency"); ?></div> <?php echo htmlspecialchars($frequency, ENT_QUOTES); ?><br /><br />
|
2018-05-27 10:42:54 +02:00
|
|
|
<div class="info-item"><?php echo _("Link Quality"); ?></div>
|
|
|
|
<div class="progress">
|
|
|
|
<div class="progress-bar progress-bar-info progress-bar-striped active"
|
|
|
|
role="progressbar"
|
2018-08-04 01:58:34 +02:00
|
|
|
aria-valuenow="<?php echo htmlspecialchars($strLinkQuality, ENT_QUOTES); ?>" aria-valuemin="0" aria-valuemax="100"
|
|
|
|
style="width: <?php echo htmlspecialchars($strLinkQuality, ENT_QUOTES); ?>%;"><?php echo htmlspecialchars($strLinkQuality, ENT_QUOTES); ?>%
|
2018-05-27 10:42:54 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div><!-- /.panel-body -->
|
|
|
|
</div><!-- /.panel-default -->
|
|
|
|
</div><!-- /.col-md-6 -->
|
|
|
|
</div><!-- /.row -->
|
2016-08-08 14:48:16 +02:00
|
|
|
|
2018-05-27 10:42:54 +02:00
|
|
|
<div class="col-lg-12">
|
2016-08-08 22:37:44 +02:00
|
|
|
<div class="row">
|
|
|
|
<form action="?page=wlan0_info" method="POST">
|
|
|
|
<?php if ( !$wlan0up ) {
|
2018-10-20 14:38:27 +02:00
|
|
|
echo '<input type="submit" class="btn btn-success" value="'._("Start ").RASPI_WIFI_CLIENT_INTERFACE.'" name="ifup_wlan0" />';
|
2016-08-08 22:37:44 +02:00
|
|
|
} else {
|
2018-10-20 14:38:27 +02:00
|
|
|
echo '<input type="submit" class="btn btn-warning" value="'._("Stop ").RASPI_WIFI_CLIENT_INTERFACE.'" name="ifdown_wlan0" />';
|
2018-05-27 10:42:54 +02:00
|
|
|
}
|
2016-08-08 22:37:44 +02:00
|
|
|
?>
|
2017-10-23 21:51:34 +02:00
|
|
|
<input type="button" class="btn btn-outline btn-primary" value="<?php echo _("Refresh"); ?>" onclick="document.location.reload(true)" />
|
2016-08-08 22:37:44 +02:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-08-08 14:48:16 +02:00
|
|
|
|
2016-08-08 22:37:44 +02:00
|
|
|
</div><!-- /.panel-body -->
|
2018-10-19 23:36:40 +02:00
|
|
|
<div class="panel-footer"><?php echo _("Information provided by ip and iw and from system."); ?></div>
|
2016-08-08 22:37:44 +02:00
|
|
|
</div><!-- /.panel-default -->
|
|
|
|
</div><!-- /.col-lg-12 -->
|
|
|
|
</div><!-- /.row -->
|
2017-10-03 06:46:02 +02:00
|
|
|
<?php
|
2016-08-08 14:48:16 +02:00
|
|
|
}
|
|
|
|
|
2018-10-19 23:36:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a human readable data size string from a number of bytes.
|
|
|
|
*
|
|
|
|
* @param long $numbytes The number of bytes.
|
|
|
|
* @param int $precision The number of numbers to round to after the dot/comma.
|
|
|
|
* @return string Data size in units: PB, TB, GB, MB or KB otherwise an empty string.
|
|
|
|
*/
|
|
|
|
function getHumanReadableDatasize($numbytes, $precision = 2)
|
|
|
|
{
|
|
|
|
$humanDatasize = '';
|
|
|
|
$kib = 1024;
|
|
|
|
$mib = $kib * 1024;
|
|
|
|
$gib = $mib * 1024;
|
|
|
|
$tib = $gib * 1024;
|
|
|
|
$pib = $tib * 1024;
|
|
|
|
if ($numbytes >= $pib) {
|
|
|
|
$humanDatasize = ' ('.round($numbytes / $pib, $precision).' PB)';
|
|
|
|
} elseif ($numbytes >= $tib) {
|
|
|
|
$humanDatasize = ' ('.round($numbytes / $tib, $precision).' TB)';
|
|
|
|
} elseif ($numbytes >= $gib) {
|
|
|
|
$humanDatasize = ' ('.round($numbytes / $gib, $precision).' GB)';
|
|
|
|
} elseif ($numbytes >= $mib) {
|
|
|
|
$humanDatasize = ' ('.round($numbytes / $mib, $precision).' MB)';
|
|
|
|
} elseif ($numbytes >= $kib) {
|
|
|
|
$humanDatasize = ' ('.round($numbytes / $kib, $precision).' KB)';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $humanDatasize;
|
|
|
|
}
|
|
|
|
|