/tmp/d39fk36sg55433gd.tmp');
exec('sudo echo "apikey=None" >> /tmp/d39fk36sg55433gd.tmp');
}
exec('sudo chown www-data:www-data /tmp/d39fk36sg55433gd.tmp');
exec('sudo chmod 664 /tmp/d39fk36sg55433gd.tmp');
//ini file to open
$filepath = '/tmp/d39fk36sg55433gd.tmp';
//after the form submit
if($_POST) {
$data = $_POST;
//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 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);
$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);
// Updates complete - copy the working file back to the proper location
exec('sudo mount -o remount,rw /'); // Make rootfs writable
exec('sudo mv /tmp/d39fk36sg55433gd.tmp /etc/bmapi.key'); // Move the file back
exec('sudo chmod 644 /etc/bmapi.key'); // Set the correct runtime permissions
exec('sudo chown root:root /etc/bmapi.key'); // Set the owner
exec('sudo mount -o remount,ro /'); // Make rootfs read-only
return $success;
}
//parse the ini file using default parse_ini_file() PHP function
$parsed_ini = parse_ini_file($filepath, true);
if (!isset($parsed_ini['key']['apikey'])) { $parsed_ini['key']['apikey'] = ""; }
echo '
";
?>