iwla

iwla Commit Details

Date:2020-12-11 09:18:50 (7 months 18 days ago)
Author:Grégory Soutadé
Branch:dev
Commit:a6f8c71bf26f4a10781a7db20e8a7c3b7075ab7a
Parents: 3ed8ba40bead82bc1d845ec9b65ee50471362c75
Message:Add parameter to do strToBytes in BlockTable and fix some errors with string and int

Changes:
Mdisplay.py (6 diffs)
Miwla.py (6 diffs)
Mplugins/display/all_visits.py (2 diffs)
Mplugins/display/filter_users.py (2 diffs)
Mplugins/display/hours_stats.py (1 diff)
Mplugins/display/robot_bandwidth.py (4 diffs)
Mplugins/display/top_visitors.py (3 diffs)

File differences

display.py
9898
9999
100100
101
101
102102
103103
104104
105105
106106
107107
108
108109
109110
110111
......
226227
227228
228229
230
231
229232
230233
231234
......
238241
239242
240243
241
242
244
245
246
247
243248
244249
245250
246251
247
248252
249253
250254
251255
252256
253
254
255
256
257257
258258
259259
......
265265
266266
267267
268
268
269269
270
271
272
273
270
274271
272
273
275274
276275
277276
......
302301
303302
304303
305
304
306305
307306
308307
......
427426
428427
429428
430
431
432
433
434
435
436429
437430
438431
439432
440433
441
434
442435
443
436
444437
445438
446439
class DisplayHTMLBlockTable(DisplayHTMLBlock):
def __init__(self, iwla, title, cols):
def __init__(self, iwla, title, cols, human_readable_cols=None):
super(DisplayHTMLBlockTable, self).__init__(iwla=iwla, title=title)
self.cols = listToStr(cols)
self.rows = []
self.cols_cssclasses = [u''] * len(cols)
self.rows_cssclasses = []
self.table_css = u'iwla_table'
self.human_readable_cols = human_readable_cols or []
def appendRow(self, row):
self.rows.append(listToStr(row))
html += u'<tr>'
for j in range(0, len(row)):
v = row[j]
if j in self.human_readable_cols:
v = bytesToStr(v)
style = self.getCellCSSClass(i, j)
if style: style = u' class="%s"' % (style)
html += u'<td%s>%s</td>' % (style, v)
class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
def __init__(self, iwla, title, cols, short_titles=None, nb_valid_rows=0, graph_cols=None):
super(DisplayHTMLBlockTableWithGraph, self).__init__(iwla=iwla, title=title, cols=cols)
def __init__(self, iwla, title, cols, short_titles=None, nb_valid_rows=0, graph_cols=None,
human_readable_cols=None):
super(DisplayHTMLBlockTableWithGraph, self).__init__(iwla=iwla, title=title, cols=cols,
human_readable_cols=human_readable_cols)
self.short_titles = short_titles or []
self.short_titles = listToStr(self.short_titles)
self.nb_valid_rows = nb_valid_rows
self.icon_path = self.iwla.getConfValue('icon_path', '/')
self.raw_rows = []
self.maxes = [0] * len(cols)
self.table_graph_css = u'iwla_graph_table'
self.td_img_css = u'iwla_td_img'
self.graph_cols = graph_cols or []
def appendRow(self, row):
self.raw_rows.append(row)
super(DisplayHTMLBlockTableWithGraph, self).appendRow(row)
def appendShortTitle(self, short_title):
self.short_titles.append(short_title)
def _computeMax(self):
for i in range(0, self.nb_valid_rows):
row = self.raw_rows[i]
row = self.row[i]
for j in range(1, len(row)):
try:
if row[j] > self.maxes[j]:
self.maxes[j] = row[j]
except:
if type(row[j]) != int:
continue
if row[j] > self.maxes[j]:
self.maxes[j] = row[j]
def _getIconFromStyle(self, style):
if style.startswith(u'iwla_page'): icon = u'vp.png'
if style: style = u' class="%s"' % (style)
alt = u'%s: %s' % (row[j], self.cols[j])
if self.maxes[j]:
height = int((self.raw_rows[i][j] * 100) / self.maxes[j]) or 1
height = int((self.rows[i][j] * 100) / self.maxes[j]) or 1
else:
height = 1
html += u'<img%s src="%s" height="%d" width="6" alt="%s" title="%s" />' % (style, icon, height, alt, alt)
def bytesToStr(_bytes):
suffixes = [u'', u' kB', u' MB', u' GB', u' TB']
try:
if type(_bytes) != int:
_bytes = int(_bytes, 10)
except:
return _bytes
for i in range(0, len(suffixes)):
if _bytes < 1024: break
_bytes /= 1024.0
if i:
return u'%.02f%s' % (_bytes, suffixes[i])
return '%.02f%s' % (_bytes, suffixes[i])
else:
return u'%d%s' % (_bytes, suffixes[i])
return '%d%s' % (_bytes, suffixes[i])
def _toStr(v):
return v
iwla.py
449449
450450
451451
452
452
453453
454454
455455
......
465465
466466
467467
468
469
468
469
470
471
470472
471473
472474
......
487489
488490
489491
490
491
492492
493493
494494
495
496
497495
498496
499497
......
504502
505503
506504
507
505
508506
509
507
510508
511509
512510
......
522520
523521
524522
525
526
523
524
525
526
527527
528528
529
530
529
530
531531
532532
533533
......
537537
538538
539539
540
541
542540
543541
544542
page.appendBlock(link)
_, nb_month_days = monthrange(cur_time.tm_year, cur_time.tm_mon)
days = self.display.createBlock(DisplayHTMLBlockTableWithGraph, self._('By day'), [self._('Day'), self._('Visits'), self._('Pages'), self._('Hits'), self._('Bandwidth'), self._('Not viewed Bandwidth')], None, nb_month_days, range(1,6))
days = self.display.createBlock(DisplayHTMLBlockTableWithGraph, self._('By day'), [self._('Day'), self._('Visits'), self._('Pages'), self._('Hits'), self._('Bandwidth'), self._('Not viewed Bandwidth')], None, nb_month_days, range(1,6), [4, 5])
days.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
nb_visits = 0
nb_days = 0
else:
row = [full_day, 0, 0, 0, 0, 0]
days.appendRow(row)
days.setCellValue(i-1, 4, bytesToStr(row[4]))
days.setCellValue(i-1, 5, bytesToStr(row[5]))
viewed_bandwidth = row[4]
not_viewed_bandwidth = row[5]
days.setCellValue(i-1, 4, viewed_bandwidth)
days.setCellValue(i-1, 5, not_viewed_bandwidth)
days.appendShortTitle(day)
adate = date(cur_time.tm_year, cur_time.tm_mon, i)
week_day = adate.weekday()
average_row = list(map(lambda v: 0, row))
average_row[0] = self._('Average')
average_row[4] = bytesToStr(average_row[4])
average_row[5] = bytesToStr(average_row[5])
days.appendRow(average_row)
row[0] = self._('Total')
row[4] = bytesToStr(row[4])
row[5] = bytesToStr(row[5])
days.appendRow(row)
page.appendBlock(days)
self.display.addPage(page)
title = '%s %d' % (self._('Summary'), year)
cols = [self._('Month'), self._('Visitors'), self._('Visits'), self._('Pages'), self._('Hits'), self._('Bandwidth'), self._('Not viewed Bandwidth'), self._('Details')]
graph_cols=range(1,7)
months = self.display.createBlock(DisplayHTMLBlockTableWithGraph, title, cols, None, 12, graph_cols)
months = self.display.createBlock(DisplayHTMLBlockTableWithGraph, title, cols, None, 12, graph_cols, [5, 6])
months.setColsCSSClass(['', 'iwla_visitor', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth', ''])
months_ = self.display.createBlock(DisplayHTMLBlockTableWithGraph, title, cols[:-1], None, 12, graph_cols[:-1])
months_ = self.display.createBlock(DisplayHTMLBlockTableWithGraph, title, cols[:-1], None, 12, graph_cols[:-1], [5, 6])
months_.setColsCSSClass(['', 'iwla_visitor', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
total = [0] * len(cols)
for i in range(1, 13):
else:
row = [full_month, 0, 0, 0, 0, 0, 0, '']
months.appendRow(row)
months.setCellValue(i-1, 5, bytesToStr(row[5]))
months.setCellValue(i-1, 6, bytesToStr(row[6]))
viewed_bandwidth = row[5]
not_viewed_bandwidth = row[6]
months.setCellValue(i-1, 5, viewed_bandwidth)
months.setCellValue(i-1, 6, not_viewed_bandwidth)
months.appendShortTitle(month)
months_.appendRow(row[:-1])
months_.setCellValue(i-1, 5, bytesToStr(row[5]))
months_.setCellValue(i-1, 6, bytesToStr(row[6]))
months_.setCellValue(i-1, 5, viewed_bandwidth)
months_.setCellValue(i-1, 6, not_viewed_bandwidth)
months_.appendShortTitle(month)
if year == cur_time.tm_year and i == cur_time.tm_mon:
css = months.getCellCSSClass(i-1, 0)
months_.setCellCSSClass(i-1, 0, css)
total[0] = self._('Total')
total[5] = bytesToStr(total[5])
total[6] = bytesToStr(total[6])
total[7] = u''
months.appendRow(total)
page.appendBlock(months)
plugins/display/all_visits.py
6767
6868
6969
70
70
7171
7272
7373
......
8080
8181
8282
83
83
8484
8585
8686
path = self.iwla.getCurDisplayPath(filename)
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Last seen'), [self.iwla._(u'Host'), self.iwla._(u'Pages'), self.iwla._(u'Hits'), self.iwla._(u'Bandwidth'), self.iwla._(u'Last seen')])
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Last seen'), [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 last_access:
address,
super_hit['viewed_pages'][0],
super_hit['viewed_hits'][0],
bytesToStr(super_hit['bandwidth'][0]),
super_hit['bandwidth'][0],
time.asctime(super_hit['last_access'])
]
table.appendRow(row)
plugins/display/filter_users.py
152152
153153
154154
155
155
156156
157157
158158
......
188188
189189
190190
191
191
192192
193193
194194
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Filtered users'), [self.iwla._(u'Pages'), self.iwla._(u'Last Access')])
table.setColsCSSClass(['iwla_page', ''])
for filtered_user in self.filtered_users:
ip = filtered_user['remote_addr']
ip = filtered_user['remote_ip']
if 'dns_name_replaced' in hits[ip].keys():
ip_title = '<b>%s [%s]</b>' % (hits[ip]['remote_addr'], ip)
else:
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Host'), self.iwla._(u'Last Access'), self.iwla._(u'Pages'), self.iwla._(u'Hits')])
table.setColsCSSClass(['', '', 'iwla_page', 'iwla_hit'])
for filtered_user in self.filtered_users:
ip = filtered_user['remote_addr']
ip = filtered_user['remote_ip']
if 'dns_name_replaced' in hits[ip].keys():
ip_title = '%s [%s]' % (hits[ip]['remote_addr'], ip)
else:
plugins/display/hours_stats.py
7070
7171
7272
73
73
7474
7575
7676
77
77
7878
7979
8080
8181
8282
83
83
8484
8585
8686
87
87
8888
# By Day
title = self.iwla._(u'By day')
days = [self.iwla._('Mon'), self.iwla._('Tue'), self.iwla._('Wed'), self.iwla._('Thu'), self.iwla._('Fri'), self.iwla._('Sat'), self.iwla._('Sun')]
table = display.createBlock(DisplayHTMLBlockTableWithGraph, title, [self.iwla._('Day'), self.iwla._('Pages'), self.iwla._('Hits'), self.iwla._('Bandwidth')], days, 7, range(1,4))
table = display.createBlock(DisplayHTMLBlockTableWithGraph, title, [self.iwla._('Day'), self.iwla._('Pages'), self.iwla._('Hits'), self.iwla._('Bandwidth')], days, 7, range(1,4), [3])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth'])
for i in range(0,7):
table.appendRow([days[i], days_stats[i]['pages'], days_stats[i]['hits'], days_stats[i]['bandwidth']])
table.setCellValue(i, 3, bytesToStr(days_stats[i]['bandwidth']))
table.setCellValue(i, 3, days_stats[i]['bandwidth'])
index.appendBlock(table)
# By Hours
title = self.iwla._(u'By Hours')
hours = ['%02d' % i for i in range(0, 24)]
table = display.createBlock(DisplayHTMLBlockTableWithGraph, title, [self.iwla._('Hours'), self.iwla._('Pages'), self.iwla._('Hits'), self.iwla._('Bandwidth')], hours, 24, range(1,4))
table = display.createBlock(DisplayHTMLBlockTableWithGraph, title, [self.iwla._('Hours'), self.iwla._('Pages'), self.iwla._('Hits'), self.iwla._('Bandwidth')], hours, 24, range(1,4), [3])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth'])
for i in range(0,24):
table.appendRow([hours[i], hours_stats[i]['pages'], hours_stats[i]['hits'], hours_stats[i]['bandwidth']])
table.setCellValue(i, 3, bytesToStr(hours_stats[i]['bandwidth']))
table.setCellValue(i, 3, hours_stats[i]['bandwidth'])
index.appendBlock(table)
plugins/display/robot_bandwidth.py
7878
7979
8080
81
81
8282
8383
8484
......
8888
8989
9090
91
91
9292
9393
9494
......
103103
104104
105105
106
106
107107
108108
109109
......
114114
115115
116116
117
117
118118
119119
120120
path = self.iwla.getCurDisplayPath(filename)
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Host'), self.iwla._(u'Bandwidth'), self.iwla._(u'Last seen')])
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Host'), self.iwla._(u'Bandwidth'), self.iwla._(u'Last seen')], [1])
table.setColsCSSClass(['', 'iwla_bandwidth', ''])
for (super_hit, bandwidth) in bandwidths:
address = super_hit['remote_addr']
row = [
address,
bytesToStr(bandwidth),
bandwidth,
time.asctime(super_hit['last_access'])
]
table.appendRow(row)
# Top in index
index = self.iwla.getDisplayIndex()
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Host'), self.iwla._(u'Bandwidth'), self.iwla._(u'Last seen')])
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Host'), self.iwla._(u'Bandwidth'), self.iwla._(u'Last seen')], [1])
table.setColsCSSClass(['', 'iwla_bandwidth', ''])
for (super_hit, bandwidth) in bandwidths[:10]:
row = [
address,
bytesToStr(bandwidth),
bandwidth,
time.asctime(super_hit['last_access'])
]
table.appendRow(row)
plugins/display/top_visitors.py
6969
7070
7171
72
72
7373
7474
7575
......
8181
8282
8383
84
84
8585
8686
8787
......
9090
9191
9292
93
9493
9594
9695
top_visitors = [hits[h[0]] for h in top_bandwidth[:10]]
index = self.iwla.getDisplayIndex()
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')])
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']
address,
super_hit['viewed_pages'][0],
super_hit['viewed_hits'][0],
bytesToStr(super_hit['bandwidth'][0]),
super_hit['bandwidth'][0],
time.asctime(super_hit['last_access'])
]
total[1] -= super_hit['viewed_pages'][0]
table.appendRow(row)
if total[1] or total[2] or total[3]:
total[0] = self.iwla._(u'Others')
total[3] = bytesToStr(total[3])
total[4] = ''
table.appendRow(total)
table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')

Archive Download the corresponding diff file

Branches

Tags