-sub cgi_sanity_check {
- my $error = undef;
- foreach (@all_files) {
- if (! -e $_) { $error = "$_ does not exist.\n"; }
- elsif (! -r $_) { $error = "$_ is unreadable.\n"; }
- elsif (! -w $_) { $error = "$_ is unwritable.\n"; }
- last if ($error);
- }
-
- return unless $error;
-
- print "Content-Type: text/html\n";
- print "\n\n<TITLE>Error</TITLE>$body_tag<H1>Error</H1>";
- print POSIX::getcwd() . "/" . $error . "<P>\n";
-
- $_ = join("</TT>, <TT>", @all_files);
- s/,([^,]*)$/, and$1/;
-
- print "Each of the files: <TT>$_</TT>\n";
- print " must exist and be readable and writable by the httpd process\n";
- print "(which probably means they must be globally readable and\n";
- print "writable, since on most systems, CGI scripts run as the\n";
- print "user <I>nobody</I>.)\n<P>\n";
-
- exit (0);
-}
-
-
-# Write the encapsulating HTML document and associated HTTP headers.
-# This is fast -- it just writes out the wrapper document corresponding
-# to the data currently on disk. It is the loading of the sub-image
-# that does the real work.
-#
-sub cgi_emit_html_document {
-
- cgi_sanity_check;
-
- my $map_file_date;
- my $doc = $html_document;
-
- my $w2 = int ($img_width * $scale);
- my $h2 = int ($img_height * $scale);
- $doc =~ s/%%WIDTH%%/$w2/g;
- $doc =~ s/%%HEIGHT%%/$h2/g;
-
- local *MAP;
- open (MAP, "<$map_file") || die "couldn't open $map_file: $!";
- if ($DEBUG > 2) { print STDERR "html: opened $map_file\n"; }
-
- flock (MAP, LOCK_SH) || die "couldn't lock $map_file: $!";
- seek (MAP, 0, 0) || die "couldn't rewind $map_file: $!";
- if ($DEBUG > 2) { print STDERR "html: locked $map_file\n"; }
-
- $map_file_date = (stat(MAP))[9];
-
- my $map = "<MAP NAME=\"collage\">\n";
- while (<MAP>) {
- my ($x, $y, $w, $h, $url) =
- m/^([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) (.*)$/;
- if ($w && $h) {
- $x = int($x * $scale);
- $y = int($y * $scale);
- $w = int($w * $scale);
- $h = int($h * $scale);
-
- # protect against URLs that contain <, >, or ".
- $url =~ s/([<>\"])/uc sprintf("%%%02X",ord($1))/eg;
-
- my $x2 = $x + $w;
- my $y2 = $y + $h;
- $map .=
- "<AREA SHAPE=RECT COORDS=\"$x,$y,$x2,$y2\" HREF=\"$url\">\n";
- }
- }
- $map .= "</MAP>";
- flock (MAP, LOCK_UN) || die "couldn't unlock $map_file: $!";
- close (MAP) || die "couldn't close $map_file: $!";
-
- if ($DEBUG > 2) { print STDERR "html: closed $map_file\n"; }
-
- $doc =~ s/%%MAP%%/$map/g;
-
- my $img_name = "current";
-
- $doc =~ s@%%IMAGE%%@images/$img_name.jpg@g;
-
-
- my $mod_time = $map_file_date;
- if ($script_date > $mod_time) { $mod_time = $script_date; }
-
- if (do_ifmod($mod_time)) {
- return;
- }
-
- my $exp = compute_expires_time($mod_time);
-
- print "Content-Type: text/html\n";
- print "Content-Length: " . length($doc) . "\n";
- print "Last-Modified: " . format_http_time($mod_time) . "\n";
-
- # This is a suggestion to consider the object invalid after the given
- # date. This is sometimes ignored.
- #
- print "Expires: " . format_http_time($exp) . "\n";
-
- # This may or may not cause a cacheing proxy to pass this stuff along.
- # It's not standardized, but was historically used for... something.
- print "Pragma: no-cache\n";
-
- # This says the same thing as the Expires header, but it is a stronger
- # assertion that we're serious and should be listened to.
- #
- my $age = $exp - time;
- print "Cache-Control: max-age=$age, must-revalidate\n";
-
- print "\n";
- print $doc;