Apache-AutoIndex

 view release on metacpan or  search on metacpan

AutoIndex.pm  view on Meta::CPAN

 	    
        if (not $cfg->{options} & SUPPRESS_COLSORT){
            if ($args{$_}){
 	            my $query = ($args{$_} eq "D") ? 'A' : 'D';
 	            print "<A HREF=\"?$_=$query\"><I>" . $lang->{$sortname{$_}} . "</I></A>";
            } else {
 	            print "<A HREF=\"?$_=D\">" . $lang->{$sortname{$_}} . "</A>";
 	            }
            }
        else {
            print $lang->{$sortname{$_}};
            }
        print "</TH>";
    }
    print "</TR>";
    
	for my $entry (@$listing) {
	    my $img = $list->{$entry}{icon};
 		my $label = $entry eq '..'  ? $lang->message('Parent') : $entry;

	    print qq{<TR valign="center">};

        #Permissions
        print "<TD>" . $list->{$entry}{mode} . "</TD>" if ($cfg->{options} & SHOW_PERMS);

        #Icon
	    print "<TD>";
        if ($cfg->{options} & ICONS_ARE_LINKS) {
            print "<TD><a href=\"$entry";
	        print "/" if $list->{$entry}{sizenice} eq '-';
	        print "\">";
            }
        print "<img width=\"" . $list->{$entry}{width} . "\" height=\"". $list->{$entry}{height} . "\" src=\"$img\" alt=\"[$list->{$entry}{alt}]\" BORDER=\"0\">";
        print "</A>" if ($cfg->{options} & ICONS_ARE_LINKS);
        print "</TD>";
        
        #Name
        print "<TD><a href=\"$entry";
	    print "/" if $list->{$entry}{sizenice} eq '-';
	    print "\">$label</a></TD>";

        #Last Modified
	    print "<TD>$list->{$entry}{modnice}</TD>" unless ( $cfg->{options} & SUPPRESS_LAST_MOD );

        #Size
	    print "<TD ALIGN=\"center\">" . $list->{$entry}{sizenice} . "</TD>" unless ( $cfg->{options} & SUPPRESS_SIZE );

        #Description
	    print "<TD>". $list->{$entry}{desc} . "</TD>" unless ( $cfg->{options} & SUPPRESS_DESC );

        print "</TR>\n";	  
    }
	
    print "</TABLE>\n";
	
    place_doc($r, $cfg, 'readme');
	
    print " <HR>" . $ENV{'SERVER_SIGNATURE'};
	
    if ($config->{debug}) {
		use Data::Dumper;
		print "<PRE>";
		print "<HR>\%list<BR><BR>";
		print Dumper \%$list;
		print "<HR>\$cfg<BR><BR>";
		print Dumper $cfg;
		}
	
    
    if ($r->dir_config("IndexHtmlFoot")){
        $subr = $r->lookup_uri($r->dir_config("IndexHtmlFoot"));
        $subr->run;
        }
    
    print "</BODY></HTML>";

return OK
}

	
sub read_dir {
    my ($r, $dirhandle) = @_;
    my $cfg = Apache::ModuleConfig->get($r);
    my @listing;
    my %list;
    my @accept;
   
    if($cfg->{options} & THUMBNAILS){
        #Decode the content-encoding accept field of the client
        foreach (split(',\s*',$r->header_in('Accept'))){
           push @accept, $_ if m:^image/:;
           }
        }
	
    while (my $file = readdir $dirhandle) {
		if ($file eq '..')
			{
			push @listing, $file;
			next;
			}
		foreach (@{$cfg->{ignore}}) {
			if ($file =~ m/^$_$/){
				$file = '.';
				last;
				}
			}
		next if $file eq '.';
        	push @listing, $file;
		}
   
	foreach my $file (@listing){
		my $subr = $r->lookup_file($file);
		stat $subr->finfo;
		$list{$file}{size} = -s _;
		if (-d _){
            		$list{$file}{size} = -1;
            		$list{$file}{sizenice} = '-';
		        }
        else {
            $list{$file}{sizenice} = size_string($list{$file}{size});
            $list{$file}{sizenice} =~ s/\s*//;    

AutoIndex.pm  view on Meta::CPAN

	$self->{options} = 0;
	$self->{options_add} = 0;
	$self->{options_del} = 0;
return $self;
}

sub new { 
	return bless {}, shift;
	}

sub DIR_MERGE {
	my ($parent, $current) = @_;
	my %new;
    	$new{options_add} = 0;
    	$new{options_del} = 0;
	$new{icon_height} = $current->{icon_height} ? $current->{icon_height} : $parent->{icon_height};
	$new{icon_width} = $current->{icon_width} ? $current->{icon_width} : $parent->{icon_width};
	$new{name_width} = $current->{name_width} ? $current->{name_width} : $parent->{name_width};
	$new{default_order} = $current->{default_order} ? $current->{default_order} : $parent->{default_order};
	$new{readme} = [ @{$current->{readme}}, @{$parent->{readme}} ];
	$new{header} = [ @{$current->{header}}, @{$parent->{header}} ];
	$new{ignore} = [ @{$current->{ignore}}, @{$parent->{ignore}} ];
	$new{indexfile} = [ @{$current->{indexfile}}, @{$parent->{indexfile}} ];
	
    	$new{desc} = {% {$current->{desc}}};    #Keep descriptions local
	
	if ($current->{options} & NO_OPTIONS){
        	#None override all directives
		$new{options} = NO_OPTIONS;
		}
	else {
		if ($current->{options} == 0) {
            		#Options are all incremental, so combine them with parent's values
			$new{options_add} = ( $parent->{options_add} | $current->{options_add}) & ~$current->{options_del};
			$new{options_del} = ( $parent->{options_del} | $current->{options_del}) ;
			$new{options} = $parent->{options} & ~NO_OPTIONS;
			}
		else {
            		#Options weren't all incremental, so forget about inheritance, simply override
			$new{options} = $current->{options};
			}
		
        	$new{options} |= $new{options_add};
		$new{options} &= ~ $new{options_del};
		}
return bless \%new, ref($parent);
}


sub status {
	my ($r, $q) = @_;
	my @s;
	my $cfg = Apache::ModuleConfig->get($r);
	push (@s, "<B>" , __PACKAGE__ , " (ver $VERSION) statistics</B><BR>");

	push (@s , "Done " . $nDir . " listings so far<BR>");
	push (@s , "Done " . $nRedir . " redirects so far<BR>");
	push (@s , "Done " . $nIndex. " indexes so far<BR>");
    	push (@s , "Done " . $nThumb. " thumbnails so far<BR>");

	use Data::Dumper;
	my $string = Dumper $cfg;
	push (@s, $string);
	
return \@s;
}

1;

__END__

=head1 NAME

Apache::AutoIndex - Perl replacment for mod_autoindex and mod_dir Apache module

=head1 SYNOPSIS

  PerlModule Apache::Icon
  PerlModule Apache::AutoIndex
  (PerlModule Image::Magick) optionnal
  PerlTransHandler Apache::AutoIndex::transhandler
  PerlHandler Apache::AutoIndex

=head1 DESCRIPTION

This module can replace completely mod_dir and mod_autoindex
standard directory handling modules shipped with apache.
It can currently live right on top of those modules, but I suggest
simply making a new httpd without these modules compiled-in.

To start using it on your site right away, simply preload
Apache::Icon and Apache::AutoIndex either with:

  PerlModule Apache::Icon
  PerlModule Apache::AutoIndex

in your httpd.conf file or with:

   use Apache::Icon ();
   use Apache::AutoIndex;
 
in your require.pl file.

Then it's simply adding

    PerlTransHandler Apache::Autoindex::transhandler
    PerlHandler Apache::AutoIndex 

somewhere in your httpd.conf but outside any Location/Directory containers.


=head2 VIRTUAL HOSTS

If used in a server using virtual hosts, since mod_perl doesn't have configuration merging routine for virtual hosts, you'll have to put the PerlHandler and PerlTransHandler directives in each and every <VHOST></VHOST> 
section you wish to use Apache::AutoIndex with.

=head1 DIRECTIVES

It uses all of the Configuration Directives defined by mod_dir and mod_autoindex.  

Since the documentation about all those directives can be found



( run in 1.880 second using v1.01-cache-2.11-cpan-39bf76dae61 )