1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | use strict; |
3 | | | use warnings; |
4 | | | use diagnostics; |
5 | | | |
6 | | | # |
7 | | | # $Id: makeindex.pl,v 1.10 2003/07/12 20:57:27 bernisys Exp $ |
8 | | | # |
9 | | | # use Getopt::Long; |
10 | | | use FindBin; |
11 | | | use lib "./lib"; |
12 | | | use lib $FindBin::RealBin; |
13 | | | use HotSaNICparser; |
14 | | | |
15 | | | # let all outputs be flushed directly |
16 | | | $|=1; |
17 | | | |
18 | | | (my $CALLDIR=$FindBin::RealBin) =~ s/\/rrdtimer//g; |
19 | | | (my $VERSION = '$Revision: 1.10 $') =~ s/.*(\d+\.\d+).*/$1/; |
20 | | | |
21 | | | my %CONFIG=HotSaNICparser::get_config($CALLDIR); |
22 | | | |
23 | | | |
24 | | | my $DAEMONDIR=$CONFIG{"DAEMONDIR"}; |
25 | | | my $WEBDIR=$CONFIG{"WEBDIR"}; |
26 | | | my $ORDER=$CONFIG{"ORDER"}; |
27 | | | my $SHOW=$CONFIG{"SHOW"}; |
28 | | | my $CONVERTMETHOD=$CONFIG{"CONVERTMETHOD"}; |
29 | | | my $THUMBSIZE=$CONFIG{"THUMBSIZE"}; |
30 | | | my $WIDTH=$CONFIG{"WIDTH"}; |
31 | | | $THUMBSIZE=~s/%//g; |
32 | | | $THUMBSIZE=~ s/,/\./g; |
33 | | | $THUMBSIZE=int($THUMBSIZE*$WIDTH/100); |
34 | | | |
35 | | | my @modules=HotSaNICparser::scan_for_modules("$DAEMONDIR/modules",-1,$SHOW); |
36 | | | |
37 | | | my (@order,$subdirs,@ITEMS,$item,%count,%lines,$dir,$MAXLINES,$num,$value,$modname,$i,$out); |
38 | | | |
39 | | | # create webdir if necessary |
40 | | | # |
41 | | | if ( ! -e $WEBDIR ) { |
42 | | | print "creating HTTP output directory:\n $WEBDIR\n"; |
43 | | | umask 000; |
44 | | | mkdir $WEBDIR,0755 or die "ERROR: $!\n\n"; |
45 | | | } |
46 | | | |
47 | | | @order=split(/ /,$ORDER); |
48 | | | |
49 | | | # first add all existing modules in the order they are listed |
50 | | | # in the "ORDER" config-string |
51 | | | # |
52 | | | $subdirs=join(" ",@modules); |
53 | | | foreach $item (@order) { |
54 | | | if (index($subdirs,$item) >=0) { push @ITEMS,$item; } |
55 | | | } |
56 | | | |
57 | | | # then add all not ordered but wanted modules in alphabetical order |
58 | | | # |
59 | | | $subdirs=join(" ",@ITEMS); |
60 | | | foreach $item (@modules) { |
61 | | | if (index($subdirs,$item) <0) { push @ITEMS,$item; } |
62 | | | } |
63 | | | |
64 | | | $MAXLINES=0; |
65 | | | print "generating index-files for each plugin...\n"; |
66 | | | |
67 | | | foreach $modname (sort @ITEMS) { |
68 | | | my $subdir="$DAEMONDIR/modules/$modname"; |
69 | | | print $modname,"\n"; |
70 | | | $count{$modname}=1; |
71 | | | if ( ! -e "$subdir/index" ) { mkdir "$subdir/index",0755; } |
72 | | | if ( -e "$subdir/makeindex.pl") { system("cd \"$subdir\"; ./makeindex.pl >/dev/null"); } |
73 | | | elsif ( -e "$subdir/makeindex") { system("cd \"$subdir\"; ./makeindex >/dev/null"); } |
74 | | | open FILE,"$subdir/idxdata"; |
75 | | | while (<FILE>) { |
76 | | | ($num,$value)=split(/##/,$_); |
77 | | | if ($MAXLINES < $num) { $MAXLINES=$num; } |
78 | | | if ( (defined $value) && ($value ne "") ) { push @{ $lines{$modname} },"$_"; } elsif ($num ne "") { $count{$modname} = $num; } |
79 | | | } |
80 | | | close FILE; |
81 | | | unlink "$subdir/idxdata"; |
82 | | | |
83 | | | # create module-subdir if necessary and copy the module's |
84 | | | # html files there. |
85 | | | # (this may vanish in future because it could also be |
86 | | | # handled by each module itself!) |
87 | | | # |
88 | | | if ( ! -e "$WEBDIR/$modname" ) { |
89 | | | print " creating directory $WEBDIR/$modname\n"; |
90 | | | mkdir "$WEBDIR/$modname",0755 or die "ERROR: $!\n"; |
91 | | | } |
92 | | | print " moving index-files to webdir\n"; |
93 | | | system ("mv -f \"$subdir/index/\"* \"$WEBDIR/$modname/\""); |
94 | | | print "\n"; |
95 | | | } |
96 | | | |
97 | | | print "\nbuilding $WEBDIR/index.html ...\n"; |
98 | | | |
99 | | | if ( ! -e "$WEBDIR/rrdtool.gif" ) { system("cp -f images/rrdtool.gif $WEBDIR"); } |
100 | | | if ( ! -e "$WEBDIR/HotSaNIC.gif" ) { system("cp -f images/HotSaNIC.gif $WEBDIR"); } |
101 | | | |
102 | | | open INDEXFILE,">$WEBDIR/index.html"; |
103 | | | print INDEXFILE "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\"> |
104 | | | <html> |
105 | | | <HEAD> |
106 | | | <META NAME=\"Author\" CONTENT=\"Bernd Pissny\"> |
107 | | | <META NAME=\"GENERATOR\" CONTENT=\"perl-script\"> |
108 | | | <TITLE>System statistics</TITLE> |
109 | | | </HEAD> |
110 | | | <body> |
111 | | | <center> |
112 | | | <table border=0>\n"; |
113 | | | |
114 | | | print "table-size: ",$MAXLINES+1," lines.\n\n"; |
115 | | | print "Modules are added in this order:\n"; |
116 | | | |
117 | | | # scan array from 0 to $MAXLINES to create the table lines. |
118 | | | # if no line was found corrosponding to actual line-number |
119 | | | # then output a table row with no entries |
120 | | | for ($i=0; $i<=$MAXLINES; $i++) { |
121 | | | print INDEXFILE " <tr valign=top>\n"; |
122 | | | foreach $modname (@ITEMS) { |
123 | | | if ($i == 0) { print $modname,"\n"; } |
124 | | | $out=0; |
125 | | | foreach (@{ $lines{$modname} }) { |
126 | | | ($num,$value)=split(/##/); |
127 | | | if ($num == $i) { |
128 | | | if ($CONVERTMETHOD eq "HTML") { |
129 | | | $value=~ s/thumb-//g; |
130 | | | $value=~ s/.gif"/-week.gif" width="$THUMBSIZE"/g; |
131 | | | $value=~ s/.png"/-week.png" width="$THUMBSIZE"/g; |
132 | | | } |
133 | | | print INDEXFILE $value; $out=1; |
134 | | | } |
135 | | | } |
136 | | | if ( $out == 0 ) { for (my $nn=1; $nn<=$count{$modname}; $nn++) { print INDEXFILE " <td></td><td></td>\n"; } } |
137 | | | } |
138 | | | print INDEXFILE " </tr>\n"; |
139 | | | } |
140 | | | print INDEXFILE "</table><br><hr><br> |
141 | | | <a href=\"http://hotsanic.sourceforge.net\"><img src=\"HotSaNIC.gif\" width=97 height=34 alt=\"HotSaNIC\" border=0></a> <a href=\"http://ee-staff.ethz.ch/~oetiker/webtools/rrdtool/\"><img src=\"rrdtool.gif\" width=120 height=34 alt=\"rrdtool\" border=0></a><br> |
142 | | | HTML overview to System and Network Information Center |
143 | | | </center> |
144 | | | </body> |
145 | | | </html>\n"; |
146 | | | |
147 | | | close INDEXFILE; |
148 | | | |
149 | | | print "\ndone.\n\n"; |
150 | | | |