1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2025-07-30 22:49:26 +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
*/
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'
)
);
}

View File

@ -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"
)
);
}

View File

@ -1,6 +1,6 @@
<?php
function DisplayAuthConfig($username)
function DisplayAuthConfig($username, $token)
{
$status = new \RaspAP\Messages\StatusMessage;
$auth = new \RaspAP\Auth\HTTPAuth;
@ -42,7 +42,8 @@ function DisplayAuthConfig($username)
echo renderTemplate(
"admin", compact(
"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;
$networks = [];
@ -148,5 +148,12 @@ function DisplayWPAConfig()
preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState) || $matchesState[1] = 'unknown';
$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
*/
function DisplayDashboard(&$extraFooterScripts): void
function DisplayDashboard(&$extraFooterScripts, $token): void
{
// instantiate RaspAP objects
$system = new \RaspAP\System\Sysinfo;
@ -74,9 +74,7 @@ function DisplayDashboard(&$extraFooterScripts): void
$varName = "freq" . str_replace('.', '', $frequency) . "active";
$$varName = "active";
$vpnStatus = $vpn ? "active" : "inactive";
if ($vpn) {
$vpnManaged = $dashboard->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);

View File

@ -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"
)
);
}

View File

@ -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"
)
);
}

View File

@ -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"
)
);
}

View File

@ -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"
)
);
}

View File

@ -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);
}
}

View File

@ -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 <a href=\"%s\" target=\"_blank\">here %s</a>"),$docUrl, $faicon);
}
echo renderTemplate("restapi", compact(
"status",
"apiKey",
"serviceStatus",
"serviceLog",
"docMsg"
));
echo renderTemplate(
"restapi", compact(
"status",
"apiKey",
"serviceStatus",
"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;
$dashboard = new \RaspAP\UI\Dashboard;
@ -146,7 +146,8 @@ function DisplaySystem(&$extraFooterScripts)
"themes",
"selectedTheme",
"logLimit",
"pluginsTable"
"pluginsTable",
"token"
));
}

View File

@ -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"
)
);
}