iwla/plugins/display/all_visits.py
Grégory Soutadé 1b4f9c0ad5 Add First CSS
2014-11-28 16:02:04 +01:00

55 lines
1.9 KiB
Python

import time
from iwla import IWLA
from iplugin import IPlugin
from display import *
class IWLADisplayAllVisits(IPlugin):
def __init__(self, iwla):
super(IWLADisplayAllVisits, self).__init__(iwla)
self.API_VERSION = 1
def hook(self):
hits = self.iwla.getValidVisitors()
display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False)
last_access = sorted(hits.values(), key=lambda t: t['last_access'], reverse=True)
title = time.strftime('All visits - %B %Y', self.iwla.getCurTime())
filename = 'all_visits.html'
path = self.iwla.getCurDisplayPath(filename)
page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', ''])
for super_hit in last_access:
address = super_hit['remote_addr']
if display_visitor_ip and\
super_hit.get('dns_name_replaced', False):
address = '%s [%s]' % (address, super_hit['remote_ip'])
row = [
address,
super_hit['viewed_pages'],
super_hit['viewed_hits'],
bytesToStr(super_hit['bandwidth']),
time.asctime(super_hit['last_access'])
]
table.appendRow(row)
page.appendBlock(table)
display = self.iwla.getDisplay()
display.addPage(page)
index = self.iwla.getDisplayIndex()
link = '<a href=\'%s\'>All visits</a>' % (filename)
block = index.getBlock('Top visitors')
if block:
block.setTitle('%s - %s' % (block.getTitle(), link))
else:
block = DisplayHTMLRawBlock()
block.setRawHTML(link)
index.appendBlock(block)