$values) {
// UnBreak special cases
$section = str_replace("_", " ", $section);
$content .= "[".$section."]\n";
//append the values
foreach($values as $key=>$value) {
if ($value == '') {
$content .= $key."= \n";
}
else {
$content .= $key."=".$value."\n";
}
}
}
// write it into file
if (!$handle = fopen($filepath, 'w')) {
return false;
}
$success = fwrite($handle, $content);
fclose($handle);
// /etc/dstarrepeater is a FLAT key=value file on disk — the
// synthetic [dstarrepeater] 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('/^\[dstarrepeater\]\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/dstarrepeater');
exec('sudo mount -o remount,ro /');
@unlink($etcStaging);
// Reload the affected daemon
exec('sudo systemctl restart dstarrepeater.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 '
";
?>