Merge branch '48-prev-reply-op' into 'config'

Resolve "Require previous replies to make a thread"

See merge request leftypol/leftypol!12
This commit is contained in:
Zankaria Auxa 2024-11-12 14:19:41 +00:00
commit c8d84afa07
3 changed files with 46 additions and 0 deletions

View file

@ -236,6 +236,9 @@
// To prevent bump atacks; returns the thread to last position after the last post is deleted. // To prevent bump atacks; returns the thread to last position after the last post is deleted.
$config['anti_bump_flood'] = false; $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: * Introduction to Tinyboard's spam filter:
* *
@ -1216,6 +1219,7 @@
// Error messages // Error messages
$config['error']['bot'] = _('You look like a bot.'); $config['error']['bot'] = _('You look like a bot.');
$config['error']['referer'] = _('Your browser sent an invalid or no HTTP referer.'); $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'] = _('The %s field was too long.');
$config['error']['toolong_body'] = _('The body was too long.'); $config['error']['toolong_body'] = _('The body was too long.');
$config['error']['tooshort_body'] = _('The body was too short or empty.'); $config['error']['tooshort_body'] = _('The body was too short or empty.');

View file

@ -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) { function threadLocked($id) {
global $board; global $board;

View file

@ -932,6 +932,13 @@ function handle_post()
// Check if banned // Check if banned
checkBan($board['uri']); 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']) { if ($post['mod'] = isset($_POST['mod']) && $_POST['mod']) {
check_login(false); check_login(false);
if (!$mod) { if (!$mod) {