#!/usr/bin/perl # # DCGuest.cgi Version 2.0 Beta # Written By David S. Choi, david@dcscripts.com # First Release DCGuest97, 16 November 1997 # DCGuest Version 2.0, 22 July 1999 # ########## YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT ############### # Copyright ©1997-1999 DCScripts All Rights Reserved # As part of the installation process, you will be asked # to accept the terms of this Agreement. This Agreement is # a legal contract, which specifies the terms of the license # and warranty limitation between you and DCScripts and DCGuest. # You should carefully read the following terms and conditions before # installing or using this software. Unless you have a different license # agreement obtained from DCScripts, installation or use of this software # indicates your acceptance of the license and warranty limitation terms # contained in this Agreement. If you do not agree to the terms of this # Agreement, promptly delete and destroy all copies of the Software. # # Versions of the Software # You may install as many copies of DCGuest Script. # # License to Redistribute # Distributing the software and/or documentation with other products # (commercial or otherwise) or by other than electronic means without # DCScripts's prior written permission is forbidden. # All rights to the DCGuest software and documentation not expressly # granted under this Agreement are reserved to DCScripts. # # Disclaimer of 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 DCGUEST 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 DCSCRIPTS WILL BE # LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE. # IN NO CASE SHALL DCSCRIPTS 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 # DCSCRIPTS IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL # DCSCRIPT'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID # BY LICENSEE TO DCSCRIPTS. # ########################################################################### # Define directory path to your setup file. # Try relative path $path = "."; #-----------NO NEED TO EDIT ANYTHING BELOW THIS LINE------ require "$path/dcguest.setup"; require "$path/cgi-lib.pl"; check_datafile($datafile); check_datafile($counter); # OK Let's read in formdata &ReadParse(); # Send HTTP header to the server print "Content-type: text/html\n\n"; # Format Comment input so that it will fit nicely in the database if ($in{'Comment'}) { $in{'Comment'} =~ s//>/g; $in{'Comment'} =~ s/\cM//g; $in{'Comment'} =~ s/\n\n/

/g; $in{'Comment'} =~ s/\r\n/

/g; $in{'Comment'} =~ s/\n/
/g; } # Depending on Form input: # 1) Display add to guest form # 2) Add guest information to the database # 3) Display guests if ($in{'action'} eq "add_form") { $header = $add_guest_header; $sub_header = $add_guest_sub_header; &add_form(); } elsif ($in{'action'} eq "add_guest") { $header = $thank_you_header; $sub_header = $thank_you_sub_header; &check_required_fields; &add_guest(); &send_all_mails(); } else { $header = $display_guest_header; $sub_header = $display_guest_sub_header; &display_guests(); } &display_output(); exit(0); ####################### END OF THE MAIN PROGRAM #################### sub display_guests { my $marker; if ($in{'marker'}) { $marker = $in{'marker'}; } else { $marker = 1; } my ($num_guests,$guest,$start_num,$stop_num) = get_guests($datafile,$marker); my $num_blocks = int(($num_guests-1)/$num_view) + 1; $html_output .= qq~

Viewing Guests $start_num-$stop_num
($num_guests Guests have signed this book)

~; for ($j=1; $j<= $num_blocks; $j++) { $j_start = ($j-1)*$num_view + 1; $j_stop = $j*$num_view; if ($j_stop > $num_guests) { $j_stop = $num_guests; } if ($start_num == $j_start) { $html_output .= "[$j] "; } else { $html_output .= "[$j] "; } } $html_output .= qq~

~; foreach (reverse sort keys %{$guest}){ my $temp = $guest_layout; $guest->{$_}->{'Email'} = "
{$_}->{'Email'}\">$guest->{$_}->{'Email'}" if ($guest->{$_}->{'Email'}); $guest->{$_}->{'Location'} = "From $guest->{$_}->{'Location'}" if ($guest->{$_}->{'Location'}); $guest->{$_}->{'Country'} = ", $guest->{$_}->{'Country'}" if ($guest->{$_}->{'Country'}); $guest->{$_}->{'Homepage'} = "
{$_}->{'Homepage'}\">$guest->{$_}->{'Homepage'}" if ($guest->{$_}->{'Homepage'}); $temp =~ s//$guest->{$_}->{$1}/g; $html_output .= $temp; } } sub check_required_fields { foreach $require_field (@required_fields) { if ($in{$require_field} eq "" || $in{$required_field} eq " ") { $flag = "1"; $header = "ERROR!!"; $sub_header = "You must at least submit Name and Comment. Please try again."; &add_form; &display_output(); &exit; } } } sub add_guest { open(GUESTBOOK,"$datafile") or my_die("Can't open $datafile",$!); flock(GUESTBOOK,2); @guestdata = ; flock(GUESTBOOK,8); close(GUESTBOOK); $id = &get_number(); ($date,$localtime) = &get_date(); $date = $localtime." ".$date; $in{'ID'} = $id; $in{'Date'} = $date; foreach $field (@guest_fields) { unless ($allow_html eq "yes") { $in{$field} =~ s/<([^>]|\n)*>//g; } $in{$field} =~ s/\|/\s/g; $in{$field} = remove_badwords($in{$field}); $newline .= $in{$field}."|"; } chop($newline); $newline .= "\n"; open(GUESTBOOK,">$datafile") or my_die("Can't open $datafile",$!); flock(GUESTBOOK,2); print GUESTBOOK $newline; print GUESTBOOK @guestdata; flock(GUESTBOOK,8); close(GUESTBOOK); } sub remove_badwords { my $body = shift; foreach (@badwords) { $body =~ s/$_/####/gi; } $body; } sub add_form { $html_output .= qq~

~; foreach $guest_field (@guest_fields){ $html_output .= &table_row($guest_field,$field_input_type{$guest_field}); } $html_output .= qq~
~; } sub table_row { my ($field,$type) = @_; my ($table_row); if ($type eq "text"){ $table_row .= qq~ $field ~; } elsif ($type eq "textarea") { $table_row .= qq~ $field ~; } $table_row; } sub get_number { my $num; open(NUMBER,"$counter") or my_die("Error in function get_number during read",$!); flock(NUMBER,2); $num = ; flock(NUMBER,8); close(NUMBER); $num++; open(NUMBER,">$counter") or my_die("Error in function get_number during write",$!); flock(NUMBER,2); print NUMBER $num; flock(NUMBER,8); close(NUMBER); $num; } sub display_output { my %name = ( HEADER => $header, SUBHEADER => $sub_header, HTMLOUTPUT => $html_output ); # Open template and read in open(TEMPLATE,"$booktemplate") or my_die("can't open $booktemplate",$!); { local($/) = undef; $template =