jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [makeindex.pl] - Rev 7 Go to most recent revision

Compare with Previous - Blame - Download


#!/usr/bin/env perl

# $Id: makeindex.pl,v 1.24 2004/08/30 11:54:24 bernisys Exp $

# include PERL libraries
use strict;
use warnings;
use diagnostics;
use FindBin;
use lib $FindBin::RealBin;
# use Getopt::Long;

# include HotSaNIC libraries
use lib "./lib";
use HotSaNICparser;
use HotSaNIChtml;

# let all outputs be flushed directly
$|=1;

(my $CALLDIR=$FindBin::RealBin) =~ s/\/rrdtimer//g;
(my $VERSION = '$Revision: 1.24 $') =~ s/.*(\d+\.\d+).*/$1/;
(my $IDENTIFIER = '$Id: makeindex.pl,v 1.24 2004/08/30 11:54:24 bernisys Exp $') =~ s/.*,v (.*) \$/$1/;

my %CONFIG=HotSaNICparser::get_config($CALLDIR);

my $DAEMONDIR=$CONFIG{DAEMONDIR};
my $VARDIR=$CONFIG{VARDIR};
my $WEBDIR=$CONFIG{WEBDIR};
my $ORDER=$CONFIG{ORDER};
my $SHOW=$CONFIG{SHOW};
my $CONVERTMETHOD=$CONFIG{CONVERTMETHOD};
my $THUMBSIZE=$CONFIG{THUMBSIZE};
my $WIDTH=$CONFIG{WIDTH};
undef my %PAGESTYLE;
$PAGESTYLE{BGCOLOR}=$CONFIG{WEB_BGCOLOR};
$PAGESTYLE{TEXT}=$CONFIG{WEB_TEXT} || "";
$PAGESTYLE{LINK}=$CONFIG{WEB_LINK} || "";
$PAGESTYLE{VLINK}=$CONFIG{WEB_VLINK} || "";
$PAGESTYLE{ALINK}=$CONFIG{WEB_ALINK} || "";
$PAGESTYLE{BACKGROUND}=$CONFIG{WEB_BACKGROUND} || "";

$THUMBSIZE=~s/%//g;
$THUMBSIZE=~ s/,/\./g;
$THUMBSIZE=int($THUMBSIZE*$WIDTH/100);

my @modules=HotSaNICparser::scan_for_modules("$DAEMONDIR/modules",$SHOW);

my (@order,$subdirs,@ITEMS,$item,%count,%lines,$dir,$MAXLINES,$num,$value,$modname,$i,$out);

# create webdir if necessary
#
if ( ! -e $WEBDIR ) {
  print "creating HTTP output directory:\n   $WEBDIR\n";
  umask 000;
  mkdir $WEBDIR,0755 or die "ERROR: $!\n\n";
  }

# create var if necessary
#
if ( ! -e $VARDIR ) {
  print "creating var directory:\n   $VARDIR\n";
  umask 000;
  mkdir $VARDIR,0755 or die "ERROR: $!\n\n";
  }

@order=split(/ /,$ORDER);

# first add all existing modules in the order they are listed
# in the "ORDER" config-string
#
$subdirs=join(" ",@modules);
foreach $item (@order) {
  if (index($subdirs,$item) >=0) { push @ITEMS,$item; }
  }

# then add all not ordered but wanted modules in alphabetical order
#
$subdirs=join(" ",@ITEMS);
foreach $item (@modules) {
  if (index($subdirs,$item) <0) { push @ITEMS,$item; }
  }

$MAXLINES=0;
print "generating index-files for each plugin...\n";

my $LIB_TIME=(stat("$DAEMONDIR/lib/HotSaNIChtml.pm"))[9];
my $SETTINGS_TIME=(stat("$DAEMONDIR/settings"))[9];

foreach $modname (sort @ITEMS) {
  print "processing $modname\n";
  my $subdir="$DAEMONDIR/modules/$modname";
  my $vardir="$VARDIR/modules/$modname";
  my $webdir="$WEBDIR/$modname";
  if (! -e $vardir) {
    print "  creating missing directory $vardir\n";
    mkdir $vardir,0755 or die "ERROR: $!\n\n";
    }
  if (! -e $webdir) {
    print "  creating missing directory $webdir\n";
    mkdir $webdir,0755 or die "ERROR: $!\n\n";
    if (-e "$vardir/idxdata") { unlink "$vardir/idxdata"; }
    }
  $count{$modname}=1;

  my $generate=0;
  my $command="";

  if ( -e "$subdir/makeindex.pl") { $command="makeindex.pl"; $generate=1; }
  elsif ( -e "$subdir/makeindex") { $command="makeindex"; $generate=1; }

  # check if module's settings file or makeindex script is newer than idxdata file
  if (-e "$vardir/idxdata") {
    my $IDX_TIME=(stat("$vardir/idxdata"))[9];
    $generate=0 if $IDX_TIME >= (stat("$subdir/settings"))[9];
    $generate=1 if (stat("$subdir/$command"))[9] >= $IDX_TIME;
    $generate=1 if $LIB_TIME >= $IDX_TIME;
    $generate=1 if $SETTINGS_TIME >= $IDX_TIME;
    }
  elsif (-e "$subdir/idxdata") {
    my $IDX_TIME=(stat("$subdir/idxdata"))[9];
    $generate=0 if $IDX_TIME >= (stat("$subdir/settings"))[9];
    $generate=1 if (stat("$subdir/$command"))[9] >= $IDX_TIME;
    $generate=1 if $LIB_TIME >= $IDX_TIME;
    $generate=1 if $SETTINGS_TIME >= $IDX_TIME;
    }

  # TODO:
  #
  # check if ALL html files for this module are up to date
  #
  # check if all html files exist
  # (not yet possible...)
  #
  if (($command ne "") and ($generate>0)) {
    if (-e "$subdir/idxdata") { unlink "$subdir/idxdata"; }
    print "  updating index files...\n";  
    system("cd \"$subdir\"; ./$command");
    }

  # process generated (hopefully) idxdata file
  if (-e "$subdir/idxdata") { system "mv -f $subdir/idxdata $vardir"; }
  open FILE,"$vardir/idxdata";
  while (<FILE>) {
    ($num,$value)=split /##/;
    chomp $num;
    if ( (defined $value) && ($value ne "") ) {
      push @{ $lines{$modname} },"$_";
      if ($MAXLINES < $num) { $MAXLINES=$num; }
      }
    elsif ($num ne "") { $count{$modname} = $num; }
    }
  close FILE;

#  unlink "$subdir/idxdata";

  }
  
print "\nbuilding $WEBDIR/index.html ...\n";

if ( ! -e "$WEBDIR/rrdtool.gif" ) { system("cp -f images/rrdtool.gif $WEBDIR"); }
if ( ! -e "$WEBDIR/HotSaNIC.gif" ) { system("cp -f images/HotSaNIC.gif $WEBDIR"); }
if ( ! -e "$WEBDIR/bg.gif" ) { system("cp -f images/bg.gif $WEBDIR"); }
if ( ! -e "$WEBDIR/menubg.gif" ) { system("cp -f images/menubg.gif $WEBDIR"); }

open INDEXFILE,">$WEBDIR/index.html";
print INDEXFILE HotSaNIChtml::create_header("",0,"",%PAGESTYLE);
print INDEXFILE "    <center>
      <table border=0>\n";

print "table-size: ",$MAXLINES+1," lines.\n\n";
print "Modules are added in this order:\n";

open MENUFILE,">$WEBDIR/menu.html";
$PAGESTYLE{BACKGROUND}=$CONFIG{WEB_MENUBACKGROUND} || "";
print MENUFILE HotSaNIChtml::create_header("",0,"",%PAGESTYLE);
print MENUFILE "    <center>
      <a href=\"http://hotsanic.sourceforge.net/\" target=\"stats\"><img src=\"HotSaNIC.gif\"></a><br><br><hr width=70%><br>
      <a href=\"./index.html\" target=\"stats\">overview</a><br><br>
";

# scan array from 0 to $MAXLINES to create the table lines.
# if no line was found corrosponding to actual line-number
# then output a table row with no entries
for ($i=0; $i<=$MAXLINES; $i++) {
  print INDEXFILE "        <tr valign=top>\n";
  foreach $modname (@ITEMS) {
    if ($i == 0) {
      print $modname,"\n";
      print MENUFILE "       <a href=\"./$modname/week.html\" target=\"stats\">$modname</a><br>\n";
      }
    $out=0;
    foreach (@{ $lines{$modname} }) {
      ($num,$value)=split(/##/);
      if ($num == $i) {
        if ($CONVERTMETHOD eq "HTML") {
          $value=~ s/thumb-//g;
          $value=~ s/.gif"/-week.gif" width="$THUMBSIZE"/g;
          $value=~ s/.png"/-week.png" width="$THUMBSIZE"/g;
          }
        print INDEXFILE $value;
        $out=1;
        }
      }
    if ( $out == 0 ) { print INDEXFILE HotSaNIChtml::create_overview_table_entry_empty(-1,$count{$modname}); }
    }
  print INDEXFILE "        </tr>\n";
  }

print INDEXFILE "      </table>\n    </center>\n".HotSaNIChtml::create_footer("");
close INDEXFILE;


print MENUFILE "      <br><hr width=70%>\n    </center>\n  </body>\n</html>\n";
close MENUFILE;

open FILE,">$WEBDIR/frame.html";
print FILE "<html>
<head>
<title>HotSaNIC - system statistics</title>
</head>
<frameset cols=\"120,*\">
<frame src=\"menu.html\" name=\"menu\">
<frame src=\"index.html\" name=\"stats\">
</frameset>
</html>
";
close FILE;

print "\ndone.\n\n";


Powered by WebSVN 2.2.1