#!/usr/bin/perl # # Mailto 1.7 # # Copyright 1995, Brandon Gillespie # # Permission to use, copy, modify and distribute this software and its # documentation is hereby granted, provided that this copyright notice # appear in all versions and documentation. No representations are made # about the suitability of this software for any purpose. This software # is provided "as is" without express or implied warranty. # ################################ # change this to point to cgi.pl require "cgi.pl"; ################################ ################################ # CONFIG # # out of simplicity, the configuration is supplied here. # # VALIDATE_RECIP # # Set this to 1 if you want to validate the recipients (make # sure they are in your list), or set it to 0, if you do not. $validate_recip = 1; # RECIPIENTS # # This is a list of valid recipients for Mailto to send to. # Mailto does not care about character case. It is best to # make sure your form entry is the same as that in this listing. # as it will care about host addresses (if they exist). # # Change the path below to the path correctly pointing to the # users file on your system. Comments are denoted with a hash # mark ('#'), and are not included. $recipients = ""; if ($validate_recip) { $filep = "mailto.users"; if (!open(ACCESS, "$filep")) { &error("Unable to open access file.\n"); } while () { (/^\s*#/) && next; s/#.*$//g; $recipients = "$recipients$_"; } } # REQUIRE_FROM # # Set this to 1 if you want to require the from field to be set, # or set it to 0, if you do not. $require_from = 0; # REQUIRE_BODY # # Set this to 1 if you want to require the body field to be set, # or set it to 0, if you do not. $require_body = 0; # VERSION # # You shouldn't be changing this... $version = "1.7"; # MAILPROG # # the sendmail program, only useful in unix. $mailprog = "/usr/lib/sendmail -oi -t"; # you shouldn't have to change anything past this. ##################################### $mbase = "http://www.declab.usu.edu/"; # Mailto's home pages $murl = "${mbase}Mailto/"; # Mailto's home pages $myurl = "http://$ENV{SERVER_NAME}"; if ($ENV{'SERVER_PORT'} ne "80") { $myurl = "$myurl:$ENV{SERVER_PORT}" } $myurl = "${myurl}/"; &CGI'init(); @keys = (); %fields = (); @list = split(/\&/, $ENV{QUERY_STRING}); for (@list) { ($name, $value) = split(/=/); if ($value) { $value = &CGI'decode($value); $name = &CGI'decode($name); } else { # this way it will test true with if ($fields{name}) $value = "NoValue"; } # this gets it into a standard lowercase format if ($name =~ /^\s*recip/i) { $fields{Recipient} = $value; } elsif ($name =~ /^\s*from/i) { $fields{From} = $value; } elsif ($name =~ /^\s*body/i) { $fields{Body} = $value; } elsif ($name =~ /^\s*followup-page/i) { $fields{Followup-Page} = $value; } elsif ($name =~ /^\s*subj/i) { $fields{Subject} = $value; } elsif ($name =~ /^\s*return/i) { $fields{Return} = $value; } elsif ($name =~ /^\s*name/i) { $fields{Name} = $value; } # Fix where multiple selections were not contained provided by Paul Fuchs # elsif ($fields{$name}) { $fields{$name} = "$fields{$name}, $value"; } else { $fields{$name} = $value; @keys = (@keys, $name); } } sub error { print <Mailto $version Error

Mailto $version Error:

@_

END exit(0); } $e_rh = $ENV{'REMOTE_HOST'} || "Unknown"; $e_ra = $ENV{'REMOTE_ADDR'} || "?.?.?.?"; $e_ref = $ENV{'HTTP_REFERER'}; # this is only around if you are using Apache if ($require_from && !$fields{From}) { &error("No email address specified.\n"); } if ($require_body && !$fields{Body}) { &error("No text in body.\n"); } sub invalid_recip { local($recip) = $fields{Recipient}; @recipients = split(/\n/, $recipients); for (@recipients) { if (/$recip/) { return 0; } } return 1; } $recip = $fields{Recipient}; if ($validate_recip && &invalid_recip()) { &error("Specified Recipient is not allowed."); } if ($fields{From} !~ /\@/) { $fields{From} = "$fields{From}\@$e_rh"; } open(MAIL, "|$mailprog") || &error("Unable to open mail program.\n"); print MAIL < To: $fields{Recipient} X-Mailer: WWW Mailto-$version Gateway (perl CGI) X-Followup-Page: $fields{Followup-Page} X-Server: $myurl X-Real-Host-From: $e_rh ($e_ra) END print MAIL "\n--------------------------------------\n"; for (@keys) { /^\s*Body\s*$/ && next; /^\s*Return\s*$/ && next; ######################################################### # If you don't want these to show up, decomment them here # and below in the message printed as a result. # /^\s*Subject\s*$/ && next; # /^\s*From\s*$/ && next; /^\s*Recipient\s*$/ && next; /^\s*Followup-Page\s*$/ && next; # /^\s*Name\s*$/ && next; print MAIL "$_: $fields{$_}\n"; } if ($e_ref) { print MAIL "Referer: $e_ref\n"; } print MAIL "--------------------------------------\n"; if ($fields{Body} ne "NoValue") { print MAIL "\n$fields{Body}\n"; } close(MAIL); if ($fields{Followup-Page}) { # print "Location: "; # if ($fields{Followup-Page} =~ /^\/.*/) { # print "${myurl}$fields{Followup-Page}\n"; # } else { # print "$fields{Followup-Page}\n"; # } print < Redirection

Redirection

Go: $fields{Followup-Page}.

You see this message because your browser does not support automatic redirection. END } else { print < Mailto-$version Gateway

[Mailto] Mailto-$version Gateway


Subject: $fields{Subject}
From:    $fields{Name} <$fields{From}>
To:      $fields{Recipient}
END

print "\n--------------------------------------\n";
for (@keys) {
    /^\s*Body\s*$/ && next;
    /^\s*Return\s*$/ && next;
    #########################################################
    # If you want/don't want these to show up, comment/decomment them here
    /^\s*Subject\s*$/ && next;
    /^\s*From\s*$/ && next;
    /^\s*Recipient\s*$/ && next;
    /^\s*Followup-Page\s*$/ && next;
    /^\s*Name\s*$/ && next;
    print "$_: $fields{$_}\n";
}
print "--------------------------------------\n";

if ($fields{Body} ne "NoValue") {
    print "\n$fields{Body}\n";
}

print "
\n
\n"; if ($fields{Return}) { if ($fields{Return} eq "NoValue" && $e_ref) { print "

Go Back

\n
"; } elsif ($fields{Return} ne "NoValue") { print "

Go Back

\n
"; } } print < Mail sent using Mailto version $version

END }