#!/usr/bin/perl # Guestbook for the World Wide Web # Created by Matt Wright Version 2.3.1 # Created on: 4/21/95 Last Modified: 10/29/95 # Consult the file README for more information and Installation Instructions. ############################################################################# # Variables $guestbookurl = "http://matrix.etseq.urv.es/alumnes/agiribet/personal/llibre/guestbook.html"; $guestbookreal = "/lliure/agiribet/html/personal/llibre/guestbook.html"; $guestlog = "/lliure/agiribet/html/personal/llibre/guestlog.html"; $cgiurl = "http:/matrix.etseq.urv.es/cgi-bin/guestbook.cgi"; $date_command = "/bin/date"; # Opciones: $mail = 0; # 1 = Yes; 0 = No $uselog = 1; # 1 = Yes; 0 = No $linkmail = 1; # 1 = Yes; 0 = No $separator = 1; # 1 =
$redirection = 0; # 1 = Yes; 0 = No
$entry_order = 1; # 1 = Newest entries added first;
# 0 = Newest Entries added last.
$remote_mail = 0; # 1 = Yes; 0 = No
$allow_html = 0; # 1 = Yes; 0 = No
$line_breaks = 1; # 1 = Yes; 0 = No
# Si contestaste 1 a $mail o $remote_mail necesitas dar un valor
# a estas dos variables
$mailprog = '/usr/sbin/sendmail';
$recipient = 'agiribet@etse.urv.es';
# Done
#############################################################################
# Get the Date for Entry
$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
$shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s///g;
if ($allow_html != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
$FORM{$name} = $value;
}
# Print the Blank Response Subroutines
&no_comments unless $FORM{'comments'};
&no_name unless $FORM{'realname'};
# Begin the Editing of the Guestbook File
open (FILE,"$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
@LINES= \n\n";
}
if ($entry_order eq '0') {
print GUEST "\n";
}
}
else {
print GUEST $_;
}
}
close (GUEST);
# Log The Entry
if ($uselog eq '1') {
&log('entry');
}
#########
# Options
# Mail Option
if ($mail eq '1') {
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n";
print MAIL "From: $FORM{'username'} ($FORM{'realname'})\n";
print MAIL "Subject: Entrada en el llibre de visites\n\n";
print MAIL "Entrada:\n\n";
print MAIL "------------------------------------------------------\n";
print MAIL "$FORM{'comments'}\n";
print MAIL "$FORM{'realname'}";
if ( $FORM{'username'} ){
print MAIL " <$FORM{'username'}>";
}
print MAIL "\n";
if ( $FORM{'city'} ){
print MAIL "$FORM{'city'},";
}
if ( $FORM{'country'} ){
print MAIL " $FORM{'country'}\n";
}
if ( $FORM{'url'} ){
print MAIL " $FORM{'url'}\n";
}
print MAIL " - $date\n";
print MAIL "------------------------------------------------------\n";
close (MAIL);
}
if ($remote_mail eq '1' && $FORM{'username'}) {
open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
print MAIL "To: $FORM{'username'}\n";
print MAIL "From: $recipient\n";
print MAIL "Subject: Llibre de visites: confirmacions\n\n";
print MAIL "Gràcies per firmar en El món d'en GIRI: .\n\n";
print MAIL "------------------------------------------------------\n";
print MAIL "$FORM{'comments'}\n";
print MAIL "$FORM{'realname'}";
if ( $FORM{'username'} ){
print MAIL " <$FORM{'username'}>";
}
print MAIL "\n";
if ( $FORM{'city'} ){
print MAIL "$FORM{'city'},";
}
if ( $FORM{'state'} ){
print MAIL " $FORM{'state'}";
}
if ( $FORM{'country'} ){
print MAIL " $FORM{'country'}\n";
}
if ( $FORM{'url'} ){
print MAIL " $FORM{'url'}\n";
}
print MAIL " - $date\n";
print MAIL "------------------------------------------------------\n";
close (MAIL);
}
# Print Out Initial Output Location Heading
if ($redirection eq '1') {
print "Location: $guestbookurl\n\n";
}
else {
&no_redirection;
}
#######################
# Subroutines
sub no_comments {
print "Content-type: text/html\n\n";
print " \n";
print " \n";
print " \n";
print "$FORM{'comments'} \n";
# Print End of HTML
print "
\n/g;
}
print GUEST "$FORM{'comments'}
\n";
if ($FORM{'url'}) {
print GUEST "$FORM{'realname'}";
}
else {
print GUEST "$FORM{'realname'}";
}
if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print GUEST " \<";
print GUEST "$FORM{'username'}\>";
}
else {
print GUEST " <$FORM{'username'}>";
}
}
print GUEST "
\n";
if ( $FORM{'city'} ){
print GUEST "$FORM{'city'},";
}
if ( $FORM{'country'} ){
print GUEST " $FORM{'country'}";
}
if ($separator eq '1') {
print GUEST " - $date
\n\n";
}
else {
print GUEST " - $dateEls teus comentaris sembla que estan en blanc
\n";
print "Els comentaris sembla que estan en blanc \n";
print "i per tant no han estat afegits al llibre de visites\n";
print ". Siusplau, introdueix els comentaris en l'espai inferior.
\n";
print "Tornar al llibre de visites.";
print "\n\n";
# Log The Error
if ($uselog eq '1') {
&log('no_comments');
}
exit;
}
sub no_name {
print "Content-type: text/html\n\n";
print "El teu nom apareix el blanc
\n";
print "La secció corresponent al seu nom esta en blanc \n";
print "i per tant no ha estat afegit al llibre de visites. \n";
print " Siusplau introdueix el teu nom en l'espai corresponent.
\n";
print "Tornar al llibre de visites.";
print "\n\n";
# Log The Error
if ($uselog eq '1') {
&log('no_name');
}
exit;
}
# Log the Entry or Error
sub log {
$log_type = $_[0];
open (LOG, ">>$guestlog");
if ($log_type eq 'entry') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate]
\n";
}
elsif ($log_type eq 'no_name') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: Sense nom
\n";
}
elsif ($log_type eq 'no_comments') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: Sense ";
print LOG "comentaris
\n";
}
}
# Redirection Option
sub no_redirection {
# Print Beginning of HTML
print "Content-Type: text/html\n\n";
print "Gràcies per firmar en el llibre de visites d'El món d'en GIRI
\n";
# Print Response
print "Gràcias per omplir el formulari. Els teus comentaris han estat \n";
print "afegits al llibre de visites.
\n";
print "Aquí hi ha el que has enviat:
\n";
if ($FORM{'url'}) {
print "$FORM{'realname'}";
}
else {
print "$FORM{'realname'}";
}
if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print " <";
print "$FORM{'username'}>";
}
else {
print " <$FORM{'username'}>";
}
}
print "
\n";
if ( $FORM{'city'} ){
print "$FORM{'city'},";
}
if ( $FORM{'country'} ){
print " $FORM{'country'}";
}
print " - $date
\n";
print "Tornar al llibre de visites\n";
print "- Es necesari recargar-lo per poder veure la teva propia entrada.\n";
print "\n";
exit;
}