Blame bin/indexmaker.lib64

Packit 3f632f
#! /usr/bin/perl -w
Packit 3f632f
# -*- mode: Perl -*-
Packit 3f632f
##################################################################
Packit 3f632f
# MRTG 2.17.7  --- Index Generator
Packit 3f632f
##################################################################
Packit 3f632f
#
Packit 3f632f
# This reads a mrtg.cfg file form std input or cmdline argument
Packit 3f632f
# and it takes a regexp on the cmdline to specify which 
Packit 3f632f
# targets to look at.
Packit 3f632f
#
Packit 3f632f
# from this info it produces a router index on stdout or
Packit 3f632f
# on the filename specified by the --output option
Packit 3f632f
#
Packit 3f632f
##################################################################
Packit 3f632f
# Distributed under the GNU General Public License
Packit 3f632f
# Copyright 2000 by Tobias Oetiker <tobi@oetiker.ch>
Packit 3f632f
##################################################################
Packit 3f632f
Packit 3f632f
$main::GRAPHFMT="png";
Packit 3f632f
Packit 3f632f
require 5.005;
Packit 3f632f
use strict;
Packit 3f632f
Packit 3f632f
# DEBUG TARGETS
Packit 3f632f
# base - basic program flow
Packit 3f632f
#@main::DEBUG=qw(base);
Packit 3f632f
Packit 3f632f
BEGIN {
Packit 3f632f
    # Automatic OS detection ... do NOT touch
Packit 3f632f
    if ( $^O =~ /^(?:(ms)?(dos|win(32|nt)?))/i ) {
Packit 3f632f
        $main::OS = 'NT';
Packit 3f632f
        $main::SL = '\\';
Packit 3f632f
        $main::PS = ';';
Packit 3f632f
    } elsif ( $^O =~ /^NetWare$/i ) {
Packit 3f632f
        $main::OS = 'NW';
Packit 3f632f
        $main::SL = '/';
Packit 3f632f
        $main::PS = ';';
Packit 3f632f
    } elsif ( $^O =~ /^VMS$/i ) {
Packit 3f632f
        $main::OS = 'VMS';
Packit 3f632f
        $main::SL = '.';
Packit 3f632f
        $main::PS = ':';
Packit 3f632f
    } else {
Packit 3f632f
        $main::OS = 'UNIX';
Packit 3f632f
        $main::SL = '/';
Packit 3f632f
        $main::PS = ':';
Packit 3f632f
    }
Packit 3f632f
}
Packit 3f632f
Packit 3f632f
use FindBin;
Packit 3f632f
use lib "${FindBin::Bin}";
Packit 3f632f
use lib "${FindBin::Bin}${main::SL}..${main::SL}lib${main::SL}mrtg2";
Packit 3f632f
Packit 3f632f
use MRTG_lib "2.100016";
Packit 3f632f
use Getopt::Long;
Packit 3f632f
use Pod::Usage;
Packit 3f632f
Packit 3f632f
#----------------------------------------------------------------------
Packit 3f632f
sub decimal_sort($$) {
Packit 3f632f
 my $a = $_[0];
Packit 3f632f
 my $b = $_[1];
Packit 3f632f
Packit 3f632f
 $a =~ s/([0-9]+)/sprintf("%09u",${1})/ge;
Packit 3f632f
 $b =~ s/([0-9]+)/sprintf("%09u",${1})/ge;
Packit 3f632f
 return $a cmp $b;
Packit 3f632f
 }
Packit 3f632f
#----------------------------------------------------------------------
Packit 3f632f
Packit 3f632f
my @argv = @ARGV;
Packit 3f632f
my $argz = "$0";
Packit 3f632f
foreach my $ar (@argv) {
Packit 3f632f
   if ($ar =~ /[ |()]/ ) {
Packit 3f632f
      $ar = sprintf qq{"%s"}, $ar;
Packit 3f632f
   }
Packit 3f632f
   $argz .= " $ar";
Packit 3f632f
}
Packit 3f632f
Packit 3f632f
Packit 3f632f
main();
Packit 3f632f
exit 0;
Packit 3f632f
Packit 3f632f
sub main {
Packit 3f632f
    # default options
Packit 3f632f
    my %opt = (
Packit 3f632f
	       sort => 'original',
Packit 3f632f
	       show => 'day',
Packit 3f632f
	       section => 'h1',
Packit 3f632f
	       columns => 2,
Packit 3f632f
	       addhead => '',
Packit 3f632f
	       bodyopt => 'bgcolor="#ffffff" text="#000000" '.
Packit 3f632f
	                  'link="#000000" vlink="#000000" alink="#000000"',
Packit 3f632f
	       title => 'MRTG Index Page',
Packit 3f632f
	       headlevel => 1,
Packit 3f632f
	       pagetopend => '',
Packit 3f632f
	       pagetop => '',
Packit 3f632f
	       pageend => '',
Packit 3f632f
	       prefix => '',
Packit 3f632f
	       rrdviewer => '/cgi-bin/14all.cgi',
Packit 3f632f
	       optlog => 1,
Packit 3f632f
	       bold => 1,
Packit 3f632f
	       boldon => '',
Packit 3f632f
	       boldoff => '',
Packit 3f632f
	       div => 'DIV',
Packit 3f632f
	       imgborder => 1,
Packit 3f632f
	       cellspacing => 10,
Packit 3f632f
	       nolegend => 0,
Packit 3f632f
	      );
Packit 3f632f
    $opt{headon} = "<H$opt{headlevel}>";
Packit 3f632f
    $opt{headoff} = "</H$opt{headlevel}>";
Packit 3f632f
    # load real options
Packit 3f632f
    options(\%opt);
Packit 3f632f
Packit 3f632f
    #adapt some defaults to the current options
Packit 3f632f
    die "ERROR: --autoprefix requires --output"
Packit 3f632f
      if ($opt{autoprefix} and !defined $opt{output});
Packit 3f632f
    $opt{pageend} = $opt{pagetopend} if (defined $opt{pagetopend} and not $opt{pageend});
Packit 3f632f
    $opt{pagetop} = $opt{pagetopend} if (defined $opt{pagetopend} and not $opt{pagetop});
Packit 3f632f
    $opt{boldon} = $opt{boldoff} = "" if (!$opt{bold});
Packit 3f632f
    $opt{picfirst} = (defined $opt{picfirst}?1:0);
Packit 3f632f
    if ($opt{compact}) {
Packit 3f632f
        $opt{imgborder} = 0;
Packit 3f632f
        $opt{cellspacing} = 0;
Packit 3f632f
        $opt{headon} = $opt{boldon};
Packit 3f632f
        $opt{headoff} = $opt{boldoff};
Packit 3f632f
    }
Packit 3f632f
	if ($opt{sidebyside}) {
Packit 3f632f
		$opt{div} = 'td';
Packit 3f632f
	}
Packit 3f632f
	
Packit 3f632f
    # slurp config files
Packit 3f632f
    my %rcfg;
Packit 3f632f
    my %cfg;
Packit 3f632f
    my @target;
Packit 3f632f
    my @routers;
Packit 3f632f
    my $cfgfile;
Packit 3f632f
    my %files;
Packit 3f632f
    while (@ARGV) {
Packit 3f632f
           $cfgfile = shift @ARGV;
Packit 3f632f
	    readcfg($cfgfile,\@routers,\%cfg,\%rcfg);
Packit 3f632f
	    if (($opt{sectionhost}) or ($opt{perhost})) {
Packit 3f632f
	    	#We need to cache the "hostname" as appeared in cfgfile,
Packit 3f632f
	    	#since it does change in cfgcheck (for ex. if multiple 
Packit 3f632f
	    	#overlapping cfgfiles are specified)
Packit 3f632f
	    	for my $targ (@routers) {
Packit 3f632f
	    		if ( !defined $rcfg{host}{$targ} and
Packit 3f632f
	    			 !($rcfg{target}{$targ} =~ m/(?
Packit 3f632f
	    			$rcfg{target}{$targ} =~ m/.*[^\\]@([^:]*)/;
Packit 3f632f
	    			$rcfg{host}{$targ} = ucfirst $1 if (defined $1);
Packit 3f632f
	    		}
Packit 3f632f
	    	}
Packit 3f632f
	    }
Packit 3f632f
	    cfgcheck(\@routers, \%cfg, \%rcfg, \@target);
Packit 3f632f
           for my $targ (@routers) {
Packit 3f632f
               if (! defined $files{$targ}) {
Packit 3f632f
                    $files{$targ}=substr($cfgfile,rindex($cfgfile,'/')+1);
Packit 3f632f
               }
Packit 3f632f
           }
Packit 3f632f
	    if ($opt{autoprefix}) {
Packit 3f632f
		    $rcfg{prefixes} = {} if (!defined $rcfg{prefixes});
Packit 3f632f
	        my $pref = subpath($cfg{htmldir},$opt{output});
Packit 3f632f
		    for my $targ (@routers) {
Packit 3f632f
		        $rcfg{prefixes}->{$targ} = $pref
Packit 3f632f
		          if (! defined $rcfg{prefixes}->{$targ});
Packit 3f632f
		    }
Packit 3f632f
		}
Packit 3f632f
    }
Packit 3f632f
    # generate index page
Packit 3f632f
    genindex(\@routers, \%cfg, \%rcfg, \%opt, \%files);
Packit 3f632f
}
Packit 3f632f
Packit 3f632f
sub cleanurl ($) {
Packit 3f632f
    my $url = shift;    
Packit 3f632f
    $url =~ s|([^/.][^/.]*/)\.\./\1|$1|g;
Packit 3f632f
    return $url;
Packit 3f632f
}
Packit 3f632f
Packit 3f632f
#Take a path the mrtg (usually the mrtg output directory) and the overview
Packit 3f632f
#file, find the relative path from the overview to the directory
Packit 3f632f
sub subpath ($$) {
Packit 3f632f
	my $sub = shift;
Packit 3f632f
	my $out = shift;
Packit 3f632f
	my @s=split /$main::SL/,$sub;
Packit 3f632f
	my @o=split /$main::SL/,$out;
Packit 3f632f
	pop @o;	#Last is a filename;
Packit 3f632f
	for my $i (0..$#s) {		#cut common dirs
Packit 3f632f
		if (defined $s[0] and
Packit 3f632f
		    defined $o[0] and
Packit 3f632f
		    $s[0] eq $o[0] ) {
Packit 3f632f
		    	shift @s;
Packit 3f632f
		    	shift @o;
Packit 3f632f
		}
Packit 3f632f
	}
Packit 3f632f
	my $ret = join $main::SL,@s;
Packit 3f632f
	for my $i (0..$#o) {
Packit 3f632f
		$ret = "..$main::SL$ret";	# ".." == "Directory below this one" for
Packit 3f632f
									# dos, windows, unix. What about VMS ?
Packit 3f632f
									# Is this correct ? HEH
Packit 3f632f
	}
Packit 3f632f
	$ret .= $main::SL;			#Possibly this should be "/" in order not
Packit 3f632f
								#to break on platforms !unix, since it will be
Packit 3f632f
								#used for generating urls ?
Packit 3f632f
	#Don't degenerate in "/" when really no prefix is needed.
Packit 3f632f
	$ret = "" if ($ret eq $main::SL);
Packit 3f632f
	return $ret;
Packit 3f632f
}
Packit 3f632f
Packit 3f632f
sub genindex ($$$$) {
Packit 3f632f
    my $routers = shift;
Packit 3f632f
    my $cfg = shift;
Packit 3f632f
    my $rcfg = shift;
Packit 3f632f
    my $opt = shift;
Packit 3f632f
    my $cfgfile = shift;
Packit 3f632f
    my $index;
Packit 3f632f
    my $metaCmdLine;
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    # keep only the items our users want (--filter)
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    my @filtered;
Packit 3f632f
    ITEM: foreach my $item (@{$routers}) {
Packit 3f632f
	foreach my $filter (@{$$opt{filter}}) {
Packit 3f632f
	    if ($filter =~ /(.+)([=!]~)(.+)/) {
Packit 3f632f
		my ($area,$comp,$regex) = ($1,$2,$3);
Packit 3f632f
		my $value;
Packit 3f632f
	        for ($area) {
Packit 3f632f
		    /^title|pagetop$/ && 
Packit 3f632f
		      do { $value = $$rcfg{$area}{$item}; last };
Packit 3f632f
Packit 3f632f
		    /^name$/ && 
Packit 3f632f
		      do { $value = $item; last };
Packit 3f632f
Packit 3f632f
		    die "ERROR: unknown filter area $_\n";
Packit 3f632f
		};
Packit 3f632f
		for ($comp) {
Packit 3f632f
		    /^=~$/ &&
Packit 3f632f
		      do { next ITEM unless $value =~ /$regex/; last };
Packit 3f632f
		    /^!~$/ &&
Packit 3f632f
		      do { next ITEM unless $value !~ /$regex/; last };
Packit 3f632f
		    die "ERROR: unknown comparison operator $_\n";
Packit 3f632f
		};
Packit 3f632f
	    } else {
Packit 3f632f
		die "ERROR: invalid filter expression $filter\n";
Packit 3f632f
	    }
Packit 3f632f
	}
Packit 3f632f
	push @filtered, $item;
Packit 3f632f
    };
Packit 3f632f
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    # get items into proper order (--sort)
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    my @order;
Packit 3f632f
    for ($$opt{sort}) {
Packit 3f632f
	/^original$/ && do {@order = @filtered; last};
Packit 3f632f
       /^name$/ &&  do { @order = sort { decimal_sort($a,$b); } @filtered; last};
Packit 3f632f
	/^title$/ && do { @order =
Packit 3f632f
                           sort { decimal_sort($$rcfg{title}{$a}, $$rcfg{title}{$b}) || $a cmp $b }
Packit 3f632f
			      @filtered;
Packit 3f632f
			  last;
Packit 3f632f
		      };
Packit 3f632f
	/^descr(iption)?$/ &&
Packit 3f632f
	    do {
Packit 3f632f
	      @order =
Packit 3f632f
	        sort {
Packit 3f632f
		  $$rcfg{pagetop}{$a} =~ 
Packit 3f632f
	           m[Description:\s*(?:\S+\s+)?(.+?)]i;
Packit 3f632f
		  my $aval = lc $1;
Packit 3f632f
		  $$rcfg{pagetop}{$b} =~ 
Packit 3f632f
	           m[Description:\s*(?:\S+\s+)?(.+?)]i;
Packit 3f632f
		  my $bval = lc $1;
Packit 3f632f
		  $aval cmp $bval;
Packit 3f632f
	        } @filtered;
Packit 3f632f
			  last;
Packit 3f632f
		      };
Packit 3f632f
	die "ERROR: unknown sort order '$$opt{sort}'\n";
Packit 3f632f
    }
Packit 3f632f
Packit 3f632f
    die "ERROR: did not find any matching data in cfg file\n" unless @order;
Packit 3f632f
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    # issue page top
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    my $interval =$$cfg{'interval'} ? $$cfg{'interval'} : 5;
Packit 3f632f
    my $expiration = &expistr($interval);
Packit 3f632f
    my $refresh =  $$cfg{'refresh'} ? $$cfg{'refresh'} : 300;
Packit 3f632f
    for ($$opt{show}) {
Packit 3f632f
       $refresh = /^week$/     && 1800
Packit 3f632f
               || /^month$/    && 7200
Packit 3f632f
               || /^year$/     && 86400
Packit 3f632f
               || $refresh ;
Packit 3f632f
    }
Packit 3f632f
Packit 3f632f
    my $gifPath = '';
Packit 3f632f
Packit 3f632f
    if ($$cfg{icondir} || $$opt{icondir}) {
Packit 3f632f
       $gifPath = $$opt{icondir} || $$cfg{icondir};
Packit 3f632f
       #lets make sure there is a trailing path separator
Packit 3f632f
     $gifPath =~ s|/*$|/|;
Packit 3f632f
   } else {
Packit 3f632f
       $gifPath = "$$cfg{imagehtml}";
Packit 3f632f
   }
Packit 3f632f
Packit 3f632f
Packit 3f632f
if ($$opt{optlog}) {
Packit 3f632f
    $metaCmdLine = $argz;
Packit 3f632f
} else {
Packit 3f632f
    $metaCmdLine = "<suppressed>";
Packit 3f632f
}
Packit 3f632f
Packit 3f632f
$metaCmdLine =~ s/&/&/g;   # Must be first, otherwise it will affect the following changes
Packit 3f632f
$metaCmdLine =~ s/"/"/g;
Packit 3f632f
$metaCmdLine =~ s/</</g;
Packit 3f632f
$metaCmdLine =~ s/>/>/g;
Packit 3f632f
    my $headeradd = $$opt{headeradd} || "";
Packit 3f632f
    $index = <
Packit 3f632f
Packit 3f632f
<HTML>
Packit 3f632f
<HEAD>
Packit 3f632f
    <TITLE>$$opt{title}</TITLE>
Packit 3f632f
    
Packit 3f632f
    
Packit 3f632f
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-15" >
Packit 3f632f
    <META NAME="Command-Line" CONTENT="$metaCmdLine" >
Packit 3f632f
    <META HTTP-EQUIV="Refresh" CONTENT="$refresh" >
Packit 3f632f
    <META HTTP-EQUIV="Cache-Control" content="no-cache" >
Packit 3f632f
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache" >
Packit 3f632f
    <META HTTP-EQUIV="Expires" CONTENT="$expiration" >
Packit 3f632f
    <LINK HREF="${gifPath}favicon.ico" rel="shortcut icon" >
Packit 3f632f
    $headeradd
Packit 3f632f
ECHO
Packit 3f632f
Packit 3f632f
    $index .= <
Packit 3f632f
<style type="text/css">
Packit 3f632f
/* commandline was: $argz */
Packit 3f632f
/* sorry, no style, just abusing this to place the commandline and pass validation */
Packit 3f632f
</style>
Packit 3f632f
ECHO
Packit 3f632f
Packit 3f632f
    $index .= <
Packit 3f632f
    $$opt{addhead}
Packit 3f632f
ECHO
Packit 3f632f
Packit 3f632f
    $index .= <
Packit 3f632f
</HEAD>
Packit 3f632f
Packit 3f632f
<BODY $$opt{bodyopt}>
Packit 3f632f
ECHO
Packit 3f632f
    $index .= <
Packit 3f632f
Packit 3f632f
$$opt{pagetop}
Packit 3f632f
$$opt{headon}$$opt{title}$$opt{headoff}
Packit 3f632f
ECHO
Packit 3f632f
Packit 3f632f
    $index .= <
Packit 3f632f

$$opt{subtitle}

Packit 3f632f
ECHO
Packit 3f632f
    
Packit 3f632f
    $index .= <
Packit 3f632f
Packit 3f632f
Packit 3f632f
Packit 3f632f
ECHO
Packit 3f632f
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    # print the graph items
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    my $itemnr = 0;
Packit 3f632f
    my $first = $order[0];
Packit 3f632f
    my $host = $$rcfg{host}{$first};
Packit 3f632f
    if ($host){    
Packit 3f632f
       $index .= "$$opt{headon}Interfaces of $host $$opt{headoff}" if $$opt{perhost};
Packit 3f632f
    } else {
Packit 3f632f
       $index .= "$$opt{headon}Special Items$$opt{headoff}" if $$opt{perhost};
Packit 3f632f
    }
Packit 3f632f
    foreach my $item (@order) {
Packit 3f632f
Packit 3f632f
	if ($$opt{perhost}) {
Packit 3f632f
		my $newhost = $$rcfg{host}{$item} || 'unspecified host';
Packit 3f632f
		if (!($host eq $newhost)) {
Packit 3f632f
			$host = $newhost;
Packit 3f632f
			if ($host){
Packit 3f632f
   		          $index .= "$$opt{headon}Interfaces of $host $$opt{headoff}\n";
Packit 3f632f
                        } else {
Packit 3f632f
   		          $index .= "$$opt{headon}Special Items$$opt{headoff}\n";
Packit 3f632f
			}
Packit 3f632f
 		        $index .= "\n";
Packit 3f632f
			$itemnr=0;
Packit 3f632f
		}
Packit 3f632f
	}
Packit 3f632f
    $$opt{prefix} = $$rcfg{prefixes}->{$item} if ($$opt{autoprefix});
Packit 3f632f
	$itemnr++;
Packit 3f632f
	$index .= "";
Packit 3f632f
        my $dirrel = "../" x ($$rcfg{'directory_web'}{$item} =~ tr|/|/|);
Packit 3f632f
Packit 3f632f
	# --- produce graph section title ---
Packit 3f632f
	my $section;
Packit 3f632f
	for ($$opt{section}) {
Packit 3f632f
	    /^h1$/ &&
Packit 3f632f
	      do{
Packit 3f632f
		  if ($$rcfg{pagetop}{$item} =~ m[<h1[^>+]*>(.+?)
Packit 3f632f
		      $section = $1;
Packit 3f632f
		      last;
Packit 3f632f
		  } else {
Packit 3f632f
		      die "ERROR: no H1 line pagetop property in $item section\n";
Packit 3f632f
		  }
Packit 3f632f
	      };
Packit 3f632f
	    /^title$/ &&
Packit 3f632f
	      do{
Packit 3f632f
		  $section = $$rcfg{title}{$item}; last
Packit 3f632f
	      };
Packit 3f632f
	    /^name$/ &&
Packit 3f632f
	      do{
Packit 3f632f
		  $section = $item; last
Packit 3f632f
	      };
Packit 3f632f
            /^descr(iption)?$/ &&
Packit 3f632f
              do{
Packit 3f632f
                  $section = "No Description for $item";
Packit 3f632f
		  $$rcfg{setenv}{$item} =~ /MRTG_INT_DESCR="(.+?)"/  #"
Packit 3f632f
                        and $section = $1;
Packit 3f632f
                  $$rcfg{pagetop}{$item} =~ 
Packit 3f632f
   		          m,Description:\s*\Q$section\E\s*([^< ][^<]+?),i
Packit 3f632f
                        and $section = $1;
Packit 3f632f
                  last;
Packit 3f632f
              };
Packit 3f632f
             /^portname$/ && 
Packit 3f632f
               do{
Packit 3f632f
                 $section = "No Portname for $item";
Packit 3f632f
                 $$rcfg{pagetop}{$item} =~ m,Port Name:\s*(.*?),i
Packit 3f632f
                      and  $section = $1;
Packit 3f632f
                 last;
Packit 3f632f
               };
Packit 3f632f
             /^ifname$/ && 
Packit 3f632f
               do{
Packit 3f632f
                 $section = "No Portname for $item";
Packit 3f632f
                 $$rcfg{pagetop}{$item} =~ m,ifname:\s*(.*?),i
Packit 3f632f
                      and  $section = $1;
Packit 3f632f
                 last;
Packit 3f632f
               };
Packit 3f632f
            die "ERROR: unknown sectioning type $_\n";
Packit 3f632f
	};
Packit 3f632f
	if (defined $$rcfg{host}{$item} and
Packit 3f632f
		!($section =~ m/\b\Q$$rcfg{host}{$item}\E\b/i)) {
Packit 3f632f
		$section = ucfirst $$rcfg{host}{$item} . ": $section";
Packit 3f632f
	}
Packit 3f632f
Packit 3f632f
	# --- write the actual graph ----
Packit 3f632f
	die "ERROR: Unknown show type $$opt{show}\n"
Packit 3f632f
	  unless $$opt{show} =~ /^day|week|month|year|none$/;
Packit 3f632f
Packit 3f632f
	my $image = "$item-$$opt{show}.${main::GRAPHFMT}"
Packit 3f632f
	 if $$opt{show} ne 'none';
Packit 3f632f
Packit 3f632f
	$index .= "<$$opt{div}>" if (!$$opt{sidebyside});
Packit 3f632f
Packit 3f632f
    if (not $image) {
Packit 3f632f
           if ($$cfg{logformat} eq 'rrdtool') {
Packit 3f632f
                my $sep = $$opt{rrdviewer} =~ /\?/ ? '&' : '?'; 
Packit 3f632f
                $index .= 
Packit 3f632f
               "".
Packit 3f632f
                       "$$opt{boldon}".
Packit 3f632f
                     "$section$$opt{boldoff}";
Packit 3f632f
            } else {
Packit 3f632f
    	          $index .= "$$opt{boldon}".
Packit 3f632f
	             "
Packit 3f632f
		        $$rcfg{directory_web}{$item}).$item.
Packit 3f632f
		        ".$$rcfg{extension}{$item}\">".
Packit 3f632f
		        "$section$$opt{boldoff}</$$opt{div}>\n<$$opt{div}>";
Packit 3f632f
	    }
Packit 3f632f
	} else {
Packit 3f632f
		#loop used for reversing (text,images) to (images,text) if req.
Packit 3f632f
		for my $picfirstloop (1,0) {
Packit 3f632f
			if ( $picfirstloop^$$opt{picfirst} ) {
Packit 3f632f
				$index .= "$$opt{boldon}$itemnr. $$opt{boldoff}"
Packit 3f632f
	  			  if $$opt{enumerate};
Packit 3f632f
			    if ($$opt{clicktext}) {
Packit 3f632f
			        $index .= "$$opt{boldon}
Packit 3f632f
					  $$rcfg{directory_web}{$item}).$item.
Packit 3f632f
					  ".$$rcfg{extension}{$item}\">";
Packit 3f632f
				$index .= $section;
Packit 3f632f
				$index .= "$$opt{boldoff}";
Packit 3f632f
			    } else {
Packit 3f632f
			    	$index .= "$$opt{boldon}$section$$opt{boldoff}";
Packit 3f632f
			    }
Packit 3f632f
	 	        $index .= "</$$opt{div}>\n<$$opt{div}>" if $picfirstloop;
Packit 3f632f
		    }
Packit 3f632f
		    
Packit 3f632f
		    if ( !($picfirstloop^$$opt{picfirst}) ) {
Packit 3f632f
		    	# figure show name for rrd viewer
Packit 3f632f
			    if ($$cfg{logformat} eq 'rrdtool') {
Packit 3f632f
               my $sep = $$opt{rrdviewer} =~ /\?/ ? '&' : '?'; 
Packit 3f632f
               $index .= "".
Packit 3f632f
		                          "
Packit 3f632f
 "SRC=\"$$opt{rrdviewer}".$sep."log=$item&cfg=$$cfgfile{$item}&png=$$opt{show}.".
Packit 3f632f
					  "s&small=1\">"
Packit 3f632f
			    } else {
Packit 3f632f
				$index .= "
Packit 3f632f
					  $$rcfg{directory_web}{$item}).$item.
Packit 3f632f
					  ".$$rcfg{extension}{$item}\">";
Packit 3f632f
		        	$index .= "
Packit 3f632f
					  "SRC=\"".cleanurl($$opt{prefix}.
Packit 3f632f
					  $$rcfg{directory_web}{$item}.$dirrel.
Packit 3f632f
					  $$cfg{imagehtml}.$$rcfg{directory_web}{$item}).
Packit 3f632f
					  "$image\"";
Packit 3f632f
				$index .= ' WIDTH="'.$$opt{width}.'"' 
Packit 3f632f
		                      if defined $$opt{width};
Packit 3f632f
				$index .= ' HEIGHT="'.$$opt{height}.'"'
Packit 3f632f
				      if defined $$opt{height};
Packit 3f632f
				$index .= ">";
Packit 3f632f
				$index .= "
"
Packit 3f632f
				      if ( ! defined $$opt{compact} );
Packit 3f632f
				$index .= "\n<SMALL>
Packit 3f632f
					  cleanurl($$opt{prefix}.$$rcfg{directory_web}{$item}).$item.
Packit 3f632f
					  ".$$rcfg{extension}{$item}\" --></SMALL>";
Packit 3f632f
			    }
Packit 3f632f
			    $index .= "</$$opt{div}>\n<$$opt{div}>" if $picfirstloop;
Packit 3f632f
			}
Packit 3f632f
		}
Packit 3f632f
	}
Packit 3f632f
Packit 3f632f
	$index .= "</$$opt{div}>" if (!$$opt{sidebyside});
Packit 3f632f
	$index .= "\n";
Packit 3f632f
Packit 3f632f
	# --- new table column if necessary ----
Packit 3f632f
	if (($itemnr) % $$opt{columns} == 0) {
Packit 3f632f
	    $index .= "\n\n";
Packit 3f632f
	}
Packit 3f632f
    }
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    # print page end
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
Packit 3f632f
Packit 3f632f
    my $VERSION = "2.17.7";
Packit 3f632f
    $index .= <
Packit 3f632f
Packit 3f632f
Packit 3f632f
Packit 3f632f
ECHO
Packit 3f632f
Packit 3f632f
   $index .= <
Packit 3f632f
$$opt{pageend}
Packit 3f632f
ECHO
Packit 3f632f
Packit 3f632f
   $index .= <
Packit 3f632f

Packit 3f632f
Packit 3f632f
  
Packit 3f632f
    
Packit 3f632f
    HREF="http://oss.oetiker.ch/mrtg/">
Packit 3f632f
    BORDER=0 SRC="${gifPath}mrtg-l.${main::GRAPHFMT}" WIDTH=63 HEIGHT=25 ALT="MRTG">
Packit 3f632f
    
Packit 3f632f
    HREF="http://oss.oetiker.ch/mrtg/">
Packit 3f632f
    BORDER=0 SRC="${gifPath}mrtg-m.${main::GRAPHFMT}" WIDTH=25 HEIGHT=25 ALT="">
Packit 3f632f
    
Packit 3f632f
    HREF="http://oss.oetiker.ch/mrtg/">
Packit 3f632f
    BORDER=0 SRC="${gifPath}mrtg-r.${main::GRAPHFMT}" WIDTH=388 HEIGHT=25
Packit 3f632f
    ALT="Multi Router Traffic Grapher">
Packit 3f632f
  
Packit 3f632f
Packit 3f632f
Packit 3f632f
  
Packit 3f632f
  <FONT FACE="Arial,Helvetica" SIZE=2>
Packit 3f632f
  version $VERSION</FONT>
Packit 3f632f
  <FONT FACE="Arial,Helvetica" SIZE=2>
Packit 3f632f
  Tobias Oetiker
Packit 3f632f
  <tobi\@oetiker.ch>
Packit 3f632f
  and Dave Rand <dlr\@bungi.com></FONT>
Packit 3f632f
  
Packit 3f632f
Packit 3f632f
Packit 3f632f
ECHO
Packit 3f632f
   $index .= <
Packit 3f632f
</BODY>
Packit 3f632f
</HTML>
Packit 3f632f
ECHO
Packit 3f632f
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    # write out the index page
Packit 3f632f
    # -----------------------------------------------------------
Packit 3f632f
    if ($$opt{output}) {
Packit 3f632f
	debug ('base', "Writing $$opt{output}");
Packit 3f632f
	open X, ">$$opt{output}" or die "ERROR: creating $$opt{output}: $!\n";
Packit 3f632f
	print X $index;
Packit 3f632f
	close X;
Packit 3f632f
    } else {
Packit 3f632f
	print $index;
Packit 3f632f
    }
Packit 3f632f
Packit 3f632f
}
Packit 3f632f
Packit 3f632f
sub options ($) {
Packit 3f632f
    my $opt = shift;
Packit 3f632f
    my @options = (
Packit 3f632f
	       'help|?',
Packit 3f632f
	       'man',
Packit 3f632f
	       'output=s',
Packit 3f632f
	       'filter=s@',
Packit 3f632f
           'addhead=s',
Packit 3f632f
	       'title=s',
Packit 3f632f
           'subtitle=s',        
Packit 3f632f
	       'bodyopt=s',
Packit 3f632f
	       'pagetopend=s',
Packit 3f632f
	       'pagetop=s',
Packit 3f632f
	       'pageend=s',
Packit 3f632f
	       'columns=i',
Packit 3f632f
	       'perhost!',
Packit 3f632f
	       'sort=s',
Packit 3f632f
	       'enumerate',
Packit 3f632f
	       'width=i',
Packit 3f632f
	       'height=i',
Packit 3f632f
	       'show=s',
Packit 3f632f
	       'section=s',
Packit 3f632f
           'version',
Packit 3f632f
	       'prefix=s',
Packit 3f632f
               'headeradd=s',
Packit 3f632f
	       'clicktext!',
Packit 3f632f
	       'optlog!',
Packit 3f632f
	       'compact!',
Packit 3f632f
	       'headlevel=i',
Packit 3f632f
	       'bold!',
Packit 3f632f
	       'picfirst!',
Packit 3f632f
	       'sidebyside!',
Packit 3f632f
	       'nolegend',
Packit 3f632f
	       'autoprefix!',
Packit 3f632f
	       'sectionhost!',
Packit 3f632f
           'icondir=s',
Packit 3f632f
	       'rrdviewer=s');
Packit 3f632f
Packit 3f632f
	#generate --option-file from --option
Packit 3f632f
	for ( grep /=s$/,@options ) {
Packit 3f632f
		my $fileopt = $_;
Packit 3f632f
		$fileopt =~ s/=s$/-file=s/;
Packit 3f632f
		push @options, $fileopt;
Packit 3f632f
	}
Packit 3f632f
	
Packit 3f632f
    GetOptions( $opt, @options ) or pod2usage(-verbose => 1);
Packit 3f632f
    
Packit 3f632f
    if ($$opt{prefix}){
Packit 3f632f
	$$opt{prefix} .= '/';
Packit 3f632f
	$$opt{prefix} =~ s|/+$|/|;
Packit 3f632f
    }
Packit 3f632f
    die ("Indexmaker for mrtg-2.17.7\n") if $$opt{version};
Packit 3f632f
    pod2usage(-exitval => 1, -verbose => 2) if $$opt{man};
Packit 3f632f
    pod2usage(-verbose => 1) if not @ARGV;
Packit 3f632f
    
Packit 3f632f
    #take care of --fileoption --> --option
Packit 3f632f
    for my $fileopt ( grep /-file$/, keys %{$opt} ) {
Packit 3f632f
    	my $orgopt = $fileopt;
Packit 3f632f
    	$orgopt =~ s/-file$//;
Packit 3f632f
    	$$opt{$orgopt} = &readfile($$opt{$fileopt});
Packit 3f632f
    }
Packit 3f632f
}
Packit 3f632f
Packit 3f632f
#return the contents of a file
Packit 3f632f
sub readfile($) {
Packit 3f632f
	my $file = shift;
Packit 3f632f
	open F,"<$file" or die "ERROR: can\'t open $file for read, $!";
Packit 3f632f
	my $sl = $/;
Packit 3f632f
	$/ = undef;
Packit 3f632f
	my $string = <F>;
Packit 3f632f
	$/ = $sl;
Packit 3f632f
	close F;
Packit 3f632f
	return $string;
Packit 3f632f
}
Packit 3f632f
Packit 3f632f
__END__
Packit 3f632f
Packit 3f632f
=pod
Packit 3f632f
Packit 3f632f
=head1 NAME
Packit 3f632f
Packit 3f632f
indexmaker - Creates index files for mrtg web sites (mrtg-2.17.7)
Packit 3f632f
Packit 3f632f
=head1 SYNOPSIS
Packit 3f632f
Packit 3f632f
indexmaker [options] mrtg.cfg [other.cfg ...]
Packit 3f632f
Packit 3f632f
=head1 OPTIONS
Packit 3f632f
Packit 3f632f
 --output=filename   set output filename (default: stdout)
Packit 3f632f
Packit 3f632f
 --filter title=~regexp  select targets by matching regexp against titles
Packit 3f632f
 --filter pagetop=~regexp  select targets by matching regexp against pagetop
Packit 3f632f
 --filter name=~regexp  select targets by matchin regexp against name
Packit 3f632f
Packit 3f632f
 --addhead=text      insert this text between </TITLE> and </HEAD>
Packit 3f632f
 --title=text        set title of generated index file
Packit 3f632f
 --subtitle=text     add a subtitle to the generated index file
Packit 3f632f
 --bodyopt=text      set body tag options
Packit 3f632f
 --headlevel=number  use <Hnumber> at top of page (default: 1)
Packit 3f632f
 --pagetop=text      insert this text between <BODY> and 

...

Packit 3f632f
 --pageend=text      insert this text after the main body
Packit 3f632f
 --pagetopend=text   use this text for pagetop or pageend if undefined
Packit 3f632f
 --nolegend          do not add the Mrtg legend at the end of the page
Packit 3f632f
Packit 3f632f
 --columns=number    show graphs in a table with x columns (default: 2)
Packit 3f632f
 --perhost           show graphs of the same host on a row
Packit 3f632f
 --compact           try to make a vertically more compact page
Packit 3f632f
 --optlog            log the used command line in the page (default: log)
Packit 3f632f
Packit 3f632f
 --sort=title        sort graphs by title
Packit 3f632f
 --sort=name         sort graphs by their name
Packit 3f632f
 --sort=descr        sort graphs by their description
Packit 3f632f
 --sort=original     leave as is (default)
Packit 3f632f
Packit 3f632f
 --enumerate         add a sequence number to the title of each graph
Packit 3f632f
Packit 3f632f
 --picfirst          place pictures before text (default: text first)
Packit 3f632f
 --width=number      set width of graphs (default: not set)
Packit 3f632f
 --height=number
Packit 3f632f
 --sidebyside        place text / pictures side by side (default: above/below)
Packit 3f632f
 --bold              use bold text (default: bold)
Packit 3f632f
 --clicktext         make the text link to the inner page (like the image)
Packit 3f632f
Packit 3f632f
 --show=day          pick which graph to show in the index (default)
Packit 3f632f
 --show=week
Packit 3f632f
 --show=month
Packit 3f632f
 --show=year
Packit 3f632f
 --show=none
Packit 3f632f
Packit 3f632f
 --section=h1        h1 tag from pagetop as section heading (default)
Packit 3f632f
 --section=title     title as section headings for graphs
Packit 3f632f
 --section=name      graph name as section heading
Packit 3f632f
 --section=descr     graph description as section heading
Packit 3f632f
 --section=ifname    interface name (ifName) as section heading
Packit 3f632f
 --section=portname  port name entry in pagetop as section heading
Packit 3f632f
 --sectionhost       Try to prepend the host to the section heading if missing
Packit 3f632f
Packit 3f632f
 --rrdviewer=path    path to rrdviewer (default: /cgi-bin/14all.cgi)
Packit 3f632f
 --icondir=path      path to icondir
Packit 3f632f
 --prefix=path       path from the location of the index.html to the graphs
Packit 3f632f
 --headeradd=string  add string to the html page header
Packit 3f632f
 --autoprefix        try to set prefix automatically
Packit 3f632f
 
Packit 3f632f
 --<opt>-file=file   read string argument for option <opt> from file
Packit 3f632f
Packit 3f632f
=head1 DESCRIPTION
Packit 3f632f
Packit 3f632f
B<Indexmaker> can create web pages which display the status of an
Packit 3f632f
array of mrtg interface status pages.
Packit 3f632f
Packit 3f632f
=over
Packit 3f632f
Packit 3f632f
=item B<--output> I<filename>
Packit 3f632f
Packit 3f632f
set output filename (default: stdout)
Packit 3f632f
Packit 3f632f
=item B<--filter> (B<title>|B<pagetop>|B<name>)(B<=~>|B)I<regexp>
Packit 3f632f
Packit 3f632f
Several filters may get set.  Each filter can match agains the contents
Packit 3f632f
of a specific section of the mrtg config file. B<Name> refers to the
Packit 3f632f
bit in square brackets (option[name]: bla).
Packit 3f632f
Packit 3f632f
Depending on the match operator chosen (B<=~> or B) the match will be
Packit 3f632f
positive or negative.
Packit 3f632f
Packit 3f632f
Note that some shells consider B a special character.  It may be
Packit 3f632f
necessary to type B<\!~> instead.
Packit 3f632f
Packit 3f632f
=item B<--title> I<text>
Packit 3f632f
Packit 3f632f
Set title of generated index file (default: regexp)
Packit 3f632f
Packit 3f632f
=item B<--bodyopt> I<text>
Packit 3f632f
Packit 3f632f
The value of this argument gets appended to
Packit 3f632f
the E<lt>BODYE<gt> tag. This allows you to set document colors.
Packit 3f632f
By default this option is set to
Packit 3f632f
Packit 3f632f
 bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000" alink="#000000"
Packit 3f632f
Packit 3f632f
=item  B<--columns> I<number>
Packit 3f632f
Packit 3f632f
Display graphs in a table with I<number> columns (default: 2)
Packit 3f632f
Packit 3f632f
=item B<--sort> B<title>|B<name>|B<descr>|B<original>
Packit 3f632f
Packit 3f632f
Sort the graphs in the page either by B<title>, by B<name>, by interface
Packit 3f632f
B<descr>iption, or leave them as is.
Packit 3f632f
Packit 3f632f
=item B<--enumerate>
Packit 3f632f
Packit 3f632f
Add a sequence number to the title of each graph
Packit 3f632f
Packit 3f632f
=item B<--width> I<number>
Packit 3f632f
Packit 3f632f
Set width of graphs
Packit 3f632f
Packit 3f632f
=item B<--height> I<number>
Packit 3f632f
Packit 3f632f
Set the height of the graphs
Packit 3f632f
Packit 3f632f
=item B<--show> B<day>|B<week>|B<month>|B<year>|B<none>
Packit 3f632f
Packit 3f632f
Select which graph to show in the index page. You can supress images
Packit 3f632f
completely with B<--show=none>.
Packit 3f632f
Packit 3f632f
=item B<--section> B

|B<title>|B<name>|B<description>|B<portname>

Packit 3f632f
Packit 3f632f
Select what to use as the title for each graph in the page.  B

is

Packit 3f632f
the H1 section from pagetop, B<title> is the graph title, B<name> is
Packit 3f632f
the bit in square brackets (option[name]: bla), and B<descr> or
Packit 3f632f
B<description> is the text from the Description field of the PageTop
Packit 3f632f
(the Cisco description text if it's available, otherwise just the
Packit 3f632f
interface description). B<portname> is the C<Port Name:> from pagetop.
Packit 3f632f
Packit 3f632f
=item B<--sectionhost>
Packit 3f632f
Packit 3f632f
Extract the hostname from the target line (this does not work if the 
Packit 3f632f
target is a mathematial expression). Prepend the hostname (and a colon)
Packit 3f632f
to the section if not already present.
Packit 3f632f
Packit 3f632f
=item B<--rrdviewer> I<path>
Packit 3f632f
Packit 3f632f
If you have set the B<LogFormat: rrdtool> property in the mrtg.cfg
Packit 3f632f
file, the index will take this into account. The only thing you must
Packit 3f632f
tell it is the path to your grapher cgi. (default: /cgi-bin/14all.cgi)
Packit 3f632f
Packit 3f632f
=item B<--prefix> I<path>
Packit 3f632f
Packit 3f632f
By  default we assume    that  the file generated by indexmaker is stored in
Packit 3f632f
I<WorkDir>.  If you want to  store it somewhere   else, specify how to reach
Packit 3f632f
I<WorkDir>  from  the place where the Index is stored. Note that you have to
Packit 3f632f
use '/' as path separator as this will be used in urls. Speaking of which,
Packit 3f632f
you can even enter a whole url.
Packit 3f632f
Packit 3f632f
=item B<--autoprefix> I<path>
Packit 3f632f
Packit 3f632f
Requires --output.
Packit 3f632f
Try to generate the prefix automatically by comparision of the path to the
Packit 3f632f
output file set with --output and the Htmldir set in the configuration files.
Packit 3f632f
Particulary useful when multiple configuration files are specified, with
Packit 3f632f
different Htmldir settings.
Packit 3f632f
Packit 3f632f
=item B<--optlog>
Packit 3f632f
Packit 3f632f
Default is logging in the generated page the command line, suppress with
Packit 3f632f
--nooptlog . Useful if the commandline contains a complex --pagetop=string
Packit 3f632f
which could confuse simple browsers.
Packit 3f632f
Packit 3f632f
=item B<--someoption-file> I<filename>
Packit 3f632f
Packit 3f632f
For any someoption which takes a I<string> as parameter you can read the
Packit 3f632f
string from a file by adding <-file> to the option keyword. The whole 
Packit 3f632f
content of the file will be read and used as the I<string>. The file must
Packit 3f632f
exist.
Packit 3f632f
Packit 3f632f
=back
Packit 3f632f
Packit 3f632f
=head1 AUTHOR
Packit 3f632f
Packit 3f632f
Tobias Oetiker E<lt>tobi@oetiker.chE<gt>
Packit 3f632f
Packit 3f632f
=head1 LICENSE
Packit 3f632f
Packit 3f632f
GNU General Public License
Packit 3f632f
Packit 3f632f
=head1 COPYRIGHT
Packit 3f632f
Packit 3f632f
2000-2001 Tobias Oetiker E<lt>tobi@oetiker.chE<gt>
Packit 3f632f
Packit 3f632f
=cut