#$Id: AutoIndex.pod,v 1.1.1.1 2003-02-17 14:42:12 gozer Exp $ package Apache::AutoIndex; use strict; use Apache::Constants qw(:common OPT_INDEXES DECLINE_CMD REDIRECT DIR_MAGIC_TYPE); use DynaLoader (); use Apache::Util qw(ht_time size_string); use Apache::ModuleConfig; use Apache::Icon; use Apache::Language; use vars qw ($VERSION); $VERSION="0.08"; #Configuration constants use constant FANCY_INDEXING => 1; use constant ICONS_ARE_LINKS => 2; use constant SCAN_HTML_TITLES => 4; use constant SUPPRESS_LAST_MOD => 8; use constant SUPPRESS_SIZE => 16; use constant SUPPRESS_DESC => 32; use constant SUPPRESS_PREAMBLE => 64; use constant SUPPRESS_COLSORT => 128; use constant THUMBNAILS => 256; use constant SHOW_PERMS => 512; use constant NO_OPTIONS => 1024; use vars qw(%GenericDirectives); %GenericDirectives = ( fancyindexing => FANCY_INDEXING, iconsarelinks => ICONS_ARE_LINKS, scanhtmltitles => SCAN_HTML_TITLES, suppresslastmodified => SUPPRESS_LAST_MOD, suppresssize => SUPPRESS_SIZE, suppressdescription => SUPPRESS_DESC, suppresshtmlperamble => SUPPRESS_PREAMBLE, suppresscolumnsorting => SUPPRESS_COLSORT, thumbnails => THUMBNAILS, showpermissions => SHOW_PERMS, ); #Default values use constant DEFAULT_ICON_WIDTH => 20; use constant DEFAULT_ICON_HEIGHT=> 22; use constant DEFAULT_NAME_WIDTH => 23; use constant DEFAULT_ORDER => "ND"; #Global Options/Congiguration Directives use vars qw($config); $config->{debug}=0; use vars qw(%sortname); %sortname = ( 'N'=>'Name' , 'M'=>'LastModified', 'S'=>'Size', 'D'=>'Description', ); #Statistics variables use vars qw($nDir $nRedir $nIndex $nThumb); $nDir=0; $nRedir=0; $nIndex=0; $nThumb=0; if ($ENV{MOD_PERL}){ no strict; @ISA=qw(DynaLoader); __PACKAGE__->bootstrap($VERSION); if (Apache->module('Apache::Status')){ Apache::Status->menu_item('AutoIndex' => 'Apache::AutoIndex status', \&status); } } sub dir_index { my($r) = @_; my $lang = new Apache::Language ($r); my %args = $r->args; my $name = $r->filename; my $cfg = Apache::ModuleConfig->get($r); my $subr; $r->filename("$name/") unless $name =~ m:/$:; unless (opendir DH, "$name"){ $r->log_reason( __PACKAGE__ . " Can't open directory for index", $r->uri . " (" . $r->filename . ")"); return FORBIDDEN; } $nDir++; if ($cfg->{options} & THUMBNAILS){ use Storable; #should check if Storable loaded ok.. Or is it part of the Perl dist?? $config->{cache_dir} = $r->dir_config("IndexCacheDir") || ".thumbnails"; $config->{dir_create} = $r->dir_config("IndexCreateDir") || 1; my $cachedir = $r->filename . $config->{cache_dir} ; stat $cachedir; $config->{cache_ok} = (-e _ && ( -r _ && -w _)) || ((not -e _) && $config->{dir_create} && mkdir $cachedir, 0755); my $oldopts; if ($config->{cache_ok} && -e "$cachedir/.config" && -r _){ $oldopts = retrieve ("$cachedir/.config"); } $config->{thumb_max_width} = $r->dir_config("ThumbMaxWidth") || DEFAULT_ICON_WIDTH*4; $config->{thumb_max_height} = $r->dir_config("ThumbMaxHeight")|| DEFAULT_ICON_HEIGHT*4; $config->{thumb_max_size} = $r->dir_config("ThumbMaxSize") || 500000; $config->{thumb_min_size} = $r->dir_config("ThumbMinSize") || 5000; $config->{thumb_width} = $r->dir_config("ThumbWidth"); $config->{thumb_height} = $r->dir_config("ThumbHeight"); $config->{thumb_scale_width} = $r->dir_config("ThumbScaleWidth"); $config->{thumb_scale_height} = $r->dir_config("ThumbScaleHeight"); $config->{changed} = 0; foreach (keys %$config){ next unless /^thumb/; if ($config->{$_} != $oldopts->{$_}) { $config->{changed} = 1; last; } } unless ($config->{cache_ok} && ((not -e "$cachedir/.config") || -w _) && store $config, "$cachedir/.config"){ $config->{changed} = 0; }; } print "\n
\nPerms | " ; } foreach ('N', 'M', 'S', 'D'){ next if( $cfg->{options} & SUPPRESS_LAST_MOD && $_ eq 'M'); next if( $cfg->{options} & SUPPRESS_SIZE && $_ eq 'S'); next if( $cfg->{options} & SUPPRESS_DESC && $_ eq 'D'); my $th = ""; $th = " | " if $_ eq 'N'; print $th; if (not $cfg->{options} & SUPPRESS_COLSORT){ if ($args{$_}){ my $query = ($args{$_} eq "D") ? 'A' : 'D'; print "" . $lang->{$sortname{$_}} . ""; } else { print "" . $lang->{$sortname{$_}} . ""; } } else { print $lang->{$sortname{$_}}; } print " | "; } print "||||
---|---|---|---|---|---|---|
" . $list->{$entry}{mode} . " | " if ($cfg->{options} & SHOW_PERMS); #Icon print ""; if ($cfg->{options} & ICONS_ARE_LINKS) { print " | {$entry}{sizenice} eq '-';
print "\">";
}
print " | ";
#Name
print "{$entry}{sizenice} eq '-'; print "\">$label | "; #Last Modified print "$list->{$entry}{modnice} | " unless ( $cfg->{options} & SUPPRESS_LAST_MOD ); #Size print "" . $list->{$entry}{sizenice} . " | " unless ( $cfg->{options} & SUPPRESS_SIZE ); #Description print "". $list->{$entry}{desc} . " | " unless ( $cfg->{options} & SUPPRESS_DESC ); print "
"; print "
\%list
"; print Dumper \%$list; print "
\$cfg
"; print Dumper $cfg; } if ($r->dir_config("IndexHtmlFoot")){ $subr = $r->lookup_uri($r->dir_config("IndexHtmlFoot")); $subr->run; } print "