BE+FE: report findinfg fixes + css

This commit is contained in:
jokob-sk
2026-07-12 10:26:53 +10:00
parent 3aa7bc5538
commit 1636d155c7
11 changed files with 238 additions and 87 deletions

View File

@@ -4,62 +4,71 @@
//------------------------------------------------------------------------------
// Check if authenticated
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/security.php';
// Get init.php
require dirname(__FILE__).'/../server/init.php';
// Get init.php
require dirname(__FILE__) . '/../server/init.php';
// ---- IMPORTS ----
header('Content-Type: text/plain; charset=utf-8');
global $configFolderPath;
//------------------------------------------------------------------------------
// Handle incoming requests
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Access the 'config' parameter from the POST request
$base64Data = $_POST['base64data'] ?? null;
if (!$base64Data) {
$msg = "Missing 'base64data' parameter.";
echo $msg;
http_response_code(400); // Bad request
die($msg);
http_response_code(400);
die("Missing 'base64data' parameter.");
}
$fileName = $_POST['fileName'] ?? null;
if (!$fileName) {
$msg = "Missing 'fileName' parameter.";
echo $msg;
http_response_code(400); // Bad request
die($msg);
http_response_code(400);
die("Missing 'fileName' parameter.");
}
//--------------------------------------------------------------------------
// Only allow known configuration files
$safeName = basename($fileName);
$allowedFiles = [
'app.conf',
'workflows.json',
'devices.csv',
];
if (!in_array($safeName, $allowedFiles, true)) {
http_response_code(400);
die("Invalid fileName.");
}
$fullPath = rtrim($configFolderPath, DIRECTORY_SEPARATOR)
. DIRECTORY_SEPARATOR
. $safeName;
//--------------------------------------------------------------------------
// Decode incoming base64 data
$input = base64_decode($base64Data, true);
if ($input === false) {
$msg = "Invalid base64 data.";
echo $msg;
http_response_code(400); // Bad request
die($msg);
http_response_code(400);
die("Invalid base64 data.");
}
$fullPath = $configFolderPath.$fileName;
//--------------------------------------------------------------------------
// Backup the original file
if (file_exists($fullPath)) {
copy($fullPath, $fullPath . ".bak");
}
//--------------------------------------------------------------------------
// Write the new configuration
$file = fopen($fullPath, "w");
if (!$file) {
$msg = "Unable to open file: ". $fullPath;
echo $msg;
http_response_code(500); // Server error
die($msg);
if (file_put_contents($fullPath, $input, LOCK_EX) === false) {
http_response_code(500);
die("Unable to save configuration file.");
}
fwrite($file, $input);
fclose($file);
echo "Configuration file saved successfully: " .$fileName ;
}
?>
echo "Configuration file saved successfully: " . $safeName;
}