#! /usr/bin/perl
use CGI qw/:standard/;
print “Content-type: text/htmlnn”;
print “Modify the file:$file<br/><br/>”;
$action = param(‘action’);
if($action eq “”){
$file_content=””;
open (MYFILE, “<“, $file);
@lines=<MYFILE>;
foreach $l(@lines){
$file_content.=$l;
}
close (MYFILE);
print<<frm;
<form action=”modify.cgi” method=”POST”>
<textarea name=”file” cols=”150″ rows=”30″>
$file_content
</textarea>
<input type=”hidden” id=”action” name=”action” value=”modify”>
<br /><br />
<input type=”submit” value=”Modify!”>
</form>
frm
}
if($action eq “modify”){
print “Done!”;
$file2=param(‘file’);
#print “File:$file”;
open MYFILE, “>$file” or die $!;
print MYFILE $file2;
close (MYFILE);
}
1;
When you need a fast web development and want to let developers modify directly a config file, you must use the following script:
#! /usr/bin/perl use CGI qw/:standard/; print “Content-type: text/htmlnn”; $file=”/etc/httpd/conf.d/my.conf”; print “Modify the file:$file<br/><br/>”; $action = param(‘action’); if($action eq “”){ $file_content=””; open (MYFILE, “<“, $file); @lines=<MYFILE>; foreach $l(@lines){ $file_content.=$l; } close (MYFILE); print<<frm; <form action=”modify.cgi” method=”POST”> <textarea name=”file” cols=”150″ rows=”30″> $file_content </textarea> <input type=”hidden” id=”action” name=”action” value=”modify”> <br /><br /> <input type=”submit” value=”Modify!”> </form> frm } if($action eq “modify”){ print “Done!”; $file2=param(‘file’); #print “File:$file”; open MYFILE, “>$file” or die $!; print MYFILE $file2; close (MYFILE); } 1;
Thanks,