All pastes #1746290 Raw Edit

all in one reporter

public text v1 · immutable
#1746290 ·published 2010-01-11 01:40 UTC
rendered paste body
#!/usr/bin/perl

use CGI;

#change this to the full pathname to the bottom of the dir structure:
my $dir = ".";

print "Content-type: text/html\n\n";
my $cgiin = CGI->new;
my $letter = $cgiin->param('letter');
if ($letter !~ /[\w|\.]/) {
	print "<h2>Please specify a valid letter</h2>";
	die "Invalid letter given";
}

my @errors;
#my $givendir = $ARGV[0];
#if ($givendir eq "") {
	$givendir = ".";
#}
opendir('FLIST', ".");
my @dirs = readdir('FLIST');
closedir('FLIST');
while(@dirs) {
	my $workdir = shift(@dirs);
	while(($workdir eq '.') || ($workdir eq '..')) {
		$workdir = shift(@dirs);
	}
	opendir('CURDIR', "$workdir");
	my @prefilelist = readdir('CURDIR');
	closedir('CURDIR');
	my @filelist;	
	while(@prefilelist) {
		my $workline = shift(@prefilelist);
		if (($workline ne '.') && ($workline ne '..')) {
			push(@filelist, "$workline");
		}
	}
	my $numfiles = @filelist;
	if ($numfiles != 1) {
		push(@errors, "in $workdir: expected 1 file, found $numfiles");
	} else {
		if ($workdir =~ /^($letter)/) {
			print "<a href=\"/cgi-bin/download.pl?filename=$workdir\">$workdir</a><br />\n";
		}
	}
}
#my $numerrors = @errors;
#if ($numerrors != 0) {
#	print "WARNING: $numerrors reported errors:\n";
#}
#while(@errors) {
#	my $errorline = shift(@errors);
#	print "$errorline\n";
#}