#!/usr/bin/perl use Env; #$override = "1"; $domain = "www.ywcaulstercounty.org"; $serverpath = "/home/sites/www.spinningwebz.com/web/addons/news"; $webpath = "/cgi-bin/news"; $blurbcount = 40; $template = "templates/template.shtml"; if ((-e "onserver")) {$lock = 1;} $mail_program = "/usr/sbin/sendmail -t"; &get_date; &ReadQuery; &GetCookies; $imagewidth= 150; $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 "BLURB") { open(FILE,"data/blurb.txt"); while() { $line = $_; chop $line; @dbf = split(/\t/,$line); $in{$dbf[0]} = $dbf[1]; } close(FILE); if ($in{'BLURBTEXT'} eq ""){$in{'BLURBTEXT'} = "more";} $outpage = "$in{'BLURB'} "; if ($in{'BLURBLINK'} ne "") { if (index(uc($in{'BLURBLINK'}),"HTTP") == -1) { $in{'BLURBLINK'} = "http://".$in{'BLURBLINK'}; } $outpage .= qq~$in{'BLURBTEXT'}\n~; } goto ExitOut; } if ($action eq "ECON") { open(FILE,"data/econ.txt"); while() { $line = $_; chop $line; @dbf = split(/\t/,$line); $in{$dbf[0]} = $dbf[1]; } close(FILE); if ($in{'ECONBLURBTEXT'} eq ""){$in{'ECONBLURBTEXT'} = "more";} $outpage = qq~News Alert: $in{'ECONBLURB'} ~; if ($in{'ECONBLURBLINK'} ne "") { if (index(uc($in{'ECONBLURBLINK'}),"HTTP") == -1) { $in{'ECONBLURBLINK'} = "http://".$in{'ECONBLURBLINK'}; } $outpage .= qq~

$in{'ECONBLURBTEXT'}\n~; } $outpage .= "

"; 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); if ($dbf[0] eq "HEADLINE") { $outpage = qq~$dbf[1]~; } } close(FILE); goto ExitOut; } $count = 1; if ($query{'COUNT'} ne ""){$count = $query{'COUNT'};} if ($count eq "ALL") { $count = 99999; $extra = ""; } else { $extra = qq~

Show All Headlines\n~; } open(FILE,"data/headlines.txt"); if ($lock){flock(FILE,2);} while() { $line = $_; chop $line; @dbf = split(/\t/,$line); if ($count > 0) { $thistdate = substr($dbf[2],-4).substr($dbf[2],0,2).substr($dbf[2],3,2); $stdbf[@stdbf] = qq~$thistdate\t$dbf[0]\t$dbf[2] $dbf[1]
~; $count--; } } @tdbf = sort {$b cmp $a} @stdbf; if (@tdbf > 0) { foreach $temp (@tdbf) { @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); $ttlip{'STORY'} =~ s/
/ /gi; @ttdbf = split(/\ /,$ttlip{'STORY'}); for($zz = 0;$zz < 8 && $zz < @ttdbf;$zz++) { $outpage .= $ttdbf[$zz]." "; } $outpage .= "...

"; } } close(FILE); $outpage .= $extra; if ($query{'TEMPLATE'} eq "YES") { $out = &LoadPage($template); $out =~ s//$outpage/gi; $outpage = $out; } goto ExitOut; } if ($action eq "SHOW" && $query{'ID'} ne "") { if ($query{'ID'} eq "-1") { open(FILE,"nextid.txt"); if ($lock){flock(FILE,2);} while() { $num = $_; chop $num; } close(FILE); # $num--; $query{'ID'} = $num; } 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~; } $outpage = &LoadPage($template); $out = qq~

$in{'HEADLINE'}

$in{'BYLINE'}

!PHOTO!$in{'DATE'} - $in{'STORY'}~; if ($in{'PHOTO'} ne "") { $temp = qq~~; } else { $temp = ""; } $out =~ s/!PHOTO!/$temp/gi; $sp_contact = ""; if ($in{'BLURBLINK'} ne "") { $moreinfo = "More Information"; if ($in{'BLURBTEXT'} ne "") { $moreinfo = $in{'BLURBTEXT'}; } if (index($in{'BLURBLINK'},"\@") != -1) { $sp_contact = qq~

$moreinfo~; } else { $wex = ""; if (index(lc($in{'BLURBLINK'}),"http") == -1) { $wex = "http://"; } $sp_contact = qq~

$moreinfo~; } } $out .= qq~$sp_contact

Show All Headlines\n~; $outpage =~ s//$out/gi; goto ExitOut; } if ($action eq "VIEW" && $query{'ID'} ne "") { if ($query{'ID'} eq "-1") { open(FILE,"nextid.txt"); if ($lock){flock(FILE,2);} while() { $num = $_; chop $num; } close(FILE); # $num--; $query{'ID'} = $num; } 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); $out = qq~

$in{'HEADLINE'}

$in{'BYLINE'}

!PHOTO!$in{'DATE'} - $in{'STORY'}

~; if ($in{'PHOTO'} ne "") { $temp = qq~~; } else { $temp = ""; } $out =~ s/!PHOTO!/$temp/gi; # $out .= qq~

Show All Headlines\n~; $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 "UPDATEBLURB") { &ReadParse; open(FILE,">data/blurb.txt"); print FILE "BLURB\t$in{'BLURB'}\n"; print FILE "BLURBLINK\t$in{'BLURBLINK'}\n"; print FILE "BLURBTEXT\t$in{'BLURBTEXT'}\n"; close(FILE); goto ShowList; } if ($action eq "UPDATEBLURBECON") { &ReadParse; open(FILE,">data/econ.txt"); print FILE "ECONBLURB\t$in{'ECONBLURB'}\n"; print FILE "ECONBLURBLINK\t$in{'ECONBLURBLINK'}\n"; print FILE "ECONBLURBTEXT\t$in{'ECONBLURBTEXT'}\n"; close(FILE); goto ShowList; } 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/newsmanager.pl?action=HEADLINE&ID=$dbf[0]"-->~; $temp =~ s/!CODE!/$code/gi; $code = qq~<!--#include virtual="$webpath/newsmanager.pl?action=SHOW&ID=$dbf[0]&MORE=YES"-->~; $temp =~ s/!BLURB!/$code/gi; $code = qq~<!--#include virtual="$webpath/newsmanager.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/newsmanager.pl?action=HEADLINE&COUNT=5"-->~; $in{'10'} = qq~<!--#include virtual="$webpath/newsmanager.pl?action=HEADLINE&COUNT=10"-->~; $in{'ALL'} = qq~<!--#include virtual="$webpath/newsmanager.pl?action=HEADLINE&COUNT=ALL"-->~; $in{'BLURBCODE'} = qq~<!--#include virtual="$webpath/newsmanager.pl?action=BLURB"-->~; $in{'RECENTSTORY'} = qq~<!--#include virtual="$webpath/newsmanager.pl?action=VIEW&ID=-1"-->~; open(FILE,"data/blurb.txt"); while() { $line = $_; chop $line; @dbf = split(/\t/,$line); $in{$dbf[0]} = $dbf[1]; } $in{'BLURB'} =~ s/
/\n/gi; close(FILE); open(FILE,"data/econ.txt"); while() { $line = $_; chop $line; @dbf = split(/\t/,$line); $in{$dbf[0]} = $dbf[1]; } $in{'ECONBLURB'} =~ s/
/\n/gi; close(FILE); $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{'BLURBLINK'} = $mreq->param("BLURBLINK"); $in{'BLURBTEXT'} = $mreq->param("BLURBTEXT"); $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'}\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{'BLURBLINK'} = $mreq->param("BLURBLINK"); $in{'BLURBTEXT'} = $mreq->param("BLURBTEXT"); $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'}"; } $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); 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,"