home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / cgi-bin / image-push.pl < prev    next >
Perl Script  |  2017-09-21  |  2KB  |  96 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # image-push CGI program.
  4. # written by Andrew Rutherford of Internode Systems <andrewr@internode.com.au>
  5. #
  6.  
  7.  
  8. # where we find local WWW libraries
  9. push(@INC, '/usr/local/etc/httpd/cgi-bin');
  10.  
  11.  
  12. require 'cgi-lib.pl';
  13.  
  14. $| = 1;
  15.  
  16. $prefix = "/web/";
  17. $default_method = "once";
  18.  
  19. $boundary = "NotVeryRandomString$$";
  20. $this_url = $ENV{"SERVER_URL"} . $ENV{"SCRIPT_NAME"};
  21.  
  22. &parse_request ;
  23.  
  24. $method = $query{'Method'};
  25. $file = $query{'File'};
  26.  
  27.  
  28. $method = $default_method if (!defined($method));
  29.  
  30. #open(FILE, $file) || &do_error("Cannot open $file");
  31. open(FILE, $file) || &do_error("Cannot open $file");
  32. $i = 0;
  33. while (<FILE>) {
  34.         chop;
  35.         s/#.*$//g;
  36.         next if /^$/;
  37.         if (/<|>|\.\.|\|/) {
  38.                 &do_error("Invalid file \"$_\"");
  39.         }
  40.         $images[$i++] = $prefix . $_;
  41. }
  42. close(FILE);
  43.  
  44. print "Content-type: multipart/x-mixed-replace;boundary=$boundary\n";
  45.  
  46. $i = 0;
  47. $increment = 1;
  48. while (1) {
  49.         for (; defined($images[$i]); $i += $increment) {
  50.                 print "\n--$boundary\n";
  51.                 if ($images[$i] =~ /\.jpg$|\.jpeg$/) {
  52.                         print "Content-type: image/jpeg\n\n";
  53.                 } else {
  54.                         print "Content-type: image/gif\n\n";
  55.                 }
  56.  
  57.                 open(FILE, $images[$i]);
  58.                 sysread(FILE, $this_image, (stat(FILE))[7]);
  59.                 close(FILE);
  60.  
  61.                 print $this_image;
  62.  
  63.                 sleep(1) if (defined($delay));
  64.         }
  65.         last if ($method eq "once");
  66.         if ($method eq "loop") {
  67.                 $i = 0;
  68.         }
  69.         if ($method eq "sweep") {
  70.                 $increment = - $increment;
  71.                 $i += $increment;
  72.         }
  73. }
  74.  
  75. print "\n--$boundary--\n";
  76. sleep(1);
  77. exit (0);
  78.  
  79. sub do_error {
  80.         print "Content-type: text/html\n\n" .
  81.                 "<title>Error: $_[0]</title>\n".
  82.         #" $query{'Method'} \n " .
  83.         # " $query{'File'} \n " .
  84.                 "<body><h1>Error: $_[0]</h1></body>\n";
  85.         sleep (1);
  86.         exit (0);
  87. }
  88.  
  89.  
  90. # MethGet
  91. # Return true if this cgi call was using the GET request, false otherwise
  92.  
  93. sub MethGet {
  94.   return ($ENV{'REQUEST_METHOD'} eq "GET");
  95. }
  96.