?? indexmaker
字號:
#! /usr/sepp/bin/perl# -*- mode: Perl -*-################################################################### MRTG 2.8.12 --- Index Generator#################################################################### This reads a mrtg.cfg file form std input or cmdline argument# and it takes a regexp on the cmdline to specify which # targets to look at.## from this info it produces a router index on std out or# on the filename specified by the -o option#################################################################### Created by Tobias Oetiker <oetiker@ee.ethz.ch># Massive patch from From andre@ml.ee Thu Feb 25 21:13:01 1999## Inclusion of the -o option by mvitorino@automail.pt Tue Jul 13 18:33:53 1999## Distributed under the GNU copyleft#################################################################### Few defaults:$regexp = ".";$pagetop = 0;$hruler = 0;$columns = 2;$sorted = 0;$numbered = 0;$WIDTH = 500;$HEIGHT = 135; # decent options: 135, 185, 235$title = 'All targets';$match = '.';$nomatch = undef;$perfile = 0;$showargs = 1;$runArgz = '';$graphs = 1;$argz = join($",@ARGV);$filename = '';$view = 'day';sub ParseOptions {while ($ARGV[0] =~ /^\-./) { if ($ARGV[0] eq '-t') { shift @ARGV ; $title = $ARGV[0]; shift @ARGV} elsif ($ARGV[0] eq '-r') { shift @ARGV ; $regexp = $ARGV[0]; shift @ARGV} elsif ($ARGV[0] eq '-b') { shift @ARGV ; $bgcolor = $ARGV[0]; shift @ARGV} elsif ($ARGV[0] eq '-o') { shift @ARGV ; $filename = $ARGV[0]; shift @ARGV} elsif ($ARGV[0] eq '-Y') { shift @ARGV ; $HEIGHT = $ARGV[0]; shift @ARGV} elsif ($ARGV[0] eq '-X') { shift @ARGV ; $WIDTH = $ARGV[0]; shift @ARGV} elsif ($ARGV[0] eq '-v') { shift @ARGV ; $view = $ARGV[0]; shift @ARGV} elsif ($ARGV[0] eq '-F') { FlushPerFile() if (!$perfile); $perfile = 1; shift @ARGV} elsif ($ARGV[0] eq '-f') { FlushPerFile() if ($perfile); $perfile = 0; shift @ARGV} elsif ($ARGV[0] eq '-P') { $pagetop = 1; shift @ARGV} elsif ($ARGV[0] eq '-p') { $pagetop = 0; shift @ARGV} elsif ($ARGV[0] eq '-H') { $hruler = 1; shift @ARGV} elsif ($ARGV[0] eq '-h') { $hruler = 0; shift @ARGV} elsif ($ARGV[0] eq '-1') { $columns = 1; shift @ARGV} elsif ($ARGV[0] eq '-2') { $columns = 2; shift @ARGV} elsif ($ARGV[0] eq '-S') { $sorted = 1; shift @ARGV} elsif ($ARGV[0] eq '-s') { $count = $sorted = 0; shift @ARGV} elsif ($ARGV[0] eq '-N') { $numbered = 1; shift @ARGV} elsif ($ARGV[0] eq '-n') { $number = $numbered = 0; shift @ARGV} elsif ($ARGV[0] eq '-G') { $graphs = 1; shift @ARGV} elsif ($ARGV[0] eq '-g') { $graphs = 0; shift @ARGV} elsif ($ARGV[0] eq '-A') { $showargs = 1; shift @ARGV} elsif ($ARGV[0] eq '-a') { $showargs = 0; shift @ARGV} elsif ($ARGV[0] eq '-M') { shift @ARGV ; $regexp=$match = $ARGV[0]; shift @ARGV} elsif ($ARGV[0] eq '-m') { shift @ARGV ; $nomatch = $ARGV[0]; shift @ARGV} else { print STDERR "Unknown option: $ARGV[0]\n" ; shift @ARGV }} if ($title) { $Title = "$title Overview"; } else { $Title = "Overview"; } $Columns = $columns-1; SWITCH: { $view = 'day', last SWITCH if $view =~ /^d/i; $view = 'week', last SWITCH if $view =~ /^w/i; $view = 'month', last SWITCH if $view =~ /^m/i; $view = 'year', last SWITCH if $view =~ /^y/i; $view = 'day' }} # ParseOptionsif (! $ARGV[0]) { Usage(); }sub Usage { die <<HELP;USAGE: indexmaker [options] <mrtg.cfg> [options] <other.cfg> [options] .. .. This tool will read the contents of each mrtg.cfg file and will return the HTML code of a webpage contanig the 'daily' graphs of all the routers whose titles match the regular expression. Options: -o filename : set output filename (default: stdout) -r regexp : use regular expression 'regexp' to match targets (default: '$regexp') -t Title : set 'Title' of index page (default: '$title') -b color : set background color bgcolor (eg. -b #ffffff) (default: '$bgcolor') -1 : make 1-column graph page (default: $columns) -2 : make 2-column table page -P : set to parse PageTop tags for graph names in index page (default: $pagetop) this reads the text immediately following the PageTop tag. -p : unset parsing of PageTop tags for graph names in index page -H : set use of <HR> tag between graphs. (default: $hruler) -h : unset use of <HR> tag between graphs. -S : sorted. present graphs in alphabetic order (default: $sorted) -s : unsorted. present graphs in order as they appear in config file -N : numbered. prepend sequence number for each graph. -n : not numbered. (default: $numbered) -X : specify WIDTH for graphs (default: $WIDTH) -Y : specify HEIGHT for graphs (default: $HEIGHT) -M regexp : include only Targets whose Title match given regexp (same as -r) -m regexp : from those that pass -M exclude those that match -m regexp -A : add indexmaker arguments to a comment of generated html page. (default: $showargs) -a : do not. (use to memorise the command line used to generate this page) -G : add graphs to the index pages (default: $graphs) -g : don't add graphs to the index pages -F : try to apply all of the above in per config file manner. -v : which graphs (d)aily, (w)eekly, (m)onthly, (y)early Options can appear between config filenames, thus allowing you to construct more complex and flexible rules for creating index files. You can use wildcards in filenames. You may find "-s -S" and "-n -N" useful between filenames.EXAMPLE: indexmaker -t 'All my Routers' -r '.' -o /home/httpd/stats/index.html mrtg.cfgYou may also want to change defaults to suite your most frequent options.HELP}sub FlushPerFile { WriteIndex(); undef(%titles); undef(%dirs); CloseTable();}#ParseOptions();while ($ARGV[0]) { ParseOptions(); Readcfg(); Header(); FlushPerFile() if ($perfile); shift @ARGV;}FlushPerFile() if (!$perfile);Footer();if (!$success) { Usage(); }sub Readcfg { #slurp the cfg file $last="1"; if (!open(FILE,$ARGV[0]) ) { print STDERR "Can't open '$ARGV[0]': $!\n" ; return; } $TargNR = ''; while(<FILE>) { s/\t/ /g; #replace tabs by spac next if /^\s+$/; #ignore white space next if /^\s*\#/; #ignore comments next if /^[a-z]+\[(\$|\^|_)\]:/i; #ignore 'default values' if (/^title\[([^\]]+)\]:\s*(.*$regexp.*)/i) { $router=lc($1); $arg=$2; if ($nomatch && $arg =~ /$nomatch/i) { next } $exclude{$router} = 0; if (!$sorted && $router !~ /^$last$/) { $count++; $TargNR = sprintf("%03d. ",$count); # we number the targets here # to get unsorted output later $last = $router; } $titles{$router} = "$TargNR$arg"; $dirs{$router} = $dirs{'^'} if ($dirs{'^'}); $success=1; # we matched at least 1 target next; } if (/^directory\[([^\]]+)\]:\s*(.*\S)/i) { $arg = $2; $tmp = lc($1); $dirs{$tmp} = "$arg/"; } if (/^icondir:\s*(.*\S)/i) { $icondir = "$1/"; next; } if (/^pagetop\[([^\]]+)\]:\s*(.*\S)/i) { $titles{$1} = $2; $titles{$1} =~ s/<[^>]+>//g; #drop tags } $router = ''; }} # Readcfgsub Header { if (!$success) { return; } if (!$perfile && $headeronce) { return; } if (!defined(%titles)) { return; } if ($filename eq '') { open(FOUT,">-"); } else { if (!open(FOUT,">$filename")) { print STDERR "Invalid filename: ($filename)\n"; return; } } if ($showargs) { $runArgz = "<!-- commandline was: indexmaker $argz -->\n"; } $BODY = "<BODY>"; if ($bgcolor) { $BODY = "<BODY bgcolor=\"$bgcolor\">" } print FOUT <<ECHO;<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"><TITLE>$Title</TITLE></HEAD>$BODYECHO if (!$headeronce) { print FOUT $runArgz; print FOUT <<'ECHO' if $ENV{USER} eq 'oetiker';<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%"> <TR><TD><A HREF="http://www.ethz.ch/"> <img border=0 alt="ETH: " src="/eth.199x32.gif" HEIGHT=32 WIDTH=199></A> </TD> <TD ALIGN=RIGHT> <A HREF="http://www.ethz.ch/"> Swiss Federal Institute of Technology Zurich</A><BR> <A HREF="http://www.ee.ethz.ch/"> Department of Electrical Engineering</A><BR> </TD> </TR></TABLE>ECHO } $headeronce++; $file=''; $file = " ($ARGV[0])" if ($perfile); print FOUT "<H1>$Title$file</H1>";}sub WriteIndex { if ( ! defined(%titles)) { return; } OpenTable() if (!defined($TableSide)); $TargNR = ''; foreach $router (sort {$titles{$a} cmp $titles{$b}} keys %titles) { next unless $exclude{$router}==0; $dirs{$router} = "" if (!defined($dirs{$router})); $rdir = $dirs{$router}; $Title = $titles{$router}; if (!$sorted) { $Title =~ s/^[0-9][0-9][0-9]\. //; # we must strip off temp numbering } if ($numbered) { $number++; $TargNR = sprintf("%03d. ",$number); $Title = "$TargNR$Title"; } if ( $Columns) { if ($TableSide eq "left" ) { $TableStart="<TR><TD>"; $TableStop ="$HR</TD>"; $TableSide="right"; } else { $TableStart="<TD>"; $TableStop ="$HR</TD></TR>"; $TableSide="left"; } } print FOUT <<ECHO;$TableStart <P><A HREF="$rdir$router.html"><B>$Title</B></A></P> <P><SMALL><!--#flastmod file="$rdir$router.html" --></SMALL></P>ECHO if ($graphs) { print FOUT <<ECHO; <A HREF="$rdir$router.html"><IMG ALT="$router Traffic Graph" BORDER=0 WIDTH=$WIDTH HEIGHT=$HEIGHT SRC="$rdir$router-$view.gif"></A>ECHO} print FOUT "$TableStop"; print FOUT "<HR>" if ($hruler && !$Columns); } # foreach } # Writeindexsub OpenTable { $TableSide="left"; if ($Columns) { print FOUT "<TABLE BORDER=0 WIDTH=\"100%\">\n"; $HR="<HR>" if ($hruler); }}sub CloseTable { return if (!defined($TableSide)); if ($Columns) { if ( $TableSide eq "right" ){ print FOUT "<td></td></tr>\n"; } print FOUT "</table>\n"; } undef($TableSide);}sub Footer {if (!$success) { return; }$VERSION = "2.8.12";print FOUT <<ECHO;<BR><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0> <TR> <TD WIDTH=63><A HREF="http://www.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg.html"><IMG BORDER=0 SRC="${icondir}mrtg-l.gif" WIDTH=63 HEIGHT=25 ALT="MRTG"></A></TD> <TD WIDTH=25><A HREF="http://www.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg.html"><IMG BORDER=0 SRC="${icondir}mrtg-m.gif" WIDTH=25 HEIGHT=25 ALT=""></A></TD> <TD WIDTH=388><A HREF="http://www.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg.html"><IMG BORDER=0 SRC="${icondir}mrtg-r.gif" WIDTH=388 HEIGHT=25 ALT="Multi Router Traffic Grapher"></A></TD> </TR></TABLE><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0> <TR VALIGN=top> <TD WIDTH=88 ALIGN=RIGHT><FONT FACE="Arial,Helvetica" SIZE=2> version $VERSION</FONT></TD> <TD WIDTH=388 ALIGN=RIGHT><FONT FACE="Arial,Helvetica" SIZE=2> <A HREF="http://www.ee.ethz.ch/~oetiker/">Tobias Oetiker</A> <A HREF="mailto:oetiker\@ee.ethz.ch"><oetiker\@ee.ethz.ch></A> and <A HREF="http://www.bungi.com/">Dave Rand</A> <A HREF="mailto:dlr\@bungi.com"><dlr\@bungi.com></A></FONT> </TD></TR></TABLE></BODY></HTML>ECHO}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -