2014-11-25 16:59:29 +01:00
|
|
|
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
|
|
|
|
|
2014-11-26 20:31:13 +01:00
|
|
|
def hook(self):
|
|
|
|
hits = self.iwla.getValidVisitors()
|
2014-11-27 09:01:51 +01:00
|
|
|
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-11-27 14:11:47 +01:00
|
|
|
title = time.strftime('All visits - %B %Y', self.iwla.getCurTime())
|
2014-11-25 16:59:29 +01:00
|
|
|
|
2014-11-27 14:11:47 +01:00
|
|
|
filename = 'all_visits.html'
|
2014-11-27 14:29:25 +01:00
|
|
|
path = self.iwla.getCurDisplayPath(filename)
|
2014-11-25 16:59:29 +01:00
|
|
|
|
2014-11-30 19:05:17 +01:00
|
|
|
page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', []))
|
2014-11-25 16:59:29 +01:00
|
|
|
table = DisplayHTMLBlockTable('Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
|
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:
|
2014-11-26 16:17:16 +01:00
|
|
|
address = super_hit['remote_addr']
|
2014-11-27 09:01:51 +01:00
|
|
|
if display_visitor_ip and\
|
2014-11-26 16:17:16 +01:00
|
|
|
super_hit.get('dns_name_replaced', False):
|
|
|
|
address = '%s [%s]' % (address, super_hit['remote_ip'])
|
|
|
|
|
2014-11-25 16:59:29 +01:00
|
|
|
row = [
|
2014-11-26 16:17:16 +01:00
|
|
|
address,
|
2014-11-25 16:59:29 +01:00
|
|
|
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)
|
|
|
|
|
2014-11-26 20:31:13 +01:00
|
|
|
index = self.iwla.getDisplayIndex()
|
2014-11-27 19:38:41 +01:00
|
|
|
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)
|