rse         99/11/24 05:38:56

  Modified:    cgi-bin  printenv
  Log:
  I know we don't want to see any "fancy" things in our printenv (as
  they were already posted by various users over the last years), but
  every time I need to use a little CGI script for testing purposes I get
  annoyed by this really too weak printenv script. Sure, tables and other
  stuff should be not our business, but at least the script should be a
  little bit more robust and useful.
  
  What I disliked most is that I usually have great problems to easily find a
  variable (because the output is not sorted) and that various environment
  values totally destroy the optical view on the table as a whole (mainly too
  large values in $PATH and the nasty contents of SERVER_SIGNATURE). So here is
  my minimal change to at least fix these problems without introducing fancy or
  insecure stuff.  Nevertheless feel free to back it out if you definitely
  dislike any changes to printenv at all.
  
  My changes are:
  
  1. add a comment line to make it clear to the user that this is more or less
     just a silly _demo_ script (for those who don't have Perl as their
     secondary language beside their native language)
  
  2. use content type text/plain instead of text/html to easily avoid printing
     problems with variables like SERVER_SIGNATURE which contains HTML
     code. This way we have to add extra escaping steps and the script
     remains small.
  
  3. sort the variables lexicographically in the output!
  
  4. make sure very large lines (usually from $PATH) do not destroy the
     total optical view on the table by cutting values and replacing
     the missing stuff with "[...]".
  
  5. surround values with quotes to allow one to better recognize newlines (as
     in SERVER_SIGNATURE) and whitespaces and also print newlines
     as \n and " as \" for a more Shell- and C-style syntax.
  
  Revision  Changes    Path
  1.4       +10 -3     apache-1.3/cgi-bin/printenv
  
  Index: printenv
  ===================================================================
  RCS file: /home/cvs/apache-1.3/cgi-bin/printenv,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- printenv  1996/12/09 03:51:57     1.3
  +++ printenv  1999/11/24 13:38:55     1.4
  @@ -1,7 +1,14 @@
   #!/usr/local/bin/perl
  +##
  +##  printenv -- demo CGI program which just prints its environment
  +##
   
  -print "Content-type: text/html\n\n";
  -while (($key, $val) = each %ENV) {
  -     print "$key = $val<BR>\n";
  +print "Content-type: text/plain\n\n";
  +foreach $var (sort(keys(%ENV))) {
  +    $val = $ENV{$var};
  +    $val =~ s|\n|\\n|g;
  +    $val =~ s|"|\\"|g;
  +    $val = substr($val, 0, 100).'[...]' if (length($val) > 100);
  +    print "${var}=\"${val}\"\n";
   }
   
  
  
  

Reply via email to