From 10bd465ea366023769b047050d48b0e81d513b9b Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Tue, 5 Apr 2011 17:36:00 +1000 Subject: [PATCH] IP address notes --- inc/config.php | 6 ++++ install.sql | 20 +++++++++++++ mod.php | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- style.css | 2 +- 4 files changed, 117 insertions(+), 2 deletions(-) diff --git a/inc/config.php b/inc/config.php index 9e26094a..b3c69faa 100644 --- a/inc/config.php +++ b/inc/config.php @@ -325,6 +325,12 @@ $config['mod']['view_banexpired'] = true; // View ban for IP address $config['mod']['view_ban'] = $config['mod']['view_banlist']; + // View IP address notes + $config['mod']['view_notes'] = JANITOR; + // Create notes + $config['mod']['create_notes'] = $config['mod']['view_notes']; + // Remote notes + $config['mod']['remove_notes'] = ADMIN; // Create a new board $config['mod']['newboard'] = ADMIN; // Manage existing boards (change title, etc) diff --git a/install.sql b/install.sql index a20b1451..bd34cfb5 100644 --- a/install.sql +++ b/install.sql @@ -223,3 +223,23 @@ CREATE TABLE IF NOT EXISTS `noticeboard` ( -- -- Dumping data for table `noticeboard` -- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `ip_notes` +-- + +CREATE TABLE IF NOT EXISTS `ip_notes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `ip` varchar(45) NOT NULL, + `mod` int(11) DEFAULT NULL, + `time` int(11) NOT NULL, + `body` text NOT NULL, + UNIQUE KEY `id` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `ip_notes` +-- + diff --git a/mod.php b/mod.php index 21119bcb..c7ee054b 100644 --- a/mod.php +++ b/mod.php @@ -1516,6 +1516,18 @@ 'mod'=>true ) ); + } elseif(preg_match('/^\/IP\/(\d+\.\d+\.\d+\.\d+|' . $config['ipv6_regex'] . ')\/deletenote\/(?P\d+)$/', $query, $matches)) { + if($mod['type'] < $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 @@ -1526,8 +1538,15 @@ $query = prepare("DELETE FROM `bans` WHERE `ip` = :ip"); $query->bindValue(':ip', $ip); $query->execute() or error(db_error($query)); + } elseif($mod['type'] >= $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)); } - $body = ''; $boards = listBoards(); @@ -1557,6 +1576,76 @@ '' . $temp . ''; } + if($mod['type'] >= $config['mod']['view_notes']) { + $query = prepare("SELECT * FROM `ip_notes` WHERE `ip` = :ip ORDER BY `id` DESC"); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error($query)); + + if($query->rowCount() > 0 || $mod['type'] >= $config['mod']['create_notes'] ) { + $body .= '
' . + $query->rowCount() . ' note' . ($query->rowCount() == 1 ?'' : 's') . ' on record' . + ''; + if($query->rowCount() > 0) { + $body .= '' . + '' . + ($mod['type'] >= $config['mod']['remove_notes'] ? '' : '') . + ''; + while($note = $query->fetch()) { + + if($note['mod']) { + $_query = prepare("SELECT `username` FROM `mods` WHERE `id` = :id"); + $_query->bindValue(':id', $note['mod']); + $_query->execute() or error(db_error($_query)); + if($_mod = $_query->fetch()) { + if($mod['type'] >= $config['mod']['editusers']) + $staff = '' . htmlentities($_mod['username']) . ''; + else + $staff = $_mod['username']; + } else { + $staff = '??'; + } + } else { + $staff = 'system'; + } + $body .= '' . + '' . + ($mod['type'] >= $config['mod']['remove_notes'] ? + '' + : '') . + ''; + } + $body .= '
StaffNoteDateActions
' . + $staff . + '' . + $note['body'] . + '' . + date($config['post_date'], $note['time']) . + '[delete]
'; + } + + if($mod['type'] >= $config['mod']['create_notes']) { + $body .= '
' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '
Staff' . $mod['username'] . '
' . + '
'; + } + + $body .= '
'; + } + } + if($mod['type'] >= $config['mod']['view_ban']) { $query = prepare("SELECT * FROM `bans` INNER JOIN `mods` ON `mod` = `id` WHERE `ip` = :ip"); $query->bindValue(':ip', $ip); diff --git a/style.css b/style.css index ebb2f2c6..019563ea 100644 --- a/style.css +++ b/style.css @@ -350,7 +350,7 @@ table.modlog tr th { table.modlog tr th { background: #98E; } -td.minimal { +td.minimal, th.minimal { width: 1%; white-space: nowrap; }