Handle hostnames with upper-case letters
[webmin.git] / webalizer / index.cgi.bak
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display available apache or squid logfiles
4
5 require './webalizer-lib.pl';
6
7 # Check if webalizer is actually installed
8 if (!&has_command($config{'webalizer'})) {
9         &header($text{'index_title'}, "", undef, 1, 1, 0,
10                 &help_search_link("webalizer", "man", "doc", "google"));
11         print "<hr>\n";
12         print "<p>",&text('index_ewebalizer', "<tt>$config{'webalizer'}</tt>",
13                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
14         print "<hr>\n";
15         &footer("/", $text{'index'});
16         exit;
17         }
18
19 # Get the version number
20 $out = `$config{'webalizer'} -v 2>&1`;
21 $out =~ /\sV(\S+)/;
22 &header($text{'index_title'}, "", undef, 1, 1, 0,
23         &help_search_link("webalizer", "man", "doc", "google"),
24         undef, undef, &text('index_version', "$1"));
25 print "<hr>\n";
26 if ($1 < 2) {
27         print "<p>",&text('index_eversion', "<tt>$config{'webalizer_conf'}</tt>",
28                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
29         print "<hr>\n";
30         &footer("/", $text{'index'});
31         exit;
32         }
33
34 # Check if the config file exists
35 if (!-r $config{'webalizer_conf'} && -r $config{'alt_conf'}) {
36         # No, but the sample one does
37         system("cp '$config{'alt_conf'}' '$config{'webalizer_conf'}' >/dev/null 2>&1");
38         }
39 if (!-r $config{'webalizer_conf'}) {
40         print "<p>",&text('index_econf', "<tt>$config{'webalizer_conf'}</tt>",
41                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
42         print "<hr>\n";
43         &footer("/", $text{'index'});
44         exit;
45         }
46
47 # Query apache and squid for their logfiles
48 %auto = map { $_, 1 } split(/,/, $config{'auto'});
49 if (&foreign_check("apache") && $auto{'apache'}) {
50         &foreign_require("apache", "apache-lib.pl");
51         $conf = &apache::get_config();
52         @dirs = ( &apache::find_all_directives($conf, "CustomLog"),
53                   &apache::find_all_directives($conf, "TransferLog") );
54         foreach $d (@dirs) {
55                 open(FILE, $d->{'words'}->[0]);
56                 local $line = <FILE>;
57                 close(FILE);
58                 if (!$line || $line =~ /^([0-9\.]+)\s+\S+\s+\S+\s+\[\d+\/[a-zA-z]+\/\d+:\d+:\d+:\d+\s+[0-9\+\-]+\]/) {
59                         push(@logs, { 'file' => $d->{'words'}->[0],
60                                       'type' => 1 });
61                         }
62                 }
63         }
64 if (&foreign_check("squid") && $auto{'squid'}) {
65         &foreign_require("squid", "squid-lib.pl");
66         $conf = &squid::get_config();
67         $log = &squid::find_value("cache_access_log", $conf);
68         $log = "$squid::config{'log_dir'}/access.log"
69                 if (!$log && -d $squid::config{'log_dir'});
70         push(@logs, { 'file' => $log,
71                       'type' => 2 }) if ($log);
72         }
73
74 # Add custom logfiles
75 push(@logs, map { $_->{'custom'} = 1; $_ } &read_custom_logs());
76
77 if (@logs) {
78         print "<a href='edit_log.cgi?new=1'>$text{'index_add'}</a>\n"
79                 if (!$access{'view'});
80         print "<table border width=100%>\n";
81         print "<tr $tb> <td><b>$text{'index_path'}</b></td> ",
82               "<td><b>$text{'index_type'}</b></td> ",
83               "<td><b>$text{'index_size'}</b></td> ",
84               "<td><b>$text{'index_latest'}</b></td> ",
85               "<td><b>$text{'index_sched'}</b></td> ",
86               "<td><b>$text{'index_rep'}</b></td> </tr>\n";
87         foreach $l (@logs) {
88                 next if ($done{$l->{'file'}}++);
89                 next if (!-f $l->{'file'});
90                 local $lconf = &get_log_config($l->{'file'});
91                 print "<tr $cb>\n";
92                 if ($access{'view'}) {
93                         print "<td>$l->{'file'}</td>\n";
94                         }
95                 else {
96                         print "<td><a href='edit_log.cgi?file=",
97                               &urlize($l->{'file'}),
98                               "&type=$l->{'type'}&custom=$l->{'custom'}'>",
99                               "$l->{'file'}</a></td>\n";
100                         }
101                 print "<td>",&text('index_type'.$l->{'type'}),"</td>\n";
102                 local @files = &all_log_files($l->{'file'});
103                 local ($size, $latest);
104                 foreach $f (@files) {
105                         local @st = stat($f);
106                         $size += $st[7];
107                         $latest = $st[9] if ($st[9] > $latest);
108                         }
109                 $latest = $latest ? localtime($latest) : "<br>";
110                 print "<td>",$size > 10*1024*1024 ? int($size/1024/1024)." MB" :
111                              $size > 10*1024 ? int($size/1024)." KB" :
112                              $size ? "$size B" : $text{'index_empty'},"</td>\n";
113                 print "<td>$latest</td>\n";
114                 print "<td>",$lconf->{'sched'} ? $text{'yes'}
115                                                : $text{'no'},"</td>\n";
116                 if ($lconf->{'dir'} && -r "$lconf->{'dir'}/index.html") {
117                         print "<td><a href='view_log.cgi/",
118                               &urlize(&urlize($l->{'file'})),
119                               "/index.html'>$text{'index_view'}</a></td>\n";
120                         }
121                 else {
122                         print "<td><br></td>\n";
123                         }
124                 print "</tr>\n";
125                 }
126         print "</table>\n";
127         }
128 else {
129         print "<p><b>$text{'index_nologs'}</b><p>\n";
130         }
131 print "<a href='edit_log.cgi?new=1'>$text{'index_add'}</a><br>\n"
132         if (!$access{'view'});
133
134 if (!$access{'view'}) {
135         print "<hr>\n";
136         print "<form action=edit_global.cgi>\n";
137         print "<table width=100%><tr>\n";
138         print "<td><input type=submit value='$text{'index_global'}'></td>\n";
139         print "<td>$text{'index_globaldesc'}</td>\n";
140         print "</tr></table></form>\n";
141         }
142
143 print "<hr>\n";
144 &footer("/", $text{'index'});
145