$values) { // UnBreak special cases $section = str_replace("_", " ", $section); $content .= "[".$section."]\n"; //append the values foreach($values as $key=>$value) { // Strip CR/LF from values before they land in the INI // file. The save handler writes `$key=$value\n` and a // newline inside $value would split the value into a // new INI line, allowing injection of arbitrary // additional keys (e.g. `value=foo\nDEBUG=1`). On a // single-operator device the practical risk is low // but the sanitiser is one line. $value = str_replace(array("\r", "\n"), "", (string)$value); $content .= $key."=".$value."\n"; } $content .= "\n"; } //write it into file if (!$handle = fopen($filepath, 'w')) { return false; } $success = fwrite($handle, $content); fclose($handle); // Atomic install: mode + owner set in one syscall sequence. // /etc/dapnetapi.key holds DAPNET credentials — mode 600 keeps // them readable only by www-data. Owner left as www-data // because the dapnetgateway daemon reads via the dashboard // (and dashboard reads it directly without sudo elsewhere); // see fulledit_bmapikey.php for the same rationale. exec('sudo mount -o remount,rw /'); exec('sudo install -m 600 -o www-data -g www-data ' . escapeshellarg($filepath) . ' /etc/dapnetapi.key'); exec('sudo mount -o remount,ro /'); return $success; } //parse the ini file using default parse_ini_file() PHP function $parsed_ini = parse_ini_file($filepath, true); echo '
'."\n"; echo csrf_field_html()."\n"; foreach($parsed_ini as $section=>$values) { // Same hardening as edit_mmdvmhost.php (#23): escape every INI // section / key / value before HTML interpolation. The save // handler writes POST bytes verbatim so legitimate values // (including any with `"` or `<`) round-trip byte-identically. $sectionHtml = htmlspecialchars((string)$section, ENT_QUOTES, 'UTF-8'); // keep the section as hidden text so we can update once the form submitted echo "\n"; echo "\n"; echo "\n"; // print all other values as input fields, so can edit. // note the name='' attribute it has both section and key foreach($values as $key=>$value) { $keyHtml = htmlspecialchars((string)$key, ENT_QUOTES, 'UTF-8'); $valueHtml = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); if (($key == "Options") || ($value)) { echo "\n"; } elseif (($key == "Display") && ($value == '')) { echo "\n"; } else { echo "\n"; } } echo "
$sectionHtml
$keyHtml
$keyHtml
$keyHtml
\n"; echo ''."\n"; echo "
\n"; } echo "
"; ?>