Code:
$filename = 'r_login_info.txt';
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$login_info = explode(",", $contents);
$port = 23;
if ($_POST['ip1'] != '')
{
$fp = fsockopen ($login_info[0], $port, $errno, $errstr);
if (!$fp)
{
$results = "Error: could not open socket connection";
}
else
{
fputs ($fp, $login_info[2]."\n"); //Password 1
fputs ($fp, "en\n"); //enable
fputs ($fp, $login_info[3]."\n"); //Password 2
fputs ($fp, "config t\n"); //Config t command
fgets ($fp, 1024); //ÿûÿûÿýÿý
$moredetails .= fgets ($fp, 1024); //Blank
$moredetails .= fgets ($fp, 1024); //User System Verification
$moredetails .= fgets ($fp, 1024); //Blank
$moredetails .= fgets ($fp, 1024); //Password 1
$moredetails .= fgets ($fp, 1024); //enable
$moredetails .= fgets ($fp, 1024); //Password 2
$moredetails .= fgets ($fp, 1024); //Config. t command
fgets ($fp, 1024); //Enter conf one by one
if($_POST['ip1'] != "" && $_POST['ip2'] != "" && $_POST['ip3'] != "" && $_POST['ip4'] != "")
{
$login_info[0] = $_POST['ip1'].".".$_POST['ip2'].".".$_POST['ip3'].".".$_POST['ip4'];
fputs ($fp, "ip address ".$_POST['ip1'].".".$_POST['ip2'].".".$_POST['ip3'].".".$_POST['ip4']." ".$_POST['smask1'].".".$_POST['smask2'].".".$_POST['smask3'].".".$_POST['smask4']."\n");
$moredetails .= fgets ($fp, 1024);
}
//-------------------------------------------------------------------------
//fputs ($fp, "end\n");
$moredetails .= fgets ($fp, 1024); //this is line 113: Exit from config-if & config
//-------------------------------------------------------------------------
$moredetails .= "\n------------------------------------\n\n"; //line
}
fclose ($fp);
$filename = 'r_login_info.txt';
$content = $login_info[0].",".$login_info[1].",".$login_info[2].",".$login_info[3].",".$login_info[4];
if (is_writable($filename))
{
/*
In our example we are opening $filename in append mode. The file pointer
is at the bottom of the file hence that is where $somecontent will go when
we fwrite() it.
*/
if (!$handle = fopen($filename, 'w'))
{
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (!fwrite($handle, $content))
{
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
}
}
$fp = fsockopen ($login_info[0], $port, $errno, $errstr);
if (!$fp)
{
$results = "Error: could not open socket connection";
}
else
{
........................
..........................
}
fclose($fp);
Those within "//------------------" is the problem i encountered.
When i commented those 2 lines, the script will be able to change the ip address in the txt file which the ip address is always used for "fsockopen($host...)" . However when I added them into the code. it will prompted me "Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\Apache Group\Apache2\htdocs\MultiVendor_2\r_interface.php on line 113".
tat line is added just to exit from the config mode n it will b display on the page to allow user to view how the config is done.
Anyone can help?