Add user agent in filter users display and limit filtered users to 10 in index
This commit is contained in:
parent
7ec7e0d644
commit
c0fc5a0131
|
@ -53,18 +53,17 @@ class IWLADisplayFilterUsers(IPlugin):
|
||||||
def __init__(self, iwla):
|
def __init__(self, iwla):
|
||||||
super(IWLADisplayFilterUsers, self).__init__(iwla)
|
super(IWLADisplayFilterUsers, self).__init__(iwla)
|
||||||
self.API_VERSION = 1
|
self.API_VERSION = 1
|
||||||
|
self.requires = ['IWLAPostAnalysisFilterUsers']
|
||||||
def load(self):
|
|
||||||
self.create_filtered_page = self.iwla.getConfValue('create_filtered_page', True)
|
self.create_filtered_page = self.iwla.getConfValue('create_filtered_page', True)
|
||||||
return True
|
|
||||||
|
|
||||||
def hook(self):
|
def hook(self):
|
||||||
display = self.iwla.getDisplay()
|
display = self.iwla.getDisplay()
|
||||||
hits = self.iwla.getValidVisitors()
|
hits = self.iwla.getValidVisitors()
|
||||||
stats = {}
|
stats = {}
|
||||||
self.filtered_users = []
|
self.filtered_users = []
|
||||||
|
|
||||||
for (key,value) in hits.items():
|
_hits = sorted(hits.items(), key=lambda x: x[1]['last_access'], reverse=True)
|
||||||
|
for (key,value) in _hits:
|
||||||
if value.get('filtered', False):
|
if value.get('filtered', False):
|
||||||
self.filtered_users.append(value)
|
self.filtered_users.append(value)
|
||||||
|
|
||||||
|
@ -75,30 +74,30 @@ class IWLADisplayFilterUsers(IPlugin):
|
||||||
path = self.iwla.getCurDisplayPath(filename)
|
path = self.iwla.getCurDisplayPath(filename)
|
||||||
|
|
||||||
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
|
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
|
||||||
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Filtered users'), [self.iwla._(u'Pages'), self.iwla._(u'Last Access')])
|
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Filtered users'), [self.iwla._(u'Pages'), self.iwla._(u'Last Access'), self.iwla._(u'User Agent')])
|
||||||
table.setColsCSSClass(['iwla_page', ''])
|
table.setColsCSSClass(['iwla_page', '', ''])
|
||||||
|
row = 0
|
||||||
|
unknown = self.iwla._('Unknown')
|
||||||
for filtered_user in self.filtered_users:
|
for filtered_user in self.filtered_users:
|
||||||
ip = filtered_user['remote_ip']
|
ip = filtered_user['remote_ip']
|
||||||
|
ip_title = ip
|
||||||
if 'dns_name_replaced' in hits[ip].keys():
|
if 'dns_name_replaced' in hits[ip].keys():
|
||||||
ip_title = '<b>%s [%s]</b>' % (hits[ip]['remote_addr'], ip)
|
ip_title = '%s [%s]' % (hits[ip]['remote_addr'], ip)
|
||||||
else:
|
if filtered_user.get('operating_system', 'android') not in ('android', 'ios_iphone'):
|
||||||
ip_title = '<b>%s</b>' % (ip)
|
location = filtered_user.get('geo_location', {})
|
||||||
table.appendRow([ip_title, ''])
|
if location:
|
||||||
nb_hits = 0
|
location_str = '(%s/%s)' % (location.get('city', unknown), location.get('countryname', unknown))
|
||||||
nb_pages = 0
|
ip_title = f'{ip_title}<br/>{location_str}'
|
||||||
|
table.appendRow([f'<b>{ip_title}</b>', '', ''])
|
||||||
|
table.setCellCSSClass(row, 0, '')
|
||||||
for r in hits[ip]['requests'][::-1]:
|
for r in hits[ip]['requests'][::-1]:
|
||||||
uri = r['extract_request']['extract_uri'].lower()
|
uri = r['extract_request']['extract_uri'].lower()
|
||||||
|
if not self.iwla.isPage(uri): continue
|
||||||
if not self.iwla.hasBeenViewed(r): continue
|
if not self.iwla.hasBeenViewed(r): continue
|
||||||
if not self.iwla.isPage(uri) or\
|
|
||||||
self.iwla.isMultimediaFile(uri):
|
|
||||||
nb_hits += 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
nb_pages += 1
|
|
||||||
uri = "%s%s" % (r.get('server_name', ''),
|
uri = "%s%s" % (r.get('server_name', ''),
|
||||||
r['extract_request']['extract_uri'])
|
r['extract_request']['extract_uri'])
|
||||||
table.appendRow([generateHTMLLink(uri), time.asctime(r['time_decoded'])])
|
table.appendRow([generateHTMLLink(uri), time.asctime(r['time_decoded']), r['http_user_agent']])
|
||||||
stats[ip] = (nb_pages, nb_hits)
|
|
||||||
page.appendBlock(table)
|
page.appendBlock(table)
|
||||||
|
|
||||||
display.addPage(page)
|
display.addPage(page)
|
||||||
|
@ -111,13 +110,16 @@ class IWLADisplayFilterUsers(IPlugin):
|
||||||
|
|
||||||
index = self.iwla.getDisplayIndex()
|
index = self.iwla.getDisplayIndex()
|
||||||
|
|
||||||
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Host'), self.iwla._(u'Last Access'), self.iwla._(u'Pages'), self.iwla._(u'Hits')])
|
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Host'), self.iwla._(u'Pages'), self.iwla._(u'Hits'), self.iwla._(u'Last Access')])
|
||||||
table.setColsCSSClass(['', '', 'iwla_page', 'iwla_hit'])
|
table.setColsCSSClass(['', '', 'iwla_page', 'iwla_hit'])
|
||||||
for filtered_user in self.filtered_users:
|
for filtered_user in self.filtered_users[:10]:
|
||||||
ip = filtered_user['remote_ip']
|
ip = filtered_user['remote_ip']
|
||||||
if 'dns_name_replaced' in hits[ip].keys():
|
if 'dns_name_replaced' in hits[ip].keys():
|
||||||
ip_title = '%s [%s]' % (hits[ip]['remote_addr'], ip)
|
ip_title = '%s [%s]' % (hits[ip]['remote_addr'], ip)
|
||||||
else:
|
else:
|
||||||
ip_title = ip
|
ip_title = ip
|
||||||
table.appendRow([ip_title, time.asctime(hits[ip]['last_access']), stats[ip][0], stats[ip][1]])
|
table.appendRow([ip_title, filtered_user['viewed_pages'][0], filtered_user['viewed_hits'][0], time.asctime(hits[ip]['last_access'])])
|
||||||
|
if len(self.filtered_users) > 10:
|
||||||
|
table.appendRow([self.iwla._(u'Others'), len(self.filtered_users)-10, '', ''])
|
||||||
|
table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')
|
||||||
index.appendBlock(table)
|
index.appendBlock(table)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user