From 45630f10f754e840adc15585276c48ad1fd76526 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 29 Mar 2012 22:51:58 +0100 Subject: [PATCH] Add the ability to view IP addresses in auth, with a basic search interface --- app/sso/templates/sso/lookup/user.html | 3 ++ .../templates/sso/ssouseripaddress_list.html | 25 ++++++++++++++++ app/sso/urls.py | 4 ++- app/sso/views.py | 29 +++++++++++++++++-- 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 app/sso/templates/sso/ssouseripaddress_list.html diff --git a/app/sso/templates/sso/lookup/user.html b/app/sso/templates/sso/lookup/user.html index 0f4678c..6bb66fe 100644 --- a/app/sso/templates/sso/lookup/user.html +++ b/app/sso/templates/sso/lookup/user.html @@ -19,6 +19,9 @@ {% if "hr"|installed %}
  • Blacklist Status: {% if blacklisted %}BLACKLISTED ({{ blacklisted }} items){% else %}OK{% endif %}
  • {% endif %} +{% if user.ip_addresses.count %} +
  • IP Address Lookup ({{ user.ip_addresses.count }} associated addresses)
  • +{% endif %}

    diff --git a/app/sso/templates/sso/ssouseripaddress_list.html b/app/sso/templates/sso/ssouseripaddress_list.html new file mode 100644 index 0000000..9b825a4 --- /dev/null +++ b/app/sso/templates/sso/ssouseripaddress_list.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% block title %}IP Search: {% if kuser %}{{ kuser }}{% else %}{{ ip }}{% endif %}{% endblock %} + +{% block content %} +

    IP Search: {% if kuser %}{{ kuser }}{% else %}{{ ip }}{% endif %}

    + +{% if object_list %} + + + + + +{% for object in object_list %} + + + + + +{% endfor %} + +
    IP AddressUserFirst UseLast Use
    {{ object.ip_address }}{{ object.user }} (Profile){{ object.first_seen }}{{ object.last_seen }}
    +{% endif %} + +{% endblock %} diff --git a/app/sso/urls.py b/app/sso/urls.py index ca131ef..bdacf9d 100644 --- a/app/sso/urls.py +++ b/app/sso/urls.py @@ -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\d+)/$', views.service_del), @@ -23,6 +23,8 @@ urlpatterns = patterns('', (r'^users/$', views.user_lookup), url(r'^users/(?P.*)/addnote/$', login_required(views.AddUserNote.as_view()), name='sso-addusernote'), url(r'^users/(?P.*)/$', views.user_view, name='sso-viewuser'), + + url(r'^address/$', login_required(views.UserIPAddressView.as_view()), name='sso-ipaddress'), ) urlpatterns += patterns('django.views.generic.simple', diff --git a/app/sso/views.py b/app/sso/views.py index 1c430e3..df43a43 100644 --- a/app/sso/views.py +++ b/app/sso/views.py @@ -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