#!/usr/bin/perl use CGI; use DBI; use Email::Valid; use strict; my $mailprog = '/usr/sbin/sendmail'; my $q = new CGI; my $args = $q->Vars; my $dbh; my $action; print "Content-type: text/html\n\n"; &startHead; my %status = ( 'A' => 'Active', 'B' => 'Alumni Status', 'C' => 'updateCalendar', 'D' => 'aDdpledges', 'E' => 'Commander', 'F' => 'Fundraising', 'G' => 'Chaplain', 'H' => 'House Corp', 'I' => 'Initiatepledges', 'J' => 'Associate/Holdover', 'L' => 'Lt. Commander', 'M' => 'House Manager', 'N' => 'Historian', 'O' => 'Recorder', 'P' => 'Pledge Marshal', 'Q' => 'Sentinel', 'R' => 'Rush', 'i' => 'IFC Rep', 'S' => 'Social Chair', 's' => 'Sports Chair', 'T' => 'Treasurer', 'r' => 'Risk Reduction', 'U' => 'statUschanges', 'W' => 'WebMaster', 'X' => 'aXcesschanges', 'Y' => 'Philanthropy', 'y' => 'Scholarship', 'Z' => 'Alumni Contact'); $$args{fromemail} =~ s/(^\s+)|(\s+$)//g; $action = $$args{action}; if (!$action) { &MailForm($args); } else { if ($action =~ /SEND/i) { &sendMail($args); } else { print ""; } } &eXit; sub eXit { print $q->end_html; exit; } sub startHead { print <Sigma Nu Fraternity - San Diego State University - Eta Kappa Chapter EOH } sub startBODY { my ($args) = @_; if ($$args{bodyStarted}) { return; } print < EOH $$args{bodyStarted} = 'Y'; #foreach my $key (keys %$args) { print "$key = $$args{$key}
"; } } sub MailErrors { my ($args,@errors) = @_; my $error; &startBODY($args); print "
"; foreach $error (@errors) { print "
$error

"; } &MailForm($args); &eXit; } sub dbConnect { my $dbh = DBI->connect("dbi:mysql:sigmanus_dsucom","sigmanus_dbuser","dbpass") || die "Can't connect: $DBI::errstr"; return($dbh); } sub MailForm { my ($args) = @_; &startBODY($args); my $fromname = $$args{fromname}; my $fromemail = $$args{fromemail}; my $message = $$args{message}; my $subject = $$args{subject}; my $toAlums = $$args{toalums}; my $toActvs = $$args{toactvs}; my $toWbmst = $$args{towbmst}; my $alumsChecked = $toAlums ? 'checked' : ''; my $actvsChecked = $toActvs ? 'checked' : ''; my $wbmstChecked = $toWbmst ? 'checked' : ''; my @bgc = qw(green green blue red gold yellow); my $bgc = $bgc[rand(@bgc)]; print <

Your Name:
Your Email:
 
Subject:

Send To:  
Active Fraternity Officers (President, Rush Chairman, etc.)
Sigma Nu SDSU Alumni Association (House Corp.)
WebMaster (SigmaNuSDSU.com)
 

 
EOH &eXit; } sub sendMail { my ($args) = @_; my @errors; my $recipList; my $who; my $fromname = $$args{fromname}; my $fromemail = $$args{fromemail}; my $message = $$args{message}; my $subject = $$args{subject}; my $toAlums = $$args{toalums}; my $toActvs = $$args{toactvs}; my $toWbmst = $$args{towbmst}; if (!$fromname || $fromname =~ /^\s+$/) { push(@errors, "Please Enter Your Name"); } if ($fromemail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) { push(@errors, "You Need to Enter a Valid Email Address"); } else { if (!Email::Valid->address(-address =>$fromemail,-mxcheck => 1)) { push(@errors, "Sorry, That Does Not Seem To Be A Valid Email Address"); } } if (!$subject || $subject =~ /^\s+$/) { push(@errors,"You Gotta Enter a Subject for your Email"); } if (!$message || $message =~ /^\s+$/) { push(@errors,"You didn't enter anything in the message text box"); } if (length($message) > 5000) { push(@errors,"Message Length Cannot Exceed 5000 Characters"); } if (!$toAlums && !$toActvs && !$toWbmst) { push(@errors, "You Must Check at Least One Recipient"); } if (@errors) { &MailErrors($args,@errors); return; } my $dbh; if ($toActvs) { $dbh = &dbConnect; my $stmt = "select first, last, email, pin, priv from members where status = 'A' and priv > ' ' and email like '%@%' order by pin desc"; my $sth = $dbh->prepare($stmt); $sth->execute || die "error executing statement $stmt\n"; while ( my ($first,$last,$email,$pin,$priv) = $sth->fetchrow_array ) { if ($priv =~ /[EFGMLNOPQRrSsTtYZi]/i) { my $name = "$first $last"; $name =~ s/\s+/ /g; $recipList .= "$email ($name),"; } } $who = "\tAll Active Officers\n"; } if ($toAlums) { $dbh ||= &dbConnect; my $stmt = "select first, last, email, pin, priv from members where (priv like '%H%' or pin = 315) and email like '%@%' order by pin desc"; my $sth = $dbh->prepare($stmt); $sth->execute || die "error executing statement $stmt\n"; while ( my ($first,$last,$email,$pin,$priv) = $sth->fetchrow_array ) { my $name = "$first $last"; $name =~ s/\s+/ /g; $recipList .= "$email ($name),"; } #$recipList .= 'HouseCorp@SigmaNuSDSU.com (House Corp),'; $who .= "\tHouse Corp Members\n"; } if ($toWbmst) { $recipList .= 'WebMaster@SigmaNuSDSU.com (SigmaNuSDSU WebMaster)'; $who .= "\tWebMaster (HK315)\n"; } $recipList =~ s/,$//; my $ipInfo = "IP Address of Sender: $ENV{REMOTE_ADDR}, Host: $ENV{REMOTE_HOST}"; if ($ipInfo =~ /\b12\.1/) { $ipInfo = ''; } if ($recipList) { open (MAIL, "|$mailprog -t -f WebMaster\@SigmaNuSDSU.com") || die "Can't open $mailprog!\n"; print MAIL "From: $fromemail ($fromname)\n"; print MAIL "To: $recipList\n"; if (!$toWbmst) { print MAIL "BCC: SigmaNuWebmaster\@gmail.com\n"; } print MAIL "Subject: SigmaNu: $subject\n\n"; print MAIL <); &startBODY($args); print "

 

YOUR MESSAGE WAS SENT !!!

"; }