2011-01-20 09:28:53 +01:00
|
|
|
<?php
|
2010-11-05 17:46:20 +01:00
|
|
|
require 'inc/functions.php';
|
|
|
|
require 'inc/display.php';
|
2010-11-30 09:21:06 +01:00
|
|
|
require 'inc/template.php';
|
2010-12-17 15:18:03 +01:00
|
|
|
require 'inc/database.php';
|
2010-11-05 17:46:20 +01:00
|
|
|
require 'inc/user.php';
|
|
|
|
|
2010-11-26 10:21:00 +01:00
|
|
|
// Fix for magic quotes
|
2010-11-05 17:46:20 +01:00
|
|
|
if (get_magic_quotes_gpc()) {
|
2010-11-26 10:20:04 +01:00
|
|
|
function strip_array($var) {
|
2010-11-05 17:46:20 +01:00
|
|
|
return is_array($var) ? array_map("strip_array", $var) : stripslashes($var);
|
|
|
|
}
|
|
|
|
|
|
|
|
$_SESSION = strip_array($_SESSION);
|
|
|
|
$_GET = strip_array($_GET);
|
|
|
|
$_POST = strip_array($_POST);
|
|
|
|
}
|
|
|
|
|
2011-01-21 03:14:11 +01:00
|
|
|
if(isset($_POST['delete'])) {
|
|
|
|
// Delete
|
|
|
|
|
|
|
|
if( !isset($_POST['board']) ||
|
|
|
|
!isset($_POST['password'])
|
|
|
|
)
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['bot']);
|
2011-01-21 03:14:11 +01:00
|
|
|
|
|
|
|
$password = $_POST['password'];
|
|
|
|
|
|
|
|
if(empty($password))
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['invalidpassword']);
|
2011-01-21 03:14:11 +01:00
|
|
|
|
|
|
|
$delete = Array();
|
|
|
|
foreach($_POST as $post => $value) {
|
|
|
|
if(preg_match('/^delete_(\d+)$/', $post, $m)) {
|
|
|
|
$delete[] = (int)$m[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sql_open();
|
|
|
|
|
|
|
|
// Check if banned
|
|
|
|
checkBan();
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
if($config['block_tor'] && isTor())
|
|
|
|
error($config['error']['tor']);
|
2011-01-21 03:14:11 +01:00
|
|
|
|
|
|
|
// Check if board exists
|
|
|
|
if(!openBoard($_POST['board']))
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['noboard']);
|
2011-01-21 03:14:11 +01:00
|
|
|
|
|
|
|
if(empty($delete))
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['nodelete']);
|
2011-01-21 03:14:11 +01:00
|
|
|
|
|
|
|
foreach($delete as &$id) {
|
|
|
|
$query = prepare(sprintf("SELECT `password` FROM `posts_%s` WHERE `id` = :id", $board['uri']));
|
|
|
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
|
|
|
$query->execute() or error(db_error($query));
|
|
|
|
|
|
|
|
if($post = $query->fetch()) {
|
|
|
|
if(!empty($password) && $post['password'] != $password)
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['invalidpassword']);
|
2011-01-21 03:14:11 +01:00
|
|
|
|
|
|
|
if(isset($_POST['file'])) {
|
|
|
|
// Delete just the file
|
|
|
|
deleteFile($id);
|
|
|
|
} else {
|
|
|
|
// Delete entire post
|
|
|
|
deletePost($id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buildIndex();
|
|
|
|
|
|
|
|
sql_close();
|
|
|
|
|
|
|
|
$is_mod = isset($_POST['mod']) && $_POST['mod'];
|
2011-02-12 07:25:15 +01:00
|
|
|
$root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root'];
|
2011-01-21 03:14:11 +01:00
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']);
|
2011-01-21 03:14:11 +01:00
|
|
|
|
|
|
|
} elseif(isset($_POST['post'])) {
|
2010-11-05 17:46:20 +01:00
|
|
|
if( !isset($_POST['name']) ||
|
|
|
|
!isset($_POST['email']) ||
|
|
|
|
!isset($_POST['subject']) ||
|
|
|
|
!isset($_POST['body']) ||
|
2010-11-30 10:40:37 +01:00
|
|
|
!isset($_POST['board']) ||
|
2010-11-05 17:46:20 +01:00
|
|
|
!isset($_POST['password'])
|
2011-02-12 07:25:15 +01:00
|
|
|
) error($config['error']['bot']);
|
2010-11-05 17:46:20 +01:00
|
|
|
|
2010-11-30 13:17:26 +01:00
|
|
|
$post = Array('board' => $_POST['board']);
|
2010-11-05 17:46:20 +01:00
|
|
|
|
|
|
|
if(isset($_POST['thread'])) {
|
|
|
|
$OP = false;
|
|
|
|
$post['thread'] = round($_POST['thread']);
|
|
|
|
} else $OP = true;
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
if(!(($OP && $_POST['post'] == $config['button_newtopic']) ||
|
|
|
|
(!$OP && $_POST['post'] == $config['button_reply'])))
|
|
|
|
error($config['error']['bot']);
|
2010-11-05 17:46:20 +01:00
|
|
|
|
|
|
|
// Check the referrer
|
|
|
|
if($OP) {
|
2011-02-12 07:25:15 +01:00
|
|
|
if(!isset($_SERVER['HTTP_REFERER']) || !preg_match($config['url_match'], $_SERVER['HTTP_REFERER'])) error($config['error']['bot']);
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Since we're now using static HTML files, we can't give them cookies on their first page view
|
|
|
|
// Find another anti-spam method.
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Check if he has a valid cookie.
|
2011-02-12 07:25:15 +01:00
|
|
|
if(!$user['valid']) error($config['error']['bot']);
|
2010-11-05 17:46:20 +01:00
|
|
|
|
|
|
|
// Check how long he has been here.
|
|
|
|
if(time()-$user['appeared']<LURKTIME) error(ERROR_LURK);
|
|
|
|
*/
|
|
|
|
|
2010-11-30 13:17:26 +01:00
|
|
|
// Open database connection
|
|
|
|
sql_open();
|
|
|
|
|
2011-01-01 15:37:52 +01:00
|
|
|
// Check if banned
|
|
|
|
checkBan();
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
if($config['block_tor'] && isTor())
|
|
|
|
error($config['error']['tor']);
|
2011-01-19 02:37:31 +01:00
|
|
|
|
2010-11-30 13:17:26 +01:00
|
|
|
// Check if board exists
|
|
|
|
if(!openBoard($post['board']))
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['noboard']);
|
2010-11-30 13:17:26 +01:00
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
//if(ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && ROBOT_MUTE) {
|
|
|
|
// checkMute();
|
|
|
|
//}
|
2011-01-20 09:24:41 +01:00
|
|
|
|
2010-11-30 13:17:26 +01:00
|
|
|
//Check if thread exists
|
|
|
|
if(!$OP && !threadExists($post['thread']))
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['nonexistant']);
|
2011-01-02 15:33:57 +01:00
|
|
|
|
2010-11-05 17:46:20 +01:00
|
|
|
// Check for a file
|
|
|
|
if($OP) {
|
|
|
|
if(!isset($_FILES['file']['tmp_name']) || empty($_FILES['file']['tmp_name']))
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['noimage']);
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$post['name'] = (!empty($_POST['name'])?$_POST['name']:'Anonymous');
|
|
|
|
$post['subject'] = $_POST['subject'];
|
|
|
|
$post['email'] = utf8tohtml($_POST['email']);
|
|
|
|
$post['body'] = $_POST['body'];
|
|
|
|
$post['password'] = $_POST['password'];
|
2011-02-03 10:28:14 +01:00
|
|
|
$post['filename'] = get_magic_quotes_gpc() ? stripslashes($_FILES['file']['name']) : $_FILES['file']['name'];
|
2010-11-05 17:46:20 +01:00
|
|
|
$post['has_file'] = $OP || !empty($_FILES['file']['tmp_name']);
|
2011-01-02 11:10:33 +01:00
|
|
|
$post['mod'] = isset($_POST['mod']) && $_POST['mod'];
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
if(empty($post['body']) && $config['force_body'])
|
|
|
|
error($config['error']['tooshortbody']);
|
2011-01-19 02:37:31 +01:00
|
|
|
|
2011-01-02 11:10:33 +01:00
|
|
|
if($post['mod']) {
|
|
|
|
require 'inc/mod.php';
|
|
|
|
if(!$mod) {
|
|
|
|
// Liar. You're not a mod.
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['notamod']);
|
2011-01-02 11:10:33 +01:00
|
|
|
}
|
2011-01-02 11:15:59 +01:00
|
|
|
|
2011-01-02 12:30:49 +01:00
|
|
|
$post['sticky'] = $OP && isset($_POST['sticky']);
|
|
|
|
$post['locked'] = $OP && isset($_POST['lock']);
|
2011-02-03 10:28:14 +01:00
|
|
|
$post['raw'] = isset($_POST['raw']);
|
2011-01-02 15:15:55 +01:00
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
if($post['sticky'] && $mod['type'] < $config['mod']['sticky']) error($config['error']['noaccess']);
|
|
|
|
if($post['locked'] && $mod['type'] < $config['mod']['lock']) error($config['error']['noaccess']);
|
|
|
|
if($post['raw'] && $mod['type'] < $config['mod']['rawhtml']) error($config['error']['noaccess']);
|
2011-01-02 11:10:33 +01:00
|
|
|
}
|
2010-11-05 17:46:20 +01:00
|
|
|
|
2011-01-02 15:33:57 +01:00
|
|
|
// Check if thread is locked
|
|
|
|
// but allow mods to post
|
2011-02-12 07:25:15 +01:00
|
|
|
if(!$OP && (!$mod || $mod['type'] < $config['mod']['postinlocked'])) {
|
2011-01-02 15:41:14 +01:00
|
|
|
if(threadLocked($post['thread']))
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['locked']);
|
2011-01-02 15:33:57 +01:00
|
|
|
}
|
|
|
|
|
2010-11-05 17:46:20 +01:00
|
|
|
if($post['has_file']) {
|
|
|
|
$size = $_FILES['file']['size'];
|
2011-02-12 07:25:15 +01:00
|
|
|
if($size > $config['max_filesize'])
|
|
|
|
error(sprintf3($config['error']['filesize'], array(
|
2010-11-04 16:20:19 +01:00
|
|
|
'sz'=>commaize($size),
|
|
|
|
'filesz'=>commaize($size),
|
2011-02-12 07:25:15 +01:00
|
|
|
'maxsz'=>commaize($config['max_filesize']))));
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
if($mod && $mod['type'] >= MOD && preg_match('/^((.+) )?## (.+)$/', $post['name'], $match)) {
|
|
|
|
if(($mod['type'] == MOD && $match[3] == 'Mod') || $mod['type'] >= ADMIN) {
|
2011-01-19 02:37:31 +01:00
|
|
|
$post['mod_tag'] = $match[3];
|
|
|
|
$post['name'] = !empty($match[2])?$match[2]:'Anonymous';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$post['mod_tag'] = false;
|
|
|
|
}
|
|
|
|
|
2010-11-05 17:46:20 +01:00
|
|
|
$trip = generate_tripcode($post['name']);
|
|
|
|
$post['name'] = $trip[0];
|
|
|
|
$post['trip'] = (isset($trip[1])?$trip[1]:'');
|
|
|
|
|
|
|
|
if($post['email'] == 'noko') {
|
|
|
|
$noko = true;
|
|
|
|
$post['email'] = '';
|
|
|
|
} else $noko = false;
|
|
|
|
|
|
|
|
if($post['has_file']) {
|
|
|
|
$post['extension'] = strtolower(substr($post['filename'], strrpos($post['filename'], '.') + 1));
|
2011-02-03 10:28:14 +01:00
|
|
|
$post['file_id'] = time() . rand(100, 999);
|
2011-02-12 07:25:15 +01:00
|
|
|
$post['file'] = $board['dir'] . $config['dir']['img'] . $post['file_id'] . '.' . $post['extension'];
|
|
|
|
$post['thumb'] = $board['dir'] . $config['dir']['thumb'] . $post['file_id'] . '.png';
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check string lengths
|
2011-02-12 07:25:15 +01:00
|
|
|
if(strlen($post['name']) > 50) error(sprintf($config['error']['toolong'], 'name'));
|
|
|
|
if(strlen($post['email']) > 30) error(sprintf($config['error']['toolong'], 'email'));
|
|
|
|
if(strlen($post['subject']) > 40) error(sprintf($config['error']['toolong'], 'subject'));
|
|
|
|
if(!$mod && strlen($post['body']) > $config['max_body']) error($config['error']['toolongbody']);
|
|
|
|
if(!(!$OP && $post['has_file']) && strlen($post['body']) < 1) error($config['error']['tooshortbody']);
|
|
|
|
if(strlen($post['password']) > 20) error(sprintf($config['error']['toolong'], 'password'));
|
2010-11-05 17:46:20 +01:00
|
|
|
|
2011-01-19 02:37:31 +01:00
|
|
|
if($post['mod_tag'])
|
|
|
|
$post['trip'] .= ' <a class="nametag">## ' . $post['mod_tag'] . '</a>';
|
|
|
|
|
2011-01-20 09:24:41 +01:00
|
|
|
$post['body_nomarkup'] = $post['body'];
|
2011-02-03 10:28:14 +01:00
|
|
|
|
|
|
|
if(!($mod && $post['raw']))
|
|
|
|
markup($post['body']);
|
2010-11-05 17:46:20 +01:00
|
|
|
|
2011-01-18 07:11:28 +01:00
|
|
|
// Check for a flood
|
2011-01-19 02:37:31 +01:00
|
|
|
if(checkFlood($post)) {
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['flood']);
|
2011-01-19 02:37:31 +01:00
|
|
|
}
|
2011-01-18 14:41:43 +01:00
|
|
|
|
2010-11-05 17:46:20 +01:00
|
|
|
if($post['has_file']) {
|
|
|
|
// Just trim the filename if it's too long
|
|
|
|
if(strlen($post['filename']) > 30) $post['filename'] = substr($post['filename'], 0, 27).'…';
|
|
|
|
// Move the uploaded file
|
2011-02-12 07:25:15 +01:00
|
|
|
if(!@move_uploaded_file($_FILES['file']['tmp_name'], $post['file'])) error($config['error']['nomove']);
|
2010-11-05 17:46:20 +01:00
|
|
|
|
|
|
|
$size = @getimagesize($post['file']);
|
|
|
|
$post['width'] = $size[0];
|
|
|
|
$post['height'] = $size[1];
|
|
|
|
|
|
|
|
// Check if the image is valid
|
|
|
|
if($post['width'] < 1 || $post['height'] < 1) {
|
|
|
|
unlink($post['file']);
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['invalidimg']);
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
if($post['width'] > $config['max_width'] || $post['height'] > $config['max_height']) {
|
2010-11-05 17:46:20 +01:00
|
|
|
unlink($post['file']);
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['maxsize']);
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
$post['filehash'] = $config['file_hash']($post['file']);
|
2010-11-05 17:46:20 +01:00
|
|
|
$post['filesize'] = filesize($post['file']);
|
|
|
|
|
|
|
|
$image = createimage($post['extension'], $post['file']);
|
|
|
|
|
|
|
|
// Create a thumbnail
|
2011-02-12 07:25:15 +01:00
|
|
|
$thumb = resize($image, $post['width'], $post['height'], $post['thumb'], $config['thumb_width'], $config['thumb_height']);
|
2010-11-05 17:46:20 +01:00
|
|
|
|
|
|
|
$post['thumbwidth'] = $thumb['width'];
|
|
|
|
$post['thumbheight'] = $thumb['height'];
|
|
|
|
}
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
/*
|
|
|
|
if(!($mod && $mod['type'] >= $config['mod']['postunoriginal']) && ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && checkRobot($post['body_nomarkup'])) {
|
2011-01-20 09:24:41 +01:00
|
|
|
if(ROBOT_MUTE) {
|
2011-02-12 07:25:15 +01:00
|
|
|
error(sprintf($config['error']['muted'], mute()));
|
2011-01-20 09:24:41 +01:00
|
|
|
} else {
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['unoriginal']);
|
2011-01-20 09:24:41 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-12 07:25:15 +01:00
|
|
|
*/
|
2011-01-20 09:24:41 +01:00
|
|
|
|
2010-11-05 17:46:20 +01:00
|
|
|
// Remove DIR_* before inserting them into the database.
|
2010-11-30 09:25:50 +01:00
|
|
|
if($post['has_file']) {
|
2011-02-12 07:25:15 +01:00
|
|
|
$post['file'] = substr_replace($post['file'], '', 0, strlen($board['dir'] . $config['dir']['img']));
|
|
|
|
$post['thumb'] = substr_replace($post['thumb'], '', 0, strlen($board['dir'] . $config['dir']['thumb']));
|
2010-11-30 09:25:50 +01:00
|
|
|
}
|
2010-11-05 17:46:20 +01:00
|
|
|
|
|
|
|
// Todo: Validate some more, remove messy code, allow more specific configuration
|
|
|
|
$id = post($post, $OP);
|
|
|
|
|
2011-02-03 10:28:14 +01:00
|
|
|
buildThread(($OP?$id:$post['thread']));
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
if(!$OP && strtolower($post['email']) != 'sage' && ($config['reply_limit'] == 0 || numPosts($post['thread']) < $config['reply_limit'])) {
|
2011-02-03 10:28:14 +01:00
|
|
|
bumpThread($post['thread']);
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
2011-01-18 14:41:43 +01:00
|
|
|
if($OP)
|
|
|
|
clean();
|
|
|
|
|
2010-11-05 17:46:20 +01:00
|
|
|
buildIndex();
|
|
|
|
sql_close();
|
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
$root = $post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'];
|
2011-01-02 11:15:59 +01:00
|
|
|
|
2011-02-12 07:25:15 +01:00
|
|
|
if($config['always_noko'] || $noko) {
|
|
|
|
header('Location: ' . $root . $board['dir'] . $config['dir']['res'] . ($OP?$id:$post['thread']) . '.html' . (!$OP?'#'.$id:''), true, $config['redirect_http']);
|
2010-11-05 17:46:20 +01:00
|
|
|
} else {
|
2011-02-12 07:25:15 +01:00
|
|
|
header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']);
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|
|
|
|
} else {
|
2011-02-12 07:25:15 +01:00
|
|
|
if(!file_exists($config['has_installed'])) {
|
2010-11-30 10:40:37 +01:00
|
|
|
sql_open();
|
|
|
|
|
|
|
|
// Build all boards
|
2010-12-17 15:18:03 +01:00
|
|
|
$boards = listBoards();
|
|
|
|
foreach($boards as &$_board) {
|
2010-11-30 10:40:37 +01:00
|
|
|
setupBoard($_board);
|
|
|
|
buildIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
sql_close();
|
2011-02-12 07:25:15 +01:00
|
|
|
touch($config['has_installed'], 0777);
|
2010-11-30 10:40:37 +01:00
|
|
|
|
|
|
|
die(Element('page.html', Array(
|
|
|
|
'index'=>ROOT,
|
|
|
|
'title'=>'Success',
|
|
|
|
'body'=>"<center>" .
|
|
|
|
"<h2>Tinyboard is now installed!</h2>" .
|
|
|
|
"</center>"
|
|
|
|
)));
|
|
|
|
} else {
|
|
|
|
// They opened post.php in their browser manually.
|
|
|
|
// Possible TODO: Redirect back to homepage.
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['nopost']);
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|