Add all_visits plugin
This commit is contained in:
parent
7405cf237a
commit
6505ca3ee5
2
conf.py
2
conf.py
|
@ -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/$']
|
||||||
|
|
14
display.py
14
display.py
|
@ -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):
|
||||||
|
|
3
iwla.py
3
iwla.py
|
@ -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
|
||||||
|
|
41
plugins/display/all_visits.py
Normal file
41
plugins/display/all_visits.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user