#!/usr/bin/perl

$c = 0;

@values = split(/&/,$ENV{'QUERY_STRING'});
foreach $i (@values) {
  ($vn, $d) = split(/=/,$i);

  if ($vn eq "pic") {
    $d =~ /^[[:alnum:]\/_\.]{1,20}$/ or next;
    $c = 1;
    unless ( -e "../images/$d" ) {
      print "Content-type: text/html\n\n";
      print "<HTML><BODY>Image not found.</BODY></HTML>\n";
      last;
    }
    print "Content-type: text/html\n\n";
    print "<HTML><BODY><IMG SRC=\"../images/$d\"></BODY></HTML>\n";
    last;
  }
}

if ( $c == 0 ) {
  print "Content-type: text/html\n\n";
  print "<HTML><BODY>Invalid command.</BODY></HTML>\n";
}