#! /usr/bin/perl -Tw $ENV{'PATH'}="/bin:/usr/bin:/sbin:/usr/sbin"; $ENV{'ENV'} = ''; $ENV{'IFS'} = ''; $| = 1; $now = scalar localtime(); $now =~ s/\s/_/g; print "Content-type: text/html Set-Cookie: wibble=splither; path=/~matthew/; domain=mr-wilkins.granta.internal; expires=Fri, 31-Dec-2005 23:59:59 GMT Set-Cookie: last-access=$now; path=/; domain=mr-wilkins; expires=Fri, 31-Dec-2005 23:59:59 GMT Dumped by "; print '$Id: env.cgi,v 1.4 2005/05/21 11:41:55 mca1001 Exp $
';

# (cookie)  expires=Thu, 20-Aug-1998 23:59:59 GMT


foreach $foo (sort keys %ENV)
{
  print "$foo = $ENV{$foo}\n";
}

%cookies = ();
if (defined $ENV{HTTP_COOKIE}) {
    print "\nCookies:\n";
    while ( $ENV{HTTP_COOKIE} =~ s/([^\s=,]+)=([^\s=;]+);?// ) {
	$cookies{$1} = $2;
	print "  $1 = $2\n";
    }
} else {
    print "\nNo cookies\n";
}

print "\nValues pairs:\n";
if ($ENV{REQUEST_METHOD} eq 'GET') {
    foreach (split '&', $ENV{QUERY_STRING}) {
	my ($k, $v) = split '=', $_;
	$k = decgi($k);
	$v = decgi($v);
	print "'$k'", ' 'x(40-length $k),"'$v'\n";
    }
} elsif ($ENV{REQUEST_METHOD} eq 'POST') {
    my $posted = join "\n", ;
    print "Posted input with added newlines = >>$posted<<\n";
    foreach (split '&', $posted) {
	my ($k, $v) = split '=', $_;
	$k = decgi($k);
	$v = decgi($v);
	print "'$k'", ' 'x(40-length $k),"'$v'\n";
    }
} else {
    print "I'm confused: REQUEST_METHOD=$ENV{REQUEST_METHOD}\n";
}

print "
"; sub decgi { local $_ = shift; return undef unless defined; tr/+/ /; s/%([0-9a-f]{2})/pack("c",hex($1))/gie; return $_; }