[17800] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5220 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 4 13:16:15 2001

Date: Thu, 4 Jan 2001 10:15:40 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978632139-v9-i5220@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 4 Jan 2001     Volume: 9 Number: 5220

Today's topics:
    Re: %ENV does not contain some variables? <c_clarkson@hotmail.com>
    Re: %ENV does not contain some variables? <joejava@dragonat.net>
    Re: %ENV does not contain some variables? (Rafael Garcia-Suarez)
    Re: %ENV does not contain some variables? <brondsem@my-deja.com>
    Re: %ENV does not contain some variables? <nospam@nospam.com>
    Re: %ENV does not contain some variables? <iltzu@sci.invalid>
    Re: %ENV does not contain some variables? <c_clarkson@hotmail.com>
    Re: %ENV does not contain some variables? <brondsem@my-deja.com>
    Re: %ENV does not contain some variables? <brondsem@my-deja.com>
    Re: %ENV does not contain some variables? <nospam@nospam.com>
    Re: %ENV does not contain some variables? <iltzu@sci.invalid>
        '/usr/sbin/sendmail' <mkupfer@hotmail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 2 Jan 2001 07:28:30 -0600
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: %ENV does not contain some variables?
Message-Id: <B8455FC436F3B63E.8B7209C55EEF096C.1A00DA151B7EB27F@lp.airnews.net>


"Dave Brondsema" <brondsem@my-deja.com> wrote in message
news:911g2j$cqf$1@nnrp1.deja.com...
: In article <3A3427B9.BC74D75D@acm.org>,
:   "John W. Krahn" <krahnj@acm.org> wrote:
: > First off, I searched through the FAQs and perldoc. Here it is in
a
: > nutshell:
: >
: > $ echo "Columns = $COLUMNS    Lines = $LINES "
: > Columns = 130    Lines = 43
: > $ perl -e 'print "Columns = $ENV{COLUMNS}    Lines = $ENV{LINES}
\n";'
: > Columns =     Lines =
: >
: > Why aren't these variables showing up in %ENV?
: >
: > John
: >
:
: Dave Brondsema wrote:
:
: I don't know if this is related, but as CGI program, the following
: doesn't print all environment variables:
:
: foreach $key (sort(keys %ENV)) {
:     print "$key = $ENV{$key}<br>\n";
: }
:
: In particular, the following must be printed seperately because they
: aren't printed in the above loop:
:
: print "<hr>SCRIPT_NAME: $ENV{SCRIPT_NAME}<br>\n";
    [snip]
: print "SERVER_SOFTWARE: $ENV{SERVER_SOFTWARE}<br>\n";
:
:
: Why doesn't the loop print *ALL* the hash keys and values?

Was $key was already used before this call?
    If it was tied to a class it can yield odd results in a foreach.

Try:
    foreach (sort (keys %ENV)) {
      print "$_ = $ENV{$_}<br>\n";
    }

or just:
    print "$_ = $ENV{$_}<BR>\n" foreach sort keys %ENV;


If that works $key was probably tied before the loop.

HTH,
Charles K. Clarkson








------------------------------

Date: Tue, 2 Jan 2001 11:25:54 -0500
From: "Joel Ricker" <joejava@dragonat.net>
Subject: Re: %ENV does not contain some variables?
Message-Id: <Hkn46.2817$of7.96812@news1.atl>


Charles K. Clarkson wrote in message ...
>
>"Dave Brondsema" <brondsem@my-deja.com> wrote in message
>news:911g2j$cqf$1@nnrp1.deja.com...
>: In article <3A3427B9.BC74D75D@acm.org>,
>:   "John W. Krahn" <krahnj@acm.org> wrote:
[* Snip *]

Here is the program that appears in CGI Programming With Perl 2.0 from
O'Reilly that prints out the %ENV variable into a nice formatted table plus
pointing out extra variables supplied by the server:

#!/usr/local/bin/perl -w

use strict;

use CGI::Carp qw(fatalsToBrowser );
my %env_info = (
  SERVER_SOFTWARE => "the server software",
  SERVER_NAME => "the server hostname or IP address",
  GATEWAY_INTERFACE => "the CGI specification revision",
  SERVER_PROTOCOL => "the server protocol name",
  SERVER_PORT => "the port number for the server",
  REQUEST_METHOD => "the HHTTP request method",
  PATH_INFO => "the extra path info",
  PATH_TRANSLATED => "the extra path info translated",
  DOCUMENT_ROOT => "the server document root directory",
  SCRIPT_NAME => "the script name",
  QUERY_STRING => "the query string",
  REMOTE_HOST => "the hostname of the client",
  REMOTE_ADDR => "the IP address of the client",
  AUTH_TYPE => "the authentication method",
  REMOTE_USER => "the authenticated user",
  REMOTE_IDENT => "the remote user is (RFC 931): ",
  CONTENT_TYPE => "the media type of the data",
  CONTENT_LENGTH => "the length of the request body",
  HTTP_ACCEPT => "the media types the client accepts",
  HTTP_USER_AGENT => "the browser the client is using",
  HTTP_REFERER => "the URL of the referring page",
  HTTP_COOKIE => "the cookie(s) the client sent"
);

print <<END_OF_HEADING;

<HTML>
<HEAD>
  <TITLE>A List of Environment Variables</TITLE>
</HEAD>

<BODY>
<H1> CGI ENVIRONMENT VARIABLES </H1>

<TABLE BORDER=1>
  <TR>
    <TH>Variable Name</TH>
    <TH>Description</TH>
    <TH>Value</TH>
  </TR>

END_OF_HEADING

my $name;

foreach $name ( keys %ENV ) {
  $env_info{$name} = "an extra variable provided by this server"
    unless exists $env_info{$name};
}

foreach $name ( sort keys %env_info ) {
  my $info = $env_info{$name};
  my $value = $ENV{$name} || "<I>Not Defined</I>";
  print "<TR><TD><B>$name</B></TD><TD>$info</TD><TD>$value</TD</TR>\n";
}

print "</TABLE>\n";
print "</BODY></HTML>\n";

 .Joel





------------------------------

Date: Tue, 02 Jan 2001 16:56:53 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: %ENV does not contain some variables?
Message-Id: <slrn95422n.6bh.rgarciasuarez@rafael.kazibao.net>

Joel Ricker wrote in comp.lang.perl.misc:
> 
> Here is the program that appears in CGI Programming With Perl 2.0 from
> O'Reilly that prints out the %ENV variable into a nice formatted table plus
> pointing out extra variables supplied by the server:

[...snip code...]

>   my $value = $ENV{$name} || "<I>Not Defined</I>";
>   print "<TR><TD><B>$name</B></TD><TD>$info</TD><TD>$value</TD</TR>\n";

And this code will produce strange results if some of the environment
variables contain characters like <, > or & (such as the
SERVER_SIGNATURE variable provided by apache). Using HTML::Entities
would have been a good idea.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


------------------------------

Date: Wed, 03 Jan 2001 00:06:53 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: %ENV does not contain some variables?
Message-Id: <92tqeo$rqn$1@nnrp1.deja.com>

In article
<B8455FC436F3B63E.8B7209C55EEF096C.1A00DA151B7EB27F@lp.airnews.net>,
  "Charles K. Clarkson" <c_clarkson@hotmail.com> wrote:
>
> "Dave Brondsema" <brondsem@my-deja.com> wrote in message
> news:911g2j$cqf$1@nnrp1.deja.com...
> : In article <3A3427B9.BC74D75D@acm.org>,
> :   "John W. Krahn" <krahnj@acm.org> wrote:
> : > First off, I searched through the FAQs and perldoc. Here it is in
> a
> : > nutshell:
> : >
> : > $ echo "Columns = $COLUMNS    Lines = $LINES "
> : > Columns = 130    Lines = 43
> : > $ perl -e 'print "Columns = $ENV{COLUMNS}    Lines = $ENV{LINES}
> \n";'
> : > Columns =     Lines =
> : >
> : > Why aren't these variables showing up in %ENV?
> : >
> : > John
> : >
> :
> : Dave Brondsema wrote:
> :
> : I don't know if this is related, but as CGI program, the following
> : doesn't print all environment variables:
> :
> : foreach $key (sort(keys %ENV)) {
> :     print "$key = $ENV{$key}<br>\n";
> : }
> :
> : In particular, the following must be printed seperately because they
> : aren't printed in the above loop:
> :
> : print "<hr>SCRIPT_NAME: $ENV{SCRIPT_NAME}<br>\n";
>     [snip]
> : print "SERVER_SOFTWARE: $ENV{SERVER_SOFTWARE}<br>\n";
> :
> :
> : Why doesn't the loop print *ALL* the hash keys and values?
>
> Was $key was already used before this call?
>     If it was tied to a class it can yield odd results in a foreach.
>
> Try:
>     foreach (sort (keys %ENV)) {
>       print "$_ = $ENV{$_}<br>\n";
>     }
>
> or just:
>     print "$_ = $ENV{$_}<BR>\n" foreach sort keys %ENV;
>
> If that works $key was probably tied before the loop.

No, $key was not used before.

I'm not familiar with tie'ing a var.  Could it be that %ENV is tied?

>
> HTH,
> Charles K. Clarkson
>
>

--
Dave Brondsema


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: 3 Jan 2001 08:35:17 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: %ENV does not contain some variables?
Message-Id: <92uo85$763$0@216.155.33.98>

In article <Hkn46.2817$of7.96812@news1.atl>, "Joel Ricker" 
<joejava@dragonat.net> wrote:

 | Charles K. Clarkson wrote in message ...
 | >
 | >"Dave Brondsema" <brondsem@my-deja.com> wrote in message
 | >news:911g2j$cqf$1@nnrp1.deja.com...
 | >: In article <3A3427B9.BC74D75D@acm.org>,
 | >:   "John W. Krahn" <krahnj@acm.org> wrote:
 | [* Snip *]
 | 
 | Here is the program that appears in CGI Programming With Perl 2.0 
 | from O'Reilly that prints out the %ENV variable into a nice 
 | formatted table plus pointing out extra variables supplied by the 
 | server:

[snip]

I was bored. *shrug* see comments. (plus I could use the practice ;)

NEW and IMPROVED

#!/usr/bin/perl -w
use strict;

# Yet another cute little Environment Info script 
# originally from CGI Programming With Perl 2.0 (O'Reilly)
# modified 01-03-2001 by Scott R. Godin in a twitchy fit of late night 
# coffee-induced insanity. i.e. the urge to hack the silly thing 
# into something nicer looking[1] was irresistable. :-)

# [1] code-wise AND output-wise ;)

# what? a CGI that doesn't "use CGI;" ? you gotta be kidding!
# let's fix that :-)
use CGI 2.66 qw(:standard :html3); # needs CGI.pm 2.66 or later

# let's also make sure you can see the error messages if there are any. 
use CGI::Carp qw(fatalsToBrowser set_message); 
    BEGIN {
       sub handle_errors {
          my $msg = shift;
          print header, start_html("CGI/Perl Script Error");
          print h2("aCk!");
          # don't forget to plug in your e-mail address info here
          print p("Whoops, that won't work...  E-mail me, ", a( 
{href=>"mailto:your\@e-mail.com"}, "yourname"), ", about this if it 
persists."), hr;
          print p("Got an error:" . br() . "$msg"), end_html;
      }
      # now you have a nice error handler that shows you YOUR e-mail
      # address and not the server admin, along with sending YOU the 
      # error message instead of dumping it to the server log...
      # GREAT for debugging purposes. 
      set_message(\&handle_errors);
    }

my %env_info = (
  SERVER_SOFTWARE => "the server software",
  SERVER_NAME => "the server hostname or IP address",
  GATEWAY_INTERFACE => "the CGI specification revision",
  SERVER_PROTOCOL => "the server protocol name",
  SERVER_PORT => "the port number for the server",
  REQUEST_METHOD => "the HHTTP request method",
  PATH_INFO => "the extra path info",
  PATH_TRANSLATED => "the extra path info translated",
  DOCUMENT_ROOT => "the server document root directory",
  SCRIPT_NAME => "the script name",
  QUERY_STRING => "the query string",
  REMOTE_HOST => "the hostname of the client",
  REMOTE_ADDR => "the IP address of the client",
  AUTH_TYPE => "the authentication method",
  REMOTE_USER => "the authenticated user",
  REMOTE_IDENT => "the remote user is (RFC 931): ",
  CONTENT_TYPE => "the media type of the data",
  CONTENT_LENGTH => "the length of the request body",
  HTTP_ACCEPT => "the media types the client accepts",
  HTTP_USER_AGENT => "the browser the client is using",
  HTTP_REFERER => "the URL of the referring page",
  HTTP_COOKIE => "the cookie(s) the client sent"
);

# made this a sub so that it would concatenate properly within the 
# multi-nesting capability available to CGI.pm :-)
sub generate_shrubbery () {
    my $shrub;
    foreach my $name ( keys %ENV ) {
      $env_info{$name} = "an extra variable provided by this server"
        unless exists $env_info{$name};
    }

    foreach my $name ( sort keys %env_info ) {
        my $info = $env_info{$name};
        my $value = $ENV{$name} || i('Not Defined');
        $return .= Tr( td({bgcolor => '#CCCC99'}, b($name) ) . 
                       td({bgcolor => 'silver'}, $info )     .
                       td({bgcolor => '#CCCCFF'}, $value )
                     );
    }
    return $shrub;
}

print header, start_html("A list of your CGI Environment Variables");

# It doesn't get much slicker than this: 
# I forget who showed me how to properly concatenate Tr() sets
# but this wouldn't work without the .'s 

# "One that looks nice" "and not too expensive"
print div({'align' => 'center'}, 
          table({border => 1, cellpadding => 5}, 
              Tr( th({colspan => 3, bgcolor => '#FFCC99'}, 
                  "CGI Environment Variables" )
                ) .
              Tr( th('Variable Name') .
                  th('Description')   .
                  th('Value') 
                ) .
              generate_shrubbery()
           ) 
       );
print end_html;

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


------------------------------

Date: 3 Jan 2001 14:26:44 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: %ENV does not contain some variables?
Message-Id: <978531381.8461@itz.pp.sci.fi>

In article <92uo85$763$0@216.155.33.98>, The WebDragon wrote:
>
>I was bored. *shrug* see comments. (plus I could use the practice ;)
>NEW and IMPROVED
>
 [snip]
>        my $value = $ENV{$name} || i('Not Defined');
>        $return .= Tr( td({bgcolor => '#CCCC99'}, b($name) ) . 
>                       td({bgcolor => 'silver'}, $info )     .
>                       td({bgcolor => '#CCCCFF'}, $value )
>                     );

But plenty of room for improvement still, it seems.  Here's my
version, which fixes the escaping problem above:


#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard escapeHTML);

#
# Read descriptions:
#
my %fields = map +($_ => /^HTTP_/ ? "(HTTP header)" : "(extra)"), keys %ENV;
while (<DATA>) {
    last unless my ($key, $val) = /(\S+)\s+(.*)/;
    $fields{$key} = $val;
}

#
# Map environment to HTML table rows:
#
my @env;
for (sort keys %fields) {
    my $name = escapeHTML $_;
    my $desc = escapeHTML $fields{$_};
    my $value = (!exists  $ENV{$_} ? b(i("NOT AVAILABLE")) :
                 !defined $ENV{$_} ? b(i("UNDEFINED")) :
                 !length  $ENV{$_} ? b(i("EMPTY")) :
                 escapeHTML $ENV{$_});

    push @env, Tr( td({bgcolor => '#CCCC99'}, b($name)),
                   td({bgcolor => 'silver' }, $desc),
                   td({bgcolor => '#CCCCFF'}, $value),
                 );
}

#
# Print HTML page:
#
print( header(),
       start_html("A list of your CGI environment variables"),
       div({align => 'center'},
           table({border => 1, cellpadding => 5},
                 Tr( th({colspan => 3, bgcolor => '#FFCC99'},
                        "CGI Environment Variables" ),
                   ),
                 Tr( th('Variable Name'),
                     th('Description'),
                     th('Value'),
                   ),
                 @env,
                )
          ),
       end_html(),
     );

__DATA__
SERVER_SOFTWARE	server software
SERVER_NAME	server hostname or IP address
GATEWAY_INTERFACE	CGI specification revision
SERVER_PROTOCOL	server protocol name
SERVER_PORT	port number for server
REQUEST_METHOD	HTTP request method
PATH_INFO	extra path info
PATH_TRANSLATED	extra path info translated
DOCUMENT_ROOT	server document root directory
SCRIPT_NAME	script name
QUERY_STRING	query string
REMOTE_HOST	hostname of client
REMOTE_ADDR	IP address of client
AUTH_TYPE	authentication method
REMOTE_USER	authenticated user
REMOTE_IDENT	remote user (RFC 931) 
CONTENT_TYPE	media type of data
CONTENT_LENGTH	length of request body
HTTP_ACCEPT	media types client accepts
HTTP_USER_AGENT	browser client is using
HTTP_REFERER	URL of referring page
HTTP_COOKIE	cookie(s) client sent

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post
 something, we discuss its implications.  If the discussion happens to
 answer a question you've asked, that's incidental." -- nobull in clpm



------------------------------

Date: Wed, 3 Jan 2001 03:26:28 -0600
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: %ENV does not contain some variables?
Message-Id: <3EF486EBEA730F49.49D450CA6D5095FC.BED2750FFDB4C8B1@lp.airnews.net>


"Dave Brondsema" <brondsem@my-deja.com> wrote in message
news:92tqeo$rqn$1@nnrp1.deja.com...
: In article
: <B8455FC436F3B63E.8B7209C55EEF096C.1A00DA151B7EB27F@lp.airnews.net>,
:   "Charles K. Clarkson" <c_clarkson@hotmail.com> wrote:
: >
: > "Dave Brondsema" <brondsem@my-deja.com> wrote in message
: > news:911g2j$cqf$1@nnrp1.deja.com...
: > : In article <3A3427B9.BC74D75D@acm.org>,
: > :   "John W. Krahn" <krahnj@acm.org> wrote:
: > : > First off, I searched through the FAQs and perldoc. Here it is
in
: > a
: > : > nutshell:
: > : >
: > : > $ echo "Columns = $COLUMNS    Lines = $LINES "
: > : > Columns = 130    Lines = 43
: > : > $ perl -e 'print "Columns = $ENV{COLUMNS}    Lines =
$ENV{LINES}
: > \n";'
: > : > Columns =     Lines =
: > : >
: > : > Why aren't these variables showing up in %ENV?
: > : >
: > : > John
: > : >
: > :
: > : Dave Brondsema wrote:
: > :
: > : I don't know if this is related, but as CGI program, the
following
: > : doesn't print all environment variables:
: > :
: > : foreach $key (sort(keys %ENV)) {
: > :     print "$key = $ENV{$key}<br>\n";
: > : }
: > :
: > : In particular, the following must be printed seperately because
they
: > : aren't printed in the above loop:
: > :
: > : print "<hr>SCRIPT_NAME: $ENV{SCRIPT_NAME}<br>\n";
: >     [snip]
: > : print "SERVER_SOFTWARE: $ENV{SERVER_SOFTWARE}<br>\n";
: > :
: > :
: > : Why doesn't the loop print *ALL* the hash keys and values?
: >
: > Was $key was already used before this call?
: >     If it was tied to a class it can yield odd results in a
foreach.
: >
: > Try:
: >     foreach (sort (keys %ENV)) {
: >       print "$_ = $ENV{$_}<br>\n";
: >     }
: >
: > or just:
: >     print "$_ = $ENV{$_}<BR>\n" foreach sort keys %ENV;
: >
: > If that works $key was probably tied before the loop.
:
: No, $key was not used before.
:
: I'm not familiar with tie'ing a var.  Could it be that %ENV is tied?
:

   Sorry Dave, I'm stumped, I tried to break this
code on my server and just couldn't do it. What
modules are you using (use, require) at the
beginning of your program? What system are
you running on? Which Perl version are you
using?

Charles







------------------------------

Date: Thu, 04 Jan 2001 02:01:53 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: %ENV does not contain some variables?
Message-Id: <930lie$7sb$1@nnrp1.deja.com>

In article
<3EF486EBEA730F49.49D450CA6D5095FC.BED2750FFDB4C8B1@lp.airnews.net>,
  "Charles K. Clarkson" <c_clarkson@hotmail.com> wrote:

>    Sorry Dave, I'm stumped, I tried to break this
> code on my server and just couldn't do it. What
> modules are you using (use, require) at the
> beginning of your program? What system are
> you running on? Which Perl version are you
> using?
>
> Charles
>

The server has perl 5.006 installed, using Microsoft-IIS/4.0

Here's the full code, verbatim from the file:

#!/usr/bin/perl
print "Content-type:text/html\n\n";

print "<html><head><title>Print Environment</title></head>
<body>";

foreach $key (sort(keys %ENV)) {
    print "$key = $ENV{$key}<br>\n";
}

print "<hr>SCRIPT_NAME: $ENV{SCRIPT_NAME}<br>\n";
print "DOCUMENT_ROOT: $ENV{DOCUMENT_ROOT}<br>\n";
print "HTTP_COOKIE: $ENV{HTTP_COOKIE}<br>\n";
print "HTTP_HOST: $ENV{HTTP_HOST}<br>\n";
print "HTTP_REFERER: $ENV{HTTP_REFERER}<br>\n";
print "HTTP_USER_AGENT: $ENV{HTTP_USER_AGENT}<br>\n";
print "QUERY_STRING: $ENV{QUERY_STRING}<br>\n";
print "REMOTE_ADDR: $ENV{REMOTE_ADDR}<br>\n";
print "REMOTE_HOST: $ENV{REMOTE_HOST}<br>\n";
print "REMOTE_PORT: $ENV{REMOTE_PORT}<br>\n";
print "REMOTE_USER: $ENV{REMOTE_USER}<br>\n";
print "REQUEST_METHOD: $ENV{REQUEST_METHOD}<br>\n";
print "SERVER_ADMIN: $ENV{SERVER_ADMIN}<br>\n";
print "SERVER_NAME: $ENV{SERVER_NAME}<br>\n";
print "SERVER_PORT: $ENV{SERVER_PORT}<br>\n";
print "SERVER_SOFTWARE: $ENV{SERVER_SOFTWARE}<br>\n";

print "REMOTE_HOST: ";
$nslookup = `nslookup $ENV{REMOTE_ADDR}`;
foreach (split(/\n/,$nslookup))
{
	$i++;
	if ($i == 4)
	{
		($name,$val) = split(/ /,$_,2);
		print $val;
	}
}

print "<hr>Cookies:<br>";

@pairs = split(/; /, $ENV{'HTTP_COOKIE'});
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    print "$name = $value<br>";
}

print "</body></html>";




--
Dave Brondsema


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: Thu, 04 Jan 2001 02:06:48 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: %ENV does not contain some variables?
Message-Id: <930lrl$87f$1@nnrp1.deja.com>

In article <930lie$7sb$1@nnrp1.deja.com>,
  Dave Brondsema <brondsem@my-deja.com> wrote:
> In article
> <3EF486EBEA730F49.49D450CA6D5095FC.BED2750FFDB4C8B1@lp.airnews.net>,
>   "Charles K. Clarkson" <c_clarkson@hotmail.com> wrote:
>
> >    Sorry Dave, I'm stumped, I tried to break this
> > code on my server and just couldn't do it. What
> > modules are you using (use, require) at the
> > beginning of your program? What system are
> > you running on? Which Perl version are you
> > using?
> >
> > Charles
> >
>
> The server has perl 5.006 installed, using Microsoft-IIS/4.0
>
> Here's the full code, verbatim from the file:

[snip]

And I forgot, here's the output...

<html><head><title>Print Environment</title></head>
<body>COMPUTERNAME = MPS-WB-01<br>
COMSPEC = C:\WINNT\system32\cmd.exe<br>
INCLUDE = C:\Program Files\Mts\Include<br>
LIB = C:\Program Files\Mts\Lib<br>
NUMBER_OF_PROCESSORS = 1<br>
OS = Windows_NT<br>
OS2LIBPATH = C:\WINNT\system32\os2\dll;<br>
PATH = C:\perl\bin\;C:\WINNT\system32;C:\WINNT;C:\Program Files\Mts<br>
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH<br>
PROCESSOR_ARCHITECTURE = x86<br>
PROCESSOR_IDENTIFIER = x86 Family 6 Model 1 Stepping 7, GenuineIntel<br>
PROCESSOR_LEVEL = 6<br>
PROCESSOR_REVISION = 0107<br>
SYSTEMDRIVE = C:<br>
SYSTEMROOT = C:\WINNT<br>
USERPROFILE = C:\WINNT\Profiles\Default User<br>
WINDIR = C:\WINNT<br>
<hr>SCRIPT_NAME: /cgi-bin/env_vars.pl<br>
DOCUMENT_ROOT: <br>
HTTP_COOKIE: acceptcookies=yes; user_id=4<br>
HTTP_HOST: www.foo.bar.com<br>
HTTP_REFERER: <br>
HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)<br>
QUERY_STRING: <br>
REMOTE_ADDR: xxx.xxx.xxx.xxx<br>
REMOTE_HOST: xxx.xxx.xxx.xxx<br>
REMOTE_PORT: 3192<br>
REMOTE_USER: <br>
REQUEST_METHOD: GET<br>
SERVER_ADMIN: <br>
SERVER_NAME: www.foo.bar.com<br>
SERVER_PORT: 80<br>
SERVER_SOFTWARE: Microsoft-IIS/4.0<br>
REMOTE_HOST:    keeping.my.privacy.com<hr>Cookies:<br>acceptcookies =
yes<br>user_id = 4<br></body></html>

--
Dave Brondsema


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: 4 Jan 2001 03:55:29 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: %ENV does not contain some variables?
Message-Id: <930s7h$bv7$0@216.155.32.33>

In article <978531381.8461@itz.pp.sci.fi>, Ilmari Karonen 
<usenet11325@itz.pp.sci.fi> wrote:

 | In article <92uo85$763$0@216.155.33.98>, The WebDragon wrote:
 | >
 | >I was bored. *shrug* see comments. (plus I could use the practice ;)
 | >NEW and IMPROVED
 | >
 |  [snip]
 | >        my $value = $ENV{$name} || i('Not Defined');
 | >        $return .= Tr( td({bgcolor => '#CCCC99'}, b($name) ) . 
 | >                       td({bgcolor => 'silver'}, $info )     .
 | >                       td({bgcolor => '#CCCCFF'}, $value )
 | >                     );

 | But plenty of room for improvement still, it seems.  Here's my
 | version, which fixes the escaping problem above:

You lost me about the 'escaping' problem -- As near as I can tell, 
there's no info that needed to be escaped anywhere in that as both 
scripts validated perfectly. 

 | #!/usr/bin/perl -w
 | use strict;
 | use CGI::Carp qw(fatalsToBrowser);
 | use CGI qw(:standard escapeHTML);
 | 
 | #
 | # Read descriptions:
 | #
 | my %fields = map +($_ => /^HTTP_/ ? "(HTTP header)" : "(extra)"), keys 
 | %ENV;
 | while (<DATA>) {
 |     last unless my ($key, $val) = /(\S+)\s+(.*)/;
 |     $fields{$key} = $val;
 | }

neat trick. :)

 | #
 | # Map environment to HTML table rows:
 | #
 | my @env;
 | for (sort keys %fields) {
 |     my $name = escapeHTML $_;
 |     my $desc = escapeHTML $fields{$_};
 |     my $value = (!exists  $ENV{$_} ? b(i("NOT AVAILABLE")) :
 |                  !defined $ENV{$_} ? b(i("UNDEFINED")) :
 |                  !length  $ENV{$_} ? b(i("EMPTY")) :
 |                  escapeHTML $ENV{$_});

also a neat trick. :)

 |     push @env, Tr( td({bgcolor => '#CCCC99'}, b($name)),
 |                    td({bgcolor => 'silver' }, $desc),
 |                    td({bgcolor => '#CCCCFF'}, $value),
 |                  );
 | }
 | 
 | #
 | # Print HTML page:
 | #
 | print( header(),
 |        start_html("A list of your CGI environment variables"),
 |        div({align => 'center'},
 |            table({border => 1, cellpadding => 5},
 |                  Tr( th({colspan => 3, bgcolor => '#FFCC99'},
 |                         "CGI Environment Variables" ),
 |                    ),
 |                  Tr( th('Variable Name'),
 |                      th('Description'),
 |                      th('Value'),
 |                    ),
 |                  @env,
 |                 )
 |           ),
 |        end_html(),
 |      );

It was my understanding that the "." concatenate was a better choice to 
make than "," when joining the sections, but I cannot argue with the 
success of the above :)

Both scripts produced 100% accurate and validatable "HTML 4.01 
Transitional" code, so I'm not 100% sure why you made the change to the 
subroutine usage and used an array instead. 

Can you elucidate?

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


------------------------------

Date: 4 Jan 2001 10:50:17 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: %ENV does not contain some variables?
Message-Id: <978605000.25617@itz.pp.sci.fi>

In article <930s7h$bv7$0@216.155.32.33>, The WebDragon wrote:
>In article <978531381.8461@itz.pp.sci.fi>, Ilmari Karonen 
><usenet11325@itz.pp.sci.fi> wrote:
> | In article <92uo85$763$0@216.155.33.98>, The WebDragon wrote:
> | >
> | >        my $value = $ENV{$name} || i('Not Defined');
> | >        $return .= Tr( td({bgcolor => '#CCCC99'}, b($name) ) . 
> | >                       td({bgcolor => 'silver'}, $info )     .
> | >                       td({bgcolor => '#CCCCFF'}, $value )
> | >                     );
>
> | But plenty of room for improvement still, it seems.  Here's my
> | version, which fixes the escaping problem above:
>
>You lost me about the 'escaping' problem -- As near as I can tell, 
>there's no info that needed to be escaped anywhere in that as both 
>scripts validated perfectly. 

Well, there were really two problems.  One was the use of ||, which
would consider the value "0" false and replace it with "Not Defined".

The second problem was the lack of escapeHTML(), causing the code to
let any < or & characters in the values through as is.

Obviously, both would only happen for some ENV values, so testing the
script with other values won't help in noticing the bug.


>Both scripts produced 100% accurate and validatable "HTML 4.01 
>Transitional" code, so I'm not 100% sure why you made the change to the 
>subroutine usage and used an array instead. 

Oh, that.  That was just personal preference.  Should work either way.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post
 something, we discuss its implications.  If the discussion happens to
 answer a question you've asked, that's incidental." -- nobull in clpm



------------------------------

Date: Thu, 4 Jan 2001 13:25:23 +0100
From: "Michel" <mkupfer@hotmail.com>
Subject: '/usr/sbin/sendmail'
Message-Id: <931q4b$768$1@news1.sunrise.ch>

Hello,

I have a script in CGI with : '/usr/sbin/sendmail'
I want use it with Windows NT and the fonction is 'blat.exe'

Somone can help me with the configuration ?

Tanks

Michel







------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 5220
**************************************


home help back first fref pref prev next nref lref last post