From ee90e2b9974ec820b17ec64973eea8b7855e8164 Mon Sep 17 00:00:00 2001 From: dlandon Date: Wed, 14 Feb 2024 16:15:43 -0600 Subject: [PATCH] Add #raw_file so a raw file can be modified and suppress any php warnings: This is the hidden input value: The value="true" could be programmatically changed so a file can be parsed or not parsed in the same page code. --- emhttp/update.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/emhttp/update.php b/emhttp/update.php index c16b7c3eb..ab50d28cf 100644 --- a/emhttp/update.php +++ b/emhttp/update.php @@ -43,12 +43,20 @@ flush(); $docroot = $_SERVER['DOCUMENT_ROOT']; if (isset($_POST['#file'])) { $file = $_POST['#file']; + $raw_file = isset($_POST['#raw_file']) ? ($_POST['#raw_file'] === 'true') : false; // prepend with boot (flash) if path is relative if ($file && $file[0]!='/') $file = "/boot/config/plugins/$file"; $section = $_POST['#section'] ?? false; $cleanup = isset($_POST['#cleanup']); $default = ($file && isset($_POST['#default'])) ? @parse_ini_file("$docroot/plugins/".basename(dirname($file))."/default.cfg", $section) : []; + // if the file is not a raw file, it can be parsed + if (! $raw_file) { + $keys = is_file($file) ? (parse_ini_file($file, $section) ?: []) : []; + } else { + $keys = []; + } + // the 'save' switch can be reset by the include file to disallow settings saving $save = true; if (isset($_POST['#include'])) { @@ -60,7 +68,6 @@ if (isset($_POST['#file'])) { } if ($save) { $text = ""; - $keys = is_file($file) ? (parse_ini_file($file, $section) ?: []) : []; if ($section) { foreach ($_POST as $key => $value) if ($key[0]!='#') $keys[$section][$key] = $default[$section][$key] ?? $value; foreach ($keys as $section => $block) {