#!/usr/bin/perl use Env; #$override = "1"; $domain = "www.ywcaulstercounty.org"; $serverpath = "/home/sites/www.spinningwebz.com/web/addons/events"; $webpath = "/cgi-bin/calendar"; $blurbcount = 40; $template = "templates/template.shtml"; $CalCMD = "/usr/bin/cal"; $SSI = 1; $Border = 1; $Days = "Su Mo Tu We Th Fr Sa"; $imagewidth = 150; if ((-e "onserver")) {$lock = 1;} $mail_program = "/usr/sbin/sendmail -t"; &get_date; &ReadQuery; &GetCookies; $action = $query{'ACTION'}; #$action = "PREVIEW"; if ($action eq "EXIT") { &SetCookie("USERNAME",""); $outpage = &LoadPage("manager6.htm"); goto ExitOut; } if ($action eq "SIGNIN") { &ReadParse; open(FILE,"admin.%"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\=/,$line); $ain{$dbf[0]} = $dbf[1]; } close(FILE); if (uc($in{'USERNAME'}) eq uc($ain{'USERNAME'}) && $in{'PASSWORD'} eq $ain{'PASSWORD'}) { &SetCookie("USERNAME",$ain{'USERNAME'}); goto ShowList; } $outpage = &LoadPage("manager6.htm"); &SetCookie("USERNAME",""); goto ExitOut; } if ($action eq "HEADLINE") { if ($query{'ID'} ne "") { open(FILE,"data/$query{'ID'}.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); $in{$dbf[0]} = $dbf[1]; } $outpage = qq~$in{'DATE'}: $in{'HEADLINE'}~; close(FILE); goto ExitOut; } $count = 1; if ($query{'COUNT'} ne ""){$count = $query{'COUNT'};} if ($count eq "ALL"){$count = 99999;} $count = 99999; $when = $fulldate; if ($query{'WHEN'} ne ""){$when = $query{'WHEN'};} $when = substr($when,0,2)."-".substr($when,-4); @dbf = split(/\-/,$when); $pyear = $dbf[1]; $pmon = $dbf[0]; $pmon--; $nyear = $dbf[1]; $nmon = $dbf[0]; $nmon++; if ($pmon < 1){$pmon = 12;$pyear--;} if ($nmon > 12){$nmon = 1;$nyear++;} $pmon = sprintf("%02i",$pmon); $nmon = sprintf("%02i",$nmon); open(FILE,"data/headlines.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); if ($count > 0) { if (substr($dbf[2],0,2) eq substr($when,0,2) && substr($dbf[2],-4) eq substr($when,-4)) { $wtemp = qq~$dbf[2]: $dbf[1]
~; $wdbf[@wdbf] = $dbf[2]."\t".$dbf[0]."\t".$wtemp; # $outpage .= qq~$dbf[2]: $dbf[1]

~; $count--; $datecheck .= $dbf[2]."| "; goto SkipIt; } if (substr($when,0,2) ne substr($fulldate,0,2) && substr($when,-4) eq substr($fulldate,-4) && substr($fulldate,0,2) eq substr($dbf[2],0,2) && substr($fulldate,-4) eq substr($dbf[2],-4)) { $wtemp = qq~$dbf[2]: $dbf[1]
~; $tdbf[@tdbf] = $dbf[2]."\t".$dbf[0]."\t".$wtemp; # $extraout .= qq~$dbf[2]: $dbf[1]

~; $count--; } SkipIt: } } close(FILE); if (@tdbf > 0) { @dbf = sort @tdbf; foreach $temp (@dbf) { @sdbf = split(/\t/,$temp); $extraout .= $sdbf[2]; open(FILE,"data/$sdbf[1].txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @ttdbf = split(/\t/,$line); $ttlip{$ttdbf[0]} = $ttdbf[1]; } close(FILE); $extraout .= qq~$ttlip{'BYLINE'} ($ttlip{'TIME'}) ~; $ttlip{'STORY'} =~ s/
/ /gi; @ttdbf = split(/\ /,$ttlip{'STORY'}); for($zz = 0;$zz < 8 && $zz < @ttdbf;$zz++) { $extraout .= $ttdbf[$zz]." "; } $extraout .= "...

"; } } if (@wdbf > 0) { @dbf = sort @wdbf; foreach $temp (@dbf) { @sdbf = split(/\t/,$temp); $outpage .= $sdbf[2]; open(FILE,"data/$sdbf[1].txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @ttdbf = split(/\t/,$line); $ttlip{$ttdbf[0]} = $ttdbf[1]; } close(FILE); $outpage .= qq~$ttlip{'BYLINE'} ($ttlip{'TIME'}) ~; $ttlip{'STORY'} =~ s/
/ /gi; @ttdbf = split(/\ /,$ttlip{'STORY'}); for($zz = 0;$zz < 8 && $zz < @ttdbf;$zz++) { $outpage .= $ttdbf[$zz]." "; } $outpage .= "...

"; } } if ($extraout ne ""){$extraout = "This Month:
\n".$extraout;} $myoutpage = &RetCal($CalCMD, $when, $Border); $myoutpage =~ s//$outpage$extraout/gi; $outpage = $myoutpage; if ($query{'TEMPLATE'} eq "YES") { $out = &LoadPage($template); $out =~ s//$outpage/gi; $outpage = $out; } goto ExitOut; } if ($action eq "SHOW" && $query{'ID'} ne "") { $thisdate = "99999999"; $thisid = 0; if ($query{'ID'} eq "CURRENT") { open(FILE,"data/headlines.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); @wday = split(/\//,$dbf[2]); $twday = $wday[2].$wday[0].$wday[1]; if((($twday * 1) >= ($compdate * 1)) && (($twday * 1) <= ($thisdate * 1))) { $thisid = $dbf[0]; $query{'ID'} = $dbf[0]; $thisdate = $twday; } } close(FILE); } open(FILE,"data/$query{'ID'}.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); $in{$dbf[0]} = $dbf[1]; } close(FILE); if ($query{'MORE'} eq "YES") { @dbf = split(/\ /,$in{'STORY'}); $in{'STORY'} = ""; # for($i = 0;$i < $blurbcount;$i++) # { # $in{'STORY'} .= "$dbf[$i] "; # } $in{'STORY'} .= qq~more information~; } $outpage = &LoadPage($template); if ($in{'TIME'} ne ""){$in{'TIME'} = " ".$in{'TIME'};} $link = ""; if ($in{'BLURBTEXT'} eq ""){$in{'BLURBTEXT'} = "more";} if ($in{'BLURBLINK'} ne "") { if (index(uc($in{'BLURBLINK'}),"HTTP") == -1) { $in{'BLURBLINK'} = "http://".$in{'BLURBLINK'}; } $link = qq~

$in{'BLURBTEXT'}\n~; } $sponsor = ""; if ($in{'SPONSOR'} ne ""){$sponsor = "

Sponsored by: $in{'SPONSOR'}\n";} $out = qq~

!PHOTO!$in{'HEADLINE'}

$in{'BYLINE'}$sponsor

$in{'DATE'}$in{'TIME'} - $in{'STORY'} $link

~; if ($in{'PHOTO'} ne "") { $temp = qq~~; } else { $temp = ""; } if ($query{'MORE'} eq "YES"){$temp = "";} $out =~ s/!PHOTO!/$temp/gi; $thistempdate = substr($in{'DATE'},-4).substr($in{'DATE'},0,2).substr($in{'DATE'},3,2); $out .= qq~

\n~; #if ($thistempdate * 1 >= $compdate) #{ # $out .= qq~Register for this event

\n~; #} $out .= qq~Show All Events\n~; $outpage =~ s//$out/gi; if ($query{'TEMPLATE'} eq "NO"){$outpage = $out;} goto ExitOut; } open(FILE,"admin.%"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\=/,$line); $ain{$dbf[0]} = $dbf[1]; } close(FILE); if ($override == 1){$mycookies{'USERNAME'} = $ain{'USERNAME'};} if ($mycookies{'USERNAME'} ne $ain{'USERNAME'}) { &SetCookie("USERNAME",""); $outpage = &LoadPage("manager6.htm"); goto ExitOut; } if ($action eq "EDIT") { $outpage = &LoadPage("manager4.htm"); open(FILE,"data/$query{'ID'}.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); if ($dbf[0] eq "PHOTO") { if ($dbf[1] ne "") { $temp = qq~
Check here to delete this photo~; $outpage =~ s/!PHOTO!/$temp/gi; $outpage =~ s/!PHOTONAME!/$dbf[1]/gi; } else { $outpage =~ s/!PHOTONAME!//gi; $outpage =~ s/!PHOTO!//gi; } } $dbf[1] =~ s/
/\n/gi; $in{$dbf[0]} = $dbf[1]; } close(FILE); @dbf = split(/\//,$in{'DATE'}); $in{'MONTH'} = $dbf[0]; $in{'DAY'} = $dbf[1]; $in{'YEAR'} = $dbf[2]; $outpage = &FillData($outpage); $outpage =~ s/!ID!/$query{'ID'}/gi; goto ExitOut; } if ($action eq "PREVIEW") { $outpage = &LoadPage("manager3.htm"); open(FILE,"data/$query{'ID'}.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); if ($dbf[0] eq "PHOTO" && $dbf[1] ne "") { $dbf[1] = qq~~; } $outpage =~ s/!$dbf[0]!/$dbf[1]/gi; } close(FILE); $outpage =~ s/!ID!/$query{'ID'}/gi; goto ExitOut; } if ($action eq "KILL") { open(FILE,"data/headlines.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); if ($dbf[0] ne $query{'ID'}) { # $line = "$in{'ID'}\t$in{'HEADLINE'}\t$in{'DATE'}"; $slines .= $line."\n"; } } close(FILE); open(FILE,">data/headlines.txt"); if ($lock){flock(FILE,2);} print FILE $slines; close(FILE); rename("data/$query{'ID'}.txt","data/$tempsession.txt"); goto ShowList; } if ($action eq "DELETE") { $outpage = &LoadPage("manager5.htm"); open(FILE,"data/$query{'ID'}.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); if ($dbf[0] eq "PHOTO" && $dbf[1] ne "") { $dbf[1] = qq~~; } $outpage =~ s/!$dbf[0]!/$dbf[1]/gi; } close(FILE); $outpage =~ s/!ID!/$query{'ID'}/gi; goto ExitOut; } if ($action eq "ADMIN") { ShowList: $outpage = &LoadPage("manager1.htm"); require "tables.pl"; $string = $tablestart; $color = 0; open(FILE,"data/headlines.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); $temp = $tablerow; $temp =~ s/!COLOR!/$tablecolor[$color]/gi; $color = (!$color * 1); $temp =~ s/!ID!/$dbf[0]/gi; $temp =~ s/!HEADLINE!/$dbf[1]/gi; $temp =~ s/!DATE!/$dbf[2]/gi; $code = qq~<!--#include virtual="$webpath/calendar.pl?action=HEADLINE&ID=$dbf[0]"-->~; $temp =~ s/!CODE!/$code/gi; $code = qq~<!--#include virtual="$webpath/calendar.pl?action=SHOW&ID=$dbf[0]&MORE=YES"-->~; $temp =~ s/!BLURB!/$code/gi; $code = qq~<!--#include virtual="$webpath/calendar.pl?action=SHOW&ID=$dbf[0]"-->~; $temp =~ s/!FULLSTORY!/$code/gi; $string .= $temp; } close(FILE); $string .= $tableend; $outpage =~ s//$string/gi; $in{'5'} = qq~<!--#include virtual="$webpath/calendar.pl?action=HEADLINE&COUNT=5"-->~; $in{'10'} = qq~<!--#include virtual="$webpath/calendar.pl?action=HEADLINE&COUNT=10"-->~; $in{'ALL'} = qq~<!--#include virtual="$webpath/calendar.pl?action=HEADLINE&COUNT=ALL"-->~; $outpage = &FillData($outpage); goto ExitOut; } if ($action eq "ADD") { use CGI; $mreq = new CGI; $in{'HEADLINE'} = $mreq->param("HEADLINE"); $in{'BYLINE'} = $mreq->param("BYLINE"); $in{'DATE'} = $mreq->param("MONTH")."/".$mreq->param("DAY")."/".$mreq->param("YEAR"); $in{'STORY'} = $mreq->param("STORY"); $in{'TIME'} = $mreq->param("TIME"); $in{'SPONSOR'} = $mreq->param("SPONSOR"); $in{'BLURBLINK'} = $mreq->param("BLURBLINK"); $in{'BLURBTEXT'} = $mreq->param("BLURBTEXT"); $in{'COST'} = $mreq->param("COST"); $tt = chr(13); $in{'STORY'} =~ s/\n/
/gi; $in{'STORY'} =~ s/$tt//gi; $in{'STORY'} =~ s/\t/ /gi; $ID = &GetNextID; $in{'PHOTO'} = &UploadFile(); $data = ""; foreach $temp (keys(%in)) { $data .= "$temp\t$in{$temp}\n"; } &SaveFile("data/$ID.txt",$data); open(FILE,"data/headlines.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; $slines .= $line; } close(FILE); open(FILE,">data/headlines.txt"); if ($lock){flock(FILE,2);} print FILE "$ID\t$in{'HEADLINE'}\t$in{'DATE'}\t$in{'COST'}\n"; print FILE $slines; close(FILE); goto ShowList; } if ($action eq "UPDATE") { use CGI; $mreq = new CGI; $in{'HEADLINE'} = $mreq->param("HEADLINE"); $in{'BYLINE'} = $mreq->param("BYLINE"); $in{'DATE'} = $mreq->param("MONTH")."/".$mreq->param("DAY")."/".$mreq->param("YEAR"); $in{'STORY'} = $mreq->param("STORY"); $in{'OLDPHOTO'} = $mreq->param("OLDPHOTO"); $in{'DELETE'} = $mreq->param("DELETE"); $in{'ID'} = $mreq->param("ID"); $in{'TIME'} = $mreq->param("TIME"); $in{'SPONSOR'} = $mreq->param("SPONSOR"); $in{'BLURBLINK'} = $mreq->param("BLURBLINK"); $in{'BLURBTEXT'} = $mreq->param("BLURBTEXT"); $in{'COST'} = $mreq->param("COST"); $tt = chr(13); $in{'STORY'} =~ s/\n/
/gi; $in{'STORY'} =~ s/$tt//gi; $in{'STORY'} =~ s/\t/ /gi; $ID = $in{'ID'}; if ($in{'DELETE'} ne "") { unlink("data/photos/$in{'DELETE'}"); $in{'OLDPHOTO'} = ""; } $in{'PHOTO'} = &UploadFile(); if ($in{'PHOTO'} eq ""){$in{'PHOTO'} = $in{'OLDPHOTO'};} $data = ""; foreach $temp (keys(%in)) { $data .= "$temp\t$in{$temp}\n"; } &SaveFile("data/$ID.txt",$data); open(FILE,"data/headlines.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); if ($dbf[0] eq $in{'ID'}) { $line = "$in{'ID'}\t$in{'HEADLINE'}\t$in{'DATE'}\t$in{'COST'}"; } $slines .= $line."\n"; } close(FILE); open(FILE,">data/headlines.txt"); if ($lock){flock(FILE,2);} print FILE $slines; close(FILE); goto ShowList; } &ReadParse; ExitOut: while(index($outpage,"[#") != -1) { $a = index($outpage,"[#"); $start = substr($outpage,0,$a); $finis = substr($outpage,$a + 2); $a = index($finis,"#]"); $num = substr($finis,0,$a); $img = qq~

~; $outpage = $start.$img.substr($finis,$a + 2); } print "Content-type: text/html\n$THEcookie\n\n"; print $outpage; exit; # Get cookies using $mycookies{} sub GetCookies { my $cookie = ""; my $value = ""; foreach (split(/; /,$ENV{'HTTP_COOKIE'})) { ($cookie,$value) = split(/=/); $cookie = uc($cookie); $mycookies{$cookie} = $value; } return; } # Strip HTML from passed variable sub StripHtml { my $string = shift; my $result = $string; $result =~ s/<.+?>\|//gi; return ($result); } # Read the command line into $query{} sub ReadQuery { local (*query) = @_ if @_; $query = $ENV{'QUERY_STRING'}; @query = split(/&/,$query); foreach $i (0 .. $#query) { # Convert plus's to spaces $query[$i] =~ s/\+/ /gi; # Remove any HTML stuff $query[$i] = StripHtml($query[$i]); # Split into key and value. ($key,$val) = split(/=/,$query[$i],2); # splits on the first =. # Convert %XX from hex numbers to alphanumeric $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; $key = uc($key); $val =~ s/!/! /gi; $val =~ s/! /! /gi; $val = &Shrink($val); # Associate key and value # \0 is the multiple separator $query{$key} .= "\0" if (defined($query{$key})); if (index($key,".") == -1) { $query{$key} .= uc($val); } else { $query{$key} .= $val; } } return length($query); } # Read the passed form fields into $in{} sub ReadParse { my $results = ""; my $tt = ""; local (*in) = @_ if @_; read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); @in = split(/&/,$in); $tt = chr(13); foreach $i (0 .. $#in) { # Convert plus's to spaces $in[$i] =~ s/\+/ /gi; # Remove any HTML stuff $in[$i] = StripHtml($in[$i]); # Split into key and value. ($key,$val) = split(/=/,$in[$i],2); # splits on the first =. # Convert %XX from hex numbers to alphanumeric $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; $key = uc($key); if ($key eq "ACTION") { $val = uc($val); } $val =~ s/\t/ /gi; $val =~ s/\n/
/gi; $val =~ s/$tt//gi; $val =~ s/ / /gi; # Associate key and value # \0 is the multiple separator $in{$key} .= "\0" if (defined($in{$key})); $in{$key} .= &Shrink($val); $in{$key} =~ s/þ//gi; } return ($results); } # Remove leading and trailing spaces sub Shrink { my $results = shift; while(substr($results,0,1) eq " ") { $results = substr($results,1); } while(substr($results,-1) eq " ") { $results = substr($results,0,length($results) - 1); } return ($results); } # Load page passed, only inside of BODY tags sub LoadBlankPage { my $page = shift; my $results = &LoadPage($page); $results = substr($results,index($results,"") + 1); $results = substr($results,0,index($results,"; close(LPFILE); $results = join(' ',@LPFILE); return ($results); } # Set cookies using $mycookies{} sub SetCookie { my $cookie = shift; my $value = shift; $THEcookie = $THEcookie."Set-Cookie: $cookie=$value; expires=$cookiedate; path=\/; domain=$domain;\n"; $mycookies{$cookie} = $value; return; } # Get todays date, cookie expire date, log date etc sub get_date { my @daynames = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); my @monthnames = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); my @daysinmonth = (31,28,31,30,31,30,31,31,30,31,30,31); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $thour = $hour; if ($year > 100) { $year = $year - 100; } if ($hour < 12 || $hour == 23) { $zz = "am"; } else { $zz = "pm"; } if ($hour > 12) { $hour = $hour - 12; } $cwday = $wday + 1; if ($cwday == 7){$cwday = 0;} $cmday = $mday + 1; $cmon = $mon; $cyear = $year; if ($cmday > $daysinmonth[$mon]){$cmday = 1;$cmon++;} if ($cmon > 11){$cmon = 0;$cyear++;} $cookiedate = "$daynames[$cwday], $cmday-$monthnames[$cmon]-20".sprintf("%02i %02i:%02i:%02i GMT",$cyear,$thour,$min,$sec); $today = sprintf("%02i/%02i/%02i",$mon + 1,$mday,$year); $fulldate = sprintf("%02i/%02i/20%02i",$mon + 1,$mday,$year); $yeardate = $year * 365 + $yday; $now = sprintf("%02i:%02i:%02i",$thour,$min,$sec); $tempsession = sprintf("%02i%02i%02i%02i%02i%02i",$year,$mon + 1,$mday,$hour,$min,$sec); $logdate = sprintf("%02i%02i%02i",$mon + 1,$mday,$year); $compdate = sprintf("20%02i%02i%02i",$year,$mon + 1,$mday); $mon++; return; } sub GetTemplate { my $content = shift; my $results = ""; my $t = ""; my $template = ""; if (index($content,""); $template = substr($template,0,$t).".htm"; } else { $template = "default.htm"; } $results = &LoadPage($template); return ($results); } sub GetTempSession { my $count = 0; while(-e "temp/$tempsession$count") { $count++; } open(FILE,">temp/$tempsession$count"); if ($lock){flock(FILE,2);} close(FILE); chmod(0755, "temp/$tempsession$count"); return ("$tempsession$count"); } sub FillData { my $what = shift; my $temp = ""; my $t2 = ""; my $t3 = ""; my $beg = ""; my $fin = ""; my $part = ""; foreach $temp (keys(%in)) { if (index($what,""); $fin = substr($part,$t2); $part = substr($part,0,$t2); if (index($part,"