forked from 0x2620/pandora
add manage.py command to recheck useragents
This commit is contained in:
parent
ad90b43b4b
commit
1872621d8c
4 changed files with 27 additions and 1 deletions
0
pandora/user/management/__init__.py
Normal file
0
pandora/user/management/__init__.py
Normal file
0
pandora/user/management/commands/__init__.py
Normal file
0
pandora/user/management/commands/__init__.py
Normal file
23
pandora/user/management/commands/update_useragents.py
Normal file
23
pandora/user/management/commands/update_useragents.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from optparse import make_option
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
import monkey_patch.models
|
||||||
|
from ... import models
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""
|
||||||
|
reparse all useragents. useful after updating python-ox
|
||||||
|
"""
|
||||||
|
help = 'reparse all useragents. useful after updating python-ox'
|
||||||
|
args = ''
|
||||||
|
|
||||||
|
def handle(self, **options):
|
||||||
|
ids = [s['session_key'] for s in models.SessionData.objects.all().values('session_key')]
|
||||||
|
for i in ids:
|
||||||
|
s = models.SessionData.objects.get(pk=i)
|
||||||
|
s.parse_useragent()
|
||||||
|
s.save()
|
|
@ -47,7 +47,7 @@ class SessionData(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u"%s" % self.session_key
|
return u"%s" % self.session_key
|
||||||
|
|
||||||
def parse_data(self):
|
def parse_useragent(self):
|
||||||
if self.useragent:
|
if self.useragent:
|
||||||
ua = ox.parse_useragent(self.useragent)
|
ua = ox.parse_useragent(self.useragent)
|
||||||
self.browser = ua['browser']['string'].lower()
|
self.browser = ua['browser']['string'].lower()
|
||||||
|
@ -58,6 +58,9 @@ class SessionData(models.Model):
|
||||||
self.system = None
|
self.system = None
|
||||||
if ua['robot']['name']:
|
if ua['robot']['name']:
|
||||||
self.level = -1
|
self.level = -1
|
||||||
|
|
||||||
|
def parse_data(self):
|
||||||
|
self.parse_useragent()
|
||||||
if self.ip:
|
if self.ip:
|
||||||
try:
|
try:
|
||||||
g = GeoIP()
|
g = GeoIP()
|
||||||
|
|
Loading…
Reference in a new issue