#!/usr/bin/perl # This script is used to add news items to a given page # Please don't laugh at my perl, this was all developed as a perl learning # exercise. use strict; use CGI; # Setup the result of the CGI my($result, $area, $page, $path, $newsname, $newsline, $commit, $highest, $temp, $OUTPUT, $phase); $result = new CGI(); # The path is where to find the information to build the pages $path = "/home/httpd/html/"; $area = $result->param('area'); $page = $result->param('page'); $commit = $result->param('commit'); $phase = $result->param('phase'); # Output the standard HTML prelude, which includes stuff like the page title print $result->header; # If there are no arguements, then output an error message if(($area eq "") || ($page eq "")){ error("$path", "The address that was passed as input was malformed"); exit; } # If there is a commit parameter then we are commiting the information if($commit ne ""){ # Get the extra arguements $newsname = $result->param('newsitem'); if($newsname eq ""){ error("$path", "No news area name specified for modification."); exit; } # We are either testing the output to see what it will look like, or # actually commiting the item - check the phase if($phase eq "commit"){ dumpfile("$path/common/stdnews-start"); print "News item committed to $newsname"; dumpfile("$path/common/stdnews-divider"); # Prepare to do the actual committal $highest=`ls $path/news/$newsname | egrep -v "^9.*" | sort -r | head -1`; $highest=$highest + 1; $highest=sprintf("%06d", $highest); print "The news item is being committed, with it's news id being $highest"; print "

\n"; # Actually commit open OUTPUT, "> $path/news/$newsname/$highest" or die "Cannot open"; $temp = $result->param('title'); print OUTPUT "TITLE: $temp\n"; $temp = $result->param('postdate'); print OUTPUT "POSTDATE: $temp\n"; $temp = $result->param('postemail'); print OUTPUT "POSTER: $temp\n"; $temp = $result->param('poster'); print OUTPUT "POSTERNAME: $temp\nBEGIN CONTENT\n"; $temp = $result->param('content'); $temp =~ s/\'\'/\"/g; print OUTPUT "$temp"; close OUTPUT; print "Done writing to $path/news/$newsname/$highest"; dumpfile("$path/common/stdnews-end"); print $result->end_html; exit; } else{ print "\n\n"; # Output the news starter dumpfile("$path/common/stdnews-start"); $temp = $result->param('title'); print "$temp\n"; dumpfile("$path/common/stdnews-divider"); $temp = $result->param('postdate'); print "$temp - \n"; $temp = $result->param('postemail'); print ""; $temp = $result->param('poster'); print "$temp

\n"; $temp = $result->param('content'); print "$temp"; dumpfile("$path/common/stdnews-end"); print "


"; print $result->start_form; print $result->input( {-type=>'hidden', -name=>"phase", -value=>'commit'}); print $result->input( {-type=>'hidden', -name=>"area", -value=>$area}); print $result->input( {-type=>'hidden', -name=>"page", -value=>$page}); print $result->input( {-type=>'hidden', -name=>"newsitem", -value=>$newsname}); $temp = $result->param('title'); print $result->input( {-type=>'hidden', -name=>"title", -value=>$temp}); $temp = $result->param('postdate'); print $result->input( {-type=>'hidden', -name=>"postdate", -value=>$temp}); $temp = $result->param('poster'); print $result->input( {-type=>'hidden', -name=>"poster", -value=>$temp}); $temp = $result->param('postemail'); print $result->input( {-type=>'hidden', -name=>"postemail", -value=>$temp}); $temp = $result->param('content'); $temp =~ s/\"/\'\'/g; print $result->input( {-type=>'hidden', -name=>"content", -value=>$temp}); print $result->submit(-value=>" Are you sure? ", -name=>"commit"); print $result->end_html; exit; } } # Determine what news entry is on this page (assume only one per page) $newsline=`grep NEWS $path/$area/$page.conf`; chomp $newsline; $_=$newsline; # Check it is a valid line if(/^NEWS:[ \t]*(.*)[ \t]+(.*)[ \t]+(.*)/){ $newsname=$1; } else{ error("$path", "The news command on this page was malformed or not present. There is the possibility that the page you requested does not exist. The news line was \"$newsline\""); exit; } # We have found the name of the news item, now ask the user to enter the news # item print "Area: $area, Page: $page, News area: $newsname"; print $result->start_form; # We need to keep the results from last time print $result->input( {-type=>'hidden', -name=>"area", -value=>$area}); print $result->input( {-type=>'hidden', -name=>"page", -value=>$page}); print $result->input( {-type=>'hidden', -name=>"newsitem", -value=>$newsname}); print $result->input( {-type=>'hidden', -name=>"phase", -value=>'test'}); print "Title: "; print $result->input( {-type=>'text', -size=>50, -maxlength=>50, -name=>"title"}); print "
"; print "Postdate"; print $result->input( {-type=>'text', -size=>50, -maxlength=>50, -name=>"postdate", -value=>`date "+%d %B %Y"`}); print "
"; print "Poster"; print $result->input( {-type=>'text', -size=>50, -maxlength=>50, -name=>"poster", -value=>'Mikal'}); print "
"; print "Poster email"; print $result->input( {-type=>'text', -size=>50, -maxlength=>50, -name=>"postemail", -value=>'mikal@stillhq.com'}); print "
"; print "Content"; print $result->textarea( {-rows=>10, -cols=>50, -wrap=>'physical', -name=>"content"}); print $result->submit(-value=>" Commit ", -name=>"commit"); print $result->end_html; exit; # Dump the named file to stdout sub dumpfile{ my($file) = @_; my($FILEBIT); print "\n\n"; open FILEBIT, $file; while(){ print "$_"; } print "\n"; close(FILEBIT); } # Display an error message to the user sub error{ my($path, $message) = @_; dumpfile("$path/common/stdnews-start"); print "Error!"; dumpfile("$path/common/stdnews-divider"); print "$message\n"; print "

\n"; print "Please contact mikal\@stillhq.com and let him know the U RL you were trying to access (normally at the top of the page), and what link you clicked on to get here (i f there was one).\n"; dumpfile("$path/common/stdnews-end"); print $result->end_html; }