help with php please!!

Status
Not open for further replies.

umadevi86

Beta member
Messages
1
Hi! I'm currently doing on a pj which need to make amendment to the source code written by others. It is some sort of web-based configuration of Router/Switch using php programming. The source code which was done previously had problem showing full information of router/switch.

Using HypterTerminal
E.g: show run configuration information.
It has a limited maximum no. of lines to display the informations, (30 lines). Once it reached the line tat say "more", you will have to press either spacebar to display the remaining information or enter to display line by line.

Web-Based Configuration
After loggin into the router config, u will be direct to it general page which display the show run config information. After the "more", we found the first 3 lines missing. Provided below is the source code tat program tis part. I have stated the comments tat I don't understand. Do hope there's ppl willin to help me solve this problem.
This is the program:

<? session_start(); ?>

<?
//session created for security purpose and to protect outsider directly entry the webpage
if ($_SESSION['login'] == "")
{
echo "<script type=\"text/javascript\"> alert(\"You must LOG IN to access this page.\"); </script>";
echo "<script type=\"text/javascript\"> self.location=\"Login.php\"; </script>";
exit();
}

?>

<?

$filename = "Login_Info.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$login_info = explode(",", $contents);

$host = $login_info[0];
$port = 23;
//$newHostname = $_POST['devicename'];

//Start of configuration when hostnames input field is not empty.
if($_POST['devicename'] != "")
{
$fp = fsockopen($host,$port,$errno,$errstr); //Open socket & for communication

if(!fp)
{
$results = "Error: Could not open socket connection";
}
else
{
//Writing to file
fputs ($fp, $login_info[2]."\n");
fputs ($fp, "en\n");
fputs ($fp, $login_info[3]."\n");
fputs ($fp, "config t\n");

//Read and return output line by line
fgets ($fp, 1024); //ÿûÿûÿýÿý
fgets ($fp, 1024); //Blank

$moredetails .= fgets ($fp, 1024); //User System Verification
$moredetails .= fgets ($fp, 1024); //Blank
$moredetails .= fgets ($fp, 1024); //telnet pwd
$moredetails .= fgets ($fp, 1024); //enable
$moredetails .= fgets ($fp, 1024); //enable pwd
$moredetails .= fgets ($fp, 1024); //config t
fgets ($fp, 1024); //ÿûÿûÿýÿý

//configure hostname
fputs ($fp, "hostname ".$_POST['devicename']."\n"); //config hostname command
$moredetails .= fgets($fp, 1024); //hostname newhostname

//exit from config. mode
fputs ($fp,"exit\n");
fputs ($fp, "\r");

$moredetails .= fgets ($fp, 1024);
$moredetails .= fgets ($fp, 1024);
$moredetails .= "\n-----------------------------------------------\n\n";
}
fclose($fp);

//store latest info into login_info.txt
$filename = "Login_Info.txt";
$store_content = $login_info[0].",".$login_info[1].",".$login_info[2].",".$login_info[3].",".$_POST['devicename'];

if(is_writeable($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;
}
fclose($handle);
}
else
{
echo "The file $filename is not writable";
}
}

//Display info upon entering the page.
$fp = fsockopen($host,$port,$errno,$errstr);

if(!$fp)
{
$results = "Error: could not open socket connection";
}
else
{
fputs ($fp, $login_info[2]."\n"); //telnet password
fputs ($fp, "en\n"); //enable
fputs ($fp, $login_info[3]."\n"); //secret password
fputs ($fp, "terminal length 0\n"); //show complete list of info without pausing
fputs ($fp, "show run\n"); //show run config. command
fputs ($fp, "\r"); //enter key

fgets ($fp, 1024); //ÿûÿûÿýÿý

while(true)
{
$tmpecho = fgets ($fp, 1024);

//Hide the string of terminal length 0
if(stristr($tmpecho,'terminal length 0') === FALSE )
{
$moredetails .= $tmpecho;
}

//break from the loop
if(substr($tmpecho,0,3) =='end')
{
fputs ($fp, "\r");
$moredetails .= fgets ($fp, 1024);
$moredetails .= fgets ($fp, 1024);
break;
}
}
}
fclose($fp);
?>

<!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 [Aironet 1200 Series]</title>
<link href="../stylesheet/cssStyle.css" rel="stylesheet" type="text/css" />
<script src="../javascript/basicCheck.js"></script>
</head>

<body class="loginCSS">
<center>
<table width="800px" cellpadding="0" cellspacing="0" border="0">
<tr><td>
cisco1200.gif
</td></tr>
<tr><td><?php include('menu_cisco1200.html'); ?></td></tr>

<tr><td height="20px"></td></tr>

<tr><td align="left">

<table width="100%" cellpadding="5" cellspacing="5" border="0">


<tr align="left" valign="top"><td width="70%">
GENERALSETTINGS

<hr size="1">
</td>
<td>
USERASSISTANCE

<hr size="1">
</td></tr>


<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">


<tr align="center"><td colspan="3">
INFORMATION:

<textarea cols="80" rows="15" readonly><? echo $moredetails; ?></textarea>
</td></tr>

<tr><td colspan="3" height="20px"></td></tr>


<tr align="center"><td colspan="3">
SETTINGS:

<hr size="1">
</td></tr>


<tr>
<td valign="top" width="25%">Host Name</td>
<td valign="top">:</td>
<td valign="top"><input type="text" name="devicename" id="devicename" /></td>
</tr>

<tr><td colspan="3" height="20px"></td></tr>


<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>


<td align="left" valign="top">
[Hostname] :


To specify or modify the host name for your network server.
</td></tr>
</table>

</td></tr>

<tr><td height="20px"></td></tr>


<tr><td align="center"><?php include ('../include/copyright.html') ?></td></tr>
</table>
</center>
</body>
</html>
 
Status
Not open for further replies.
Back
Top Bottom