#!/usr/bin/perl

print "Content-type: text/html\n\n";
$curdir=`pwd`;
chomp $curdir;
$curdir=~s:^/home/www/html::;
print "<HTML>\n<HEAD><TITLE>Contents of $curdir</TITLE></HEAD>\n";
print "<BODY>";
print "<H1>Contents of $curdir</H1><P>\n\n";

mkdir("thumbs",0755) if(! -e "thumbs");

opendir(DIR,".");

print "<TABLE>\n";

$count = 0;

foreach $n (sort readdir DIR) {
	if ($n=~/jpe?g$/ ||
	    $n=~/JPE?G$/) {
		$command = "djpeg $n | pnmscale -xysize 100 100 | " .
			"cjpeg > thumbs/$n";
	} elsif ($n=~/gif$/ ||
	         $n=~/GIF$/) {
		$command = "giftopnm $n | pnmscale -xysize 100 100 | " .
			"pnmtogif > thumbs/$n";
	} elsif ($n=~/png$/ ||
	         $n=~/PNG$/) {
		$command = "pngtopnm $n | pnmscale -xysize 100 100 | " .
			"pnmtopng > thumbs/$n";
	} else {
		next;
	}

	print "<TR>" if(($count++ % 4) == 0);
	print "<TD><A HREF=\"view.cgi?$n\"><IMG SRC=\"thumbs/$n\"><BR>$n</A>\n";
	
	if ( ! -e "thumbs/$n" ) {
		system $command;
		next;
	}
	
	@ts = stat("thumbs/$n");
	@s = stat($n);
	
	system $command if($ts[9]<$s[9]);
}

print "</TABLE>\n";

closedir DIR;

print "</BODY>\n</HTML>\n";

