3 ## Zebra Looking Glass version 1.0
5 ## Copyright (C) 2000 John W. Fraizer III <john.fraizer@enterzone.net>
6 ## *All* copyright notices must remain in place to use this code.
8 ## The latest version of this code is available at:
9 ## ftp://ftp.enterzone.net/looking-glass/
12 ## This file is part of GNU Zebra.
14 ## GNU Zebra is free software; you can redistribute it and/or modify it
15 ## under the terms of the GNU General Public License as published by the
16 ## Free Software Foundation; either version 2, or (at your option) any
19 ## GNU Zebra is distributed in the hope that it will be useful, but
20 ## WITHOUT ANY WARRANTY; without even the implied warranty of
21 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ## General Public License for more details.
24 ## You should have received a copy of the GNU General Public License
25 ## along with GNU Zebra; see the file COPYING. If not, write to the
26 ## Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ## Boston, MA 02111-1307, USA.
35 ## Set the URL for your site.
36 $url="http://www.sample.com/mrlg.cgi";
38 ## Set your router variables in sub set_router and modify the selections in Main to match.
41 ############################################################
43 ############################################################
46 ## Set the router default
47 @Form{'router'} = "router1";
49 ## Get the form results now so we can override the default router
52 print "Content-type: text/html\n\n";
57 <title>Multi-Router Looking Glass for Zebra</title>
61 <font face=arial size=3 color=blue>
62 <h1>Multi-Router Looking Glass for Zebra</h1>
63 Copyright 2000 - John Fraizer, EnterZone Inc.
70 print "<form METHOD=\"POST\" action=\"$url\">\n";
71 print "<B>Router:</B> <SELECT Name=\"router\" Size=1>\n";
72 print "<OPTION Value=\"$Form{'router'}\">$Form{'router'}\n";
74 <OPTION Value="router1">router1
75 <OPTION Value="router2">router2
76 <OPTION Value="router3">router3
77 <OPTION Value="router4">router4
82 <input type=radio name=query value=1>show ip bgp<br>
83 <input type=radio name=query value=2>show ip bgp summary<br>
84 <input type=radio name=query value=3>show ip route<br>
85 <input type=radio name=query value=4>show interface<br>
86 <input type=radio name=query value=5>show ipv6 bgp<br>
87 <input type=radio name=query value=6>show ipv6 bgp summary<br>
88 <input type=radio name=query value=7>show ipv6 route<br>
90 <B>Argument:</B> <input type=text name=arg length=20 maxlength=60>
91 <input type="submit" value="Execute"></form>
94 ## Set up the address, pw and ports, etc for the selected router.
97 ## Set up which command is to be executed (and then execute it!)
104 <font color=blue face=arial size=2>
105 Multi-Router Looking Glass for Zebra version 1.0<br>
106 Written by: John Fraizer -
107 <a href="http://www.ez-hosting.net/">EnterZone, Inc</a><br>
108 Source code: <a href="ftp://ftp.enterzone.net/looking-glass/">ftp://ftp.enterzone.net/looking-glass/</a>
119 ############################################################
121 ############################################################
125 read(STDIN
, $buffer, $ENV{'CONTENT_LENGTH'});
127 # Split the name-value pairs
128 @pairs = split(/&/, $buffer);
130 # For each name-value pair:
131 foreach $pair (@pairs)
134 # Split the pair up into individual variables.
135 local($name, $value) = split(/=/, $pair);
137 # Decode the form encoding on the name and value variables.
139 $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
142 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
144 # If they try to include server side includes, erase them, so they
145 # aren't a security risk if the html gets returned. Another
146 # security hole plugged up.
147 $value =~ s/<!--(.|\n)*-->//g;
149 @Form{$name} = $value ;
155 ############################################################
157 ############################################################
159 ## $server is the IP address of the router running zebra
160 ## $login_pass is the password of the router
161 ## $bgpd is the port that bgpd will answer on
162 ## $zebra is the port that zebra will answer on
163 ## if $zebra is "", it will disable sh ip route and sh int for that router.
164 ## if $full_tables is set to "1" for a router, full BGP and IP ROUTE table dumps will be allowed via the looking glass.
165 ## This is a BAD thing to do if you have multiple full views on a router. That's why the option is there.
168 if ($Form{'router'} eq 'router1')
170 $server = '10.1.1.1';
171 $login_pass = 'zebra';
178 elsif ($Form{'router'} eq 'router2')
180 $server = '10.1.1.2';
181 $login_pass = 'zebra';
186 elsif ($Form{'router'} eq 'router3')
188 $server = '10.1.1.3';
189 $login_pass = 'zebra';
195 elsif ($Form{'router'} eq 'router4')
197 $server = '10.1.1.4';
198 $login_pass = 'zebra';
207 ############################################################
209 ############################################################
211 if ($Form{'query'} eq '1')
216 elsif ($Form{'query'} eq '2')
221 if ($Form{'query'} eq '3')
226 if ($Form{'query'} eq '4')
230 if ($Form{'query'} eq '5')
234 if ($Form{'query'} eq '6')
236 sh_ip_bgp_sum
('ipv6');
238 if ($Form{'query'} eq '7')
243 ############################################################
245 ############################################################
247 my $protocol = shift(@_);
249 if ($protocol ne 'ip' && $protocol ne 'ipv6')
251 print "Invalid protocol: $protocol\n";
252 print "protocol must be 'ip' or 'ipv6'\n\n";
255 $command = "show $protocol bgp $Form{'arg'}";
256 if ($Form{'arg'} eq '')
258 if ($full_tables eq '1')
264 print "Sorry. Displaying the FULL routing table would put too much load on the router!\n\n";
273 ############################################################
275 ############################################################
277 my $protocol = shift(@_);
279 if ($protocol ne 'ip' && $protocol ne 'ipv6')
281 print "Invalid protocol: $protocol\n";
282 print "protocol must be 'ip' or 'ipv6'\n\n";
285 $command = "show $protocol bgp summary";
289 ############################################################
291 ############################################################
296 print "Sorry. The <b>show ip route</b> command is disabled for this router."
302 my $protocol = shift(@_);
303 if ($protocol ne 'ip' && $protocol ne 'ipv6')
305 print "Invalid protocol: $protocol\n";
306 print "protocol must be 'ip' or 'ipv6'\n\n";
309 $command = "show $protocol route $Form{'arg'}";
310 if ($Form{'arg'} eq '')
312 if ($full_tables eq '1')
318 print "Sorry. Displaying the FULL routing table would put too much load on the router!\n\n";
328 ############################################################
330 ############################################################
334 print "Sorry. The <b>show interface</b> command is disabled for this router."
339 $command = "show interface $Form{'arg'}";
346 ############################################################
348 ############################################################
349 ## This code is based on:
351 ## Zebra interactive console
352 ## Copyright (C) 2000 Vladimir B. Grebenschikov <vova@express.ru>
358 print "Executing command = $command";
360 # my $port = ($opt_z ? 'zebra' : 0) ||
361 # ($opt_b ? 'bgpd' : 0) ||
362 # ($opt_o ? 'ospfd' : 0) ||
363 # ($opt_r ? 'ripd' : 0) || 'bgpd';
368 my $t = new Net
::Telnet
(Timeout
=> 10,
369 Prompt
=> '/[\>\#] $/',
374 $t->cmd ($login_pass);
383 ############################################################
385 ############################################################
388 my @lines = $t->cmd ($cmd);
390 print join ('', grep (!/[\>\#] $/, @lines)), "\n";