#!/usr/bin/perl # Fresh Guest Book Version 1.0 by Webfresh (TM) # Copyright ©1999-2000 Webfresh All Rights Reserved # # This program is being distributed as shareware. It may be used and # modified by anyone, so long as this copyright notice and the header # above remain intact, but any usage should be registered. (See the # program documentation for registration information.) Selling the # code for this program without prior written consent is expressly # forbidden. Obtain permission before redistributing this program # over the Internet or in any other medium. In all cases copyright # and header must remain intact. # # VERSIONS OF SOFTWARE #----------------------------------------------------------------------- # Only one copy of the shareware or registered version of Fresh Guest # Book may be used on one web site owned by one owner or an entity. # # LICENSE TO REDISTRIBUTE #----------------------------------------------------------------------- # Distributing the software and/or documentation with other products # (commercial or otherwise) or by other than electronic means without # Webfresh prior written permission is forbidden. # All rights to the Fresh Guest Book software and documentation not # expressly granted under this Agreement are reserved to Webfresh. # # DISCLAIMER OR WARRANTY #----------------------------------------------------------------------- # THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND # WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER # WARRANTIES WHETHER EXPRESSED OR IMPLIED. BECAUSE OF THE VARIOUS HARDWARE # AND SOFTWARE ENVIRONMENTS INTO WHICH THE FRESH GUEST BOOK MAY BE USED, # NO WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE IS OFFERED. THE USER MUST # ASSUME THE ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF WEBFRESH WILL BE # LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE. # IN NO CASE SHALL WEBFRESH BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR # CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS # OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE # BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT, # NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF # WEBFRESH IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL # WEBFRESH'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID # BY LICENSEE TO WEBFRESH. # ################################################################################# ######################################################### # EDIT DIRTY WORDS @dirty_words = ('fuck','shit','cocksucker','asshole','cunt','pussy','tits','bastard','bitch','piss','fucken','bitchen','fucker','shiter'); ######################################################### # NO EDITING REQUIRED BELOW ######################################################### # PATH INFO if ($0=~m#^(.*)(\\|/)#) { $dir = $1; } else { $dir = `pwd`; chomp $dir; } $script_url = $ENV{'SCRIPT_NAME'}; $data_dir = "$dir/data"; $guest_dat = "$data_dir/guest.dat"; $guest_info = "$data_dir/info.dat"; $guest_mail_text = "$data_dir/guestmail.txt"; $home_mail_text = "$data_dir/homemail.txt"; %in = &ReadForm; ######################################################### # LOAD GUESTBOOK INFO open(INFO,"$guest_info"); @info = ; close(INFO); $content_info = @info[0]; ($guestbook_name, $guest_per_page,$guest_mail,$home_mail,$home_addr,$sendemail,$datetype,$admin_pass) = split(/\|/,$content_info); ######################################################### # DATE ROUTINE @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); @months = ('January','February','March','April','May','June','July','August','September','October','November','December'); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $mon_num = $mon+1; $savehour = $hour; $hour = "0$hour" if ($hour < 10); $min = "0$min" if ($min < 10); $sec = "0$sec" if ($sec < 10); $saveyear = ($year % 100); $year = 1900 + $year; if ($datetype == 1) { $mon_num = "0$mon_num" if ($mon_num < 10); $mday = "0$mday" if ($mday < 10); $saveyear = "0$saveyear" if ($saveyear < 10); $date = "$mon_num/$mday/$saveyear"; } elsif ($datetype == 2) { $mon_num = "0$mon_num" if ($mon_num < 10); $mday = "0$mday" if ($mday < 10); $saveyear = "0$saveyear" if ($saveyear < 10); $date = "$mday\.$mon_num\.$saveyear"; } elsif ($datetype == 3) { $mon_num = "0$mon_num" if ($mon_num < 10); $mday = "0$mday" if ($mday < 10); $saveyear = "0$saveyear" if ($saveyear < 10); $date = "$mon_num/$mday/$saveyear-$hour\:$min"; } elsif ($datetype == 4) { $mon_num = "0$mon_num" if ($mon_num < 10); $mday = "0$mday" if ($mday < 10); $saveyear = "0$saveyear" if ($saveyear < 10); $date = "$mday\.$mon_num\.$saveyear-$hour\:$min"; } ######################################################### # ADD ENTRY if($action eq "add") { if ($guest_message_new ne "") { $dwords = $guest_message_new; foreach $dwords (@dirty_words) { if ($guest_message_new =~ /$dwords/i) { &Template("$data_dir/guest.temp",'temp'); $display_dirty_words .= &Cell('dirty_words'); print &Template("$data_dir/guest.temp",'temp'); exit; } } } if ($guest_email_new ne "") { $temp = $guest_email_new; $temp =~ s/-/a/g; $temp =~ s/_/a/g; unless ($temp =~ /\w+@\w+\.\w\w+/) { &Template("$data_dir/guest.temp",'temp'); $display_dirty_words .= &Cell('dirty_words'); print &Template("$data_dir/guest.temp",'temp'); exit; } } if ($guest_url_new ne "") { $guest_url_new = "http://".$guest_url_new; unless ($guest_url_new =~ /^(f|ht)tp:\/\/.+\..+/) { &Template("$data_dir/guest.temp",'temp'); $display_dirty_words .= &Cell('dirty_words'); print &Template("$data_dir/guest.temp",'temp'); exit; } } if ($guest_name_new ne "") { $dwords = $guest_name_new; foreach $dwords (@dirty_words) { if ($guest_name_new =~ /$dwords/i) { &Template("$data_dir/guest.temp",'temp'); $display_dirty_words .= &Cell('dirty_words'); print &Template("$data_dir/guest.temp",'temp'); exit; } } } open(GUEST_DAT,"$guest_dat"); @guest_content = ; close(GUEST_DAT); $content = @guest_content[0]; ($ID,$guest_date,$guest_name,$guest_email,$guest_url,$guest_message) = split(/\|/,$content); $new_ID = $ID +1; if ($guest_email_new) { $guest_name_new_x = "$guest_name_new"; } else { $guest_name_new_x = $guest_name_new; } if ($guest_url_new) { $guest_url_new_x = "$guest_url_new"; } else { $guest_url_new_x = $guest_url_new; } open(GUEST_DAT,">$guest_dat"); print GUEST_DAT "$new_ID|$date|$guest_name_new_x|$guest_email_new|$guest_url_new_x|$guest_message_new\n"; foreach $line (@guest_content) { print GUEST_DAT $line; } close(GUEST_DAT); if ($guest_mail eq "1" && $guest_email_new) { open(GUEST_MAIL_TEXT,"$guest_mail_text"); @guest_text = ; close(GUEST_MAIL_TEXT); open(MAIL,"|$sendemail -t"); print MAIL "To: $guest_email_new\n"; print MAIL "From: $home_addr\n"; print MAIL "Subject: Thanks for your Love Tips Entry.\n"; foreach $line (@guest_text) { print MAIL $line; } close MAIL; } if ($home_mail eq "1" && $home_addr) { open(HOME_MAIL_TEXT,"$home_mail_text"); @home_text = ; close(HOME_MAIL_TEXT); open(MAIL,"|$sendemail -t"); print MAIL "To: $home_addr\n"; print MAIL "From: $guest_email_new\n"; print MAIL "Subject: Love Tips Entry.\n"; foreach $line (@home_text) { print MAIL $line; } close MAIL; } } ######################################################### # GET CONTENT if($guest) { open(GUEST,"<$guest_dat"); while() { ($ID,$guest_date,$guest_name,$guest_email,$guest_url,$guest_message) = split(/\|/,$_); $push = "$ID\|$guest_date\|$guest_name\|$guest_email\|$guest_url\|$guest_message\n"; push(@reprint,$_); } close(GUEST); } ######################################################### # GUESTBOOK CONTENT &Template("$data_dir/guest.temp"); open(GUEST_DAT,"<$guest_dat"); @guest_dat_content = ; close(GUEST_DAT); foreach$content(@guest_dat_content) { ($ID,$guest_date,$guest_name,$guest_email,$guest_url,$guest_message) = split(/\|/,$content); $push = "$ID\|$guest_date\|$guest_name\|$guest_email\|$guest_url\|$guest_message\n"; push(@guest_dat,$push); } ######################################################### # GUESTBOOK ADD ENTRY PAGE if($guest eq "add") { $display_add_entry .= &Cell('add_entry'); } ######################################################### # GENERATE GUESTBOOK $show_max = $guest_per_page; if($guest eq "") { for($guest_content = $show; $guest_content < scalar @guest_dat;) { ($ID,$guest_date,$guest_name,$guest_email,$guest_url,$guest_message) = split(/\|/,$guest_dat[$guest_content]); if($ID ne "") { $display_content .= &Cell('guest_content'); } $guest_content++; last if $guest_content-$show == $show_max; } if($guest_content > $show_max || $guest_content < @guest_dat) { if($guest_content > $show_max) { $show_back = $show-$show_max; $back_span = "Back"; } if($guest_content < @guest_dat) { if($guest_content-$show == $show_max) { $show_next = $show+$show_max; $next_span = "Next"; } } $display_back_span .= &Cell("show_back_span"); $display_next_span .= &Cell("show_next_span"); } if(!$display_content) { $display_content = "

There are currently no entries in my Love tips.

Please be the first to contribute.

" }; } print &Template("$data_dir/guest.temp",'temp'); ######################################################### # TEMPLATE sub Template { local(*FILE); if ($_[1] eq 'temp') { print "Content-type: text/html\n\n" unless ($ContentType++ > 0); } elsif ($_[1] eq 'text') { print "Content-type: text/plain\n\n" unless ($ContentType++ > 0); } if (!$_[0]) { return "
\nTemplate : No file was specified
\n"; } elsif (!-e "$_[0]") { return "
\nTemplate : File '$_[0]' does not exist
\n"; } else { open(FILE, "<$_[0]") || return "
\nTemplate : Could open $_[0]
\n"; while () { $FILE .= $_; } close(FILE); for ($FILE) { s//\1/gi; # show hidden inserts s/(?:\r\n|\n)?(.*?)/ $CELL{$1}=$2;''/ges; # read/remove template cells s/\%(\w+)\%/${$1}/g; # translate %% } } return $FILE; } ######################################################### # TRANSLATE CELL sub Cell { my($CELL); for (0..$#_) { if ($_[$_]) { $CELL .= $CELL{$_[$_]}; }} if (!$_[0]) { return "
\nCell : No cell was specified
\n"; } elsif (!$CELL) { return "
\nCell : Cell '$_[0]' is not defined
\n"; } else { $CELL =~ s/\%(\w+)\%/${$1}/g; } # translate %% return $CELL; } ######################################################### # PARSE FORM sub ReadForm { my($max) = $_[1]; # Max Input Size my($name,$value,$pair,@pairs,$buffer,%hash); # localize variables # Check input size if max input size is defined if ($max && ($ENV{'CONTENT_LENGTH'}||length $ENV{'QUERY_STRING'}) > $max) { die("ReadForm : Input exceeds max input limit of $max bytes\n"); } # Read GET or POST form into $buffer if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } if ($ENV{'QUERY_STRING'}) { $buffer .= $ENV{'QUERY_STRING'}; } @pairs = split(/&/, $buffer); # Split into name/value pairs foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # split into $name and $value $value =~ s/\+/ /g; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/~!/ ~!/g; $value =~ s/\n/
/sg; $value =~ s/\[\]//g; $value =~ tr/+/ /; # replace "+" with " " $value =~ s/%([A-F0-9]{2})/pack("C", hex($1))/egi; # replace %hex with char $value =~ s/\:D//sg; $value =~ s/\:confused://sg; $value =~ s/\:cool://sg; $value =~ s/\:eek://sg; $value =~ s/\:o://sg; $value =~ s/\:\(//sg; $value =~ s/\:mad://sg; $value =~ s/\:rolleyes://sg; $value =~ s/\:\)//sg; $value =~ s/\:p//sg; $value =~ s/\;\)//sg; $$name = $value; } return %hash; }