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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
#!/usr/bin/perl
##
## Zebra Looking Glass version 1.0
## 01 FEB 2000
## Copyright (C) 2000 John W. Fraizer III <john.fraizer@enterzone.net>
## *All* copyright notices must remain in place to use this code.
##
## The latest version of this code is available at:
## ftp://ftp.enterzone.net/looking-glass/
##
##
## This file is part of GNU Zebra.
##
## GNU Zebra is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by the
## Free Software Foundation; either version 2, or (at your option) any
## later version.
##
## GNU Zebra is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with GNU Zebra; see the file COPYING. If not, write to the
## Free Software Foundation, Inc., 59 Temple Place - Suite 330,
## Boston, MA 02111-1307, USA.
require 5.002;
use POSIX;
use Net::Telnet ();
## Set the URL for your site.
$url="http://www.sample.com/mrlg.cgi";
## Set your router variables in sub set_router and modify the selections in Main to match.
############################################################
#Main
############################################################
{
## Set the router default
@Form{'router'} = "router1";
## Get the form results now so we can override the default router
get_form();
print "Content-type: text/html\n\n";
print '
<html>
<head>
<title>Multi-Router Looking Glass for Zebra</title>
</head>
<body bgcolor=white>
<font face=arial size=3 color=blue>
<h1>Multi-Router Looking Glass for Zebra</h1>
Copyright 2000 - John Fraizer, EnterZone Inc.
<br>
';
print '
<font color=black>
';
print "<form METHOD=\"POST\" action=\"$url\">\n";
print "<B>Router:</B> <SELECT Name=\"router\" Size=1>\n";
print "<OPTION Value=\"$Form{'router'}\">$Form{'router'}\n";
print '
<OPTION Value="router1">router1
<OPTION Value="router2">router2
<OPTION Value="router3">router3
<OPTION Value="router4">router4
</select>
<br><br>
<B>Query</B>:
<br>
<input type=radio name=query value=1>show ip bgp<br>
<input type=radio name=query value=2>show ip bgp summary<br>
<input type=radio name=query value=3>show ip route<br>
<input type=radio name=query value=4>show interface<br>
<input type=radio name=query value=5>show ipv6 bgp<br>
<input type=radio name=query value=6>show ipv6 bgp summary<br>
<input type=radio name=query value=7>show ipv6 route<br>
<br>
<B>Argument:</B> <input type=text name=arg length=20 maxlength=60>
<input type="submit" value="Execute"></form>
';
## Set up the address, pw and ports, etc for the selected router.
set_router();
## Set up which command is to be executed (and then execute it!)
set_command();
print '
<br><br>
</font>
<font color=blue face=arial size=2>
Multi-Router Looking Glass for Zebra version 1.0<br>
Written by: John Fraizer -
<a href="http://www.ez-hosting.net/">EnterZone, Inc</a><br>
Source code: <a href="ftp://ftp.enterzone.net/looking-glass/">ftp://ftp.enterzone.net/looking-glass/</a>
</body>
</html>
';
## All done!
exit (0);
}
############################################################
sub get_form
############################################################
{
#read STDIN
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
# For each name-value pair:
foreach $pair (@pairs)
{
# Split the pair up into individual variables.
local($name, $value) = split(/=/, $pair);
# Decode the form encoding on the name and value variables.
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# If they try to include server side includes, erase them, so they
# aren't a security risk if the html gets returned. Another
# security hole plugged up.
$value =~ s/<!--(.|\n)*-->//g;
@Form{$name} = $value ;
}
}
############################################################
sub set_router
############################################################
## $server is the IP address of the router running zebra
## $login_pass is the password of the router
## $bgpd is the port that bgpd will answer on
## $zebra is the port that zebra will answer on
## if $zebra is "", it will disable sh ip route and sh int for that router.
## if $full_tables is set to "1" for a router, full BGP and IP ROUTE table dumps will be allowed via the looking glass.
## This is a BAD thing to do if you have multiple full views on a router. That's why the option is there.
{
if ($Form{'router'} eq 'router1')
{
$server = '10.1.1.1';
$login_pass = 'zebra';
$bgpd = "2605";
$zebra = "";
$full_tables=1;
}
elsif ($Form{'router'} eq 'router2')
{
$server = '10.1.1.2';
$login_pass = 'zebra';
$bgpd = "2605";
$zebra = "2601";
}
elsif ($Form{'router'} eq 'router3')
{
$server = '10.1.1.3';
$login_pass = 'zebra';
$bgpd = "2605";
$zebra = "2601";
$full_tables=1;
}
elsif ($Form{'router'} eq 'router4')
{
$server = '10.1.1.4';
$login_pass = 'zebra';
$bgpd = "2605";
$zebra = "2601";
}
}
############################################################
sub set_command
############################################################
{
if ($Form{'query'} eq '1')
{
sh_ip_bgp('ip');
}
elsif ($Form{'query'} eq '2')
{
sh_ip_bgp_sum('ip');
}
if ($Form{'query'} eq '3')
{
sh_ip_route('ip');
}
if ($Form{'query'} eq '4')
{
sh_int();
}
if ($Form{'query'} eq '5')
{
sh_ip_bgp('ipv6');
}
if ($Form{'query'} eq '6')
{
sh_ip_bgp_sum('ipv6');
}
if ($Form{'query'} eq '7')
{
sh_ip_route('ipv6');
}
}
############################################################
sub sh_ip_bgp
############################################################
{
my $protocol = shift(@_);
$port = $bgpd;
if ($protocol ne 'ip' && $protocol ne 'ipv6')
{
print "Invalid protocol: $protocol\n";
print "protocol must be 'ip' or 'ipv6'\n\n";
return;
}
$command = "show $protocol bgp $Form{'arg'}";
if ($Form{'arg'} eq '')
{
if ($full_tables eq '1')
{
execute_command();
}
else
{
print "Sorry. Displaying the FULL routing table would put too much load on the router!\n\n";
}
}
else
{
execute_command();
}
}
############################################################
sub sh_ip_bgp_sum
############################################################
{
my $protocol = shift(@_);
$port = $bgpd;
if ($protocol ne 'ip' && $protocol ne 'ipv6')
{
print "Invalid protocol: $protocol\n";
print "protocol must be 'ip' or 'ipv6'\n\n";
return;
}
$command = "show $protocol bgp summary";
execute_command();
}
############################################################
sub sh_ip_route
############################################################
{
if ($zebra eq '')
{
print "Sorry. The <b>show ip route</b> command is disabled for this router."
}
else
{
$port = $zebra;
my $protocol = shift(@_);
if ($protocol ne 'ip' && $protocol ne 'ipv6')
{
print "Invalid protocol: $protocol\n";
print "protocol must be 'ip' or 'ipv6'\n\n";
return;
}
$command = "show $protocol route $Form{'arg'}";
if ($Form{'arg'} eq '')
{
if ($full_tables eq '1')
{
execute_command();
}
else
{
print "Sorry. Displaying the FULL routing table would put too much load on the router!\n\n";
}
}
else
{
execute_command();
}
}
}
############################################################
sub sh_int
############################################################
{
if ($zebra eq '')
{
print "Sorry. The <b>show interface</b> command is disabled for this router."
}
else
{
$port = $zebra;
$command = "show interface $Form{'arg'}";
execute_command();
}
}
############################################################
sub execute_command
############################################################
## This code is based on:
##
## Zebra interactive console
## Copyright (C) 2000 Vladimir B. Grebenschikov <vova@express.ru>
##
{
print "Executing command = $command";
# my $port = ($opt_z ? 'zebra' : 0) ||
# ($opt_b ? 'bgpd' : 0) ||
# ($opt_o ? 'ospfd' : 0) ||
# ($opt_r ? 'ripd' : 0) || 'bgpd';
my $cmd = $command;
my $t = new Net::Telnet (Timeout => 10,
Prompt => '/[\>\#] $/',
Port => $port);
$t->open ($server);
$t->cmd ($login_pass);
if ($cmd)
{
docmd ($t, $cmd);
}
}
############################################################
sub docmd
############################################################
{
my ($t, $cmd) = @_;
my @lines = $t->cmd ($cmd);
print "<pre>\n";
print join ('', grep (!/[\>\#] $/, @lines)), "\n";
print "</pre>";
}
|