This commit is contained in:
jokob-sk
2025-03-27 21:23:11 +11:00
parent e996c9eccc
commit 7e5373b2cd
16 changed files with 144 additions and 131 deletions

View File

@@ -1,6 +1,6 @@
<?php
ini_set('error_log', '../../log/app.php_errors.log'); // initializing the app.php_errors.log file for the maintenance section
require dirname(__FILE__).'/../templates/timezone.php';
require dirname(__FILE__).'/../templates/globals.php';
require dirname(__FILE__).'/db.php';
require dirname(__FILE__).'/util.php';
require dirname(__FILE__).'/../templates/language/lang.php';

View File

@@ -13,21 +13,23 @@ require dirname(__FILE__).'/../server/init.php';
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// Get query string parameters ?file=settings_table.json&download=true
$file = isset($_GET['file']) ? $_GET['file'] : null;
$download = isset($_GET['download']) ? $_GET['download'] === 'true' : false;
$download = isset($_GET['download']) && $_GET['download'] === 'true';
// Check if file parameter is provided
if ($file) {
// Define the folder where files are located
$filePath = "/app/config/" . basename($file);
// Check if the file exists
if (file_exists($filePath)) {
// Handle download behavior
// Check if the file exists and is readable
if (file_exists($filePath) && is_readable($filePath)) {
// Determine file extension
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
if ($download) {
// Force file download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
@@ -35,19 +37,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
readfile($filePath);
exit;
} else {
// Display file content
header('Content-Type: text/plain');
echo file_get_contents($filePath);
// Serve file based on type
if ($extension === 'json') {
header('Content-Type: application/json');
echo json_encode(json_decode(file_get_contents($filePath), true), JSON_PRETTY_PRINT);
} else {
header('Content-Type: text/plain');
echo file_get_contents($filePath);
}
exit;
}
} else {
// File not found response
http_response_code(404);
header('Content-Type: application/json');
echo json_encode(["error" => "File not found"]);
exit;
}
} else {
// Missing file parameter response
http_response_code(400);
header('Content-Type: application/json');
echo json_encode(["error" => "Missing 'file' parameter"]);
exit;
}
}
?>

View File

@@ -8,16 +8,24 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/security.php';
require dirname(__FILE__).'/../server/init.php';
// ---- IMPORTS ----
global $fullConfPath;
global $configFolderPath;
//------------------------------------------------------------------------------
// Handle incoming requests
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Access the 'config' parameter from the POST request
$base64Data = $_POST['config'] ?? null;
$base64Data = $_POST['base64data'] ?? null;
if (!$base64Data) {
$msg = "Missing 'config' parameter.";
$msg = "Missing 'base64data' parameter.";
echo $msg;
http_response_code(400); // Bad request
die($msg);
}
$fileName = $_POST['fileName'] ?? null;
if (!$fileName) {
$msg = "Missing 'fileName' parameter.";
echo $msg;
http_response_code(400); // Bad request
die($msg);
@@ -33,15 +41,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
die($msg);
}
$fullPath = $configFolderPath.$fileName;
// Backup the original file
if (file_exists($fullConfPath)) {
copy($fullConfPath, $fullConfPath . ".bak");
if (file_exists($fullPath)) {
copy($fullPath, $fullPath . ".bak");
}
// Write the new configuration
$file = fopen($fullConfPath, "w");
$file = fopen($fullPath, "w");
if (!$file) {
$msg = "Unable to open file!";
$msg = "Unable to open file: ". $fullPath;
echo $msg;
http_response_code(500); // Server error
die($msg);
@@ -50,6 +60,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
fwrite($file, $input);
fclose($file);
echo "Configuration saved successfully.";
echo "Configuration file saved successfully: " .$fileName ;
}
?>

View File

@@ -8,7 +8,7 @@
# Puche 2021 / 2022+ jokob jokob@duck.com GNU GPLv3
//------------------------------------------------------------------------------
require dirname(__FILE__).'/../templates/timezone.php';
require dirname(__FILE__).'/../templates/globals.php';
require dirname(__FILE__).'/../templates/skinUI.php';
//------------------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
<?php
require dirname(__FILE__).'/../templates/timezone.php';
require dirname(__FILE__).'/../templates/globals.php';
//------------------------------------------------------------------------------
// check if authenticated