Update ui

This commit is contained in:
2026-04-01 21:52:29 +11:00
parent 3e6d348554
commit bf11b675e8
4 changed files with 48 additions and 10 deletions
@@ -0,0 +1,18 @@
# Generated by Django 5.2.12 on 2026-04-01 10:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('nginxmon', '0005_banned_ip_model'),
]
operations = [
migrations.AddField(
model_name='bannedip',
name='unbanned_at',
field=models.DateTimeField(blank=True, null=True),
),
]
+5
View File
@@ -209,11 +209,16 @@ class BannedIP(models.Model):
reason = models.TextField()
request_count = models.IntegerField(default=0)
banned_at = models.DateTimeField(auto_now_add=True)
unbanned_at = models.DateTimeField(null=True, blank=True)
country = models.CharField(max_length=100, blank=True)
city = models.CharField(max_length=100, blank=True)
class Meta:
ordering = ['-banned_at']
@property
def is_unbanned(self):
return self.unbanned_at is not None
def __str__(self):
return f'{self.ip} [{self.get_ban_source_display()}] @ {self.banned_at:%Y-%m-%d %H:%M}'
+20 -7
View File
@@ -286,11 +286,12 @@
</thead>
<tbody class="divide-y divide-gray-50">
{% for ban in banned_ips %}
<tr class="hover:bg-gray-50">
<td class="px-4 py-2 font-mono font-medium text-red-700">
<button class="hover:underline" onclick="setFilter('ip','{{ ban.ip }}')">{{ ban.ip }}</button>
<tr class="{% if ban.is_unbanned %}bg-green-50 hover:bg-green-100{% else %}hover:bg-gray-50{% endif %}">
<td class="px-4 py-2 font-mono font-medium">
<button class="hover:underline {% if ban.is_unbanned %}text-green-700 line-through{% else %}text-red-700{% endif %}"
onclick="setFilter('ip','{{ ban.ip }}')">{{ ban.ip }}</button>
</td>
<td class="px-4 py-2 text-gray-500 hidden sm:table-cell">
<td class="px-4 py-2 hidden sm:table-cell {% if ban.is_unbanned %}text-green-600{% else %}text-gray-500{% endif %}">
{% if ban.city or ban.country %}{{ ban.city }}{% if ban.city and ban.country %}, {% endif %}{{ ban.country }}{% else %}—{% endif %}
</td>
<td class="px-4 py-2">
@@ -302,16 +303,28 @@
{{ ban.get_ban_source_display }}
</span>
</td>
<td class="px-4 py-2 text-gray-600 max-w-sm truncate" title="{{ ban.reason }}">{{ ban.reason }}</td>
<td class="px-4 py-2 text-right font-mono text-gray-500">{{ ban.request_count }}</td>
<td class="px-4 py-2 text-gray-400 hidden md:table-cell whitespace-nowrap">{{ ban.banned_at|date:"m/d H:i" }}</td>
<td class="px-4 py-2 max-w-sm truncate {% if ban.is_unbanned %}text-green-600{% else %}text-gray-600{% endif %}"
title="{{ ban.reason }}"><span class="{% if ban.is_unbanned %}line-through{% endif %}">{{ ban.reason }}</span></td>
<td class="px-4 py-2 text-right font-mono {% if ban.is_unbanned %}text-green-500{% else %}text-gray-500{% endif %}">{{ ban.request_count }}</td>
<td class="px-4 py-2 hidden md:table-cell {% if ban.is_unbanned %}text-green-600{% else %}text-gray-400 whitespace-nowrap{% endif %}">
<span class="{% if ban.is_unbanned %}line-through text-gray-400{% endif %}">{{ ban.banned_at|date:"m/d H:i" }}</span>
{% if ban.is_unbanned %}
<br><span class="text-green-700 font-medium">&#10003; unbanned {{ ban.unbanned_at|date:"m/d H:i" }}</span>
{% endif %}
</td>
<td class="px-4 py-2 text-right">
{% if ban.is_unbanned %}
<span class="inline-flex items-center gap-1 px-2 py-0.5 rounded bg-green-100 text-green-700 text-xs font-semibold">
<i class="fas fa-check"></i> Unbanned
</span>
{% else %}
<form method="post" action="{% url 'nginxmon-unban' ban.pk %}" class="inline"
onsubmit="return confirm('Unban {{ ban.ip }}?')">
{% csrf_token %}
<button type="submit"
class="text-xs text-gray-400 hover:text-red-600 hover:underline">Unban</button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}
+5 -3
View File
@@ -305,7 +305,8 @@ class DismissAlertView(View):
class UnbanIPView(View):
"""Remove an IP from both the BannedIP table and the ConfigMap block list."""
"""Mark an IP as manually unbanned — removes it from the ConfigMap block list
but keeps the BannedIP record so auto-ban never re-bans it."""
def post(self, request, pk):
ban = get_object_or_404(BannedIP, pk=pk)
@@ -318,8 +319,9 @@ class UnbanIPView(View):
_write_blocked_ips(blocked)
except Exception as exc:
logger.warning('nginxmon unban: could not update ConfigMap for %s: %s', ip, exc)
ban.delete()
# Remove notes from log rows for this IP
ban.unbanned_at = timezone.now()
ban.save(update_fields=['unbanned_at'])
# Clear ban notes from log rows
NginxAccessLog.objects.filter(remote_addr=ip).update(note='')
messages.success(request, f'{ip} has been unbanned.')
return redirect('nginxmon-dashboard')