-
Notifications
You must be signed in to change notification settings - Fork 32
/
lg.cgi
executable file
·1226 lines (1143 loc) · 39.4 KB
/
lg.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
#
# Looking Glass CGI with ssh, telnet, rexec and remote LG support
# with IPv4 and IPv6 support
#
# Copyright (C) 2000-2014 Cougar <[email protected]>
# http://www.version6.net/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
use strict qw(subs vars);
$configfile = "lg.conf";
$ENV{HOME} = "."; # SSH needs access for $HOME/.ssh
use XML::Parser;
my $SYS_progid = '$Id: lg.cgi,v 1.30 2004/11/25 14:12:42 cougar Exp $';
my $default_ostype = "ios";
my $lgurl;
my $logfile;
my $asfile;
my $logoimage;
my $logoalign;
my $logolink;
my $title;
my $favicon;
my $email;
my $rshcmd;
my $ipv4enabled;
my $ipv6enabled;
my $httpmethod = "POST";
my $timeout;
my $disclaimer;
my $securemode = 1;
my $ssh2key;
my $ssh2pubkey;
my %router_list;
my @routers;
my %namemap;
my %ostypes;
my %logicalsystem;
my %cmdmap;
my $default_router;
my $xml_current_router_name = "";
my $xml_current_cgi_name = "";
my $xml_current_replace_name = "";
my $xml_current_replace_proto = "";
my %valid_query = (
"ios" => {
"ipv4" => {
"bgp" => "show ip bgp %s",
"advertised-routes" => "show ip bgp neighbors %s advertised-routes",
"summary" => "show ip bgp summary",
"ping" => "ping %s",
"trace" => "traceroute %s"
},
"ipv6" => {
"bgp" => "show bgp ipv6 %s",
"advertised-routes" => "show bgp ipv6 neighbors %s advertised-routes",
"summary" => "show bgp ipv6 summary",
"ping" => "ping ipv6 %s",
"trace" => "traceroute ipv6 %s"
}
},
"zebra" => {
"ipv4" => {
"bgp" => "show ip bgp %s",
"advertised-routes" => "show ip bgp neighbors %s advertised-routes",
"summary" => "show ip bgp summary",
"ping" => "ping %s",
"trace" => "traceroute %s"
},
"ipv6" => {
"bgp" => "show bgp ipv6 %s",
"advertised-routes" => "show bgp ipv6 neighbors %s advertised-routes",
"summary" => "show bgp ipv6 summary",
"ping" => "ping ipv6 %s",
"trace" => "traceroute ipv6 %s"
}
},
"junos" => {
"ipv4" => {
"trace" => "traceroute %s as-number-lookup"
},
"ipv6" => {
"trace" => "traceroute %s"
},
"ipv46" => {
"bgp" => "show bgp %s",
"advertised-routes" => "show route advertising-protocol bgp %s %s",
"summary" => "show bgp summary",
"ping" => "ping count 5 %s"
}
}
);
my %whois = (
"RIPE" => "http://www.ripe.net/perl/whois?AS%s",
"ARIN" => "http://www.arin.net/cgi-bin/whois.pl?queryinput=%s",
"APNIC" => "http://www.apnic.net/apnic-bin/whois.pl?searchtext=AS%s",
"default" => "http://www.sixxs.net/tools/whois/?AS%s"
);
$| = 1;
&read_config;
# grab CGI data
my $incoming;
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $incoming, $ENV{'CONTENT_LENGTH'});
} else {
$incoming = $ENV{'QUERY_STRING'};
}
my %FORM = &cgi_decode($incoming);
my $date = localtime;
if ($logfile ne "") {
open(LOG, ">>$logfile");
($ENV{REMOTE_HOST}) && ( print LOG "$ENV{'REMOTE_HOST'} ");
($ENV{REMOTE_ADDR}) && ( print LOG "$ENV{'REMOTE_ADDR'} ");
print LOG "- - [$date]";
($ENV{HTTP_REFERER}) && ( print LOG " $ENV{'HTTP_REFERER'}");
}
my $query_cmd = "";
if (defined $valid_query{$ostypes{$FORM{router}}}{"ipv46"}{$FORM{query}}) {
$query_cmd = $valid_query{$ostypes{$FORM{router}}}{"ipv46"}{$FORM{query}};
} elsif (defined $valid_query{$ostypes{$FORM{router}}}{lc($FORM{protocol})}{$FORM{query}}) {
$query_cmd = $valid_query{$ostypes{$FORM{router}}}{lc($FORM{protocol})}{$FORM{query}};
} elsif (($FORM{router} ne "") || ($FORM{protocol} ne "") || ($FORM{query})) {
if ($logfile ne "") {
print LOG " \"$FORM{router}\" \"ILLEGAL QUERY: [$ostypes{$FORM{router}}] [$FORM{protocol}] [$FORM{query}]\"\n";
close(LOG);
}
&print_head;
&print_form;
&print_tail;
exit;
}
if ((! defined $router_list{$FORM{router}}) ||
($query_cmd eq "")) {
if ($logfile ne "") {
print LOG "\n";
close(LOG);
}
&print_head;
&print_form;
&print_tail;
exit;
}
$FORM{addr} =~ s/\s.*// if (($FORM{query} eq "ping") || ($FORM{query} eq "trace"));
$FORM{addr} =~ s/[^\s\d\.:\w\-_\/\$]//g;
if ($router_list{$FORM{router}} =~ /^http[s]{0,1}:/) {
if ($logfile ne "") {
print LOG " \"$FORM{router}\" \"$FORM{query}" . ($FORM{addr} ne "" ? " $FORM{addr}" : "") . "\"\n";
close LOG;
}
if ($router_list{$FORM{router}} =~ /\?/) {
$incoming = "&$incoming";
} else {
$incoming = "?$incoming";
}
my $remote = $router_list{$FORM{router}};
if (defined $cmdmap{$remote}{lc($FORM{protocol})}) {
$incoming .= "&";
my $mapref = $cmdmap{$remote}{lc($FORM{protocol})};
foreach my $key (keys (%{$mapref})) {
next if ($key eq "DEFAULT");
(my $urlkey = $key) =~ s/([+*\/\\])/\\$1/g;
if (${$mapref}{$key} eq "") {
$incoming =~ s/([\?\&])($urlkey)=[^\&]*\&/$1/g;
} elsif (${$mapref}{$key} =~ /=/) {
$incoming =~ s/([\?\&])($urlkey)\&/"${1}${$mapref}{$2}&"/e;
}
}
foreach my $key (keys (%{$mapref})) {
next if ($key eq "DEFAULT");
$incoming =~ s/([\?\&])($key)=/"${1}${$mapref}{$2}="/e;
}
$incoming =~ s|&$||g;
if (defined ${$mapref}{DEFAULT}) {
$incoming .= "&${$mapref}{DEFAULT}";
}
}
print "Location: $router_list{$FORM{router}}${incoming}\n\n";
exit;
}
my $command = sprintf($query_cmd, $FORM{addr});
print LOG " \"$FORM{router}\" \"$command\"\n";
close LOG;
&print_head($command);
if ($FORM{addr} !~ /^[\w\.\^\$\-\/ ]*$/) {
if ($FORM{addr} =~ /^[\w\.\^\$\-\:\/ ]*$/) {
if (($FORM{protocol} ne "IPv6") && ($ostypes{$FORM{router}} ne "junos")){
&print_error("ERROR: IPv6 address for IPv4 query");
}
} else {
&print_error("Illegal characters in parameter string");
}
}
$FORM{addr} = "" if ($FORM{addr} =~ /^[ ]*$/);
if ($query_cmd =~ /%s/) {
&print_error("Parameter missing") if ($FORM{addr} eq "");
} else {
&print_warning("No parameter needed") if ($FORM{addr} ne "");
}
my %AS;
if ($asfile =~ /\.db$/) {
use DB_File;
tie (%AS, 'DB_File', $asfile, O_RDONLY, 0644, $DB_HASH) or
print STDERR "Can\'t read AS database $asfile: $!\n";
} else {
%AS = &read_as_list($asfile);
}
my $table;
$table = "table inet.0" if ($FORM{protocol} eq "IPv4");
$table = "table inet6.0" if ($FORM{protocol} eq "IPv6");
if ($ostypes{$FORM{router}} eq "junos") {
if ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+)$/) {
# show bgp n.. <IP> ---> show bgp neighbor <IP>
$command = "show bgp neighbor $1";
} elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+) ro\w*$/) {
# show bgp n.. <IP> ro.. ---> show route receive-protocol bgp <IP>
$command = "show route receive-protocol bgp $1 $table";
} elsif ($command =~ /^show bgp neighbors ([\d\.A-Fa-f:]+) routes all$/) {
# show bgp neighbors <IP> routes all ---> show route receive-protocol bgp <IP> all
$command = "show route receive-protocol bgp $1 all $table";
} elsif ($command =~ /^show bgp neighbors ([\d\.A-Fa-f:]+) routes damping suppressed$/) {
# show bgp neighbors <IP> routes damping suppressed ---> show route receive-protocol bgp <IP> damping suppressed
$command = "show route receive-protocol bgp $1 damping suppressed $table";
} elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+) advertised-routes ([\d\.A-Fa-f:\/]+)$/) {
# show ip bgp n.. <IP> advertised-routes <prefix> ---> show route advertising-protocol bgp <IP> <prefix> exact detail
$command = "show route advertising-protocol bgp $1 $2 exact detail $table";
} elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+) receive-protocol ([\d\.A-Fa-f:\/]+)$/) {
# show ip bgp n.. <IP> receive-protocol <prefix> ---> show route receive-protocol bgp <IP> <prefix> exact detail
$command = "show route receive-protocol bgp $1 $2 exact detail $table";
} elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+) a[\w\-]*$/) {
# show ip bgp n.. <IP> a.. ---> show route advertising-protocol bgp <IP>
$command = "show route advertising-protocol bgp $1 $table";
} elsif ($command =~ /^show bgp\s+([\d\.A-Fa-f:]+\/\d+)$/) {
# show bgp <IP>/mask ---> show route protocol bgp <IP> all
$command = "show route protocol bgp $1 terse exact all $table";
} elsif ($command =~ /^show bgp\s+([\d\.A-Fa-f:]+)$/) {
# show bgp <IP> ---> show route protocol bgp <IP> all
$command = "show route protocol bgp $1 terse $table";
} elsif ($command =~ /^show bgp\s+([\d\.A-Fa-f:\/]+) exact$/) {
# show bgp <IP> exact ---> show route protocol bgp <IP> exact detail all
$command = "show route protocol bgp $1 exact detail all $table";
} elsif ($command =~ /^show bgp re\w*\s+(.*)$/) {
# show ip bgp re <regexp> ---> show route aspath-regex <regexp> all
my $re = $1;
$re = ".*${re}" if ($re !~ /^\^/);
$re = "${re}.*" if ($re !~ /\$$/);
$re =~ s/_/ /g;
$command = "show route protocol bgp aspath-regex \"$re\" all $table terse";
}
}
&run_command($FORM{router}, $router_list{$FORM{router}}, $command);
&print_tail;
exit;
sub read_config {
my $xp = new XML::Parser(ProtocolEncoding => "ISO-8859-1", Handlers => {Char => \&xml_charparse, Start => \&xml_startparse, End => \&xml_endparse});
$xp->parsefile($configfile);
undef($xp);
}
sub xml_charparse {
my ($xp,$str) = @_;
return if $str =~ /^\s*$/m;
my $elem = lc($xp->current_element);
if ($xml_current_router_name ne "") {
if ($elem eq "url") {
$router_list{$xml_current_router_name} = $str;
push @routers, $xml_current_router_name;
} elsif ($elem eq "title") {
$namemap{$xml_current_router_name} .= $str;
} else {
die("Illegal value for configuration tag \"" . $xp->current_element . "\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
} elsif (($xml_current_cgi_name ne "") && ($xml_current_replace_name ne "")) {
if (($elem eq "replace") ||
($elem eq "default")) {
$cmdmap{$xml_current_cgi_name}{"ipv4"}{$xml_current_replace_name} .= $str if ($xml_current_replace_proto ne "ipv6");
$cmdmap{$xml_current_cgi_name}{"ipv6"}{$xml_current_replace_name} .= $str if ($xml_current_replace_proto ne "ipv4");
} else {
die("Illegal value for configuration tag \"" . $xp->current_element . "\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
} elsif ($elem eq "lgurl") {
$lgurl = $str;
} elsif ($elem eq "logfile") {
$logfile = $str;
} elsif ($elem eq "aslist") {
$asfile = $str;
} elsif ($elem eq "logoimage") {
$logoimage = $str;
} elsif ($elem eq "htmltitle") {
$title = $str;
} elsif ($elem eq "favicon") {
$favicon = $str;
} elsif ($elem eq "contactmail") {
$email = $str;
} elsif ($elem eq "rshcmd") {
$rshcmd = $str;
} elsif ($elem eq "httpmethod") {
$httpmethod = $str;
} elsif ($elem eq "timeout") {
$timeout = $str;
} elsif ($elem eq "disclaimer") {
$disclaimer = "<CENTER><TABLE WIDTH=\"85%\"><TR><TD><FONT SIZE=-3>Disclaimer: $str</FONT></TD></TR></TABLE></CENTER>\n";
} elsif ($elem eq "securemode") {
if ($str =~ /^(0|off|no)$/i) {
$securemode = 0;
} elsif ($str =~ /^(1|on|yes)$/i) {
$securemode = 1;
} else {
die("Illegal securemode \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
} elsif ($elem eq "separator") {
push @routers, "---- $str ----";
} elsif ($elem eq "ssh2key") {
$ssh2key = $str;
} elsif ($elem eq "ssh2pubkey") {
$ssh2pubkey = $str;
} else {
print "<!-- C [$xml_current_router_name] [" . $xp->current_element . "] [$str] -->\n";
}
}
sub xml_startparse {
my ($xp,$str,@attrval) = @_;
my $elem = lc($xp->current_element);
my $str2 = lc($str);
if ($elem eq "") {
if ($str2 ne "lg_conf_file") {
die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
} elsif ($elem eq "lg_conf_file") {
if ($str2 eq "logoimage") {
for (my $i = 0; $i <= $#attrval; $i += 2) {
if (lc($attrval[$i]) eq "align") {
$logoalign = " Align=\"" . $attrval[$i+1] . "\"";
} elsif (lc($attrval[$i]) eq "link") {
$logolink = $attrval[$i+1];
} else {
die("Illegal parameter for LogoImage \"" . $attrval[$i] . "\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
}
} elsif (($str2 ne "lgurl") &&
($str2 ne "logfile") &&
($str2 ne "aslist") &&
($str2 ne "htmltitle") &&
($str2 ne "favicon") &&
($str2 ne "contactmail") &&
($str2 ne "rshcmd") &&
($str2 ne "httpmethod") &&
($str2 ne "timeout") &&
($str2 ne "disclaimer") &&
($str2 ne "securemode") &&
($str2 ne "ssh2key") &&
($str2 ne "ssh2pubkey") &&
($str2 ne "router_list") &&
($str2 ne "argument_list")) {
die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
} elsif ($elem eq "router_list") {
if ($str2 eq "router") {
for (my $i = 0; $i <= $#attrval; $i += 2) {
if (lc($attrval[$i]) eq "name") {
$xml_current_router_name = $attrval[$i+1];
$ostypes{$xml_current_router_name} = lc($default_ostype);
$ipv4enabled ++;
} elsif (lc($attrval[$i]) eq "default") {
if (lc($attrval[$i+1]) eq "yes") {
$default_router = $xml_current_router_name;
}
} elsif (lc($attrval[$i]) eq "enableipv6") {
if (lc($attrval[$i+1]) eq "yes") {
$ipv4enabled--;
$ipv6enabled++;
}
} elsif (lc($attrval[$i]) eq "ostype") {
$ostypes{$xml_current_router_name} = lc($attrval[$i+1]);
} elsif (lc($attrval[$i]) eq "logical-system") {
$logicalsystem{$xml_current_router_name} = lc($attrval[$i+1]);
}
}
if ($xml_current_router_name eq "") {
die("Variable \"Name\" missing at line " . $xp->current_line . ", column " . $xp->current_column);
}
} elsif ($str2 eq "separator") {
} else {
die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
} elsif ($elem eq "router") {
if (($str2 ne "title") &&
($str2 ne "url")) {
die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
} elsif ($elem eq "argument_list") {
if ($str2 eq "lg") {
for (my $i = 0; $i <= $#attrval; $i += 2) {
if (lc($attrval[$i]) eq "url") {
$xml_current_cgi_name = $attrval[$i+1];
}
}
if ($xml_current_cgi_name eq "") {
die("Variable \"URL\" missing at line " . $xp->current_line . ", column " . $xp->current_column);
}
} else {
die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
} elsif ($elem eq "lg") {
if ($str2 eq "replace") {
for (my $i = 0; $i <= $#attrval; $i += 2) {
if (lc($attrval[$i]) eq "param") {
$xml_current_replace_name = $attrval[$i+1];
} elsif (lc($attrval[$i]) eq "proto") {
$xml_current_replace_proto = lc($attrval[$i+1]);
}
}
if ($xml_current_replace_name eq "") {
die("Variable \"Param\" missing at line " . $xp->current_line . ", column " . $xp->current_column);
}
$cmdmap{$xml_current_cgi_name}{"ipv4"}{$xml_current_replace_name} = "" if ($xml_current_replace_proto ne "ipv6");
$cmdmap{$xml_current_cgi_name}{"ipv6"}{$xml_current_replace_name} = "" if ($xml_current_replace_proto ne "ipv4");
} elsif ($str2 eq "default") {
$xml_current_replace_name = "DEFAULT";
} else {
die("Illegal configuration tag \"$str\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
} else {
die("ASSERT str=\"$str\" elem=\"" . $xp->current_element . "\" at line " . $xp->current_line . ", column " . $xp->current_column);
}
}
sub xml_endparse {
my ($xp,$str) = @_;
my $elem = lc($xp->current_element);
my $str2 = lc($str);
if ($elem eq "router_list") {
if ($str2 eq "router") {
$xml_current_router_name = "";
}
} elsif ($elem eq "lg") {
if (($str2 eq "replace") ||
($str2 eq "default")) {
$xml_current_replace_name = "";
$xml_current_replace_proto = "";
}
}
}
sub print_head {
my ($arg) = @_;
my ($titlestr) = $title;
$titlestr .= " - $arg" if ($arg ne "");
print "Content-type: text/html; charset=utf-8\n\n";
print "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
print "<!--\n\t$SYS_progid\n\thttp://freshmeat.net/projects/lg/\n-->\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>$titlestr</TITLE>\n";
if ($favicon ne "") {
print "<LINK REL=\"shortcut icon\" HREF=\"${favicon}\">\n";
}
print "<meta name=description content=\"$titlestr\"\>\n";
print "<meta name=keywords content=\"Looking glass, LG, BGP, prefix-list, AS-path, ASN, traceroute, ping, IPv6, Cisco, Juniper, Zebra, Quagga, internet\"/>\n";
print "<style>em { font-style: normal; background: #ffff00; color: #000000; }</style>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n";
if ($logoimage ne "") {
print "<TABLE BORDER=\"0\" WIDTH=\"100%\"><TR><TD$logoalign>";
print "<A HREF=\"$logolink\">" if ($logolink ne "");
print "<IMG SRC=\"$logoimage\" BORDER=\"0\" ALT=\"LG\">";
print "</A>" if ($logolink ne "");
print "</TD></TR></TABLE>\n";
}
print "<CENTER>\n";
print "<H2>$titlestr</H2>\n";
print "</CENTER>\n";
print "<P>\n";
print "<HR SIZE=2 WIDTH=\"85%\" NOSHADE>\n";
print "<P>\n";
}
sub print_form {
if ($httpmethod eq "GET") {
print "<FORM ACTION=\"$lgurl\">\n";
} else {
print "<FORM METHOD=$httpmethod ACTION=\"$lgurl\">\n";
}
print <<EOT;
<CENTER>
<TABLE BORDER=0 BGCOLOR="#EFEFEF"><TR><TD>
<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
<TR>
<TH BGCOLOR="#000000" NOWRAP><FONT COLOR="#FFFFFF">Type of Query</FONT></TH>
<TH BGCOLOR="#000000" NOWRAP><FONT COLOR="#FFFFFF">Additional parameters</FONT></th>
<TH BGCOLOR="#000000" NOWRAP><FONT COLOR="#FFFFFF">Node</FONT></TH></TR>
<TR><TD>
<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
<TR><TD><INPUT TYPE=radio NAME=query VALUE=bgp></TD><TD> bgp</TD></TR>
<TR><TD><INPUT TYPE=radio NAME=query VALUE=advertised-routes></TD><TD> bgp advertised-routes</TD></TR>
<TR><TD><INPUT TYPE=radio NAME=query VALUE=summary></TD><TD> bgp summary</TD></TR>
<TR><TD><INPUT TYPE=radio NAME=query VALUE=ping></TD><TD> ping</TD></TR>
<TR><TD><INPUT TYPE=radio NAME=query VALUE=trace CHECKED></TD><TD> trace</TD></TR>
EOT
if ($ipv4enabled && $ipv6enabled) {
print <<EOT;
<TR><TD></TD><TD><SELECT NAME=protocol>
<OPTION VALUE=IPv4> IPv4
<OPTION VALUE=IPv6> IPv6
</SELECT></TD></TR>
</TABLE>
EOT
} elsif ($ipv4enabled) {
print "</TABLE>\n<INPUT TYPE=hidden NAME=protocol VALUE=IPv4>\n";
} elsif ($ipv6enabled) {
print "</TABLE>\n<INPUT TYPE=hidden NAME=protocol VALUE=IPv6>\n";
}
print <<EOT;
</TD>
<TD ALIGN=CENTER> <BR><INPUT NAME=addr SIZE=30><BR><FONT SIZE=-1> <SUP> </SUP> </FONT></TD>
<TD ALIGN=RIGHT> <BR><SELECT NAME=router>
EOT
my $remotelg = 0;
my $optgroup = 0;
for (my $i = 0; $i <= $#routers; $i++) {
my $router = $routers[$i];
if ($router =~ /^---- (.*) ----$/) {
$router = $1;
print "</OPTGROUP>\n" if ($optgroup);
print "<OPTGROUP LABEL=\"" . html_encode($router) . "\">\n";
$optgroup = 1;
next;
}
my $descr = "";
my $default = "";
if ($FORM{router} ne "") {
if ($router eq $FORM{router}) {
$default = " selected";
}
} elsif ($router eq $default_router) {
$default = " SELECTED";
}
if (defined $namemap{$router}) {
$descr = $namemap{$router};
} else {
$descr = $router;
}
if ($router_list{$router} =~ /^http/) {
$descr .= " *";
$remotelg++;
}
print "<OPTION VALUE=\"". html_encode($router) . "\"$default> " . html_encode($descr) . "\n";
}
print "</OPTGROUP>\n" if ($optgroup);
if ($remotelg) {
$remotelg = "<SUP>*</SUP> remote LG script";
} else {
$remotelg = "<SUP> </SUP> ";
}
print <<EOT;
</SELECT><BR><FONT SIZE=-1> $remotelg</FONT></TD>
</TR>
<TR><TD ALIGN=CENTER COLSPAN=3>
<P>
<INPUT TYPE=SUBMIT VALUE=Submit> | <INPUT TYPE=RESET VALUE=Reset>
<P>
</TD></TR>
</TABLE>
</TD></TR></TABLE>
</CENTER>
<P>
</FORM>
EOT
}
sub print_tail {
print <<EOT;
<P>
<HR SIZE=2 WIDTH="85%" NOSHADE>
$disclaimer
<P>
<CENTER>
<I>Please email questions or comments to <A HREF="mailto:$email">$email</A>.</I>
<P>
</CENTER>
</BODY>
</HTML>
EOT
}
sub print_error
{
print "<CENTER><FONT SIZE=+2 COLOR=\"#ff0000\">" . join(" ", @_) . "</FONT></CENTER>\n";
&print_tail;
exit 1;
}
sub print_warning
{
print "<CENTER><FONT SIZE=+2 COLOR=\"#0000ff\">WARNING! " . join(" ", @_) . "</FONT></CENTER>\n";
print <<EOT;
<P>
<HR SIZE=2 WIDTH="85%" NOSHADE>
<P>
EOT
}
my $regexp = 0;
sub run_command
{
my ($hostname, $host, $command) = @_;
my $best = 0;
my $count = 0;
my $telnet;
my $ssh;
my $ssh2;
my @output;
# This regexp is from RFC 2396 - URI Generic Syntax
if ($host !~ /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/) {
die ("Illegal URI: \"$host\"");
}
my $scheme = $2;
$host = $4;
if ($host !~ /^((([^:\@\[]+)(:([^\@]+))?)\@)?([^\/?#]*)$/) {
die ("Can't extract login/pass from host: \"$host\"");
}
my $login = $3;
my $password = $5;
$host = $6;
my $port;
if ($host =~ /^\[(.+)\](:([\d,]+))?$/) {
$host = $1;
$port = $3;
} elsif ($host =~ /^([^:]+)(:([\d,]+))?$/) {
$host = $1;
$port = $3;
} else {
die ("Illegal host address \"$host\"");
}
print "<B>Router:</B> " . html_encode($hostname) . "\n";
print "<BR>\n";
print "<B>Command:</B> " . html_encode($command) . "\n";
print "<P><PRE><CODE>\n";
if (($command =~ /show route protocol bgp aspath-regex \"(.*)\"/) ||
($command =~ /show ip bgp reg\w*\s+(.*)/)) {
$regexp = $1;
}
if ($scheme eq "rsh") {
print_error("Configuration error, missing rshcmd") if ($rshcmd eq "");
open(P, "$rshcmd $host \'$command\' |");
while (<P>) {
showlines($_);
}
close(P);
} elsif ($scheme eq "ssh") {
eval "
use IO::Handle;
use Net::SSH::Perl;
use Net::SSH::Perl::Cipher;
";
die $@ if $@;
my $remotecmd = "$command; quit";
$remotecmd = "set cli logical-system $logicalsystem{$FORM{router}}; " . $command if (defined $logicalsystem{$FORM{router}});
$port = 22 if ($port eq "");
my $ssh = Net::SSH::Perl->new($host, port => $port);
if ($] > 5.007) {
require Encode;
$login = Encode::encode_utf8($login);
$password = Encode::encode_utf8($password);
$remotecmd = Encode::encode_utf8($remotecmd);
}
$ssh->login($login, $password);
$ssh->register_handler('stdout', sub { showlines($_[1]->bytes); });
$ssh->register_handler('stderr', sub { showlines($_[1]->bytes); });
$ssh->cmd("$remotecmd");
} elsif ($scheme eq "ssh2") {
eval "
use Net::SSH2;
";
die $@ if $@;
my $remotecmd = "$command; quit";
$remotecmd = "set cli logical-system $logicalsystem{$FORM{router}}; " . $command if (defined $logicalsystem{$FORM{router}});
$port = 22 if ($port eq "");
$ssh2 = Net::SSH2->new();
$ssh2->connect($host, $port) or die $!;
if ($password) {
$ssh2->auth_password($login, $password);
} else {
$ssh2->auth_publickey($login, $ssh2pubkey, $ssh2key);
}
my $chan = $ssh2->channel();
$chan->blocking(1);
$chan->exec("$remotecmd");
while ($chan->read($_, 1024)) {
showlines($_);
};
$chan->close;
} elsif ($scheme eq "telnet") {
my @output;
eval "
use Net::Telnet;
";
die $@ if $@;
if ($ostypes{$FORM{router}} eq "zebra") {
if (($command =~ /^ping /) || ($command =~ /^traceroute /)) {
$port = $1 if ($port =~ /^(\d+),\d*$/);
$port = 2601 if ($port eq "");
} else {
$port = $1 if ($port =~ /^\d*,(\d+)$/);
$port = 2605 if ($port eq "");
}
}
$port = 23 if ($port eq "");
my $telnet = new Net::Telnet;
$telnet->errmode( sub { print "ERROR:" . join('|', @_) . "\n"; } );
$telnet->timeout($timeout);
$telnet->option_callback( sub { return; } );
$telnet->option_accept(Do => 31); # TELOPT_NAWS
$telnet->open(Host => $host,
Port => $port);
if ($login ne "") {
$telnet->waitfor('/(ogin|name|word):.*$/');
$telnet->print("$login");
}
if ($password ne "") {
$telnet->waitfor('/word:.*$/');
$telnet->print("$password");
}
$telnet->waitfor(Match => '/.*[\$%>] {0,1}$/',
Match => '/^[^#]*[\$%#>] {0,1}$/');
$telnet->telnetmode(0);
$telnet->put(pack("C9",
255, # TELNET_IAC
250, # TELNET_SB
31, 0, 200, 0, 0, # TELOPT_NAWS
255, # TELNET_IAC
240)); # TELNET_SE
$telnet->telnetmode(1);
my $telnetcmd = $command;
$telnetcmd .= " | no-more" if ($ostypes{$FORM{router}} eq "junos");
$telnet->print("$telnetcmd");
$telnet->getline; # read out command line
while (1) {
if ($#output >= 0) {
$_ = shift (@output);
} elsif (! $telnet->eof) {
my ($prematch, $match) = $telnet->waitfor(
Match => '/\n/',
Match => '/[\$%#>] {0,1}$/',
Errmode => "return")
or do {
};
if ($match =~ /[\$%#>] {0,1}$/) {
$telnet->print("quit");
$telnet->close;
last;
}
push @output, $prematch . $match;
next;
} else {
last;
}
showlines($_);
}
} else {
print_error("Configuration error, no such scheme: $scheme\n");
}
print "</CODE></PRE>\n";
}
my $best = 0;
my $hidden = 0;
my $count = 0;
my $telnet;
my $lastip = "";
my $inemptyheader = 1;
my $linebuf = "";
my $in_func_showlines = 0;
sub showlines {
my $input = shift;
if ($command =~ /^trace/i | $command =~ /^ping/i) {
if ($command =~ /^trace/i) {
$input =~ s/(\[AS\s+)(\d+)(\])/($1 . as2link($2) . $3)/e;
}
print $input;
return;
}
$linebuf .= $input;
return if ($in_func_showlines);
$in_func_showlines = 1;
while ($linebuf =~ /\n/) {
my $line1;
($line1, $linebuf) = split(/\n/, $linebuf, 2);
showline ($line1);
}
$in_func_showlines = 0;
}
sub showline {
$_ = shift;
chomp;
next if (/Type escape sequence to abort./);
next if (/Translating .*\.\.\.domain server/);
next if (/Logical system: /);
next if (($inemptyheader) && (/^$/));
$inemptyheader = 0;
$_ = html_encode($_);
if ($command eq "show ip bgp summary") {
s/( local AS number )(\d+)/($1 . as2link($2))/e;
s/^([\d\.]+\s+\d+\s+)(\d+)/($1 . as2link($2))/e;
s/^(\d+\.\d+\.\d+\.\d+)(\s+.*\s+)([1-9]\d*)$/($1 . $2 . bgplink($3, "neighbors+$1+routes"))/e;
s/^(\d+\.\d+\.\d+\.\d+)(\s+)/(bgplink($1, "neighbors+$1") . $2)/e;
# Zebra IPv6 neighbours
s/^(.{15} 4\s+)(\d+)/($1 . as2link($2))/e;
s/^([\dA-Fa-f]*:[\dA-Fa-f:]*)(\s+)/(bgplink($1, "neighbors+$1") . $2)/e;
s/^([\dA-Fa-f]*:[\dA-Fa-f:]*)$/bgplink($1, "neighbors+$1")/e;
} elsif ($command eq "show bgp ipv6 summary") {
s/^(.{15} 4\s+)(\d+)/($1 . as2link($2))/e;
if (/^([\dA-Fa-f]*:[\dA-Fa-f:]*)\s+4\s+/) {
$lastip = $1;
s/^([\dA-Fa-f:]+)(\s+.*\s+)([1-9]\d*)$/($1 . $2 . bgplink($3, "neighbors+${lastip}+routes"))/e;
s/^([\dA-Fa-f:]+)(\s+)/(bgplink($1, "neighbors+$1") . $2)/e;
$lastip = "";
}
if (/^([\dA-Fa-f:]+)$/) {
$lastip = $1;
s/^([\dA-Fa-f:]+)$/bgplink($1, "neighbors+$1")/e;
}
if (($lastip ne "") && (/^(\s+.*\s+)([1-9]\d*)$/)) {
s/^(\s+.*\s+)([1-9]\d*)$/($1 . bgplink($2, "neighbors+${lastip}+routes"))/e;
$lastip = "";
}
} elsif ($command eq "show bgp summary") {
# JunOS
if ($securemode) {
next if (/\.l[23]vpn/); # don't show MPLS
next if (/inet6?\.2/); # don't show multicast
next if (/\.inet6?\.0/); # don't show VRFs
}
if (/^([\dA-Fa-f:][\d\.A-Fa-f:]+)\s+/) {
$lastip = $1;
# IPv4
#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;
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;
# IPv4/IPv6
s/^([\dA-Fa-f:][\d\.A-Fa-f:]+\s+)(\d+)(\s+)/($1 . as2link($2) . $3)/e;
s/^([\dA-Fa-f:][\d\.A-Fa-f:]+)(\s+)/(bgplink($1, "neighbors+$1") . $2)/e;
}
if (($lastip ne "") && (/(\s+inet6?\.0: )(\d+)\/(\d+)\/(\d+)$/)) {
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;
}
} elsif (($command =~ /^show ip bgp\s+n\w*\s+[\d\.]+\s+(ro|re|a)/i) ||
($command =~ /^show bgp ipv6\s+n\w*\s+[\dA-Fa-f:]+\s+(ro|re|a)/i) ||
($command =~ /^show ip bgp\s+re/i) ||
($command =~ /^show bgp ipv6\s+re/i) ||
($command =~ /^show ip bgp\s+[\d\.]+\s+[\d\.]+\s+(l|s)/i) ||
($command =~ /^show (ip bgp|bgp ipv6) prefix-list/i) ||
($command =~ /^show (ip bgp|bgp ipv6) route-map/i)) {
s/^([\*r ](>|d|h| ).{59})([\d\s,\{\}]+)([ie\?])$/($1 . as2link($3, $regexp) . $4)/e;
s/^([\*r ](>|d|h| )[i ])([\d\.A-Fa-f:\/]+)(\s+)/($1 . bgplink($3, $3) . $4)/e;
s/^([\*r ](>|d|h| )[i ])([\d\.A-Fa-f:\/]+)$/($1 . bgplink($3, $3))/e;
s/^(( ){20}.{41})([\d\s,\{\}]+)([ie\?])$/($1 . as2link($3, $regexp) . $4)/e;
s/(, remote AS )(\d+)(,)/($1 . as2link($2) . $3)/e;
} elsif ($command =~ /^show route (?:advertising|receive)-protocol bgp [\d\.A-Fa-f:]+ [\d\.A-Fa-f:\/]+ /i) {
s/^([ \*] )([\d\.A-Fa-f:\/]+)(\s+)/($1 . bgplink($2, $2) . $3)/e;
s/^( AS path: )([\d\s,\{\}\[\]]+)( [IE\?] \((?:LocalAgg)?\))$/($1 . as2link($2) . $3)/e;
s/^( Communities: )([\d: ]+)/($1 . community2link($2))/e;
} elsif ($command =~ /^show route ((advertising|receive)-protocol) bgp\s+([\d\.A-Fa-f:]+)/i) {
my $type = $1;
my $ip = $3;
s/^([\* ] [\d\.\s].{62})([\d\s,\{\}\[\]]+)([IE\?])$/($1 . as2link($2) . $3)/e;
s/^([\* ] [\d\.\s].{22}\s)([\d\.A-Fa-f:]+)(\s+)/($1 . bgplink($2, "neighbors+$2") . $3)/e;
s/^([\dA-Fa-f:\/]+)(\s+)/(bgplink($1, "$1+exact") . $2)/e;
s/^([\d\.\/]+)(\s+)/(bgplink($1, "$1+exact") . $2)/e;
s/^([\dA-Fa-f:\/]+)(\s*)$/(bgplink($1, "$1+exact") . $2)/e;
s/^([\d\.\/]+)\s*$/(bgplink($1, "$1+exact"))/e;
s/^([ \*] )([\d\.A-Fa-f:\/]+)(\s+)/($1 . bgplink($2, "neighbors+$ip+" . (($type eq "advertising-protocol")?"advertised-routes":"receive-protocol") . "+$2") . $3)/e;
} elsif (($command =~ /^show ip bgp n\w*\s+([\d\.]+)/i) ||
($command =~ /^show ip bgp n\w*$/i)) {
$lastip = $1 if ($1 ne "");
$lastip = $1 if (/^BGP neighbor is ([\d\.]+),/);
if ($securemode) {
s/((Local|Foreign) port: )\d+/${1}???/g;
}
s/(Prefix )(advertised)( [1-9]\d*)/($1 . bgplink($2, "neighbors+$lastip+advertised-routes") . $3)/e;
s/( Prefixes Total: )(\d+)( )/($1 . bgplink($2, "neighbors+$lastip+advertised-routes") . $3)/e;
s/(prefixes )(received)( [1-9]\d*)/($1 . bgplink($2, "neighbors+$lastip+routes") . $3)/e;
s/^( Prefixes Current: \s+)(\d+)(\s+)(\d+)/($1 . bgplink($2, "neighbors+$lastip+advertised-routes") . $3 . bgplink($4, "neighbors+$lastip+routes"))/e;
s/(\s+)(Received)( prefixes:\s+[1-9]\d*)/($1 . bgplink($2, "neighbors+$lastip+routes") . $3)/e;
s/^( Saved \(soft-reconfig\):\s+)(\d+|n\/a)(\s+)(\d+)/($1 . $2 . $3 . bgplink($4, "neighbors+$lastip+received-routes"))/e;
s/( [1-9]\d* )(accepted)( prefixes)/($1 . bgplink($2, "neighbors+$lastip+routes") . $3)/e;
s/^( [1-9]\d* )(accepted|denied but saved)( prefixes consume \d+ bytes)/($1 . bgplink($2, "neighbors+$lastip+received-routes") . $3)/e;
s/^(BGP neighbor is )(\d+\.\d+\.\d+\.\d+)(,)/($1 . pinglink($2) . $3)/e;
s/^( Description: )(.*)$/$1<B>$2<\/B>/;
s/(,\s+remote AS )(\d+)(,)/($1 . as2link($2) . $3)/e;
s/(, local AS )(\d+)(,)/($1 . as2link($2) . $3)/e;
s/( update prefix filter list is )(\S+)/($1 . bgplink($2, "prefix-list+$2"))/e;
s/(Route map for \S+ advertisements is\s+)(\S+)/($1 . bgplink($2, "route-map+$2"))/e;
} elsif ($command =~ /^show bgp ipv6 n\w*\s+([\dA-Fa-f:]+)/i) {
my $ip = $1;
if ($securemode) {
s/((Local|Foreign) port: )\d+/${1}???/g;
}
s/(Prefix )(advertised)( [1-9]\d*)/($1 . bgplink($2, "neighbors+$ip+advertised-routes") . $3)/e;
s/^( [1-9]\d* )(accepted)( prefixes)/($1 . bgplink($2, "neighbors+$ip+routes") . $3)/e;
s/^( Description: )(.*)$/$1<B>$2<\/B>/;
s/(\s+remote AS )(\d+)(,)/($1 . as2link($2) . $3)/e;
s/(\s+local AS )(\d+)(,)/($1 . as2link($2) . $3)/e;
s/( update prefix filter list is )(\S+)/($1 . bgplink($2, "prefix-list+$2"))/e;
s/(Route map for \S+ advertisements is\s+)(\S+)/($1 . bgplink($2, "route-map+$2"))/e;
} elsif ($command =~ /^show bgp n\w*\s+([\d\.A-Fa-f:]+)/i) {
my $ip = $1;
if ($securemode) {
if ($hidden) {
$hidden = 0 unless (/^ /);
next if ($hidden);
}
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;
if (/^ Table (.*\.l[23]vpn|inet6?\.2|\S+\.inet6?\.0)/) {
s/^( Table) \S+/$1 (hidden)/g;
$hidden = 1;
}
}
s/(\s+AS )(\d+)/($1 . as2link($2))/eg;
s/(\s+AS: )(\d+)/($1 . as2link($2))/eg;
s/^( Active prefixes:\s+)(\d+)/($1 . bgplink($2, "neighbors+$ip+routes"))/e;
s/^( Received prefixes:\s+)(\d+)/($1 . bgplink($2, "neighbors+$ip+routes+all"))/e;
s/^( Suppressed due to damping:\s+)(\d+)/($1 . bgplink($2, "neighbors+$ip+routes+damping+suppressed"))/e;
s/^( Advertised prefixes:\s+)(\d+)/($1 . bgplink($2, "neighbors+$ip+advertised-routes"))/e;
s/^( )(Export)(: )/($1 . bgplink($2, "neighbors+$ip+advertised-routes") . $3)/e;
s/^( )(Import)(: )/($1 . bgplink($2, "neighbors+$ip+routes+all") . $3)/e;
# JUNOS bugfix
s/([^ ])( )(Import)(: )/($1 . "\n " . $2 . bgplink($3, "neighbors+$ip+routes+all") . $4)/e;
} elsif ($command =~ /^show route protocol bgp .* terse/i) {
s/^(.{20} B .{25} (?:>| ).{15}[^ ]*)( [\d\s,\{\}]+)(.*)$/($1 . as2link($2, $regexp) . $3)/e;
s/^([\* ] )([\d\.A-Fa-f:\/]+)(\s+)/($1 . bgplink($2, "$2+exact") . $3)/e;
} elsif (($command =~ /^show route protocol bgp /i) ||
($command =~ /^show route aspath-regex /i)) {
if ($securemode) {
s/(Task: BGP_[\d\.A-Fa-f:]+\+)\d+/${1}???/g;
}
if (/^ (.)BGP /) {
if ($1 eq "*") {