\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Factory Reset NOT performed
Server-side confirmation did not match. Factory reset cancelled.
\n"; unset($_POST); } else { echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Factory Reset Config
Loading fresh configuration file(s)...
\n"; unset($_POST); //Reset the config exec('sudo mount -o remount,rw /'); // Make rootfs writable exec('sudo rm -rf /etc/pistar-css.ini'); // Delete the Config exec('sudo mount -o remount,ro /'); // Make rootfs read-only echo ''; die(); } } else { //update ini file, call function update_ini_file($data, $filepath); } } //this is the function going to update your ini file function update_ini_file($data, $filepath) { $content = ""; //parse the ini file to get the sections //parse the ini file using default parse_ini_file() PHP function $parsed_ini = parse_ini_file($filepath, true); foreach($data as $section=>$values) { // UnBreak special cases $section = str_replace("_", " ", $section); $section = str_replace("BannerH2", "BannerH1", $section); $content .= "[".$section."]\n"; //append the values foreach($values as $key=>$value) { if ($value == '') { $content .= $key."=none\n"; } else { $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 — see the matching block earlier in this // file for the rationale. Single sudo call, content + mode // + owner all set together; no transient state on disk. // $filepath here is the function parameter, which is the // same per-request tempnam path created at file-top (A3-3). exec('sudo mount -o remount,rw /'); exec('sudo install -m 644 -o root -g root ' . escapeshellarg($filepath) . ' /etc/pistar-css.ini'); 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); if (isset($parsed_ini['Lookup']['popupWidth'])) { unset($parsed_ini['Lookup']['popupWidth']); } if (isset($parsed_ini['Lookup']['popupHeight'])) { unset($parsed_ini['Lookup']['popupHeight']); } 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 ( $section == "Lookup" && $key == "Service" ) { echo "\n"; } else { echo "\n"; } } echo "
$sectionHtml
$keyHtml\n"; echo " \n"; echo "
$keyHtml
\n"; echo ''."\n"; echo "

\n"; } echo "
"; echo "
\n"; echo 'if you took it all too far and now it makes you feel sick, click below to reset the changes made on this page, this will ONLY reset the CSS settings above and will not change any other settings or configuration.'."\n"; echo '
'."\n"; echo csrf_field_html()."\n"; echo '
'."\n"; // Server-side confirmation. JS factoryReset() prompts for the // magic word and only populates this input on a match. The // handler requires factoryResetConfirm === 'RESET' before doing // the wipe — closes the "valid CSRF token + accidental replay" // attack class. echo '
'."\n"; echo '
'."\n"; echo ''."\n"; ?>