| 1 | 1 | simandl | #!/usr/bin/env perl |
| 2 | | | |
| 3 | | | # $Id: makeindex.pl,v 1.24 2004/08/30 11:54:24 bernisys Exp $ |
| 4 | | | |
| 5 | | | # include PERL libraries |
| 6 | | | use strict; |
| 7 | | | use warnings; |
| 8 | | | use diagnostics; |
| 9 | | | use FindBin; |
| 10 | | | use lib $FindBin::RealBin; |
| 11 | | | # use Getopt::Long; |
| 12 | | | |
| 13 | | | # include HotSaNIC libraries |
| 14 | | | use lib "./lib"; |
| 15 | | | use HotSaNICparser; |
| 16 | | | use HotSaNIChtml; |
| 17 | | | |
| 18 | | | # let all outputs be flushed directly |
| 19 | | | $|=1; |
| 20 | | | |
| 21 | | | (my $CALLDIR=$FindBin::RealBin) =~ s/\/rrdtimer//g; |
| 22 | | | (my $VERSION = '$Revision: 1.24 $') =~ s/.*(\d+\.\d+).*/$1/; |
| 23 | | | (my $IDENTIFIER = '$Id: makeindex.pl,v 1.24 2004/08/30 11:54:24 bernisys Exp $') =~ s/.*,v (.*) \$/$1/; |
| 24 | | | |
| 25 | | | my %CONFIG=HotSaNICparser::get_config($CALLDIR); |
| 26 | | | |
| 27 | | | my $DAEMONDIR=$CONFIG{DAEMONDIR}; |
| 28 | | | my $VARDIR=$CONFIG{VARDIR}; |
| 29 | | | my $WEBDIR=$CONFIG{WEBDIR}; |
| 30 | | | my $ORDER=$CONFIG{ORDER}; |
| 31 | | | my $SHOW=$CONFIG{SHOW}; |
| 32 | | | my $CONVERTMETHOD=$CONFIG{CONVERTMETHOD}; |
| 33 | | | my $THUMBSIZE=$CONFIG{THUMBSIZE}; |
| 34 | | | my $WIDTH=$CONFIG{WIDTH}; |
| 35 | | | undef my %PAGESTYLE; |
| 36 | | | $PAGESTYLE{BGCOLOR}=$CONFIG{WEB_BGCOLOR}; |
| 37 | | | $PAGESTYLE{TEXT}=$CONFIG{WEB_TEXT} || ""; |
| 38 | | | $PAGESTYLE{LINK}=$CONFIG{WEB_LINK} || ""; |
| 39 | | | $PAGESTYLE{VLINK}=$CONFIG{WEB_VLINK} || ""; |
| 40 | | | $PAGESTYLE{ALINK}=$CONFIG{WEB_ALINK} || ""; |
| 41 | | | $PAGESTYLE{BACKGROUND}=$CONFIG{WEB_BACKGROUND} || ""; |
| 42 | | | |
| 43 | | | $THUMBSIZE=~s/%//g; |
| 44 | | | $THUMBSIZE=~ s/,/\./g; |
| 45 | | | $THUMBSIZE=int($THUMBSIZE*$WIDTH/100); |
| 46 | | | |
| 47 | | | my @modules=HotSaNICparser::scan_for_modules("$DAEMONDIR/modules",$SHOW); |
| 48 | | | |
| 49 | | | my (@order,$subdirs,@ITEMS,$item,%count,%lines,$dir,$MAXLINES,$num,$value,$modname,$i,$out); |
| 50 | | | |
| 51 | | | # create webdir if necessary |
| 52 | | | # |
| 53 | | | if ( ! -e $WEBDIR ) { |
| 54 | | | print "creating HTTP output directory:\n $WEBDIR\n"; |
| 55 | | | umask 000; |
| 56 | | | mkdir $WEBDIR,0755 or die "ERROR: $!\n\n"; |
| 57 | | | } |
| 58 | | | |
| 59 | | | # create var if necessary |
| 60 | | | # |
| 61 | | | if ( ! -e $VARDIR ) { |
| 62 | | | print "creating var directory:\n $VARDIR\n"; |
| 63 | | | umask 000; |
| 64 | | | mkdir $VARDIR,0755 or die "ERROR: $!\n\n"; |
| 65 | | | } |
| 66 | | | |
| 67 | | | @order=split(/ /,$ORDER); |
| 68 | | | |
| 69 | | | # first add all existing modules in the order they are listed |
| 70 | | | # in the "ORDER" config-string |
| 71 | | | # |
| 72 | | | $subdirs=join(" ",@modules); |
| 73 | | | foreach $item (@order) { |
| 74 | | | if (index($subdirs,$item) >=0) { push @ITEMS,$item; } |
| 75 | | | } |
| 76 | | | |
| 77 | | | # then add all not ordered but wanted modules in alphabetical order |
| 78 | | | # |
| 79 | | | $subdirs=join(" ",@ITEMS); |
| 80 | | | foreach $item (@modules) { |
| 81 | | | if (index($subdirs,$item) <0) { push @ITEMS,$item; } |
| 82 | | | } |
| 83 | | | |
| 84 | | | $MAXLINES=0; |
| 85 | | | print "generating index-files for each plugin...\n"; |
| 86 | | | |
| 87 | | | my $LIB_TIME=(stat("$DAEMONDIR/lib/HotSaNIChtml.pm"))[9]; |
| 88 | | | my $SETTINGS_TIME=(stat("$DAEMONDIR/settings"))[9]; |
| 89 | | | |
| 90 | | | foreach $modname (sort @ITEMS) { |
| 91 | | | print "processing $modname\n"; |
| 92 | | | my $subdir="$DAEMONDIR/modules/$modname"; |
| 93 | | | my $vardir="$VARDIR/modules/$modname"; |
| 94 | | | my $webdir="$WEBDIR/$modname"; |
| 95 | | | if (! -e $vardir) { |
| 96 | | | print " creating missing directory $vardir\n"; |
| 97 | | | mkdir $vardir,0755 or die "ERROR: $!\n\n"; |
| 98 | | | } |
| 99 | | | if (! -e $webdir) { |
| 100 | | | print " creating missing directory $webdir\n"; |
| 101 | | | mkdir $webdir,0755 or die "ERROR: $!\n\n"; |
| 102 | | | if (-e "$vardir/idxdata") { unlink "$vardir/idxdata"; } |
| 103 | | | } |
| 104 | | | $count{$modname}=1; |
| 105 | | | |
| 106 | | | my $generate=0; |
| 107 | | | my $command=""; |
| 108 | | | |
| 109 | | | if ( -e "$subdir/makeindex.pl") { $command="makeindex.pl"; $generate=1; } |
| 110 | | | elsif ( -e "$subdir/makeindex") { $command="makeindex"; $generate=1; } |
| 111 | | | |
| 112 | | | # check if module's settings file or makeindex script is newer than idxdata file |
| 113 | | | if (-e "$vardir/idxdata") { |
| 114 | | | my $IDX_TIME=(stat("$vardir/idxdata"))[9]; |
| 115 | | | $generate=0 if $IDX_TIME >= (stat("$subdir/settings"))[9]; |
| 116 | | | $generate=1 if (stat("$subdir/$command"))[9] >= $IDX_TIME; |
| 117 | | | $generate=1 if $LIB_TIME >= $IDX_TIME; |
| 118 | | | $generate=1 if $SETTINGS_TIME >= $IDX_TIME; |
| 119 | | | } |
| 120 | | | elsif (-e "$subdir/idxdata") { |
| 121 | | | my $IDX_TIME=(stat("$subdir/idxdata"))[9]; |
| 122 | | | $generate=0 if $IDX_TIME >= (stat("$subdir/settings"))[9]; |
| 123 | | | $generate=1 if (stat("$subdir/$command"))[9] >= $IDX_TIME; |
| 124 | | | $generate=1 if $LIB_TIME >= $IDX_TIME; |
| 125 | | | $generate=1 if $SETTINGS_TIME >= $IDX_TIME; |
| 126 | | | } |
| 127 | | | |
| 128 | | | # TODO: |
| 129 | | | # |
| 130 | | | # check if ALL html files for this module are up to date |
| 131 | | | # |
| 132 | | | # check if all html files exist |
| 133 | | | # (not yet possible...) |
| 134 | | | # |
| 135 | | | if (($command ne "") and ($generate>0)) { |
| 136 | | | if (-e "$subdir/idxdata") { unlink "$subdir/idxdata"; } |
| 137 | | | print " updating index files...\n"; |
| 138 | | | system("cd \"$subdir\"; ./$command"); |
| 139 | | | } |
| 140 | | | |
| 141 | | | # process generated (hopefully) idxdata file |
| 142 | | | if (-e "$subdir/idxdata") { system "mv -f $subdir/idxdata $vardir"; } |
| 143 | | | open FILE,"$vardir/idxdata"; |
| 144 | | | while (<FILE>) { |
| 145 | | | ($num,$value)=split /##/; |
| 146 | | | chomp $num; |
| 147 | | | if ( (defined $value) && ($value ne "") ) { |
| 148 | | | push @{ $lines{$modname} },"$_"; |
| 149 | | | if ($MAXLINES < $num) { $MAXLINES=$num; } |
| 150 | | | } |
| 151 | | | elsif ($num ne "") { $count{$modname} = $num; } |
| 152 | | | } |
| 153 | | | close FILE; |
| 154 | | | |
| 155 | | | # unlink "$subdir/idxdata"; |
| 156 | | | |
| 157 | | | } |
| 158 | | | |
| 159 | | | print "\nbuilding $WEBDIR/index.html ...\n"; |
| 160 | | | |
| 161 | | | if ( ! -e "$WEBDIR/rrdtool.gif" ) { system("cp -f images/rrdtool.gif $WEBDIR"); } |
| 162 | | | if ( ! -e "$WEBDIR/HotSaNIC.gif" ) { system("cp -f images/HotSaNIC.gif $WEBDIR"); } |
| 163 | | | if ( ! -e "$WEBDIR/bg.gif" ) { system("cp -f images/bg.gif $WEBDIR"); } |
| 164 | | | if ( ! -e "$WEBDIR/menubg.gif" ) { system("cp -f images/menubg.gif $WEBDIR"); } |
| 165 | | | |
| 166 | | | open INDEXFILE,">$WEBDIR/index.html"; |
| 167 | | | print INDEXFILE HotSaNIChtml::create_header("",0,"",%PAGESTYLE); |
| 168 | | | print INDEXFILE " <center> |
| 169 | | | <table border=0>\n"; |
| 170 | | | |
| 171 | | | print "table-size: ",$MAXLINES+1," lines.\n\n"; |
| 172 | | | print "Modules are added in this order:\n"; |
| 173 | | | |
| 174 | | | open MENUFILE,">$WEBDIR/menu.html"; |
| 175 | | | $PAGESTYLE{BACKGROUND}=$CONFIG{WEB_MENUBACKGROUND} || ""; |
| 176 | | | print MENUFILE HotSaNIChtml::create_header("",0,"",%PAGESTYLE); |
| 177 | | | print MENUFILE " <center> |
| 178 | | | <a href=\"http://hotsanic.sourceforge.net/\" target=\"stats\"><img src=\"HotSaNIC.gif\"></a><br><br><hr width=70%><br> |
| 179 | | | <a href=\"./index.html\" target=\"stats\">overview</a><br><br> |
| 180 | | | "; |
| 181 | | | |
| 182 | | | # scan array from 0 to $MAXLINES to create the table lines. |
| 183 | | | # if no line was found corrosponding to actual line-number |
| 184 | | | # then output a table row with no entries |
| 185 | | | for ($i=0; $i<=$MAXLINES; $i++) { |
| 186 | | | print INDEXFILE " <tr valign=top>\n"; |
| 187 | | | foreach $modname (@ITEMS) { |
| 188 | | | if ($i == 0) { |
| 189 | | | print $modname,"\n"; |
| 190 | | | print MENUFILE " <a href=\"./$modname/week.html\" target=\"stats\">$modname</a><br>\n"; |
| 191 | | | } |
| 192 | | | $out=0; |
| 193 | | | foreach (@{ $lines{$modname} }) { |
| 194 | | | ($num,$value)=split(/##/); |
| 195 | | | if ($num == $i) { |
| 196 | | | if ($CONVERTMETHOD eq "HTML") { |
| 197 | | | $value=~ s/thumb-//g; |
| 198 | | | $value=~ s/.gif"/-week.gif" width="$THUMBSIZE"/g; |
| 199 | | | $value=~ s/.png"/-week.png" width="$THUMBSIZE"/g; |
| 200 | | | } |
| 201 | | | print INDEXFILE $value; |
| 202 | | | $out=1; |
| 203 | | | } |
| 204 | | | } |
| 205 | | | if ( $out == 0 ) { print INDEXFILE HotSaNIChtml::create_overview_table_entry_empty(-1,$count{$modname}); } |
| 206 | | | } |
| 207 | | | print INDEXFILE " </tr>\n"; |
| 208 | | | } |
| 209 | | | |
| 210 | | | print INDEXFILE " </table>\n </center>\n".HotSaNIChtml::create_footer(""); |
| 211 | | | close INDEXFILE; |
| 212 | | | |
| 213 | | | |
| 214 | | | print MENUFILE " <br><hr width=70%>\n </center>\n </body>\n</html>\n"; |
| 215 | | | close MENUFILE; |
| 216 | | | |
| 217 | | | open FILE,">$WEBDIR/frame.html"; |
| 218 | | | print FILE "<html> |
| 219 | | | <head> |
| 220 | | | <title>HotSaNIC - system statistics</title> |
| 221 | | | </head> |
| 222 | | | <frameset cols=\"120,*\"> |
| 223 | | | <frame src=\"menu.html\" name=\"menu\"> |
| 224 | | | <frame src=\"index.html\" name=\"stats\"> |
| 225 | | | </frameset> |
| 226 | | | </html> |
| 227 | | | "; |
| 228 | | | close FILE; |
| 229 | | | |
| 230 | | | print "\ndone.\n\n"; |
| 231 | | | |