|
#!/usr/bin/perl
$configurl = "/var/www/";
$config_file = "router.cfg";
$config_file2 = "router2.cfg";
print "Content-type:text/html\n\n";
use CGI;
$req = new CGI;
$lan_ip = $req->param("lan_ip");
open(CONFIG,"<$configurl$config_file");
//这里,打开些文件老是出错,会是什么原因?
if(!(open (OUTFILE, ">$configurl$config_file2")))
{
print "Failed";
}
@array = <CONFIG>;
foreach $var(@array)
{
if($var =~ m/LAN_IP/)
{
($name,$value) = split(/=/,$var);
print OUTFILE "$name=$lan_ip";
next;
}
print OUTFILE $var;
}
close(OUTFILE);
close(CONFIG);
unlink("$configurl$config_file");
rename("$configurl$config_file2","$configurl$config_file"); |
|