diff --git a/app/classes/config.php b/app/classes/config.php index 14c8e87..5db59fd 100644 --- a/app/classes/config.php +++ b/app/classes/config.php @@ -2,6 +2,35 @@ class Config { + // edit the config file + public function editConfigFile($updatedConfig) { + // first we get a fresh config file contents as text + $config_contents = file_get_contents($config_file); + if (!$config_contents) { + return "Failed to read the config file \"$config_file\"."; + } + + // loop through the variables and updated them + foreach ($updatedConfig as $key => $newValue) { + // we look for 'option' => value + // option is always in single quotes + // value is without quotes, because it could be true/false + $patterm = "/(['\"]{$key}['\"]\s*=>\s*)([^,]+),/" + + // prepare the value and replace it + $replacementValue = var_export($newValue, true); + $config_contents = preg_replace($pattern, "$1{$replacementValue},", $config_contents); + } + + // write the new config file + if (!file_put_contents($config_file, $config_contents)) { + return "Failed to write the config file \"$config_file\"."; + } + + return true; + } + + // loading the config.js public function getPlatformConfigjs($jitsiUrl, $raw = false) { // constructing the URL diff --git a/app/pages/config.php b/app/pages/config.php index 5b9e727..f16c577 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -20,8 +20,17 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { // $content = file_get_contents($config_file); // $updatedContent = $content; + // editing the config file + if (isset($_POST['item']) && $_POST['item'] === 'config_file') { + $result = $configObject->editConfigFile($_POST); + if ($result === true) { + $_SESSION['notice'] = "The config file is edited."; + } else { + $_SESSION['error'] = "Editing the config file failed. Error: $result"; + } + // new host adding - if (isset($_POST['new']) && isset($_POST['item']) && $_POST['new'] === 'true' && $_POST['item'] === 'host') { + } elseif (isset($_POST['new']) && isset($_POST['item']) && $_POST['new'] === 'true' && $_POST['item'] === 'host') { $newHost = [ 'address' => $address, 'port' => $port, diff --git a/app/templates/config-configfile-edit.php b/app/templates/config-configfile-edit.php index e54f548..97cd390 100644 --- a/app/templates/config-configfile-edit.php +++ b/app/templates/config-configfile-edit.php @@ -6,7 +6,7 @@

this may break everything, use with extreme caution

-
+

this may break everything, use with extreme caution

+
+ Cancel   
-