iwla/plugins/pre_analysis/page_to_hit.py

42 lines
1.3 KiB
Python
Raw Normal View History

2014-11-25 16:22:07 +01:00
import re
2014-11-26 19:53:00 +01:00
import time
2014-11-25 16:22:07 +01:00
from iwla import IWLA
from iplugin import IPlugin
# Basic rule to detect robots
class IWLAPreAnalysisPageToHit(IPlugin):
def __init__(self, iwla):
super(IWLAPreAnalysisPageToHit, self).__init__(iwla)
self.API_VERSION = 1
def load(self):
# Remove logo from indefero
self.regexps = self.iwla.getConfValue('page_to_hit_conf', [])
if not self.regexps: return False
self.regexps = map(lambda(r): re.compile(r), self.regexps)
return True
def hook(self):
2014-11-26 19:53:00 +01:00
start_time = self.iwla.getStartAnalysisTime()
start_time = time.mktime(start_time)
2014-11-25 16:22:07 +01:00
hits = self.iwla.getCurrentVisists()
2014-11-26 19:53:00 +01:00
viewed_http_codes = self.iwla.getConfValue('viewed_http_codes', [200, 304])
2014-11-25 16:22:07 +01:00
for (k, super_hit) in hits.items():
if super_hit['robot']: continue
for p in super_hit['requests']:
if not p['is_page']: continue
2014-11-26 19:53:00 +01:00
if time.mktime(p['time_decoded']) < start_time: continue
2014-11-25 16:22:07 +01:00
uri = p['extract_request']['extract_uri']
for r in self.regexps:
if r.match(uri):
p['is_page'] = False
super_hit['viewed_pages'] -= 1
super_hit['viewed_hits'] += 1
break