This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wunderland.php
159 lines (145 loc) · 4.08 KB
/
wunderland.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
//////////////////////////////////////////////////////////////////////////////
//
// wunderland.php
//
// Original Attribution
// PHP Looking Glass - Copyright (c) 2000
// version 1.8 (2009)
// by
// Gabriella Paolini - [email protected]
// Updated by Jered Sutton - [email protected]
// Looking Glass for CISCO Routers.
//
//////////////////////////////////////////////////////////////////////////////
// Default Password
$pw = "****\r\n";
//telnet information
$cfgPort = 23;
$cfgTimeOut = 10;
//define the cisco devices here
$deviceList = array(
'Kansas' => array(
'ip' =>'192.168.1.1',
'sourceip' =>'192.168.2.1',
'pw' => '****\r\n',
),
'New York' => array(
'ip' =>'172.16.10.1',
'sourceip' =>'172.16.20.1',
'pw' => '****\r\n',
),
'LA' => array(
'ip' =>'10.1.1.1',
'sourceip' =>'',
'pw' => '****\r\n',
)
);
?>
<HTML>
<HEAD>
<title>Wunderland Looking Glass</title>
</HEAD>
<style type="text/css" media="all">@import url(style.css);</style>
<div id='container'>
<BODY>
<h1>Wunderland Looking Glass</h1>
<FORM ACTION="index.php" METHOD="POST">
<TABLE CELLPADDING="2" cellspacing="2">
<tr>
<TD>Device:</TD>
<TD>Command:</TD>
<TD>IP Address:</TD>
<td></td>
</tr>
<tr>
<TD>
<SELECT NAME="device">
<?php
foreach (array_keys($deviceList) as $k) {
echo "<option value=\"$k\">$k</option>";
}
php?>
</SELECT>
</TD>
<TD>
<SELECT NAME="query">
<OPTION VALUE="traceroute" > traceroute
<OPTION VALUE="ping" > ping
</SELECT>
</td>
<TD><input type="text" name="destip" size="25"></TD>
<td><INPUT TYPE=submit VALUE="Submit"> <INPUT TYPE=reset VALUE="Reset"></td>
</tr>
</TABLE>
</FORM>
</div>
<div align="left">
<pre>
<?php
//retrieve POST values
$device = $_POST['device'];
$query = $_POST['query'];
$destip = $_POST['destip'];
$ip = $deviceList[$device]['ip'];
// validate all input for the script
if ( ($ip != "") &&
($query == "ping" || $query == "traceroute") &&
preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" . "(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $destip) &&
getenv("REQUEST_METHOD") != "post"){
//open the telnet connection
$usenet = fsockopen($ip, $cfgPort, $errno, $errstr, $cfgTimeOut);
socket_set_timeout($usenet, 3);
if(!$usenet)
echo "Cannot connect to the router \n";
//construct the command string
else {
if ($query == "traceroute")
if($sourceip != "")
$command = $query." ip ".$destip." source ".$sourceip."\r\n";
else
$command = $query." ".$destip."\r\n";
elseif ($query == "ping")
$command = $query." ".$destip."\r\n";
if($sourceip != "")
$command = $query." ip ".$destip." source ".$sourceip."\r\n";
else
$command = $query." ".$destip."\r\n";
//send password and text terminal setting
fputs ($usenet, $pw);
fputs ($usenet, "terminal length 0\r\n");
fputs ($usenet, "\r\n");
//absorb extraneous terminal output
$j = 0;
while ($j<7){
fgets($usenet, 128);
$j++;
}
//run the command
fputs ($usenet, $command);
//some formatting
echo "<hr>";
//print the results
while ($r = fgets($usenet, 128)) {
echo "$r";
//enables realtime output to the browser
ob_flush();
flush();
}
echo "<hr>";
//logout
fputs ($usenet, "exit\r\n");
//close the fsocket
fclose($usenet);
}
}
?>
</PRE>
</div>
<br>
<br>
<p align="center">Wunderland Looking Glass v 1.8 - php
script made by <a
href="mailto:[email protected]">Gabriella Paolini</a> - Open
Source 2000-2002 Modified by Jered Sutton</p>
</body>