#!/usr/local/bin/perl

require "cgi-lib.pl";

binmode STDIN;
print "General Purpose Environment Checker\n";

&ReadParse(*input);
print "Value of all components extracted from the URL\n";


foreach $key (keys %input)
{
  $output = $input{ "$key" };
  $len=length($output);
  $output =~ s/\n/<br>/g;
  $output =~ tr/\0-\37\177-\377/./;
  $output =~ s/\n/<br>\n/g;
  $output =~ s/\r/&lt;cr&gt;/g;	# so that we can see these..
  print "$key";
  print " (Length of record is $len)\n";
  print "\n $output\n";
}
print "<\n";

print "hex dump\n";

print "\n";
foreach $key (keys %input)
{
  $output = $input{ "$key" };
  $len=length($output);
  print "$key";
  print " (Length of record is $len)";
  print "\n";
  $index=0;

  while ($index < $len)
  {
    $hex0="\@${index}H";
    $hex1="\@${index}h";
    $buf0=unpack("$hex0", $output);
    $buf1=unpack("$hex1", $output);
    print "$buf0", "$buf1", ' ';
    $index++;
    if ("$index"%25 == 0){ print "\n";}
  }
  print "\n";
}
print "\n";


print "Value of all environmental variables\n";
#print "::\n";
print " \n";
$output = $ENV{'QUERY_STRING'}; 
if ($output) {
    print "Query string is \n";
    print "$output\n";
}


foreach $key (keys %ENV)
{
  $output = $ENV{ $key };
  $output =~ s/\n/<br>\n/g;
  $output =~ s/\r/&lt;cr&gt;/g;

  print "$key\n $output \n";
}

