I have a script that takes form input data and writes it back to ifcfg-eth0 with no problem but, I cannot see (though I confess I am no PHP code-monkey
When I write the file back using the code below and reboot the server, the system cannot read the file and looking at it in Webmin I get a message indicating that the filename has invalid characters!!!???.
However, if I simply vi the file and :set ff=unix, save and quit and then reboot the server, the config file works fine so I am thinkin' it's a file format issue. (The byte size of the file changes if I do the ff thing, it reduces by circa 6 so it's stripping something out)
Code below
Code: Select all
$fn = "/etc/sysconfig/network-scripts/ifcfg-eth0";
//--------------------------------------------------
// Removes backslashes
//--------------------------------------------------
$content = stripslashes($_POST['content']);
//--------------------------------------------------
// Removes trailing linespace
//--------------------------------------------------
$content = trim($content);
//--------------------------------------------------
//Open the file for writing, zero content the file
//--------------------------------------------------
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
//--------------------------------------------------
// Then write the new sanitized content
//--------------------------------------------------
fwrite($fp,$content);
//--------------------------------------------------
// Then close the file
//----------------------------------------------
fclose($fp) or die ("Error closing file!");