Skip to content
This repository
tag: v1.1
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 287 lines (248 sloc) 9.783 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
<?php
# TinyIB
#
# https://github.com/tslocum/TinyIB

error_reporting(E_ALL);
ini_set("display_errors", 1);
session_start();

if (get_magic_quotes_gpc()) {
foreach ($_GET as $key => $val) { $_GET[$key] = stripslashes($val); }
foreach ($_POST as $key => $val) { $_POST[$key] = stripslashes($val); }
}
if (get_magic_quotes_runtime()) { set_magic_quotes_runtime(0); }

function fancyDie($message) {
die('<body text="#800000" bgcolor="#FFFFEE" align="center"><br><span style="background-color: #F0E0D6;font-size: 1.25em;font-family: Tahoma, Geneva, sans-serif;padding: 7px;border: 1px solid #D9BFB7;border-left: none;border-top: none;">' . $message . '</span><br><br>- <a href="javascript:history.go(-1)">Click here to go back</a> -</body>');
}

if (!file_exists('settings.php')) {
fancyDie('Please rename the file settings.default.php to settings.php');
}
require 'settings.php';

// Check directories are writable by the script
$writedirs = array("res", "src", "thumb");
if (TINYIB_DBMODE == 'flatfile') { $writedirs[] = "inc/flatfile"; }
foreach ($writedirs as $dir) {
if (!is_writable($dir)) {
fancyDie("Directory '" . $dir . "' can not be written to! Please modify its permissions.");
}
}

$includes = array("inc/functions.php", "inc/html.php");
if (in_array(TINYIB_DBMODE, array('flatfile', 'mysql', 'sqlite'))) {
$includes[] = 'inc/database_' . TINYIB_DBMODE . '.php';
} else {
fancyDie("Unknown database mode specificed");
}

foreach ($includes as $include) {
include $include;
}

if (TINYIB_TRIPSEED == '' || TINYIB_ADMINPASS == '') {
fancyDie('TINYIB_TRIPSEED and TINYIB_ADMINPASS must be configured!');
}

$redirect = true;
// Check if the request is to make a post
if (isset($_POST["message"]) || isset($_POST["file"])) {
list($loggedin, $isadmin) = manageCheckLogIn();
$modpost = isModPost();
if (!$loggedin) {
checkBanned();
checkMessageSize();
checkFlood();
}

$post = newPost();
$post['parent'] = setParent();
$post['ip'] = $_SERVER['REMOTE_ADDR'];

list($post['name'], $post['tripcode']) = nameAndTripcode($_POST["name"]);

$post['name'] = cleanString(substr($post['name'], 0, 75));
$post['email'] = cleanString(str_replace('"', '&quot;', substr($_POST["email"], 0, 75)));
$post['subject'] = cleanString(substr($_POST["subject"], 0, 75));
if ($modpost) {
$modposttext = ($isadmin) ? ' <span style="color: red;">## Admin</span>' : ' <span style="color: purple;">## Mod</span>';
$post['message'] = $_POST["message"]; // Treat message as raw HTML
} else {
$modposttext = '';
$post['message'] = str_replace("\n", "<br>", colorQuote(postLink(cleanString(rtrim($_POST["message"])))));
}
$post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : '';
if (strtolower($post['email']) == "noko") {
$post['email'] = '';
$noko = true;
} else {
$noko = false;
}
$post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $modposttext);

if (isset($_FILES['file'])) {
if ($_FILES['file']['name'] != "") {
validateFileUpload();

if (!is_file($_FILES['file']['tmp_name']) || !is_readable($_FILES['file']['tmp_name'])) {
fancyDie("File transfer failure. Please retry the submission.");
}

$post['file_original'] = substr(htmlentities($_FILES['file']['name'], ENT_QUOTES), 0, 50);
$post['file_hex'] = md5_file($_FILES['file']['tmp_name']);
$post['file_size'] = $_FILES['file']['size'];
$post['file_size_formatted'] = convertBytes($post['file_size']);
$file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name'])); if ($file_type == '.jpeg') { $file_type = '.jpg'; }
$file_name = time() . mt_rand(1, 99);
$post['thumb'] = $file_name . "s" . $file_type;
$post['file'] = $file_name . $file_type;
$thumb_location = "thumb/" . $post['thumb'];
$file_location = "src/" . $post['file'];

if (!($file_type == '.jpg' || $file_type == '.gif' || $file_type == '.png')) {
fancyDie("Only GIF, JPG, and PNG files are allowed.");
}

if (!@getimagesize($_FILES['file']['tmp_name'])) {
fancyDie("Failed to read the size of the uploaded file. Please retry the submission.");
}
$file_info = getimagesize($_FILES['file']['tmp_name']);
$file_mime = $file_info['mime'];

if (!($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png")) {
fancyDie("Only GIF, JPG, and PNG files are allowed.");
}

checkDuplicateImage($post['file_hex']);

if (!move_uploaded_file($_FILES['file']['tmp_name'], $file_location)) {
fancyDie("Could not copy uploaded file.");
}

if ($_FILES['file']['size'] != filesize($file_location)) {
fancyDie("File transfer failure. Please go back and try again.");
}

$post['image_width'] = $file_info[0]; $post['image_height'] = $file_info[1];

list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post['image_width'], $post['image_height']);

if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) {
fancyDie("Could not create thumbnail.");
}

$thumb_info = getimagesize($thumb_location);
$post['thumb_width'] = $thumb_info[0]; $post['thumb_height'] = $thumb_info[1];
}
}

if ($post['file'] == '') { // No file uploaded
if ($post['parent'] == '0') {
fancyDie("An image is required to start a thread.");
}
if (str_replace('<br>', '', $post['message']) == "") {
fancyDie("Please enter a message and/or upload an image to make a reply.");
}
}

$post['id'] = insertPost($post);
if ($noko) {
$redirect = 'res/' . ($post['parent'] == '0' ? $post['id'] : $post['parent']) . '.html#' . $post['id'];
}
trimThreads();
echo 'Updating thread page...<br>';
if ($post['parent'] != '0') {
rebuildThread($post['parent']);

if (strtolower($post['email']) != "sage") {
bumpThreadByID($post['parent']);
}
} else {
rebuildThread($post['id']);
}

echo 'Updating thread index...<br>';
rebuildIndexes();
// Check if the request is to delete a post and/or its associated image
} elseif (isset($_GET['delete']) && !isset($_GET['manage'])) {
if (isset($_POST['delete'])) {
$post = postByID($_POST['delete']);
if ($post) {
if ($post['password'] != '' && md5(md5($_POST['password'])) == $post['password']) {
deletePostByID($post['id']);
if ($post['parent'] == 0) { threadUpdated($post['id']); } else { threadUpdated($post['parent']); }
echo 'Post successfully deleted.';
} else {
fancyDie('Invalid password.');
}
} else {
fancyDie('Sorry, an invalid post identifier was sent. Please go back, refresh the page, and try again.');
}
} else {
fancyDie('Tick the box next to a post and click "Delete" to delete it.');
}
$redirect = false;
// Check if the request is to access the management area
} elseif (isset($_GET["manage"])) {
$text = ""; $onload = ""; $navbar = "&nbsp;";
$redirect = false; $loggedin = false; $isadmin = false;
$returnlink = basename($_SERVER['PHP_SELF']);

list($loggedin, $isadmin) = manageCheckLogIn();

if ($loggedin) {
if ($isadmin) {
if (isset($_GET["rebuildall"])) {
$allthreads = allThreads();
foreach ($allthreads as $thread) {
rebuildThread($thread["id"]);
}
rebuildIndexes();
$text .= "Rebuilt board.";
} elseif (isset($_GET["bans"])) {
clearExpiredBans();

if (isset($_POST['ip'])) {
if ($_POST['ip'] != '') {
$banexists = banByIP($_POST['ip']);
if ($banexists) {
fancyDie('Sorry, there is already a ban on record for that IP address.');
}

$ban = array();
$ban['ip'] = $_POST['ip'];
$ban['expire'] = ($_POST['expire'] > 0) ? (time() + $_POST['expire']) : 0;
$ban['reason'] = $_POST['reason'];

insertBan($ban);
$text .= '<b>Successfully added a ban record for ' . $ban['ip'] . '</b><br>';
}
} elseif (isset($_GET['lift'])) {
$ban = banByID($_GET['lift']);
if ($ban) {
deleteBanByID($_GET['lift']);
$text .= '<b>Successfully lifted ban on ' . $ban['ip'] . '</b><br>';
}
}

$onload = manageOnLoad('bans');
$text .= manageBanForm();
$text .= manageBansTable();
}
}

if (isset($_GET["delete"])) {
$post = postByID($_GET['delete']);
if ($post) {
deletePostByID($post['id']);
rebuildIndexes();
if ($post['parent'] > 0) {
rebuildThread($post['parent']);
}
$text .= '<b>Post No.' . $post['id'] . ' successfully deleted.</b>';
} else {
fancyDie("Sorry, there doesn't appear to be a post with that ID.");
}
} elseif (isset($_GET["moderate"])) {
if ($_GET['moderate'] > 0) {
$post = postByID($_GET['moderate']);
if ($post) {
$text .= manageModeratePost($post);
} else {
fancyDie("Sorry, there doesn't appear to be a post with that ID.");
}
} else {
$onload = manageOnLoad('moderate');
$text .= manageModeratePostForm();
}
} elseif (isset($_GET["modpost"])) {
$onload = manageOnLoad('modpost');
$text .= manageModpostForm();
} elseif (isset($_GET["logout"])) {
$_SESSION['tinyib'] = '';
session_destroy();
die('--&gt; --&gt; --&gt;<meta http-equiv="refresh" content="0;url=' . $returnlink . '?manage">');
}
if ($text == '') {
$threads = countThreads();
$bans = count(allBans());
$text = $threads . ' ' . plural('thread', $threads) . ', ' . $bans . ' ' . plural('ban', $bans) . '.';
}
} else {
$onload = manageOnLoad('login');
$text .= manageLogInForm();
}

echo managePage($text, $onload);
} elseif (!file_exists('index.html') || count(allThreads()) == 0) {
rebuildIndexes();
}

if ($redirect) {
echo '--&gt; --&gt; --&gt;<meta http-equiv="refresh" content="0;url=' . (is_string($redirect) ? $redirect : 'index.html') . '">';
}

?>
Something went wrong with that request. Please try again.