From e11c12bef54d5b05f4716f5b76202edab23fc18f Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 27 Mar 2022 18:47:58 +0200 Subject: [PATCH] Adds delete by IP excluded IP array, and config to exclude threads from delete by IP --- inc/config.php | 5 +++++ inc/mod/pages.php | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/inc/config.php b/inc/config.php index c5fa69d9..4472be9b 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1375,6 +1375,11 @@ * Mod settings * ==================== */ + // Exclude these IPs from "delete by IP", meaning clicking D+ or D++ won't affect these IPs. + $config['deletebyip_excluded_ips'] = array(); + + // If true, D+ and D++ won't affect threads. This means threads will need to be deleted manually (using D). + $config['deletebyip_exclude_threads'] = false; // Limit how many bans can be removed via the ban list. Set to false (or zero) for no limit. $config['mod']['unban_limit'] = false; diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 1b68fb2c..1ba4ab30 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2214,14 +2214,22 @@ function mod_deletebyip($boardName, $post, $global = false) { if (!$ip = $query->fetchColumn()) error($config['error']['invalidpost']); - // HACK: Prevent D+ or D++ deletion of Tor node or migration placeholder IP - if ($ip == "127.0.0.1" || $ip == "127.0.0.2") {error("Don't nuke ".$ip);} + if (in_array($ip, $config['deletebyip_excluded_ips'])) { + error("The following IP is protected by the deletebyip_excluded_ips configuration ".$ip); + } + + $threadFilter = $config['deletebyip_exclude_threads'] ? "" : "AND `thread` IS NOT NULL"; $boards = $global ? listBoards() : array(array('uri' => $boardName)); $query = ''; foreach ($boards as $_board) { - $query .= sprintf("SELECT `thread`, `id`, '%s' AS `board` FROM ``posts_%s`` WHERE `ip` = :ip UNION ALL ", $_board['uri'], $_board['uri']); + $query .= sprintf( + "SELECT `thread`, `id`, '%s' AS `board` FROM ``posts_%s`` WHERE `ip` = :ip %s UNION ALL ", + $_board['uri'], + $_board['uri'], + $threadFilter + ); } $query = preg_replace('/UNION ALL $/', '', $query);