#!/usr/bin/perl # FG Guestbook - guestbook.pl - written in XEmacs (http://www.xemacs.org/) # # Version: 3.2 - 29-Apr-2003 # Author & Copyright: Felix Gertz - felix.gertz@epost.de # FG Guestbook homepage: http://fgguestbook.sourceforge.net # # First, please read the README! # There are the install instructions. # # This guestbook is free available, because it stands under the # GPL (GNU General Public License). See LICENSE for more information. # # For all that,you shouldn't remove the copyright notice in the footer_template. # That would be nice.. :-) # To remove the copyright notice you can send me an postcard or you can pay a # little amount. More info is in the readme file.. # # If you have a question, first read the README again, then read the FAQ on the # homepage and then feel free to email me. # use strict; # use CGI::Carp "fatalsToBrowser"; #----------------------------- BEGIN CONFIGURATION ----------------------------# # Number of entries you want to see at each page. # Set to 1000 or so to have all on one page. my $eppage = 10; # Length of the visible pagebar. my $pagebar_length = 11; # If a word is larger then this value, then it will be wraped. # A good protection against design killers. ;-) # Set to 0 to disable. my $wrap_at = 60; # Allow posting HTML-code? # 0 = off , 1 = on my $allowhtml = 0; # Make a link from an posted URL? my $set_link = 1; # Find and kill duplicates? my $find_duplicate = 1; # Check Browserstring, if doesn't match, guestbook will deny display. # Protection against spambots my $check_browserstring = 1; my $allowed_browsers = ['mozilla','lynx','links','googlebot','scooter','fast-webcrawler','w3c_validator','opera']; # Convert the email to ascii-ordinal-numbers? # So spambots can't read it. my $convert_email = 1; # Enable logging? my $logging = 1; # Filtering bad words? my $badword_filter = 1; # Word to replace with my $badword_replace = "CENSORED"; # Use emoticons? my $use_emoticons = 0; # URI to the emoticonpath.It can be absolut _or_ relativ.. my $emoticon_path = "/emoticons/"; # Force input in the name field? # That should be.. :) my $force_name = 1; # Force the email field? my $force_email = 0; # Force the homepage field? my $force_homepage = 0; # Force the text field? my $force_text = 1; # Error text, if somebody filled not out a forced field. my $error_text = "
Sorry, you must fill in the portion listed below.
Go back and do it.
\n";
# Enable email notification?
my $send_email_notification = 0;
# The mailprogram
# Most it's ok so..
my $email_program = "/usr/sbin/sendmail";
# Your email
# You must set the '@' with a backslash '\@' !
my $your_email = "noname\@nodomain.com";
# Email subject
my $mail_subject = "New guestbook entry";
# Email message
my $mail_msg = "There is a new guestbook entry!\n";
# Thanx message, if somebody signed the guestbook.
my $thanxmsg = "Thank you very much for your guestbook entry!";
# Will be displayed if no homepage was given.
# Leave blank to disable.
my $nohomepage = "n/a";
#------------------------------ END CONFIGURATION -----------------------------#
# That was it!
# ---------- BEGIN MAIN
my $gdata = "./gdata/";
my %params = &get_param();
if($params{'cwrite'})
{
&check_input($error_text,$gdata,$params{'Name'},$params{'E-Mail'},$params{'Homepage'},$params{'Text'},$force_name,$force_email,$force_homepage,$force_text);
my $timestring = &get_timestring();
if(&write_message($gdata,$allowhtml,$set_link,$wrap_at,$params{'Name'},$params{'E-Mail'},$params{'Homepage'},$params{'Text'},$nohomepage,$find_duplicate,$timestring,$convert_email))
{
unless(&count_message($gdata)) { &common_error('count_message'); }
if($logging)
{ unless(&write_log($gdata,$timestring)) { &common_error('write_log'); } }
if($send_email_notification)
{
unless(&send_mail_notification($email_program,$your_email,$mail_subject,$mail_msg))
{ &common_error('send email notification'); }
}
}
}
&print_all($gdata,$eppage,$params{'next'},$params{'cwrite'},$thanxmsg,$pagebar_length,$check_browserstring);
# ---------- END MAIN
sub print_all
{
my $gdata = $_[0];
my $eppage = $_[1];
my $cache = $_[2];
my $cwrite = $_[3];
my $thanxmsg = $_[4];
my $pagebar_length = $_[5];
my $check_browserstring = $_[6];
my $pthanxmsg = "
".$thanxmsg."";
my $scriptname = $ENV{'SCRIPT_NAME'};
my $number_of_entries = &get_nb_of_entries($gdata);
my $sector = $eppage;
if($cache) { $sector = $cache; }
my $next = $sector+$eppage;
my $last = $sector-$eppage;
my $page = $sector/$eppage;
my $pagebar = &get_pagebar($eppage,$number_of_entries,$page,$scriptname,$pagebar_length);
my @data = &get_gdata($gdata,$number_of_entries,$sector,$eppage);
my @template_cache = &get_data($gdata,'body_template');
my @template_data = ("");
my $line;
my $blback = "";
my $blnext = "";
my $elback = "";
my $elnext = "";
if($last > 0) { $blback = ""; $elback = ""; }
if($sector < $number_of_entries) { $blnext = ""; $elnext = ""; }
if($cwrite eq "") { $thanxmsg=""; $pthanxmsg=""; }
foreach $line(@template_cache)
{
$line =~ s/\%PTHANXMSG\%/$pthanxmsg/g;
$line =~ s/\%THANXMSG\%/$thanxmsg/g;
$line =~ s/\%NUMBERENTRIES\%/$number_of_entries/g;
$line =~ s/\%PAGE\%/$page/g;
$line =~ s/\%PAGEBAR\%/$pagebar/g;
$line =~ s/\%BEGINLBACK\%/$blback/g;
$line =~ s/\%ENDLBACK\%/$elback/g;
$line =~ s/\%BEGINLNEXT\%/$blnext/g;
$line =~ s/\%ENDLNEXT\%/$elnext/g;
if($line=~ s/\%DATA\%//g)
{ push(@template_data,@data); }
push(@template_data,$line);
}
print "Content-type: text/html\n\n";
print &get_data($gdata,'header_template');
if($check_browserstring)
{
if(&check_if_browser_allowed($allowed_browsers))
{ print @template_data; }
else
{ print "
"; }
}
print &get_data($gdata,'footer_template');
}
sub get_param
{
my $data;
my $name;
my $value;
my $formularfield;
my @formularfields = ("");
my %params;
if($ENV{'REQUEST_METHOD'} eq 'GET')
{ $data = $ENV{'QUERY_STRING'}; }
else
{ read(STDIN, $data, $ENV{'CONTENT_LENGTH'}); }
@formularfields = split(/&/,$data);
foreach $formularfield (@formularfields)
{
($name,$value) = split(/=/, $formularfield);
$params{$name} = $value;
}
return %params;
}
sub check_input
{
my $error_text = $_[0];
my $gdata = $_[1];
my $name = $_[2];
my $email = &string_convert($_[3],0);
my $homepage = &string_convert($_[4],0);
my $text = $_[5];
my $force_name = $_[6];
my $force_email = $_[7];
my $force_homepage = $_[8];
my $force_text = $_[9];
if((($name eq "") && $force_name) || ((($email eq "") || ($email !~ /\@/) || ($email !~ /\./)) && $force_email) || ((($homepage eq "http://") || ($homepage eq "") || ($homepage !~ /http:\/\//) || ($homepage !~ /\./)) && $force_homepage) || (($text eq "") && $force_text))
{
print "Content-type: text/html\n\n";
print &get_data($gdata,'header_template');
print $error_text;
if(($name eq "") && $force_name) { print "
Name
\n"; }
if((($email eq "") || ($email !~ /\@/) || ($email !~ /\./)) && $force_email) { print "
E-Mail
\n"; }
if((($homepage eq "http://") || ($homepage eq "") || ($homepage !~ /http:\/\//) || ($homepage !~ /\./)) && $force_homepage) { print "
Homepage
\n"; }
if(($text eq "") && $force_text) { print "
Text
\n"; }
print &get_data($gdata,'footer_template');
die;
}
}
sub common_error
{
my $catchword = $_[0];
print "Content-type: text/html\n\n";
print "\n