mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Add the ability to view IP addresses in auth, with a basic search interface
This commit is contained in:
@@ -19,6 +19,9 @@
|
||||
{% if "hr"|installed %}
|
||||
<li><b>Blacklist Status: {% if blacklisted %}<font color='red'>BLACKLISTED</font> ({{ blacklisted }} items){% else %}<font color='geen'>OK</font>{% endif %}</b></li>
|
||||
{% endif %}
|
||||
{% if user.ip_addresses.count %}
|
||||
<li><a href="{% url sso-ipaddress %}?user={{ user.username }}">IP Address Lookup</a> ({{ user.ip_addresses.count }} associated addresses)</li>
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
||||
25
app/sso/templates/sso/ssouseripaddress_list.html
Normal file
25
app/sso/templates/sso/ssouseripaddress_list.html
Normal file
@@ -0,0 +1,25 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}IP Search: {% if kuser %}{{ kuser }}{% else %}{{ ip }}{% endif %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>IP Search: {% if kuser %}{{ kuser }}{% else %}{{ ip }}{% endif %}</h1>
|
||||
|
||||
{% if object_list %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>IP Address</th><th>User</th><th>First Use</th><th>Last Use</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for object in object_list %}
|
||||
<tr><td><a href="{% url sso-ipaddress %}?ip={{ object.ip_address }}">{{ object.ip_address }}</a></td>
|
||||
<td><a href="{% url sso-ipaddress %}?user={{ object.user.username }}">{{ object.user }}</a> (<a href="{% url sso-viewuser object.user.username %}">Profile</a>)</td>
|
||||
<td>{{ object.first_seen }}</td>
|
||||
<td>{{ object.last_seen }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
@@ -7,7 +7,7 @@ from sso import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
('^$', views.profile),
|
||||
(r'^profile/$', views.profile),
|
||||
url(r'^profile/$', views.profile, name='sso-profile'),
|
||||
(r'^profile/add/service', views.service_add),
|
||||
(r'^profile/del/service/$', views.service_del),
|
||||
(r'^profile/del/service/(?P<serviceid>\d+)/$', views.service_del),
|
||||
@@ -23,6 +23,8 @@ urlpatterns = patterns('',
|
||||
(r'^users/$', views.user_lookup),
|
||||
url(r'^users/(?P<username>.*)/addnote/$', login_required(views.AddUserNote.as_view()), name='sso-addusernote'),
|
||||
url(r'^users/(?P<username>.*)/$', views.user_view, name='sso-viewuser'),
|
||||
|
||||
url(r'^address/$', login_required(views.UserIPAddressView.as_view()), name='sso-ipaddress'),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('django.views.generic.simple',
|
||||
|
||||
@@ -13,7 +13,7 @@ from django.contrib.auth.decorators import login_required
|
||||
from django.template import RequestContext
|
||||
from django.core import serializers
|
||||
from django.conf import settings
|
||||
from django.views.generic import FormView
|
||||
from django.views.generic import FormView, ListView
|
||||
|
||||
from gargoyle import gargoyle
|
||||
from gargoyle.decorators import switch_is_active
|
||||
@@ -23,7 +23,7 @@ from eve_api.models import EVEAccount, EVEPlayerCharacter
|
||||
from eve_api.tasks import import_apikey, import_apikey_result, update_user_access
|
||||
from eve_proxy.models import ApiAccessLog
|
||||
from reddit.tasks import update_user_flair
|
||||
from sso.models import ServiceAccount, Service, SSOUser, ExistingUser, ServiceError
|
||||
from sso.models import ServiceAccount, Service, SSOUser, ExistingUser, ServiceError, SSOUserIPAddress
|
||||
from sso.forms import UserServiceAccountForm, ServiceAccountResetForm, UserLookupForm, APIPasswordForm, EmailChangeForm, PrimaryCharacterForm, UserNoteForm
|
||||
|
||||
@login_required
|
||||
@@ -366,3 +366,28 @@ class AddUserNote(FormView):
|
||||
obj.save()
|
||||
|
||||
return super(AddUserNote, self).form_valid(form)
|
||||
|
||||
|
||||
class UserIPAddressView(ListView):
|
||||
|
||||
model = SSOUserIPAddress
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.has_perm('sso.can_view_users_restricted'):
|
||||
return HttpResponseForbidden()
|
||||
return super(AddUserNote, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_queryset(self):
|
||||
if self.request.GET.has_key('user'):
|
||||
qs = self.model.objects.filter(user__username__exact=self.request.GET.get('user'))
|
||||
else:
|
||||
qs = self.model.objects.filter(ip_address__contains=self.request.GET.get('ip', ''))
|
||||
return qs.order_by('-last_seen')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super(UserIPAddressView, self).get_context_data(**kwargs)
|
||||
ctx.update({
|
||||
'ip': self.request.GET.get('ip', None),
|
||||
'kuser': self.request.GET.get('user', None),
|
||||
})
|
||||
return ctx
|
||||
|
||||
Reference in New Issue
Block a user