$values) { // UnBreak special cases if (strpos($section, 'aprs') !== false) { $section = str_replace("_", ".", $section); } else { $section = str_replace("_", " ", $section); $section = str_replace(".", " ", $section); } $content .= "[".$section."]\n"; //append the values foreach($values as $key=>$value) { $content .= $key."=".$value."\n"; } $content .= "\n"; } // write it into file if (!$handle = fopen($filepath, 'w')) { return false; } $success = fwrite($handle, $content); fclose($handle); // Updates complete - copy the working file back to the proper location exec('sudo mount -o remount,rw /'); // Make rootfs writable exec('sudo cp /tmp/aFEds45dgs4tFS.tmp /etc/nxdngateway'); // Move the file back exec('sudo chmod 644 /etc/nxdngateway'); // Set the correct runtime permissions exec('sudo chown root:root /etc/nxdngateway'); // Set the owner exec('sudo mount -o remount,ro /'); // Make rootfs read-only // Reload the affected daemon exec('sudo systemctl restart nxdngateway.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"; foreach($parsed_ini as $section=>$values) { // keep the section as hidden text so we can update once the form submitted echo "\n"; echo "
\n"; echo "

$section

\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) { echo "
$key
\n"; } echo "
\n"; echo '
'."\n"; } echo "
"; ?>