#! /usr/local/bin/perl ############################################################################## # guestbook.pl V3.0 # # COPYRIGHT NOTICE # # Copyright 1998 Wolfgang Wiese All Rights Reserved. # # EMail: unrzc9@rrze.uni-erlangen.de # # URL : http://www.rrze.uni-erlangen.de/~unrzc9 # # # # Guestbook may be used and modified free of charge by anyone so long as # # this copyright notice and the comments above remain intact. By using this # # code you agree to indemnify Wolfgang Wiese from any liability that # # might arise from it's use. # # # # Selling the code for this program without prior written consent is # # expressly forbidden. In other words, please ask first before you try and # # make money off of my program. # # # # Obtain permission before redistributing this software over the Internet or # # in any other medium. In all cases copyright and header must remain intact.# ############################################################################## require "/home/iti_db/eike/public_html/pzguest/cgi-library.pl"; # Constants. $HOST = $ENV{'REMOTE_HOST'}; $guestbook_log ='/home/iti_db/eike/public_html/pzguest/guestbooks.dat'; $guestbook_helppage='http://cgi.xwolf.com/cgi/guestbook.shtml'; $progurl = 'http://wwwiti.cs.uni-magdeburg.de/~eike/pzguest/guestbook.cgi'; $tempfile = '/home/iti_db/eike/public_html/pzguest/guestbook.tmp1'; $temp2 = '/home/iti_db/eike/public_html/pzguest/guestbook.tmp2'; $mailprog = '/usr/lib/sendmail'; ############################################################################## # Get the variables passed down via the web &ReadParse; $rw_book = $in{'rw'}; # rw must be either 'read' or 'write'. $varfile = $in{'varfile'}; # This definies the filename, where all # parameters I explained above gave to be # written in. $name = $in{'name'}; # Eingabe: Name des USers $email = $in{'email'}; # Eingabe: Email des Users $text = $in{'text'}; # Eingabe: Text des Users $homepage = $in{'homepage'}; # Eingabe: Homepage des Users $input_zeit = $in{'input_zeit'}; # Eingabe: Zeit der Eingabe. # The following constants can be written in the $varfile, but it works here too $hintergrund = $in{'hintergrund'}; # background of the book (-tag) for the old version... $bodytag = $in{'bodytag'}; # bodytags for html, replaces background! () $titel = $in{'titel'} || 'Guestbook'; # Title of the book $kopf = $in{'top'} || ' '; # Here, you can give in HTML-code, the head of your document. Esp. If # you like to have icons there. The title is after it! $bottom = $in{'bottom'}; # Same as above, but it will be at the bottom $book_file = $in{'book'}; # Text-File of the book $forbit_html = $in{'forbit_html'} || 0; # If this is set to 1, no html-tags are allowed $counter = $in{'counter'} || 0; # 0 = Counter off, 1 = Dumb Counter on, 2 = HideCounter and normal on. # The numbers of accesses of the normal counter will # be written in the file $varfile, if it was set to 1 # If the hidecounter is on, the hosts/accesses will be written in # another file too. $ignore = $in{'ignore'} || 'off'; $allow_home = $in{'allow_home'} || 1; # 1 = Feld fuer Homepage da, 0 = ohne Feld. $language = $in{'language'} || 'german'; # default=german, english possible in the future $need_mail = $in{'need_mail'} || 0; # 0 or 1. If 1, then the user has to enter an email. If 0, it don't # matter, if he lets it out. But notice, that if this value is 0, # no mail will be send to the user of writing a message. $answer_mail = $in{'answer_mail'} || 0; # 1 or 0, If 1 is set the author of a new entry will get a 'thank'-mail $new_file = $in{'new_file'}; # If this field is given, a html-file named new_file will be created, # in which all entrys will be written. $seperator = $in{'seperator'} || '

'; #


or

. Is for the deviding of the entrys in the book $add_beginning = $in{'add_beginning'} || 1; # 1 or 0. If 1 is set the entry will inserted at the top of the document. $italic = $in{'italic'} || 1; # If 1 the text of the entries will be displyed italic. $pre_text = $in{'pre_text'}; $entry_ask = $in{'entry_ask'}; $past_text = $in{'past_text'}; $newconfig = $in{'new_config'}; # This is the message, which is displayed above the guestbook-data. # entry_ask is the text, with the link to the input of new entries, why pre_text # and past_text are surrounding this field. # Notice: If $entry_ask is set to 'none', it won't be displayed. $okval = $in{'ok'}; # To test if the input is right if ($need_mail == 0) {$answer_mail=0;} if ($italic ==1) {$starti = ''; $stopi = '';} else {$starti = ''; $stopi='';} $varfile=&Check_Name($varfile); #########################Main program is starting here######################### print(&PrintHeader); if ($okval) { if (($okval =~ /wiederholen /i) || ($okval =~/ Dismiss /i)) { $rw_book="dismiss";} else { $rw_book="save_now";} } if (!($varfile)) { &Fehlermeldung("You gave no $varfile!
The guestbook cannot run without it");} &LadeParameter; &AutoRemove; if (($rw_book eq 'read') && ($counter)) { if ($counter == 2) { # Call for the hidecounter, if he was set on. $kurz=$book_file.','.$ignore; &Hidecount($kurz); } else { # Add 1 to the dumb counter: $access++; &SaveParameter; } } if ($newconfig) {&SaveParameter;} if ((($rw_book =~ /write/) || ($rw_book =~ /dismiss/)) && ($INPUT_LAYOUT)) { # Es liegt eine Eingabe vor und diese hat ihren eigenen Style, # also mach keine HTML_TOP-Ausgabe } else { if ($HTML_TOP) { open (f5,"<$HTML_TOP") || &Fehlermeldung("Cannot open HTML_TOP: $HTML_TOP "); while() { chop($_); print "$_\n"; } close f5; } else { if (!($bodytag)) {$bodytag='background="'.$hintergrund.'"';} $kurz=$titel.','.$bodytag.','.$kopf; &HtmlTop($kurz); } } if ($rw_book eq 'write') { $dismiss=0;&new_entry; } elsif ($rw_book eq 'dismiss') { $dismiss=1;&new_entry; } elsif ($rw_book eq 'save') { &check_entry;} elsif ($rw_book eq 'save_now') { &save_entry; &read_data;} else { # Read all entrys if ($entry_ask eq 'none') {print "$pre_text $past_text\n";} else {print "$pre_text $entry_ask $past_text\n";} if ($language =~ /german/) { if ($counter) {print "
Diese Seite wurde bisher $access mal aufgerufen.\n";} } elsif ($language =~ /english/i) { if ($counter) {print "
This page was accessed $access times.\n";} } if (not $HTML_TOP) {print "


\n";} &read_data; } #if ((($rw_book ne 'write') || ($rw_book ne 'dismiss')) && ($INPUT_LAYOUT)) { if ($HTML_BOT) { open (f5,"<$HTML_BOT") || &Fehlermeldung("Cannot open HTML_BOT: $HTML_BOT"); while() { chop($_); print "$_\n"; } close f5; } else { print "
$bottom
\n"; print "


"; print "Script written by\n"; print "xwolf
"; print "

\n"; } #} exit; ############################Sub are starting here############################## sub LogWriter { if ($LOGFILE) { open(f1,">>$LOGFILE"); print f1 "$ENV{'REMOTE_ADDR'}, $zeit, $name, $email, $homepage\n"; close f1; } } ##################################################################################### sub ReadLayout { my ($LAYOUTFILE)=@_; $i=0; open(f1,"<$LAYOUTFILE") || &Fehlermeldung("Kann Layout-Datei $LAYOUTFILE nicht oeffnen!"); while() { chop($_); if (length($_) > 3) { $LAYOUTDATA[$i++] = $_; } } close f1; } ############################################################################## sub new_entry { # Here a new entry can be written my ($shorttext,$short_laenge); my ($kurzmessage); if ($INPUT_LAYOUT) { # Vorgegebenes Layout &ReadLayout($INPUT_LAYOUT); $kurzmessage=""; if ($dismiss) { $i=0; open(f1, "<$temp2") || print "

Error Cannot open $tempmess"; &NLock($temp2); while() { chop($_); $shorttext[$i]=$_; $i++; } &NUnlock($temp2); close f1; $short_laenge=$i; for ($i=0;$i 1) { chop($shorttext[$i]); $kurzmessage=$kurzmessage."$shorttext[$i]\n"; } } } for ($i=0; $i<=$#LAYOUTDATA; $i++) { $LAYOUTDATA[$i] =~ s/#MESSAGE#/$kurzmessage/g; $LAYOUTDATA[$i] =~ s/#INPUTTIME#/$zeit/g; $LAYOUTDATA[$i] =~ s/#INPUTNAME#/$name/g; $LAYOUTDATA[$i] =~ s/#INPUTHOMEPAGE#/$homepage/g; $LAYOUTDATA[$i] =~ s/#INPUTEMAIL#/$email/g; print "$LAYOUTDATA[$i]\n"; } } else { # Ab hier Standard-Layout if ($language =~ /english/i) { print "Now you can add your own entry for the guestbook.\n"; if ($forbit_html == 1) {print "Please notice, that HTML-tags arn't allowed.\n";} else {print "HTML-Tags will be permitted\n";} print "

\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "
Your Name:\n"; if ($dismiss) {print "
\n";} else {print "
\n";} print "
Your EMail:\n"; if ($dismiss) {print "
\n";} else {print "
\n";} if ($allow_home == 1) { print "
Your Homepage:\n"; if ($dismiss) {print "
\n";} else {print "
\n";} } print "
Your Text:\n"; if ($dismiss) { $i=0; open(f1, "<$temp2") || print "

Error Cannot open $tempmess"; &NLock($temp2); while() { chop($_); $shorttext[$i]=$_; $i++; } &NUnlock($temp2); close f1; $short_laenge=$i; print "

\n"; } else {print "
\n";} print "

\n"; print "

\n"; print "
\n"; } else { # Now in german print "Jetzt können Sie einen neuen Eintrag in das Gästebuch machen.\n"; if ($forbit_html == 1) {print "Bitte beachten Sie, dass HTML-Tags nicht angenommen werden.\n";} else {print "HTML-Tags werden innerhalb des Textfeldes unterstützt.\n";} print "
\n"; print "
\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "
Ihr Name:\n"; if ($dismiss) {print "
\n";} else {print "
\n";} print "
Ihre EMail:\n"; if ($dismiss) {print "
\n";} else {print "
\n";} if ($allow_home == 1) { print "
Ihre Homepage:\n"; if ($dismiss) {print "
\n";} else {print "
\n";} } print "
Text:\n"; if ($dismiss) { $i=0; open(f1, "<$temp2") || print "

Error Cannot open $tempmess"; &NLock($temp2); while() { chop($_); $shorttext[$i]=$_; $i++; } &NUnlock($temp2); close f1; $short_laenge=$i; print "

\n"; } else {print "
\n";} print "

\n"; print "

\n"; print "
\n"; } } } ##################################################################################### sub Fehlermeldung { # Gibt Fehlermeldungen aus local($fehlertext)=@_; if ($HEADER) {&HtmlTop(',,');} print "

ERROR!
\n"; print "

The following failure was detected:

\n"; print "

$fehlertext
\n"; print "

"; print "

There is a help avaible for this. Check out: \n"; print "Informations about the guestbook\n"; print "


"; print "Skript written by xwolf, feedback welcome"; exit(0); } ##################################################################################### sub check_entry { my($server,$subpage); if (length($homepage) < 11) {$homepage="";} if (($allow_home) && ($homepage =~ /http/)) { $server=substr($homepage,7,length($homepage)); $subpage=substr($server,index($server,'/'),length($server)); $server=substr($server,0,index($server,'/')); $status = &httpstatus($server,$subpage); if ($status >= 400) {$homepage='';} } if ((! $name) || ((! $email) && ($need_mail==1)) || (! $text)) { if ($language =~ /german/) { print "


Sie haben nicht alle nötigen Felder ausgefüllt!

\n"; if (! $name) { print "Sie gaben keinen Namen an!\n";} if ((! $email) && ($need_mail==1)) { print "Nanu?! Keine EMail? \n";} if (! $text) { print "Einen Eintrag ohne Text??\n";} print "

\n"; print "\n"; print "\n"; print "\n"; print " oder "; print "

\n"; print "\n"; print "\n"; print "
\n"; } else { print "

You gave not all important entrys!

\n"; if (! $name) { print "You gave no name??\n";} if ((! $email) && ($need_mail ==1)) { print "Strange! No EMail?! \n";} if (! $text) { print "A message without text??\n";} print "

\n"; print "

\n"; print "\n"; print "\n"; print "
or "; print "
\n"; print "\n"; print "\n"; print "
\n"; } } else { # First of all, I save the text, to avoid problems with HTML-tags if I would # use this values as hidden-objects in the following input-form. open(f1,">$temp2") || print "

Error Cannot open $tempmess"; print f1 "$text\n"; close f1; # Now the preview: &preview; } } ##################################################################################### sub preview { # Here the users will get a preview of their new entry local($shorttext,$short_laenge); if ($language =~ /german/) { print "

Voransicht:

\n";} else {print "

Preview:

\n";} print "$seperator"; $i=0; open(f1, "<$temp2") || print "

Error Cannot open $tempmess"; &NLock($temp2); while() { chop($_); $shorttext[$i]=$_; $shorttext[$i]=$shorttext[$i].'
'; $i++; } &NUnlock($temp2); close f1; $short_laenge=$i; if (($allow_home==1) && ($homepage)) { print "

$name"; } else {print "
$name";} if ($email) {print " ($email), $zeit
";} else {print ", $zeit
";} print "

"; for ($i=0;$i<$short_laenge;$i++) { print "

$starti $shorttext[$i] $stopi\n"; } &EndHtmlTags(1); print "$seperator\n"; print "
\n"; if ($language =~ /german/) { print "
\n"; print ""; print ""; print ""; print "\n"; print "\n"; print "\n"; print " or "; print "
\n"; } else { print "
\n"; print ""; print ""; print ""; print "\n"; print "\n"; print "\n"; print " or "; print "
\n"; } print ""; } ##################################################################################### sub save_entry { # I will now save the entry local($shorttext,$short_laenge); # First check for HTML-Tags $name =~ s/<([^>]|\n)*>//g; $email =~ s/<([^>]|\n)*>//g; $homepage =~ s/<([^>]|\n)*>//g; $i=0; open(f1, "<$temp2") || print "

Error Cannot open $temp2"; &NLock($temp2); while() { chop($_); $shorttext[$i]=$_; $shorttext[$i] =~ s/]|\n)*>//g; $shorttext[$i] =~ s/]|\n)*>//g; # No Meta $shorttext[$i] =~ s/