summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/config.php3
-rw-r--r--inc/functions.php18
-rw-r--r--inc/mod/ban.php2
-rw-r--r--install.php4
-rw-r--r--install.sql1
-rw-r--r--templates/banned.html16
6 files changed, 35 insertions, 9 deletions
diff --git a/inc/config.php b/inc/config.php
index ed4a31f1..b7f6d220 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -366,6 +366,9 @@
// When true, a blank password will be used for files (not usable for deletion).
$config['field_disable_password'] = false;
+ // Require users to see the ban page at least once for a ban even if it has since expired?
+ $config['require_ban_view'] = false;
+
/*
* ====================
* Markup settings
diff --git a/inc/functions.php b/inc/functions.php
index 4b0e56d8..8d6e0a2d 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -579,6 +579,12 @@ function ago($timestamp) {
function displayBan($ban) {
global $config;
+ if (!$ban['seen']) {
+ $query = prepare("UPDATE `bans` SET `seen` = 1 WHERE `id` = :id");
+ $query->bindValue(':id', $ban['id'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+ }
+
$ban['ip'] = $_SERVER['REMOTE_ADDR'];
// Show banned page and exit
@@ -605,12 +611,12 @@ function checkBan($board = 0) {
if (event('check-ban', $board))
return true;
- $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1");
+ $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board);
$query->execute() or error(db_error($query));
if ($query->rowCount() < 1 && $config['ban_range']) {
- $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND :ip LIKE REPLACE(REPLACE(`ip`, '%', '!%'), '*', '%') ESCAPE '!' ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
+ $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND :ip LIKE REPLACE(REPLACE(`ip`, '%', '!%'), '*', '%') ESCAPE '!' ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board);
$query->execute() or error(db_error($query));
@@ -618,7 +624,7 @@ function checkBan($board = 0) {
if ($query->rowCount() < 1 && $config['ban_cidr'] && !isIPv6()) {
// my most insane SQL query yet
- $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board)
+ $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board)
AND (
`ip` REGEXP '^(\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+\)\/(\[0-9]+)$'
AND
@@ -635,10 +641,14 @@ function checkBan($board = 0) {
if ($ban = $query->fetch()) {
if ($ban['expires'] && $ban['expires'] < time()) {
// Ban expired
- $query = prepare("DELETE FROM `bans` WHERE `id` = :id LIMIT 1");
+ $query = prepare("DELETE FROM `bans` WHERE `id` = :id");
$query->bindValue(':id', $ban['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
+ if ($config['require_ban_view'] && !$ban['seen']) {
+ displayBan($ban);
+ }
+
return;
}
diff --git a/inc/mod/ban.php b/inc/mod/ban.php
index 30234157..cfc2636f 100644
--- a/inc/mod/ban.php
+++ b/inc/mod/ban.php
@@ -56,7 +56,7 @@ function parse_time($str) {
function ban($mask, $reason, $length, $board) {
global $mod, $pdo;
- $query = prepare("INSERT INTO `bans` VALUES (NULL, :ip, :mod, :time, :expires, :reason, :board)");
+ $query = prepare("INSERT INTO `bans` VALUES (NULL, :ip, :mod, :time, :expires, :reason, :board, 0)");
$query->bindValue(':ip', $mask);
$query->bindValue(':mod', $mod['id']);
$query->bindValue(':time', time());
diff --git a/install.php b/install.php
index 1447c723..71d1c910 100644
--- a/install.php
+++ b/install.php
@@ -1,7 +1,7 @@
<?php
// Installation/upgrade file
-define('VERSION', 'v0.9.6-dev-7');
+define('VERSION', 'v0.9.6-dev-8');
require 'inc/functions.php';
@@ -227,6 +227,8 @@ if (file_exists($config['has_installed'])) {
query(sprintf("CREATE INDEX `thread_id` ON `posts_%s` (`thread`, `id`)", $_board['uri'])) or error(db_error());
query(sprintf("ALTER TABLE `posts_%s` DROP INDEX `thread`", $_board['uri'])) or error(db_error());
}
+ case 'v0.9.6-dev-7':
+ query("ALTER TABLE `bans` ADD `seen` BOOLEAN NOT NULL") or error(db_error());
case false:
// Update version number
file_write($config['has_installed'], VERSION);
diff --git a/install.sql b/install.sql
index 811811e2..04896681 100644
--- a/install.sql
+++ b/install.sql
@@ -51,6 +51,7 @@ CREATE TABLE IF NOT EXISTS `bans` (
`expires` int(11) DEFAULT NULL,
`reason` text,
`board` varchar(120) DEFAULT NULL,
+ `seen` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
diff --git a/templates/banned.html b/templates/banned.html
index e912c1a9..e7b626f6 100644
--- a/templates/banned.html
+++ b/templates/banned.html
@@ -1,9 +1,17 @@
{% filter remove_whitespace %}
{# Automatically removes unnecessary whitespace #}
<div class="ban">
- <h2>{% trans %}You are banned! ;_;{% endtrans %}</h2>
+ {% if ban.expires and time() >= ban.expires %}
+ <h2>{% trans %}You were banned! ;_;{% endtrans %}</h2>
+ {% else %}
+ <h2>{% trans %}You are banned! ;_;{% endtrans %}</h2>
+ {% endif %}
<p>
- {% trans %}You have been banned from{% endtrans %}
+ {% if ban.expires and time() >= ban.expires %}
+ {% trans %}You were banned from{% endtrans %}
+ {% else %}
+ {% trans %}You have been banned from{% endtrans %}
+ {% endif %}
{% if ban.board %}
<strong>{{ config.board_abbreviation|sprintf(ban.board) }}</strong>
{% else %}
@@ -23,7 +31,9 @@
<p>
{% trans %}Your ban was filed on{% endtrans %}
<strong>{{ ban.set|date(config.ban_date) }}</strong> {% trans %}and{% endtrans %} <span id="expires">
- {% if ban.expires %}
+ {% if ban.expires and time() >= ban.expires %}
+ {% trans %} has since expired. Refresh the page to continue.{% endtrans %}
+ {% elseif ban.expires %}
{% trans %}expires{% endtrans %} <span id="countdown">{{ ban.expires|until }}</span> {% trans %}from now, which is on{% endtrans %}
<strong>
{{ ban.expires|date(config.ban_date) }}