From c87cd9ab82335da4d05d6212dfb8bf3b1028c4c1 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Mon, 18 Jan 2021 01:30:20 -0600 Subject: [PATCH 1/4] Removes rebuild after each deleted post when deleting by ip. --- inc/mod/pages.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 0ea5328d..dec5e24a 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2259,8 +2259,6 @@ function mod_deletebyip($boardName, $post, $global = false) { rebuildThemes('post-delete', $board['uri']); - buildIndex(); - if ($post['thread']) $threads_to_rebuild[$post['board']][$post['thread']] = true; else From 8c842362bb35af65e2a2807fc1aac166899653d1 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Mon, 18 Jan 2021 01:35:18 -0600 Subject: [PATCH 2/4] If mod, bypass password on delete --- post.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/post.php b/post.php index bf42d052..5254e6fa 100644 --- a/post.php +++ b/post.php @@ -183,9 +183,18 @@ function handle_nntpchan() { function handle_delete(){ // Delete - global $config,$board; + global $config, $board, $mod; if (!isset($_POST['board'], $_POST['password'])) error($config['error']['bot']); + + check_login(false); + $is_mod = !!$mod; + + if (isset($_POST['mod']) && $_POST['mod'] && !$mod) { + // Mismatched claims. (As stated below "Liar, you are not a mod.") + error($config['error']['notamod']); + } + $password = &$_POST['password']; @@ -234,10 +243,14 @@ function handle_delete(){ error($config['error']['nodeletethread']); } - if ($password != '' && $post['password'] != $password && (!$thread || $thread['password'] != $password)) + if ($password != '' + && $post['password'] != $password + && (!$thread || $thread['password'] != $password) + && !$is_mod) { error($config['error']['invalidpassword']); + } - if ($post['time'] > time() - $config['delete_time'] && (!$thread || $thread['password'] != $password)) { + if ($post['time'] > time() - $config['delete_time']) { error(sprintf($config['error']['delete_too_soon'], until($post['time'] + $config['delete_time']))); } @@ -259,7 +272,7 @@ function handle_delete(){ buildIndex(); - $is_mod = isset($_POST['mod']) && $_POST['mod']; + $root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root']; if (!isset($_POST['json_response'])) { From c838a10bcee88b63225f9679468d6d26bd181b74 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Mon, 18 Jan 2021 01:40:04 -0600 Subject: [PATCH 3/4] Adds checks for mod permissions to delete posts in board --- post.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/post.php b/post.php index 5254e6fa..48f7ab90 100644 --- a/post.php +++ b/post.php @@ -213,12 +213,16 @@ function handle_delete(){ // Check if board exists if (!openBoard($_POST['board'])) error($config['error']['noboard']); + + // Check if mod has permission to delete posts in this board + if ($is_mod && !hasPermission($config['mod']['delete'], $board)) + error($config['error']['noaccess']); // Check if banned checkBan($board['uri']); - // Check if deletion enabled - if (!$config['allow_delete']) + // Check if deletion is enabled + if (!$is_mod && !$config['allow_delete']) error(_('Post deletion is not allowed!')); if (empty($delete)) From d9c763a8a96ea2b882308a474f4b9343010377a0 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Mon, 18 Jan 2021 18:44:30 -0600 Subject: [PATCH 4/4] Optimizes board rebuilds on deletion by IP --- inc/mod/pages.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index dec5e24a..4a2afc73 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2209,9 +2209,11 @@ function mod_deletebyip($boardName, $post, $global = false) { @set_time_limit($config['mod']['rebuild_timelimit']); + $boards_to_rebuild = array(); $threads_to_rebuild = array(); $threads_deleted = array(); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { + $boards_to_rebuild[$post['board']] = true; openBoard($post['board']); if ($config['autotagging']){ $query2 = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE id = :id", $post['board'])); @@ -2257,8 +2259,6 @@ function mod_deletebyip($boardName, $post, $global = false) { deletePost($post['id'], false, false); - rebuildThemes('post-delete', $board['uri']); - if ($post['thread']) $threads_to_rebuild[$post['board']][$post['thread']] = true; else @@ -2266,11 +2266,16 @@ function mod_deletebyip($boardName, $post, $global = false) { } foreach ($threads_to_rebuild as $_board => $_threads) { - openBoard($_board); + openBoard($_board); // Set $board which is globally referenced by buildThread() foreach ($_threads as $_thread => $_dummy) { if ($_dummy && !isset($threads_deleted[$_board][$_thread])) buildThread($_thread); } + } + + foreach(array_keys($boards_to_rebuild) as $_board) { + openBoard($_board); + rebuildThemes('post-delete', $board['uri']); buildIndex(); }