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-24 21:37:37 +01:00
|
|
|
import socket
|
2024-10-27 09:16:01 +01:00
|
|
|
import re
|
2014-11-24 21:37:37 +01:00
|
|
|
|
2014-11-21 16:57:37 +01:00
|
|
|
from iwla import IWLA
|
2014-11-24 17:13:59 +01:00
|
|
|
from iplugin import IPlugin
|
2014-11-21 16:57:37 +01:00
|
|
|
|
2014-12-19 11:34:25 +01:00
|
|
|
"""
|
2024-10-27 09:16:01 +01:00
|
|
|
Pre analysis hook
|
2014-12-19 11:34:25 +01:00
|
|
|
|
|
|
|
Replace IP by reverse DNS names
|
|
|
|
|
|
|
|
Plugin requirements :
|
|
|
|
None
|
|
|
|
|
|
|
|
Conf values needed :
|
2024-10-27 09:16:01 +01:00
|
|
|
robot_domains*
|
2014-12-19 11:34:25 +01:00
|
|
|
|
|
|
|
Output files :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics creation :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics update :
|
|
|
|
valid_visitors:
|
|
|
|
remote_addr
|
|
|
|
dns_name_replaced
|
|
|
|
dns_analyzed
|
|
|
|
|
|
|
|
Statistics deletion :
|
|
|
|
None
|
|
|
|
"""
|
2014-12-10 07:09:05 +01:00
|
|
|
|
2014-11-24 17:13:59 +01:00
|
|
|
class IWLAPostAnalysisReverseDNS(IPlugin):
|
2014-11-27 12:34:42 +01:00
|
|
|
|
2014-11-24 21:37:37 +01:00
|
|
|
def load(self):
|
2024-10-27 09:16:01 +01:00
|
|
|
self.robot_domains_re = []
|
|
|
|
robot_domains = self.iwla.getConfValue('robot_domains', [])
|
|
|
|
for domain in robot_domains:
|
|
|
|
self.robot_domains_re.append(re.compile(domain))
|
|
|
|
|
2014-11-24 21:37:37 +01:00
|
|
|
return True
|
|
|
|
|
2014-11-26 20:31:13 +01:00
|
|
|
def hook(self):
|
2016-02-04 20:44:36 +01:00
|
|
|
hits = self.iwla.getCurrentVisits()
|
2014-11-24 17:13:59 +01:00
|
|
|
for (k, hit) in hits.items():
|
|
|
|
if hit.get('dns_analysed', False): continue
|
2023-03-11 20:51:44 +01:00
|
|
|
# Do reverse for feed parser even if they're not
|
|
|
|
# valid visitors
|
2024-10-27 09:16:01 +01:00
|
|
|
if hit.get('robot', False) and not hit.get('feed_parser', False):
|
2016-01-18 07:33:48 +01:00
|
|
|
continue
|
2024-10-27 09:16:01 +01:00
|
|
|
|
|
|
|
res = self.iwla.reverseDNS(hit)
|
|
|
|
|
|
|
|
for r in self.robot_domains_re:
|
|
|
|
if r.match(hit['remote_addr']):
|
|
|
|
hit['robot'] = True
|
|
|
|
break
|
2014-11-21 16:57:37 +01:00
|
|
|
|