diff --git a/inc/config.php b/inc/config.php index 766fe912..d5cfc6d0 100644 --- a/inc/config.php +++ b/inc/config.php @@ -236,6 +236,9 @@ // To prevent bump atacks; returns the thread to last position after the last post is deleted. $config['anti_bump_flood'] = false; + // Reject thread creation from IPs without any prior post history. + $config['op_require_history'] = false; + /* * Introduction to Tinyboard's spam filter: * @@ -1216,6 +1219,7 @@ // Error messages $config['error']['bot'] = _('You look like a bot.'); $config['error']['referer'] = _('Your browser sent an invalid or no HTTP referer.'); + $config['error']['opnohistory'] = _('You must post at least once before creating thread.'); $config['error']['toolong'] = _('The %s field was too long.'); $config['error']['toolong_body'] = _('The body was too long.'); $config['error']['tooshort_body'] = _('The body was too short or empty.'); diff --git a/inc/functions.php b/inc/functions.php index 2328c1b7..83333af0 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -918,6 +918,41 @@ function checkBan($board = false) { } } +/** + * Checks if the given IP has any previous posts. + * + * @param string $ip The IP to check. + * @return bool True if the ip has already sent at least one post, false otherwise. + */ +function has_any_history(string $ip): bool { + global $config; + + if ($config['cache']['enabled']) { + $ret = cache::get("post_history_$ip"); + if ($ret !== false) { + return $ret !== 0x0; + } + } + + foreach (listBoards(true) as $board_uri) { + $query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `ip` = :ip LIMIT 1', $board_uri)); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error()); + + if ($query->fetchColumn() !== false) { + // Found a post. + if ($config['cache']['enabled']) { + cache::set("post_history_$ip", 0xA); + } + return true; + } + } + if ($config['cache']['enabled']) { + cache::set("post_history_$ip", 0x0); + } + return false; +} + function threadLocked($id) { global $board; diff --git a/post.php b/post.php index 997201b0..daaffcf6 100644 --- a/post.php +++ b/post.php @@ -932,6 +932,13 @@ function handle_post() // Check if banned checkBan($board['uri']); + if ($config['op_require_history'] && $post['op']) { + $has_any = has_any_history($_SERVER['REMOTE_ADDR']); + if (!$has_any) { + error($config['error']['opnohistory']); + } + } + if ($post['mod'] = isset($_POST['mod']) && $_POST['mod']) { check_login(false); if (!$mod) {