2014-12-18 19:54:31 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright Grégory Soutadé 2015
|
|
|
|
|
|
|
|
# This file is part of iwla
|
|
|
|
|
|
|
|
# iwla is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# iwla is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with iwla. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2014-11-25 16:22:07 +01:00
|
|
|
import re
|
2015-05-22 07:51:11 +02:00
|
|
|
import logging
|
2014-11-25 16:22:07 +01:00
|
|
|
|
|
|
|
from iwla import IWLA
|
|
|
|
from iplugin import IPlugin
|
|
|
|
|
2014-12-19 11:34:25 +01:00
|
|
|
"""
|
|
|
|
Pre analysis hook
|
|
|
|
Change page into hit and hit into page into statistics
|
|
|
|
|
|
|
|
Plugin requirements :
|
|
|
|
None
|
|
|
|
|
|
|
|
Conf values needed :
|
|
|
|
page_to_hit_conf*
|
|
|
|
hit_to_page_conf*
|
|
|
|
|
|
|
|
Output files :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics creation :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics update :
|
|
|
|
visits :
|
|
|
|
remote_addr =>
|
|
|
|
is_page
|
|
|
|
|
|
|
|
Statistics deletion :
|
|
|
|
None
|
|
|
|
"""
|
2014-11-25 16:22:07 +01:00
|
|
|
|
|
|
|
class IWLAPreAnalysisPageToHit(IPlugin):
|
|
|
|
|
|
|
|
def __init__(self, iwla):
|
|
|
|
super(IWLAPreAnalysisPageToHit, self).__init__(iwla)
|
|
|
|
self.API_VERSION = 1
|
|
|
|
|
|
|
|
def load(self):
|
2014-11-27 13:46:58 +01:00
|
|
|
# Page to hit
|
|
|
|
self.ph_regexps = self.iwla.getConfValue('page_to_hit_conf', [])
|
|
|
|
self.ph_regexps = map(lambda(r): re.compile(r), self.ph_regexps)
|
|
|
|
|
|
|
|
# Hit to page
|
|
|
|
self.hp_regexps = self.iwla.getConfValue('hit_to_page_conf', [])
|
|
|
|
self.hp_regexps = map(lambda(r): re.compile(r), self.hp_regexps)
|
2014-11-25 16:22:07 +01:00
|
|
|
|
2015-05-22 07:51:11 +02:00
|
|
|
self.logger = logging.getLogger(self.__class__.__name__)
|
2014-11-25 16:22:07 +01:00
|
|
|
return True
|
|
|
|
|
2014-11-26 20:31:13 +01:00
|
|
|
def hook(self):
|
2016-02-06 14:45:09 +01:00
|
|
|
hits = self.iwla.getCurrentVisits()
|
2014-11-27 12:34:42 +01:00
|
|
|
|
2014-11-25 16:22:07 +01:00
|
|
|
for (k, super_hit) in hits.items():
|
|
|
|
if super_hit['robot']: continue
|
|
|
|
|
2014-12-14 15:10:13 +01:00
|
|
|
for request in super_hit['requests'][::-1]:
|
|
|
|
if not self.iwla.isValidForCurrentAnalysis(request):
|
|
|
|
break
|
|
|
|
|
|
|
|
if not self.iwla.hasBeenViewed(request):
|
2014-11-27 13:07:14 +01:00
|
|
|
continue
|
2014-11-27 13:46:58 +01:00
|
|
|
|
2014-11-27 09:01:51 +01:00
|
|
|
uri = request['extract_request']['extract_uri']
|
2014-11-27 13:46:58 +01:00
|
|
|
|
|
|
|
if request['is_page']:
|
|
|
|
# Page to hit
|
|
|
|
for regexp in self.ph_regexps:
|
|
|
|
if regexp.match(uri):
|
2015-05-22 07:51:11 +02:00
|
|
|
self.logger.debug('%s changed from page to hit' % (uri))
|
2014-11-27 13:46:58 +01:00
|
|
|
request['is_page'] = False
|
|
|
|
super_hit['viewed_pages'] -= 1
|
|
|
|
super_hit['viewed_hits'] += 1
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
# Hit to page
|
|
|
|
for regexp in self.hp_regexps:
|
|
|
|
if regexp.match(uri):
|
2015-05-22 07:51:11 +02:00
|
|
|
self.logger.debug('%s changed from hit to page' % (uri))
|
2014-11-27 13:46:58 +01:00
|
|
|
request['is_page'] = True
|
|
|
|
super_hit['viewed_pages'] += 1
|
|
|
|
super_hit['viewed_hits'] -= 1
|
|
|
|
break
|