function mod_page_ip($ip) { global $config, $mod; if (filter_var($ip, FILTER_VALIDATE_IP) === false) { error("Invalid IP address."); } if (isset($_POST['ban_id'], $_POST['unban'])) { if (!hasPermission($config['mod']['unban'])) { error($config['error']['noaccess']); } Bans::delete($_POST['ban_id'], true); header('Location: ?/IP/' . $ip . '#bans', true, $config['redirect_http']); return; } if (isset($_POST['note'])) { if (!hasPermission($config['mod']['create_notes'])) { error($config['error']['noaccess']); } $_POST['note'] = escape_markup_modifiers($_POST['note']); markup($_POST['note']); $query = prepare('INSERT INTO ``ip_notes`` VALUES (NULL, :ip, :mod, :time, :body)'); $query->bindValue(':ip', $ip); $query->bindValue(':mod', $mod['id']); $query->bindValue(':time', time()); $query->bindValue(':body', $_POST['note']); $query->execute() or error(db_error($query)); modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>"); header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']); return; } $args = array(); $args['ip'] = $ip; $args['posts'] = array(); if ($config['mod']['dns_lookup']) { $args['hostname'] = rDNS($ip); } $boards = listBoards(); foreach ($boards as $board) { openBoard($board['uri']); if (!hasPermission($config['mod']['show_ip'], $board['uri'])) { continue; } $query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `ip` = :ip ORDER BY `sticky` DESC, `id` DESC LIMIT :limit', $board['uri'])); $query->bindValue(':ip', $ip); $query->bindValue(':limit', $config['mod']['ip_recentposts'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { if (!$post['thread']) { $po = new Thread($post, '?/', $mod, false); } else { $po = new Post($post, '?/', $mod); } if (!isset($args['posts'][$board['uri']])) { $args['posts'][$board['uri']] = array('board' => $board, 'posts' => array()); } $args['posts'][$board['uri']]['posts'][] = $po->build(true); } } $args['boards'] = $boards; $args['token'] = make_secure_link_token('ban'); if (hasPermission($config['mod']['view_ban'])) { $args['bans'] = Bans::find($ip, false, true); } if (hasPermission($config['mod']['view_notes'])) { $query = prepare("SELECT ``ip_notes``.*, `username` FROM ``ip_notes`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `ip` = :ip ORDER BY `time` DESC"); $query->bindValue(':ip', $ip); $query->execute() or error(db_error($query)); $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC); } if (hasPermission($config['mod']['modlog_ip'])) { $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 50"); $query->bindValue(':search', '%' . $ip . '%'); $query->execute() or error(db_error($query)); $args['logs'] = $query->fetchAll(PDO::FETCH_ASSOC); } else { $args['logs'] = array(); } $args['security_token'] = make_secure_link_token('IP/' . $ip); mod_page(sprintf('%s: %s', _('IP'), $ip), 'mod/view_ip.html', $args, $args['hostname']); }
echo Element('page.html', array('config' => $config, 'title' => 'New ban', 'body' => $body, 'mod' => true)); } elseif (preg_match('/^\\/IP\\/(\\d+\\.\\d+\\.\\d+\\.\\d+|' . $config['ipv6_regex'] . ')\\/deletenote\\/(?P<id>\\d+)$/', $query, $matches)) { if (!hasPermission($config['mod']['remove_notes'])) { error($config['error']['noaccess']); } $ip = $matches[1]; $id = $matches['id']; $query = prepare("DELETE FROM `ip_notes` WHERE `ip` = :ip AND `id` = :id"); $query->bindValue(':ip', $ip); $query->bindValue(':id', $id); $query->execute() or error(db_error($query)); header('Location: ?/IP/' . $ip, true, $config['redirect_http']); } elseif (preg_match('/^\\/IP\\/(\\d+\\.\\d+\\.\\d+\\.\\d+|' . $config['ipv6_regex'] . ')$/', $query, $matches)) { // View information on an IP address $ip = $matches[1]; $host = $config['mod']['dns_lookup'] ? rDNS($ip) : false; if (hasPermission($config['mod']['unban']) && isset($_POST['unban']) && isset($_POST['ban_id'])) { removeBan($_POST['ban_id']); header('Location: ?/IP/' . $ip, true, $config['redirect_http']); } elseif (hasPermission($config['mod']['create_notes']) && isset($_POST['note'])) { $query = prepare("INSERT INTO `ip_notes` VALUES(NULL, :ip, :mod, :time, :body)"); $query->bindValue(':ip', $ip); $query->bindValue(':mod', $mod['id'], PDO::PARAM_INT); $query->bindValue(':time', time(), PDO::PARAM_INT); markup($_POST['note']); $query->bindValue(':body', $_POST['note']); $query->execute() or error(db_error($query)); header('Location: ?/IP/' . $ip, true, $config['redirect_http']); } else { $body = ''; $boards = listBoards();
function mod_page_ip($ip) { global $config, $mod; if (filter_var($ip, FILTER_VALIDATE_IP) === false) { error("Invalid IP address."); } if (isset($_POST['ban_id'], $_POST['unban'])) { if (!hasPermission($config['mod']['unban'])) { error($config['error']['noaccess']); } require_once 'inc/mod/ban.php'; unban($_POST['ban_id']); header('Location: ?/IP/' . $ip . '#bans', true, $config['redirect_http']); return; } if (isset($_POST['note'])) { if (!hasPermission($config['mod']['create_notes'])) { error($config['error']['noaccess']); } markup($_POST['note']); $query = prepare('INSERT INTO `ip_notes` VALUES (NULL, :ip, :mod, :time, :body)'); $query->bindValue(':ip', $ip); $query->bindValue(':mod', $mod['id']); $query->bindValue(':time', time()); $query->bindValue(':body', $_POST['note']); $query->execute() or error(db_error($query)); modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>"); header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']); return; } $args = array(); $args['ip'] = $ip; $args['posts'] = array(); if ($config['mod']['dns_lookup']) { $args['hostname'] = rDNS($ip); } $boards = listBoards(); foreach ($boards as $board) { openBoard($board['uri']); $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `id` DESC LIMIT :limit', $board['uri'])); $query->bindValue(':ip', $ip); $query->bindValue(':limit', $config['mod']['ip_recentposts'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { if (!$post['thread']) { // TODO: There is no reason why this should be such a f*****g mess. $po = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $post['sage'], $post['embed'], '?/', $mod, false); } else { $po = new Post($post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], '?/', $mod); } if (!isset($args['posts'][$board['uri']])) { $args['posts'][$board['uri']] = array('board' => $board, 'posts' => array()); } $args['posts'][$board['uri']]['posts'][] = $po->build(true); } } $args['boards'] = $boards; $args['token'] = make_secure_link_token('ban'); if (hasPermission($config['mod']['view_ban'])) { $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip"); $query->bindValue(':ip', $ip); $query->execute() or error(db_error($query)); $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC); } if (hasPermission($config['mod']['view_notes'])) { $query = prepare("SELECT `ip_notes`.*, `username` FROM `ip_notes` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip"); $query->bindValue(':ip', $ip); $query->execute() or error(db_error($query)); $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC); } mod_page(sprintf('%s: %s', _('IP'), $ip), 'mod/view_ip.html', $args, $args['hostname']); }