WIP
This commit is contained in:
parent
b1b92412e0
commit
7507b8e77f
31
display.py
31
display.py
|
@ -109,10 +109,12 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
||||||
self.rows_cssclasses = []
|
self.rows_cssclasses = []
|
||||||
self.table_css = u'iwla_table'
|
self.table_css = u'iwla_table'
|
||||||
self.human_readable_cols = human_readable_cols or []
|
self.human_readable_cols = human_readable_cols or []
|
||||||
|
self.objects = []
|
||||||
|
|
||||||
def appendRow(self, row):
|
def appendRow(self, row, _object=None):
|
||||||
self.rows.append(listToStr(row))
|
self.rows.append(listToStr(row))
|
||||||
self.rows_cssclasses.append([u''] * len(row))
|
self.rows_cssclasses.append([u''] * len(row))
|
||||||
|
self.objects.append(_object)
|
||||||
|
|
||||||
def insertCol(self, col_number, col_title='', col_css_class=''):
|
def insertCol(self, col_number, col_title='', col_css_class=''):
|
||||||
self.cols.insert(col_number, col_title)
|
self.cols.insert(col_number, col_title)
|
||||||
|
@ -142,6 +144,12 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
||||||
|
|
||||||
return self.rows[row][col]
|
return self.rows[row][col]
|
||||||
|
|
||||||
|
def getRowObject(self, row):
|
||||||
|
if row < 0 or row >= len(self.rows):
|
||||||
|
raise ValueError('Invalid indices %d' % (row))
|
||||||
|
|
||||||
|
return self.objects[row]
|
||||||
|
|
||||||
def setCellValue(self, row, col, value):
|
def setCellValue(self, row, col, value):
|
||||||
if row < 0 or col < 0 or\
|
if row < 0 or col < 0 or\
|
||||||
row >= len(self.rows) or col >= len(self.cols):
|
row >= len(self.rows) or col >= len(self.cols):
|
||||||
|
@ -208,9 +216,9 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
||||||
target_col = col
|
target_col = col
|
||||||
break
|
break
|
||||||
if target_col is None: return
|
if target_col is None: return
|
||||||
for row in self.rows:
|
for idx, row in enumerate(self.rows):
|
||||||
res = function(row[target_col], **args)
|
res = function(row[target_col], self.objects[idx], **args)
|
||||||
if res:
|
if res is not None:
|
||||||
row[target_col] = res
|
row[target_col] = res
|
||||||
|
|
||||||
def _buildHTML(self):
|
def _buildHTML(self):
|
||||||
|
@ -419,6 +427,21 @@ class DisplayHTMLBuild(object):
|
||||||
def addColumnFilter(self, column, function, args):
|
def addColumnFilter(self, column, function, args):
|
||||||
self.filters.append(({'column':column, 'args':args}, function))
|
self.filters.append(({'column':column, 'args':args}, function))
|
||||||
|
|
||||||
|
def getDisplayName(self, visitor):
|
||||||
|
display_visitor_ip = True
|
||||||
|
compact_host_name = True
|
||||||
|
address = visitor['remote_addr']
|
||||||
|
if display_visitor_ip and\
|
||||||
|
super_hit.get('dns_name_replaced', False):
|
||||||
|
host_name = address
|
||||||
|
if compact_host_name:
|
||||||
|
ip = visitor['remote_ip'].replace('.', '-')
|
||||||
|
host_name = host_name.replace(ip, 'IP')
|
||||||
|
ip = ip.replace('-', '')
|
||||||
|
host_name = host_name.replace(ip, 'IP')
|
||||||
|
address = '%s [%s]' % (host_name, visitor['remote_ip'])
|
||||||
|
return address
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Global functions
|
# Global functions
|
||||||
|
|
|
@ -72,10 +72,6 @@ class IWLADisplayAllVisits(IPlugin):
|
||||||
|
|
||||||
for super_hit in last_access:
|
for super_hit in last_access:
|
||||||
address = super_hit['remote_addr']
|
address = super_hit['remote_addr']
|
||||||
if display_visitor_ip and\
|
|
||||||
super_hit.get('dns_name_replaced', False):
|
|
||||||
address = '%s [%s]' % (address, super_hit['remote_ip'])
|
|
||||||
|
|
||||||
row = [
|
row = [
|
||||||
address,
|
address,
|
||||||
super_hit['viewed_pages'][0],
|
super_hit['viewed_pages'][0],
|
||||||
|
@ -83,7 +79,7 @@ class IWLADisplayAllVisits(IPlugin):
|
||||||
super_hit['bandwidth'][0],
|
super_hit['bandwidth'][0],
|
||||||
time.asctime(super_hit['last_access'])
|
time.asctime(super_hit['last_access'])
|
||||||
]
|
]
|
||||||
table.appendRow(row)
|
table.appendRow(row, address)
|
||||||
page.appendBlock(table)
|
page.appendBlock(table)
|
||||||
|
|
||||||
display.addPage(page)
|
display.addPage(page)
|
||||||
|
|
|
@ -71,15 +71,9 @@ class IWLADisplayAllVisitsEnlight(IPlugin):
|
||||||
return
|
return
|
||||||
|
|
||||||
for (idx, row) in enumerate(block.rows):
|
for (idx, row) in enumerate(block.rows):
|
||||||
# Direct IP
|
remote_addr = block.objects[idx]
|
||||||
ip = row[0]
|
if remote_addr is None or not remote_addr in visitors.keys(): continue
|
||||||
if not ip in visitors.keys():
|
visitor = visitors[remote_addr]
|
||||||
# name [IP]
|
if visitor.get('enlight', False) or\
|
||||||
ip = self.ip_re.match(row[0])
|
visitor.get('filtered', False):
|
||||||
if not ip: continue
|
|
||||||
ip = ip[1]
|
|
||||||
if not ip in visitors.keys():
|
|
||||||
continue
|
|
||||||
if visitors[ip].get('enlight', False) or\
|
|
||||||
visitors[ip].get('filtered', False):
|
|
||||||
block.setCellCSSClass(idx, 0, 'iwla_enlight')
|
block.setCellCSSClass(idx, 0, 'iwla_enlight')
|
||||||
|
|
|
@ -81,8 +81,6 @@ class IWLADisplayFilterUsers(IPlugin):
|
||||||
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
|
ip_title = ip
|
||||||
if 'dns_name_replaced' in hits[ip].keys():
|
|
||||||
ip_title = '%s [%s]' % (hits[ip]['remote_addr'], ip)
|
|
||||||
location = filtered_user.get('geo_location', {})
|
location = filtered_user.get('geo_location', {})
|
||||||
if location:
|
if location:
|
||||||
city = location.get('city', unknown)
|
city = location.get('city', unknown)
|
||||||
|
@ -107,7 +105,7 @@ class IWLADisplayFilterUsers(IPlugin):
|
||||||
referer = ''
|
referer = ''
|
||||||
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']), r['http_user_agent'], referer])
|
table.appendRow([generateHTMLLink(uri), time.asctime(r['time_decoded']), r['http_user_agent'], referer], filtered_user['remote_addr'])
|
||||||
page.appendBlock(table)
|
page.appendBlock(table)
|
||||||
|
|
||||||
display.addPage(page)
|
display.addPage(page)
|
||||||
|
@ -123,12 +121,8 @@ class IWLADisplayFilterUsers(IPlugin):
|
||||||
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Host'), self.iwla._(u'Pages'), self.iwla._(u'Hits'), self.iwla._(u'Last Access')])
|
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[:10]:
|
for filtered_user in self.filtered_users[:10]:
|
||||||
ip = filtered_user['remote_ip']
|
ip_title = filtered_user['remote_ip']
|
||||||
if 'dns_name_replaced' in hits[ip].keys():
|
table.appendRow([ip_title, filtered_user['viewed_pages'][0], filtered_user['viewed_hits'][0], time.asctime(hits[ip]['last_access'])], filtered_user['remote_addr'])
|
||||||
ip_title = '%s [%s]' % (hits[ip]['remote_addr'], ip)
|
|
||||||
else:
|
|
||||||
ip_title = ip
|
|
||||||
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:
|
if len(self.filtered_users) > 10:
|
||||||
table.appendRow([self.iwla._(u'Others'), len(self.filtered_users)-10, '', ''])
|
table.appendRow([self.iwla._(u'Others'), len(self.filtered_users)-10, '', ''])
|
||||||
table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')
|
table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')
|
||||||
|
|
|
@ -64,19 +64,14 @@ class IWLADisplayIPToGeo(IPlugin):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod # Needed to have unbound method
|
@staticmethod # Needed to have unbound method
|
||||||
def FlagFilter(host, self):
|
def FlagFilter(host, remote_addr, self):
|
||||||
cc = None
|
if remote_addr is None or not remote_addr in self.visitors.keys():
|
||||||
host_name = host.split(' ')[0] # hostname or ip
|
return None
|
||||||
if host_name in self.visitors.keys():
|
visitor = self.visitors[remote_addr]
|
||||||
cc = self.visitors[host_name].get('country_code', None)
|
|
||||||
else:
|
|
||||||
for visitor in self.visitors.values():
|
|
||||||
if visitor['remote_addr'] == host_name:
|
|
||||||
cc = visitor.get('country_code', None)
|
cc = visitor.get('country_code', None)
|
||||||
break
|
if not cc: return None
|
||||||
if not cc or cc == 'ip': return None
|
|
||||||
icon = '<img alt="%s flag" src="/%s/flags/%s.png"/>' % (cc, self.icon_path, cc)
|
icon = '<img alt="%s flag" src="/%s/flags/%s.png"/>' % (cc, self.icon_path, cc)
|
||||||
return '%s %s' % (icon ,host)
|
return '%s %s' % (icon, host)
|
||||||
|
|
||||||
def hook(self):
|
def hook(self):
|
||||||
display = self.iwla.getDisplay()
|
display = self.iwla.getDisplay()
|
||||||
|
|
|
@ -33,7 +33,7 @@ Plugin requirements :
|
||||||
None
|
None
|
||||||
|
|
||||||
Conf values needed :
|
Conf values needed :
|
||||||
display_visitor_ip*
|
None
|
||||||
|
|
||||||
Output files :
|
Output files :
|
||||||
OUTPUT_ROOT/year/month/index.html
|
OUTPUT_ROOT/year/month/index.html
|
||||||
|
@ -72,13 +72,8 @@ class IWLADisplayTopVisitors(IPlugin):
|
||||||
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Top visitors'), [self.iwla._(u'Host'), self.iwla._(u'Pages'), self.iwla._(u'Hits'), self.iwla._(u'Bandwidth'), self.iwla._(u'Last seen')], [3])
|
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Top visitors'), [self.iwla._(u'Host'), self.iwla._(u'Pages'), self.iwla._(u'Hits'), self.iwla._(u'Bandwidth'), self.iwla._(u'Last seen')], [3])
|
||||||
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', ''])
|
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', ''])
|
||||||
for super_hit in top_visitors:
|
for super_hit in top_visitors:
|
||||||
address = super_hit['remote_addr']
|
|
||||||
if display_visitor_ip and\
|
|
||||||
super_hit.get('dns_name_replaced', False):
|
|
||||||
address = '%s [%s]' % (address, super_hit['remote_ip'])
|
|
||||||
|
|
||||||
row = [
|
row = [
|
||||||
address,
|
super_hit['remote_addr'],
|
||||||
super_hit['viewed_pages'][0],
|
super_hit['viewed_pages'][0],
|
||||||
super_hit['viewed_hits'][0],
|
super_hit['viewed_hits'][0],
|
||||||
super_hit['bandwidth'][0],
|
super_hit['bandwidth'][0],
|
||||||
|
@ -87,7 +82,7 @@ class IWLADisplayTopVisitors(IPlugin):
|
||||||
total[1] -= super_hit['viewed_pages'][0]
|
total[1] -= super_hit['viewed_pages'][0]
|
||||||
total[2] -= super_hit['viewed_hits'][0]
|
total[2] -= super_hit['viewed_hits'][0]
|
||||||
total[3] -= super_hit['bandwidth'][0]
|
total[3] -= super_hit['bandwidth'][0]
|
||||||
table.appendRow(row)
|
table.appendRow(row, super_hit['remote_addr'])
|
||||||
if total[1] or total[2] or total[3]:
|
if total[1] or total[2] or total[3]:
|
||||||
total[0] = self.iwla._(u'Others')
|
total[0] = self.iwla._(u'Others')
|
||||||
total[4] = ''
|
total[4] = ''
|
||||||
|
|
|
@ -55,7 +55,7 @@ Statistics deletion :
|
||||||
class IWLAPostAnalysisIPType(IPlugin):
|
class IWLAPostAnalysisIPType(IPlugin):
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
self.v4_re = re.compile('[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
|
self.v4_re = re.compile('([0-9]{1,3}\.){3}[0-9]{1,3}$')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def hook(self):
|
def hook(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user