PERL   21

readenv cgi

Guest on 20th June 2022 05:53:48 AM

  1. #!/usr/bin/perl
  2.  
  3. # readenv.cgi -- reads the environment, argv, and stdin
  4.  
  5. # the first line of this script may have to be changed
  6. # if your system's Perl interpreter is not located in /usr/bin/perl
  7.  
  8. # Written by P. Lutus 2/21 lutusp@arachnoid.com
  9.  
  10. print "Content-type:text/html\n\n<HTML><PRE>";
  11.  
  12. print ("Environment Entries:\n"); # there are always some of these!
  13. foreach $n (keys %ENV) {
  14.         print ("\t$n=$ENV{$n}\n");
  15. }
  16.  
  17. if ($ARGV[0]) {
  18.         print ("Command-line Arguments:\n");
  19.         foreach $n (@ARGV) {
  20.                 print ("\t$n\n");
  21.         }
  22. }
  23.  
  24. if($ENV{'CONTENT_LENGTH'}) {
  25.                 if($ENV{'CONTENT_LENGTH'} > 0) {
  26.                         read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  27.                 print ("Stdin Contents:\n");
  28.                 print "\tRaw form: $buffer\n\n";
  29.                 print "\tFormatted:\n\n";
  30.                 @pairs = split(/&/, $buffer);
  31.                 foreach $pair (@pairs) {
  32.                         ($name, $value) = split(/=/, $pair);
  33.                         $name =~ tr/+/ /;
  34.                         $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
  35.                         $name =~ s/~!/ ~!/g; # Stop people from using subshells to execute commands
  36.                         $value =~ tr/+/ /;
  37.                         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
  38.                         $value =~ s/~!/ ~!/g; # Stop people from using subshells to execute commands
  39.                         print "\t\t$name = $value\n";
  40.                 }
  41.         }
  42. }
  43.  
  44. print "</PRE></HTML>"

Raw Paste


Login or Register to edit or fork this paste. It's free.