@.com"; $mailSubject = "New Guestbook Entry"; ############################################################ ## Configuration Step 3 : Customize the HTML Header ############################################################ ## You'll obviously want to make the guestbook look like ## part of your site, and that means customizing the HTML ## code for the header and footer. By header I mean all ## the HTml from the DOCTYPE and starting tag to ## the point just before the guestbook content begins. By ## footer I mean all the HTML from the point just after ## the guestbook content ends to the closing tag. ## Place your custom code between the appropriate comments ## below. ############################################################ function displayHeader() { global $version,$css_file, $page_title, $resource_dir; header ("Expires: Sat, 01 Jan 2000 00:00:00 GMT"); echo ''; echo ''; echo ' '; echo "$page_title"; include ("../inc/head.html"); echo ''; echo ''; include "../inc/top.html"; } ############################################################ ## Configuration Step 4 : Customize the HTML Footer ############################################################ ## Place your custom code between the appropriate comments ## below. ############################################################ function displayFooter() { echo '

Back to the homepage

'; include "../inc/bottom.html"; echo ''; echo ''; } ############################################################ ## Configuration Step 5 : Number of messages displayed ############################################################ ## This variable allows you to set the number of messages ## that can be displayed at one time. 0 will cause it to ## display all messages on one page. (not recommended) ############################################################ $displayStep = 10; ############################################################ ## END CONFIGURATION ############################################################ $allowAutoLink=1; // Register_Globals improvements // By Hubert Hanghofer (webmaster@BierIG.org) // $absoluteScriptPath is the name of the current script (this file) and which is going to // be modified by itself. This means that (theoretically) this file can be // placed anywhere on the system, with any fileName. $absoluteScriptPath = $PATH_TRANSLATED; // $_SERVER["PATH_TRANSLATED"]; $relativeScriptPath = $PHP_SELF; // $_SERVER["PHP_SELF"]; $refererpage = $HTTP_REFERER; // $_SERVER["HTTP_REFERER"]; // when the php preprocessor is installed as an independant binary (as CGI). if ($PATH_INFO!="") { $relativeScriptPath = $PATH_INFO; } // to be used when $PHP_SELF contains virtual directory reference // (for multi-users servers, eg : free.fr, online.fr ...) if (($SERVER_NAME=="php.proxad.net")||(($SERVER_NAME=="php3.pro.proxad.net"))) { $relativeScriptPath = substr($relativeScriptPath, strpos(substr($relativeScriptPath, 1), "/")+1); } $theName=substr($absoluteScriptPath, 0, strrpos($absoluteScriptPath, ".")); $extension=substr($absoluteScriptPath, strrpos($absoluteScriptPath, ".")+1); // The dataFile contains all the guestbook entries, and $adminpassword . // $adminpassword is the password which will be asked for any administration // actions. This password could be changed only if in admin mode (old // $adminpassword matches $admin). // Defines the name of the database file where the entries are stored. $dataFile = "${theName}.dat.${extension}"; // Multiple guestbooks, data files in one dir // Johny Bergmann $dataFile = $data_dir . strtolower($kennel_name) . '.' . ${extension}; //****************************************************************************** // function displayForm : Display the form which enables the client to type a // message. function displayForm() { global $relativeScriptPath; global $langName; global $langEmail; global $langWebsite; global $langOptional; global $langMessage; global $langSubmit; global $langSignGuestbook; global $langColor; global $langSize; global $langBig; global $langBigger; global $langBiggest; global $langHelp; global $resource_dir; // Writing HTML Code echo ("
\n"); echo ("

$langSignGuestbook

\n"); echo ("
\n"); echo ("\n"); echo ("\n"); echo ("
\n"); echo ("
\n"); echo ("\n"); echo ("\n"); echo ("
\n"); echo ("
\n"); echo ("\n"); echo ("\n"); echo ("
\n"); echo ("
\n"); echo ("\n"); echo ("
\n"); echo ("\"smiley\"\n"); echo ("\"grin\"\n"); echo ("\"rolleyes\"\n"); echo ("\"eek\"\n"); echo ("\"mad\"\n"); echo ("\"sad\"\n"); echo ("\"lol2\"\n"); echo ("\"looney\"\n"); echo (" \"bold\"\n"); echo ("\"italic\"\n"); echo ("\"underline\"\n"); echo (" \n"); echo (" \n"); echo ("
\n"); echo ("\n"); echo ("
\n"); echo ("
\n"); echo ("\n"); echo ("\n"); echo ("
\n"); echo ("
\n"); } //****************************************************************************** // function displayMessage displays the $errorMessage error message. function displayMessage($errorMessage,$msgType) { global $langAdminError; global $langSystemError; global $langSystemMessage; global $langGuestbookName; displayHeader(); echo ("\n\n
\n"); echo ("

$langGuestbookName

\n"); echo ("
\n"); if ($msgType=="1") // Admin Message echo ($langAdminError); if ($msgType=="2") // System Error echo ($langSystemError); if ($msgType=="3") // System Message echo ($langSystemMessage); echo ("\n
\n"); echo ("
\n"); echo ($errorMessage); echo ("\n
\n"); echo ("
\n\n"); displayFooter(); exit; } //****************************************************************************** // Filters all user-submitted text prior to storage. function standardizeStoredText($str) { $str = str_replace("\\'", "'", $str); $str = str_replace("\\\"", "\"", $str); $str = htmlspecialchars($str); $str = str_replace("\n", "
", $str); $str = str_replace("$", "$", $str); return $str; } // Filters all user-submitted text prior to display, after storage. function standardizeDisplayedText($str) { return $str; } // Filters all user-submitted text prior to display on admin page, after storage. function standardizeAdminDisplayedText($str) { return $str; } // Filters message body prior to display, after storage. function standardizeMessageText($str) { global $resource_dir; $str = preg_replace('/\[emo-(\w*)\]/','smiley',$str); $str = preg_replace('/\[(\/?[biu])\]/','<\1>',$str); $str = preg_replace('/\[((red)|(green)|(blue)|(orange)|(purple)|(brown))\]/','',$str); $str = preg_replace('/\[\/((red)|(green)|(blue)|(orange)|(purple)|(brown))\]/','',$str); $str = preg_replace('/\[big\]/','',$str); $str = preg_replace('/\[\/big\]/','',$str); $str = preg_replace('/\[bigger\]/','',$str); $str = preg_replace('/\[\/bigger\]/','',$str); $str = preg_replace('/\[biggest\]/','',$str); $str = preg_replace('/\[\/biggest\]/','',$str); $str = preg_replace('/([A-Zwm_]{37})(\S)/','\1 \2',$str); // Try to prevent repetitive characters from breaking the layout $str = preg_replace('/(\S{70})(\S)/','\1 \2',$str); // Try to prevent repetitive characters from breaking the layout $str = preg_replace('/(fuck|shit|asswipe|asshole|ass hole)/i','[bleep]',$str); // Try to filter some cuss words return $str; } // Filters email address prior to display, after storage. function standardizeEmailText($str) { $str = mungEmail($str); return $str; } // Scrambles an email address. function mungEmail($str) { $str = preg_replace('/\s/','',$str); preg_match('/([^\.@\n]+(\.[^\.@\n]+)*)@([^\.@\n]+(\.[^\.@\n]+)+)/e',$str,$matches); $len = strlen($matches[1]); $result = $matches[1] . $matches[3] . "." . $len; return $result; } // Filters user's website before display, after storage. function standardizeWebsiteText($str) { if (preg_match('/^\w*script:/i',$str)) return ''; // watch out for XSS! if (!preg_match('/^(\w+:\/\/)?(\w+\.\w+(\.\w+)*)(\/.*)?/',$str,$matches)) return ''; // validate and break down the url if (!$matches[1]) $matches[1] = 'http://'; // add if missing $str = $matches[1] . $matches[2] . $matches[4]; // reassemble and return return $str; } // Turns URLs into hyperlinks. function seekHttp($rawText) { $pattern = array("/http:\/\/((\w|\.|\?|\%|=|\/|-|~|#)*)/" ,"/https:\/\/((\w|\.|\?|\%|=|\/|-|~|#)*)/" ,"/(\w+(\.\w+)*@\w+(\.\w+)+)/" ); $replacement = array("http://\\1" ,"https://\\1" ,"\\1" ); $hyperLinkedText=preg_replace($pattern, $replacement, $rawText); return $hyperLinkedText; } //****************************************************************************** // function Xfopen : opens a file $fileName and locks it function Xfopen($fileName, $openMode, $sharing) { global $langOpenError; $fp=@fopen($fileName, $openMode); if (!$fp) { displayMessage($langOpenError,2); } if ($sharing==true) { $op=1; } else { $op=2; } if (!@flock($fp,$op)) { @flock($fp,3); displayMessage("flock timeout",2); } return $fp; } //****************************************************************************** // function Xfclose : unlocks the file $fp and closes it function Xfclose($fp) { @flock($fp,3); @fclose($fp); } //****************************************************************************** // function fullDisplay function fullDisplay() { global $displayStep, $displayBegin, $maxDisplay ; global $relativeScriptPath; global $index; global $archive_name, $archive_mail, $archive_website, $archive_text, $archive_date; global $allowAutoLink; global $langSignGuestbook, $langWelcome, $langPostedBy; // Checks if $displayBegin is not too large (Thanks to Ahmet Sabri ALPER ) if ($displayBegin>$maxDisplay) { $displayBegin=$maxDisplay-$displayStep+1; } displayHeader(); #echo ($displayStep ."-". $displayBegin ."-". $maxDisplay); if ($index==0) { displayFooter(); return; } echo ("
\n"); echo ("

$langWelcome

\n"); //no signing right now: echo ("$langSignGuestbook\n"); echo ("

$langSignGuestbook

\n"); echo ("
\n"); // Message arrays are displayed here : // Displaying all the entries. if ($displayStep==0) { $displayBegin=1; $displayStep=$index; } if ($displayBegin==1) { $startAt=$index % $displayStep; if ($startAt==0) $startAt=$displayStep; } else { $startAt=$displayBegin+$displayStep-1; } for ($msgNumber=$startAt ; $msgNumber>=$displayBegin ; $msgNumber--) { echo ("
\n"); echo ("
\n"); if ($archive_mail[$msgNumber]) { echo ("#$msgNumber $langPostedBy\n"); echo (""); echo (standardizeDisplayedText($archive_name[$msgNumber])); echo ("\n"); } else { echo ("#$msgNumber $langPostedBy\n"); echo (standardizeDisplayedText($archive_name[$msgNumber])); } if (standardizeWebsiteText($archive_website[$msgNumber])) { echo (' -- '); echo ('"); echo (standardizeDisplayedText(standardizeWebsiteText($archive_website[$msgNumber]))); echo ("\n"); } echo ("
\n"); echo ("
\n"); echo ("$archive_date[$msgNumber]\n"); echo ("
\n"); echo ("

\n"); if ($allowAutoLink==1) echo (seekHttp(standardizeDisplayedText(standardizeMessageText($archive_text[$msgNumber])))); else echo (standardizeDisplayedText(standardizeMessageText($archive_text[$msgNumber]))); echo ("\n

\n"); echo ("
\n"); } echo ("\n
\n"); for($i=1;$i<=$index;$i=$nextEnd+1) { $nextBegin = $i; if ($i==1) { $nextEnd=$index % $displayStep; if ($nextEnd==0) $nextEnd=$displayStep; } else $nextEnd = $i+$displayStep-1; if ($displayBegin==$nextBegin && $nextEnd!=$nextBegin) echo ("[$nextBegin-$nextEnd]\n"); else if ($displayBegin==$nextBegin && $nextEnd==$nextBegin) echo ("[$nextBegin]\n"); else if ($nextEnd==$nextBegin) echo ("[$nextBegin]\n"); else echo ("[$nextBegin-$nextEnd]\n"); } echo ("
\n"); // Displays the entry form to enable the client to type a message. // displayForm(); displayFooter(); } //****************************************************************************** function readData($resetBegin) { global $adminpassword; global $index; global $dataFile; global $archive_name, $archive_mail, $archive_website, $archive_text, $archive_date; global $displayBegin, $displayStep, $maxDisplay; // Includes automatically filled data arrays : $index = 0; $fout=Xfopen($dataFile, "r", true); include($dataFile); Xfclose($fout); // From now, $index will indicate the number of data entries. // Beginning of the data to be displayed, default = 1 if (!isset($displayBegin)) $displayBegin=""; if ($displayBegin=="" || $resetBegin==1) { $displayBegin = $index-$displayStep+1; if ($displayBegin<=0) $displayBegin=1; } // Sets the maximum that $displayBegin can reach $maxDisplay = $index; } //****************************************************************************** // If the Datafile does not exist, creates it. if (!file_exists(${dataFile})) { $fout = Xfopen($dataFile, "w+", false); fputs($fout, "
This is the auto-generated default post that gets created the first time somebody looks at the guestbook through a browser. You can log in as administrator and change the password and/or edit/delete this guestbook's messages (including this post), view the online documentation, or view the license for this software.

Please be sure to log in and change the administrator password!

-The XBook Team [emo-smiley]\";\n"); fputs($fout, "\n?>"); Xfclose ($fout); } // $admin could be set via Admin-Form by POST or via URL by GET $admin=$HTTP_POST_VARS["admin"]; if (!isset($admin)) $admin=$HTTP_GET_VARS["admin"]; else // assign POST-variables from Admin-Form { $newPassword1=$HTTP_POST_VARS["newPassword1"]; $newPassword2=$HTTP_POST_VARS["newPassword2"]; $command=$HTTP_POST_VARS["command"]; $index=$HTTP_POST_VARS["index"]; } if (!isset($admin)) { // assing variables from Guestbook-From $name=$HTTP_POST_VARS["name"]; $email=$HTTP_POST_VARS["email"]; $website=$HTTP_POST_VARS["website"]; // GREG REIMER -- adding field for posting one's website $message=$HTTP_POST_VARS["message"]; if (!$displayBegin=$HTTP_POST_VARS["displayBegin"]) $displayBegin=$HTTP_GET_VARS["displayBegin"]; if (!isset($name)) { $name=""; $message=""; } if ($name=="" || $message=="") { /**************************************************************************************** * Use Case no 1-A * * This case is encountered when a client simply wants to read the * guestbook. (Every variable is empty); ************************************************************************************/ readData(0); fullDisplay(); exit; } else { /******************************************************************************** * Use Case no 1-B * * Case is encountered when a client has just filled in the appropriate fields * (name, mail, message). * $name = "Some Name" * $email = "Some@Email" * $website = "http://www.whatever.com" * $message = "Some Message" * Simply add message in the top of all previous messages. ********************************************************************************/ $position = filesize($dataFile) - 3; $fout = Xfopen($dataFile, "r+", false); fseek($fout,$position); $insert_msgdate = date( "dS F Y - h:i:s A" ); $name=standardizeStoredText($name); $email=standardizeStoredText($email); $website=standardizeStoredText($website); $message=standardizeStoredText($message); fputs ($fout,"\$archive_name[++\$index] = \"$name\";\n"); fputs ($fout,"\$archive_mail[ \$index] = \"$email\";\n"); fputs ($fout,"\$archive_website[ \$index] = \"$website\";\n"); fputs ($fout,"\$archive_date[ \$index] = \"$insert_msgdate\";\n"); fputs ($fout,"\$archive_text[ \$index] = \"$message\";\n"); fputs ($fout,"\n?>"); Xfclose($fout); // Sending a mail to $mailRecipient if $carbonCopy=1, with the subject $mailSubject. if ($carbonCopy==1) { $message = str_replace("
", "\n", $message); $mailBody = "From: $name <$email>\n$insert_msgdate\n\n$message"; @mail($mailRecipient,$mailSubject,$mailBody,"From: $email\nReply-to: $name <$email>"); } if (strpos($refererpage, "?")==false) $page=$refererpage; else $page=substr($refererpage, 0, strpos($refererpage, "?")); header("Location: $page?"); exit; } } else { readData(0); if ($admin==$adminpassword) { if ($command=="") { displayHeader(); /************************************************************************ * Use Case no 2-A * * Admin mode (The administrator can modify password, fields, or remove * messages). * $admin = $adminpassword * Shows a password modification form. * Shows all messages and enables to modify/delete them. ************************************************************************/ echo("

XBook

$langGbAdmin

\n"); // Display the form which enables the admin to change his password echo ("
\n"); echo ("

$langPassword.

\n"); echo ("
\n"); echo ("
\n"); echo ("
\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("
\n"); echo ("
\n"); // Message arrays are displayed here in forms in order to modify them : echo ("
\n"); for ($i=1 ; $i<=$index ; $i++) { $msgNumber = $index - $i + 1; $str = str_replace("
", "\n", $archive_text[$msgNumber]); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("\n"); echo ("
$langEntry #$msgNumber
 
\n"); echo ("\n"); echo ("
\n\n"); } echo ("\n"); echo ("\n"); echo ("\n"); echo ("
\n"); echo ("
\n"); displayFooter(); exit; } else if ($command=="passwd") { // Use Case no 2-B // Admin mode (The administrator is modifying his password.). // $admin = $adminpassword // $newPassword1 = "New Password 1" // $newPassword2 = "New Password 2" // Check if $newPassword1 matches $newPassword2 // Set the $adminpassword line to : // $adminpassword = "$newPassword1" in the dataFile if($newPassword1!=$newPassword2) { // The passwords doesn't match displayMessage("$langPassError",1); } else { // Rewrites the whole Datafile with the new password, and all the entries. $fout = Xfopen($dataFile, "w", false); fputs ($fout,""); Xfclose($fout); displayMessage("$langPassChanged",3); exit; } } else if ($command=="modify") { /******************************************************************************** * Use Case no 2-C * * * * Admin mode (The administrator is updating entries). * * $admin = $adminpassword * * $nameXXX = "Modified name (no XXX)" * * $emailXXX = "Modified email (no XXX)" * * $messageXXX = "Modified message (no XXX)" * * $keep = "on" or "" * * Check if $admin matches $adminpassword. * * Rewrites ALL the fields except when $keepXXX = "" * * Rewrites the whole Datafile with the new password, and all the entries. * ********************************************************************************/ $fout = Xfopen($dataFile, "w", false); fputs ($fout,""); Xfclose($fout); if (strpos($refererpage, "?")==false) $page=$refererpage; else $page=substr($refererpage, 0, strpos($refererpage, "?")); header("Location: $page?"); exit; } } else { /************************************************ * Use Case no 2-Z * * If $admin does NOT match $adminpassword. * $admin != $adminpassword * Error message : "Wrong Admin Password" ************************************************/ displayMessage("$langWrongPassword",1); } } ?>