diff --git a/plugins/display/feeds.py b/plugins/display/feeds.py index 8e66ce4..d6960c9 100644 --- a/plugins/display/feeds.py +++ b/plugins/display/feeds.py @@ -70,7 +70,6 @@ class IWLADisplayFeeds(IPlugin): title = createCurTitle(self.iwla, self.iwla._(u'All Feeds parsers')) filename = 'all_feeds.html' path = self.iwla.getCurDisplayPath(filename) - display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False) page = display.createPage(title, path, self.iwla.getConfValue('css_path', [])) table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'All feeds parsers'), [self.iwla._(u'Host'), self.iwla._(u'Pages'), self.iwla._(u'Hits'), self.iwla._(u'Last Access')]) @@ -81,9 +80,6 @@ class IWLADisplayFeeds(IPlugin): continue nb_feeds_parsers += 1 address = super_hit['remote_addr'] - if display_visitor_ip and\ - super_hit.get('dns_name_replaced', False): - address = '%s [%s]' % (address, super_hit['remote_ip']) if super_hit['feed_parser'] == IWLAPostAnalysisFeeds.MERGED_FEED_PARSER: address += ' *' pages = super_hit['not_viewed_pages'][0] + super_hit['viewed_pages'][0] diff --git a/plugins/display/robot_bandwidth.py b/plugins/display/robot_bandwidth.py index 65ea358..1c452cf 100644 --- a/plugins/display/robot_bandwidth.py +++ b/plugins/display/robot_bandwidth.py @@ -33,7 +33,6 @@ Plugin requirements : None Conf values needed : - display_visitor_ip* create_all_robot_bandwidth_page* Output files : @@ -54,7 +53,6 @@ class IWLADisplayRobotBandwidth(IPlugin): def __init__(self, iwla): super(IWLADisplayRobotBandwidth, self).__init__(iwla) self.API_VERSION = 1 - self.display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False) self.create_all_pages = self.iwla.getConfValue('create_all_robot_bandwidth_page', True) def load(self): @@ -93,10 +91,6 @@ class IWLADisplayRobotBandwidth(IPlugin): table.setColsCSSClass(['', 'iwla_bandwidth', '', '']) for (super_hit, bandwidth) in bandwidths: address = super_hit['remote_addr'] - if self.display_visitor_ip and\ - super_hit.get('dns_name_replaced', False): - address = '%s [%s]' % (address, super_hit['remote_ip']) - row = [ address, bandwidth, diff --git a/plugins/display/visitor_ip.py b/plugins/display/visitor_ip.py new file mode 100644 index 0000000..86cc6d0 --- /dev/null +++ b/plugins/display/visitor_ip.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +# +# Copyright Grégory Soutadé 2023 + +# 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 . +# + +from ipaddress import ip_address + +from iwla import IWLA +from iplugin import IPlugin +from display import * + +""" +Display hook + +Display IP below visitor name + +Plugin requirements : + None + +Conf values needed : + compact_ip* + +Output files : + OUTPUT_ROOT/year/month/index.html + +Statistics creation : + None + +Statistics update : + None + +Statistics deletion : + None +""" + +class IWLADisplayVisitorIP(IPlugin): + def load(self): + display = self.iwla.getDisplay() + display.addColumnFilter(self.iwla._(u'Host'), self.IPFilter, {'self':self}) + + self.compact_ip = self.iwla.getConfValue('compact_ip', False) + + return True + + def processIP(self, host_name, ip): + host_name = host_name.replace(ip, 'IP') + ip = ip.replace('.', '-') + ip = ip.replace(':', '-') + host_name = host_name.replace(ip, 'IP') + ip = ip.replace('-', '') + host_name = host_name.replace(ip, 'IP') + + return host_name + + @staticmethod # Needed to have unbound method + def IPFilter(host, remote_ip, self): + if remote_ip is None or not remote_ip in self.visitors.keys(): return None + visitor = self.visitors[remote_ip] + if remote_ip == visitor['remote_addr']: return None + host_name = host + if self.compact_ip: + host_name = self.processIP(host_name, visitor['remote_ip']) + host_name = self.processIP(host_name, + ip_address(visitor['remote_ip']).exploded) + return '%s [%s]' % (host_name, visitor['remote_ip']) + + def hook(self): + self.visitors = self.iwla.getCurrentVisits()