#!/usr/bin/perl $Password = "woods"; $BaseDir = "/InetPub/wwwroot/LostAcresResort/rates"; $BaseURL = "http://www.lostacresresort.com/rates"; $CGI_URL = "http://www.lostacresresort.com/rates/rates.cgi"; $DataFile = "rates.dta"; $allow_html = 1; # Set to 1 to allow html commands in the text require '/InetPub/wwwroot/ResortWebOnline/cgi-bin/subroutines/specials.lib'; if ($ENV{'QUERY_STRING'} ne "") { # Parse the query string &UnWeb1; $Q = 1; } else { &UnWeb; $Q = 0; } if ($in{'action'} eq "add") { # Add a story header('Add Stories'); body('#D2B48C'); print "\n"; print "
\n"; print "\n"; $Filename = filename(); print "\n"; print "

\n"; print "\n"; print "

To add a new story to the system, enter your password,\n"; print "the headline, the lead\n"; print "paragraph (limited to 40 characters), and the body of the story. The headline and lead\n"; print "paragraph will be shown to users in the list of all stories available.

\n"; print "\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

Password:

Headline:

Lead Paragraph:

Body of Story:

\n"; print "

\n"; print "\n"; print "

\n"; print "

\n"; print "\n"; print "
\n"; footer(); } if ($in{'action'} eq "add2") { # Check to see that all information was filled in if (($in{'Filename'} eq "") || ($in{'Headline'} eq "") || ($in{'Lead'} eq "") || ($in{'Body'} eq "") || ($in{'Password'} eq "")) { # Not all information was filled in &Error (Information_Incomplete); } unless ($in{'Password'} eq $Password) { # Password is incorrect &Error ("Password_Incorrect"); } # Write the information to the file # Write the Headline, Lead Paragraph, and Body for future editing open (NEWFILE,">$BaseDir/$in{'Filename'}.head"); print NEWFILE "$in{'Headline'}"; close NEWFILE; open (NEWFILE,">$BaseDir/$in{'Filename'}.lead"); print NEWFILE "$in{'Lead'}"; close NEWFILE; open (NEWFILE,">$BaseDir/$in{'Filename'}.body"); print NEWFILE "$in{'Body'}"; close NEWFILE; # Expand the comments for html $in{'Body'} =~ s/\n/
\n/go; open (NEWFILE,">$BaseDir/$in{'Filename'}.html"); $Header = head1($in{'Headline'}); print NEWFILE "$Header"; $date = date(); print NEWFILE "Posted on: $date

\n"; print NEWFILE "

$in{'Headline'}

\n"; print NEWFILE "

$in{'Lead'}

\n"; print NEWFILE "$in{'Body'}

\n"; $Footer = foot1(); print NEWFILE "$Footer"; close NEWFILE; # Now update the index file for that directory. open(GW,">>$BaseDir/$DataFile"); print GW "$in{'Headline'}\t$in{'Filename'}.html\t$in{'Lead'}\n"; close GW; header('Stories Posted'); body('#FFFFFF'); hr(); print "

Stories Posted!

\n"; print "The stories entitled $in{'Headline'} has been posted to directory $BaseDir/$in{'Filename'}.

\n"; footer(); } if ($in{'action'} eq "delete") { # Delete a story # Read in the datafile open (DATA, "$BaseDir/$DataFile"); @Data = ; close DATA; $Count = 0; foreach $Line (@Data) { @Temp = split (/\t/, $Line); $StoryLine[$Count] = "

\n"; print "\n"; print "

\n"; print "\n"; print "

To delete a story from the system, select the story\n"; print "below and hit the delete button.

\n"; print "\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

Please Enter Your Password:

Choose the story to delete:

\n"; print "

\n"; print "\n"; print "

\n"; print "

\n"; print "\n"; print "
\n"; footer(); } if ($in{'action'} eq "delete2") { if (($in{'Password'} eq "") || ($in{'Filename'} eq "")) { &Error ("Information_Incomplete"); } unless ($in{'Password'} eq $Password) { # The password doesn't match &Error ("Password_Incorrect"); } unlink ("$BaseDir/$in{'Filename'}"); $fname = "$in{'Filename'}"; @fname = split (/.html/ , $fname); unlink ("$BaseDir/$fname[0].head"); unlink ("$BaseDir/$fname[0].lead"); unlink ("$BaseDir/$fname[0].body"); # Now update the index file for that directory. open(GW,"$BaseDir/$DataFile"); @lines = ; close GW; open (GB,">$BaseDir/$DataFile"); foreach $line (@lines) { chop $line; @TempData = split (/\t/, $line); if ($TempData[1] ne "$in{'Filename'}") { print GB "$line\n"; } } close GB; header('Story Deleted'); body('#FFFFFF'); hr(); print "

Story Deleted!

\n"; print "The file $in{'Filename'} has been deleted.

\n"; footer(); } if ($in{'action'} eq "change") { # Change a story # Read in the datafile open (DATA, "$BaseDir/$DataFile"); @Data = ; close DATA; $Count = 0; foreach $Line (@Data) { @Temp = split (/\t/, $Line); $StoryLine[$Count] = "

\n"; print "\n"; print "

\n"; print "\n"; print "

To change a story from the system, select the story\n"; print "below and hit the change button.

\n"; print "\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

Please Enter Your Password:

Choose the story to change:

\n"; print "

\n"; print "\n"; print "

\n"; print "

\n"; print "\n"; print "
\n"; footer(); } if ($in{'action'} eq "change2") { # Change a story $fname = "$in{'Filename'}"; @fname = split (/.html/ , $fname); open (HEAD, "$BaseDir/$fname[0].head"); @Head = ; close HEAD; open (LEAD, "$BaseDir/$fname[0].lead"); @Lead = ; close LEAD; open (BODY, "$BaseDir/$fname[0].body"); @Body = ; close BODY; foreach (@Body) { $_ =~ s/\n//go; $alpha = $alpha . $_; } header('Change Stories'); body('#D2B48C'); print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "

\n"; print "\n"; print "

To change a story, \n"; print "edit the headline, the lead\n"; print "paragraph (limited to 40 characters), and the body of the story. The headline and lead\n"; print "paragraph will be shown to users in the list of all stories available.

\n"; print "\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

Headline:

Lead Paragraph:

Body of Story:

\n"; print "

\n"; print "\n"; print "

\n"; print "

\n"; print "\n"; print "
\n"; footer(); } if ($in{'action'} eq "change3") { # Check to see that all information was filled in if (($in{'Filename'} eq "") || ($in{'Headline'} eq "") || ($in{'Lead'} eq "") || ($in{'Body'} eq "") || ($in{'Password'} eq "")) { # Not all information was filled in &Error (Information_Incomplete); } unless ($in{'Password'} eq $Password) { # Password is incorrect &Error ("Password_Incorrect"); } # Write the information to the file # Write the Headline, Lead Paragraph, and Body for future editing $fname = "$in{'Filename'}"; @fname = split (/.html/ , $fname); open (NEWFILE,">$BaseDir/$fname[0].head"); print NEWFILE "$in{'Headline'}"; close NEWFILE; open (NEWFILE,">$BaseDir/$fname[0].lead"); print NEWFILE "$in{'Lead'}"; close NEWFILE; open (NEWFILE,">$BaseDir/$fname[0].body"); print NEWFILE "$in{'Body'}"; close NEWFILE; # Expand the comments for html $in{'Body'} =~ s/\n/
\n/go; open (NEWFILE,">$BaseDir/$in{'Filename'}"); $Header = head1($in{'Headline'}); print NEWFILE "$Header"; $date = date(); print NEWFILE "Posted on: $date

\n"; print NEWFILE "

$in{'Headline'}

\n"; print NEWFILE "

$in{'Lead'}

\n"; print NEWFILE "$in{'Body'}

\n"; $Footer = foot1(); print NEWFILE "$Footer"; close NEWFILE; # Now update the index file for that directory. open(GW,"$BaseDir/$DataFile"); @lines = ; close GW; open (GB,">$BaseDir/$DataFile"); foreach $line (@lines) { chop $line; @TempData = split (/\t/, $line); if ($TempData[1] ne "$in{'Filename'}") { print GB "$line\n"; } } close GB; open(GW,">>$BaseDir/$DataFile"); print GW "$in{'Headline'}\t$in{'Filename'}\t$in{'Lead'}\n"; close GW; header('Stories Changed'); body('#FFFFFF'); hr(); print "

Stories Changed!

\n"; print "The stories entitled $in{'Headline'} has been changed $BaseDir/$in{'Filename'}.

\n"; footer(); } if ($in{'action'} eq "") { # Display all available stories # Open the datafile open (DATA, "$BaseDir/$DataFile"); @Data = ; close DATA; header('Available Stories'); body('#D2B48C'); print "

Click on a headline to view the full article:

\n"; foreach $Story (@Data) { @Temp = split (/\t/, $Story); print "

$Temp[0]

\n"; print "$Temp[2]


\n"; } footer(); } if ($in{'action'} eq "view") { print "Location: $BaseURL/$in{'item'}\n\n"; } sub Error { local($UserError) = @_; if ($UserError eq "Information_Incomplete") { header('Information Incomplete'); body('#FFFFFF'); hr(); print "

Information Incomplete!

\n"; print "You did not fill out all required information. Please go back and make sure every field is filled in before submitting.

\n"; footer(); exit; } if ($UserError eq "Password_Incorrect") { header('Incorrect password'); body('#FFFFFF'); hr(); print "

Incorrect Password!

\n"; print "The password you entered was incorrect. Please go back and re-enter your password.

\n"; footer(); exit; } } sub UnWeb1 { # Get the input # read(STDIN, $buffer, $ENV{'QUERY_STRING'}); # Split the name-value pairs @pairs = split(/&/, $ENV{'QUERY_STRING'}); 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; $value =~ s///g; if ($allow_html != 1) { $value =~ s/<([^>]|\n)*>//g; } else { unless ($name eq 'body') { $value =~ s/<([^>]|\n)*>//g; } } $in{$name} = $value; } } sub UnWeb { # 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; $value =~ s///g; if ($AllowHTML != 1) { $value =~ s/<([^>]|\n)*>//g; } else { unless ($name eq 'body') { $value =~ s/<([^>]|\n)*>//g; } } $in{$name} = $value; } }