iwla

iwla Git Source Tree

Root/plugins/display/all_visits.py

Source at commit 4e02325733e5e8e4f5de2f0046e721f8da7abfff created 6 years 10 months ago.
By Gregory Soutade, Initial commit
1# -*- coding: utf-8 -*-
2#
3# Copyright Grégory Soutadé 2015
4
5# This file is part of iwla
6
7# iwla is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# iwla is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with iwla. If not, see <http://www.gnu.org/licenses/>.
19#
20
21import time
22
23from iwla import IWLA
24from iplugin import IPlugin
25from display import *
26
27"""
28Display hook
29
30Create All visits page
31
32Plugin requirements :
33 None
34
35Conf values needed :
36 display_visitor_ip*
37
38Output files :
39 OUTPUT_ROOT/year/month/all_visits.html
40 OUTPUT_ROOT/year/month/index.html
41
42Statistics creation :
43 None
44
45Statistics update :
46 None
47
48Statistics deletion :
49 None
50"""
51
52class IWLADisplayAllVisits(IPlugin):
53 def __init__(self, iwla):
54 super(IWLADisplayAllVisits, self).__init__(iwla)
55 self.API_VERSION = 1
56
57 def hook(self):
58 display = self.iwla.getDisplay()
59 hits = self.iwla.getValidVisitors()
60 display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False)
61
62 last_access = sorted(hits.values(), key=lambda t: t['last_access'], reverse=True)
63
64 title = createCurTitle(self.iwla, u'All visits')
65
66 filename = 'all_visits.html'
67 path = self.iwla.getCurDisplayPath(filename)
68
69 page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
70 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')])
71 table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', ''])
72
73 for super_hit in last_access:
74 address = super_hit['remote_addr']
75 if display_visitor_ip and\
76 super_hit.get('dns_name_replaced', False):
77 address = '%s [%s]' % (address, super_hit['remote_ip'])
78
79 row = [
80 address,
81 super_hit['viewed_pages'],
82 super_hit['viewed_hits'],
83 bytesToStr(super_hit['bandwidth']),
84 time.asctime(super_hit['last_access'])
85 ]
86 table.appendRow(row)
87 page.appendBlock(table)
88
89 display.addPage(page)
90
91 index = self.iwla.getDisplayIndex()
92 link = '<a href=\'%s\'>%s</a>' % (filename, self.iwla._(u'All visits'))
93 block = index.getBlock(self.iwla._(u'Top visitors'))
94 if block:
95 block.setTitle('%s - %s' % (block.getTitle(), link))
96 else:
97 block = display.createBlock(DisplayHTMLRawBlock)
98 block.setRawHTML(link)
99 index.appendBlock(block)

Archive Download this file

Branches

Tags