volka wrote:and the fgets? Why didn't you replace the fgets? Why why why?
edit: OMG, you didn't replace fputs by my_fputs WITHIN the function my_fputs, did you?
please again post your current script.
I'm sorry about it. I have replaced the fputs with my_fputs. By the way after replacing with the my_fputs and my_fgets and i tried to login to the device, the web page couldnt not be loaded.
Error:
Internet Explorer cannot display the webpage
Most likely causes:
. You are not connected to the Internet.
. The website is encountering problems.
. There might be a typing error in the address.
What you can try:
. Diagnose Connection Problems
. More information
This problem can be caused by a variety of issues, including:
Internet connectivity has been lost.
The website is temporarily unavailable.
The Domain Name Server (DNS) is not reachable.
The Domain Name Server (DNS) does not have a listing for the website's domain.
If this is an HTTPS (secure) address, click Tools, click Internet Options, click Advanced, and check to be sure the SSL and TLS protocols are enabled under the security section.
For offline users
You can still view subscribed feeds and some recently viewed webpages.
To view subscribed feeds
Click the Favorites Center button , click Feeds, and then click the feed you want to view.
To view recently visited webpages (might not work on all pages)
Click Tools , and then click Work Offline.
Click the Favorites Center button , click History, and then click the page you want to view.
Below's the current php coding
Code: Select all
<? session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
//session_start();
function my_fgets($fp, $maxlen) {
$read = array($fp); $write=$except=null;
while( false===stream_select($read, $write, $except, 1) ) {
echo '<div>', date('H:m:i'), " - idle</div>\n"; flush();
}
$s = my_fgets($fp, $maxlen);
echo '<div>', date('H:m:i'), ' Debug my_fgets: ', htmlentities($s), "</div>"; flush();
return $s;
}
function my_fputs($fp, $s, $len=null) {
echo '<div>', date('H:m:i'), ' Debug my_fputs: ', htmlentities($s), "</div>"; flush();
return ( is_null($len) ) ? my_fputs($fp, $s) : my_fputs($fp, $s, $len);
} /* Above by FiOh */
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SMART Multi-Vendor Network Deployment System -- CISCO [Router 2612 Series]</title>
<link href="../stylesheet/cssStyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?
$ip = "172.16.221.210";
$username ="cisco"; // $_POST['username'];
$password ="class"; // $_POST['password'];
$enable_password ="class"; // $_POST['enable_password'];
$host = $ip;
$port = 23;
$fp = fsockopen ($host, $port, $errno, $errstr);
if (!$fp)
{
echo $results .= "<br><font face=verdana color=red size=2>";
echo $results .= "<p align=center>";
echo $results .= "<b>ERROR: Could Not Open Socket Connection. Please try again.</b>";
echo $results .= "</font>";
exit();
}
else
{
my_fgets ($fp, 1024); //junk line
//****************************************************************
//clear terminal line
$p=0;
$n=0;
while($p<4)
{
my_fputs ($fp, "cl li 35");
my_fputs ($fp, "\r");
my_fputs ($fp, "\r");
my_fgets ($fp, 1024);
my_fgets ($fp, 1024);
my_fgets ($fp, 1024);
$p++;
}
while($n<4)
{
my_fputs ($fp, "cl li 34");
my_fputs ($fp, "\r");
my_fputs ($fp, "\r");
my_fgets ($fp, 1024);
my_fgets ($fp, 1024);
my_fgets ($fp, 1024);
$n++;
}
//****************************************************************
//end clear terminal line codes
$device="2r2";
$x=0;
$s=0;
my_fputs ($fp, $device);
while ($s<3)
{
my_fputs ($fp, "\r\n");
$s++;
}
while ($x<4)
{
my_fgets ($fp, 1024);
$x++;
}
//seccond negotiation required to access other devices via terminal server
my_fputs($fp,chr(0xFF).chr(0xFD).chr(0x01));
my_fputs($fp,chr(0xFF).chr(0xFD).chr(0x03));
my_fputs($fp,chr(0xFF).chr(0xFB).chr(0x18));
my_fputs($fp,chr(0xFF).chr(0xFB).chr(0x1F));
my_fputs($fp,chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x3C));
my_fputs($fp,chr(0xFF).chr(0xF0));
my_fputs($fp,chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x41).chr(0x4E).chr(0x53).chr(0x49));
my_fputs($fp,chr(0xFF).chr(0xF0));
//end second negotatiation
my_fputs($fp,"\r"); //enter console by inputting \r
my_fgets ($fp, 1024); //junk text
my_fputs($fp,"\r"); //get started by inputting \r
my_fgets ($fp, 1024); //blank
my_fputs($fp,$password."\r"); //enter telnet password
my_fgets ($fp, 1024); //user access verification:
my_fgets ($fp, 1024); //blank
my_fgets ($fp, 1024); //password:
my_fputs($fp,"en"."\r");
my_fputs($fp,$enable_password."\r"); //enter enable password
my_fgets ($fp, 1024); //password:
$temps=my_fgets ($fp, 1024); //this is the line to check for bad password and get hostname , Hello>en
my_fgets ($fp, 1024); //password: (for enabled)
//*******************************
//get hostname codes
$gethostname=explode(">",$temps); //seperate base on ">" so can get hostname
$hostname=$gethostname[0];
//*******************************
my_fputs ($fp, "terminal length 0\n");
my_fputs ($fp, "show run");
my_fputs ($fp, "\r");
$count=0;
while(true)
{
$tmpecho = my_fgets ($fp, 4096);
//Hide the string of terminal length 0
if(stristr($tmpecho,'terminal length 0') === FALSE )
{
$moredetails .=$tmpecho;
}
//break from the loop
if(strstr($tmpecho,"end"))
{
my_fputs ($fp, "\r");
my_fputs ($fp, "exit"); //break connection with the router and let it time out, alternative should be found
$moredetails .=my_fgets ($fp, 1024);
break;
}
}
fclose($fp);
}
$filename = 'Login_Info.txt';
$store_content = $ip.",".$username.",".$password.",".$enable_password.",".$hostname;
// Lets make sure the file exists and is writable first.
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, $store_content))
{
echo "Cannot write to file ($filename)";
exit;
}
$_SESSION['login'] = $username;
echo "<script type="text/javascript"> self.location="General.php"; </script>";
fclose($handle);
}
else
{
echo "The file $filename is not writable";
}
?>
<body class="loginCSS">
<center>
<table width="800px" cellpadding="0" cellspacing="0" border="0">
<tr><td><img border="0" src="../assets/images/cisco/cisco2612.gif"></td></tr>
<tr><td><?php include('menu_cisco2612.html'); ?></td></tr>
<tr><td height="20px"></td></tr>
<tr><td align="left">
<!--CENTER SECTION-->
<table width="100%" cellpadding="5" cellspacing="5" border="0">
<!--HEADERS-->
<tr align="left" valign="top"><td width="70%">
<strong>G E N E R A L S E T T I N G S</strong>
<br /><hr size="1">
</td>
<td>
<strong>U S E R A S S I S T A N C E</strong>
<br><hr size="1">
</td></tr>
<!--LEFT COLUMN: DISPLAY INFORMATION & SETTINGS-->
<tr><td align="center">
<form name="General" method="post" action="<?php echo $PHP_SELF; ?>" onSubmit="return general_check();">
<table width="75%" cellpadding="0" cellspacing="0" border="0">
<!--Display Box-->
<tr align="center"><td colspan="3">
<strong>INFORMATION:</strong><br />
<textarea cols="90" rows="15" readonly><? echo $moredetails; ?></textarea>
</td></tr>
<tr><td colspan="3" height="20px"></td></tr>
<!--SETTINGS FOR CONFIGURATION-->
<tr align="center"><td colspan="3">
<strong>SETTINGS:</strong><br />
<hr size="1">
</td></tr>
<!--set hostname-->
<tr>
<td valign="top" width="25%"><strong>Host Name</strong></td>
<td valign="top"><strong>: </strong></td>
<td valign="top"><input type="text" name="devicename" id="devicename" /></td>
</tr>
<tr><td colspan="3" height="20px"></td></tr>
<!--submit or cancel current configuration-->
<tr align="center"><td colspan="3">
<input type="submit" name="submit" id="submit" value="Save" />
<input type="reset" name="cancel" id="cancel" value="Cancel" />
</td></tr>
</table>
</form>
</td>
<!--RIGHT COLUMN: INSTRUCTIONS-->
<td align="left" valign="top">
[<strong>Hostname</strong>] :
<br />
To specify or modify the host name for your network server.
</td></tr>
</table>
</td></tr>
<tr><td height="20px"></td></tr>
<!--COPYRIGHT-->
<tr><td align="center"><?php include ('../include/copyright.html') ?></td></tr>
</table>
</center>
</body>
</html>
[/list]