2016-08-08 14:48:16 +02:00
|
|
|
<?php
|
|
|
|
|
2020-06-07 18:17:16 +02:00
|
|
|
require_once 'includes/config.php';
|
|
|
|
require_once 'includes/wifi_functions.php';
|
2021-02-02 13:26:14 +01:00
|
|
|
require_once 'includes/functions.php';
|
2021-03-07 18:36:48 +01:00
|
|
|
require_once 'includes/get_clients.php';
|
2020-02-14 03:38:46 +01:00
|
|
|
|
2016-08-08 14:48:16 +02:00
|
|
|
/**
|
2020-02-15 18:57:46 +01:00
|
|
|
* Show dashboard page.
|
|
|
|
*/
|
2020-02-02 09:37:15 +01:00
|
|
|
function DisplayDashboard(&$extraFooterScripts)
|
2019-04-10 10:37:35 +02:00
|
|
|
{
|
2020-06-07 18:17:16 +02:00
|
|
|
getWifiInterface();
|
2019-04-10 10:37:35 +02:00
|
|
|
$status = new StatusMessages();
|
|
|
|
// Need this check interface name for proper shell execution.
|
2020-06-09 20:25:19 +02:00
|
|
|
if (!preg_match('/^([a-zA-Z0-9]+)$/', $_SESSION['wifi_client_interface'])) {
|
2019-04-10 10:37:35 +02:00
|
|
|
$status->addMessage(_('Interface name invalid.'), 'danger');
|
|
|
|
$status->showMessages();
|
|
|
|
return;
|
2018-10-23 11:57:55 +02:00
|
|
|
}
|
2019-04-10 10:37:35 +02:00
|
|
|
|
|
|
|
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;
|
2018-10-23 11:57:55 +02:00
|
|
|
}
|
2021-03-15 13:29:16 +01:00
|
|
|
|
|
|
|
// ------------------------- Button pressed to switch client on/off ---------------------------------------------------------
|
|
|
|
$switchedOn = false;
|
|
|
|
if (!RASPI_MONITOR_ENABLED) {
|
|
|
|
if (isset($_POST['ifdown_wlan0'])) {
|
|
|
|
// Pressed stop button
|
|
|
|
$status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning');
|
|
|
|
setClientState("down");
|
|
|
|
$status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success');
|
|
|
|
} elseif (isset($_POST['ifup_wlan0'])) {
|
|
|
|
// Pressed start button
|
|
|
|
$status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning');
|
|
|
|
setClientState("up");
|
|
|
|
$status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success');
|
|
|
|
$switchedOn = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-07 18:36:48 +01:00
|
|
|
|
|
|
|
// ----------------------------- INFOS ABOUT THE ACCESS POINT -------------------------------------------------------------
|
|
|
|
|
2020-06-10 10:09:10 +02:00
|
|
|
exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp);
|
2019-04-10 10:37:35 +02:00
|
|
|
$stdoutIpAllLinesGlued = implode(" ", $stdoutIp);
|
|
|
|
$stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued);
|
2018-10-19 23:36:40 +02:00
|
|
|
|
2019-04-10 10:37:35 +02:00
|
|
|
preg_match('/link\/ether ([0-9a-f:]+)/i', $stdoutIpWRepeatedSpaces, $matchesMacAddr) || $matchesMacAddr[1] = _('No MAC Address Found');
|
|
|
|
$macAddr = $matchesMacAddr[1];
|
2018-10-19 23:36:40 +02:00
|
|
|
|
2019-04-10 10:37:35 +02:00
|
|
|
$ipv4Addrs = '';
|
|
|
|
$ipv4Netmasks = '';
|
2019-07-30 23:15:08 +02:00
|
|
|
if (!preg_match_all('/inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/([0-3][0-9])/i', $stdoutIpWRepeatedSpaces, $matchesIpv4AddrAndSubnet, PREG_SET_ORDER)) {
|
2019-04-10 10:37:35 +02:00
|
|
|
$ipv4Addrs = _('No IPv4 Address Found');
|
|
|
|
} else {
|
2019-07-30 23:15:08 +02:00
|
|
|
foreach ($matchesIpv4AddrAndSubnet as $inet) {
|
2019-09-07 17:42:31 +02:00
|
|
|
$address = $inet[1];
|
|
|
|
$suffix = (int) $inet[2];
|
|
|
|
$netmask = long2ip(-1 << (32 - $suffix));
|
2019-07-30 23:15:08 +02:00
|
|
|
|
2019-09-07 17:42:31 +02:00
|
|
|
$ipv4Addrs .= " $address";
|
|
|
|
$ipv4Netmasks .= " $netmask";
|
2019-04-10 10:37:35 +02:00
|
|
|
}
|
2019-07-30 23:15:08 +02:00
|
|
|
$ipv4Addrs = trim($ipv4Addrs);
|
|
|
|
$ipv4Netmasks = trim($ipv4Netmasks);
|
2019-04-10 10:37:35 +02:00
|
|
|
}
|
2019-11-03 10:45:55 +01:00
|
|
|
$ipv4Netmasks = empty($ipv4Netmasks) ? "-" : $ipv4Netmasks;
|
2018-10-19 23:36:40 +02:00
|
|
|
|
2019-04-10 10:37:35 +02:00
|
|
|
$ipv6Addrs = '';
|
|
|
|
if (!preg_match_all('/inet6 ([a-f0-9:]+)/i', $stdoutIpWRepeatedSpaces, $matchesIpv6Addr)) {
|
|
|
|
$ipv6Addrs = _('No IPv6 Address Found');
|
|
|
|
} else {
|
2019-07-30 22:24:01 +02:00
|
|
|
if (isset($matchesIpv6Addr[1])) {
|
|
|
|
$ipv6Addrs = implode(' ', $matchesIpv6Addr[1]);
|
2019-04-10 10:37:35 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-19 23:36:40 +02:00
|
|
|
|
2019-04-10 10:37:35 +02:00
|
|
|
preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState) || $matchesState[1] = 'unknown';
|
|
|
|
$interfaceState = $matchesState[1];
|
2018-10-19 23:36:40 +02:00
|
|
|
|
2019-04-10 10:37:35 +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.
|
2020-06-09 16:32:49 +02:00
|
|
|
exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/rx_packets ', $stdoutCatRxPackets);
|
2019-04-10 10:37:35 +02:00
|
|
|
$strRxPackets = _('No data');
|
|
|
|
if (ctype_digit($stdoutCatRxPackets[0])) {
|
|
|
|
$strRxPackets = $stdoutCatRxPackets[0];
|
|
|
|
}
|
2018-10-19 23:36:40 +02:00
|
|
|
|
2020-06-09 16:32:49 +02:00
|
|
|
exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/tx_packets ', $stdoutCatTxPackets);
|
2019-04-10 10:37:35 +02:00
|
|
|
$strTxPackets = _('No data');
|
|
|
|
if (ctype_digit($stdoutCatTxPackets[0])) {
|
|
|
|
$strTxPackets = $stdoutCatTxPackets[0];
|
|
|
|
}
|
|
|
|
|
2020-06-09 16:32:49 +02:00
|
|
|
exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/rx_bytes ', $stdoutCatRxBytes);
|
2019-04-10 10:37:35 +02:00
|
|
|
$strRxBytes = _('No data');
|
|
|
|
if (ctype_digit($stdoutCatRxBytes[0])) {
|
|
|
|
$strRxBytes = $stdoutCatRxBytes[0];
|
|
|
|
$strRxBytes .= getHumanReadableDatasize($strRxBytes);
|
|
|
|
}
|
|
|
|
|
2020-06-09 16:32:49 +02:00
|
|
|
exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/tx_bytes ', $stdoutCatTxBytes);
|
2019-04-10 10:37:35 +02:00
|
|
|
$strTxBytes = _('No data');
|
|
|
|
if (ctype_digit($stdoutCatTxBytes[0])) {
|
|
|
|
$strTxBytes = $stdoutCatTxBytes[0];
|
|
|
|
$strTxBytes .= getHumanReadableDatasize($strTxBytes);
|
2018-10-19 23:36:40 +02:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:20:34 +01:00
|
|
|
// ------------------------ INFOS ABOUT THE CLIENT---------------------------------------------------------------
|
2021-03-07 18:36:48 +01:00
|
|
|
$clientinfo=array("name"=>"none","type"=>-1,"connected"=>"n");
|
|
|
|
$raspi_client=$_SESSION['wifi_client_interface'];
|
2021-03-27 18:39:42 +01:00
|
|
|
loadClientConfig();
|
2021-03-12 12:20:34 +01:00
|
|
|
$all_clients = getClients(false);
|
|
|
|
$clientinfo = array("name" => "none", "connected" => "n");
|
|
|
|
if ( ($idx = findCurrentClientIndex($all_clients)) >= 0) $clientinfo = $all_clients["device"][$idx];
|
2021-03-07 18:36:48 +01:00
|
|
|
if ($clientinfo["name"] != "none") $raspi_client = $clientinfo["name"];
|
|
|
|
$interfaceState = $clientinfo["connected"] == "y" ? 'UP' : 'DOWN';
|
|
|
|
$txPower="";
|
|
|
|
if ($clientinfo["type"] == "wlan") {
|
|
|
|
// txpower is now displayed on iw dev(..) info command, not on link command.
|
|
|
|
exec('iw dev '.$clientinfo["name"].' info | sed -rn "s/.*txpower ([0-9]*)[0-9\.]*( dBm).*/\1\2/p"', $stdoutIwInfo);
|
|
|
|
if (!empty($stdoutIwInfo)) $txPower=$stdoutIwInfo[0];
|
|
|
|
}
|
2021-03-12 12:20:34 +01:00
|
|
|
|
2019-04-10 10:37:35 +02:00
|
|
|
$classMsgDevicestatus = 'warning';
|
|
|
|
if ($interfaceState === 'UP') {
|
|
|
|
$classMsgDevicestatus = 'success';
|
|
|
|
}
|
2021-03-15 13:29:16 +01:00
|
|
|
|
|
|
|
if ($switchedOn) exec('sudo ip -s a f label ' . $raspi_client);
|
2021-03-07 18:36:48 +01:00
|
|
|
|
2021-02-02 13:26:14 +01:00
|
|
|
// brought in from template
|
|
|
|
$arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
|
|
|
|
$bridgedEnable = $arrHostapdConf['BridgedEnable'];
|
2021-03-07 18:36:48 +01:00
|
|
|
if ($arrHostapdConf['WifiAPEnable'] == 1) {
|
|
|
|
$client_interface = 'uap0';
|
|
|
|
} else {
|
|
|
|
$client_interface = $clientinfo["name"];
|
|
|
|
}
|
2021-02-02 13:26:14 +01:00
|
|
|
$apInterface = $_SESSION['ap_interface'];
|
2021-03-12 12:20:34 +01:00
|
|
|
$clientInterface = $raspi_client;
|
2021-02-02 13:26:14 +01:00
|
|
|
$MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"';
|
|
|
|
if (getBridgedState()) {
|
|
|
|
$moreLink = "hostapd_conf";
|
|
|
|
exec('iw dev ' . $apInterface . ' station dump | grep -oE ' . $MACPattern, $clients);
|
|
|
|
} else {
|
|
|
|
$moreLink = "dhcpd_conf";
|
|
|
|
exec('cat ' . RASPI_DNSMASQ_LEASES . '| grep -E $(iw dev ' . $apInterface . ' station dump | grep -oE ' . $MACPattern . ' | paste -sd "|")', $clients);
|
|
|
|
}
|
2021-03-07 18:36:48 +01:00
|
|
|
$ifaceStatus = $clientinfo["connected"]=="y" ? "up" : "down";
|
|
|
|
switch($clientinfo["type"]) {
|
|
|
|
case "eth":
|
2021-03-18 18:20:52 +01:00
|
|
|
case "usb":
|
2021-03-12 12:20:34 +01:00
|
|
|
$client_title = "Client: Ethernet cable";
|
2021-03-07 18:36:48 +01:00
|
|
|
$type_name = "Ethernet";
|
|
|
|
break;
|
|
|
|
case "phone":
|
|
|
|
$client_title = "Client: Smartphone (USB tethering)";
|
|
|
|
$type_name = "Smartphone";
|
|
|
|
break;
|
|
|
|
case "wlan":
|
|
|
|
$client_title = "Wireless Client";
|
|
|
|
$type_name = "Wifi";
|
|
|
|
break;
|
|
|
|
case "ppp":
|
|
|
|
case "hilink":
|
|
|
|
$client_title = "Mobile Data Client";
|
|
|
|
$type_name = "Mobile Data";
|
|
|
|
break;
|
|
|
|
default:
|
2021-03-27 18:00:40 +01:00
|
|
|
$client_title = "No information available";
|
2021-03-27 17:43:15 +01:00
|
|
|
$type_name = "Not configured";
|
|
|
|
$ifaceStatus = "warn";
|
2021-03-07 18:36:48 +01:00
|
|
|
}
|
2016-08-08 14:48:16 +02:00
|
|
|
|
2020-02-15 18:57:46 +01:00
|
|
|
echo renderTemplate(
|
|
|
|
"dashboard", compact(
|
2021-02-02 13:26:14 +01:00
|
|
|
"clients",
|
2021-03-12 12:20:34 +01:00
|
|
|
"client_title",
|
|
|
|
"type_name",
|
2021-02-02 13:26:14 +01:00
|
|
|
"moreLink",
|
|
|
|
"apInterface",
|
|
|
|
"clientInterface",
|
|
|
|
"ifaceStatus",
|
|
|
|
"bridgedEnable",
|
2020-02-15 18:57:46 +01:00
|
|
|
"status",
|
|
|
|
"ipv4Addrs",
|
|
|
|
"ipv4Netmasks",
|
|
|
|
"ipv6Addrs",
|
|
|
|
"macAddr",
|
|
|
|
"strRxPackets",
|
|
|
|
"strRxBytes",
|
|
|
|
"strTxPackets",
|
|
|
|
"strTxBytes",
|
|
|
|
"txPower",
|
2021-03-12 12:20:34 +01:00
|
|
|
"clientinfo"
|
2020-02-15 18:57:46 +01:00
|
|
|
)
|
|
|
|
);
|
2020-02-02 09:37:15 +01:00
|
|
|
$extraFooterScripts[] = array('src'=>'app/js/dashboardchart.js', 'defer'=>false);
|
2020-06-30 17:50:21 +02:00
|
|
|
$extraFooterScripts[] = array('src'=>'app/js/linkquality.js', 'defer'=>false);
|
2016-08-08 14:48:16 +02:00
|
|
|
}
|
|
|
|
|