mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Added some DNS lookup for the IP viewer
This commit is contained in:
@@ -11,6 +11,9 @@ from django.contrib.contenttypes import generic
|
||||
from django.utils import simplejson as json
|
||||
|
||||
from jsonfield.fields import JSONField
|
||||
from IPy import IP
|
||||
import dns.resolver
|
||||
|
||||
from eve_api.models import EVEAccount, EVEPlayerCorporation, EVEPlayerAlliance, EVEPlayerCharacter
|
||||
|
||||
from sso.app_defines import *
|
||||
@@ -89,6 +92,19 @@ class SSOUserIPAddress(models.Model):
|
||||
ip_address = models.CharField("IP Address", max_length=200, blank=False)
|
||||
user = models.ForeignKey(User, blank=False, null=False, related_name='ip_addresses')
|
||||
|
||||
@property
|
||||
def hostname(self):
|
||||
arpa = IP(self.ip_address).reverseName()
|
||||
try:
|
||||
res = dns.resolver.query(arpa, 'PTR').response
|
||||
return res.answer[0][0].to_text()
|
||||
except:
|
||||
return arpa
|
||||
|
||||
@property
|
||||
def related_users(self):
|
||||
return SSOUserIPAddress.objects.filter(ip_address=self.ip_address).count()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.ip_address
|
||||
|
||||
|
||||
@@ -8,11 +8,12 @@
|
||||
{% if object_list %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>IP Address</th><th>User</th><th>First Use</th><th>Last Use</th></tr>
|
||||
<tr><th>IP Address</th><th>Hostname</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>
|
||||
<tr><td><a href="{% url sso-ipaddress %}?ip={{ object.ip_address }}">{{ object.ip_address }}</a> {% if object.related_users > 1 %}({{ object.related_users }} users){% endif %}</td>
|
||||
<td>{{ object.hostname }}</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>
|
||||
|
||||
@@ -17,3 +17,5 @@ nexus
|
||||
-e git+https://github.com/nikdoof/gargoyle.git@dca57fc4b437b85f8cbc#egg=gargoyle
|
||||
beautifulsoup
|
||||
django-redis-cache
|
||||
IPy==0.75
|
||||
dnspython
|
||||
|
||||
Reference in New Issue
Block a user