#!/usr/local/bin/perl
# index.cgi
# Display available apache or squid logfiles
require './webalizer-lib.pl';
# Check if webalizer is actually installed
if (!&has_command($config{'webalizer'})) {
&header($text{'index_title'}, "", undef, 1, 1, 0,
&help_search_link("webalizer", "man", "doc", "google"));
print "
\n";
print "",&text('index_ewebalizer', "$config{'webalizer'}",
"$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n";
print "
\n";
&footer("/", $text{'index'});
exit;
}
# Get the version number
$out = `$config{'webalizer'} -v 2>&1`;
$out =~ /\sV(\S+)/;
&header($text{'index_title'}, "", undef, 1, 1, 0,
&help_search_link("webalizer", "man", "doc", "google"),
undef, undef, &text('index_version', "$1"));
print "
\n";
if ($1 < 2) {
print "",&text('index_eversion', "$config{'webalizer_conf'}",
"$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n";
print "
\n";
&footer("/", $text{'index'});
exit;
}
# Check if the config file exists
if (!-r $config{'webalizer_conf'} && -r $config{'alt_conf'}) {
# No, but the sample one does
system("cp '$config{'alt_conf'}' '$config{'webalizer_conf'}' >/dev/null 2>&1");
}
if (!-r $config{'webalizer_conf'}) {
print "",&text('index_econf', "$config{'webalizer_conf'}",
"$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n";
print "
\n";
&footer("/", $text{'index'});
exit;
}
# Query apache and squid for their logfiles
%auto = map { $_, 1 } split(/,/, $config{'auto'});
if (&foreign_check("apache") && $auto{'apache'}) {
&foreign_require("apache", "apache-lib.pl");
$conf = &apache::get_config();
@dirs = ( &apache::find_all_directives($conf, "CustomLog"),
&apache::find_all_directives($conf, "TransferLog") );
foreach $d (@dirs) {
open(FILE, $d->{'words'}->[0]);
local $line = ;
close(FILE);
if (!$line || $line =~ /^([0-9\.]+)\s+\S+\s+\S+\s+\[\d+\/[a-zA-z]+\/\d+:\d+:\d+:\d+\s+[0-9\+\-]+\]/) {
push(@logs, { 'file' => $d->{'words'}->[0],
'type' => 1 });
}
}
}
if (&foreign_check("squid") && $auto{'squid'}) {
&foreign_require("squid", "squid-lib.pl");
$conf = &squid::get_config();
$log = &squid::find_value("cache_access_log", $conf);
$log = "$squid::config{'log_dir'}/access.log"
if (!$log && -d $squid::config{'log_dir'});
push(@logs, { 'file' => $log,
'type' => 2 }) if ($log);
}
# Add custom logfiles
push(@logs, map { $_->{'custom'} = 1; $_ } &read_custom_logs());
if (@logs) {
print "$text{'index_add'}\n"
if (!$access{'view'});
print "\n";
print " | $text{'index_path'} | ",
"$text{'index_type'} | ",
"$text{'index_size'} | ",
"$text{'index_latest'} | ",
"$text{'index_sched'} | ",
"$text{'index_rep'} |
\n";
foreach $l (@logs) {
next if ($done{$l->{'file'}}++);
next if (!-f $l->{'file'});
local $lconf = &get_log_config($l->{'file'});
print "\n";
if ($access{'view'}) {
print "| $l->{'file'} | \n";
}
else {
print "{'type'}&custom=$l->{'custom'}'>",
"$l->{'file'} | \n";
}
print "",&text('index_type'.$l->{'type'})," | \n";
local @files = &all_log_files($l->{'file'});
local ($size, $latest);
foreach $f (@files) {
local @st = stat($f);
$size += $st[7];
$latest = $st[9] if ($st[9] > $latest);
}
$latest = $latest ? localtime($latest) : "
";
print "",$size > 10*1024*1024 ? int($size/1024/1024)." MB" :
$size > 10*1024 ? int($size/1024)." KB" :
$size ? "$size B" : $text{'index_empty'}," | \n";
print "$latest | \n";
print "",$lconf->{'sched'} ? $text{'yes'}
: $text{'no'}," | \n";
if ($lconf->{'dir'} && -r "$lconf->{'dir'}/index.html") {
print "$text{'index_view'} | \n";
}
else {
print "
| \n";
}
print "
\n";
}
print "
\n";
}
else {
print "$text{'index_nologs'}
\n";
}
print "$text{'index_add'}
\n"
if (!$access{'view'});
if (!$access{'view'}) {
print "
\n";
print "\n";
}
print "
\n";
&footer("/", $text{'index'});