From b3c61782749559ae710b2bcc608ecf6f000650f5 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 25 Mar 2025 05:22:29 -0700 Subject: [PATCH] Accept $token object, pass to renderTemplate() --- includes/about.php | 5 +++-- includes/adblock.php | 6 ++--- includes/admin.php | 5 +++-- includes/configure_client.php | 11 ++++++++-- includes/dashboard.php | 9 ++++---- includes/dhcp.php | 5 +++-- includes/hostapd.php | 5 +++-- includes/login.php | 5 +++-- includes/openvpn.php | 5 +++-- includes/page_actions.php | 41 ++++++++++++++++++----------------- includes/restapi.php | 19 +++++++++------- includes/system.php | 5 +++-- includes/wireguard.php | 5 +++-- 13 files changed, 72 insertions(+), 54 deletions(-) diff --git a/includes/about.php b/includes/about.php index 45008f2d..12bf1897 100755 --- a/includes/about.php +++ b/includes/about.php @@ -5,7 +5,7 @@ require_once "app/lib/Parsedown.php"; /** * Displays info about the RaspAP project */ -function DisplayAbout() +function DisplayAbout($token) { $Parsedown = new Parsedown(); $strContent = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/BACKERS.md'); @@ -17,7 +17,8 @@ function DisplayAbout() echo renderTemplate( "about", compact( 'sponsorsHtml', - 'contributingHtml' + 'contributingHtml', + 'token' ) ); } diff --git a/includes/adblock.php b/includes/adblock.php index ec6fb38d..75a751f0 100755 --- a/includes/adblock.php +++ b/includes/adblock.php @@ -6,7 +6,7 @@ require_once 'config.php'; * Manages ad blocking (dnsmasq) configuration * */ -function DisplayAdBlockConfig() +function DisplayAdBlockConfig($token) { $status = new \RaspAP\Messages\StatusMessage; $enabled = false; @@ -93,7 +93,6 @@ function DisplayAdBlockConfig() $adblock_log = "Unable to open log file"; } $logdata = getLogLimited(RASPI_DHCPCD_LOG, $adblock_log); - echo renderTemplate( "adblock", compact( "status", @@ -102,7 +101,8 @@ function DisplayAdBlockConfig() "enabled", "custom_enabled", "adblock_custom_content", - "logdata" + "logdata", + "token" ) ); } diff --git a/includes/admin.php b/includes/admin.php index 61dd21ed..c169a6f4 100755 --- a/includes/admin.php +++ b/includes/admin.php @@ -1,6 +1,6 @@ getVpnManged($vpn); - } + $vpnManaged = $vpn ? $dashboard->getVpnManaged($vpn) : null; $firewallManaged = $firewallStatus = ""; $firewallInstalled = array_filter($plugins, fn($p) => str_ends_with($p, 'Firewall')) ? true : false; if (!$firewallInstalled) { @@ -122,7 +120,8 @@ function DisplayDashboard(&$extraFooterScripts): void "wirelessActive", "tetheringActive", "cellularActive", - "status" + "status", + "token" ) ); $extraFooterScripts[] = array('src'=>'app/js/dashboardchart.js', 'defer'=>false); diff --git a/includes/dhcp.php b/includes/dhcp.php index fd6a47ac..2986c602 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -5,7 +5,7 @@ require_once 'config.php'; /** * Manage DHCP configuration */ -function DisplayDHCPConfig() +function DisplayDHCPConfig($token) { $status = new \RaspAP\Messages\StatusMessage; if (!RASPI_MONITOR_ENABLED) { @@ -74,7 +74,8 @@ function DisplayDHCPConfig() "upstreamServers", "interfaces", "leases", - "logdata" + "logdata", + "token" ) ); } diff --git a/includes/hostapd.php b/includes/hostapd.php index 99b24fe3..6483c425 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -9,7 +9,7 @@ getWifiInterface(); * Initialize hostapd values, display interface * */ -function DisplayHostAPDConfig() +function DisplayHostAPDConfig($token) { $status = new \RaspAP\Messages\StatusMessage; $system = new \RaspAP\System\Sysinfo; @@ -165,7 +165,8 @@ function DisplayHostAPDConfig() "operatingSystem", "selectedHwMode", "countryCodes", - "logdata" + "logdata", + "token" ) ); } diff --git a/includes/login.php b/includes/login.php index e3084a27..742ff6c1 100755 --- a/includes/login.php +++ b/includes/login.php @@ -6,7 +6,7 @@ require_once 'includes/functions.php'; /** * Handler for administrative user login */ -function DisplayLogin() +function DisplayLogin($token) { // initialize auth object $auth = new \RaspAP\Auth\HTTPAuth; @@ -33,7 +33,8 @@ function DisplayLogin() echo renderTemplate( "login", compact( "status", - "redirectUrl" + "redirectUrl", + "token" ) ); } diff --git a/includes/openvpn.php b/includes/openvpn.php index 2b59666b..9c2c4418 100755 --- a/includes/openvpn.php +++ b/includes/openvpn.php @@ -8,7 +8,7 @@ getWifiInterface(); /** * Manage OpenVPN configuration */ -function DisplayOpenVPNConfig() +function DisplayOpenVPNConfig($token) { $status = new \RaspAP\Messages\StatusMessage; if (!RASPI_MONITOR_ENABLED) { @@ -79,7 +79,8 @@ function DisplayOpenVPNConfig() "authUser", "authPassword", "clients", - "conf_default" + "conf_default", + "token" ) ); } diff --git a/includes/page_actions.php b/includes/page_actions.php index c9649792..28606e07 100755 --- a/includes/page_actions.php +++ b/includes/page_actions.php @@ -9,7 +9,7 @@ $page = $_SERVER['PATH_INFO']; // Check if any plugin wants to handle the request if (!$pluginManager->handlePageAction($page)) { // If no plugin is available fall back to core page action handlers - handleCorePageAction($page, $extraFooterScripts); + handleCorePageAction($page, $extraFooterScripts, $token); } /** @@ -17,64 +17,65 @@ if (!$pluginManager->handlePageAction($page)) { * * @param string $page * @param array $extraFooterScripts + * @param object $token * @return void */ -function handleCorePageAction(string $page, array &$extraFooterScripts): void +function handleCorePageAction(string $page, array &$extraFooterScripts, object $token): void { switch ($page) { case "/wlan0_info": - DisplayDashboard($extraFooterScripts); + DisplayDashboard($extraFooterScripts, $token); break; case "/dhcpd_conf": - DisplayDHCPConfig(); + DisplayDHCPConfig($token); break; case "/wpa_conf": - DisplayWPAConfig(); + DisplayWPAConfig($token); break; case "/network_conf": - DisplayNetworkingConfig(); + DisplayNetworkingConfig($token); break; case "/hostapd_conf": - DisplayHostAPDConfig(); + DisplayHostAPDConfig($token); break; case "/adblock_conf": - DisplayAdBlockConfig(); + DisplayAdBlockConfig($token); break; case "/openvpn_conf": - DisplayOpenVPNConfig(); + DisplayOpenVPNConfig($token); break; case "/wg_conf": - DisplayWireGuardConfig(); + DisplayWireGuardConfig($token); break; case "/provider_conf": - DisplayProviderConfig(); + DisplayProviderConfig($token); break; case "/torproxy_conf": - DisplayTorProxyConfig(); + DisplayTorProxyConfig($token); break; case "/auth_conf": - DisplayAuthConfig($_SESSION['user_id']); + DisplayAuthConfig($_SESSION['user_id'], $token); break; case "/save_hostapd_conf": - SaveTORAndVPNConfig(); + SaveTORAndVPNConfig($token); break; case "/data_use": - DisplayDataUsage($extraFooterScripts); + DisplayDataUsage($extraFooterScripts, $token); break; case "/system_info": - DisplaySystem($extraFooterScripts); + DisplaySystem($extraFooterScripts, $token); break; case "/restapi_conf": - DisplayRestAPI(); + DisplayRestAPI($token); break; case "/about": - DisplayAbout(); + DisplayAbout($token); break; case "/login": - DisplayLogin(); + DisplayLogin($token); break; default: - DisplayDashboard($extraFooterScripts); + DisplayDashboard($extraFooterScripts, $token); } } diff --git a/includes/restapi.php b/includes/restapi.php index 4c11cfce..621e390f 100755 --- a/includes/restapi.php +++ b/includes/restapi.php @@ -6,7 +6,7 @@ require_once 'config.php'; /** * Handler for RestAPI settings */ -function DisplayRestAPI() +function DisplayRestAPI($token) { // initialize status object $status = new \RaspAP\Messages\StatusMessage; @@ -59,13 +59,16 @@ function DisplayRestAPI() $docMsg = sprintf(_("RestAPI docs are accessible here %s"),$docUrl, $faicon); } - echo renderTemplate("restapi", compact( - "status", - "apiKey", - "serviceStatus", - "serviceLog", - "docMsg" - )); + echo renderTemplate( + "restapi", compact( + "status", + "apiKey", + "serviceStatus", + "serviceLog", + "docMsg", + "token" + ) + ); } /** diff --git a/includes/system.php b/includes/system.php index d37a5450..addaeea2 100755 --- a/includes/system.php +++ b/includes/system.php @@ -6,7 +6,7 @@ require_once 'config.php'; /** * */ -function DisplaySystem(&$extraFooterScripts) +function DisplaySystem(&$extraFooterScripts, $token) { $status = new \RaspAP\Messages\StatusMessage; $dashboard = new \RaspAP\UI\Dashboard; @@ -146,7 +146,8 @@ function DisplaySystem(&$extraFooterScripts) "themes", "selectedTheme", "logLimit", - "pluginsTable" + "pluginsTable", + "token" )); } diff --git a/includes/wireguard.php b/includes/wireguard.php index f6beb3dd..5a04801a 100755 --- a/includes/wireguard.php +++ b/includes/wireguard.php @@ -5,7 +5,7 @@ require_once 'config.php'; /** * Displays wireguard server & peer configuration */ -function DisplayWireGuardConfig() +function DisplayWireGuardConfig($token) { $status = new \RaspAP\Messages\StatusMessage; $parseFlag = true; @@ -98,7 +98,8 @@ function DisplayWireGuardConfig() "wg_pendpoint", "wg_pallowedips", "wg_pkeepalive", - "wg_log" + "wg_log", + "token" ) ); }