#!/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( $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( ";
}
}
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( $in{'BYLINE'} !PHOTO!$in{'DATE'} - $in{'STORY'}~;
if ($in{'PHOTO'} ne "")
{
$temp = 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( $in{'BYLINE'} !PHOTO!$in{'DATE'} - $in{'STORY'} ~;
if ($in{'PHOTO'} ne "")
{
$temp = qq~ Show All Headlines\n~;
$outpage = $out;
goto ExitOut;
}
open(FILE,"admin.%");
if ($lock){flock(FILE,2);}
while(
Show All Headlines\n~;
}
open(FILE,"data/headlines.txt");
if ($lock){flock(FILE,2);}
while(
~;
$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(
/ /gi;
@ttdbf = split(/\ /,$ttlip{'STORY'});
for($zz = 0;$zz < 8 && $zz < @ttdbf;$zz++)
{
$outpage .= $ttdbf[$zz]." ";
}
$outpage .= "...$in{'HEADLINE'}
~;
}
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~
$in{'HEADLINE'}
~;
}
else
{
$temp = "";
}
$out =~ s/!PHOTO!/$temp/gi;
# $out .= 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(~;
}
$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(
~;
}
$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(
/\n/gi;
close(FILE);
open(FILE,"data/econ.txt");
while(
/\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(
/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(
~;
$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,"