mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-02-17 11:28:41 +01:00
feat: edit pre-existing bans
This commit is contained in:
parent
fe3e4997b6
commit
d34f083a6b
16
inc/bans.php
16
inc/bans.php
@ -113,20 +113,25 @@ class Bans {
|
|||||||
return array($ipstart, $ipend);
|
return array($ipstart, $ipend);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function find($ip, $board = false, $get_mod_info = false) {
|
static public function find($ip, $board = false, $get_mod_info = false, $banid = false) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
if (!$banid)
|
||||||
|
$search = '(`ipstart` = :ip OR (:ip >= `ipstart` AND :ip <= `ipend`)))';
|
||||||
|
else
|
||||||
|
$search = '(``bans``.`id` = :ip))';
|
||||||
|
|
||||||
$query = prepare('SELECT ``bans``.*' . ($get_mod_info ? ', `username`' : '') . ' FROM ``bans``
|
$query = prepare('SELECT ``bans``.*' . ($get_mod_info ? ', `username`' : '') . ' FROM ``bans``
|
||||||
' . ($get_mod_info ? 'LEFT JOIN ``mods`` ON ``mods``.`id` = `creator`' : '') . '
|
' . ($get_mod_info ? 'LEFT JOIN ``mods`` ON ``mods``.`id` = `creator`' : '') . '
|
||||||
WHERE
|
WHERE
|
||||||
(' . ($board !== false ? '(`board` IS NULL OR `board` = :board) AND' : '') . '
|
(' . ($board !== false ? '(`board` IS NULL OR `board` = :board) AND' : '') . '
|
||||||
(`ipstart` = :ip OR (:ip >= `ipstart` AND :ip <= `ipend`)))
|
' . $search . '
|
||||||
ORDER BY `expires` IS NULL, `expires` DESC');
|
ORDER BY `expires` IS NULL, `expires` DESC');
|
||||||
|
|
||||||
if ($board !== false)
|
if ($board !== false)
|
||||||
$query->bindValue(':board', $board, PDO::PARAM_STR);
|
$query->bindValue(':board', $board, PDO::PARAM_STR);
|
||||||
|
|
||||||
$query->bindValue(':ip', inet_pton($ip));
|
$query->bindValue(':ip', (!$banid) ? inet_pton($ip) : $ip);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$ban_list = array();
|
$ban_list = array();
|
||||||
@ -289,6 +294,9 @@ class Bans {
|
|||||||
$query->bindValue(':board', null, PDO::PARAM_NULL);
|
$query->bindValue(':board', null, PDO::PARAM_NULL);
|
||||||
|
|
||||||
if ($post) {
|
if ($post) {
|
||||||
|
if (!isset($board['uri']))
|
||||||
|
openBoard($post['board']);
|
||||||
|
|
||||||
$post['board'] = $board['uri'];
|
$post['board'] = $board['uri'];
|
||||||
$query->bindValue(':post', json_encode($post));
|
$query->bindValue(':post', json_encode($post));
|
||||||
} else
|
} else
|
||||||
|
@ -1566,6 +1566,8 @@
|
|||||||
$config['mod']['unban'] = MOD;
|
$config['mod']['unban'] = MOD;
|
||||||
// Spoiler image
|
// Spoiler image
|
||||||
$config['mod']['spoilerimage'] = JANITOR;
|
$config['mod']['spoilerimage'] = JANITOR;
|
||||||
|
// Edit bans
|
||||||
|
$config['mod']['edit_ban'] = JANITOR;
|
||||||
// Delete file (and keep post)
|
// Delete file (and keep post)
|
||||||
$config['mod']['deletefile'] = JANITOR;
|
$config['mod']['deletefile'] = JANITOR;
|
||||||
// Delete all posts by IP
|
// Delete all posts by IP
|
||||||
|
@ -842,6 +842,14 @@ function mod_page_ip($cip) {
|
|||||||
header('Location: ?/IP/' . $cip . '#bans', true, $config['redirect_http']);
|
header('Location: ?/IP/' . $cip . '#bans', true, $config['redirect_http']);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['ban_id'], $_POST['edit_ban'])) {
|
||||||
|
if (!hasPermission($config['mod']['edit_ban']))
|
||||||
|
error($config['error']['noaccess']);
|
||||||
|
|
||||||
|
header('Location: ?/edit_ban/' . $_POST['ban_id'], true, $config['redirect_http']);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_POST['note'])) {
|
if (isset($_POST['note'])) {
|
||||||
if (!hasPermission($config['mod']['create_notes']))
|
if (!hasPermission($config['mod']['create_notes']))
|
||||||
@ -946,6 +954,57 @@ function mod_page_ip($cip) {
|
|||||||
mod_page(sprintf('%s: %s', _('IP'), htmlspecialchars($cip)), $config['file_mod_view_ip'], $args, $args['hostname']);
|
mod_page(sprintf('%s: %s', _('IP'), htmlspecialchars($cip)), $config['file_mod_view_ip'], $args, $args['hostname']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mod_edit_ban($ban_id) {
|
||||||
|
global $mod, $config;
|
||||||
|
|
||||||
|
if (!hasPermission($config['mod']['edit_ban']))
|
||||||
|
error($config['error']['noaccess']);
|
||||||
|
|
||||||
|
$args['bans'] = Bans::find($ban_id, false, true, true);
|
||||||
|
$args['ban_id'] = $ban_id;
|
||||||
|
$args['boards'] = listBoards();
|
||||||
|
$args['current_board'] = isset($args['bans'][0]['board']) ? $args['bans'][0]['board'] : false;
|
||||||
|
|
||||||
|
if (!$args['bans'])
|
||||||
|
error($config['error']['404']);
|
||||||
|
|
||||||
|
if (isset($_POST['new_ban'])) {
|
||||||
|
|
||||||
|
$new_ban['mask'] = $args['bans'][0]['mask'];
|
||||||
|
$new_ban['post'] = isset($args['bans'][0]['post']) ? $args['bans'][0]['post'] : false;
|
||||||
|
$new_ban['board'] = $args['current_board'];
|
||||||
|
|
||||||
|
if (isset($_POST['reason']))
|
||||||
|
$new_ban['reason'] = $_POST['reason'];
|
||||||
|
else
|
||||||
|
$new_ban['reason'] = $args['bans'][0]['reason'];
|
||||||
|
|
||||||
|
if (isset($_POST['ban_length']) && !empty($_POST['ban_length']))
|
||||||
|
$new_ban['length'] = $_POST['ban_length'];
|
||||||
|
else
|
||||||
|
$new_ban['length'] = false;
|
||||||
|
|
||||||
|
if (isset($_POST['board'])) {
|
||||||
|
if ($_POST['board'] == '*')
|
||||||
|
$new_ban['board'] = false;
|
||||||
|
else
|
||||||
|
$new_ban['board'] = $_POST['board'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Bans::new_ban($new_ban['mask'], $new_ban['reason'], $new_ban['length'], $new_ban['board'], false, $new_ban['post']);
|
||||||
|
Bans::delete($ban_id);
|
||||||
|
|
||||||
|
header('Location: ?/', true, $config['redirect_http']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$args['token'] = make_secure_link_token('edit_ban/' . $ban_id);
|
||||||
|
|
||||||
|
mod_page(_('Edit ban'), 'mod/edit_ban.html', $args);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function mod_ban() {
|
function mod_ban() {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ var banlist_init = function(token, my_boards, inMod) {
|
|||||||
}
|
}
|
||||||
return pre+f.mask;
|
return pre+f.mask;
|
||||||
} },
|
} },
|
||||||
reason: {name: _("Reason"), width: "calc(100% - 715px - 6 * 4px)", fmt: function(f) {
|
reason: {name: _("Reason"), width: "calc(100% - 770px - 6 * 4px)", fmt: function(f) {
|
||||||
var add = "", suf = '';
|
var add = "", suf = '';
|
||||||
if (f.seen == 1) add += "<i class='fa fa-check' title='"+_("Seen")+"'></i>";
|
if (f.seen == 1) add += "<i class='fa fa-check' title='"+_("Seen")+"'></i>";
|
||||||
if (f.message) {
|
if (f.message) {
|
||||||
@ -73,7 +73,12 @@ var banlist_init = function(token, my_boards, inMod) {
|
|||||||
un = "<em>"+_("system")+"</em>";
|
un = "<em>"+_("system")+"</em>";
|
||||||
}
|
}
|
||||||
return pre + un + suf;
|
return pre + un + suf;
|
||||||
} }
|
} },
|
||||||
|
id: {
|
||||||
|
name: (inMod)?"Edit":" ", width: (inMod)?"35px":"0px", fmt: function(f) {
|
||||||
|
if (!inMod) return '';
|
||||||
|
return "<a href=?/edit_ban/"+f.id+">Edit</a>";
|
||||||
|
} }
|
||||||
}, {}, t);
|
}, {}, t);
|
||||||
|
|
||||||
$("#select-all").click(function(e) {
|
$("#select-all").click(function(e) {
|
||||||
|
1
mod.php
1
mod.php
@ -64,6 +64,7 @@ $pages = array(
|
|||||||
'/ban' => 'secure_POST ban', // new ban
|
'/ban' => 'secure_POST ban', // new ban
|
||||||
'/bans' => 'secure_POST bans', // ban list
|
'/bans' => 'secure_POST bans', // ban list
|
||||||
'/bans.json' => 'secure bans_json', // ban list JSON
|
'/bans.json' => 'secure bans_json', // ban list JSON
|
||||||
|
'/edit_ban/(\d+)' => 'secure_POST edit_ban',
|
||||||
'/ban-appeals' => 'secure_POST ban_appeals', // view ban appeals
|
'/ban-appeals' => 'secure_POST ban_appeals', // view ban appeals
|
||||||
|
|
||||||
'/recent/(\d+)' => 'recent_posts', // view recent posts
|
'/recent/(\d+)' => 'recent_posts', // view recent posts
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
{% if post and board %}
|
{% if post and board %}
|
||||||
{% set action = '?/' ~ board ~ '/ban/' ~ post %}
|
{% set action = '?/' ~ board ~ '/ban/' ~ post %}
|
||||||
|
{% elseif edit_ban %}
|
||||||
|
{% set action = '' %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set action = '?/ban' %}
|
{% set action = '?/ban' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -14,7 +16,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
|
{% if not edit_ban %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
<label for="ip">{% trans 'IP' %} <span class="unimportant">{% trans '(or subnet)' %}</span></label>
|
<label for="ip">{% trans 'IP' %} <span class="unimportant">{% trans '(or subnet)' %}</span></label>
|
||||||
@ -27,6 +29,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
<label for="reason">{% trans 'Reason' %}</label>
|
<label for="reason">{% trans 'Reason' %}</label>
|
||||||
@ -66,7 +69,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<ul style="list-style:none;padding:2px 5px">
|
<ul style="list-style:none;padding:2px 5px">
|
||||||
<li>
|
<li>
|
||||||
<input type="radio" name="board" value="*" id="ban-allboards" checked>
|
<input type="radio" name="board" value="*" id="ban-allboards" {% if edit_ban and not current_board %}checked{% elseif not edit_ban %}checked{% endif %}>
|
||||||
<label style="display:inline" for="ban-allboards">
|
<label style="display:inline" for="ban-allboards">
|
||||||
<em>{% trans 'all boards' %}</em>
|
<em>{% trans 'all boards' %}</em>
|
||||||
</label>
|
</label>
|
||||||
@ -74,7 +77,7 @@
|
|||||||
|
|
||||||
{% for board in boards %}
|
{% for board in boards %}
|
||||||
<li>
|
<li>
|
||||||
<input type="radio" name="board" value="{{ board.uri }}" id="ban-board-{{ board.uri }}">
|
<input type="radio" name="board" value="{{ board.uri }}" id="ban-board-{{ board.uri }}" {% if edit_ban and current_board == board.uri %}checked{% endif %}>
|
||||||
<label style="display:inline" for="ban-board-{{ board.uri }}">
|
<label style="display:inline" for="ban-board-{{ board.uri }}">
|
||||||
{{ config.board_abbreviation|sprintf(board.uri) }} - {{ board.title|e }}
|
{{ config.board_abbreviation|sprintf(board.uri) }} - {{ board.title|e }}
|
||||||
</label>
|
</label>
|
||||||
@ -85,7 +88,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td><input name="new_ban" type="submit" value="{% trans 'New Ban' %}"></td>
|
<td><input name="new_ban" type="submit" value="{% if edit_ban %}{% trans 'Edit Ban' %}{% else %}{% trans 'New Ban' %}{% endif %}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
|
70
templates/mod/ban_history.html
Normal file
70
templates/mod/ban_history.html
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<table style="width:400px;margin-bottom:10px;border-bottom:1px solid #ddd;padding:5px">
|
||||||
|
<tr>
|
||||||
|
<th>{% trans 'Status' %}</th>
|
||||||
|
<td>
|
||||||
|
{% if config.mod.view_banexpired and ban.expires != 0 and ban.expires < time() %}
|
||||||
|
{% trans 'Expired' %}
|
||||||
|
{% else %}
|
||||||
|
{% trans 'Active' %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans 'IP' %}</th>
|
||||||
|
<td>{{ ban.cmask }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans 'Reason' %}</th>
|
||||||
|
<td>
|
||||||
|
{% if ban.reason %}
|
||||||
|
{{ ban.reason }}
|
||||||
|
{% else %}
|
||||||
|
<em>{% trans 'no reason' %}</em>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans 'Board' %}</th>
|
||||||
|
<td>
|
||||||
|
{% if ban.board %}
|
||||||
|
{{ config.board_abbreviation|sprintf(ban.board) }}
|
||||||
|
{% else %}
|
||||||
|
<em>{% trans 'all boards' %}</em>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans 'Set' %}</th>
|
||||||
|
<td>{{ ban.created|date(config.post_date) }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans 'Expires' %}</th>
|
||||||
|
<td>
|
||||||
|
{% if ban.expires %}
|
||||||
|
{{ ban.expires|date(config.post_date) }}
|
||||||
|
{% else %}
|
||||||
|
<em>{% trans 'never' %}</em>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans 'Seen' %}</th>
|
||||||
|
<td>
|
||||||
|
{% if ban.seen %}
|
||||||
|
{% trans 'Yes' %}
|
||||||
|
{% else %}
|
||||||
|
{% trans 'No' %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans 'Staff' %}</th>
|
||||||
|
<td>
|
||||||
|
{% if ban.username %}
|
||||||
|
{{ ban.username|e }}
|
||||||
|
{% else %}
|
||||||
|
<em>{% trans 'deleted?' %}</em>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
14
templates/mod/edit_ban.html
Normal file
14
templates/mod/edit_ban.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<p style="text-align: center">
|
||||||
|
{% trans %}The previous ban will be replaced by the edited ban and the ban duration will start from the time of the edit.<br/>
|
||||||
|
The ban public message will <strong>not</strong> be changed.{% endtrans %}
|
||||||
|
</p>
|
||||||
|
<hr>
|
||||||
|
{% for ban in bans %}
|
||||||
|
<h2 style="text-align:center">{% trans %}Current ban{% endtrans %}</h2>
|
||||||
|
<form style="text-align:center; margin-bottom: unset"> {# dummy form to trigger css rules #}
|
||||||
|
{% include 'mod/ban_history.html' %}
|
||||||
|
</form>
|
||||||
|
<hr>
|
||||||
|
<h2 style="text-align:center">{% trans %}New ban{% endtrans %}</h2>
|
||||||
|
{% include 'mod/ban_form.html' with {'edit_ban': true} %}
|
||||||
|
{% endfor %}
|
@ -167,78 +167,10 @@
|
|||||||
{% for ban in bans %}
|
{% for ban in bans %}
|
||||||
<form action="" method="post" style="text-align:center">
|
<form action="" method="post" style="text-align:center">
|
||||||
<input type="hidden" name="token" value="{{ security_token }}">
|
<input type="hidden" name="token" value="{{ security_token }}">
|
||||||
<table style="width:400px;margin-bottom:10px;border-bottom:1px solid #ddd;padding:5px">
|
{% include 'mod/ban_history.html' %}
|
||||||
<tr>
|
|
||||||
<th>{% trans 'Status' %}</th>
|
|
||||||
<td>
|
|
||||||
{% if config.mod.view_banexpired and ban.expires != 0 and ban.expires < time() %}
|
|
||||||
{% trans 'Expired' %}
|
|
||||||
{% else %}
|
|
||||||
{% trans 'Active' %}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>{% trans 'IP' %}</th>
|
|
||||||
<td>{{ ban.cmask }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>{% trans 'Reason' %}</th>
|
|
||||||
<td>
|
|
||||||
{% if ban.reason %}
|
|
||||||
{{ ban.reason }}
|
|
||||||
{% else %}
|
|
||||||
<em>{% trans 'no reason' %}</em>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>{% trans 'Board' %}</th>
|
|
||||||
<td>
|
|
||||||
{% if ban.board %}
|
|
||||||
{{ config.board_abbreviation|sprintf(ban.board) }}
|
|
||||||
{% else %}
|
|
||||||
<em>{% trans 'all boards' %}</em>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>{% trans 'Set' %}</th>
|
|
||||||
<td>{{ ban.created|date(config.post_date) }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>{% trans 'Expires' %}</th>
|
|
||||||
<td>
|
|
||||||
{% if ban.expires %}
|
|
||||||
{{ ban.expires|date(config.post_date) }}
|
|
||||||
{% else %}
|
|
||||||
<em>{% trans 'never' %}</em>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>{% trans 'Seen' %}</th>
|
|
||||||
<td>
|
|
||||||
{% if ban.seen %}
|
|
||||||
{% trans 'Yes' %}
|
|
||||||
{% else %}
|
|
||||||
{% trans 'No' %}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>{% trans 'Staff' %}</th>
|
|
||||||
<td>
|
|
||||||
{% if ban.username %}
|
|
||||||
{{ ban.username|e }}
|
|
||||||
{% else %}
|
|
||||||
<em>{% trans 'deleted?' %}</em>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<input type="hidden" name="ban_id" value="{{ ban.id }}">
|
<input type="hidden" name="ban_id" value="{{ ban.id }}">
|
||||||
<input type="submit" name="unban" value="{% trans 'Remove ban' %}">
|
<input type="submit" name="unban" value="{% trans 'Remove ban' %}">
|
||||||
|
<input type="submit" name="edit_ban" value="{% trans 'Edit ban' %}">
|
||||||
</form>
|
</form>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user