From c245bbb3be4a2251959b62cfe610f594bd771862 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Wed, 6 Nov 2024 18:39:51 +0200 Subject: [PATCH] Adds check if config file is writable --- app/pages/config.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/pages/config.php b/app/pages/config.php index 75d715b..709d288 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -17,11 +17,16 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { // editing the config file if (isset($_POST['item']) && $_POST['item'] === 'config_file') { - $result = $configObject->editConfigFile($_POST, $config_file); - if ($result === true) { - $_SESSION['notice'] = "The config file is edited."; + // check if file is writable + if (!is_writable($config_file)) { + $_SESSION['error'] = "Configuration file is not writable."; } else { - $_SESSION['error'] = "Editing the config file failed. Error: $result"; + $result = $configObject->editConfigFile($_POST, $config_file); + if ($result === true) { + $_SESSION['notice'] = "The config file is edited."; + } else { + $_SESSION['error'] = "Editing the config file failed. Error: $result"; + } } // new host adding @@ -144,14 +149,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { } -// FIXME - if this is not needed for editing the flat file, remove it -// // check if file is writable -// if (!is_writable($config_file)) { -// $_SESSION['error'] = getError('Configuration file is not writable.'); -// header("Location: $app_root?platform=$platform_id&page=config"); -// exit(); -// } - // FIXME the new file is not loaded on first page load unset($config); header("Location: $app_root?page=config&item=$item");