2024-08-12 11:12:24 +00:00
|
|
|
<?php
|
|
|
|
|
2024-12-04 10:13:33 +00:00
|
|
|
/**
|
2025-01-23 10:42:27 +00:00
|
|
|
* Config management.
|
2024-12-04 10:13:33 +00:00
|
|
|
*
|
2025-01-23 10:42:27 +00:00
|
|
|
* This page handles the config file.
|
2024-12-04 10:13:33 +00:00
|
|
|
*/
|
|
|
|
|
2025-01-13 08:45:31 +00:00
|
|
|
// Get any new messages
|
|
|
|
include '../app/includes/messages.php';
|
|
|
|
include '../app/includes/messages-show.php';
|
|
|
|
|
2024-09-04 09:53:02 +00:00
|
|
|
require '../app/classes/config.php';
|
2024-08-18 19:12:45 +00:00
|
|
|
|
2024-09-06 16:34:03 +00:00
|
|
|
$configObject = new Config();
|
2024-08-18 19:12:45 +00:00
|
|
|
|
2025-01-23 10:42:27 +00:00
|
|
|
// For AJAX requests
|
|
|
|
$isAjax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
|
|
|
|
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
|
|
|
|
|
2025-01-23 12:06:36 +00:00
|
|
|
// Check if file is writable
|
|
|
|
$isWritable = is_writable($config_file);
|
|
|
|
$configMessage = '';
|
|
|
|
if (!$isWritable) {
|
|
|
|
$configMessage = Messages::render('ERROR', 'DEFAULT', 'Config file is not writable', false);
|
|
|
|
}
|
|
|
|
|
2025-01-23 10:42:27 +00:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
// Ensure no output before this point
|
|
|
|
ob_clean();
|
|
|
|
|
|
|
|
// For AJAX requests, get JSON data
|
|
|
|
if ($isAjax) {
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
// Get raw input
|
|
|
|
$jsonData = file_get_contents('php://input');
|
|
|
|
$postData = json_decode($jsonData, true);
|
|
|
|
|
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
|
Messages::flash('ERROR', 'DEFAULT', 'Invalid JSON data received', true);
|
|
|
|
echo json_encode([
|
|
|
|
'success' => false,
|
|
|
|
'message' => 'Invalid JSON data received'
|
|
|
|
]);
|
|
|
|
exit;
|
2024-11-01 16:23:40 +00:00
|
|
|
}
|
|
|
|
|
2025-01-23 10:42:27 +00:00
|
|
|
// Try to update config file
|
|
|
|
$result = $configObject->editConfigFile($postData, $config_file);
|
|
|
|
if ($result === true) {
|
|
|
|
$messageData = Messages::getMessageData('NOTICE', 'DEFAULT', 'Config file updated successfully', true);
|
|
|
|
echo json_encode([
|
|
|
|
'success' => true,
|
|
|
|
'message' => 'Config file updated successfully',
|
|
|
|
'messageData' => $messageData
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$messageData = Messages::getMessageData('ERROR', 'DEFAULT', "Error updating config file: $result", true);
|
|
|
|
echo json_encode([
|
|
|
|
'success' => false,
|
|
|
|
'message' => "Error updating config file: $result",
|
|
|
|
'messageData' => $messageData
|
|
|
|
]);
|
2024-09-22 09:26:19 +00:00
|
|
|
}
|
2025-01-22 20:52:50 +00:00
|
|
|
exit;
|
2025-01-23 10:42:27 +00:00
|
|
|
}
|
2024-09-22 09:26:19 +00:00
|
|
|
|
2025-01-23 10:42:27 +00:00
|
|
|
// Handle non-AJAX POST
|
2025-01-23 12:06:36 +00:00
|
|
|
$result = $configObject->editConfigFile($_POST, $config_file);
|
|
|
|
if ($result === true) {
|
|
|
|
Messages::flash('NOTICE', 'DEFAULT', 'Config file updated successfully', true);
|
2025-01-23 10:42:27 +00:00
|
|
|
} else {
|
2025-01-23 12:06:36 +00:00
|
|
|
Messages::flash('ERROR', 'DEFAULT', "Error updating config file: $result", true);
|
2024-08-19 10:25:09 +00:00
|
|
|
}
|
|
|
|
|
2025-01-23 10:42:27 +00:00
|
|
|
header('Location: ' . htmlspecialchars($app_root) . '?page=config');
|
|
|
|
exit;
|
2024-08-18 19:12:45 +00:00
|
|
|
}
|
2024-08-12 11:12:24 +00:00
|
|
|
|
2025-01-23 10:42:27 +00:00
|
|
|
// Only include template for non-AJAX requests
|
|
|
|
if (!$isAjax) {
|
|
|
|
include '../app/templates/config.php';
|
|
|
|
}
|
2024-08-12 11:12:24 +00:00
|
|
|
?>
|