#!/usr/bin/perl

if ( $ENV{HTTP_HOST} eq 'venus.is-koeln.de' ) {
	$html_path = '/home/httpd/test/cgn/test';
} else {
	$html_path = '/home/wwwadmin/www/pub/mediavision/bilder';
}

$template=$html_path.'/cam.html';

opendir DIR,$html_path or die "Cannot opendir $html_path";
@files=grep !/^\.\.?$/,readdir DIR;
closedir DIR;

foreach $file ( @files ) {
	if ( $file =~ /^pic/ ) {
		$mtime = (stat "$html_path/$file")[9];
		if ( defined $pics{$mtime} ) {
			push(@{$pics{$mtime}},$file);
		} else {
			$pics{$mtime} = [ $file ];
		}
	}
}

$src=${$pics{(reverse sort keys %pics)[0]}}[0];

undef $/;
open TMPL,"<$template";
$tmpl = <TMPL>;
close TMPL;

$tmpl =~ s/\@\@BILD\@\@/$src/;

print "Content-type: text/html\n\n";
print $tmpl;

