iwla/plugins/display/all_visits.py

95 lines
2.9 KiB
Python
Raw Normal View History

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-25 16:59:29 +01:00
import time
from iwla import IWLA
from iplugin import IPlugin
from display import *
"""
Display hook
Create All visits page
Plugin requirements :
None
Conf values needed :
display_visitor_ip*
Output files :
OUTPUT_ROOT/year/month/all_visits.html
OUTPUT_ROOT/year/month/index.html
Statistics creation :
None
Statistics update :
None
Statistics deletion :
None
"""
2014-12-10 21:15:56 +01:00
2014-11-25 16:59:29 +01:00
class IWLADisplayAllVisits(IPlugin):
def __init__(self, iwla):
super(IWLADisplayAllVisits, self).__init__(iwla)
self.API_VERSION = 1
def hook(self):
display = self.iwla.getDisplay()
hits = self.iwla.getValidVisitors()
display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False)
2014-11-25 16:59:29 +01:00
last_access = sorted(hits.values(), key=lambda t: t['last_access'], reverse=True)
2014-12-19 17:50:45 +01:00
title = createCurTitle(self.iwla, u'All visits')
2014-11-25 16:59:29 +01:00
2014-11-27 14:11:47 +01:00
filename = 'all_visits.html'
path = self.iwla.getCurDisplayPath(filename)
2014-11-25 16:59:29 +01:00
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'All visits'), [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-27 21:40:23 +01:00
2014-11-25 16:59:29 +01:00
for super_hit in last_access:
row = [
super_hit['remote_addr'],
super_hit['viewed_pages'][0],
super_hit['viewed_hits'][0],
super_hit['bandwidth'][0],
2014-11-25 16:59:29 +01:00
time.asctime(super_hit['last_access'])
]
table.appendRow(row, super_hit['remote_ip'])
2014-11-25 16:59:29 +01:00
page.appendBlock(table)
display.addPage(page)
index = self.iwla.getDisplayIndex()
link = '<a href=\'%s\'>%s</a>' % (filename, self.iwla._(u'All visits'))
block = index.getBlock(self.iwla._(u'Top visitors'))
if block:
block.setTitle('%s - %s' % (block.getTitle(), link))
else:
block = display.createBlock(DisplayHTMLRawBlock)
block.setRawHTML(link)
index.appendBlock(block)