1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2025-07-06 22:37:40 +02:00
RaspAP/includes/dashboard.php
billz b0ba029c66 Revert "Accept $token object, pass to renderTemplate()"
This reverts commit b3c61782749559ae710b2bcc608ecf6f000650f5.
2025-03-25 13:23:58 -07:00

177 lines
5.9 KiB
PHP
Executable File

<?php
require_once 'includes/config.php';
require_once 'includes/wifi_functions.php';
require_once 'includes/functions.php';
/**
* Displays the dashboard
*/
function DisplayDashboard(&$extraFooterScripts): void
{
// instantiate RaspAP objects
$system = new \RaspAP\System\Sysinfo;
$dashboard = new \RaspAP\UI\Dashboard;
$status = new \RaspAP\Messages\StatusMessage;
$pluginManager = \RaspAP\Plugins\PluginManager::getInstance();
// set AP and client interface session vars
getWifiInterface();
$interface = $_SESSION['ap_interface'] ?? 'wlan0';
$clientInterface = $_SESSION['wifi_client_interface'];
$hostname = $system->hostname();
$revision = $system->rpiRevision();
$deviceImage = $dashboard->getDeviceImage($revision);
$hostapd = $system->hostapdStatus();
$adblock = $system->adBlockStatus();
$vpn = $system->getActiveVpnInterface();
$frequency = $dashboard->getFrequencyBand($interface);
$details = $dashboard->getInterfaceDetails($interface);
$wireless = $dashboard->getWirelessDetails($interface);
$connectionType = $dashboard->getConnectionType();
$connectionIcon = $dashboard->getConnectionIcon($connectionType);
$state = strtolower($details['state']);
$wirelessClients = $dashboard->getWirelessClients();
$ethernetClients = $dashboard->getEthernetClients();
$totalClients = $wirelessClients + $ethernetClients;
$plugins = $pluginManager->getInstalledPlugins();
$bridgedEnable = getBridgedState();
// handle page actions
if (!empty($_POST)) {
$status = $dashboard->handlePageAction($state, $_POST, $status, $interface);
// refresh interface details + state
$details = $dashboard->getInterfaceDetails($interface);
$state = strtolower($details['state']);
}
$ipv4Address = $details['ipv4'];
$ipv4Netmask = $details['ipv4_netmask'];
$macAddress = $details['mac'];
$ssid = $wireless['ssid'];
$ethernetActive = ($connectionType === 'ethernet') ? "active" : "inactive";
$wirelessActive = ($connectionType === 'wireless') ? "active" : "inactive";
$tetheringActive = ($connectionType === 'tethering') ? "active" : "inactive";
$cellularActive = ($connectionType === 'cellular') ? "active" : "inactive";
$bridgedStatus = ($bridgedEnable == 1) ? "active" : "";
$hostapdStatus = ($hostapd[0] == 1) ? "active" : "";
$adblockStatus = ($adblock == true) ? "active" : "";
$wirelessClientActive = ($wirelessClients > 0) ? "active" : "inactive";
$wirelessClientLabel = sprintf(
_('%d WLAN %s'),
$wirelessClients,
$dashboard->formatClientLabel($wirelessClients)
);
$ethernetClientActive = ($ethernetClients > 0) ? "active" : "inactive";
$ethernetClientLabel = sprintf(
_('%d LAN %s'),
$ethernetClients,
$dashboard->formatClientLabel($ethernetClients)
);
$totalClientsActive = ($totalClients > 0) ? "active": "inactive";
$freq5active = $freq24active = "";
$varName = "freq" . str_replace('.', '', $frequency) . "active";
$$varName = "active";
$vpnStatus = $vpn ? "active" : "inactive";
if ($vpn) {
$vpnManaged = $dashboard->getVpnManged($vpn);
}
$firewallManaged = $firewallStatus = "";
$firewallInstalled = array_filter($plugins, fn($p) => str_ends_with($p, 'Firewall')) ? true : false;
if (!$firewallInstalled) {
$firewallUnavailable = '<i class="fas fa-slash fa-stack-1x"></i>';
} else {
$firewallManaged = '<a href="/plugin__Firewall">';
$firewallStatus = ($dashboard->firewallEnabled() == true) ? "active" : "";
}
echo renderTemplate(
"dashboard", compact(
"revision",
"deviceImage",
"interface",
"clientInterface",
"state",
"bridgedStatus",
"hostapdStatus",
"adblockStatus",
"vpnStatus",
"vpnManaged",
"firewallUnavailable",
"firewallStatus",
"firewallManaged",
"ipv4Address",
"ipv4Netmask",
"macAddress",
"ssid",
"frequency",
"freq5active",
"freq24active",
"wirelessClients",
"wirelessClientLabel",
"wirelessClientActive",
"ethernetClients",
"ethernetClientLabel",
"ethernetClientActive",
"totalClients",
"totalClientsActive",
"connectionType",
"connectionIcon",
"ethernetActive",
"wirelessActive",
"tetheringActive",
"cellularActive",
"status"
)
);
$extraFooterScripts[] = array('src'=>'app/js/dashboardchart.js', 'defer'=>false);
}
/**
* Renders a URL for an svg solid line representing the associated
* connection type
*
* @param string $connectionType
* @return string
*/
function renderConnection(string $connectionType): string
{
$deviceMap = [
'ethernet' => 'device-1',
'wireless' => 'device-2',
'tethering' => 'device-3',
'cellular' => 'device-4'
];
$device = $deviceMap[$connectionType] ?? 'device-unknown';
// return generated URL for solid.php
return sprintf('app/img/solid.php?joint&%s&out', $device);
}
/**
* Renders a URL for an svg solid line representing associated
* client connection(s)
*
* @param int $wirelessClients
* @param int $ethernetClients
* @return string
*/
function renderClientConnections(int $wirelessClients, int $ethernetClients): string
{
$devices = [];
if ($wirelessClients > 0) {
$devices[] = 'device-1&out';
}
if ($ethernetClients > 0) {
$devices[] = 'device-2&out';
}
return empty($devices) ? '' : sprintf(
'<img src="app/img/right-solid.php?%s" class="solid-lines solid-lines-right" alt="Client connections">',
implode('&', $devices)
);
}