summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-04-13 09:29:08 +1000
committerMichael Save <savetheinternet@tinyboard.org>2012-04-13 09:29:08 +1000
commit78f3ea783394dba14b51b27f7f2db3974ce8b8b3 (patch)
tree82e89fa261d1710e069c787db4944a928759fdcb /inc
parentf9ca74d763e570bd8004ec432c8d9c69d6c5d9e7 (diff)
View IP adress page, ban form.
Diffstat (limited to 'inc')
-rw-r--r--inc/mod/ban.php77
-rw-r--r--inc/mod/pages.php28
2 files changed, 103 insertions, 2 deletions
diff --git a/inc/mod/ban.php b/inc/mod/ban.php
new file mode 100644
index 00000000..236b2b14
--- /dev/null
+++ b/inc/mod/ban.php
@@ -0,0 +1,77 @@
+<?php
+
+/*
+ * Copyright (c) 2010-2012 Tinyboard Development Group
+ */
+
+if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
+ // You cannot request this file directly.
+ exit;
+}
+
+function parse_time($str) {
+ if(empty($str))
+ return false;
+
+ if (($time = @strtotime($str)) !== false)
+ return $time;
+
+ if (!preg_match('/^((\d+)\s*ye?a?r?s?)?\s*+((\d+)\s*mon?t?h?s?)?\s*((\d+)\s*we?e?k?s?)?\s*((\d+)\s*da?y?s?)?((\d+)\s*ho?u?r?s?)?\s*((\d+)\s*mi?n?u?t?e?s?)?\s*+((\d+)\s*se?c?o?n?d?s?)?$/', $str, $matches))
+ return false;
+ $expire = time();
+
+ if (isset($m[2])) {
+ // Years
+ $expire += $m[2]*60*60*24*365;
+ }
+ if (isset($m[4])) {
+ // Months
+ $expire += $m[4]*60*60*24*30;
+ }
+ if (isset($m[6])) {
+ // Weeks
+ $expire += $m[6]*60*60*24*7;
+ }
+ if (isset($m[8])) {
+ // Days
+ $expire += $m[8]*60*60*24;
+ }
+ if (isset($m[10])) {
+ // Hours
+ $expire += $m[10]*60*60;
+ }
+ if (isset($m[12])) {
+ // Minutes
+ $expire += $m[12]*60;
+ }
+ if (isset($m[14])) {
+ // Seconds
+ $expire += $m[14];
+ }
+
+ return $expire;
+}
+
+function ban($mask, $reason, $length, $board) {
+ global $mod;
+
+ $query = prepare("INSERT INTO `bans` VALUES (NULL, :ip, :mod, UNIX_TIMESTAMP(), :expires, :reason, :board)");
+ $query->bindValue(':ip', $mask);
+ $query->bindValue(':mod', $mod['id']);
+ if ($reason !== '')
+ $query->bindValue(':reason', $reason);
+ else
+ $query->bindValue(':reason', null, PDO::PARAM_NULL);
+
+ if ($length > 0)
+ $query->bindValue(':expires', time() + $length);
+ else
+ $query->bindValue(':expires', null, PDO::PARAM_NULL);
+
+ if ($board)
+ $query->bindValue(':board', $board);
+ else
+ $query->bindValue(':board', null, PDO::PARAM_NULL);
+
+ $query->execute() or error(db_error($query));
+}
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 9d154181..c00cd672 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -94,12 +94,17 @@ function mod_view_thread($boardName, $thread) {
function mod_page_ip($ip) {
global $config, $mod;
+ if(filter_var($ip, FILTER_VALIDATE_IP) === false)
+ error("Invalid IP address.");
+
$args = array();
$args['ip'] = $ip;
$args['posts'] = array();
$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);
@@ -122,11 +127,30 @@ function mod_page_ip($ip) {
}
if (!isset($args['posts'][$board['uri']]))
- $args['posts'][$board['uri']] = array();
- $args['posts'][$board['uri']][] = $po->build(true);
+ $args['posts'][$board['uri']] = array('board' => $board, 'posts' => array());
+ $args['posts'][$board['uri']]['posts'][] = $po->build(true);
}
}
+ $args['boards'] = $boards;
+
mod_page("IP: $ip", 'mod/view_ip.html', $args);
}
+function mod_page_ban() {
+ if(!isset($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board']))
+ error($config['error']['missedafield']);
+
+ $ip = $_POST['ip'];
+
+ require_once 'inc/mod/ban.php';
+
+ ban($_POST['ip'], $_POST['reason'], parse_time($_POST['length']), $_POST['board'] == '*' ? false : $_POST['board']);
+
+
+ if(isset($_POST['redirect']))
+ header('Location: ' . $_POST['redirect'], true, $config['redirect_http']);
+ else
+ header('Location: ?/', true, $config['redirect_http']);
+}
+