1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2025-07-31 17:59:25 +02:00

Accept $token object, pass to renderTemplate()

This commit is contained in:
billz 2025-03-25 05:22:29 -07:00
parent a5907d8f7f
commit b3c6178274
13 changed files with 72 additions and 54 deletions

View File

@ -5,7 +5,7 @@ require_once "app/lib/Parsedown.php";
/** /**
* Displays info about the RaspAP project * Displays info about the RaspAP project
*/ */
function DisplayAbout() function DisplayAbout($token)
{ {
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();
$strContent = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/BACKERS.md'); $strContent = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/BACKERS.md');
@ -17,7 +17,8 @@ function DisplayAbout()
echo renderTemplate( echo renderTemplate(
"about", compact( "about", compact(
'sponsorsHtml', 'sponsorsHtml',
'contributingHtml' 'contributingHtml',
'token'
) )
); );
} }

View File

@ -6,7 +6,7 @@ require_once 'config.php';
* Manages ad blocking (dnsmasq) configuration * Manages ad blocking (dnsmasq) configuration
* *
*/ */
function DisplayAdBlockConfig() function DisplayAdBlockConfig($token)
{ {
$status = new \RaspAP\Messages\StatusMessage; $status = new \RaspAP\Messages\StatusMessage;
$enabled = false; $enabled = false;
@ -93,7 +93,6 @@ function DisplayAdBlockConfig()
$adblock_log = "Unable to open log file"; $adblock_log = "Unable to open log file";
} }
$logdata = getLogLimited(RASPI_DHCPCD_LOG, $adblock_log); $logdata = getLogLimited(RASPI_DHCPCD_LOG, $adblock_log);
echo renderTemplate( echo renderTemplate(
"adblock", compact( "adblock", compact(
"status", "status",
@ -102,7 +101,8 @@ function DisplayAdBlockConfig()
"enabled", "enabled",
"custom_enabled", "custom_enabled",
"adblock_custom_content", "adblock_custom_content",
"logdata" "logdata",
"token"
) )
); );
} }

View File

@ -1,6 +1,6 @@
<?php <?php
function DisplayAuthConfig($username) function DisplayAuthConfig($username, $token)
{ {
$status = new \RaspAP\Messages\StatusMessage; $status = new \RaspAP\Messages\StatusMessage;
$auth = new \RaspAP\Auth\HTTPAuth; $auth = new \RaspAP\Auth\HTTPAuth;
@ -42,7 +42,8 @@ function DisplayAuthConfig($username)
echo renderTemplate( echo renderTemplate(
"admin", compact( "admin", compact(
"status", "status",
"username" "username",
"token"
) )
); );
} }

View File

@ -6,7 +6,7 @@ require_once 'includes/wifi_functions.php';
* *
* *
*/ */
function DisplayWPAConfig() function DisplayWPAConfig($token)
{ {
$status = new \RaspAP\Messages\StatusMessage; $status = new \RaspAP\Messages\StatusMessage;
$networks = []; $networks = [];
@ -148,5 +148,12 @@ function DisplayWPAConfig()
preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState) || $matchesState[1] = 'unknown'; preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState) || $matchesState[1] = 'unknown';
$ifaceStatus = strtolower($matchesState[1]) ? "up" : "down"; $ifaceStatus = strtolower($matchesState[1]) ? "up" : "down";
echo renderTemplate("configure_client", compact("status", "clientInterface", "ifaceStatus")); echo renderTemplate(
"configure_client", compact(
"status",
"clientInterface",
"ifaceStatus",
"token"
)
);
} }

View File

@ -7,7 +7,7 @@ require_once 'includes/functions.php';
/** /**
* Displays the dashboard * Displays the dashboard
*/ */
function DisplayDashboard(&$extraFooterScripts): void function DisplayDashboard(&$extraFooterScripts, $token): void
{ {
// instantiate RaspAP objects // instantiate RaspAP objects
$system = new \RaspAP\System\Sysinfo; $system = new \RaspAP\System\Sysinfo;
@ -74,9 +74,7 @@ function DisplayDashboard(&$extraFooterScripts): void
$varName = "freq" . str_replace('.', '', $frequency) . "active"; $varName = "freq" . str_replace('.', '', $frequency) . "active";
$$varName = "active"; $$varName = "active";
$vpnStatus = $vpn ? "active" : "inactive"; $vpnStatus = $vpn ? "active" : "inactive";
if ($vpn) { $vpnManaged = $vpn ? $dashboard->getVpnManaged($vpn) : null;
$vpnManaged = $dashboard->getVpnManged($vpn);
}
$firewallManaged = $firewallStatus = ""; $firewallManaged = $firewallStatus = "";
$firewallInstalled = array_filter($plugins, fn($p) => str_ends_with($p, 'Firewall')) ? true : false; $firewallInstalled = array_filter($plugins, fn($p) => str_ends_with($p, 'Firewall')) ? true : false;
if (!$firewallInstalled) { if (!$firewallInstalled) {
@ -122,7 +120,8 @@ function DisplayDashboard(&$extraFooterScripts): void
"wirelessActive", "wirelessActive",
"tetheringActive", "tetheringActive",
"cellularActive", "cellularActive",
"status" "status",
"token"
) )
); );
$extraFooterScripts[] = array('src'=>'app/js/dashboardchart.js', 'defer'=>false); $extraFooterScripts[] = array('src'=>'app/js/dashboardchart.js', 'defer'=>false);

View File

@ -5,7 +5,7 @@ require_once 'config.php';
/** /**
* Manage DHCP configuration * Manage DHCP configuration
*/ */
function DisplayDHCPConfig() function DisplayDHCPConfig($token)
{ {
$status = new \RaspAP\Messages\StatusMessage; $status = new \RaspAP\Messages\StatusMessage;
if (!RASPI_MONITOR_ENABLED) { if (!RASPI_MONITOR_ENABLED) {
@ -74,7 +74,8 @@ function DisplayDHCPConfig()
"upstreamServers", "upstreamServers",
"interfaces", "interfaces",
"leases", "leases",
"logdata" "logdata",
"token"
) )
); );
} }

View File

@ -9,7 +9,7 @@ getWifiInterface();
* Initialize hostapd values, display interface * Initialize hostapd values, display interface
* *
*/ */
function DisplayHostAPDConfig() function DisplayHostAPDConfig($token)
{ {
$status = new \RaspAP\Messages\StatusMessage; $status = new \RaspAP\Messages\StatusMessage;
$system = new \RaspAP\System\Sysinfo; $system = new \RaspAP\System\Sysinfo;
@ -165,7 +165,8 @@ function DisplayHostAPDConfig()
"operatingSystem", "operatingSystem",
"selectedHwMode", "selectedHwMode",
"countryCodes", "countryCodes",
"logdata" "logdata",
"token"
) )
); );
} }

View File

@ -6,7 +6,7 @@ require_once 'includes/functions.php';
/** /**
* Handler for administrative user login * Handler for administrative user login
*/ */
function DisplayLogin() function DisplayLogin($token)
{ {
// initialize auth object // initialize auth object
$auth = new \RaspAP\Auth\HTTPAuth; $auth = new \RaspAP\Auth\HTTPAuth;
@ -33,7 +33,8 @@ function DisplayLogin()
echo renderTemplate( echo renderTemplate(
"login", compact( "login", compact(
"status", "status",
"redirectUrl" "redirectUrl",
"token"
) )
); );
} }

View File

@ -8,7 +8,7 @@ getWifiInterface();
/** /**
* Manage OpenVPN configuration * Manage OpenVPN configuration
*/ */
function DisplayOpenVPNConfig() function DisplayOpenVPNConfig($token)
{ {
$status = new \RaspAP\Messages\StatusMessage; $status = new \RaspAP\Messages\StatusMessage;
if (!RASPI_MONITOR_ENABLED) { if (!RASPI_MONITOR_ENABLED) {
@ -79,7 +79,8 @@ function DisplayOpenVPNConfig()
"authUser", "authUser",
"authPassword", "authPassword",
"clients", "clients",
"conf_default" "conf_default",
"token"
) )
); );
} }

View File

@ -9,7 +9,7 @@ $page = $_SERVER['PATH_INFO'];
// Check if any plugin wants to handle the request // Check if any plugin wants to handle the request
if (!$pluginManager->handlePageAction($page)) { if (!$pluginManager->handlePageAction($page)) {
// If no plugin is available fall back to core page action handlers // 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 string $page
* @param array $extraFooterScripts * @param array $extraFooterScripts
* @param object $token
* @return void * @return void
*/ */
function handleCorePageAction(string $page, array &$extraFooterScripts): void function handleCorePageAction(string $page, array &$extraFooterScripts, object $token): void
{ {
switch ($page) { switch ($page) {
case "/wlan0_info": case "/wlan0_info":
DisplayDashboard($extraFooterScripts); DisplayDashboard($extraFooterScripts, $token);
break; break;
case "/dhcpd_conf": case "/dhcpd_conf":
DisplayDHCPConfig(); DisplayDHCPConfig($token);
break; break;
case "/wpa_conf": case "/wpa_conf":
DisplayWPAConfig(); DisplayWPAConfig($token);
break; break;
case "/network_conf": case "/network_conf":
DisplayNetworkingConfig(); DisplayNetworkingConfig($token);
break; break;
case "/hostapd_conf": case "/hostapd_conf":
DisplayHostAPDConfig(); DisplayHostAPDConfig($token);
break; break;
case "/adblock_conf": case "/adblock_conf":
DisplayAdBlockConfig(); DisplayAdBlockConfig($token);
break; break;
case "/openvpn_conf": case "/openvpn_conf":
DisplayOpenVPNConfig(); DisplayOpenVPNConfig($token);
break; break;
case "/wg_conf": case "/wg_conf":
DisplayWireGuardConfig(); DisplayWireGuardConfig($token);
break; break;
case "/provider_conf": case "/provider_conf":
DisplayProviderConfig(); DisplayProviderConfig($token);
break; break;
case "/torproxy_conf": case "/torproxy_conf":
DisplayTorProxyConfig(); DisplayTorProxyConfig($token);
break; break;
case "/auth_conf": case "/auth_conf":
DisplayAuthConfig($_SESSION['user_id']); DisplayAuthConfig($_SESSION['user_id'], $token);
break; break;
case "/save_hostapd_conf": case "/save_hostapd_conf":
SaveTORAndVPNConfig(); SaveTORAndVPNConfig($token);
break; break;
case "/data_use": case "/data_use":
DisplayDataUsage($extraFooterScripts); DisplayDataUsage($extraFooterScripts, $token);
break; break;
case "/system_info": case "/system_info":
DisplaySystem($extraFooterScripts); DisplaySystem($extraFooterScripts, $token);
break; break;
case "/restapi_conf": case "/restapi_conf":
DisplayRestAPI(); DisplayRestAPI($token);
break; break;
case "/about": case "/about":
DisplayAbout(); DisplayAbout($token);
break; break;
case "/login": case "/login":
DisplayLogin(); DisplayLogin($token);
break; break;
default: default:
DisplayDashboard($extraFooterScripts); DisplayDashboard($extraFooterScripts, $token);
} }
} }

View File

@ -6,7 +6,7 @@ require_once 'config.php';
/** /**
* Handler for RestAPI settings * Handler for RestAPI settings
*/ */
function DisplayRestAPI() function DisplayRestAPI($token)
{ {
// initialize status object // initialize status object
$status = new \RaspAP\Messages\StatusMessage; $status = new \RaspAP\Messages\StatusMessage;
@ -59,13 +59,16 @@ function DisplayRestAPI()
$docMsg = sprintf(_("RestAPI docs are accessible <a href=\"%s\" target=\"_blank\">here %s</a>"),$docUrl, $faicon); $docMsg = sprintf(_("RestAPI docs are accessible <a href=\"%s\" target=\"_blank\">here %s</a>"),$docUrl, $faicon);
} }
echo renderTemplate("restapi", compact( echo renderTemplate(
"status", "restapi", compact(
"apiKey", "status",
"serviceStatus", "apiKey",
"serviceLog", "serviceStatus",
"docMsg" "serviceLog",
)); "docMsg",
"token"
)
);
} }
/** /**

View File

@ -6,7 +6,7 @@ require_once 'config.php';
/** /**
* *
*/ */
function DisplaySystem(&$extraFooterScripts) function DisplaySystem(&$extraFooterScripts, $token)
{ {
$status = new \RaspAP\Messages\StatusMessage; $status = new \RaspAP\Messages\StatusMessage;
$dashboard = new \RaspAP\UI\Dashboard; $dashboard = new \RaspAP\UI\Dashboard;
@ -146,7 +146,8 @@ function DisplaySystem(&$extraFooterScripts)
"themes", "themes",
"selectedTheme", "selectedTheme",
"logLimit", "logLimit",
"pluginsTable" "pluginsTable",
"token"
)); ));
} }

View File

@ -5,7 +5,7 @@ require_once 'config.php';
/** /**
* Displays wireguard server & peer configuration * Displays wireguard server & peer configuration
*/ */
function DisplayWireGuardConfig() function DisplayWireGuardConfig($token)
{ {
$status = new \RaspAP\Messages\StatusMessage; $status = new \RaspAP\Messages\StatusMessage;
$parseFlag = true; $parseFlag = true;
@ -98,7 +98,8 @@ function DisplayWireGuardConfig()
"wg_pendpoint", "wg_pendpoint",
"wg_pallowedips", "wg_pallowedips",
"wg_pkeepalive", "wg_pkeepalive",
"wg_log" "wg_log",
"token"
) )
); );
} }