mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
122 lines
3.3 KiB
PHP
Executable File
122 lines
3.3 KiB
PHP
Executable File
<?php
|
|
//------------------------------------------------------------------------------
|
|
// Pi.Alert
|
|
// Open Source Network Guard / WIFI & LAN intrusion detector
|
|
//
|
|
// parameters.php - Front module. Server side. Manage Parameters
|
|
//------------------------------------------------------------------------------
|
|
# Puche 2021 / 2022+ jokob jokob@duck.com GNU GPLv3
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
// External files
|
|
require 'db.php';
|
|
require 'util.php';
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Action selector
|
|
//------------------------------------------------------------------------------
|
|
// Set maximum execution time to 15 seconds
|
|
ini_set ('max_execution_time','15');
|
|
|
|
$skipCache = FALSE;
|
|
|
|
if (isset ($_REQUEST['skipcache'])) {
|
|
$skipCache = TRUE;
|
|
}
|
|
|
|
// Action functions
|
|
if (isset ($_REQUEST['action']) && !empty ($_REQUEST['action'])) {
|
|
$action = $_REQUEST['action'];
|
|
switch ($action) {
|
|
case 'get': getParameter($skipCache); break;
|
|
case 'set': setParameter(); break;
|
|
default: logServerConsole ('Action: '. $action); break;
|
|
}
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Get Parameter Value
|
|
//------------------------------------------------------------------------------
|
|
function getParameter($skipCache) {
|
|
|
|
$parameter = $_REQUEST['parameter'];
|
|
$value = "";
|
|
|
|
// get the value from the cookie if available
|
|
if(getCache($parameter) != "")
|
|
{
|
|
$value = getCache($parameter);
|
|
}
|
|
|
|
// query the database if no cache entry found or requesting live data for the Back_App_State in the header
|
|
if($skipCache || $value == "" )
|
|
{
|
|
global $db;
|
|
|
|
$sql = 'SELECT par_Value FROM Parameters
|
|
WHERE par_ID="'. quotes($parameter) .'"';
|
|
|
|
$result = $db->query($sql);
|
|
$row = $result -> fetchArray (SQLITE3_NUM);
|
|
$value = $row[0];
|
|
|
|
// Commit DB
|
|
CommitDB();
|
|
|
|
// update cookie cache
|
|
setCache($parameter, $value);
|
|
}
|
|
// return value
|
|
echo (json_encode ($value));
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Set Parameter Value
|
|
//------------------------------------------------------------------------------
|
|
function setParameter() {
|
|
|
|
$parameter = $_REQUEST['parameter'];
|
|
$value = $_REQUEST['value'];
|
|
|
|
global $db;
|
|
|
|
// Update value
|
|
$sql = 'UPDATE Parameters SET par_Value="'. quotes ($value) .'"
|
|
WHERE par_ID="'. quotes($parameter) .'"';
|
|
$result = $db->query($sql);
|
|
|
|
if (! $result == TRUE) {
|
|
echo "Error updating parameter\n\n$sql \n\n". $db->lastErrorMsg();
|
|
return;
|
|
}
|
|
|
|
$changes = $db->changes();
|
|
if ($changes == 0) {
|
|
// Insert new value
|
|
$sql = 'INSERT INTO Parameters (par_ID, par_Value)
|
|
VALUES ("'. quotes($parameter) .'",
|
|
"'. quotes($value) .'")';
|
|
$result = $db->query($sql);
|
|
|
|
if (! $result == TRUE) {
|
|
echo "Error creating parameter\n\n$sql \n\n". $db->lastErrorMsg();
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Commit DB
|
|
CommitDB();
|
|
|
|
// update cookie cache
|
|
setCache($parameter, $value);
|
|
|
|
echo 'OK';
|
|
}
|
|
|
|
?>
|