Page 1 of 1

OK, I cannot see for looking :(

Posted: Mon Dec 04, 2006 7:09 am
by LOFer
Probably something real simple but I could do with some input here.

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 :roll: ) how I can get the file to be written back in unix format.

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!");
Hope it makes sense and apologies for the n00b question!

Posted: Mon Dec 04, 2006 7:13 am
by volka
Maybe because of different linebreaks.

Code: Select all

$content = str_replace("\r\n", "\n", $content);

Ummm

Posted: Mon Dec 04, 2006 7:18 am
by LOFer
:oops:

Danke!

Posted: Mon Dec 04, 2006 7:24 am
by volka
I really hate it when something that simple causes almost untraceable problems because some wiseheimer wrote super-extra-strict-correct code but is unable to provide reasonable error handling</rant>