First version of this module, which can configure, run and schedule the Sarg Squid log report generation tool. Thanks to Omar Armas for sponsoring the development of this module.
---- Changes since 1.250 ----
Added a Module Config option to prevent the Webmin header and footer from being added when viewing a SARG report.
+---- Changes since 1.490 ----
+SARG reports that use daily subdirectories can now be viewed from within Webmin, even if they are missing an index.html file.
$odir = &find_value("output_dir", $conf);
$odir ||= &find_value("output_dir", $conf, 1);
$sfile = &find_value("access_log", $conf);
-if ($sfile || $odir && -r "$odir/index.html") {
+if ($sfile || $odir && -d $odir) {
print &ui_hr();
print &ui_buttons_start();
}
&gen_range_input());
print "<tr> <td><p></td> </tr>\n";
}
-if ($odir && -r "$odir/index.html") {
- print &ui_buttons_row("view.cgi/index.html", $text{'index_view'},
+if ($odir && -d $odir) {
+ print &ui_buttons_row(-r "$odir/index.html" ? "view.cgi/index.html"
+ : "view.cgi/",
+ $text{'index_view'},
&text('index_viewdesc', "<tt>$odir</tt>"));
}
if ($sfile || $odir && -r "$odir/index.html") {
$odir ||= &find_value("output_dir", $conf, 1);
$odir || &error($text{'view_eodir'});
$full = "$odir$file";
-open(FILE, $full) || &error($text{'view_eopen'}." : $full");
+&is_under_directory($odir, $full) || &error($text{'view_efile'});
+
+# Show index page
+if (-d $full && -r "$full/index.html") {
+ $full = "$full/index.html";
+ }
# Display file contents
if ($full =~ /\.(html|htm)$/i && !$config{'naked'}) {
+ open(FILE, $full) || &error($text{'view_eopen'}." : $full");
while(read(FILE, $buf, 1024)) {
$data .= $buf;
}
print "</div>\n";
&ui_print_footer("", $text{'index_return'});
}
+elsif (-d $full) {
+ # Show directory listing
+ &ui_print_header(undef, $text{'view_title'}, "");
+ print "<ul>\n";
+ opendir(DIR, $full);
+ foreach $f (sort { lc($a) cmp lc($b) } readdir(DIR)) {
+ next if ($f eq "." || $f eq "..");
+ print "<li><a href='$f/'>$f</a>\n";
+ }
+ closedir(DIR);
+ print "</ul>\n";
+ &ui_print_footer("", $text{'index_return'});
+ }
else {
- print "Content-type: ",$full =~ /\.png$/i ? "image/png" :
- $full =~ /\.gif$/i ? "image/gif" :
- $full =~ /\.(jpg|jpeg)$/i ? "image/jpeg" :
- $full =~ /\.(html|htm)$/i ? "text/html" :
- "text/plain","\n";
+ # Show RAW file contents
+ open(FILE, $full) || &error($text{'view_eopen'}." : $full");
+ print "Content-type: ",&guess_mime_type($full, "text/plain"),"\n";
print "\n";
while(read(FILE, $buf, 1024)) {
print $buf;