Is there something wrong with my coding?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

FiOh wrote:I see. I'm sorry that i sound stupid and caused so much trouble here. >.<
It's no problem, don't worry about it.
FiOh wrote:May i know where is the debug code information? Where do i see it? How to i open the debug code information?
It should have been output to your browser. I guess I should assume it did not then.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The problem might be that all the output of the relevant code is "within" the head element

Code: Select all

<head>
<?php
... your connect code ...
?>
The browser should better see it as part of the body element.
Try

Code: Select all

<?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 = fgets($fp, $maxlen);
	echo '<div>', date('H:m:i'), ' Debug fgets: ', htmlentities($s), "</div>"; flush();
	return $s;
}

function my_fputs($fp, $s, $len=null) {
	echo '<div>', date('H:m:i'), ' Debug fputs: ', htmlentities($s), "</div>"; flush();
	return ( is_null($len) ) ? fputs($fp, $s) : fputs($fp, $s, $len);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<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>
<?php
$ip = "172.16.221.210";
$username ="cisco";     // $_POST['username'];
$password ="cisco";     // $_POST['password'];
$enable_password ="class";      // $_POST['enable_password'];

$host = $ip;
$port = 23;

$fp = fsockopen ($host, $port, $errno, $errstr, 10);

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");
... and so on ...
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

I've tried the suggested coding and have some new errors:
Notice: Undefined variable: moredetails in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 147

Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 140
Line 147 is the

Code: Select all

$moredetails .=$tmpecho;
while line 140 is the of the

Code: Select all

while(true)
paragraph

Code: Select all

$count=0;
		while(true)
		{
			$tmpecho = fgets ($fp, 4096);

			//Hide the string of terminal length 0
		if(stristr($tmpecho,'terminal length 0') === FALSE )
			{
				$moredetails .=$tmpecho;
			}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and you didn't get any output from my_gets and my_fputs? You certainly did something wrng then but I can't tell what it is.
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

Yah... i didnt get any output from my_gets and my_fputs.
>.<
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please post your current script.
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Current Code -> Login_Process.php of cisco2612

Post by FiOh »

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 = fgets($fp, $maxlen); 
        echo '<div>', date('H:m:i'), ' Debug fgets: ', htmlentities($s), "</div>"; flush(); 
        return $s; 
} 

function my_fputs($fp, $s, $len=null) { 
        echo '<div>', date('H:m:i'), ' Debug fputs: ', htmlentities($s), "</div>"; flush(); 
        return ( is_null($len) ) ? fputs($fp, $s) : 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 ="cisco";	// $_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
	{
		fgets ($fp, 1024);			//junk line

		//****************************************************************
		//clear terminal line
		$p=0;
		$n=0;
		while($p<4)
		{
			fputs ($fp, "cl li 35");
			fputs ($fp, "\r");
			fputs ($fp, "\r");
			fgets ($fp, 1024);
			fgets ($fp, 1024);
			fgets ($fp, 1024);
			$p++;
		}
		while($n<4)
		{
			fputs ($fp, "cl li 34");
			fputs ($fp, "\r");
			fputs ($fp, "\r");
			fgets ($fp, 1024);
			fgets ($fp, 1024);
			fgets ($fp, 1024);
			$n++;
		}
		//****************************************************************
		//end clear terminal line codes

		$device="2r2";
		$x=0;
		$s=0;

		fputs ($fp, $device);

			while ($s<3)
			{
				fputs ($fp, "\r\n");
				$s++;
			}

			while ($x<4)
			{
				fgets ($fp, 1024);
				$x++;
			}

		//seccond negotiation required to access other devices via terminal server
		fputs($fp,chr(0xFF).chr(0xFD).chr(0x01));
		fputs($fp,chr(0xFF).chr(0xFD).chr(0x03));
		fputs($fp,chr(0xFF).chr(0xFB).chr(0x18));
		fputs($fp,chr(0xFF).chr(0xFB).chr(0x1F));
		fputs($fp,chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x3C));
		fputs($fp,chr(0xFF).chr(0xF0));
		fputs($fp,chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x41).chr(0x4E).chr(0x53).chr(0x49));
		fputs($fp,chr(0xFF).chr(0xF0));
		//end second negotatiation

		fputs($fp,"\r");							//enter console by inputting \r
		fgets ($fp, 1024);							//junk text

		fputs($fp,"\r");							//get started by inputting \r
		fgets ($fp, 1024);							//blank
		fputs($fp,$password."\r");					//enter telnet password
		fgets ($fp, 1024);							//user access verification:
		fgets ($fp, 1024);							//blank
		fgets ($fp, 1024);							//password:

		fputs($fp,"en"."\r");
		fputs($fp,$enable_password."\r");			//enter enable password
		fgets ($fp, 1024);							//password:
		$temps=fgets ($fp, 1024);					//this is the line to check for bad password and get hostname , Hello>en
		fgets ($fp, 1024);							//password: (for enabled)

		//*******************************
		//get hostname codes
		$gethostname=explode(">",$temps);			//seperate base on ">" so can get hostname
		$hostname=$gethostname[0];
		//*******************************

		fputs ($fp, "terminal length 0\n");
		fputs ($fp, "show run");
		fputs ($fp, "\r");

		$count=0;
		while(true)
		{
			$tmpecho = 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"))
			{
				fputs ($fp, "\r");
				fputs ($fp, "exit");						//break connection with the router and let it time out, alternative should be found
				$moredetails .=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&nbsp;E&nbsp;N&nbsp;E&nbsp;R&nbsp;A&nbsp;L&nbsp;&nbsp;&nbsp;S&nbsp;E&nbsp;T&nbsp;T&nbsp;I&nbsp;N&nbsp;G&nbsp;S</strong>
				<br /><hr size="1">
			</td>
			<td>
				<strong>U&nbsp;S&nbsp;E&nbsp;R&nbsp;&nbsp;&nbsp;A&nbsp;S&nbsp;S&nbsp;I&nbsp;S&nbsp;T&nbsp;A&nbsp;N&nbsp;C&nbsp;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>:&nbsp;&nbsp;</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" />
						&nbsp;&nbsp;&nbsp;
						<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>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

volka wrote:and replace all fgets by my_fgets for debugging purposes. Remember to keep backup files ;)
Same with fputs -> my_fputs
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

Now the error is:
Fatal error: Call to undefined function my_fputs() in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 63
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

strange since the function is there
function my_fputs($fp, $s, $len=null) {
check the script again.

edit: If you ran a simple replace fputs->my_fputs you got function my_my_fputs and you had to correct that. But then I'd really have to ask you to pay more attention to your work(?).
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

volka wrote:strange since the function is there
function my_fputs($fp, $s, $len=null) {
check the script again.

edit: If you ran a simple replace fputs->my_fputs you got function my_my_fputs and you had to correct that. But then I'd really have to ask you to pay more attention to your work(?).
Sorry about the my_my_fputs... i have edited and try the program again. The weird thing that happened is that when i tried to login to the selected device, after i click the enter button, the same page shows a long lines of '10:01:56 Debug my_fputs: cl li 35' and the web page immediately shows something like 'The Webpage cannot be found'.

Then when i tried to load the same login page, no matter how long i waited, the page wont load. And the entire web site is on the local host only.

The Error is as follows:
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
10:01:56 Debug my_fputs: cl li 35
and it goes on and on. I have to restart my pc before i can get the site on the local host loaded.
>.<
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

There's no output from my_fgets or did you replace only fputs? (and if so, why so?)

It keeps printing Debug my_fputs: cl li 35 again and again?
That's strange. There's only one fputs with cli li 35 and that's

Code: Select all

//clear terminal line
$p=0;
$n=0;
while($p<4)
{
	fputs ($fp, "cl li 35");
	fputs ($fp, "\r");
	fputs ($fp, "\r");
	fgets ($fp, 1024);
	fgets ($fp, 1024);
	fgets ($fp, 1024);
	$p++;
}
I don't see how this can repeat more than 4 times.
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

I dont know why is this happening as well... i only replace all the fputs with my_fputs via the find all and replace. I did change the my_my_fputs to my_fputs.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

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.
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

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&nbsp;E&nbsp;N&nbsp;E&nbsp;R&nbsp;A&nbsp;L&nbsp;&nbsp;&nbsp;S&nbsp;E&nbsp;T&nbsp;T&nbsp;I&nbsp;N&nbsp;G&nbsp;S</strong>
				<br /><hr size="1">
			</td>
			<td>
				<strong>U&nbsp;S&nbsp;E&nbsp;R&nbsp;&nbsp;&nbsp;A&nbsp;S&nbsp;S&nbsp;I&nbsp;S&nbsp;T&nbsp;A&nbsp;N&nbsp;C&nbsp;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>:&nbsp;&nbsp;</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" />
						&nbsp;&nbsp;&nbsp;
						<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]
Post Reply