diff --git a/inc/bans.php b/inc/bans.php index 84d30cbf..8f2d3de7 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -113,20 +113,22 @@ class Bans { 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 = null) { global $config; - + $query = prepare('SELECT ``bans``.*' . ($get_mod_info ? ', `username`' : '') . ' FROM ``bans`` ' . ($get_mod_info ? 'LEFT JOIN ``mods`` ON ``mods``.`id` = `creator`' : '') . ' WHERE (' . ($board !== false ? '(`board` IS NULL OR `board` = :board) AND' : '') . ' - (`ipstart` = :ip OR (:ip >= `ipstart` AND :ip <= `ipend`))) + (`ipstart` = :ip OR (:ip >= `ipstart` AND :ip <= `ipend`)) OR (``bans``.id = :id)) ORDER BY `expires` IS NULL, `expires` DESC'); if ($board !== false) $query->bindValue(':board', $board, PDO::PARAM_STR); + $query->bindValue(':id', $banid); $query->bindValue(':ip', inet_pton($ip)); + $query->execute() or error(db_error($query)); $ban_list = array(); @@ -289,6 +291,9 @@ class Bans { $query->bindValue(':board', null, PDO::PARAM_NULL); if ($post) { + if (!isset($board['uri'])) + openBoard($post['board']); + $post['board'] = $board['uri']; $query->bindValue(':post', json_encode($post)); } else diff --git a/inc/config.php b/inc/config.php index ba4ecf8b..85f5e82b 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1566,6 +1566,8 @@ $config['mod']['unban'] = MOD; // Spoiler image $config['mod']['spoilerimage'] = JANITOR; + // Edit bans + $config['mod']['edit_ban'] = &$config['mod']['ban']; // Delete file (and keep post) $config['mod']['deletefile'] = JANITOR; // Delete all posts by IP diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 7522e2a5..6f73f0ab 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -842,6 +842,14 @@ function mod_page_ip($cip) { header('Location: ?/IP/' . $cip . '#bans', true, $config['redirect_http']); 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 (!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']); } +function mod_edit_ban($ban_id) { + global $mod, $config; + + if (!hasPermission($config['mod']['edit_ban'])) + error($config['error']['noaccess']); + + $args['bans'] = Bans::find(null, false, true, $ban_id); + $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() { global $config; diff --git a/js/mod/ban-list.js b/js/mod/ban-list.js index 7e5fdac0..d50fb5d2 100644 --- a/js/mod/ban-list.js +++ b/js/mod/ban-list.js @@ -37,7 +37,7 @@ var banlist_init = function(token, my_boards, inMod) { } 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 = ''; if (f.seen == 1) add += ""; if (f.message) { @@ -73,7 +73,12 @@ var banlist_init = function(token, my_boards, inMod) { un = ""+_("system")+""; } return pre + un + suf; - } } + } }, + id: { + name: (inMod)?_("Edit"):" ", width: (inMod)?"35px":"0px", fmt: function(f) { + if (!inMod) return ''; + return "Edit"; + } } }, {}, t); $("#select-all").click(function(e) { diff --git a/mod.php b/mod.php index d95a7fc7..282fc666 100644 --- a/mod.php +++ b/mod.php @@ -64,6 +64,7 @@ $pages = array( '/ban' => 'secure_POST ban', // new ban '/bans' => 'secure_POST bans', // ban list '/bans.json' => 'secure bans_json', // ban list JSON + '/edit_ban/(\d+)' => 'secure_POST edit_ban', '/ban-appeals' => 'secure_POST ban_appeals', // view ban appeals '/recent/(\d+)' => 'recent_posts', // view recent posts diff --git a/templates/mod/ban_form.html b/templates/mod/ban_form.html index 20981819..044197f4 100644 --- a/templates/mod/ban_form.html +++ b/templates/mod/ban_form.html @@ -1,5 +1,7 @@ {% if post and board %} {% set action = '?/' ~ board ~ '/ban/' ~ post %} +{% elseif edit_ban %} + {% set action = '' %} {% else %} {% set action = '?/ban' %} {% endif %} @@ -14,7 +16,7 @@ {% endif %} - + {% if not edit_ban %} + {% endif %} - +
@@ -27,6 +29,7 @@ {% endif %}
@@ -66,7 +69,7 @@
  • - + @@ -74,7 +77,7 @@ {% for board in boards %}
  • - + @@ -85,7 +88,7 @@
diff --git a/templates/mod/ban_history.html b/templates/mod/ban_history.html new file mode 100644 index 00000000..812a3ee1 --- /dev/null +++ b/templates/mod/ban_history.html @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{% trans 'Status' %} + {% if config.mod.view_banexpired and ban.expires != 0 and ban.expires < time() %} + {% trans 'Expired' %} + {% else %} + {% trans 'Active' %} + {% endif %} +
{% trans 'IP' %}{{ ban.cmask }}
{% trans 'Reason' %} + {% if ban.reason %} + {{ ban.reason }} + {% else %} + {% trans 'no reason' %} + {% endif %} +
{% trans 'Board' %} + {% if ban.board %} + {{ config.board_abbreviation|sprintf(ban.board) }} + {% else %} + {% trans 'all boards' %} + {% endif %} +
{% trans 'Set' %}{{ ban.created|date(config.post_date) }}
{% trans 'Expires' %} + {% if ban.expires %} + {{ ban.expires|date(config.post_date) }} + {% else %} + {% trans 'never' %} + {% endif %} +
{% trans 'Seen' %} + {% if ban.seen %} + {% trans 'Yes' %} + {% else %} + {% trans 'No' %} + {% endif %} +
{% trans 'Staff' %} + {% if ban.username %} + {{ ban.username|e }} + {% else %} + {% trans 'deleted?' %} + {% endif %} +
diff --git a/templates/mod/edit_ban.html b/templates/mod/edit_ban.html new file mode 100644 index 00000000..a39c6ca7 --- /dev/null +++ b/templates/mod/edit_ban.html @@ -0,0 +1,14 @@ +

+{% trans %}The previous ban will be replaced by the edited ban and the ban duration will start from the time of the edit.
+The ban public message will not be changed.{% endtrans %} +

+
+{% for ban in bans %} +

{% trans %}Current ban{% endtrans %}

+
{# dummy form to trigger css rules #} + {% include 'mod/ban_history.html' %} +
+
+

{% trans %}New ban{% endtrans %}

+ {% include 'mod/ban_form.html' with {'edit_ban': true} %} +{% endfor %} diff --git a/templates/mod/view_ip.html b/templates/mod/view_ip.html index 891e4e21..a4ef3fcc 100644 --- a/templates/mod/view_ip.html +++ b/templates/mod/view_ip.html @@ -167,78 +167,10 @@ {% for ban in bans %}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{% trans 'Status' %} - {% if config.mod.view_banexpired and ban.expires != 0 and ban.expires < time() %} - {% trans 'Expired' %} - {% else %} - {% trans 'Active' %} - {% endif %} -
{% trans 'IP' %}{{ ban.cmask }}
{% trans 'Reason' %} - {% if ban.reason %} - {{ ban.reason }} - {% else %} - {% trans 'no reason' %} - {% endif %} -
{% trans 'Board' %} - {% if ban.board %} - {{ config.board_abbreviation|sprintf(ban.board) }} - {% else %} - {% trans 'all boards' %} - {% endif %} -
{% trans 'Set' %}{{ ban.created|date(config.post_date) }}
{% trans 'Expires' %} - {% if ban.expires %} - {{ ban.expires|date(config.post_date) }} - {% else %} - {% trans 'never' %} - {% endif %} -
{% trans 'Seen' %} - {% if ban.seen %} - {% trans 'Yes' %} - {% else %} - {% trans 'No' %} - {% endif %} -
{% trans 'Staff' %} - {% if ban.username %} - {{ ban.username|e }} - {% else %} - {% trans 'deleted?' %} - {% endif %} -
+ {% include 'mod/ban_history.html' %} +
{% endfor %}