| 1 |
#! /home/oetiker/.plenv/shims/perl -w |
| 2 |
# -*- mode: Perl -*- |
| 3 |
################################################################## |
| 4 |
# MRTG 2.17.10 --- 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 stdout or |
| 12 |
# on the filename specified by the --output option |
| 13 |
# |
| 14 |
################################################################## |
| 15 |
# Distributed under the GNU General Public License |
| 16 |
# Copyright 2000 by Tobias Oetiker <[email protected]> |
| 17 |
################################################################## |
| 18 |
|
| 19 |
$main::GRAPHFMT="png"; |
| 20 |
|
| 21 |
require 5.005; |
| 22 |
use strict; |
| 23 |
|
| 24 |
# DEBUG TARGETS |
| 25 |
# base - basic program flow |
| 26 |
#@main::DEBUG=qw(base); |
| 27 |
|
| 28 |
BEGIN { |
| 29 |
# Automatic OS detection ... do NOT touch |
| 30 |
if ( $^O =~ /^(?:(ms)?(dos|win(32|nt)?))/i ) { |
| 31 |
$main::OS = 'NT'; |
| 32 |
$main::SL = '\\'; |
| 33 |
$main::PS = ';'; |
| 34 |
} elsif ( $^O =~ /^NetWare$/i ) { |
| 35 |
$main::OS = 'NW'; |
| 36 |
$main::SL = '/'; |
| 37 |
$main::PS = ';'; |
| 38 |
} elsif ( $^O =~ /^VMS$/i ) { |
| 39 |
$main::OS = 'VMS'; |
| 40 |
$main::SL = '.'; |
| 41 |
$main::PS = ':'; |
| 42 |
} else { |
| 43 |
$main::OS = 'UNIX'; |
| 44 |
$main::SL = '/'; |
| 45 |
$main::PS = ':'; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
use FindBin; |
| 50 |
use lib "${FindBin::Bin}"; |
| 51 |
use lib "${FindBin::Bin}${main::SL}..${main::SL}lib${main::SL}mrtg2"; |
| 52 |
|
| 53 |
use MRTG_lib "2.100016"; |
| 54 |
use Getopt::Long; |
| 55 |
use Pod::Usage; |
| 56 |
|
| 57 |
#---------------------------------------------------------------------- |
| 58 |
sub decimal_sort($$) { |
| 59 |
my $a = $_[0]; |
| 60 |
my $b = $_[1]; |
| 61 |
|
| 62 |
$a =~ s/([0-9]+)/sprintf("%09u",${1})/ge; |
| 63 |
$b =~ s/([0-9]+)/sprintf("%09u",${1})/ge; |
| 64 |
return $a cmp $b; |
| 65 |
} |
| 66 |
#---------------------------------------------------------------------- |
| 67 |
|
| 68 |
my @argv = @ARGV; |
| 69 |
my $argz = "$0"; |
| 70 |
foreach my $ar (@argv) { |
| 71 |
if ($ar =~ /[ |()]/ ) { |
| 72 |
$ar = sprintf qq{"%s"}, $ar; |
| 73 |
} |
| 74 |
$argz .= " $ar"; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
main(); |
| 79 |
exit 0; |
| 80 |
|
| 81 |
sub main { |
| 82 |
# default options |
| 83 |
my %opt = ( |
| 84 |
sort => 'original', |
| 85 |
show => 'day', |
| 86 |
section => 'h1', |
| 87 |
columns => 2, |
| 88 |
addhead => '', |
| 89 |
bodyopt => 'bgcolor="#ffffff" text="#000000" '. |
| 90 |
'link="#000000" vlink="#000000" alink="#000000"', |
| 91 |
title => 'MRTG Index Page', |
| 92 |
headlevel => 1, |
| 93 |
pagetopend => '', |
| 94 |
pagetop => '', |
| 95 |
pageend => '', |
| 96 |
prefix => '', |
| 97 |
rrdviewer => '/cgi-bin/14all.cgi', |
| 98 |
optlog => 1, |
| 99 |
bold => 1, |
| 100 |
boldon => '<B>', |
| 101 |
boldoff => '</B>', |
| 102 |
div => 'DIV', |
| 103 |
imgborder => 1, |
| 104 |
cellspacing => 10, |
| 105 |
nolegend => 0, |
| 106 |
); |
| 107 |
$opt{headon} = "<H$opt{headlevel}>"; |
| 108 |
$opt{headoff} = "</H$opt{headlevel}>"; |
| 109 |
# load real options |
| 110 |
options(\%opt); |
| 111 |
|
| 112 |
#adapt some defaults to the current options |
| 113 |
die "ERROR: --autoprefix requires --output" |
| 114 |
if ($opt{autoprefix} and !defined $opt{output}); |
| 115 |
$opt{pageend} = $opt{pagetopend} if (defined $opt{pagetopend} and not $opt{pageend}); |
| 116 |
$opt{pagetop} = $opt{pagetopend} if (defined $opt{pagetopend} and not $opt{pagetop}); |
| 117 |
$opt{boldon} = $opt{boldoff} = "" if (!$opt{bold}); |
| 118 |
$opt{picfirst} = (defined $opt{picfirst}?1:0); |
| 119 |
if ($opt{compact}) { |
| 120 |
$opt{imgborder} = 0; |
| 121 |
$opt{cellspacing} = 0; |
| 122 |
$opt{headon} = $opt{boldon}; |
| 123 |
$opt{headoff} = $opt{boldoff}; |
| 124 |
} |
| 125 |
if ($opt{sidebyside}) { |
| 126 |
$opt{div} = 'td'; |
| 127 |
} |
| 128 |
|
| 129 |
# slurp config files |
| 130 |
my %rcfg; |
| 131 |
my %cfg; |
| 132 |
my @target; |
| 133 |
my @routers; |
| 134 |
my $cfgfile; |
| 135 |
my %files; |
| 136 |
while (@ARGV) { |
| 137 |
$cfgfile = shift @ARGV; |
| 138 |
readcfg($cfgfile,\@routers,\%cfg,\%rcfg); |
| 139 |
if (($opt{sectionhost}) or ($opt{perhost})) { |
| 140 |
#We need to cache the "hostname" as appeared in cfgfile, |
| 141 |
#since it does change in cfgcheck (for ex. if multiple |
| 142 |
#overlapping cfgfiles are specified) |
| 143 |
for my $targ (@routers) { |
| 144 |
if ( !defined $rcfg{host}{$targ} and |
| 145 |
!($rcfg{target}{$targ} =~ m/(?<!\\)[ \`]/) ) { |
| 146 |
$rcfg{target}{$targ} =~ m/.*[^\\]@([^:]*)/; |
| 147 |
$rcfg{host}{$targ} = ucfirst $1 if (defined $1); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
cfgcheck(\@routers, \%cfg, \%rcfg, \@target); |
| 152 |
for my $targ (@routers) { |
| 153 |
if (! defined $files{$targ}) { |
| 154 |
$files{$targ}=substr($cfgfile,rindex($cfgfile,'/')+1); |
| 155 |
} |
| 156 |
} |
| 157 |
if ($opt{autoprefix}) { |
| 158 |
$rcfg{prefixes} = {} if (!defined $rcfg{prefixes}); |
| 159 |
my $pref = subpath($cfg{htmldir},$opt{output}); |
| 160 |
for my $targ (@routers) { |
| 161 |
$rcfg{prefixes}->{$targ} = $pref |
| 162 |
if (! defined $rcfg{prefixes}->{$targ}); |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
# generate index page |
| 167 |
genindex(\@routers, \%cfg, \%rcfg, \%opt, \%files); |
| 168 |
} |
| 169 |
|
| 170 |
sub cleanurl ($) { |
| 171 |
my $url = shift; |
| 172 |
$url =~ s|([^/.][^/.]*/)\.\./\1|$1|g; |
| 173 |
return $url; |
| 174 |
} |
| 175 |
|
| 176 |
#Take a path the mrtg (usually the mrtg output directory) and the overview |
| 177 |
#file, find the relative path from the overview to the directory |
| 178 |
sub subpath ($$) { |
| 179 |
my $sub = shift; |
| 180 |
my $out = shift; |
| 181 |
my @s=split /$main::SL/,$sub; |
| 182 |
my @o=split /$main::SL/,$out; |
| 183 |
pop @o; #Last is a filename; |
| 184 |
for my $i (0..$#s) { #cut common dirs |
| 185 |
if (defined $s[0] and |
| 186 |
defined $o[0] and |
| 187 |
$s[0] eq $o[0] ) { |
| 188 |
shift @s; |
| 189 |
shift @o; |
| 190 |
} |
| 191 |
} |
| 192 |
my $ret = join $main::SL,@s; |
| 193 |
for my $i (0..$#o) { |
| 194 |
$ret = "..$main::SL$ret"; # ".." == "Directory below this one" for |
| 195 |
# dos, windows, unix. What about VMS ? |
| 196 |
# Is this correct ? HEH |
| 197 |
} |
| 198 |
$ret .= $main::SL; #Possibly this should be "/" in order not |
| 199 |
#to break on platforms !unix, since it will be |
| 200 |
#used for generating urls ? |
| 201 |
#Don't degenerate in "/" when really no prefix is needed. |
| 202 |
$ret = "" if ($ret eq $main::SL); |
| 203 |
return $ret; |
| 204 |
} |
| 205 |
|
| 206 |
sub genindex ($$$$) { |
| 207 |
my $routers = shift; |
| 208 |
my $cfg = shift; |
| 209 |
my $rcfg = shift; |
| 210 |
my $opt = shift; |
| 211 |
my $cfgfile = shift; |
| 212 |
my $index; |
| 213 |
my $metaCmdLine; |
| 214 |
# ----------------------------------------------------------- |
| 215 |
# keep only the items our users want (--filter) |
| 216 |
# ----------------------------------------------------------- |
| 217 |
my @filtered; |
| 218 |
ITEM: foreach my $item (@{$routers}) { |
| 219 |
foreach my $filter (@{$$opt{filter}}) { |
| 220 |
if ($filter =~ /(.+)([=!]~)(.+)/) { |
| 221 |
my ($area,$comp,$regex) = ($1,$2,$3); |
| 222 |
my $value; |
| 223 |
for ($area) { |
| 224 |
/^title|pagetop$/ && |
| 225 |
do { $value = $$rcfg{$area}{$item}; last }; |
| 226 |
|
| 227 |
/^name$/ && |
| 228 |
do { $value = $item; last }; |
| 229 |
|
| 230 |
die "ERROR: unknown filter area $_\n"; |
| 231 |
}; |
| 232 |
for ($comp) { |
| 233 |
/^=~$/ && |
| 234 |
do { next ITEM unless $value =~ /$regex/; last }; |
| 235 |
/^!~$/ && |
| 236 |
do { next ITEM unless $value !~ /$regex/; last }; |
| 237 |
die "ERROR: unknown comparison operator $_\n"; |
| 238 |
}; |
| 239 |
} else { |
| 240 |
die "ERROR: invalid filter expression $filter\n"; |
| 241 |
} |
| 242 |
} |
| 243 |
push @filtered, $item; |
| 244 |
}; |
| 245 |
|
| 246 |
# ----------------------------------------------------------- |
| 247 |
# get items into proper order (--sort) |
| 248 |
# ----------------------------------------------------------- |
| 249 |
my @order; |
| 250 |
for ($$opt{sort}) { |
| 251 |
/^original$/ && do {@order = @filtered; last}; |
| 252 |
/^name$/ && do { @order = sort { decimal_sort($a,$b); } @filtered; last}; |
| 253 |
/^title$/ && do { @order = |
| 254 |
sort { decimal_sort($$rcfg{title}{$a}, $$rcfg{title}{$b}) || $a cmp $b } |
| 255 |
@filtered; |
| 256 |
last; |
| 257 |
}; |
| 258 |
/^descr(iption)?$/ && |
| 259 |
do { |
| 260 |
@order = |
| 261 |
sort { |
| 262 |
$$rcfg{pagetop}{$a} =~ |
| 263 |
m[<td>Description:</td>\s*<td>(?:\S+\s+)?(.+?)</td>]i; |
| 264 |
my $aval = lc $1; |
| 265 |
$$rcfg{pagetop}{$b} =~ |
| 266 |
m[<td>Description:</td>\s*<td>(?:\S+\s+)?(.+?)</td>]i; |
| 267 |
my $bval = lc $1; |
| 268 |
$aval cmp $bval; |
| 269 |
} @filtered; |
| 270 |
last; |
| 271 |
}; |
| 272 |
die "ERROR: unknown sort order '$$opt{sort}'\n"; |
| 273 |
} |
| 274 |
|
| 275 |
die "ERROR: did not find any matching data in cfg file\n" unless @order; |
| 276 |
|
| 277 |
# ----------------------------------------------------------- |
| 278 |
# issue page top |
| 279 |
# ----------------------------------------------------------- |
| 280 |
my $interval =$$cfg{'interval'} ? $$cfg{'interval'} : 5; |
| 281 |
my $expiration = &expistr($interval); |
| 282 |
my $refresh = $$cfg{'refresh'} ? $$cfg{'refresh'} : 300; |
| 283 |
for ($$opt{show}) { |
| 284 |
$refresh = /^week$/ && 1800 |
| 285 |
|| /^month$/ && 7200 |
| 286 |
|| /^year$/ && 86400 |
| 287 |
|| $refresh ; |
| 288 |
} |
| 289 |
|
| 290 |
my $gifPath = ''; |
| 291 |
|
| 292 |
if ($$cfg{icondir} || $$opt{icondir}) { |
| 293 |
$gifPath = $$opt{icondir} || $$cfg{icondir}; |
| 294 |
#lets make sure there is a trailing path separator |
| 295 |
$gifPath =~ s|/*$|/|; |
| 296 |
} else { |
| 297 |
$gifPath = "$$cfg{imagehtml}"; |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
if ($$opt{optlog}) { |
| 302 |
$metaCmdLine = $argz; |
| 303 |
} else { |
| 304 |
$metaCmdLine = "<suppressed>"; |
| 305 |
} |
| 306 |
|
| 307 |
$metaCmdLine =~ s/&/&/g; # Must be first, otherwise it will affect the following changes |
| 308 |
$metaCmdLine =~ s/"/"/g; |
| 309 |
$metaCmdLine =~ s/</</g; |
| 310 |
$metaCmdLine =~ s/>/>/g; |
| 311 |
my $headeradd = $$opt{headeradd} || ""; |
| 312 |
$index = <<ECHO; |
| 313 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 314 |
<HTML> |
| 315 |
<HEAD> |
| 316 |
<TITLE>$$opt{title}</TITLE> |
| 317 |
<!-- Command line is easier to read using "View Page Properties" of your browser --> |
| 318 |
<!-- But not all browsers show that information. :-( --> |
| 319 |
<meta http-equiv="content-type" content="text/html; charset=iso-8859-15" > |
| 320 |
<META NAME="Command-Line" CONTENT="$metaCmdLine" > |
| 321 |
<META HTTP-EQUIV="Refresh" CONTENT="$refresh" > |
| 322 |
<META HTTP-EQUIV="Cache-Control" content="no-cache" > |
| 323 |
<META HTTP-EQUIV="Pragma" CONTENT="no-cache" > |
| 324 |
<META HTTP-EQUIV="Expires" CONTENT="$expiration" > |
| 325 |
<LINK HREF="${gifPath}favicon.ico" rel="shortcut icon" > |
| 326 |
$headeradd |
| 327 |
ECHO |
| 328 |
|
| 329 |
$index .= <<ECHO if ($$opt{optlog}); |
| 330 |
<style type="text/css"> |
| 331 |
/* commandline was: $argz */ |
| 332 |
/* sorry, no style, just abusing this to place the commandline and pass validation */ |
| 333 |
</style> |
| 334 |
ECHO |
| 335 |
|
| 336 |
$index .= <<ECHO if ($$opt{addhead}); |
| 337 |
$$opt{addhead} |
| 338 |
ECHO |
| 339 |
|
| 340 |
$index .= <<ECHO; |
| 341 |
</HEAD> |
| 342 |
|
| 343 |
<BODY $$opt{bodyopt}> |
| 344 |
ECHO |
| 345 |
$index .= <<ECHO; |
| 346 |
|
| 347 |
$$opt{pagetop} |
| 348 |
$$opt{headon}$$opt{title}$$opt{headoff} |
| 349 |
ECHO |
| 350 |
|
| 351 |
$index .= <<ECHO if $$opt{subtitle}; |
| 352 |
<p>$$opt{subtitle}</p> |
| 353 |
ECHO |
| 354 |
|
| 355 |
$index .= <<ECHO; |
| 356 |
|
| 357 |
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=$$opt{cellspacing}> |
| 358 |
<tr> |
| 359 |
ECHO |
| 360 |
|
| 361 |
# ----------------------------------------------------------- |
| 362 |
# print the graph items |
| 363 |
# ----------------------------------------------------------- |
| 364 |
my $itemnr = 0; |
| 365 |
my $first = $order[0]; |
| 366 |
my $host = $$rcfg{host}{$first}; |
| 367 |
if ($host){ |
| 368 |
$index .= "<a NAME=\"$host\"></a><tr><td>$$opt{headon}Interfaces of $host $$opt{headoff}</td></tr>" if $$opt{perhost}; |
| 369 |
} else { |
| 370 |
$index .= "<a NAME=\"$host\"></a><tr><td>$$opt{headon}Special Items$$opt{headoff}</td></tr>" if $$opt{perhost}; |
| 371 |
} |
| 372 |
foreach my $item (@order) { |
| 373 |
|
| 374 |
if ($$opt{perhost}) { |
| 375 |
my $newhost = $$rcfg{host}{$item} || 'unspecified host'; |
| 376 |
if (!($host eq $newhost)) { |
| 377 |
$host = $newhost; |
| 378 |
if ($host){ |
| 379 |
$index .= "<tr><td>$$opt{headon}Interfaces of $host $$opt{headoff}</td></tr>\n"; |
| 380 |
} else { |
| 381 |
$index .= "<tr><td>$$opt{headon}Special Items$$opt{headoff}</td></tr>\n"; |
| 382 |
} |
| 383 |
$index .= "<tr>\n"; |
| 384 |
$itemnr=0; |
| 385 |
} |
| 386 |
} |
| 387 |
$$opt{prefix} = $$rcfg{prefixes}->{$item} if ($$opt{autoprefix}); |
| 388 |
$itemnr++; |
| 389 |
$index .= "<td>"; |
| 390 |
my $dirrel = "../" x ($$rcfg{'directory_web'}{$item} =~ tr|/|/|); |
| 391 |
|
| 392 |
# --- produce graph section title --- |
| 393 |
my $section; |
| 394 |
for ($$opt{section}) { |
| 395 |
/^h1$/ && |
| 396 |
do{ |
| 397 |
if ($$rcfg{pagetop}{$item} =~ m[<h1[^>+]*>(.+?)</h1]i) { |
| 398 |
$section = $1; |
| 399 |
last; |
| 400 |
} else { |
| 401 |
die "ERROR: no H1 line pagetop property in $item section\n"; |
| 402 |
} |
| 403 |
}; |
| 404 |
/^title$/ && |
| 405 |
do{ |
| 406 |
$section = $$rcfg{title}{$item}; last |
| 407 |
}; |
| 408 |
/^name$/ && |
| 409 |
do{ |
| 410 |
$section = $item; last |
| 411 |
}; |
| 412 |
/^descr(iption)?$/ && |
| 413 |
do{ |
| 414 |
$section = "No Description for $item"; |
| 415 |
$$rcfg{setenv}{$item} =~ /MRTG_INT_DESCR="(.+?)"/ #" |
| 416 |
and $section = $1; |
| 417 |
$$rcfg{pagetop}{$item} =~ |
| 418 |
m,<td>Description:</td>\s*<td>\Q$section\E\s*([^< ][^<]+?)</td>,i |
| 419 |
and $section = $1; |
| 420 |
last; |
| 421 |
}; |
| 422 |
/^portname$/ && |
| 423 |
do{ |
| 424 |
$section = "No Portname for $item"; |
| 425 |
$$rcfg{pagetop}{$item} =~ m,<td>Port Name:</td>\s*<td>(.*?)</td>,i |
| 426 |
and $section = $1; |
| 427 |
last; |
| 428 |
}; |
| 429 |
/^ifname$/ && |
| 430 |
do{ |
| 431 |
$section = "No Portname for $item"; |
| 432 |
$$rcfg{pagetop}{$item} =~ m,<td>ifname:</td>\s*<td>(.*?)</td>,i |
| 433 |
and $section = $1; |
| 434 |
last; |
| 435 |
}; |
| 436 |
die "ERROR: unknown sectioning type $_\n"; |
| 437 |
}; |
| 438 |
if (defined $$rcfg{host}{$item} and |
| 439 |
!($section =~ m/\b\Q$$rcfg{host}{$item}\E\b/i)) { |
| 440 |
$section = ucfirst $$rcfg{host}{$item} . ": $section"; |
| 441 |
} |
| 442 |
|
| 443 |
# --- write the actual graph ---- |
| 444 |
die "ERROR: Unknown show type $$opt{show}\n" |
| 445 |
unless $$opt{show} =~ /^day|week|month|year|none$/; |
| 446 |
|
| 447 |
my $image = "$item-$$opt{show}.${main::GRAPHFMT}" |
| 448 |
if $$opt{show} ne 'none'; |
| 449 |
|
| 450 |
$index .= "<$$opt{div}>" if (!$$opt{sidebyside}); |
| 451 |
|
| 452 |
if (not $image) { |
| 453 |
if ($$cfg{logformat} eq 'rrdtool') { |
| 454 |
my $sep = $$opt{rrdviewer} =~ /\?/ ? '&' : '?'; |
| 455 |
$index .= |
| 456 |
"<A HREF=\"$$opt{rrdviewer}".$sep."log=$item&cfg=$$cfgfile{$item}\">". |
| 457 |
"$$opt{boldon}". |
| 458 |
"$section$$opt{boldoff}</A>"; |
| 459 |
} else { |
| 460 |
$index .= "$$opt{boldon}". |
| 461 |
"<A HREF=\"".cleanurl($$opt{prefix}. |
| 462 |
$$rcfg{directory_web}{$item}).$item. |
| 463 |
".$$rcfg{extension}{$item}\">". |
| 464 |
"$section$$opt{boldoff}</A></$$opt{div}>\n<$$opt{div}>"; |
| 465 |
} |
| 466 |
} else { |
| 467 |
#loop used for reversing (text,images) to (images,text) if req. |
| 468 |
for my $picfirstloop (1,0) { |
| 469 |
if ( $picfirstloop^$$opt{picfirst} ) { |
| 470 |
$index .= "$$opt{boldon}$itemnr. $$opt{boldoff}" |
| 471 |
if $$opt{enumerate}; |
| 472 |
if ($$opt{clicktext}) { |
| 473 |
$index .= "$$opt{boldon}<A HREF=\"".cleanurl($$opt{prefix}. |
| 474 |
$$rcfg{directory_web}{$item}).$item. |
| 475 |
".$$rcfg{extension}{$item}\">"; |
| 476 |
$index .= $section; |
| 477 |
$index .= "</A>$$opt{boldoff}"; |
| 478 |
} else { |
| 479 |
$index .= "$$opt{boldon}$section$$opt{boldoff}"; |
| 480 |
} |
| 481 |
$index .= "</$$opt{div}>\n<$$opt{div}>" if $picfirstloop; |
| 482 |
} |
| 483 |
|
| 484 |
if ( !($picfirstloop^$$opt{picfirst}) ) { |
| 485 |
# figure show name for rrd viewer |
| 486 |
if ($$cfg{logformat} eq 'rrdtool') { |
| 487 |
my $sep = $$opt{rrdviewer} =~ /\?/ ? '&' : '?'; |
| 488 |
$index .= "<A HREF=\"$$opt{rrdviewer}".$sep."log=$item&cfg=$$cfgfile{$item}\">". |
| 489 |
"<IMG BORDER=$$opt{imgborder} ALT=\"$item Traffic Graph\" ". |
| 490 |
"SRC=\"$$opt{rrdviewer}".$sep."log=$item&cfg=$$cfgfile{$item}&png=$$opt{show}.". |
| 491 |
"s&small=1\"></A>" |
| 492 |
} else { |
| 493 |
$index .= "<A HREF=\"".cleanurl($$opt{prefix}. |
| 494 |
$$rcfg{directory_web}{$item}).$item. |
| 495 |
".$$rcfg{extension}{$item}\">"; |
| 496 |
$index .= "<IMG BORDER=$$opt{imgborder} ALT=\"$item Traffic Graph\" ". |
| 497 |
"SRC=\"".cleanurl($$opt{prefix}. |
| 498 |
$$rcfg{directory_web}{$item}.$dirrel. |
| 499 |
$$cfg{imagehtml}.$$rcfg{directory_web}{$item}). |
| 500 |
"$image\""; |
| 501 |
$index .= ' WIDTH="'.$$opt{width}.'"' |
| 502 |
if defined $$opt{width}; |
| 503 |
$index .= ' HEIGHT="'.$$opt{height}.'"' |
| 504 |
if defined $$opt{height}; |
| 505 |
$index .= "></A>"; |
| 506 |
$index .= "<BR>" |
| 507 |
if ( ! defined $$opt{compact} ); |
| 508 |
$index .= "\n<SMALL><!--#flastmod file=\"". |
| 509 |
cleanurl($$opt{prefix}.$$rcfg{directory_web}{$item}).$item. |
| 510 |
".$$rcfg{extension}{$item}\" --></SMALL>"; |
| 511 |
} |
| 512 |
$index .= "</$$opt{div}>\n<$$opt{div}>" if $picfirstloop; |
| 513 |
} |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
$index .= "</$$opt{div}>" if (!$$opt{sidebyside}); |
| 518 |
$index .= "\n</td>"; |
| 519 |
|
| 520 |
# --- new table column if necessary ---- |
| 521 |
if (($itemnr) % $$opt{columns} == 0) { |
| 522 |
$index .= "</tr>\n<tr>\n"; |
| 523 |
} |
| 524 |
} |
| 525 |
# ----------------------------------------------------------- |
| 526 |
# print page end |
| 527 |
# ----------------------------------------------------------- |
| 528 |
|
| 529 |
|
| 530 |
my $VERSION = "2.17.10"; |
| 531 |
$index .= <<ECHO; |
| 532 |
<td></td> |
| 533 |
</tr> |
| 534 |
</TABLE> |
| 535 |
ECHO |
| 536 |
|
| 537 |
$index .= <<ECHO if (defined $$opt{pageend}); |
| 538 |
$$opt{pageend} |
| 539 |
ECHO |
| 540 |
|
| 541 |
$index .= <<ECHO if (!$$opt{nolegend}); |
| 542 |
<BR> |
| 543 |
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0> |
| 544 |
<TR> |
| 545 |
<TD WIDTH=63><A |
| 546 |
HREF="http://oss.oetiker.ch/mrtg/"><IMG |
| 547 |
BORDER=0 SRC="${gifPath}mrtg-l.${main::GRAPHFMT}" WIDTH=63 HEIGHT=25 ALT="MRTG"></A></TD> |
| 548 |
<TD WIDTH=25><A |
| 549 |
HREF="http://oss.oetiker.ch/mrtg/"><IMG |
| 550 |
BORDER=0 SRC="${gifPath}mrtg-m.${main::GRAPHFMT}" WIDTH=25 HEIGHT=25 ALT=""></A></TD> |
| 551 |
<TD WIDTH=388><A |
| 552 |
HREF="http://oss.oetiker.ch/mrtg/"><IMG |
| 553 |
BORDER=0 SRC="${gifPath}mrtg-r.${main::GRAPHFMT}" WIDTH=388 HEIGHT=25 |
| 554 |
ALT="Multi Router Traffic Grapher"></A></TD> |
| 555 |
</TR> |
| 556 |
</TABLE> |
| 557 |
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0> |
| 558 |
<TR VALIGN=top> |
| 559 |
<TD WIDTH=88 ALIGN=RIGHT><FONT FACE="Arial,Helvetica" SIZE=2> |
| 560 |
version $VERSION</FONT></TD> |
| 561 |
<TD WIDTH=388 ALIGN=RIGHT><FONT FACE="Arial,Helvetica" SIZE=2> |
| 562 |
<A HREF="http://tobi.oetiker.ch/">Tobias Oetiker</A> |
| 563 |
<A HREF="mailto:tobi+mrtglink\@oetiker.ch"><tobi\@oetiker.ch></A> |
| 564 |
and <A HREF="http://www.bungi.com/">Dave Rand</A> <A HREF="mailto:dlr\@bungi.com"><dlr\@bungi.com></A></FONT> |
| 565 |
</TD> |
| 566 |
</TR> |
| 567 |
</TABLE> |
| 568 |
ECHO |
| 569 |
$index .= <<ECHO; |
| 570 |
</BODY> |
| 571 |
</HTML> |
| 572 |
ECHO |
| 573 |
|
| 574 |
# ----------------------------------------------------------- |
| 575 |
# write out the index page |
| 576 |
# ----------------------------------------------------------- |
| 577 |
if ($$opt{output}) { |
| 578 |
debug ('base', "Writing $$opt{output}"); |
| 579 |
open X, ">$$opt{output}" or die "ERROR: creating $$opt{output}: $!\n"; |
| 580 |
print X $index; |
| 581 |
close X; |
| 582 |
} else { |
| 583 |
print $index; |
| 584 |
} |
| 585 |
|
| 586 |
} |
| 587 |
|
| 588 |
sub options ($) { |
| 589 |
my $opt = shift; |
| 590 |
my @options = ( |
| 591 |
'help|?', |
| 592 |
'man', |
| 593 |
'output=s', |
| 594 |
'filter=s@', |
| 595 |
'addhead=s', |
| 596 |
'title=s', |
| 597 |
'subtitle=s', |
| 598 |
'bodyopt=s', |
| 599 |
'pagetopend=s', |
| 600 |
'pagetop=s', |
| 601 |
'pageend=s', |
| 602 |
'columns=i', |
| 603 |
'perhost!', |
| 604 |
'sort=s', |
| 605 |
'enumerate', |
| 606 |
'width=i', |
| 607 |
'height=i', |
| 608 |
'show=s', |
| 609 |
'section=s', |
| 610 |
'version', |
| 611 |
'prefix=s', |
| 612 |
'headeradd=s', |
| 613 |
'clicktext!', |
| 614 |
'optlog!', |
| 615 |
'compact!', |
| 616 |
'headlevel=i', |
| 617 |
'bold!', |
| 618 |
'picfirst!', |
| 619 |
'sidebyside!', |
| 620 |
'nolegend', |
| 621 |
'autoprefix!', |
| 622 |
'sectionhost!', |
| 623 |
'icondir=s', |
| 624 |
'rrdviewer=s'); |
| 625 |
|
| 626 |
#generate --option-file from --option |
| 627 |
for ( grep /=s$/,@options ) { |
| 628 |
my $fileopt = $_; |
| 629 |
$fileopt =~ s/=s$/-file=s/; |
| 630 |
push @options, $fileopt; |
| 631 |
} |
| 632 |
|
| 633 |
GetOptions( $opt, @options ) or pod2usage(-verbose => 1); |
| 634 |
|
| 635 |
if ($$opt{prefix}){ |
| 636 |
$$opt{prefix} .= '/'; |
| 637 |
$$opt{prefix} =~ s|/+$|/|; |
| 638 |
} |
| 639 |
die ("Indexmaker for mrtg-2.17.10\n") if $$opt{version}; |
| 640 |
pod2usage(-exitval => 1, -verbose => 2) if $$opt{man}; |
| 641 |
pod2usage(-verbose => 1) if not @ARGV; |
| 642 |
|
| 643 |
#take care of --fileoption --> --option |
| 644 |
for my $fileopt ( grep /-file$/, keys %{$opt} ) { |
| 645 |
my $orgopt = $fileopt; |
| 646 |
$orgopt =~ s/-file$//; |
| 647 |
$$opt{$orgopt} = &readfile($$opt{$fileopt}); |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
#return the contents of a file |
| 652 |
sub readfile($) { |
| 653 |
my $file = shift; |
| 654 |
open F,"<$file" or die "ERROR: can\'t open $file for read, $!"; |
| 655 |
my $sl = $/; |
| 656 |
$/ = undef; |
| 657 |
my $string = <F>; |
| 658 |
$/ = $sl; |
| 659 |
close F; |
| 660 |
return $string; |
| 661 |
} |
| 662 |
|
| 663 |
__END__ |
| 664 |
|
| 665 |
=pod |
| 666 |
|
| 667 |
=head1 NAME |
| 668 |
|
| 669 |
indexmaker - Creates index files for mrtg web sites (mrtg-2.17.10) |
| 670 |
|
| 671 |
=head1 SYNOPSIS |
| 672 |
|
| 673 |
indexmaker [options] mrtg.cfg [other.cfg ...] |
| 674 |
|
| 675 |
=head1 OPTIONS |
| 676 |
|
| 677 |
--output=filename set output filename (default: stdout) |
| 678 |
|
| 679 |
--filter title=~regexp select targets by matching regexp against titles |
| 680 |
--filter pagetop=~regexp select targets by matching regexp against pagetop |
| 681 |
--filter name=~regexp select targets by matching regexp against name |
| 682 |
|
| 683 |
--addhead=text insert this text between </TITLE> and </HEAD> |
| 684 |
--title=text set title of generated index file |
| 685 |
--subtitle=text add a subtitle to the generated index file |
| 686 |
--bodyopt=text set body tag options |
| 687 |
--headlevel=number use <Hnumber> at top of page (default: 1) |
| 688 |
--pagetop=text insert this text between <BODY> and <H1>...</H1> |
| 689 |
--pageend=text insert this text after the main body |
| 690 |
--pagetopend=text use this text for pagetop or pageend if undefined |
| 691 |
--nolegend do not add the Mrtg legend at the end of the page |
| 692 |
|
| 693 |
--columns=number show graphs in a table with x columns (default: 2) |
| 694 |
--perhost show graphs of the same host on a row |
| 695 |
--compact try to make a vertically more compact page |
| 696 |
--optlog log the used command line in the page (default: log) |
| 697 |
|
| 698 |
--sort=title sort graphs by title |
| 699 |
--sort=name sort graphs by their name |
| 700 |
--sort=descr sort graphs by their description |
| 701 |
--sort=original leave as is (default) |
| 702 |
|
| 703 |
--enumerate add a sequence number to the title of each graph |
| 704 |
|
| 705 |
--picfirst place pictures before text (default: text first) |
| 706 |
--width=number set width of graphs (default: not set) |
| 707 |
--height=number |
| 708 |
--sidebyside place text / pictures side by side (default: above/below) |
| 709 |
--bold use bold text (default: bold) |
| 710 |
--clicktext make the text link to the inner page (like the image) |
| 711 |
|
| 712 |
--show=day pick which graph to show in the index (default) |
| 713 |
--show=week |
| 714 |
--show=month |
| 715 |
--show=year |
| 716 |
--show=none |
| 717 |
|
| 718 |
--section=h1 h1 tag from pagetop as section heading (default) |
| 719 |
--section=title title as section headings for graphs |
| 720 |
--section=name graph name as section heading |
| 721 |
--section=descr graph description as section heading |
| 722 |
--section=ifname interface name (ifName) as section heading |
| 723 |
--section=portname port name entry in pagetop as section heading |
| 724 |
--sectionhost Try to prepend the host to the section heading if missing |
| 725 |
|
| 726 |
--rrdviewer=path path to rrdviewer (default: /cgi-bin/14all.cgi) |
| 727 |
--icondir=path path to icondir |
| 728 |
--prefix=path path from the location of the index.html to the graphs |
| 729 |
--headeradd=string add string to the html page header |
| 730 |
--autoprefix try to set prefix automatically |
| 731 |
|
| 732 |
--<opt>-file=file read string argument for option <opt> from file |
| 733 |
|
| 734 |
=head1 DESCRIPTION |
| 735 |
|
| 736 |
B<Indexmaker> can create web pages which display the status of an |
| 737 |
array of mrtg interface status pages. |
| 738 |
|
| 739 |
=over |
| 740 |
|
| 741 |
=item B<--output> I<filename> |
| 742 |
|
| 743 |
set output filename (default: stdout) |
| 744 |
|
| 745 |
=item B<--filter> (B<title>|B<pagetop>|B<name>)(B<=~>|B<!~>)I<regexp> |
| 746 |
|
| 747 |
Several filters may get set. Each filter can match against the contents |
| 748 |
of a specific section of the mrtg config file. B<Name> refers to the |
| 749 |
bit in square brackets (option[name]: bla). |
| 750 |
|
| 751 |
Depending on the match operator chosen (B<=~> or B<!~>) the match will be |
| 752 |
positive or negative. |
| 753 |
|
| 754 |
Note that some shells consider B<!> a special character. It may be |
| 755 |
necessary to type B<\!~> instead. |
| 756 |
|
| 757 |
=item B<--title> I<text> |
| 758 |
|
| 759 |
Set title of generated index file (default: regexp) |
| 760 |
|
| 761 |
=item B<--bodyopt> I<text> |
| 762 |
|
| 763 |
The value of this argument gets appended to |
| 764 |
the E<lt>BODYE<gt> tag. This allows you to set document colors. |
| 765 |
By default this option is set to |
| 766 |
|
| 767 |
bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000" alink="#000000" |
| 768 |
|
| 769 |
=item B<--columns> I<number> |
| 770 |
|
| 771 |
Display graphs in a table with I<number> columns (default: 2) |
| 772 |
|
| 773 |
=item B<--sort> B<title>|B<name>|B<descr>|B<original> |
| 774 |
|
| 775 |
Sort the graphs in the page either by B<title>, by B<name>, by interface |
| 776 |
B<descr>iption, or leave them as is. |
| 777 |
|
| 778 |
=item B<--enumerate> |
| 779 |
|
| 780 |
Add a sequence number to the title of each graph |
| 781 |
|
| 782 |
=item B<--width> I<number> |
| 783 |
|
| 784 |
Set width of graphs |
| 785 |
|
| 786 |
=item B<--height> I<number> |
| 787 |
|
| 788 |
Set the height of the graphs |
| 789 |
|
| 790 |
=item B<--show> B<day>|B<week>|B<month>|B<year>|B<none> |
| 791 |
|
| 792 |
Select which graph to show in the index page. You can suppress images |
| 793 |
completely with B<--show=none>. |
| 794 |
|
| 795 |
=item B<--section> B<h1>|B<title>|B<name>|B<description>|B<portname> |
| 796 |
|
| 797 |
Select what to use as the title for each graph in the page. B<h1> is |
| 798 |
the H1 section from pagetop, B<title> is the graph title, B<name> is |
| 799 |
the bit in square brackets (option[name]: bla), and B<descr> or |
| 800 |
B<description> is the text from the Description field of the PageTop |
| 801 |
(the Cisco description text if it's available, otherwise just the |
| 802 |
interface description). B<portname> is the C<Port Name:> from pagetop. |
| 803 |
|
| 804 |
=item B<--sectionhost> |
| 805 |
|
| 806 |
Extract the hostname from the target line (this does not work if the |
| 807 |
target is a mathematical expression). Prepend the hostname (and a colon) |
| 808 |
to the section if not already present. |
| 809 |
|
| 810 |
=item B<--rrdviewer> I<path> |
| 811 |
|
| 812 |
If you have set the B<LogFormat: rrdtool> property in the mrtg.cfg |
| 813 |
file, the index will take this into account. The only thing you must |
| 814 |
tell it is the path to your grapher cgi. (default: /cgi-bin/14all.cgi) |
| 815 |
|
| 816 |
=item B<--prefix> I<path> |
| 817 |
|
| 818 |
By default we assume that the file generated by indexmaker is stored in |
| 819 |
I<WorkDir>. If you want to store it somewhere else, specify how to reach |
| 820 |
I<WorkDir> from the place where the Index is stored. Note that you have to |
| 821 |
use '/' as path separator as this will be used in urls. Speaking of which, |
| 822 |
you can even enter a whole url. |
| 823 |
|
| 824 |
=item B<--autoprefix> I<path> |
| 825 |
|
| 826 |
Requires --output. |
| 827 |
Try to generate the prefix automatically by comparison of the path to the |
| 828 |
output file set with --output and the Htmldir set in the configuration files. |
| 829 |
Particularly useful when multiple configuration files are specified, with |
| 830 |
different Htmldir settings. |
| 831 |
|
| 832 |
=item B<--optlog> |
| 833 |
|
| 834 |
Default is logging in the generated page the command line, suppress with |
| 835 |
--nooptlog . Useful if the commandline contains a complex --pagetop=string |
| 836 |
which could confuse simple browsers. |
| 837 |
|
| 838 |
=item B<--someoption-file> I<filename> |
| 839 |
|
| 840 |
For any someoption which takes a I<string> as parameter you can read the |
| 841 |
string from a file by adding <-file> to the option keyword. The whole |
| 842 |
content of the file will be read and used as the I<string>. The file must |
| 843 |
exist. |
| 844 |
|
| 845 |
=back |
| 846 |
|
| 847 |
=head1 AUTHOR |
| 848 |
|
| 849 |
Tobias Oetiker E<lt>[email protected]<gt> |
| 850 |
|
| 851 |
=head1 LICENSE |
| 852 |
|
| 853 |
GNU General Public License |
| 854 |
|
| 855 |
=head1 COPYRIGHT |
| 856 |
|
| 857 |
2000-2001 Tobias Oetiker E<lt>[email protected]<gt> |
| 858 |
|
| 859 |
=cut |