#!/usr/bin/perl -w
use strict;
use Fcntl ':mode';
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
$| = 1;
my %auth = ('127.0.0.1' => 1,
'24.221.85.168' => 1);
my $root = $ENV{'DOCUMENT_ROOT'};
my $script = $ENV{'SCRIPT_NAME'};
if(not $auth{$ENV{'REMOTE_ADDR'}}) {
print "Content-type: text/html\n\n";
print "Forbidden from $ENV{'REMOTE_ADDR'}";
exit;
}
my $dir = param('d');
if(not defined($dir)) {
die "Undefined directory.";
}
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($dir);
if( -d "$root/$dir") {
chdir($root.$dir);
my @files = `ls -1a`;
print "Content-type: text/html\n\n";
print "<pre>";
my $cnt = 0;
foreach (@files) {
print " <a href=\"$script"."?d=$dir/$_\">$_</a>";
}
print "</pre>";
} else {
print "Location: $dir\n\n";
}