Debian Codegraph @

contrib/ovmrtg/index

raw
1 #!/usr/local/gnu/bin/perl5
2 # -*- mode: Perl -*-
3 ##################################################################
4 # Multi Router Traffic Grapher: Index Generator
5 ##################################################################
6 #
7 # This reads a mrtg.cfg file form std input or cmdline argument
8 # and it takes a regexp on the cmdline to specify which
9 # targets to look at.
10 #
11 # from this info it produces a router index on std out.
12 #
13 ##################################################################
14 # Created by Tobias Oetiker <[email protected]>
15 # Modifications by Laurie Gellatly <[email protected]>
16 # Distributed under the GNU copyleft
17 #
18 # $Id: index,v 1.1.1.1 2002/02/26 10:16:36 oetiker Exp $
19 ##################################################################
20
21
22 $regexp = pop @ARGV;
23 $Title = pop @ARGV;
24 if (defined($Title) && -f $Title) {
25 push(@ARGV, $Title);
26 $Title = "$Title Overview ($regexp)";
27 }
28 if (! -f $ARGV[0]) {
29 print "
30
31 USAGE: index <mrtg.cfg> <title> <regular expression>
32
33 This tool will read the contents of the mrtg.cfg file and will
34 return the HTML code of a webpage contanig the 'daily' graphs
35 of all the routers whose titles match the regular expression.
36
37 NOTE: you have to adjust this tool to your needs as the HTML
38 contains our logo and our name ...
39
40 ";
41
42 exit ;
43
44 }
45
46 #slurp the cfg file
47 while(<>) {
48 s/\t/ /g; #replace tabs by spac
49 next if /^\s+$/; #ignore white space
50 next if /^\s*\#/; #ignore comments
51 if (/$regexp/i && ! /\[\^\]/ && ! /\[\$\]/ && /^title\[([^\]]+)\]:\s*(.*\S)/i) {
52 $router=lc($1);
53 $arg=$2;
54 $titles{$router} = $arg;
55 next;
56 }
57 if (/^directory\[([^\]]+)\]:\s*(.*\S)/i) {
58 $arg = $2;
59 $tmp = lc($1);
60 $dirs{$tmp} = "$arg/";
61 }
62 if ($router && /^pagetop\[([^\]]+)\]:\s*(.*\S)/i) {
63 next;
64 }
65 if ($router && /^\s+(.*?)<\/H1>/) {
66 $titles{$router} .= " $1";
67 }
68 $router = '';
69 }
70
71 $Today=datestr(time);
72 print <<ECHO;
73 <HTML>
74 <HEAD>
75 <TITLE>$Title</TITLE>
76 <META HTTP-EQUIV="Refresh" CONTENT=300 >
77 </HEAD>
78 <BODY bgcolor=#ffffff>
79
80 <H1>$Title</H1>
81
82 These statistics were last updated <B>$Today </B>
83
84 ECHO
85
86 foreach $router (sort {$titles{$a} cmp $titles{$b}} keys %titles) {
87 $dirs{$router} = "" if (!defined($dirs{$router}));
88 $rdir = $dirs{$router};
89 print <<ECHO;
90 <P><B><A HREF="$rdir$router.html">$titles{$router}</B><P>
91 <SMALL><!--#flastmod file="$rdir$router.html" --></SMALL></P>
92 <IMG BORDER=0 WIDTH=500 HEIGHT=135 SRC="$rdir$router-day.gif"></A>
93 <HR>
94 ECHO
95 }
96
97 '$Revision: 1.1.1.1 $ ' =~ /Revision: (\S*)/;
98 $rev=$1;
99 '$Date: 2002/02/26 10:16:36 $ ' =~ /Date: (\S*)/;
100 $date=$1;
101
102 print <<ECHO;
103 <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
104 <TR>
105 <TD WIDTH=63><A ALT="MRTG"
106 HREF="http://www.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg.html"><IMG
107 BORDER=0 SRC="../mrtg-l.gif"></A></TD>
108 <TD WIDTH=25><A ALT=""
109 HREF="http://www.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg.html"><IMG
110 BORDER=0 SRC="../mrtg-m.gif"></A></TD>
111 <TD WIDTH=388><A ALT=""
112 http://www.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg.html"><IMG
113 BORDER=0 SRC="../mrtg-r.gif"></A></TD>
114 </TR>
115 </TABLE>
116
117 <SPACER TYPE=VERTICAL SIZE=4>
118 <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
119 <TR VALIGN=top>
120 <TD WIDTH=88 ALIGN=RIGHT><FONT FACE="Arial,Helvetica" SIZE=2>
121 $rev-$date</FONT></TD>
122 <TD WIDTH=388 ALIGN=RIGHT><FONT FACE="Arial,Helvetica" SIZE=2>
123 <A HREF="http://www.ee.ethz.ch/~oetiker">Tobias Oetiker</A>
124 <A HREF="mailto:oetiker\@ee.ethz.ch">&lt;oetiker\@ee.ethz.ch&gt;</A>
125 and&nbsp;<A HREF="http://www.bungi.com">Dave&nbsp;Rand</A>&nbsp;<A HREF="mailto:dlr\@bungi.com">&lt;dlr\@bungi.com&gt;</A><br>
126 <A HREF="../routers.html">Back to Main Router List</A></FONT>
127
128
129 </TR>
130 </TABLE>
131 </BODY></HTML>
132 ECHO
133
134 sub datestr {
135 my ($time) = shift(@_) || return 0;
136 my ($wday) = ('Sunday','Monday','Tuesday','Wednesday',
137 'Thursday','Friday','Saturday')[(localtime($time))[6]];
138 my ($month) = ('January','February' ,'March' ,'April' ,
139 'May' , 'June' , 'July' , 'August' , 'September' ,
140 'October' ,
141 'November' , 'December' )[(localtime($time))[4]];
142 my ($mday,$year,$hour,$min) = (localtime($time))[3,5,2,1];
143 if ($min<10) {$min = "0$min";}
144 return "$wday, $mday $month ".($year+1900)." at $hour:$min";
145 }
146
147
148
149