2014-12-18 19:54:31 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright Grégory Soutadé 2015
|
|
|
|
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
2014-11-21 16:57:37 +01:00
|
|
|
import time
|
|
|
|
|
2014-11-24 17:13:59 +01:00
|
|
|
from iwla import IWLA
|
|
|
|
from iplugin import IPlugin
|
|
|
|
from display import *
|
2014-11-21 16:57:37 +01:00
|
|
|
|
2014-12-19 11:34:25 +01:00
|
|
|
"""
|
|
|
|
Display hook
|
|
|
|
|
|
|
|
Create TOP visitors block
|
|
|
|
|
|
|
|
Plugin requirements :
|
|
|
|
None
|
|
|
|
|
|
|
|
Conf values needed :
|
2023-04-28 16:17:47 +02:00
|
|
|
None
|
2014-12-19 11:34:25 +01:00
|
|
|
|
|
|
|
Output files :
|
|
|
|
OUTPUT_ROOT/year/month/index.html
|
|
|
|
|
|
|
|
Statistics creation :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics update :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics deletion :
|
|
|
|
None
|
|
|
|
"""
|
2014-12-11 21:13:24 +01:00
|
|
|
|
2014-11-24 17:13:59 +01:00
|
|
|
class IWLADisplayTopVisitors(IPlugin):
|
2014-11-24 21:42:57 +01:00
|
|
|
def __init__(self, iwla):
|
|
|
|
super(IWLADisplayTopVisitors, self).__init__(iwla)
|
2014-11-24 17:13:59 +01:00
|
|
|
self.API_VERSION = 1
|
2014-11-22 19:23:56 +01:00
|
|
|
|
2014-11-26 20:31:13 +01:00
|
|
|
def hook(self):
|
2014-11-26 21:06:36 +01:00
|
|
|
hits = self.iwla.getValidVisitors()
|
2014-12-08 14:13:26 +01:00
|
|
|
display = self.iwla.getDisplay()
|
2014-11-27 09:01:51 +01:00
|
|
|
display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False)
|
2014-11-26 21:06:36 +01:00
|
|
|
|
2014-12-05 16:03:09 +01:00
|
|
|
total = [0]*5
|
|
|
|
for super_hit in hits.values():
|
2017-08-24 07:55:53 +02:00
|
|
|
total[1] += super_hit['viewed_pages'][0]
|
|
|
|
total[2] += super_hit['viewed_hits'][0]
|
|
|
|
total[3] += super_hit['bandwidth'][0]
|
2014-12-05 16:03:09 +01:00
|
|
|
|
2017-08-24 07:55:53 +02:00
|
|
|
top_bandwidth = [(k,v['bandwidth'][0]) for (k,v) in hits.items()]
|
2014-11-26 21:06:36 +01:00
|
|
|
top_bandwidth = sorted(top_bandwidth, key=lambda t: t[1], reverse=True)
|
|
|
|
top_visitors = [hits[h[0]] for h in top_bandwidth[:10]]
|
2014-11-22 19:23:56 +01:00
|
|
|
|
2014-11-26 20:31:13 +01:00
|
|
|
index = self.iwla.getDisplayIndex()
|
2020-12-11 09:18:50 +01:00
|
|
|
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])
|
2014-11-28 16:02:04 +01:00
|
|
|
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', ''])
|
2014-11-26 21:06:36 +01:00
|
|
|
for super_hit in top_visitors:
|
2014-11-24 17:13:59 +01:00
|
|
|
row = [
|
2023-04-28 16:17:47 +02:00
|
|
|
super_hit['remote_addr'],
|
2017-08-24 07:55:53 +02:00
|
|
|
super_hit['viewed_pages'][0],
|
|
|
|
super_hit['viewed_hits'][0],
|
2020-12-11 09:18:50 +01:00
|
|
|
super_hit['bandwidth'][0],
|
2014-11-24 17:13:59 +01:00
|
|
|
time.asctime(super_hit['last_access'])
|
|
|
|
]
|
2017-08-24 07:55:53 +02:00
|
|
|
total[1] -= super_hit['viewed_pages'][0]
|
|
|
|
total[2] -= super_hit['viewed_hits'][0]
|
|
|
|
total[3] -= super_hit['bandwidth'][0]
|
2023-05-21 11:04:40 +02:00
|
|
|
table.appendRow(row, super_hit['remote_ip'])
|
2014-12-05 16:03:09 +01:00
|
|
|
if total[1] or total[2] or total[3]:
|
2014-12-17 20:31:59 +01:00
|
|
|
total[0] = self.iwla._(u'Others')
|
2014-12-05 16:03:09 +01:00
|
|
|
total[4] = ''
|
|
|
|
table.appendRow(total)
|
|
|
|
table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')
|
2014-11-24 17:13:59 +01:00
|
|
|
index.appendBlock(table)
|