3 # Display available apache or squid logfiles
5 require './webalizer-lib.pl';
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"));
12 print "<p>",&text('index_ewebalizer', "<tt>$config{'webalizer'}</tt>",
13 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
15 &footer("/", $text{'index'});
19 # Get the version number
20 $out = `$config{'webalizer'} -v 2>&1`;
22 &header($text{'index_title'}, "", undef, 1, 1, 0,
23 &help_search_link("webalizer", "man", "doc", "google"),
24 undef, undef, &text('index_version', "$1"));
27 print "<p>",&text('index_eversion', "<tt>$config{'webalizer_conf'}</tt>",
28 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
30 &footer("/", $text{'index'});
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");
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";
43 &footer("/", $text{'index'});
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") );
55 open(FILE, $d->{'words'}->[0]);
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],
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);
75 push(@logs, map { $_->{'custom'} = 1; $_ } &read_custom_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";
88 next if ($done{$l->{'file'}}++);
89 next if (!-f $l->{'file'});
90 local $lconf = &get_log_config($l->{'file'});
92 if ($access{'view'}) {
93 print "<td>$l->{'file'}</td>\n";
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";
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);
107 $latest = $st[9] if ($st[9] > $latest);
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";
122 print "<td><br></td>\n";
129 print "<p><b>$text{'index_nologs'}</b><p>\n";
131 print "<a href='edit_log.cgi?new=1'>$text{'index_add'}</a><br>\n"
132 if (!$access{'view'});
134 if (!$access{'view'}) {
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";
144 &footer("/", $text{'index'});