#!/usr/bin/perl

# mrtgidx - generate html index page based on mrtg.cfg
#
# Syntax: mrtgidx <pathname-of-mrtg.cfg> 
#
# v0.1 1996-11 by Axel Dunkel (ad@Dunkel.de)
#

# --- start of configuration section ---

$include_inactive	= 1;	# include interfaces that are commented out

# --- eof of configuration section ---

if ($#ARGV < 0) {
  print "mrtgidx: generate HTML index page based on MRTG config file\n";
  print "\nUsage: mrtgidx <pathname-of-mrtg.cfg-file>\n";
  exit 2;
}

while ($line = <>) {
   chop $line;
   if ($line =~ /^(#*).*Title\[(\S+)\]:\s*([^:]*):\s*(.*)$/) {
	  $cmt 		= $1;
	  $itf		= $2;
	  $title	= $3;
	  $title_if = $4;
      if ($cmt ne "#" || $include_inactive) {
	    if ($itf =~ /(.*)\.([0-9]+)/) {
		  $router{$1,$2} = $title_if;
		  $router_f{$1,$2} = $itf;
		  $router_n{$1} = $title;
          $active{$1,$2} = $cmt;
	    } else {
		  print STDERR "Warning: can not interpret : $itf\n";
		}
      }
   } 
}

# print HTML header

print "MRTG Index\n";
print "\n";
print "
MRTG - Index
\n";
print "generated by mrtgidx by Axel Dunkel\n";
print "
\n";

foreach $r (sort keys %router_n) {
  print "<P>
- 
$r

\n";
  foreach $i (0..200) {
    if (defined $router{$r,$i}) {
	  print "
- ";
      if ($active{$r,$i} ne "#") { print ""; }
	  print "$router{$r,$i}";
      if ($active{$r,$i} ne "#") { print "\n"; }
    }
  }
  print "
\n";
}

print "
\n";

