Creating Server Scripts
The Common Gateway Interface (CGI) is the specified standard for communication between HTTP servers (Web servers) and server-side gateway programs. The CGI specifications define how data passes from the server to gateway programs, and vice versa.
Gateway programs can be compiled programs written in languages such as C, C++ or Pascal, or they can be executable scripts written in languages such as Perl, TCL, ASP, and other various shell programs. Most gateway programs are Perl scripts; they are easy to write and modify and are transportable between computers.

#!/usr/local/bin/perl
# check for the POST method
if ($ENV{‘REQUEST_METHOD’} eq ‘POST’)
{
# How many bytes are we supposed to receive?
read(STDIN, $buffer, $ENV{‘CONTENT_LENGTH’});
# make a list of keyword/value pairs
@pairs = split(/&/, $buffer);
# cycle through each pair and decipher the values foreach $pair (@pairs)
{
# get the name/value pair strings
($name, $value) = split(/=/, $pair);
# translate "+" to a space
$value =~ tr/+/ /;
# decipher ASCIhexidecimal escaped characters, if any
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# find profile/contsupp field names that begin with cs*_
if ($name =~ /cs\d_/)
#add the profile/contsupp pair to a list keyed on the name of the variable
{$csarry{$name} = $value;}
else {
#add the basic field data pair to a list keyed on the name of the variable
$contents{$name} = $value
}
}
}
($mon,$day,$year) = split(m>>/>>,‘/bin/date +%B/%e/%Y‘);
$date = "$mon $day, $year";
$to = $contents{‘email_to’};
&mailto;
&thankyou;
###############
## subroutines from here on down!
###############
sub thankyou {
print "Location: http://www.ivanti.com/thankyou.htm\n\n";
exit;
}
sub mailto {
open (MAIL, ">>/usr/lib/sendmail -t") >>>>die "can’t open pipe to sendmail \n";
print MAIL "Content-Type: application/x-gm-impdata\n";
print MAIL "To: $to\n";
print MAIL "From: $csarry{‘cs2_ContSupRef’}\n";
print MAIL "Subject: datafromgoldform.pl\n";
print MAIL "\n\n";
print MAIL "\[Instructions\]\n";
print MAIL "SaveThis=Web Import File\n";
print MAIL "DupCheck1=Contact\n";
print MAIL "\n";
print MAIL "OnNewSendEmail=Bart,NEW,Prospect requesting information \n";
print MAIL "OnDupSendEmail=Natalie,,Duplicate Record \n”;
print MAIL "\n";
print MAIL "OnNewAttachTrack=WEBLead\n";
print MAIL "\n";
# The following is an example of testing a field for a value
#print MAIL "Below a message will be printed if the CITY is
Torrance\n\n";
if ($contents{CITY}eq "Torrance") {
print MAIL "OnAnySendEmail=John,WCC,This one is from Torrance\n";
}
print MAIL "\n";
#print MAIL "Run=c:\goldmine\webimp.exe\n";
print MAIL "\n";
print MAIL "\n";
print MAIL "\[Data\]\n";
# print out general fields and values
foreach $name (sort keys %contents) {
next if $contents{$name} eq "";
print MAIL "$name = $contents{$name}\n";
}
print MAIL "\n";
print MAIL "\[ContSupp\]\n";
# print out profile/contsupp fields and values
foreach $name (sort keys %csarry) {
next if $csarry{$name} eq "";
print MAIL "$name = $csarry{$name}\n";
}
print MAIL "\n";
print MAIL "\n";
print MAIL "\n";
print MAIL "\n\n";
close (MAIL);
}