Add all_visits plugin

This commit is contained in:
Grégory Soutadé 2014-11-25 16:59:29 +01:00
parent 7405cf237a
commit 6505ca3ee5
4 changed files with 58 additions and 2 deletions

View File

@ -13,7 +13,7 @@ DISPLAY_ROOT = './output/'
pre_analysis_hooks = ['page_to_hit', 'robots'] pre_analysis_hooks = ['page_to_hit', 'robots']
post_analysis_hooks = ['top_visitors', 'reverse_dns'] post_analysis_hooks = ['top_visitors', 'reverse_dns']
display_hooks = ['top_visitors'] display_hooks = ['top_visitors', 'all_visits']
reverse_dns_timeout = 0.2 reverse_dns_timeout = 0.2
page_to_hit_conf = [r'^.+/logo/$'] page_to_hit_conf = [r'^.+/logo/$']

View File

@ -1,12 +1,24 @@
class DisplayHTMLBlock(object): class DisplayHTMLBlock(object):
def __init__(self, title): def __init__(self, title=''):
self.title = title self.title = title
def build(self, f): def build(self, f):
pass pass
class DisplayHTMLRawBlock(DisplayHTMLBlock):
def __init__(self, title=''):
super(DisplayHTMLRawBlock, self).__init__(title)
self.html = ''
def setRawHTML(self, html):
self.html = html
def build(self, f):
f.write(self.html)
class DisplayHTMLBlockTable(DisplayHTMLBlock): class DisplayHTMLBlockTable(DisplayHTMLBlock):
def __init__(self, title, cols): def __init__(self, title, cols):

View File

@ -69,6 +69,9 @@ class IWLA(object):
def getDisplay(self): def getDisplay(self):
return self.display return self.display
def getCurTime(self):
return self.meta_infos['last_time']
def _clearMeta(self): def _clearMeta(self):
self.meta_infos = { self.meta_infos = {
'last_time' : None 'last_time' : None

View File

@ -0,0 +1,41 @@
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, iwla):
hits = iwla.getValidVisitors()
last_access = sorted(hits.values(), key=lambda t: t['last_access'], reverse=True)
cur_time = self.iwla.getCurTime()
title = time.strftime('All visits %B %Y', cur_time)
filename = 'all_visits_%d.html' % (cur_time.tm_mon)
path = '%d/%s' % (cur_time.tm_year, filename)
page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
for super_hit in last_access:
row = [
super_hit['remote_addr'],
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 = iwla.getDisplayIndex()
block = DisplayHTMLRawBlock()
block.setRawHTML('<a href=\'%s\'>All visits</a>' % (filename))
index.appendBlock(block)