#!/usr/local/bin/perl
# Name: form_processor.cgi (form.cgi)
#
# Version: 3.0
#
# Last Modified: 10-21-98 (Jim Lucas)
#
# Copyright Information: This application was written by Selena Sol
# (selena@eff.org, http://www.eff.org/~erict) having been inspired by
# countless other Perl authors. Feel free to copy, cite, reference,
# sample, borrow, resell or plagiarize the contents. However, if you
# don't mind, please let me know where it goes so that I can at least
# watch and take part in the development of the memes. Information wants
# to be free, support public domain freware. Donations are appreciated
# and will be spent on further upgrades and other public domain scripts.
#######################################################################
# Begin Processing the Form. #
#######################################################################
# First, print out the HTTP header. We'll output this quickly so that we
# will be able to do some of our debugging from the web and so that in
# the case of a bogged down server, we won't get timed-out. We will also
# bypass the Perl buffer with the first line.
$| = 1;
print "Content-type: text/html\n\n";
#######################################################################
# Require Libraries and Parse Form Data #
#######################################################################
# Use cgi-lib.pl to read the incoming form data. However, send form_data
# as a parameter to the subroutine &ReadParse in cgi-lib.pl so that the
# associative array of form keys/values comes back with a descriptinve
# name rather than just $in. Also require the library which we will use
# to send out mail using sendmail
require "/home/staff/itc/http/form/form.setup";
require "/home/staff/itc/http/form/mail-lib.pl";
require "/home/staff/itc/http/form/cgi-lib.pl";
require "/home/staff/itc/http/form/cgi-lib.sol";
#######################################################################
# Gather Form Data. #
#######################################################################
# Use cgi-lib.pl to parse the incoming form data and tell cgi-lib to
# prepare that information in the associative array %form_data
&ReadParse(*form_data);
#######################################################################
# Security Test #
#######################################################################
# Next let's figure out where the form that is requesting our attention
# is located. We'll do this by accessing the environment variable
# $ENV{'HTTP_REFERER'} which is equal to the url of the form in question
# (ie: http://www.foobar.com/Feedback/feedback.html). We are going to take
# that value and split it up into separate variables for every occurance of
# "/". We do this in order to isolate www.foobar.com which we can compare
# to the value of $your_server_name. Thus $referring_server is the
# only varriable here we actually give a hoot about. If they are
# not the same, the script # is being accessed by a form on another server.
($http, $empty, $referring_server, @path) = split (/\//, $ENV{'HTTP_REFERER'});
# Now if the $restricted_use has been set to yes, "and" the
# $referring_server is not the same as $your_server_name it means that we
# have had an illegal attempted access and we will deny the use of this
# script.
if ($restricted_use eq "yes")
{
if ($referring_server ne "$your_server_name")
{
&html_header("Form Error - Wrong Server");
print qq!
$wrong_server_error_message