#!/usr/bin/perl



                         ### *** IMPORTANT *** ###

         ### *** Make sure the path to PERL above is correct *** ###
   
                   ## Could be any of the following:

                   ## #!/usr/local/bin/perl
                   ## #!/usr/bin/perl
                   ## #!/usr/local/bin/perl5

                   # date = /bin/date
                   # mail = /usr/sbin/sendmail


      #################################################################
      #                                                               #
      #                          SITE TEST                            #
      #                                                               #
      #                                                               #
      #                              by                               #
      #                        Ranson Johnson                         #
      #                                                               #
      # E-Mail: ranson@rlaj.com                                       #
      #                                                               #
      # Script name: sitetest.cgi                                     #
      #                                                               #
      # Copywrite 1997/1998 by Ranson's Scripts all rights reserved   #
      # Sale or re-distribution of this program without prior written #
      # permision is prohibited.                                      #
      #                                                               #
      #################################################################


                      ### *** IMPORTANT *** ###

### *** If FTP'ing this file, be sure to send in ASCII format *** ###

# You must chmod the cgi's to 755 
# For information on chmod see Ranson's FAQ's

#    Configure the varialbles in the configuration section below
#    be careful to not disturb the single (') or double quotes (") 
#    surounding each variable, or the semicolon (;) at the end of 
#    each line.



      ### *** Rename this file to sitetest.pl for Windows NT Servers *** ###



# Install this file in the directory you want to check the PATH for
# Enter your E-Mail address below in the configuration section
# Select your operation system - NT or Unix
# 
# If you rename this file, be sure to change the name below

# This program is set up for Unix mail - Sendmail
# And NT mail gateways
#                       blat
#                       windmail
#                       imail
# 
# ASK YOUR SERVER ADMINISTRATOR FOR THE PATH AND NAME OF THE MAIL PROGRAM


# Run the program from the web using your favorite browser. 
# The path information will be printed back in your browser window.
# An email will be sent to you to test the gateway
#
# This program will also show all the environment variables passed
# by your browser and variables available on your server.



                ### *** CONFIGURATION SECTION *** ###



# Enter the operating system for the server
# Unix = '0' 
# NT = '1'
$operating_system = '0';


# Enter the path to the mail program
#$mailprog = '/var/qmail/bin/qmail-inject';     
$mailprog = '/usr/sbin/sendmail';
 
# Enter the your email address     
$webmaster = 'carve@telusplanet.net';

# Enter the email address for who the mail is from
$mail_from = 'carve@telusplanet.net';

# Enter the name of this file
$thisfile = 'sitetest.cgi';


            ### *** DONT CHANGE ANYTHING BELOW *** ###


### *** *** ###  ### *** *** ###    ### *** *** ###    ### *** *** ###    ### *** *** ###     
### *** *** ###  ### *** *** ###    ### *** *** ###    ### *** *** ###    ### *** *** ###  



$path = $ENV{'SCRIPT_FILENAME'};
$path =~ s/$thisfile//;


if ($operating_system eq "0") {

$mymail="Unix - SendMail";

open (MAIL, "|$mailprog $webmaster") || &open_error("$mailprog");

   print MAIL "Subject: Test of mail program\n";
   print MAIL "To: $webmaster\n";
   print MAIL "Reply-to: $mail_from\n";
   print MAIL "From: $mail_from\n\n";


   print MAIL "This is a test of the mail program\n\n";


close (MAIL);

}else{


                  ## THIS IS WINDOWS MAIL ##

$temp_msg = 'temp.mail';


               ### *** SEND MAIL TO USER *** ###


open (MAIL, ">$temp_msg") || &open_error($temp_msg);
       
        print MAIL <<"END_OF_MAIL";  
To: $webmaster
From: $mail_from
Subject: Test of mail program

Test of Mail Program.

END_OF_MAIL

close (MAIL);

if ($mailprog =~ /blat/i) {
system("blat.exe \"$temp_msg\" -s \"Test of mail program\" -f \"$mail_from\" -t $webmaster");
$mymail="NT - Blat";
}
elsif ($mailprog =~ /windmail/i) {
$mymail="NT - Windmail";
system("\"$mailprog\" -t -t -n $temp_msg");
}
elsif ($mailprog =~ /imail/) {
$mymail="NT - iMail";
system ("$mailprog -f $temp_msg -s \"Test of mail program\" -u $mail_from -t $webmaster");
}
unlink ("$temp_msg");

}

                         ### *** *** ###
                         ### *** *** ###
                         ### *** *** ###


print "Content-type: text/html\n\n";

print <<"EOT";

<HTML>
<HEAD>
<TITLE>Site Test by RLAJ.COM</TITLE>
</HEAD>
<BODY BGCOLOR=FFFFFF TEXT=000000>

<CENTER><H2>Path and Environment Test</H2></CENTER>
<HR>

EOT

print "\n<P>\n<B>Mail was sent to <FONT COLOR=0000FF>$webmaster</FONT> via the mail program: <FONT COLOR=FF0000>$mymail</FONT></B>\n<P>\n"; 

print "\n<P>\n<B>The Mail path is: <FONT COLOR=FF0000>$mailprog</FONT></B>\n<P>\n"; 

print <<"EOT";

<B>
The path for this file is: <FONT COLOR=#F04E00>$path
</FONT></B>
<P>
<HR>
<P>
EOT


foreach $key (keys(%ENV)) {

print "$key = $ENV{$key}<br>\n";
}

print "<P><B>Perl Version $] </B>";

print "\n<P>\nMail was sent to $webmaster via the mail program: $mailprog\n<P>\n"; 

print "<HR><HR><HR></body></html>";


exit;

                          ### *** *** ###

sub open_error
    {

    local ($filename) = @_;

    print "Content-Type: text/html\n\n";


    print "
<P>
<HR>
<P>
<H1>Error!</H1>
<P>
<H4>The program can not find, or is not able to open the 
specified file:</H4>
<H2>$filename</H2><P>  
Please check the file name.<B>";

exit;

} # End sub open_error
