iwla

iwla Commit Details

Date:2016-09-25 20:38:49 (4 years 9 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:dc4695f539d2290d90d004bb354b4a06641a1921
Parents: b425edfa9a20b42b93e082f7ef3adf30716836af
Message:Add robot bandwidth display plugin

Changes:
Aplugins/display/robot_bandwidth.py (full)
Mplugins/display/top_hits.py (1 diff)

File differences

plugins/display/robot_bandwidth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
#
# Copyright Grégory Soutadé 2016
# This file is part of iwla
# iwla is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iwla is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iwla. If not, see <http://www.gnu.org/licenses/>.
#
import time
from iwla import IWLA
from iplugin import IPlugin
from display import *
"""
Display hook
Display top 10 robot bandwidth use
Plugin requirements :
None
Conf values needed :
display_visitor_ip*
create_all_robot_bandwidth_page*
Output files :
OUTPUT_ROOT/year/month/top_robots_bandwidth.html
OUTPUT_ROOT/year/month/index.html
Statistics creation :
None
Statistics update :
None
Statistics deletion :
None
"""
class IWLADisplayRobotBandwidth(IPlugin):
def __init__(self, iwla):
super(IWLADisplayRobotBandwidth, self).__init__(iwla)
self.API_VERSION = 1
self.display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False)
self.create_all_pages = self.iwla.getConfValue('create_all_robot_bandwidth_page', True)
def load(self):
return True
def hook(self):
display = self.iwla.getDisplay()
hits = self.iwla.getCurrentVisits()
bandwidths = []
for (k, super_hit) in hits.items():
if not self.iwla.isRobot(super_hit):
continue
bandwidths.append((super_hit, super_hit['bandwidth']))
bandwidths.sort(key=lambda tup: tup[1], reverse=True)
# All in a page
if self.create_all_pages:
title = createCurTitle(self.iwla, u'Robots bandwidth')
filename = 'top_robots_bandwidth.html'
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.setColsCSSClass(['', 'iwla_bandwidth', ''])
for (super_hit, bandwidth) in bandwidths:
address = super_hit['remote_addr']
if self.display_visitor_ip and\
super_hit.get('dns_name_replaced', False):
address = '%s [%s]' % (address, super_hit['remote_ip'])
row = [
address,
bytesToStr(bandwidth),
time.asctime(super_hit['last_access'])
]
table.appendRow(row)
page.appendBlock(table)
display.addPage(page)
title = self.iwla._(u'Robots bandwidth')
if self.create_all_pages:
link = '<a href=\'%s\'>%s</a>' % (filename, self.iwla._(u'All robots bandwidth'))
title = '%s - %s' % (title, link)
# 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.setColsCSSClass(['', 'iwla_bandwidth', ''])
for (super_hit, bandwidth) in bandwidths[:10]:
address = super_hit['remote_addr']
if self.display_visitor_ip and\
super_hit.get('dns_name_replaced', False):
address = '%s [%s]' % (address, super_hit['remote_ip'])
row = [
address,
bytesToStr(bandwidth),
time.asctime(super_hit['last_access'])
]
table.appendRow(row)
index.appendBlock(table)
plugins/display/top_hits.py
8686
8787
8888
89
89
9090
9191
9292
display.addPage(page)
title = 'Top Hits'
title = u'Top Hits'
if self.create_all_hits:
link = '<a href=\'%s\'>%s</a>' % (filename, self.iwla._(u'All Hits'))
title = '%s - %s' % (title, link)

Archive Download the corresponding diff file

Branches

Tags