Browse Source

Mod log in ?/IP (ie. ban history)

pull/40/head
Michael Save 11 years ago
parent
commit
64ae123739
  1. 3
      inc/config.php
  2. 15
      inc/mod/ban.php
  3. 9
      inc/mod/pages.php
  4. 40
      templates/mod/view_ip.html

3
inc/config.php

@ -986,6 +986,9 @@
$config['mod']['createusers'] = ADMIN; $config['mod']['createusers'] = ADMIN;
// View the moderation log // View the moderation log
$config['mod']['modlog'] = ADMIN; $config['mod']['modlog'] = ADMIN;
// View relevant moderation log entries on IP address pages (ie. ban history, etc.)
// Warning: Can be pretty resource exhaustive if your mod logs are huge.
$config['mod']['modlog_ip'] = MOD;
// Create a PM (viewing mod usernames) // Create a PM (viewing mod usernames)
$config['mod']['create_pm'] = JANITOR; $config['mod']['create_pm'] = JANITOR;
// Read any PM, sent to or from anybody // Read any PM, sent to or from anybody

15
inc/mod/ban.php

@ -80,16 +80,25 @@ function ban($mask, $reason, $length, $board) {
modLog('Created a new ' . modLog('Created a new ' .
($length > 0 ? preg_replace('/^(\d+) (\w+?)s?$/', '$1-$2', until($length)) : 'permanent') . ($length > 0 ? preg_replace('/^(\d+) (\w+?)s?$/', '$1-$2', until($length)) : 'permanent') .
' ban (<small>#' . $pdo->lastInsertId() . '</small>) for ' . ' ban on ' .
($board ? '/' . $board . '/' : 'all boards') .
' for ' .
(filter_var($mask, FILTER_VALIDATE_IP) !== false ? "<a href=\"?/IP/$mask\">$mask</a>" : utf8tohtml($mask)) . (filter_var($mask, FILTER_VALIDATE_IP) !== false ? "<a href=\"?/IP/$mask\">$mask</a>" : utf8tohtml($mask)) .
' (<small>#' . $pdo->lastInsertId() . '</small>)' .
' with ' . ($reason ? 'reason: ' . utf8tohtml($reason) . '' : 'no reason')); ' with ' . ($reason ? 'reason: ' . utf8tohtml($reason) . '' : 'no reason'));
} }
function unban($id) { function unban($id) {
$query = prepare("SELECT `ip` FROM `bans` WHERE `id` = :id");
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
$mask = $query->fetchColumn();
$query = prepare("DELETE FROM `bans` WHERE `id` = :id"); $query = prepare("DELETE FROM `bans` WHERE `id` = :id");
$query->bindValue(':id', $id); $query->bindValue(':id', $id);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
modLog("Removed ban #{$id}"); if ($mask)
modLog("Removed ban #{$id} for " . (filter_var($mask, FILTER_VALIDATE_IP) !== false ? "<a href=\"?/IP/$mask\">$mask</a>" : utf8tohtml($mask)));
} }

9
inc/mod/pages.php

@ -600,6 +600,15 @@ function mod_page_ip($ip) {
$args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC); $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
} }
if (hasPermission($config['mod']['modlog_ip'])) {
$query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 20");
$query->bindValue(':search', '%' . $ip . '%');
$query->execute() or error(db_error($query));
$args['logs'] = $query->fetchAll(PDO::FETCH_ASSOC);
} else {
$args['logs'] = array();
}
mod_page(sprintf('%s: %s', _('IP'), $ip), 'mod/view_ip.html', $args, $args['hostname']); mod_page(sprintf('%s: %s', _('IP'), $ip), 'mod/view_ip.html', $args, $args['hostname']);
} }

40
templates/mod/view_ip.html

@ -161,3 +161,43 @@
{% include 'mod/ban_form.html' %} {% include 'mod/ban_form.html' %}
</fieldset> </fieldset>
{% endif %} {% endif %}
{% if logs|count > 0 %}
<fieldset id="history">
<legend>History</legend>
<table class="modlog" style="width:100%">
<tr>
<th>{% trans 'Staff' %}</th>
<th>{% trans 'Time' %}</th>
<th>{% trans 'Board' %}</th>
<th>{% trans 'Action' %}</th>
</tr>
{% for log in logs %}
<tr>
<td class="minimal">
{% if log.username %}
<a href="?/log:{{ log.username|e }}">{{ log.username|e }}</a>
{% elseif log.mod == -1 %}
<em>system</em>
{% else %}
<em>{% trans 'deleted?' %}</em>
{% endif %}
</td>
<td class="minimal">
<span title="{{ log.time|date(config.post_date) }}">{{ log.time|ago }}</span>
</td>
<td class="minimal">
{% if log.board %}
<a href="?/{{ config.board_path|sprintf(log.board) }}{{ config.file_index }}">{{ config.board_abbreviation|sprintf(log.board) }}</a>
{% else %}
-
{% endif %}
</td>
<td>
{{ log.text }}
</td>
</tr>
{% endfor %}
</table>
</fieldset>
{% endif %}

Loading…
Cancel
Save