#!/usr/local/bin/perl ########################################################################## # COPYRIGHT NOTICE: # # Copyright FocalMedia.Net 2001 # # This program is free to use for commercial and non commercial use. # This script may be used and modified by anyone, so long as this copyright # notice and the header above remain intact. Selling the code for this # program without prior written consent is expressly forbidden. # # This program is distributed "as is" and without warranty of any # kind, either express or implied. # ########################################################################## &get_env; &get_setup; $cgidir = "$cgidir/guestbook.cgi"; print "Content-type: text/html\n\n"; if ($fields{'fct'} eq "post"){&post_operation;} if ($fields{'fct'} eq ""){&display_guestbook;} exit; ############################################################################################ sub display_guestbook { $fsize1 = (-s "$html_loc/main_layout.html"); open (RVF, "$html_loc/main_layout.html"); read(RVF,$ml,$fsize1); close (RVF); if ($imagep eq "Y"){$ml = &InsertImages($ml);} $ml =~ s/!!cgiscript!!/$cgidir/g; $fsize1 = (-s "$html_loc/listings.html"); open (RVF, "$html_loc/listings.html"); read(RVF,$listformat,$fsize1); close (RVF); open (DT, "data.txt"); while (defined($line=
)) { if (length($line) > 4) { ($name, $msg, $email, $date) =split(/::-::/,$line); $listings = $listformat; if ($email ne "") {$name = "$name";} $listings =~ s/!!from!!/$name/g; $listings =~ s/!!date!!/$date/g; $listings =~ s/!!comment!!/$msg/g; $gentries = $gentries . $listings; } } close (DT); $listformat = &strip_html_body_tags ($listformat); $ml =~ s/!!guest_book_entries!!/$gentries/g; print "$ml"; } sub post_operation { if ($fields{'name'} eq "") { &post_prb ("You have to supply a name to post."); } if ($fields{'comment'} eq "") { &post_prb ("You have to supply a comment to post."); } $fields{'comment'} =~ s/\n/
/g; $fsize1 = (-s "data.txt"); open (RVF, "data.txt"); read(RVF,$tdata,$fsize1); close (RVF); ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime(); $year = "20" . substr($year, 1, 2); $mon = &decode_month($mon); $wday = &decode_weekday($wday); $today = "$wday $mday $mon $year"; $fields{'comment'} =~ s/\n//g; $crit = chr(10); $fields{'comment'} =~ s/$crit//g; $crit = chr(13); $fields{'comment'} =~ s/$crit//g; open (DT, "> data.txt"); print DT $fields{'name'} . "::-::" . $fields{'comment'} . "::-::" . $fields{'email'} . "::-::" . $today . "\n" . $tdata; close (DT); $fsize1 = (-s "$html_loc/thanks.html"); open (RVF, "$html_loc/thanks.html"); read(RVF,$ml,$fsize1); close (RVF); if ($imagep eq "Y"){$ml = &InsertImages($ml);} $ml =~ s/!!cgiscript!!/$cgidir/g; print $ml; exit; } sub post_prb { my ($problem) = @_; $fsize1 = (-s "$html_loc/problem.html"); open (RVF, "$html_loc/problem.html"); read(RVF,$ml,$fsize1); close (RVF); if ($imagep eq "Y"){$ml = &InsertImages($ml);} $ml =~ s/!!problem!!/$problem/g; print "$ml"; exit; } sub get_env { if ($ENV{'QUERY_STRING'} ne "") { $temp = $ENV{'QUERY_STRING'}; } else { read(STDIN, $temp, $ENV{'CONTENT_LENGTH'}); } @pairs=split(/&/,$temp); foreach $item(@pairs) { ($key,$content)=split (/=/,$item,2); $content=~tr/+/ /; $content=~ s/%(..)/pack("c",hex($1))/ge; $fields{$key}=$content; } } sub get_setup { #### GET CONFIGURATION ######################################################## $setupcfg = "setup.cfg"; $exists = (-e "$setupcfg"); if ($exists > 0) { open (STP, "$setupcfg"); while (defined($line=)) { if ($line =~ m/#/g) { $r = pos($line); $line = substr($line, 0, $r - 1); } $line =~ s/\n//g; if ($line =~ /CGIURL/){$line =~ s/CGIURL//g; $line =~ s/ //g; $cgidir = $line;} if ($line =~ /PASSWORD/){$line =~ s/PASSWORD//g; $line =~ s/ //g; $password = $line;} if ($line =~ /USERNAME/){$line =~ s/USERNAME//g; $line =~ s/ //g; $username = $line;} if ($line =~ /HTML_LOC/){$line =~ s/HTML_LOC//g; $line =~ s/ //g; $html_loc = $line;} if ($line =~ /HTML_URL/){$line =~ s/HTML_URL//g; $line =~ s/ //g; $html_url = $line;} if ($line =~ /IMAGEP/){$line =~ s/IMAGEP//g; $line =~ s/ //g; $imagep = $line;} #chdir("$scripts_loc"); } close (STP); } else { print "Content-type: text/html\n\n"; print "Could not find setup.cfg"; exit; } #### END CONFIGURATION ######################################################## } sub InsertImages { my ($html) = @_; if ($html =~ /= 0) { $ichar = substr($aline, $r, 1); $r = $r - 1; if (($ichar eq "\\") or ($ichar eq "/")) { $sb = "true"; } if (($ichar eq "=") or ($ichar eq "\"")) { if ($geturl ne "true") { $sb = ""; $iname = "$html_url/" . $iname; $geturl = "true"; } } if ($sb ne "true") { $iname = $ichar . $iname; } } $iname = $iname . substr($aline, $orgp, length($aline) - $orgp); #print "==> $iname
"; return ($iname); } sub strip_html_body_tags { my ($thehtml) = @_; $thestripped = ""; @html_lines=split(/\n/,$thehtml); foreach $item (@html_lines) { if (($item !~ //) and ($item !~ //) and ($item !~ //) and ($item !~ //) and ($item !~ /<\/html>/) and ($item !~ /<\/head>/) and ($item !~ /<\/body>/)) { $thestripped = $thestripped . "$item" . "\n"; } } return ($thestripped); } sub decode_month { my ($themonth) = @_; if ($themonth == 0) {$themonth = "January";} if ($themonth == 1) {$themonth = "February";} if ($themonth == 2) {$themonth = "March";} if ($themonth == 3) {$themonth = "April";} if ($themonth == 4) {$themonth = "Mei";} if ($themonth == 5) {$themonth = "June";} if ($themonth == 6) {$themonth = "July";} if ($themonth == 7) {$themonth = "August";} if ($themonth == 8) {$themonth = "September";} if ($themonth == 9) {$themonth = "October";} if ($themonth == 10) {$themonth = "November";} if ($themonth == 11) {$themonth = "December";} return ($themonth); } sub decode_weekday { my ($theweekday) = @_; if ($theweekday == 0) {$theweekday = "Sunday";} if ($theweekday == 1) {$theweekday = "Monday";} if ($theweekday == 2) {$theweekday = "Tuesday";} if ($theweekday == 3) {$theweekday = "Wednesday";} if ($theweekday == 4) {$theweekday = "Thursday";} if ($theweekday == 5) {$theweekday = "Friday";} if ($theweekday == 6) {$theweekday = "Saterday";} return ($theweekday); }