iwla

iwla Commit Details

Date:2014-11-24 13:44:04 (6 years 8 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:670f0249053a9a265fff0c80ffadee6100e5fb1c
Parents: 38c041126d1b1604ec47b64c5591b92a69e121b6
Message:Add bytesToStr() Automatically convert list into strings in appendRow() Add package information

Changes:
Aplugins/__init__.py (full)
Aplugins/display/__init__.py (full)
Aplugins/post_analysis/__init__.py (full)
Aplugins/pre_analysis/__init__.py (full)
Mdisplay.py (2 diffs)
Miwla.py (2 diffs)
Mplugins/display/top_visitors.py (1 diff)
Mplugins/post_analysis/reverse_dns.py (1 diff)

File differences

display.py
1515
1616
1717
18
18
1919
2020
2121
......
6868
6969
7070
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
self.rows = []
def appendRow(self, row):
self.rows.append(row)
self.rows.append(listToStr(row))
def build(self, f):
f.write('<table>')
def build(self, root):
for page in self.pages:
page.build(root)
def bytesToStr(bytes):
suffixes = ['', ' kB', ' MB', ' GB', ' TB']
for i in range(0, len(suffixes)):
if bytes < 1024: break
bytes /= 1024.0
if i:
return '%.02f%s' % (bytes, suffixes[i])
else:
return '%d%s' % (bytes, suffixes[i])
def _toStr(v):
if type(v) != str: return str(v)
else: return v
def listToStr(l): return map(lambda(v) : _toStr(v), l)
iwla.py
237237
238238
239239
240
241
240
241
242242
243243
244244
......
247247
248248
249249
250
250
251251
252
252
253253
254
255
254
255
256
257
256258
257
258
259
260
261
259262
260263
261264
nb_visits = 0
for k in keys:
stats = self.current_analysis['days_stats'][k]
row = [k, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'], stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
row = map(lambda(v): str(v), row)
row = [k, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'],
bytesToStr(stats['viewed_bandwidth']), bytesToStr(stats['not_viewed_bandwidth'])]
days.appendRow(row)
nb_visits += stats['nb_visitors']
nb_days = len(keys)
row = [0, nb_visits, stats['viewed_pages'], stats['viewed_hits'], stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
if nb_days:
row = map(lambda(v): str(int(v/nb_days)), row)
average_row = map(lambda(v): str(int(v/nb_days)), row)
else:
row = map(lambda(v): '0', row)
average_row = map(lambda(v): '0', row)
row[0] = 'Average'
days.appendRow(row)
average_row[0] = 'Average'
average_row[4] = bytesToStr(row[4])
average_row[5] = bytesToStr(row[5])
days.appendRow(average_row)
row = ['Total', nb_visits, stats['viewed_pages'], stats['viewed_hits'], stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
row = map(lambda(v): str(v), row)
row[0] = 'Total'
row[4] = bytesToStr(row[4])
row[5] = bytesToStr(row[5])
days.appendRow(row)
page.appendBlock(days)
self.display.addPage(page)
plugins/__init__.py
1
2
__all__ = ['pre_analysis', 'post_analysis', 'display']
plugins/display/__init__.py
1
#
plugins/display/top_visitors.py
1818
1919
2020
21
21
22
2223
2324
2425
2526
2627
27
28
29
30
28
29
30
31
32
33
34
35
3136
3237
def hook(iwla):
stats = iwla.getMonthStats()
if not 'top_visitors' in stats.keys():
top_visitors = stats.get('top_visitors', None)
if not top_visitors:
print 'Top visitors post analysis plugin not installed'
return
index = iwla.getDisplayIndex()
table = DisplayHTMLBlockTable('Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
for super_hit in stats['top_visitors']:
row = [super_hit['remote_addr'], super_hit['viewed_pages'], super_hit['viewed_hits'], super_hit['bandwidth'], 0]
row = map(lambda(v): str(v), row)
row[4] = time.asctime(super_hit['last_access'])
for super_hit in top_visitors:
row = [
super_hit['remote_addr'],
super_hit['viewed_pages'],
super_hit['viewed_hits'],
bytesToStr(super_hit['bandwidth']),
time.asctime(super_hit['last_access'])
]
table.appendRow(row)
index.appendBlock(table)
plugins/post_analysis/__init__.py
1
#
plugins/post_analysis/reverse_dns.py
1919
2020
2121
22
2223
2324
2425
2526
2627
28
29
2730
def hook(iwla):
hits = iwla.getValidVisitors()
for (k, hit) in hits.items():
if hit.get('dns_analysed', False): continue
try:
name, _, _ = socket.gethostbyaddr(k)
hit['remote_addr'] = name
except:
pass
finally:
hit['dns_analysed'] = True
plugins/pre_analysis/__init__.py
1
#

Archive Download the corresponding diff file

Branches

Tags