This commit is contained in:
Gregory Soutade 2023-04-28 16:17:47 +02:00
parent b1b92412e0
commit 7507b8e77f
7 changed files with 48 additions and 51 deletions

View File

@ -109,10 +109,12 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
self.rows_cssclasses = []
self.table_css = u'iwla_table'
self.human_readable_cols = human_readable_cols or []
def appendRow(self, row):
self.objects = []
def appendRow(self, row, _object=None):
self.rows.append(listToStr(row))
self.rows_cssclasses.append([u''] * len(row))
self.objects.append(_object)
def insertCol(self, col_number, col_title='', col_css_class=''):
self.cols.insert(col_number, col_title)
@ -142,6 +144,12 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
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):
if row < 0 or col < 0 or\
row >= len(self.rows) or col >= len(self.cols):
@ -208,9 +216,9 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
target_col = col
break
if target_col is None: return
for row in self.rows:
res = function(row[target_col], **args)
if res:
for idx, row in enumerate(self.rows):
res = function(row[target_col], self.objects[idx], **args)
if res is not None:
row[target_col] = res
def _buildHTML(self):
@ -419,6 +427,21 @@ class DisplayHTMLBuild(object):
def addColumnFilter(self, column, function, args):
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

View File

@ -72,10 +72,6 @@ class IWLADisplayAllVisits(IPlugin):
for super_hit in last_access:
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 = [
address,
super_hit['viewed_pages'][0],
@ -83,7 +79,7 @@ class IWLADisplayAllVisits(IPlugin):
super_hit['bandwidth'][0],
time.asctime(super_hit['last_access'])
]
table.appendRow(row)
table.appendRow(row, address)
page.appendBlock(table)
display.addPage(page)

View File

@ -71,15 +71,9 @@ class IWLADisplayAllVisitsEnlight(IPlugin):
return
for (idx, row) in enumerate(block.rows):
# Direct IP
ip = row[0]
if not ip in visitors.keys():
# name [IP]
ip = self.ip_re.match(row[0])
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):
remote_addr = block.objects[idx]
if remote_addr is None or not remote_addr in visitors.keys(): continue
visitor = visitors[remote_addr]
if visitor.get('enlight', False) or\
visitor.get('filtered', False):
block.setCellCSSClass(idx, 0, 'iwla_enlight')

View File

@ -81,8 +81,6 @@ class IWLADisplayFilterUsers(IPlugin):
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 = '%s [%s]' % (hits[ip]['remote_addr'], ip)
location = filtered_user.get('geo_location', {})
if location:
city = location.get('city', unknown)
@ -107,7 +105,7 @@ class IWLADisplayFilterUsers(IPlugin):
referer = ''
uri = "%s%s" % (r.get('server_name', ''),
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)
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.setColsCSSClass(['', '', 'iwla_page', 'iwla_hit'])
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, filtered_user['viewed_pages'][0], filtered_user['viewed_hits'][0], time.asctime(hits[ip]['last_access'])])
ip_title = filtered_user['remote_ip']
table.appendRow([ip_title, filtered_user['viewed_pages'][0], filtered_user['viewed_hits'][0], time.asctime(hits[ip]['last_access'])], filtered_user['remote_addr'])
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')

View File

@ -64,19 +64,14 @@ class IWLADisplayIPToGeo(IPlugin):
return True
@staticmethod # Needed to have unbound method
def FlagFilter(host, self):
cc = None
host_name = host.split(' ')[0] # hostname or ip
if host_name in self.visitors.keys():
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)
break
if not cc or cc == 'ip': return None
def FlagFilter(host, remote_addr, self):
if remote_addr is None or not remote_addr in self.visitors.keys():
return None
visitor = self.visitors[remote_addr]
cc = visitor.get('country_code', None)
if not cc: return None
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):
display = self.iwla.getDisplay()

View File

@ -33,7 +33,7 @@ Plugin requirements :
None
Conf values needed :
display_visitor_ip*
None
Output files :
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.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', ''])
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 = [
address,
super_hit['remote_addr'],
super_hit['viewed_pages'][0],
super_hit['viewed_hits'][0],
super_hit['bandwidth'][0],
@ -87,7 +82,7 @@ class IWLADisplayTopVisitors(IPlugin):
total[1] -= super_hit['viewed_pages'][0]
total[2] -= super_hit['viewed_hits'][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]:
total[0] = self.iwla._(u'Others')
total[4] = ''

View File

@ -55,7 +55,7 @@ Statistics deletion :
class IWLAPostAnalysisIPType(IPlugin):
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
def hook(self):