#!/usr/bin/perl -Tw
#
# LDAP Apache Configs
# $Source: /repos/development/acs-http/acs-http/cgi-bin/vars.cgi,v $
# $Revision: 1.1.2.24 $
# $Date: 2004/11/23 11:41:12 $
# $Author: syzdek $
# $Locker: $
#
# vars.cgi - simple CGI example that displays Apache ENV Variables
#
# +-=-=-=-=-=-+
# | |
# | Headers |
# | |
# +-=-=-=-=-=-+
use CGI::Carp qw(fatalsToBrowser); # Make errors safe for Web servers
use strict; # Enforce good programming habits
$|++; # Disables Line buffering
our $CONFIGURATION = '/dev/null';
our $PROGRAM_NAME = 'vars.cgi';
our $VERSION = '0.01';
our $DESCRIPTION = 'simple CGI example that displays Apache ENV Variables';
our $AUTHOR = 'David Syzdek ';
our $COPYRIGHT = 'Copyright (c) 2004 David M. Syzdek ';
# +-=-=-=-=-=-=-=+
# | |
# | Prototypes |
# | |
# +-=-=-=-=-=-=-=+
sub cookie_data($); # displays http_cookie data
sub headers($$); # displays headers
sub html_bottom(); # displays last part of HTML
sub html_top(); # displays first part of HTML
sub query_data($); # displays query_string data
sub sourcedump($$); # displays source code
sub vars(%); # displays Apache environment variables
sub main(@); # main statement (old C habit)
# +-=-=-=-=-=-=-+
# | |
# | Functions |
# | |
# +-=-=-=-=-=-=-+
# displays formatted data
sub cookie_data($)
{
# grabs passed args
my $data = shift || return(0);
# declares local vars
my $decoded;
my $pair;
my $name;
my $value;
my @pairs;
# cleans up data
$decoded = $data;
$decoded =~ tr/+/ /;
$decoded =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# displays html
print (" HTTP_COOKIE Data\n");
print (" \n");
print ("
\n");
print (" \n");
print (" | formatted_data | \n");
print (" \n");
print (" \n");
print (" | Field | Value | \n");
# loops through vars
$data =~ s/; /;/g;
@pairs = split(/;/, $data);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
if ($name =~ /^([\w]+)$/) {
$name = $1;
} else {
die "illeagal characters in data name: $name\n";
};
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
print (" | $name | $value | \n");
};
# finishes html
print (" \n");
print (" | \n");
print ("
\n");
print ("
\n");
print ("
\n");
# ends function
return(0);
};
# displayes headers
sub headers($$)
{
# grabs passed args
my $request_method = shift;
my $content_length = shift;
# declares local vars
my $buffer;
my $name;
my $value;
my $pair;
my @pairs;
my %data;
# reads posted data
if (defined($request_method) && defined($content_length)) { # verifies that the env variables were defined
if ($request_method eq 'POST') { # verifies that there is POST data to read
read(STDIN, $buffer, $content_length); # retrieves posted data
@pairs = split(/&/, $buffer); # splits apart the buffer in name and value pairs
chomp (@pairs); # removes unnecessary newlines and carriage returns
foreach $pair (@pairs) { # loops through each pair
($name, $value) = split(/=/, $pair); # seperates the field name and value
if ($name =~ /^([\w]+)$/) { # verifies the name has allowed characters
$name = $1; # detaints data
} else {
die "illeagal characters in data name: $name\n"; # kills script if invalid characters where in field name
};
$value =~ tr/+/ /; # decodes white space
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # decodes hex data
$data{$name} = $value; # stores data in a hash
};
};
};
# sets cookies
# if (! defined($data{'timestamp'})) {
# print ("Set-Cookie: timestamp=", time, "; path=/\n");
# print ("Set-Cookie: program_name=$PROGRAM_NAME; path=/\n");
# print ("Set-Cookie: version=$VERSION; path=/\n");
# print ("Set-Cookie: description=$DESCRIPTION; path=/\n");
# print ("Set-Cookie: author=$AUTHOR; path=/\n");
# print ("Set-Cookie: copyright=$COPYRIGHT; path=/\n");
# } else {
# print('Set-Cookie: timestamp=null; path=/; expires=Thursday, 27-Feb-03 00:00:00 GMT;', "\n");
# print('Set-Cookie: program_name=null; path=/; expires=Thursday, 27-Feb-03 00:00:00 GMT;', "\n");
# print('Set-Cookie: version=null; path=/; expires=Thursday, 27-Feb-03 00:00:00 GMT;', "\n");
# print('Set-Cookie: description=null; path=/; expires=Thursday, 27-Feb-03 00:00:00 GMT;', "\n");
# print('Set-Cookie: author=null; path=/; expires=Thursday, 27-Feb-03 00:00:00 GMT;', "\n");
# print('Set-Cookie: copyright=null; path=/; expires=Thursday, 27-Feb-03 00:00:00 GMT;', "\n");
# };
# Specifies format
print ("Content-type: text/html\n\n\n");
# ends function
return(0);
};
# displays last part of HTML
sub html_bottom()
{
# displays html
print (" \n");
print (" View Source Code\n");
print ("
\n");
print ("
\n");
print (" \n");
print (" | \n");
print (" \n");
print (" | \n");
print (" \n");
print (" | \n");
print ("
\n");
print ("
\n");
print (" \n");
print (" \n");
print ("