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):
|
||||
super(IWLADisplayFilterUsers, self).__init__(iwla)
|
||||
self.API_VERSION = 1
|
||||
|
||||
def load(self):
|
||||
self.requires = ['IWLAPostAnalysisFilterUsers']
|
||||
self.create_filtered_page = self.iwla.getConfValue('create_filtered_page', True)
|
||||
return True
|
||||
|
||||
|
||||
def hook(self):
|
||||
display = self.iwla.getDisplay()
|
||||
hits = self.iwla.getValidVisitors()
|
||||
stats = {}
|
||||
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):
|
||||
self.filtered_users.append(value)
|
||||
|
||||
|
@ -75,30 +74,30 @@ class IWLADisplayFilterUsers(IPlugin):
|
|||
path = self.iwla.getCurDisplayPath(filename)
|
||||
|
||||
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.setColsCSSClass(['iwla_page', ''])
|
||||
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', '', ''])
|
||||
row = 0
|
||||
unknown = self.iwla._('Unknown')
|
||||
for filtered_user in self.filtered_users:
|
||||
ip = filtered_user['remote_ip']
|
||||
ip_title = ip
|
||||
if 'dns_name_replaced' in hits[ip].keys():
|
||||
ip_title = '<b>%s [%s]</b>' % (hits[ip]['remote_addr'], ip)
|
||||
else:
|
||||
ip_title = '<b>%s</b>' % (ip)
|
||||
table.appendRow([ip_title, ''])
|
||||
nb_hits = 0
|
||||
nb_pages = 0
|
||||
ip_title = '%s [%s]' % (hits[ip]['remote_addr'], ip)
|
||||
if filtered_user.get('operating_system', 'android') not in ('android', 'ios_iphone'):
|
||||
location = filtered_user.get('geo_location', {})
|
||||
if location:
|
||||
location_str = '(%s/%s)' % (location.get('city', unknown), location.get('countryname', unknown))
|
||||
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]:
|
||||
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.isPage(uri) or\
|
||||
self.iwla.isMultimediaFile(uri):
|
||||
nb_hits += 1
|
||||
continue
|
||||
|
||||
nb_pages += 1
|
||||
uri = "%s%s" % (r.get('server_name', ''),
|
||||
r['extract_request']['extract_uri'])
|
||||
table.appendRow([generateHTMLLink(uri), time.asctime(r['time_decoded'])])
|
||||
stats[ip] = (nb_pages, nb_hits)
|
||||
table.appendRow([generateHTMLLink(uri), time.asctime(r['time_decoded']), r['http_user_agent']])
|
||||
page.appendBlock(table)
|
||||
|
||||
display.addPage(page)
|
||||
|
@ -111,13 +110,16 @@ class IWLADisplayFilterUsers(IPlugin):
|
|||
|
||||
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'])
|
||||
for filtered_user in self.filtered_users:
|
||||
for filtered_user in self.filtered_users[:10]:
|
||||
ip = filtered_user['remote_ip']
|
||||
if 'dns_name_replaced' in hits[ip].keys():
|
||||
ip_title = '%s [%s]' % (hits[ip]['remote_addr'], ip)
|
||||
else:
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user