mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-23 23:20:57 +01:00
$config['require_ban_view']: Force users to view the "You are banned" page at least once before letting a ban disappear naturally.
This commit is contained in:
parent
29b10c88db
commit
c8f30550af
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
|
@ -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 ;
|
||||
|
@ -1,9 +1,17 @@
|
||||
{% filter remove_whitespace %}
|
||||
{# Automatically removes unnecessary whitespace #}
|
||||
<div class="ban">
|
||||
{% if ban.expires and time() >= ban.expires %}
|
||||
<h2>{% trans %}You were banned! ;_;{% endtrans %}</h2>
|
||||
{% else %}
|
||||
<h2>{% trans %}You are banned! ;_;{% endtrans %}</h2>
|
||||
{% endif %}
|
||||
<p>
|
||||
{% 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) }}
|
||||
|
Loading…
Reference in New Issue
Block a user