You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rs...@hyperreal.org on 1999/11/24 14:38:56 UTC

cvs commit: apache-1.3/cgi-bin printenv

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";
   }
   
  
  
  

Re: cvs commit: apache-1.3/cgi-bin printenv

Posted by Ben Laurie <be...@algroup.co.uk>.
Marc Slemko wrote:
> >   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.
> 
> Is it really standard to not display "'s normally, but to stick a \ in
> front of them?  I don't see that much.

Standard or not, if you are going to do it, you really ought to replace
\ with \\, too.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
     - Indira Gandhi

Re: cvs commit: apache-1.3/cgi-bin printenv

Posted by Ben Laurie <be...@algroup.co.uk>.
Marc Slemko wrote:
> >   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.
> 
> Is it really standard to not display "'s normally, but to stick a \ in
> front of them?  I don't see that much.

Standard or not, if you are going to do it, you really ought to replace
\ with \\, too.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
     - Indira Gandhi

Re: cvs commit: apache-1.3/cgi-bin printenv

Posted by Marc Slemko <ma...@znep.com>.
On 24 Nov 1999 rse@hyperreal.org wrote:

>   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 "[...]".

Erm... this makes it less useful.  If there is a long variable, then 
it is saying something and you should see it.  I don't buy that it is 
"destroying the total optical view on the table".  You can make it even
prettier by not displaying more than the first 50 characters, but you lose
even more information.

>   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.

Is it really standard to not display "'s normally, but to stick a \ in
front of them?  I don't see that much.


Re: cvs commit: apache-1.3/cgi-bin printenv

Posted by Marc Slemko <ma...@znep.com>.
On 24 Nov 1999 rse@hyperreal.org wrote:

>   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 "[...]".

Erm... this makes it less useful.  If there is a long variable, then 
it is saying something and you should see it.  I don't buy that it is 
"destroying the total optical view on the table".  You can make it even
prettier by not displaying more than the first 50 characters, but you lose
even more information.

>   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.

Is it really standard to not display "'s normally, but to stick a \ in
front of them?  I don't see that much.