home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
bombers.k12.ar.us
/
bombers.k12.ar.us.tar
/
bombers.k12.ar.us
/
cgi-bin
/
utils1.pl
< prev
Wrap
Text File
|
2003-10-07
|
16KB
|
525 lines
$eventlist =$datapath.'events.dat';
$registry = $datapath.'registry.dat';
$registrar =$CGI_URL.'registrar.pl';
$admin = $CGI_URL.'secure/admin.pl';
$adminURL = $URL.'/admin';
$eventURL=$CGI_URL.'registrar.pl';
###############################################################################
sub main {
if ($bgcolor){$bgcolor=" BGCOLOR=\"$bgcolor\" ";}
if ($background){$background=" BACKGROUND=\"$background\" ";}
if ($adminbuttons){$adminbuttons=" ADMINBUTTONS=\"$adminbuttons\" ";}
if ($::debug) {
print "Content-type: text/html\n\n
<HTML><HEAD><TITLE>DEBUG</TITLE></HEAD>
<BODY $bgcolor $background><H2>DEBUG MODE</H2>\n";
}
# PARSE THE FORM INPUT
&form_parse;
# BEGIN THE HTML PAGE
&header2;
# DECIDE WHERE TO GO NEXT
if($E{'regform'}) {®form;}
if($E{'register'}) {®ister;}
®istrar;
if ($::debug) {print "</BODY></HTML>\n";}
}
###############################################################################
# form_parse: Reads in the form information from a POST and
# parses it out into $E{'variable_name'}
sub form_parse {
# GET THE INPUT
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# SPLIT THE NAME-VALUE PAIRS
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# UN-WEBIFY PLUS SIGNS AND %-ENCODING
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Stop people from using subshells to execute commands
# Not a big deal when using sendmail, but very important
# when using UCB mail (aka mailx).
# $value =~ s/~!/ ~!/g;
$value =~ s/<!--(.|\n)*-->//g;
$value =~ s/"/'/g; # neutralize quotes
$value =~ s/^\s*//; # remove leading whitespace
$value =~ s/\s*$//; # remove trailing whitespace
$value =~ s/\r\n/\n/g; #NEW: make windows files look Unix
$value =~ s/\n/<BR>/g; #NEW: kill the carriage returns
$value =~ s/&/and/g; #NEW: kill the ampersands
&db("FORM_PARSE: Setting $name to $value");
$E{$name} = $value;
}
} # end sub
##############################################################################
# OUTPUT A DEBUG LINE
sub db {
$line = shift;
if(!$::debug) {return 0;}
print "\n<!-- $line -->\n";
return 1;
} # END SUB
##############################################################################
sub UnTaint{
$var = shift;
if ($var =~ m#^([-+><@\w./\\:]+)$#){
$var = $1;
}
else{
die "ERROR: File name can not be untainted: [$var]\n";
}
return($var);
} # END SUB UnTaint
#######################################################################
# month2number - given month, return # for that month
sub month2number {
if ($month =~ /jan/i) {$month=1;}
elsif ($month =~ /feb/i) {$month=2;}
elsif ($month =~ /mar/i) {$month=3;}
elsif ($month =~ /apr/i) {$month=4;}
elsif ($month =~ /may/i) {$month=5;}
elsif ($month =~ /jun/i) {$month=6;}
elsif ($month =~ /jul/i) {$month=7;}
elsif ($month =~ /aug/i) {$month=8;}
elsif ($month =~ /sep/i) {$month=9;}
elsif ($month =~ /oct/i) {$month=10;}
elsif ($month =~ /nov/i) {$month=11;}
elsif ($month =~ /dec/i) {$month=12;}
} # end sub
#######################################################################
# todayjulean - returns today's julean date. Calls julean.
sub todayjulean {
$date=localtime(time);
@date=split (/\s+/, $date);
$month=$date[1];
&month2number;
&julean ($month, $date[2], $date[4]);
$today = $jule;
} # end sub
#######################################################################
# julean - returns julean date with jan 1, 1992 as day 1
# Takes date in Month, day, and year order and finds julean date.
# Outputs julean number for inputted date.
# This sub by David Moose Pitts, mod. by Rich Bowen and Chuck Lund
# Usage: &julean(6, 16, 2003);
sub julean {
$thisdayjulean=0;
#@months=(0,31,28,31,30,31,30,31,31,30,31,30,31);
my @months=(0,31,28,31,30,31,30,31,31,30,31,30,31); # 9/24/03
$local_month=$_[0];
$tday=$_[1];
$tyear=$_[2];
$leapdays=( ($tyear-1992)/4 ) + 1; #must be a leap year, so I chose 1992
# THIS SECTION DROPS THE REMAINDER OF THE LEAP DAY FOR THE YEAR.
$leapdays2=(($tyear-1992)%4);
$leapdays-=($leapdays2*0.25);
if ($tyear % 100==0 ) {if ($tyear % 400 == 0) {$leapdays -= 1;}}
# even 100 year years do not have
# leap days in them except those
# divisible by 400
$local_thisyear=$tyear-1992;
for ($local_i=1;$local_i<=$local_thisyear;$local_i++) {$thisdayjulean+=365;}
for ($local_i=1;$local_i<$local_month;$local_i++) {$thisdayjulean+=$months[$local_i];}
#minus 1 because current month not complete
if ($local_month<3 && $leapdays2==0) {$leapdays--;}
$thisdayjulean+=$leapdays+$tday;
$jule=$thisdayjulean;
} # end sub
#######################################################################
# redirect - redirect to another URL
# usage: &redirect('http://www.acme.com');
sub redirect {
if($::debug) {
print "\nRedirect to: <A HREF=\"$_[0]\">$_[0]</A>\n";
}
else {
print"Location: $_[0] \n\n";
}
} # end sub
###############################################################################
# get_date - get the date from the system, version 2
sub get_date {
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
#@months = ('January','February','March','April','May','June','July',
my @months = ('January','February','March','April','May','June','July', # 9/24/03
'August','September','October','November','December');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
$time = "$hour\:$min\:$sec";
$year += 1900;
$date = "$days[$wday], $months[$mon] $mday, $year at $time";
} # end sub
#######################################################################
# conf_number - generate a 5-digit random confirmation number
sub conf_number {
srand;
$conf=int(rand(100000));
} # end sub
###############################################################
sub footer2 {
print <<"eopage";
<HR><font class="footertext">$footer</font></TD>
</TR></TABLE>
</CENTER>
</BODY></HTML>
eopage
} # end sub
###############################################################
sub header2 {
print "Content-type: text/html\n\n";
print <<"eopage";
<HTML><HEAD>
<TITLE>$pagetitle</TITLE>
$pagecss
</HEAD>
<BODY $bgcolor $background>
<CENTER>
<TABLE class="tableborder">
<TR><TD class="pagetitlespecs">
$pagetitle</TD>
</TR>
<TR><TD class="tablecolor">
eopage
} # end sub
###############################################################
# month_txt - given #, return month
sub month_txt {
($_)=@_;
if ($_==1) {$month_txt = 'January';}
elsif ($_==2) {$month_txt='February';}
elsif ($_==3) {$month_txt='March';}
elsif ($_==4) {$month_txt='April';}
elsif ($_==5) {$month_txt='May';}
elsif ($_==6) {$month_txt='June';}
elsif ($_==7) {$month_txt='July';}
elsif ($_==8) {$month_txt='August';}
elsif ($_==9) {$month_txt='September';}
elsif ($_==10) {$month_txt='October';}
elsif ($_==11) {$month_txt='November';}
elsif ($_==12) {$month_txt='December';}
else {$month_txt='ERROR in Month';}
} # end sub
###############################################################################
sub open2 {
$iz=0;
while(-f $lockfile) {
sleep 2; # wait from 1 to 2 seconds to check again
$iz++;
if($iz > 5) {unlink($lockfile);} # delete, if file was not released within 5-10 seconds
}
open(LOCKFILE,">$lockfile") || die "Can't create lock file"; # create a lockfile
open($_[0], $_[1]) || return 0; # open the database, return failed if unavailable
return 1; # return passed
} # end sub
###########################################################
sub close2 {
close($_[0]);
close(LOCKFILE);
unlink($lockfile) || die "Can't delete lock file";
} # end sub
###########################################################
# Print html page when form data is missing
sub nox {
print <<"eopage";
<CENTER>
<H1><FONT COLOR="#FF0000">ERROR</FONT></H1></CENTER></TD>
</TR>
<TR>
<TD BGCOLOR="#FFFFFF">
<H3>"$missing" was not entered.</H3
This information is needed to process your registration.<BR>
Please use your browser's "back" button to return to the form and
enter "$missing."
eopage
&footer2;
exit;
} # end sub
#######################################################################
# Warn when file cannot be opened
# Uses string "$missing" which identifies the file being opened
sub punt {
$missing="ERROR: Could not open $missing<BR>Please notify system administrator.";
&header2;
print <<"eopage";
<CENTER>
<H2>$missing</H2>
</CENTER><BR>
eopage
&footer2;
exit;
} # end sub
#######################################################################
# print html for nav button(s)
sub nav {
print "<CENTER><A HREF=\"$adminURL\">
<IMG SRC=\"$adminbuttons/admin.gif\" BORDER=0 HEIGHT=36 WIDTH=238
ALT=\"Administrator's Console\"></A><BR>
<A HREF=\"$CGI_URL/registrar.pl\"><IMG SRC=\"$adminbuttons/registrar.gif\"
BORDER=0 HEIGHT=43 WIDTH=195 ALT=\"Registration Form\"></A><BR>
<A HREF=\"../../../help/Troubleshooting.html\">
<IMG SRC=\"$adminbuttons/help.gif\" BORDER=0 HEIGHT=36 WIDTH=238
ALT=\"Help & Troubleshooting\"></A><BR></CENTER>\n
";
}
########################################################################
# Remove registrants from the registry when marked as deleted or
# when the class no longer exists.
sub purge {
# READ IN ALL THE REGISTRY DATA
&getregistry;
# WRITE OUT THE VALID LINES
$paren='';
if($::debug) {$paren = " ($registry)";}
$missing = "Registry for$paren writing.";
if(!$flocking) {unless (&open2(OUT, ">$registry")) {&punt;}}
else {
unless (open(OUT, ">$registry")) {&punt;}
flock OUT, 2;
}
foreach (@people){
($thiscode) = split(/\t/);
if($thiscode =~ /event/i) {next;}
$save=1;
foreach $del (@deletecodes) {
if ($thiscode eq $del) {$save = 0;}
}
if($save && $okcodes[0]){
$save=0;
foreach $ok (@okcodes) {
if($thiscode eq $ok) {$save=1 ;}
}
}
if($save) {print OUT $_;}
}
if($flocking) {
flock OUT, 8;
close(OUT);
}
else {&close2(OUT);}
} # end sub
########################################################################
sub getevents {
$paren='';
if($::debug) {$paren = " ($eventlist)";}
$missing = "Events database$paren for reading.";
&db("GETEVENTS: Opening $eventlist");
if(!$flocking) {
&open2(IN,$eventlist) || &punt;
}
else {
unless (open(IN,$eventlist)) {&punt;}
flock IN, 2;
}
@events=<IN>;
if($flocking) {
flock IN, 8;
close(IN);
}
else {&close2(IN);}
return(1);
}
########################################################################
sub getregistry {
$paren='';
if($::debug) {$paren = " ($registry)";}
$missing = "Registry database$paren for reading.";
if(!$flocking) {
&open2(IN,$registry) || &punt;
}
else {
unless (open(IN,$registry)) {&punt;}
flock IN, 2;
}
@people=<IN>;
if($flocking) {
flock IN, 8;
close(IN);
}
else {&close2(IN);}
return(1);
}
########################################################################
#
# Encode a string as Base64
# Copyright 1995-1996, Karl Erickson (kae@citilink.com)
# Used with permission
sub b64encode {
&db("B64ENCODE: checkpoint1");
local ($_) = @_;
local ($chunk);
local ($result);
&db("<BR>B64ENCODE: checkpoint2");
$base64_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'abcdefghijklmnopqrstuvwxyz'.
'0123456789+/';
$base64_pad = '=';
&db("B64ENCODE: checkpoint3");
$uuencode_alphabet = q|`!"#$%&'()*+,-./0123456789:;<=>?|.
'@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'; # double that '\\'!
# $uuencode_pad = '`';
($tr_uuencode = ' '.$uuencode_alphabet) =~ s/\\/\\\\/;
$tr_base64 = 'A'.$base64_alphabet;
&db("B64ENCODE: checkpoint 4");
# break into chunks of 45 input chars, use perl's builtin
# uuencoder to convert each chunk to uuencode format,
# then kill the leading "M", translate to the base64 alphabet,
# and finally append a newline.
while (s/^((.|\n){45})//) {
$chunk = substr(pack("u", $&), $[+1, 60);
eval qq{
\$chunk =~ tr|$tr_uuencode|$tr_base64|;
};
$result .= $chunk . "\n";
}
&db("<BR>B64ENCODE: checkpoint 5");
# any leftover chars go onto a shorter line
# with uuencode padding converted to base64 padding
if ($_ ne '') {
$chunk = substr(pack("u", $_), $[+1,
int((length($_)+2)/3)*4 - (45-length($_))%3);
eval qq{
\$chunk =~ tr|$tr_uuencode|$tr_base64|;
};
$result .= $chunk . ($base64_pad x ((60 - length($chunk)) % 4)) . "\n";
}
# return result
$result;
} # end sub b64encode
########################################################################
########################################################################
# Activate this subroutine by removing all ##'s (leave all single #'s)
# Then insert the correct IP address and sender address (2 places)
##sub NTmailit {
## # Ref:
## #http://www.activestate.com/ActivePerl/docs/Perl-Win32/perlwin32faq4.html
## #http://www.geocities.com/SiliconValley/Park/8312/mail.htm
## use Net::SMTP;
## my $mailto = shift;
## my $mailfrom = shift;
## my $subject = shift;
## $smtp = Net::SMTP->new('180.119.101.125');# connect to SMTP server
## $smtp->mail($mailfrom); # sender's address
## $smtp->to($mailto); # recipient's address
## $smtp->data(); # Start the mail
## # Send the header.
## $smtp->datasend("To: $mailto\n");
## $smtp->datasend("From: $mailfrom\n");
## $smtp->datasend("Subject: $subject\n");
## $smtp->datasend("\n");
## # Send the body.
## $smtp->datasend($message);
## $smtp->dataend(); # Finish sending the mail
## $smtp->quit; # Close SMTP connection
## } # end sub NTmailit
########################################################################
########################################################################
# FOR BLAT USERS...
# Activate this subroutine by removing all ##'s (leave all single #'s)
# THE CALLS TO THIS ROUTINE MUST BE ALTERED TO SUIT THIS USAGE:
# USAGE: &mailit($recipients = shift,$fromsender,$subject,$message);
sub mailit {
my $recipients = shift;
my $fromsender = shift;
my $subject = shift;
my $message = shift;
## EDIT HERE ##
$blatfile = ' C:\inetpub\wwwroot\cgi-bin\registrar\blatfile.txt ';
$Blatpath = 'c:\winnt\system32\Blat.exe ';
$server = 'caexmta2.amd.com';
## END EDIT ##
open (BLAT,">$blatfile") || print "Error: cannot send email.<BR>\n";
print BLAT $message;
close BLAT;
# GET MESSAGE READY
$commandline = $Blatpath;
$commandline .= $blatfile;
$commandline .= "-s \"$subject\" " if $subject;
$commandline .= "-t \"$recipients\" " if $recipients;
$commandline .= "-f $fromsender " if $fromsender;
$commandline .= "-c $ccaddress " if $ccaddress;
$commandline .= "-server $server " if $server;
$commandline .= "-q " unless $db; # QUIET MODE
# SEND MAIL USING BLAT AND THE SYSTEM COMMAND
system($commandline);
} # end sub mailit
1;