Add support for listing directories if index.html is missing

This commit is contained in:
Jamie Cameron
2009-09-26 14:33:33 -07:00
parent c4cf4355b5
commit 581df3a5ec
3 changed files with 30 additions and 9 deletions
+2
View File
@@ -2,3 +2,5 @@
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.
+5 -3
View File
@@ -44,7 +44,7 @@ $conf = &get_config();
$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();
}
@@ -57,8 +57,10 @@ if ($sfile) {
&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") {
+23 -6
View File
@@ -13,10 +13,16 @@ $odir = &find_value("output_dir", $conf);
$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;
}
@@ -33,12 +39,23 @@ if ($full =~ /\.(html|htm)$/i && !$config{'naked'}) {
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;