From c5678daa06d4a90a4686702160f8113461af5443 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 21 Apr 2012 15:42:33 +1000 Subject: [PATCH] ?/deletebyip --- inc/mod/pages.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ mod.php | 1 + 2 files changed, 63 insertions(+) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 5bba5145..260ad94c 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -534,6 +534,68 @@ function mod_deletefile($board, $post) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } +function mod_deletebyip($boardName, $post, $global = false) { + global $config, $mod, $board; + + $global = (bool)$global; + + if (!openBoard($boardName)) + error($config['error']['noboard']); + + if (!$global && !hasPermission($config['mod']['deletebyip'], $boardName)) + error($config['error']['noaccess']); + + if ($global && !hasPermission($config['mod']['deletebyip_global'], $boardName)) + error($config['error']['noaccess']); + + // Find IP address + $query = prepare(sprintf('SELECT `ip` FROM `posts_%s` WHERE `id` = :id', $boardName)); + $query->bindValue(':id', $post); + $query->execute() or error(db_error($query)); + if (!$ip = $query->fetchColumn(0)) + error($config['error']['invalidpost']); + + $boards = $global ? listBoards() : array(array('uri' => $boardName)); + + $query = ''; + foreach ($boards as $_board) { + $query .= sprintf("SELECT `id`, '%s' AS `board` FROM `posts_%s` WHERE `ip` = :ip UNION ALL ", $_board['uri'], $_board['uri']); + } + $query = preg_replace('/UNION ALL $/', '', $query); + + $query = prepare($query); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error($query)); + + if ($query->rowCount() < 1) + error($config['error']['invalidpost']); + + $boards = array(); + while ($post = $query->fetch()) { + openBoard($post['board']); + $boards[] = $post['board']; + + deletePost($post['id'], false); + } + + $boards = array_unique($boards); + + foreach ($boards as $_board) { + openBoard($_board); + buildIndex(); + } + + if ($global) { + $board = false; + } + + // Record the action + modLog("Deleted all posts by IP address: $ip"); + + // Redirect + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); +} + function mod_user($uid) { global $config, $mod; diff --git a/mod.php b/mod.php index f3726c24..7ebb0da7 100644 --- a/mod.php +++ b/mod.php @@ -48,6 +48,7 @@ $pages = array( '!^/(\w+)/delete/(\d+)$!' => 'delete', // delete post '!^/(\w+)/ban(&delete)?/(\d+)$!' => 'ban_post', // ban poster '!^/(\w+)/deletefile/(\d+)$!' => 'deletefile', // delete file from post + '!^/(\w+)/deletebyip/(\d+)(/global)?$!' => 'deletebyip', // delete all posts by IP address '!^/(\w+)/(un)?lock/(\d+)$!' => 'lock', // lock thread '!^/(\w+)/(un)?sticky/(\d+)$!' => 'sticky', // sticky thread '!^/(\w+)/bump(un)?lock/(\d+)$!' => 'bumplock', // "bumplock" thread