├── favicon.ico ├── .gitignore ├── communities.txt ├── as.txt ├── CHANGELOG ├── makedb.pl ├── makeaslist.pl ├── README ├── lg.conf ├── COPYING └── lg.cgi /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cougar/lg/HEAD/favicon.ico -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | as-*.txt 2 | as.db 3 | 4 | .* 5 | !.gitignore 6 | 7 | *~ 8 | -------------------------------------------------------------------------------- /communities.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cougar/lg/HEAD/communities.txt -------------------------------------------------------------------------------- /as.txt: -------------------------------------------------------------------------------- 1 | # 2 | # AS data not included any more. Create data files yourself with makeaslist.pl 3 | # or you can download them from http://www.version6.net/lg/db/ 4 | # 5 | 6 | #include as-afrinic.txt 7 | #include as-apnic.txt 8 | #include as-arin.txt 9 | #include as-jpnic.txt 10 | #include as-lacnic.txt 11 | #include as-ripe.txt 12 | 13 | # 14 | # these lines owerwrite previous records 15 | # 16 | 17 | 65333 The Team Cymru Bogon Route Server Project 18 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 25.11.2004 1.9 2 | + disclaimer 3 | ! SECURITY: rshcmd check 4 | ! new TELNET protocol handling, change term size to fit command string 5 | + async line-by-line reading of telnet data to show traceroutes 6 | in realtime 7 | ! hide BGP session port numbers if "secure" mode used 8 | 9 | 09.11.2004 10 | ! OPTGROUP instead of router description headings 11 | 12 | 07.11.2004 1.8p3 13 | ! HTML is valid HTML 4.01 Transitional now 14 | 15 | 05.11.2004 16 | - traceroute wait removed to make command shorter. problem with cmdline scrolling. telnet module needs changes to accept that ;-( 17 | ! APNIC whois search page link updated 18 | + show all routes when exact was asked in JunOS 19 | - prompt wait in ios code removed. there was sometimes problems with that 20 | ! BGP neighbor "ping" link instead of loop to the same screen 21 | ! parser improvements for "show ip bgp neighbor" and "show route protocol bgp .* terse" 22 | ! load libraries only if needed - thanks to Marco d'Itri 23 | 24 | 15.06.2004 1.8p2 25 | ! JunOS traceroute does not support AS lookup yet 26 | + some parser improvements 27 | ! APNIC db location change 28 | + JPNIC, LACNIC (country only) 29 | ! use SixXS whois for unknown AS 30 | 31 | 17.01.2004 1.8p1 32 | + different port for zebra ping and traceroute commands 33 | 34 | 02.07.2003 1.8 35 | + Community descriptions 36 | ! use Berkeley DB instead of plain text file (compile with makedb.pl) 37 | 38 | 17.06.2003 1.7p7 39 | ! as2link parser fix - thanks to Rob Wise 40 | 41 | 20.05.2003 1.7p6 42 | ! deny IPv6 addresses in IPv4 query 43 | + It is now possible to see all BGP neighbors 44 | 45 | 04.03.2003 1.7p5 46 | ! link from "show bgp ipv6 summary" to 47 | "show bgp ipv6 neighbors x routes" fixed when summary used one line 48 | 49 | 18.02.2003 1.7p4 50 | ! regexp fix for unwrapped IPv6 summary lines 51 | ! as2link fix for IPv6 address lines without AS numbers 52 | ! lg does not need IO::Handle, Net::Telnet, Net::SSH::Perl and 53 | Net::SSH::Perl::Cipher if using method that doesn't need them 54 | 55 | 17.01.2003 1.7p3 56 | ! one parser for all Cisco/Zebra BGP route table output 57 | ! new as2link(). lines with MOAS (AS1 {AS2,AS3}) are also OK now 58 | 59 | 29.12.2002 1.7p2 60 | ! output parser fix for damped, history and RIB-failure prefixes 61 | ! wrapped lines are displayed now correctly 62 | 63 | 27.12.2002 1.7p1 64 | ! telnet/ssh missing last line fix - thanks to nomad 65 | 66 | 03.12.2002 1.7 67 | + Juniper output support (telnet, SSH) 68 | + Telnet protocol support (Net::Telnet required) 69 | + SSH support (Net::SSH::Perl required) 70 | ! RFC 2396 URI syntax for router address 71 | 72 | 73 | 16.07.2002 1.6 74 | + Favicon support 75 | + Perl script for downloading AS num data from RIPE/ARIN/APNIC 76 | ! new IPv6 configuration option 77 | ! improved hyperlinking between different IPv6 BGP screens 78 | ! new router-servers and one new IPv6 LG 79 | 80 | 81 | 25.06.2002 1.5 Major feature enhancements 82 | ! RIPE whois link update 83 | + HTTPS method 84 | + configuration option for default router selection 85 | + separators in router list 86 | ! improved hyperlinking between different BGP screens 87 | ! other small fixes 88 | 89 | 90 | 28.05.2002 1.4 The first public release, initial freshmeat announcement 91 | + IPv6 support 92 | + XML configuration file 93 | ! other small fixes and changes 94 | 95 | 96 | 17.05.2001 1.3 97 | small configuration change 98 | 99 | 100 | 19.03.2001 1.2 101 | A lot of changes. More complex configuration file. Telnet support 102 | 103 | 104 | 26.02.2000 1.1 105 | The first version of LG in CVS 106 | It supports remote LG sites with the same variable names 107 | The design is mainly borrowed from KPNQwest LG 108 | (http://stats.kpni.net/cgi-bin/lg.pl) 109 | -------------------------------------------------------------------------------- /makedb.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use DB_File; 4 | 5 | my $asfile = "as.txt"; 6 | my $communityfile = "communities.txt"; 7 | my $dbfile = "as.db"; 8 | 9 | my %GLOBALVAR; 10 | my %LOCALVAR; 11 | my %COMMUNITY; 12 | my %ANYNUM = ("0=0" => "", "1=1" => "", "2=2" => "", "3=3" => "", "4=4" => "", 13 | "5=5" => "", "6=6" => "", "7=7" => "", "8=8" => "", "9=9" => ""); 14 | 15 | my %AS; 16 | 17 | tie (%AS, 'DB_File', $dbfile, O_RDWR|O_CREAT, 0644, $DB_HASH) or 18 | die "Can\'t write AS database $dbfile: $!"; 19 | 20 | undef %AS; 21 | 22 | print "Reading AS names..\n"; 23 | %AS = &read_as_list($asfile); 24 | print " OK\n"; 25 | 26 | print "Reading community names..\n"; 27 | my %COMMUNITY = &read_community_list($communityfile); 28 | foreach my $key (keys (%COMMUNITY)) { 29 | $AS{$key} = $COMMUNITY{$key}; 30 | } 31 | print " OK\n"; 32 | 33 | print "Setting up database..\n"; 34 | untie %AS; 35 | print " OK\n"; 36 | 37 | sub read_as_list { 38 | my ($fn) = @_; 39 | 40 | local *F; 41 | my %AS; 42 | 43 | if (! open(F, $fn)) { 44 | print "ERROR: Can't read AS list from $fn: $!\n"; 45 | return; 46 | } 47 | print " Read AS list from $fn..\n"; 48 | while () { 49 | chop; 50 | if (/^#include\s+(.+)$/) { 51 | my %AS2 = &read_as_list($1); 52 | foreach my $key (keys (%AS2)) { 53 | $AS{$key} = $AS2{$key}; 54 | } 55 | undef %AS2; 56 | next; 57 | } 58 | next if (/^$/ || /^\s*#/); 59 | my ($asnum, $descr) = split /\t+/; 60 | $asnum =~ s/^[^\d]*(\d+)[^\d]*$/$1/; 61 | $AS{$asnum} = $descr; 62 | } 63 | close(F); 64 | return (%AS); 65 | } 66 | 67 | sub read_community_list { 68 | my ($fn) = @_; 69 | 70 | local *F; 71 | 72 | if (! open(F, $fn)) { 73 | print "ERROR: Can't read community list from $fn: $!\n"; 74 | return; 75 | } 76 | print " Read community list from $fn..\n"; 77 | my $asnum = ""; 78 | while () { 79 | chop; 80 | if (/^#include\s+(.+)$/) { 81 | my %COMMUNITY2 = &read_community_list($1); 82 | foreach my $key (keys (%COMMUNITY2)) { 83 | $COMMUNITY{$key} = $COMMUNITY2{$key}; 84 | } 85 | undef %COMMUNITY2; 86 | next; 87 | } 88 | next if (/^$/ || /^\s*#/); 89 | s/#.*$//; 90 | 91 | if (/^AS(\d+)$/) { 92 | $asnum = $1; 93 | undef %LOCALVAR; 94 | next; 95 | } 96 | 97 | my ($community, $descr) = split /\t+/; 98 | 99 | if ($community =~ /^(\d+):/) { 100 | die "ERROR! AS $1 begin tag missing at line $." unless ($1 == $asnum); 101 | } 102 | 103 | if ($community =~ /^([A-Z]+=\d+)$/) { 104 | $GLOBALVAR{$community} = $descr; 105 | next; 106 | } 107 | if ($community =~ /^([a-z]+=\d+)$/) { 108 | $LOCALVAR{$community} = $descr; 109 | next; 110 | } 111 | if ($community =~ /^\d+:\d+$/) { 112 | $COMMUNITY{$community} = $descr; 113 | next; 114 | } 115 | if ($community =~ /^URL$/) { 116 | $COMMUNITY{$asnum . ":URL"} = $descr; 117 | next; 118 | } 119 | if ($community =~ /^(\d+):(\d*)([a-zA-Z\.].*)$/) { 120 | &complete_community($community, $descr, %LOCALVAR); 121 | next; 122 | } 123 | die "ERROR: Illegal community line $.: \"$_\""; 124 | } 125 | close(F); 126 | return (%COMMUNITY); 127 | } 128 | 129 | sub complete_community { 130 | my ($community, $descr) = @_; 131 | 132 | if ($community =~ /^\d+:\d+$/) { 133 | $COMMUNITY{$community} = $descr; 134 | return; 135 | } 136 | 137 | my @clist; 138 | if ($community =~ /^\d+:\d*([a-zA-Z\.]).*$/) { 139 | my $var1 = $1; 140 | $var1 .= "+" if ($var1 ne "."); 141 | $community =~ /^(\d+):(\d*)(($var1))(.*)$/; 142 | my $asnum = $1; 143 | my $commpref = $2; 144 | my $commvar = $3; 145 | my $commsuf = $5; 146 | 147 | my $varref; 148 | if ($commvar =~ /^[A-Z]+$/) { 149 | $varref = \%GLOBALVAR; 150 | } elsif ($commvar =~ /^[a-z]+$/) { 151 | $varref = \%LOCALVAR; 152 | } elsif ($commvar eq ".") { 153 | $varref = \%ANYNUM; 154 | } else { 155 | die "Illegal community variable \"$commvar\" in \"$community\""; 156 | } 157 | 158 | my $c = 0; 159 | foreach my $key (sort keys (%{$varref})) { 160 | if ($key !~ /^($commvar)=(.+)$/) { 161 | next; 162 | } 163 | my $repl = $2; 164 | my $newcomm = $asnum . ":" . $commpref . $repl . $commsuf; 165 | my $descr2 = ${$varref}{$key}; 166 | $descr2 = $key if ($commvar eq "."); 167 | (my $newdescr = $descr) =~ s/(\$$commvar)/$descr2/g; 168 | &complete_community($newcomm, $newdescr); 169 | $c++; 170 | } 171 | if ($c == 0) { 172 | die "$community - no match for \"$commvar\""; 173 | } 174 | return; 175 | } 176 | die "complete_community() called without proper pattern"; 177 | } 178 | -------------------------------------------------------------------------------- /makeaslist.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | &make_arin; 4 | &make_nic("RIPE", "ftp://ftp.ripe.net/ripe/dbase/split/ripe.db.aut-num.gz", "as-ripe.txt"); 5 | &make_nic("APNIC", "ftp://ftp.apnic.net/pub/whois-data/APNIC/split/apnic.db.aut-num.gz", "as-apnic.txt"); 6 | &make_nic("JPNIC", "ftp://ftp.apnic.net/pub/whois-data/JPNIC/split/jpnic.db.aut-num.gz", "as-jpnic.txt"); 7 | &make_lacnic; 8 | &make_afrinic; 9 | 10 | sub make_arin() { 11 | 12 | open (F1, "wget -q -O - ftp://ftp.arin.net/info/asn.txt |"); 13 | open (F2, "> as-arin.txt"); 14 | 15 | print F2 <) { 25 | chop; 26 | next if (/ APNIC-AS-\d+-BLOCK /); 27 | next if (/ APNIC-AS-BLOCK /); 28 | next if (/ APNIC-AS-X-BLOCK /); 29 | next if (/ RIPE-\d+ /); 30 | next if (/ RIPE-ASN?BLOCK-?\d+ /); 31 | next if (/ ASNBLK-RIPE /); 32 | next if (/ ASNBLK-RIPE-NCC /); 33 | next if (/ ASN-BLKRIPE\d+ /); 34 | next if (/ APNIC-\d+ /); 35 | next if (/ LACNIC-\d+ /); 36 | next if (/ AFRINIC-ASNBLOCK-\d+ /); 37 | if (/^\s*([\d\-]+)\s+(\S+)\s/) { 38 | my $autnum = $1; 39 | my $descr = $2; 40 | if ($autnum =~ /^(\d+)-(\d+)$/) { 41 | for (my $i = $1; $i <= $2; $i++) { 42 | printf(F2 "%5d\tARIN:%s\n", $i, $descr); 43 | } 44 | } else { 45 | printf(F2 "%5d\tARIN:%s\n", $autnum, $descr); 46 | } 47 | } else { 48 | next; 49 | } 50 | } 51 | 52 | close F2; 53 | close F1; 54 | } 55 | 56 | sub make_nic() { 57 | my ($nicprefix, $url, $filename) = @_; 58 | 59 | open (F1, "wget -q -O - $url | gunzip |"); 60 | 61 | my $autnum = ""; 62 | my $descr = ""; 63 | my $nic = $nicprefix; 64 | 65 | my @asnum; 66 | 67 | while () { 68 | chop; 69 | if (/^aut-num:\s+[Aa][Ss](\d+)$/) { 70 | $autnum = $1; 71 | next; 72 | } elsif (/^as-name:\s+(.*)$/) { 73 | next if ($1 eq "UNSPECIFIED"); 74 | $descr = $1 if ($descr eq ""); 75 | next; 76 | } elsif (/^descr:\s+(.*\w.*)$/) { 77 | next if ($autnum eq ""); 78 | $descr = $1 if ($descr eq ""); 79 | next; 80 | } elsif (/^mnt-by:\s+MNT-KRNIC-AP$/) { 81 | # Mark KRNIC records in the APNIC database 82 | $nic = 'KRNIC'; 83 | next; 84 | } elsif ($_ eq '') { 85 | # Write information to the $asnum array 86 | } else { 87 | next; 88 | } 89 | 90 | if ($autnum ne "") { 91 | $asnum[$autnum] = "$nic:$descr"; 92 | $autnum = ""; 93 | $name = ""; 94 | $descr = ""; 95 | $nic = $nicprefix; 96 | } else { 97 | print STDERR "missing aut-num for as-name [$1] in line $.\n"; 98 | } 99 | } 100 | 101 | close F1; 102 | 103 | open (F2, "> $filename"); 104 | 105 | print F2 <) { 134 | chop; 135 | if (/^owner:\s+(.+)$/) { 136 | $asowner = $1; 137 | last; 138 | } 139 | } 140 | 141 | close F35; 142 | 143 | return "$asowner, $country"; 144 | } 145 | 146 | sub make_lacnic() { 147 | open (F1, "wget -q -O - ftp://whois.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest |"); 148 | open (F2, "> as-lacnic.txt"); 149 | 150 | print F2 <) { 160 | chop; 161 | if (/^lacnic\|([A-Z][A-Z])\|asn\|(\d+)\|/) { 162 | printf(F2 "%5d\tLACNIC:%s\n", $2, &get_lacnic_as_desc($2, $1)); 163 | sleep(10); # LACNIC whois HTTP interface has a "query rate limit"... 164 | } 165 | } 166 | 167 | close F2; 168 | close F1; 169 | } 170 | 171 | sub get_afrinic_as_desc() { 172 | my $asn = $_[0]; 173 | my $country = $_[1]; 174 | my $asname = ''; 175 | my $asdescr = ''; 176 | 177 | # Note the "query" parameter MUST start with AS contrary to the LACNIC interface 178 | open (F35, "wget -q -O - \"http://www.afrinic.net/cgi-bin/whois?query=AS$asn\" |"); 179 | 180 | while () { 181 | chop; 182 | if (/^as-name:\s+(.+)$/) { 183 | $asname = $1; 184 | } 185 | elsif (/^descr:\s+(.+)$/ && ('' ne $asname)) { 186 | $asdescr = $1; 187 | last; 188 | } 189 | } 190 | 191 | close F35; 192 | 193 | my $descr = ('' ne $asdescr) ? $asdescr : $asname; 194 | $descr = '?' if ('' eq $descr); 195 | 196 | return "$descr, $country"; 197 | } 198 | 199 | sub make_afrinic() { 200 | 201 | open (F1, "wget -q -O - ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest |"); 202 | open (F2, "> as-afrinic.txt"); 203 | 204 | print F2 <) { 214 | chop; 215 | if (/^afrinic\|([A-Z][A-Z])\|asn\|(\d+)\|/) { 216 | printf(F2 "%5d\tAFRINIC:%s\n", $2, &get_afrinic_as_desc($2, $1)); 217 | } 218 | } 219 | 220 | close F2; 221 | close F1; 222 | } 223 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | 3 | SUMMARY 4 | 5 | 6 | LG is a Looking Glass written in Perl as a CGI script. It can execute almost 7 | all BGP-related commands and do ping and traceroute in routers or relay these 8 | queries to other looking glasses. It supports both IPv4 and IPv6 commands, 9 | and is tested with Cisco, Zebra and Juniper. It can connect to router using 10 | either SSH, telnet or rsh protocol. 11 | 12 | LG is released under GPL licence. Look at COPYING file. 13 | 14 | 15 | 16 | SECURITY 17 | 18 | 19 | It is suggested to move configuration file lg.conf outside of webserver 20 | direcory. One suitable place for that could be /usr/local/etc. Just move 21 | configuration to this directory and add full path to the $configfile 22 | variable in the beginning of lg.cgi. 23 | 24 | The default location of SSH configuration directory .ssh is initialized to 25 | the same directory where CGI is running: /usr/local/httpd/htdocs/lg. 26 | It is suggested to change $HOME enironment variable in the beginning 27 | of lg.cgi script to some other directory accessible by webserver (wwwrun 28 | for example) which is outside of default webserver root (in opensuse 29 | /var/lib/wwwrun can be used). It is srongly suggested to change this in 30 | case you are going to use key based authentication. 31 | 32 | 33 | INSTALL 34 | 35 | 36 | This example assumes that you use Apache webserver and LG will be installed 37 | to /usr/local/httpd/htdocs/lg directory. 38 | 39 | 40 | 1. Create directory where you want to keep LG files 41 | 42 | > mkdir /usr/local/httpd/htdocs/lg 43 | 44 | 2. Copy lg.cgi, lg.conf and favicon.ico to this directory, make CGI executable 45 | 46 | > cp lg.cgi lg.conf favicon.ico /usr/local/httpd/htdocs/lg 47 | > chmod 644 /usr/local/httpd/htdocs/lg/* 48 | > chmod 755 /usr/local/httpd/htdocs/lg/lg.cgi 49 | 50 | 3. Add these lines to your webserver config (In SuSE it is located at 51 | /etc/httpd/httpd.conf or /etc/httpd/suse_include.conf). The order of these 52 | lines is VERY IMPORTANT 53 | 54 | Alias /lg/favicon.ico /usr/local/httpd/htdocs/lg/favicon.ico 55 | ScriptAlias /lg /usr/local/httpd/htdocs/lg/lg.cgi 56 | 57 | 4. Restart webserver 58 | 59 | > killall -1 httpd 60 | 61 | 5. DONE! 62 | 63 | 6. Now you have time to set up AS num and community description files 64 | 65 | Download as.txt, as-apnic.txt, as-arin.txt, as-ripe.txt, as-jpnic.txt, 66 | as-lacnic.txt and communities.txt form http://www.version6.net/lg/db/ . 67 | Put all files to LG directory (/usr/local/httpd/htdocs/lg). 68 | 69 | > wget http://www.version6.net/lg/db/as.txt 70 | > wget http://www.version6.net/lg/db/as-apnic.txt 71 | > wget http://www.version6.net/lg/db/as-arin.txt 72 | > wget http://www.version6.net/lg/db/as-ripe.txt 73 | > wget http://www.version6.net/lg/db/as-jpnic.txt 74 | > wget http://www.version6.net/lg/db/as-lacnic.txt 75 | > wget http://www.version6.net/lg/db/communities.txt 76 | 77 | 7. If you prefer use Berkeley DB (you should! :-) ), then set up a database 78 | file. PS! you can't use community descriptions without using Berkeley DB. 79 | 80 | 7.1 Create db file yourself by running makedb.pl in LG directory: 81 | 82 | > ./makedb.pl 83 | 84 | or 85 | 86 | 7.2 Download as.db from http://www.version6.net/lg/db/ 87 | 88 | > wget http://www.version6.net/lg/db/as.db 89 | 90 | 8. Make sure that all these files are readable for webrserver 91 | 92 | > chmod a+r /usr/local/httpd/htdocs/lg/*.txt 93 | > chmod a+r /usr/local/httpd/htdocs/lg/as.db 94 | 95 | 96 | 97 | 98 | ADVANCED CONFIURATION 99 | 100 | 101 | You can generate as-*.txt files yourself. Just run Perl script makeaslist.pl 102 | and it creates these three files in your current directory. It is recommended 103 | to update these files sometimes to get fresh information about new AS numbers. 104 | Don't forget to run makedb.pl after that as well. 105 | 106 | You can also edit as.txt file. These three autogenerated files are included 107 | at the beginning of as.txt file. All lines below just overwrites previous 108 | ones. This means that you can put any better names for AS numbers to this file 109 | and will see it instead of these autogenerated names (which are quite hard to 110 | understand some times). 111 | 112 | Also you have to edit communities.txt file by hand. Don't forget to run 113 | makedb.pl after that again. 114 | 115 | A little bit about lg.conf file. In this example all logins are replaced with 116 | "login" and passwords with "password". These lines are also commented out, so 117 | you can use this configuration file even without any modification. 118 | 119 | You can set ASList as as.txt file or as.db database. With my 900 MHz Celeron 120 | it takes about 4 sec to load as.txt (and all included files) while using DB 121 | takes only 0.2 sec ;-) Use DB if possible! 122 | 123 | As long as the configuration file is quite simple, I don't give here any help 124 | how to configure LG. Just look at lg.conf, all possible ways how to configure 125 | it, are shown in this file already ;-) 126 | 127 | Default logfile is /var/log/lg.log, be sure that your webserver can write 128 | it or use any other file (or don't use at all). 129 | 130 | 131 | 132 | NOTES 133 | 134 | 135 | Don't try to use LG sites with newer DIGEX code as external LG sites. These 136 | will check Referer and therefore deny all outside links. 137 | 138 | There are also some LG sites which support only POST method and are also 139 | unusable. LG can forward browsers to any other address but can't send POST 140 | data with it. It is possible to act as proxy for these sites but this is not 141 | implemented yet and I'm not sure it is necessary at all. At least at the 142 | current moment ;-) 143 | 144 | When using Zebra you can specify one port for bgpd and another for zebra 145 | itself (ping and traceroute commands). All these syntaxes have the same 146 | meaning: 147 | 148 | - telnet://pass@host default ports (2601 and 2605) 149 | - telnet://pass@host:2601,2605 user defined ports 150 | - telnet://pass@host:2601, user defined zebra port and default bgpd port 151 | - telnet://pass@host:,2605 default zebra port and user defined bgpd port 152 | 153 | but these don't work as you expect (the same port for bgpd and zebra): 154 | 155 | - telnet://pass@host:2601 156 | - telnet://pass@host:2605 157 | 158 | "logical-system" works only with OSType="JunOS" and when using SSH. 159 | 160 | 161 | DOWNLOAD 162 | 163 | 164 | You can get the latest source from http://www.version6.net/ 165 | 166 | All new releases will be announced in Freshmeat (subscribe!) 167 | http://freshmeat.net/projects/lg/ 168 | 169 | 170 | 171 | Enjoy! 172 | 173 | --- 174 | Cougar 175 | -------------------------------------------------------------------------------- /lg.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | /lg/ 8 | /var/log/lg.log 9 | ./as.db 10 | /images/logo.gif 11 | Looking Glass 12 | /lg/favicon.ico 13 | cougar@random.ee 14 | /usr/bin/rsh -l lg 15 | POST 16 | 15 17 | All commands will be logged for possible later analysis and statistics. If you don't like this policy, please disconnect now! 18 | /var/www/.ssh/id_rsa 19 | /var/www/.ssh/id_rsa.pub 20 | On 21 | 22 | 23 | 30 | 31 | 63 | 64 | 65 | 66 | ISPs in Estonia 67 | 68 | 69 | Data Telecom (AS 3327) 70 | http://lg.version6.net/ 71 | 72 | 73 | 74 | http://cache2.online.ee:81/cgi-bin/nph-lg.pl 75 | 76 | 77 | 78 | EsData (AS 2380) 79 | https://laura.estnet.ee/lg 80 | 81 | 82 | 83 | 84 | Public peering points 85 | 86 | 87 | AMSIX 88 | http://www.ams-ix.net/cgi-bin/lg 89 | 90 | 91 | INXS peering LAN Munich 92 | http://noc.r-kom.de/cgi-bin/lg/lg.cgi 93 | 94 | 95 | http://www.linx.net/tools/stats/looking-glass.thtml 96 | 97 | 98 | http://www.linx.net/tools/stats/looking-glass.thtml 99 | 100 | 101 | http://www.linx.net/tools/stats/looking-glass.thtml 102 | 103 | 104 | BLNX 105 | http://routeserver.blnx.net/lg/ 106 | 107 | 108 | 111 | 112 | 113 | 114 | RIPE (AS 3292) 115 | 116 | 117 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 118 | 119 | 120 | 121 | 122 | TDC Tele Danmark (AS 3292) 123 | 124 | 125 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 126 | 127 | 128 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 129 | 130 | 131 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 132 | 133 | 134 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 135 | 136 | 137 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 138 | 139 | 140 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 141 | 142 | 143 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 144 | 145 | 146 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 147 | 148 | 149 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 150 | 151 | 152 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 153 | 154 | 155 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 156 | 157 | 158 | http://noc.tele.dk/cgi-bin/looking_glass.cgi 159 | 160 | 161 | 162 | 163 | KPNQwest (AS 286) 164 | 165 | 166 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 167 | 168 | 169 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 170 | 171 | 172 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 173 | 174 | 175 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 176 | 177 | 178 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 179 | 180 | 181 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 182 | 183 | 184 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 185 | 186 | 187 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 188 | 189 | 190 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 191 | 192 | 193 | http://statistics.kpnqwest.net/cgi-bin/lookingglass.cgi 194 | 195 | 196 | 197 | 198 | NORDUnet (AS 2603) 199 | 200 | 201 | http://www.nordu.net/connectivity/looking-glass/lg.cgi 202 | 203 | 204 | http://www.nordu.net/connectivity/looking-glass/lg.cgi 205 | 206 | 207 | 208 | 209 | Other LGs 210 | 211 | 212 | http://www.zimage.delbg.com/cgi-bin/lg.cgi 213 | 214 | 215 | http://lg.he.net/cgi-bin/index.cgi 216 | 217 | 218 | 219 | Routeservers 220 | 221 | 222 | telnet://ner-routes.bbnplanet.net 223 | 224 | 225 | telnet://route-server.ip.att.net 226 | 227 | 228 | telnet://route-server.cerf.net 229 | 230 | 231 | telnet://route-server.gblx.net 232 | 233 | 234 | telnet://route-views.oregon-ix.net 235 | 236 | 237 | telnet://route-server.as5388.net 238 | 239 | 240 | telnet://route-server.colt.net 241 | 242 | 243 | telnet://ch-views.swinog.ch 244 | 245 | 246 | telnet://route-server.exodus.net 247 | 248 | 249 | telnet://route-server-ap.exodus.net 250 | 251 | 252 | telnet://route-server-eu.exodus.net 253 | 254 | 255 | telnet://zebra.swinog.ch 256 | 257 | 258 | telnet://route-server.ip.tiscali.net 259 | 260 | 261 | telnet://route-views.on.bb.telus.com 262 | 263 | 264 | telnet://route-server.gt.ca 265 | 266 | 267 | telnet://route-server.gblx.net 268 | 269 | 270 | telnet://route-server.opentransit.net 271 | 272 | 273 | telnet://route-server.gt.ca 274 | 275 | 276 | 277 | 278 | IPv6 LGs 279 | 280 | 281 | http://lg.version6.net/ 282 | 283 | 284 | http://www.6tap.net/cgi-bin/6tap-lg.cgi 285 | 286 | 287 | http://www.ipv6.lava.net/cgi-bin/lg.pl 288 | 289 | 290 | iTk 291 | http://www.ipv6.pl/cgi-bin/lg/lg.cgi 292 | 293 | 294 | http://www.ipv6.edisontel.it/cgi-bin/lg.cgi 295 | 296 | 297 | 298 | 299 | 300 | cmd=bgpsummary 301 | cmd 302 | host 303 | timeout=20 304 | 305 | 306 | cmd=bgpsummary 307 | cmd 308 | host 309 | timeout=20 310 | 311 | 312 | query_type=+BGP 313 | query_type=+BGP+Summary 314 | query_type=+Ping 315 | query_type=+Trace 316 | address 317 | 318 | site=LINX-London 319 | site=LINX-Transit 320 | site=LINX-Multicast 321 | run=true&.submit=Submit+Query&.cgifields=query_type 322 | 323 | 324 | host=br1-atl2" 325 | 326 | 327 | query=show+ip+bgp 328 | query=show+ip+bgp+summary 329 | query=traceroute 330 | 331 | router=amsixnxg1 332 | router=lynxg1 333 | router=virnxg2 334 | router=ffm2nxg1 335 | router=ldn2nxg1 336 | router=ldn2nxg2 337 | router=NewYorknxi1 338 | router=NewYork2nxg1 339 | router=NewYork2nxg2 340 | router=osl-nyd-cr1 341 | router=osl-prg-cr1 342 | router=stkm1nxg1 343 | 344 | 345 | cmd=bgp 346 | cmd=bgpsummary 347 | query=ping 348 | query=trace 349 | 350 | router=amsterdam 351 | router=antwerp 352 | router=berlin 353 | router=brussels 354 | router=dublin 355 | router=frankfurt 356 | router=leiden 357 | router=london 358 | router=munich 359 | router=rotterdam 360 | 361 | 362 | query=bgp+summary 363 | arg 364 | router=ne-gw.nordu.net 365 | router=west-gw.nordu.net 366 | 367 | 368 | cmd=BGP 369 | cmd=BGP+summary 370 | cmd=Ping 371 | cmd=Traceroute 372 | host=New+York,+NY&proto=IPv4-unicast&mult=off 373 | 374 | 375 | command=003 376 | command=005 377 | command=009 378 | command=011 379 | arguments 380 | submit=Submit 381 | 382 | 383 | query=1 384 | query=2 385 | query=8 386 | query=7 387 | arg 388 | router=router1 389 | 390 | 391 | router=gw2-bgpd 392 | query=bgp%20summary 393 | submit=Submit 394 | 395 | 396 | query=bgpsum 397 | address 398 | query=bgp6 399 | query=bgp6sum 400 | query=trace6 401 | query=ping6 402 | 403 | router=router-center.delbg.com 404 | 405 | 406 | query=bgp4 407 | query=bgp4sum 408 | query=tracert 409 | 410 | 411 | 412 | 413 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 675 Mass Ave, Cambridge, MA 02139, USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 19yy 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) 19yy name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Library General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /lg.cgi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # Looking Glass CGI with ssh, telnet, rexec and remote LG support 4 | # with IPv4 and IPv6 support 5 | # 6 | # Copyright (C) 2000-2014 Cougar 7 | # http://www.version6.net/ 8 | # 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | # 23 | 24 | use strict qw(subs vars); 25 | 26 | $configfile = "lg.conf"; 27 | $ENV{HOME} = "."; # SSH needs access for $HOME/.ssh 28 | 29 | use XML::Parser; 30 | 31 | my $SYS_progid = '$Id: lg.cgi,v 1.30 2004/11/25 14:12:42 cougar Exp $'; 32 | 33 | my $default_ostype = "ios"; 34 | 35 | my $lgurl; 36 | my $logfile; 37 | my $asfile; 38 | my $logoimage; 39 | my $logoalign; 40 | my $logolink; 41 | my $title; 42 | my $favicon; 43 | my $email; 44 | my $rshcmd; 45 | my $ipv4enabled; 46 | my $ipv6enabled; 47 | my $httpmethod = "POST"; 48 | my $timeout; 49 | my $disclaimer; 50 | my $securemode = 1; 51 | my $ssh2key; 52 | my $ssh2pubkey; 53 | 54 | my %router_list; 55 | my @routers; 56 | my %namemap; 57 | my %ostypes; 58 | my %logicalsystem; 59 | my %cmdmap; 60 | 61 | my $default_router; 62 | 63 | my $xml_current_router_name = ""; 64 | my $xml_current_cgi_name = ""; 65 | my $xml_current_replace_name = ""; 66 | my $xml_current_replace_proto = ""; 67 | 68 | my %valid_query = ( 69 | "ios" => { 70 | "ipv4" => { 71 | "bgp" => "show ip bgp %s", 72 | "advertised-routes" => "show ip bgp neighbors %s advertised-routes", 73 | "summary" => "show ip bgp summary", 74 | "ping" => "ping %s", 75 | "trace" => "traceroute %s" 76 | }, 77 | "ipv6" => { 78 | "bgp" => "show bgp ipv6 %s", 79 | "advertised-routes" => "show bgp ipv6 neighbors %s advertised-routes", 80 | "summary" => "show bgp ipv6 summary", 81 | "ping" => "ping ipv6 %s", 82 | "trace" => "traceroute ipv6 %s" 83 | } 84 | }, 85 | "zebra" => { 86 | "ipv4" => { 87 | "bgp" => "show ip bgp %s", 88 | "advertised-routes" => "show ip bgp neighbors %s advertised-routes", 89 | "summary" => "show ip bgp summary", 90 | "ping" => "ping %s", 91 | "trace" => "traceroute %s" 92 | }, 93 | "ipv6" => { 94 | "bgp" => "show bgp ipv6 %s", 95 | "advertised-routes" => "show bgp ipv6 neighbors %s advertised-routes", 96 | "summary" => "show bgp ipv6 summary", 97 | "ping" => "ping ipv6 %s", 98 | "trace" => "traceroute ipv6 %s" 99 | } 100 | }, 101 | "junos" => { 102 | "ipv4" => { 103 | "trace" => "traceroute %s as-number-lookup" 104 | }, 105 | "ipv6" => { 106 | "trace" => "traceroute %s" 107 | }, 108 | "ipv46" => { 109 | "bgp" => "show bgp %s", 110 | "advertised-routes" => "show route advertising-protocol bgp %s %s", 111 | "summary" => "show bgp summary", 112 | "ping" => "ping count 5 %s" 113 | } 114 | } 115 | ); 116 | 117 | my %whois = ( 118 | "RIPE" => "http://www.ripe.net/perl/whois?AS%s", 119 | "ARIN" => "http://www.arin.net/cgi-bin/whois.pl?queryinput=%s", 120 | "APNIC" => "http://www.apnic.net/apnic-bin/whois.pl?searchtext=AS%s", 121 | "default" => "http://www.sixxs.net/tools/whois/?AS%s" 122 | ); 123 | 124 | $| = 1; 125 | 126 | &read_config; 127 | 128 | # grab CGI data 129 | my $incoming; 130 | if ($ENV{'REQUEST_METHOD'} eq "POST") { 131 | read(STDIN, $incoming, $ENV{'CONTENT_LENGTH'}); 132 | } else { 133 | $incoming = $ENV{'QUERY_STRING'}; 134 | } 135 | my %FORM = &cgi_decode($incoming); 136 | 137 | my $date = localtime; 138 | if ($logfile ne "") { 139 | open(LOG, ">>$logfile"); 140 | ($ENV{REMOTE_HOST}) && ( print LOG "$ENV{'REMOTE_HOST'} "); 141 | ($ENV{REMOTE_ADDR}) && ( print LOG "$ENV{'REMOTE_ADDR'} "); 142 | print LOG "- - [$date]"; 143 | ($ENV{HTTP_REFERER}) && ( print LOG " $ENV{'HTTP_REFERER'}"); 144 | } 145 | 146 | my $query_cmd = ""; 147 | 148 | if (defined $valid_query{$ostypes{$FORM{router}}}{"ipv46"}{$FORM{query}}) { 149 | $query_cmd = $valid_query{$ostypes{$FORM{router}}}{"ipv46"}{$FORM{query}}; 150 | } elsif (defined $valid_query{$ostypes{$FORM{router}}}{lc($FORM{protocol})}{$FORM{query}}) { 151 | $query_cmd = $valid_query{$ostypes{$FORM{router}}}{lc($FORM{protocol})}{$FORM{query}}; 152 | } elsif (($FORM{router} ne "") || ($FORM{protocol} ne "") || ($FORM{query})) { 153 | if ($logfile ne "") { 154 | print LOG " \"$FORM{router}\" \"ILLEGAL QUERY: [$ostypes{$FORM{router}}] [$FORM{protocol}] [$FORM{query}]\"\n"; 155 | close(LOG); 156 | } 157 | &print_head; 158 | &print_form; 159 | &print_tail; 160 | exit; 161 | } 162 | 163 | if ((! defined $router_list{$FORM{router}}) || 164 | ($query_cmd eq "")) { 165 | if ($logfile ne "") { 166 | print LOG "\n"; 167 | close(LOG); 168 | } 169 | &print_head; 170 | &print_form; 171 | &print_tail; 172 | exit; 173 | } 174 | 175 | $FORM{addr} =~ s/\s.*// if (($FORM{query} eq "ping") || ($FORM{query} eq "trace")); 176 | $FORM{addr} =~ s/[^\s\d\.:\w\-_\/\$]//g; 177 | 178 | if ($router_list{$FORM{router}} =~ /^http[s]{0,1}:/) { 179 | if ($logfile ne "") { 180 | print LOG " \"$FORM{router}\" \"$FORM{query}" . ($FORM{addr} ne "" ? " $FORM{addr}" : "") . "\"\n"; 181 | close LOG; 182 | } 183 | if ($router_list{$FORM{router}} =~ /\?/) { 184 | $incoming = "&$incoming"; 185 | } else { 186 | $incoming = "?$incoming"; 187 | } 188 | my $remote = $router_list{$FORM{router}}; 189 | if (defined $cmdmap{$remote}{lc($FORM{protocol})}) { 190 | $incoming .= "&"; 191 | my $mapref = $cmdmap{$remote}{lc($FORM{protocol})}; 192 | foreach my $key (keys (%{$mapref})) { 193 | next if ($key eq "DEFAULT"); 194 | (my $urlkey = $key) =~ s/([+*\/\\])/\\$1/g; 195 | if (${$mapref}{$key} eq "") { 196 | $incoming =~ s/([\?\&])($urlkey)=[^\&]*\&/$1/g; 197 | } elsif (${$mapref}{$key} =~ /=/) { 198 | $incoming =~ s/([\?\&])($urlkey)\&/"${1}${$mapref}{$2}&"/e; 199 | } 200 | } 201 | foreach my $key (keys (%{$mapref})) { 202 | next if ($key eq "DEFAULT"); 203 | $incoming =~ s/([\?\&])($key)=/"${1}${$mapref}{$2}="/e; 204 | } 205 | $incoming =~ s|&$||g; 206 | if (defined ${$mapref}{DEFAULT}) { 207 | $incoming .= "&${$mapref}{DEFAULT}"; 208 | } 209 | } 210 | print "Location: $router_list{$FORM{router}}${incoming}\n\n"; 211 | exit; 212 | } 213 | 214 | my $command = sprintf($query_cmd, $FORM{addr}); 215 | 216 | print LOG " \"$FORM{router}\" \"$command\"\n"; 217 | close LOG; 218 | 219 | &print_head($command); 220 | 221 | if ($FORM{addr} !~ /^[\w\.\^\$\-\/ ]*$/) { 222 | if ($FORM{addr} =~ /^[\w\.\^\$\-\:\/ ]*$/) { 223 | if (($FORM{protocol} ne "IPv6") && ($ostypes{$FORM{router}} ne "junos")){ 224 | &print_error("ERROR: IPv6 address for IPv4 query"); 225 | } 226 | } else { 227 | &print_error("Illegal characters in parameter string"); 228 | } 229 | } 230 | 231 | $FORM{addr} = "" if ($FORM{addr} =~ /^[ ]*$/); 232 | 233 | if ($query_cmd =~ /%s/) { 234 | &print_error("Parameter missing") if ($FORM{addr} eq ""); 235 | } else { 236 | &print_warning("No parameter needed") if ($FORM{addr} ne ""); 237 | } 238 | 239 | my %AS; 240 | if ($asfile =~ /\.db$/) { 241 | use DB_File; 242 | tie (%AS, 'DB_File', $asfile, O_RDONLY, 0644, $DB_HASH) or 243 | print STDERR "Can\'t read AS database $asfile: $!\n"; 244 | } else { 245 | %AS = &read_as_list($asfile); 246 | } 247 | 248 | my $table; 249 | $table = "table inet.0" if ($FORM{protocol} eq "IPv4"); 250 | $table = "table inet6.0" if ($FORM{protocol} eq "IPv6"); 251 | 252 | if ($ostypes{$FORM{router}} eq "junos") { 253 | if ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+)$/) { 254 | # show bgp n.. ---> show bgp neighbor 255 | $command = "show bgp neighbor $1"; 256 | } elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+) ro\w*$/) { 257 | # show bgp n.. ro.. ---> show route receive-protocol bgp 258 | $command = "show route receive-protocol bgp $1 $table"; 259 | } elsif ($command =~ /^show bgp neighbors ([\d\.A-Fa-f:]+) routes all$/) { 260 | # show bgp neighbors routes all ---> show route receive-protocol bgp all 261 | $command = "show route receive-protocol bgp $1 all $table"; 262 | } elsif ($command =~ /^show bgp neighbors ([\d\.A-Fa-f:]+) routes damping suppressed$/) { 263 | # show bgp neighbors routes damping suppressed ---> show route receive-protocol bgp damping suppressed 264 | $command = "show route receive-protocol bgp $1 damping suppressed $table"; 265 | } elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+) advertised-routes ([\d\.A-Fa-f:\/]+)$/) { 266 | # show ip bgp n.. advertised-routes ---> show route advertising-protocol bgp exact detail 267 | $command = "show route advertising-protocol bgp $1 $2 exact detail $table"; 268 | } elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+) receive-protocol ([\d\.A-Fa-f:\/]+)$/) { 269 | # show ip bgp n.. receive-protocol ---> show route receive-protocol bgp exact detail 270 | $command = "show route receive-protocol bgp $1 $2 exact detail $table"; 271 | } elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+) a[\w\-]*$/) { 272 | # show ip bgp n.. a.. ---> show route advertising-protocol bgp 273 | $command = "show route advertising-protocol bgp $1 $table"; 274 | } elsif ($command =~ /^show bgp\s+([\d\.A-Fa-f:]+\/\d+)$/) { 275 | # show bgp /mask ---> show route protocol bgp all 276 | $command = "show route protocol bgp $1 terse exact all $table"; 277 | } elsif ($command =~ /^show bgp\s+([\d\.A-Fa-f:]+)$/) { 278 | # show bgp ---> show route protocol bgp all 279 | $command = "show route protocol bgp $1 terse $table"; 280 | } elsif ($command =~ /^show bgp\s+([\d\.A-Fa-f:\/]+) exact$/) { 281 | # show bgp exact ---> show route protocol bgp exact detail all 282 | $command = "show route protocol bgp $1 exact detail all $table"; 283 | } elsif ($command =~ /^show bgp re\w*\s+(.*)$/) { 284 | # show ip bgp re ---> show route aspath-regex all 285 | my $re = $1; 286 | $re = ".*${re}" if ($re !~ /^\^/); 287 | $re = "${re}.*" if ($re !~ /\$$/); 288 | $re =~ s/_/ /g; 289 | $command = "show route protocol bgp aspath-regex \"$re\" all $table terse"; 290 | } 291 | } 292 | 293 | &run_command($FORM{router}, $router_list{$FORM{router}}, $command); 294 | 295 | &print_tail; 296 | exit; 297 | 298 | sub read_config { 299 | my $xp = new XML::Parser(ProtocolEncoding => "ISO-8859-1", Handlers => {Char => \&xml_charparse, Start => \&xml_startparse, End => \&xml_endparse}); 300 | $xp->parsefile($configfile); 301 | undef($xp); 302 | } 303 | 304 | sub xml_charparse { 305 | my ($xp,$str) = @_; 306 | return if $str =~ /^\s*$/m; 307 | my $elem = lc($xp->current_element); 308 | if ($xml_current_router_name ne "") { 309 | if ($elem eq "url") { 310 | $router_list{$xml_current_router_name} = $str; 311 | push @routers, $xml_current_router_name; 312 | } elsif ($elem eq "title") { 313 | $namemap{$xml_current_router_name} .= $str; 314 | } else { 315 | die("Illegal value for configuration tag \"" . $xp->current_element . "\" at line " . $xp->current_line . ", column " . $xp->current_column); 316 | } 317 | } elsif (($xml_current_cgi_name ne "") && ($xml_current_replace_name ne "")) { 318 | if (($elem eq "replace") || 319 | ($elem eq "default")) { 320 | $cmdmap{$xml_current_cgi_name}{"ipv4"}{$xml_current_replace_name} .= $str if ($xml_current_replace_proto ne "ipv6"); 321 | $cmdmap{$xml_current_cgi_name}{"ipv6"}{$xml_current_replace_name} .= $str if ($xml_current_replace_proto ne "ipv4"); 322 | } else { 323 | die("Illegal value for configuration tag \"" . $xp->current_element . "\" at line " . $xp->current_line . ", column " . $xp->current_column); 324 | } 325 | } elsif ($elem eq "lgurl") { 326 | $lgurl = $str; 327 | } elsif ($elem eq "logfile") { 328 | $logfile = $str; 329 | } elsif ($elem eq "aslist") { 330 | $asfile = $str; 331 | } elsif ($elem eq "logoimage") { 332 | $logoimage = $str; 333 | } elsif ($elem eq "htmltitle") { 334 | $title = $str; 335 | } elsif ($elem eq "favicon") { 336 | $favicon = $str; 337 | } elsif ($elem eq "contactmail") { 338 | $email = $str; 339 | } elsif ($elem eq "rshcmd") { 340 | $rshcmd = $str; 341 | } elsif ($elem eq "httpmethod") { 342 | $httpmethod = $str; 343 | } elsif ($elem eq "timeout") { 344 | $timeout = $str; 345 | } elsif ($elem eq "disclaimer") { 346 | $disclaimer = "
Disclaimer: $str
\n"; 347 | } elsif ($elem eq "securemode") { 348 | if ($str =~ /^(0|off|no)$/i) { 349 | $securemode = 0; 350 | } elsif ($str =~ /^(1|on|yes)$/i) { 351 | $securemode = 1; 352 | } else { 353 | die("Illegal securemode \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column); 354 | } 355 | } elsif ($elem eq "separator") { 356 | push @routers, "---- $str ----"; 357 | } elsif ($elem eq "ssh2key") { 358 | $ssh2key = $str; 359 | } elsif ($elem eq "ssh2pubkey") { 360 | $ssh2pubkey = $str; 361 | } else { 362 | print "\n"; 363 | } 364 | } 365 | 366 | sub xml_startparse { 367 | my ($xp,$str,@attrval) = @_; 368 | my $elem = lc($xp->current_element); 369 | my $str2 = lc($str); 370 | if ($elem eq "") { 371 | if ($str2 ne "lg_conf_file") { 372 | die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column); 373 | } 374 | } elsif ($elem eq "lg_conf_file") { 375 | if ($str2 eq "logoimage") { 376 | for (my $i = 0; $i <= $#attrval; $i += 2) { 377 | if (lc($attrval[$i]) eq "align") { 378 | $logoalign = " Align=\"" . $attrval[$i+1] . "\""; 379 | } elsif (lc($attrval[$i]) eq "link") { 380 | $logolink = $attrval[$i+1]; 381 | } else { 382 | die("Illegal parameter for LogoImage \"" . $attrval[$i] . "\" at line " . $xp->current_line . ", column " . $xp->current_column); 383 | } 384 | } 385 | } elsif (($str2 ne "lgurl") && 386 | ($str2 ne "logfile") && 387 | ($str2 ne "aslist") && 388 | ($str2 ne "htmltitle") && 389 | ($str2 ne "favicon") && 390 | ($str2 ne "contactmail") && 391 | ($str2 ne "rshcmd") && 392 | ($str2 ne "httpmethod") && 393 | ($str2 ne "timeout") && 394 | ($str2 ne "disclaimer") && 395 | ($str2 ne "securemode") && 396 | ($str2 ne "ssh2key") && 397 | ($str2 ne "ssh2pubkey") && 398 | ($str2 ne "router_list") && 399 | ($str2 ne "argument_list")) { 400 | die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column); 401 | } 402 | } elsif ($elem eq "router_list") { 403 | if ($str2 eq "router") { 404 | for (my $i = 0; $i <= $#attrval; $i += 2) { 405 | if (lc($attrval[$i]) eq "name") { 406 | $xml_current_router_name = $attrval[$i+1]; 407 | $ostypes{$xml_current_router_name} = lc($default_ostype); 408 | $ipv4enabled ++; 409 | } elsif (lc($attrval[$i]) eq "default") { 410 | if (lc($attrval[$i+1]) eq "yes") { 411 | $default_router = $xml_current_router_name; 412 | } 413 | } elsif (lc($attrval[$i]) eq "enableipv6") { 414 | if (lc($attrval[$i+1]) eq "yes") { 415 | $ipv4enabled--; 416 | $ipv6enabled++; 417 | } 418 | } elsif (lc($attrval[$i]) eq "ostype") { 419 | $ostypes{$xml_current_router_name} = lc($attrval[$i+1]); 420 | } elsif (lc($attrval[$i]) eq "logical-system") { 421 | $logicalsystem{$xml_current_router_name} = lc($attrval[$i+1]); 422 | } 423 | } 424 | if ($xml_current_router_name eq "") { 425 | die("Variable \"Name\" missing at line " . $xp->current_line . ", column " . $xp->current_column); 426 | } 427 | } elsif ($str2 eq "separator") { 428 | } else { 429 | die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column); 430 | } 431 | } elsif ($elem eq "router") { 432 | if (($str2 ne "title") && 433 | ($str2 ne "url")) { 434 | die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column); 435 | } 436 | } elsif ($elem eq "argument_list") { 437 | if ($str2 eq "lg") { 438 | for (my $i = 0; $i <= $#attrval; $i += 2) { 439 | if (lc($attrval[$i]) eq "url") { 440 | $xml_current_cgi_name = $attrval[$i+1]; 441 | } 442 | } 443 | if ($xml_current_cgi_name eq "") { 444 | die("Variable \"URL\" missing at line " . $xp->current_line . ", column " . $xp->current_column); 445 | } 446 | } else { 447 | die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column); 448 | } 449 | } elsif ($elem eq "lg") { 450 | if ($str2 eq "replace") { 451 | for (my $i = 0; $i <= $#attrval; $i += 2) { 452 | if (lc($attrval[$i]) eq "param") { 453 | $xml_current_replace_name = $attrval[$i+1]; 454 | } elsif (lc($attrval[$i]) eq "proto") { 455 | $xml_current_replace_proto = lc($attrval[$i+1]); 456 | } 457 | } 458 | if ($xml_current_replace_name eq "") { 459 | die("Variable \"Param\" missing at line " . $xp->current_line . ", column " . $xp->current_column); 460 | } 461 | $cmdmap{$xml_current_cgi_name}{"ipv4"}{$xml_current_replace_name} = "" if ($xml_current_replace_proto ne "ipv6"); 462 | $cmdmap{$xml_current_cgi_name}{"ipv6"}{$xml_current_replace_name} = "" if ($xml_current_replace_proto ne "ipv4"); 463 | } elsif ($str2 eq "default") { 464 | $xml_current_replace_name = "DEFAULT"; 465 | } else { 466 | die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column); 467 | } 468 | } else { 469 | die("ASSERT str=\"$str\" elem=\"" . $xp->current_element . "\" at line " . $xp->current_line . ", column " . $xp->current_column); 470 | 471 | } 472 | } 473 | 474 | sub xml_endparse { 475 | my ($xp,$str) = @_; 476 | my $elem = lc($xp->current_element); 477 | my $str2 = lc($str); 478 | 479 | if ($elem eq "router_list") { 480 | if ($str2 eq "router") { 481 | $xml_current_router_name = ""; 482 | } 483 | } elsif ($elem eq "lg") { 484 | if (($str2 eq "replace") || 485 | ($str2 eq "default")) { 486 | $xml_current_replace_name = ""; 487 | $xml_current_replace_proto = ""; 488 | } 489 | } 490 | } 491 | 492 | sub print_head { 493 | my ($arg) = @_; 494 | my ($titlestr) = $title; 495 | $titlestr .= " - $arg" if ($arg ne ""); 496 | print "Content-type: text/html; charset=utf-8\n\n"; 497 | print "\n"; 498 | print "\n"; 499 | print "\n"; 500 | print "\n"; 501 | print "$titlestr\n"; 502 | if ($favicon ne "") { 503 | print "\n"; 504 | } 505 | print "\n"; 506 | print "\n"; 507 | print "\n"; 508 | print "\n"; 509 | print "\n"; 510 | if ($logoimage ne "") { 511 | print ""; 512 | print "" if ($logolink ne ""); 513 | print "\"LG\""; 514 | print "" if ($logolink ne ""); 515 | print "
\n"; 516 | } 517 | print "
\n"; 518 | print "

$titlestr

\n"; 519 | print "
\n"; 520 | print "

\n"; 521 | print "


\n"; 522 | print "

\n"; 523 | } 524 | 525 | sub print_form { 526 | if ($httpmethod eq "GET") { 527 | print "

\n"; 528 | } else { 529 | print "\n"; 530 | } 531 | print < 533 |
534 | 535 | 536 | 537 | 538 | 539 |
Type of QueryAdditional parametersNode
540 | 541 | 542 | 543 | 544 | 545 | 546 | EOT 547 | if ($ipv4enabled && $ipv6enabled) { 548 | print < 553 |
 bgp
 bgp advertised-routes
 bgp summary
 ping
 trace
554 | EOT 555 | } elsif ($ipv4enabled) { 556 | print "
\n\n"; 557 | } elsif ($ipv6enabled) { 558 | print "
\n\n"; 559 | } 560 | print < 562 |  

    563 |  
| 608 |

609 | 610 | 611 | 612 | 613 |

614 |

615 | EOT 616 | } 617 | 618 | sub print_tail { 619 | print < 621 |
622 | $disclaimer 623 |

624 |

625 | Please email questions or comments to $email. 626 |

627 |

628 | 629 | 630 | EOT 631 | } 632 | 633 | sub print_error 634 | { 635 | print "
" . join(" ", @_) . "
\n"; 636 | &print_tail; 637 | exit 1; 638 | } 639 | 640 | sub print_warning 641 | { 642 | print "
WARNING! " . join(" ", @_) . "
\n"; 643 | print < 645 |
646 |

647 | EOT 648 | } 649 | 650 | my $regexp = 0; 651 | 652 | sub run_command 653 | { 654 | my ($hostname, $host, $command) = @_; 655 | my $best = 0; 656 | my $count = 0; 657 | my $telnet; 658 | my $ssh; 659 | my $ssh2; 660 | my @output; 661 | # This regexp is from RFC 2396 - URI Generic Syntax 662 | if ($host !~ /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/) { 663 | die ("Illegal URI: \"$host\""); 664 | } 665 | my $scheme = $2; 666 | $host = $4; 667 | if ($host !~ /^((([^:\@\[]+)(:([^\@]+))?)\@)?([^\/?#]*)$/) { 668 | die ("Can't extract login/pass from host: \"$host\""); 669 | } 670 | my $login = $3; 671 | my $password = $5; 672 | $host = $6; 673 | my $port; 674 | if ($host =~ /^\[(.+)\](:([\d,]+))?$/) { 675 | $host = $1; 676 | $port = $3; 677 | } elsif ($host =~ /^([^:]+)(:([\d,]+))?$/) { 678 | $host = $1; 679 | $port = $3; 680 | } else { 681 | die ("Illegal host address \"$host\""); 682 | } 683 | 684 | print "Router: " . html_encode($hostname) . "\n"; 685 | print "
\n"; 686 | print "Command: " . html_encode($command) . "\n"; 687 | print "

\n";
 688 | 
 689 | 	if (($command =~ /show route protocol bgp aspath-regex \"(.*)\"/) ||
 690 | 	    ($command =~ /show ip bgp reg\w*\s+(.*)/)) {
 691 | 		$regexp = $1;
 692 | 	}
 693 | 
 694 | 	if ($scheme eq "rsh") {
 695 | 		print_error("Configuration error, missing rshcmd") if ($rshcmd eq "");
 696 | 		open(P, "$rshcmd $host \'$command\' |");
 697 | 		while (

) { 698 | showlines($_); 699 | } 700 | close(P); 701 | } elsif ($scheme eq "ssh") { 702 | eval " 703 | use IO::Handle; 704 | use Net::SSH::Perl; 705 | use Net::SSH::Perl::Cipher; 706 | "; 707 | die $@ if $@; 708 | my $remotecmd = "$command; quit"; 709 | $remotecmd = "set cli logical-system $logicalsystem{$FORM{router}}; " . $command if (defined $logicalsystem{$FORM{router}}); 710 | $port = 22 if ($port eq ""); 711 | my $ssh = Net::SSH::Perl->new($host, port => $port); 712 | if ($] > 5.007) { 713 | require Encode; 714 | $login = Encode::encode_utf8($login); 715 | $password = Encode::encode_utf8($password); 716 | $remotecmd = Encode::encode_utf8($remotecmd); 717 | } 718 | $ssh->login($login, $password); 719 | $ssh->register_handler('stdout', sub { showlines($_[1]->bytes); }); 720 | $ssh->register_handler('stderr', sub { showlines($_[1]->bytes); }); 721 | $ssh->cmd("$remotecmd"); 722 | } elsif ($scheme eq "ssh2") { 723 | eval " 724 | use Net::SSH2; 725 | "; 726 | die $@ if $@; 727 | my $remotecmd = "$command; quit"; 728 | $remotecmd = "set cli logical-system $logicalsystem{$FORM{router}}; " . $command if (defined $logicalsystem{$FORM{router}}); 729 | $port = 22 if ($port eq ""); 730 | $ssh2 = Net::SSH2->new(); 731 | $ssh2->connect($host, $port) or die $!; 732 | if ($password) { 733 | $ssh2->auth_password($login, $password); 734 | } else { 735 | $ssh2->auth_publickey($login, $ssh2pubkey, $ssh2key); 736 | } 737 | my $chan = $ssh2->channel(); 738 | $chan->blocking(1); 739 | $chan->exec("$remotecmd"); 740 | while ($chan->read($_, 1024)) { 741 | showlines($_); 742 | }; 743 | $chan->close; 744 | } elsif ($scheme eq "telnet") { 745 | my @output; 746 | eval " 747 | use Net::Telnet; 748 | "; 749 | die $@ if $@; 750 | if ($ostypes{$FORM{router}} eq "zebra") { 751 | if (($command =~ /^ping /) || ($command =~ /^traceroute /)) { 752 | $port = $1 if ($port =~ /^(\d+),\d*$/); 753 | $port = 2601 if ($port eq ""); 754 | } else { 755 | $port = $1 if ($port =~ /^\d*,(\d+)$/); 756 | $port = 2605 if ($port eq ""); 757 | } 758 | } 759 | $port = 23 if ($port eq ""); 760 | my $telnet = new Net::Telnet; 761 | $telnet->errmode( sub { print "ERROR:" . join('|', @_) . "\n"; } ); 762 | $telnet->timeout($timeout); 763 | $telnet->option_callback( sub { return; } ); 764 | $telnet->option_accept(Do => 31); # TELOPT_NAWS 765 | $telnet->open(Host => $host, 766 | Port => $port); 767 | 768 | if ($login ne "") { 769 | $telnet->waitfor('/(ogin|name|word):.*$/'); 770 | $telnet->print("$login"); 771 | } 772 | if ($password ne "") { 773 | $telnet->waitfor('/word:.*$/'); 774 | $telnet->print("$password"); 775 | } 776 | 777 | $telnet->waitfor(Match => '/.*[\$%>] {0,1}$/', 778 | Match => '/^[^#]*[\$%#>] {0,1}$/'); 779 | 780 | $telnet->telnetmode(0); 781 | $telnet->put(pack("C9", 782 | 255, # TELNET_IAC 783 | 250, # TELNET_SB 784 | 31, 0, 200, 0, 0, # TELOPT_NAWS 785 | 255, # TELNET_IAC 786 | 240)); # TELNET_SE 787 | $telnet->telnetmode(1); 788 | 789 | my $telnetcmd = $command; 790 | $telnetcmd .= " | no-more" if ($ostypes{$FORM{router}} eq "junos"); 791 | 792 | $telnet->print("$telnetcmd"); 793 | $telnet->getline; # read out command line 794 | while (1) { 795 | if ($#output >= 0) { 796 | $_ = shift (@output); 797 | } elsif (! $telnet->eof) { 798 | my ($prematch, $match) = $telnet->waitfor( 799 | Match => '/\n/', 800 | Match => '/[\$%#>] {0,1}$/', 801 | Errmode => "return") 802 | or do { 803 | }; 804 | if ($match =~ /[\$%#>] {0,1}$/) { 805 | $telnet->print("quit"); 806 | $telnet->close; 807 | last; 808 | } 809 | push @output, $prematch . $match; 810 | next; 811 | } else { 812 | last; 813 | } 814 | showlines($_); 815 | } 816 | } else { 817 | print_error("Configuration error, no such scheme: $scheme\n"); 818 | } 819 | print "

\n"; 820 | } 821 | 822 | my $best = 0; 823 | my $hidden = 0; 824 | my $count = 0; 825 | my $telnet; 826 | my $lastip = ""; 827 | my $inemptyheader = 1; 828 | my $linebuf = ""; 829 | my $in_func_showlines = 0; 830 | 831 | sub showlines { 832 | my $input = shift; 833 | 834 | if ($command =~ /^trace/i | $command =~ /^ping/i) { 835 | if ($command =~ /^trace/i) { 836 | $input =~ s/(\[AS\s+)(\d+)(\])/($1 . as2link($2) . $3)/e; 837 | } 838 | print $input; 839 | return; 840 | } 841 | 842 | $linebuf .= $input; 843 | return if ($in_func_showlines); 844 | $in_func_showlines = 1; 845 | while ($linebuf =~ /\n/) { 846 | my $line1; 847 | ($line1, $linebuf) = split(/\n/, $linebuf, 2); 848 | showline ($line1); 849 | } 850 | $in_func_showlines = 0; 851 | } 852 | 853 | sub showline { 854 | $_ = shift; 855 | chomp; 856 | 857 | next if (/Type escape sequence to abort./); 858 | next if (/Translating .*\.\.\.domain server/); 859 | next if (/Logical system: /); 860 | 861 | next if (($inemptyheader) && (/^$/)); 862 | $inemptyheader = 0; 863 | 864 | $_ = html_encode($_); 865 | if ($command eq "show ip bgp summary") { 866 | s/( local AS number )(\d+)/($1 . as2link($2))/e; 867 | s/^([\d\.]+\s+\d+\s+)(\d+)/($1 . as2link($2))/e; 868 | s/^(\d+\.\d+\.\d+\.\d+)(\s+.*\s+)([1-9]\d*)$/($1 . $2 . bgplink($3, "neighbors+$1+routes"))/e; 869 | s/^(\d+\.\d+\.\d+\.\d+)(\s+)/(bgplink($1, "neighbors+$1") . $2)/e; 870 | # Zebra IPv6 neighbours 871 | s/^(.{15} 4\s+)(\d+)/($1 . as2link($2))/e; 872 | s/^([\dA-Fa-f]*:[\dA-Fa-f:]*)(\s+)/(bgplink($1, "neighbors+$1") . $2)/e; 873 | s/^([\dA-Fa-f]*:[\dA-Fa-f:]*)$/bgplink($1, "neighbors+$1")/e; 874 | } elsif ($command eq "show bgp ipv6 summary") { 875 | s/^(.{15} 4\s+)(\d+)/($1 . as2link($2))/e; 876 | if (/^([\dA-Fa-f]*:[\dA-Fa-f:]*)\s+4\s+/) { 877 | $lastip = $1; 878 | s/^([\dA-Fa-f:]+)(\s+.*\s+)([1-9]\d*)$/($1 . $2 . bgplink($3, "neighbors+${lastip}+routes"))/e; 879 | s/^([\dA-Fa-f:]+)(\s+)/(bgplink($1, "neighbors+$1") . $2)/e; 880 | $lastip = ""; 881 | } 882 | if (/^([\dA-Fa-f:]+)$/) { 883 | $lastip = $1; 884 | s/^([\dA-Fa-f:]+)$/bgplink($1, "neighbors+$1")/e; 885 | } 886 | if (($lastip ne "") && (/^(\s+.*\s+)([1-9]\d*)$/)) { 887 | s/^(\s+.*\s+)([1-9]\d*)$/($1 . bgplink($2, "neighbors+${lastip}+routes"))/e; 888 | $lastip = ""; 889 | } 890 | } elsif ($command eq "show bgp summary") { 891 | # JunOS 892 | if ($securemode) { 893 | next if (/\.l[23]vpn/); # don't show MPLS 894 | next if (/inet6?\.2/); # don't show multicast 895 | next if (/\.inet6?\.0/); # don't show VRFs 896 | } 897 | if (/^([\dA-Fa-f:][\d\.A-Fa-f:]+)\s+/) { 898 | $lastip = $1; 899 | # IPv4 900 | #s/^(\d+\.\d+\.\d+\.\d+)(\s+.*\s+)([1-9]\d*)(\s+\d+\s+\d+\s+\d+\s+\d+\s+[\d:ywdh]+\s+)(\d+)\/(\d+)\/(\d+)(\s+)/($1 . $2 . bgplink($3, "neighbors+$1+routes") . $4 . bgplink($5, "neighbors+$1+routes") . "\/" . bgplink($6, "neighbors+$1+routes+all") . "\/" . bgplink($7, "neighbors+$1+routes+damping+suppressed") . $8)/e; 901 | s/^(\d+\.\d+\.\d+\.\d+)(\s+)([1-9]\d*)(\s+\d+\s+\d+\s+\d+\s+\d+\s+[\d:ywdh]+\s+)(\d+)\/(\d+)\/(\d+)(\s+)/($1 . $2 . bgplink($3, "neighbors+$1+routes") . $4 . bgplink($5, "neighbors+$1+routes") . "\/" . bgplink($6, "neighbors+$1+routes+all") . "\/" . bgplink($7, "neighbors+$1+routes+damping+suppressed") . $8)/e; 902 | # IPv4/IPv6 903 | s/^([\dA-Fa-f:][\d\.A-Fa-f:]+\s+)(\d+)(\s+)/($1 . as2link($2) . $3)/e; 904 | s/^([\dA-Fa-f:][\d\.A-Fa-f:]+)(\s+)/(bgplink($1, "neighbors+$1") . $2)/e; 905 | } 906 | if (($lastip ne "") && (/(\s+inet6?\.0: )(\d+)\/(\d+)\/(\d+)$/)) { 907 | s/^(\s+inet6?\.0: )(\d+)\/(\d+)\/(\d+)$/($1 . bgplink($2, "neighbors+${lastip}+routes") . "\/" . bgplink($3, "neighbors+${lastip}+routes+all") . "\/" . bgplink($4, "neighbors+${lastip}+routes+damping+suppressed"))/e; 908 | } 909 | } elsif (($command =~ /^show ip bgp\s+n\w*\s+[\d\.]+\s+(ro|re|a)/i) || 910 | ($command =~ /^show bgp ipv6\s+n\w*\s+[\dA-Fa-f:]+\s+(ro|re|a)/i) || 911 | ($command =~ /^show ip bgp\s+re/i) || 912 | ($command =~ /^show bgp ipv6\s+re/i) || 913 | ($command =~ /^show ip bgp\s+[\d\.]+\s+[\d\.]+\s+(l|s)/i) || 914 | ($command =~ /^show (ip bgp|bgp ipv6) prefix-list/i) || 915 | ($command =~ /^show (ip bgp|bgp ipv6) route-map/i)) { 916 | s/^([\*r ](>|d|h| ).{59})([\d\s,\{\}]+)([ie\?])$/($1 . as2link($3, $regexp) . $4)/e; 917 | s/^([\*r ](>|d|h| )[i ])([\d\.A-Fa-f:\/]+)(\s+)/($1 . bgplink($3, $3) . $4)/e; 918 | s/^([\*r ](>|d|h| )[i ])([\d\.A-Fa-f:\/]+)$/($1 . bgplink($3, $3))/e; 919 | s/^(( ){20}.{41})([\d\s,\{\}]+)([ie\?])$/($1 . as2link($3, $regexp) . $4)/e; 920 | s/(, remote AS )(\d+)(,)/($1 . as2link($2) . $3)/e; 921 | } elsif ($command =~ /^show route (?:advertising|receive)-protocol bgp [\d\.A-Fa-f:]+ [\d\.A-Fa-f:\/]+ /i) { 922 | s/^([ \*] )([\d\.A-Fa-f:\/]+)(\s+)/($1 . bgplink($2, $2) . $3)/e; 923 | s/^( AS path: )([\d\s,\{\}\[\]]+)( [IE\?] \((?:LocalAgg)?\))$/($1 . as2link($2) . $3)/e; 924 | s/^( Communities: )([\d: ]+)/($1 . community2link($2))/e; 925 | } elsif ($command =~ /^show route ((advertising|receive)-protocol) bgp\s+([\d\.A-Fa-f:]+)/i) { 926 | my $type = $1; 927 | my $ip = $3; 928 | s/^([\* ] [\d\.\s].{62})([\d\s,\{\}\[\]]+)([IE\?])$/($1 . as2link($2) . $3)/e; 929 | s/^([\* ] [\d\.\s].{22}\s)([\d\.A-Fa-f:]+)(\s+)/($1 . bgplink($2, "neighbors+$2") . $3)/e; 930 | s/^([\dA-Fa-f:\/]+)(\s+)/(bgplink($1, "$1+exact") . $2)/e; 931 | s/^([\d\.\/]+)(\s+)/(bgplink($1, "$1+exact") . $2)/e; 932 | s/^([\dA-Fa-f:\/]+)(\s*)$/(bgplink($1, "$1+exact") . $2)/e; 933 | s/^([\d\.\/]+)\s*$/(bgplink($1, "$1+exact"))/e; 934 | s/^([ \*] )([\d\.A-Fa-f:\/]+)(\s+)/($1 . bgplink($2, "neighbors+$ip+" . (($type eq "advertising-protocol")?"advertised-routes":"receive-protocol") . "+$2") . $3)/e; 935 | } elsif (($command =~ /^show ip bgp n\w*\s+([\d\.]+)/i) || 936 | ($command =~ /^show ip bgp n\w*$/i)) { 937 | $lastip = $1 if ($1 ne ""); 938 | $lastip = $1 if (/^BGP neighbor is ([\d\.]+),/); 939 | if ($securemode) { 940 | s/((Local|Foreign) port: )\d+/${1}???/g; 941 | } 942 | s/(Prefix )(advertised)( [1-9]\d*)/($1 . bgplink($2, "neighbors+$lastip+advertised-routes") . $3)/e; 943 | s/( Prefixes Total: )(\d+)( )/($1 . bgplink($2, "neighbors+$lastip+advertised-routes") . $3)/e; 944 | s/(prefixes )(received)( [1-9]\d*)/($1 . bgplink($2, "neighbors+$lastip+routes") . $3)/e; 945 | s/^( Prefixes Current: \s+)(\d+)(\s+)(\d+)/($1 . bgplink($2, "neighbors+$lastip+advertised-routes") . $3 . bgplink($4, "neighbors+$lastip+routes"))/e; 946 | s/(\s+)(Received)( prefixes:\s+[1-9]\d*)/($1 . bgplink($2, "neighbors+$lastip+routes") . $3)/e; 947 | s/^( Saved \(soft-reconfig\):\s+)(\d+|n\/a)(\s+)(\d+)/($1 . $2 . $3 . bgplink($4, "neighbors+$lastip+received-routes"))/e; 948 | s/( [1-9]\d* )(accepted)( prefixes)/($1 . bgplink($2, "neighbors+$lastip+routes") . $3)/e; 949 | s/^( [1-9]\d* )(accepted|denied but saved)( prefixes consume \d+ bytes)/($1 . bgplink($2, "neighbors+$lastip+received-routes") . $3)/e; 950 | s/^(BGP neighbor is )(\d+\.\d+\.\d+\.\d+)(,)/($1 . pinglink($2) . $3)/e; 951 | s/^( Description: )(.*)$/$1$2<\/B>/; 952 | s/(,\s+remote AS )(\d+)(,)/($1 . as2link($2) . $3)/e; 953 | s/(, local AS )(\d+)(,)/($1 . as2link($2) . $3)/e; 954 | s/( update prefix filter list is )(\S+)/($1 . bgplink($2, "prefix-list+$2"))/e; 955 | s/(Route map for \S+ advertisements is\s+)(\S+)/($1 . bgplink($2, "route-map+$2"))/e; 956 | } elsif ($command =~ /^show bgp ipv6 n\w*\s+([\dA-Fa-f:]+)/i) { 957 | my $ip = $1; 958 | if ($securemode) { 959 | s/((Local|Foreign) port: )\d+/${1}???/g; 960 | } 961 | s/(Prefix )(advertised)( [1-9]\d*)/($1 . bgplink($2, "neighbors+$ip+advertised-routes") . $3)/e; 962 | s/^( [1-9]\d* )(accepted)( prefixes)/($1 . bgplink($2, "neighbors+$ip+routes") . $3)/e; 963 | s/^( Description: )(.*)$/$1$2<\/B>/; 964 | s/(\s+remote AS )(\d+)(,)/($1 . as2link($2) . $3)/e; 965 | s/(\s+local AS )(\d+)(,)/($1 . as2link($2) . $3)/e; 966 | s/( update prefix filter list is )(\S+)/($1 . bgplink($2, "prefix-list+$2"))/e; 967 | s/(Route map for \S+ advertisements is\s+)(\S+)/($1 . bgplink($2, "route-map+$2"))/e; 968 | } elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+)/i) { 969 | my $ip = $1; 970 | if ($securemode) { 971 | if ($hidden) { 972 | $hidden = 0 unless (/^ /); 973 | next if ($hidden); 974 | } 975 | s/^(Peer:\s+[\d\.A-Fa-f:]+\+)\d+(\s+AS\s+\d+\s+Local:\s+[\d\.A-Fa-f:]+\+)\d+(\s+AS\s+\d+)/${1}???${2}???${3}/g; 976 | if (/^ Table (.*\.l[23]vpn|inet6?\.2|\S+\.inet6?\.0)/) { 977 | s/^( Table) \S+/$1 (hidden)/g; 978 | $hidden = 1; 979 | } 980 | } 981 | s/(\s+AS )(\d+)/($1 . as2link($2))/eg; 982 | s/(\s+AS: )(\d+)/($1 . as2link($2))/eg; 983 | s/^( Active prefixes:\s+)(\d+)/($1 . bgplink($2, "neighbors+$ip+routes"))/e; 984 | s/^( Received prefixes:\s+)(\d+)/($1 . bgplink($2, "neighbors+$ip+routes+all"))/e; 985 | s/^( Suppressed due to damping:\s+)(\d+)/($1 . bgplink($2, "neighbors+$ip+routes+damping+suppressed"))/e; 986 | s/^( Advertised prefixes:\s+)(\d+)/($1 . bgplink($2, "neighbors+$ip+advertised-routes"))/e; 987 | s/^( )(Export)(: )/($1 . bgplink($2, "neighbors+$ip+advertised-routes") . $3)/e; 988 | s/^( )(Import)(: )/($1 . bgplink($2, "neighbors+$ip+routes+all") . $3)/e; 989 | # JUNOS bugfix 990 | s/([^ ])( )(Import)(: )/($1 . "\n " . $2 . bgplink($3, "neighbors+$ip+routes+all") . $4)/e; 991 | } elsif ($command =~ /^show route protocol bgp .* terse/i) { 992 | s/^(.{20} B .{25} (?:>| ).{15}[^ ]*)( [\d\s,\{\}]+)(.*)$/($1 . as2link($2, $regexp) . $3)/e; 993 | s/^([\* ] )([\d\.A-Fa-f:\/]+)(\s+)/($1 . bgplink($2, "$2+exact") . $3)/e; 994 | } elsif (($command =~ /^show route protocol bgp /i) || 995 | ($command =~ /^show route aspath-regex /i)) { 996 | if ($securemode) { 997 | s/(Task: BGP_[\d\.A-Fa-f:]+\+)\d+/${1}???/g; 998 | } 999 | if (/^ (.)BGP /) { 1000 | if ($1 eq "*") { 1001 | $best = "\#FF0000"; 1002 | } else { 1003 | $best = ""; 1004 | } 1005 | } elsif (/^[\d\.A-Fa-f:\/\s]{19}([\*\+\- ])\[BGP\//) { 1006 | if ($1 =~ /[\*\+]/) { 1007 | $best = "\#FF0000"; 1008 | } elsif ($1 eq "-") { 1009 | $best = "\#008800"; 1010 | } else { 1011 | $best = ""; 1012 | } 1013 | } elsif (/^$/) { 1014 | $best = ""; 1015 | } 1016 | s/( from )([0-9A-Fa-f][0-9\.A-Fa-f:]+)/($1 . bgplink($2, "neighbors+$2"))/e; 1017 | s/( Source: )([0-9\.A-Fa-f:]+)/($1 . bgplink($2, "neighbors+$2"))/e; 1018 | s/(\s+AS: )([\d ]+)/($1 . as2link($2))/eg; 1019 | s/(Community: )([\d: ]+)/($1 . community2link($2))/e; 1020 | s/(Communities: )([\d: ]+)/($1 . community2link($2))/e; 1021 | s/(^\s+AS path: )(Merged\[3\]: )?([\d ]+)/($1 . $2 . as2link($3))/e; 1022 | s/^([\dA-Fa-f:]+[\d\.A-Fa-f:\/]+)(\s*)/("" . bgplink($1, "$1+exact") . "<\/B>$2")/e; 1023 | $_ = "$_" if ($best ne ""); 1024 | } elsif ($command =~ /bgp/) { 1025 | s|^(BGP routing table entry for) (\S+)|$1 $2|; 1026 | s|^(Paths:\ .*)\ best\ \#(\d+) 1027 | |$1\ best\ \#$2|x 1028 | && do { $best = $2; }; 1029 | # Fix for IPv6 route output where there are no addional 3 spaces before addresses 1030 | if ((/^ Advertised to non peer-group peers:$/) && 1031 | ($command =~ / ipv6 /)) { 1032 | $count--; 1033 | } 1034 | if ((/^ (\d+.*)/ && ! /^ \d+\./) || (/^ Local/)) { 1035 | $count++; 1036 | $_ = as2link($_); 1037 | } 1038 | $_ = "$_" if $best && $best == $count; 1039 | s/( from )([0-9A-Fa-f][0-9\.A-Fa-f:]+)( )/($1 . bgplink($2, "neighbors+$2") . $3)/e; 1040 | s/(Community: )([\d: ]+)/($1 . community2link($2))/e; 1041 | s/(Communities: )([\d: ]+)/($1 . community2link($2))/e; 1042 | s/(^\s+AS path: )([\d ]+)/($1 . as2link($2))/e; 1043 | if ($command =~ /-protocol/) { 1044 | s/^([ \*] )([\d\.A-Fa-f:\/]+)(\s+)/($1 . bgplink($2, "$2+exact") . $3)/e; 1045 | } 1046 | } 1047 | print "$_\n"; 1048 | } 1049 | 1050 | ######## Portion of code is borrowed from NCSA WebMonitor "mail" code 1051 | 1052 | sub cgi_decode { 1053 | my ($incoming) = @_; 1054 | 1055 | my %FORM; 1056 | my $ref = "FORM"; 1057 | 1058 | my @pairs = split(/&/, $incoming); 1059 | 1060 | foreach (@pairs) { 1061 | my ($name, $value) = split(/=/, $_); 1062 | 1063 | $name =~ tr/+/ /; 1064 | $value =~ tr/+/ /; 1065 | $name =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/gie; 1066 | $value =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/gie; 1067 | 1068 | $FORM{$name} .= $value; 1069 | } 1070 | return (%FORM); 1071 | } 1072 | 1073 | sub read_as_list { 1074 | my ($fn) = @_; 1075 | 1076 | local *F; 1077 | my %AS; 1078 | 1079 | if (! open(F, $fn)) { 1080 | print "\n"; 1081 | return; 1082 | } 1083 | while () { 1084 | chop; 1085 | if (/^#include\s+(.+)$/) { 1086 | my %AS2 = &read_as_list($1); 1087 | foreach my $key (keys (%AS2)) { 1088 | $AS{$key} = $AS2{$key}; 1089 | } 1090 | undef %AS2; 1091 | next; 1092 | } 1093 | next if (/^$/ || /^\s*#/); 1094 | my ($asnum, $descr) = split /\t+/; 1095 | $asnum =~ s/^[^\d]*(\d+)[^\d]*$/$1/; 1096 | $AS{$asnum} = $descr; 1097 | } 1098 | close(F); 1099 | return (%AS); 1100 | } 1101 | 1102 | sub as2link { 1103 | my ($line, $regexp) = @_; 1104 | 1105 | my $prefix; 1106 | my $suffix; 1107 | if ($line =~ /^([^\d]*)((\d)|(\d[\d\s\[\]\{\}]*\d))([^\d]*)$/) { 1108 | $prefix = $1; 1109 | $line = $4; 1110 | $suffix = $5; 1111 | } 1112 | return($prefix . $line . $suffix) if ($line =~ /^\s*$/); 1113 | if ($line =~ /:/) { 1114 | return($prefix . $line . $suffix); 1115 | } 1116 | my @aslist = split(/[^\d]+/, $line); 1117 | my @separators = split(/[\d]+/, $line); 1118 | my @regexplist = split(/[_^$ ]+/, $regexp); 1119 | $line = ""; 1120 | for (my $i = 0; $i <= $#aslist; $i++) { 1121 | my $as = $aslist[$i]; 1122 | my $sep = ""; 1123 | $sep = $separators[$i + 1] if ($i <= $#separators); 1124 | my $astxt = $as; 1125 | for (my $j = 0; $j <= $#regexplist; $j++) { 1126 | if ($regexplist[$j] eq $as) { 1127 | $astxt = "$as"; 1128 | last; 1129 | } 1130 | } 1131 | my $rep; 1132 | if (! defined $AS{$as}) { 1133 | $rep = $astxt; 1134 | } else { 1135 | my $link = ""; 1136 | if ($AS{$as} =~ /(\w+):/) { 1137 | if (defined $whois{$1}) { 1138 | $link = sprintf(" HREF=\"$whois{$1}\" TARGET=_lookup", $as); 1139 | } elsif (defined $whois{default}) { 1140 | $link = sprintf(" HREF=\"$whois{default}\" TARGET=_lookup", $as); 1141 | } 1142 | } 1143 | my $descr = $AS{$as}; 1144 | $descr = "$2 ($1)" if ($descr =~ /^([^:]+):(.*)$/); 1145 | $rep = "$astxt"; 1146 | } 1147 | $line .= $rep . $sep; 1148 | } 1149 | $suffix =~ s/(aggregated by )(\d+)( )/($1 . as2link($2) . $3)/e; 1150 | return($prefix . $line . $suffix); 1151 | } 1152 | 1153 | sub community2link { 1154 | my ($line) = @_; 1155 | 1156 | my $prefix; 1157 | my $suffix; 1158 | my @communitylist = split(/[^\d:]+/, $line); 1159 | my @separators = split(/[\d:]+/, $line); 1160 | $line = ""; 1161 | for (my $i = 0; $i <= $#communitylist; $i++) { 1162 | my $community = $communitylist[$i]; 1163 | my $sep = ""; 1164 | $sep = $separators[$i + 1] if ($i <= $#separators); 1165 | my $rep; 1166 | if (! defined $AS{$community}) { 1167 | $rep = $community; 1168 | } else { 1169 | my $link = ""; 1170 | my $descr = $AS{$community}; 1171 | my $asnum = $1 if ($community =~ /^(\d+):/); 1172 | if (defined $AS{$asnum . ":URL"}) { 1173 | $rep = "$community (" . html_encode($descr) . ")"; 1174 | } else { 1175 | $rep = html_encode("$community ($descr)"); 1176 | } 1177 | } 1178 | $line .= $rep . $sep; 1179 | } 1180 | return($line); 1181 | } 1182 | 1183 | sub bgplink { 1184 | my ($txt, $cmd) = @_; 1185 | 1186 | my $link = $lgurl; 1187 | my $router = $FORM{router}; 1188 | 1189 | $router =~ s/\+/%2B/; 1190 | $router =~ s/=/%3D/; 1191 | $router =~ s/\&/%26/g; 1192 | 1193 | $link .= "?query=bgp"; 1194 | $link .= "&protocol=" . $FORM{protocol}; 1195 | $link .= "&addr=$cmd"; 1196 | $link .= "&router=$router"; 1197 | $link =~ s/ /+/g; 1198 | return("$txt"); 1199 | } 1200 | 1201 | sub pinglink { 1202 | my ($ip) = @_; 1203 | 1204 | my $link = $lgurl; 1205 | my $router = $FORM{router}; 1206 | 1207 | $router =~ s/\+/%2B/; 1208 | $router =~ s/=/%3D/; 1209 | $router =~ s/\&/%26/g; 1210 | 1211 | $link .= "?query=ping"; 1212 | $link .= "&protocol=" . $FORM{protocol}; 1213 | $link .= "&addr=$ip"; 1214 | $link .= "&router=$router"; 1215 | $link =~ s/ /+/g; 1216 | return("$ip"); 1217 | } 1218 | 1219 | sub html_encode { 1220 | ($_) = @_; 1221 | s|[\r\n]||g; 1222 | s|&|&|g; 1223 | s|<|<|g; 1224 | s|>|>|g; 1225 | return $_; 1226 | } 1227 | --------------------------------------------------------------------------------