$values) { // UnBreak special cases $section = str_replace("_", " ", $section); $content .= "[".$section."]\n"; //append the values foreach($values as $key=>$value) { if ($value == '') { $content .= $key."=".$value." \n"; } else { $content .= $key."=".$value."\n"; } } } // write it into file if (!$handle = fopen($filepath, 'w')) { return false; } $success = fwrite($handle, $content); fclose($handle); // /etc/starnetserver is a FLAT key=value file on disk — the // synthetic [starnetserver] header is injected only for // parse_ini_file()'s benefit. Strip it via PHP and install // the cleaned content directly (L-7: drops sudo sed -i; // L-5: collapses cp + chmod + chown into one atomic install). // See edit_ircddbgateway.php for the full rationale. $etcContent = preg_replace('/^\[starnetserver\]\r?\n/m', '', $content); // A3-3: per-request random staging — see edit_ircddbgateway.php $etcStaging = tempnam('/tmp', 'pistar-edit-etc-'); file_put_contents($etcStaging, $etcContent); exec('sudo mount -o remount,rw /'); exec('sudo install -m 644 -o root -g root ' . escapeshellarg($etcStaging) . ' /etc/starnetserver'); exec('sudo mount -o remount,ro /'); @unlink($etcStaging); // Reload the affected daemon so the saved edits take effect // without a manual restart. Was commented out historically; // restored so behaviour matches the other edit_*.php files. exec('sudo systemctl restart starnetserver.service'); // Reload the daemon 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) { // keep the section as hidden text so we can update once the form submitted // INI section / key / value all come from the underlying // /etc/ file. Same hardening as edit_mmdvmhost.php // (#23): htmlspecialchars(ENT_QUOTES) on display so a value // with a literal `"` or `<` (e.g. an Options string) can't // break out of the `value="…"` attribute. The save handler // writes the POST bytes verbatim, so legitimate quoted // values round-trip byte-identically. $sectionHtml = htmlspecialchars((string)$section, ENT_QUOTES, 'UTF-8'); 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'); echo "\n"; } echo "
$sectionHtml
$keyHtml
\n"; echo ''."\n"; echo "
\n"; } echo ""; ?>