rendered paste body<?php/* bboard.php: Simple flatfile PHP bulletin board/guestbook system * Copyright © 2008 Segin Takushiro <segin2005@gmail.com> * * Licensed under the GNU GPLv2. */function PMA_getenv($var_name) { if (isset($_SERVER[$var_name])) { return $_SERVER[$var_name]; } elseif (isset($_ENV[$var_name])) { return $_ENV[$var_name]; } elseif (getenv($var_name)) { return getenv($var_name); } elseif (function_exists('apache_getenv') && apache_getenv($var_name, true)) { return apache_getenv($var_name, true); } return '';}if (isset($_GET['submit'])) { $dosubmit = 1;}if (isset($_GET['user'])){ if($_GET['user'] == '') { $user = "Anonymous"; } else { $user = $_GET['user']; }} else { $user = 'Anonymous';}if (isset($_GET['email'])){ if($_GET['email'] == '') { $email = "(none)"; } else { $email = $_GET['email']; }} else { $email = '(none)';}if (isset($_GET['message'])){ if($_GET['message'] == '') { $dosubmit = 0; } else { $message = $_GET['message']; }} else { $dosubmit = 0;}if (empty($HTTP_HOST)) { if (PMA_getenv('HTTP_HOST')) { $HTTP_HOST = PMA_getenv('HTTP_HOST'); } else { $HTTP_HOST = ''; }}$messageFile = "log.txt";if (isset($_GET['erase'])){ if(file_exists($messageFile)) unlink($messageFile); header("Location: " . "http://" . $HTTP_HOST . $_SERVER['SCRIPT_NAME'] . "?"); exit();}if (!is_file($messageFile)) { $fp = fopen($messageFile, 'w+');} else $fp = fopen($messageFile, 'r+');if (filesize($messageFile) > 0) $messageFileContents = fread($fp, filesize ($messageFile));preg_match_all('/user = (.*)\nemail = (.*)\nmessage = (.*)\n/',$messageFileContents,$matches);/* * $nm = New $messages * $nc = new count * $oc = old count */if (count($matches[1]) > 50) { $nc = count($matches[1]) - ($dosubmit ? 49 : 50); $oc = $nc + ($dosubmit ? 49 : 50); fclose($fp); $fp = fopen($messageFile, 'w+'); for($i = 0; $i + $nc < $oc ; $i++) { fwrite($fp, "user = " . $matches[1][$i + $nc] . "\n"); fwrite($fp, "email = " . $matches[2][$i + $nc] . "\n"); fwrite($fp, "message = " . $matches[3][$i + $nc] . "\n"); } fclose($fp); $fp = fopen($messageFile, 'r+'); $messageFileContents = fread($fp, filesize ($messageFile)); preg_match_all('/user = (.*)\nemail = (.*)\nmessage = (.*)\n/',$messageFileContents,$matches);}if ($dosubmit == 1) { $message = strip_tags($message, "<a><p><br><span><div><b><i><u><img>"); $message = nl2br($message); $message = str_replace("\n", "", $message); fwrite($fp, "user = " . $user . "\n"); fwrite($fp, "email = " . $email . "\n"); fwrite($fp, "message = " . $message . "\n"); fclose($fp); header("Location: " . "http://" . $HTTP_HOST . $_SERVER['SCRIPT_NAME'] . "?"); exit();}if (count($_REQUEST) > 1000) { die('possible exploit');}if (! function_exists('preg_match_all')) { die("Can't load PCRE!");}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head> <title>Arika Server Bulletin Board</title> <style type="text/css"> table { border-width: 3px; color: rgb(64,64,255); } td.nomsg { font-weight: bold; text-align: center; background: rgb(255,232,232); } tr.msg { background: rgb(232,232,255); } tr.head { background: rgb(232,255,232); font-weight: bold; } </style></head><body><form method="get" action="bboard.php" target="_self"><p><input type="checkbox" checked="1" name="submit" style="display:none" /><table align="center"> <tr> <td colspan="2" style="text-align: center; font-family: sans-serif; font-weight:bold"> Arika Server Bulletin Board </td> </tr> <tr> <td>User:</td> <td><input style="WIDTH: 300px; HEIGHT: 22px" size="38" name="user" /></td> </tr> <tr> <td>E-mail:</td> <td><input style="WIDTH: 300px; HEIGHT: 22px" size="38" name="email" /></td> </tr> <tr> <td colspan="2">Message:</td> </tr> <tr> <td colspan="2"> <textarea style="WIDTH: 359px; HEIGHT: 111px" name="message" rows="4" cols="37"></textarea> </td> </tr> <tr> <td colspan="2"> <p align="center"><input type="submit" value="Submit Query"></p> </td> </tr></table></p></form><table width="100%" cellspacing="1" cellpadding="1" border="1"> <tr class="head"> <td width="17.5%">User</thead> <td width="25%">E-mail Address</thead> <td width="100%">Message</thead> </tr><?php if(count($matches[1]) == 0) { ?> <tr> <td class="nomsg" colspan="3">No Messages</td> </tr></table> <?php?><?php } else { for($a = 0; $a < (count($matches[1]) < 51 ? count($matches[1]) : 50) ; $a++ ) { echo " <tr class=\"msg\">\n"; echo " <td>" . $matches[1][$a] . "</td>\n"; echo " <td><a href=\"mailto:" . $matches[2][$a] . "\">" . $matches[2][$a] . "</a></td>\n"; echo " <td><tt>". $matches[3][$a] . "</tt></td>\n"; echo " </td>\n"; }?></table><?php } echo "<p align=\"center\">Message count: " . count($matches[1]) . "</p>\n";?></body></html>