Display visitor IP is now a filter
This commit is contained in:
		@@ -70,7 +70,6 @@ class IWLADisplayFeeds(IPlugin):
 | 
				
			|||||||
            title = createCurTitle(self.iwla, self.iwla._(u'All Feeds parsers'))
 | 
					            title = createCurTitle(self.iwla, self.iwla._(u'All Feeds parsers'))
 | 
				
			||||||
            filename = 'all_feeds.html'
 | 
					            filename = 'all_feeds.html'
 | 
				
			||||||
            path = self.iwla.getCurDisplayPath(filename)
 | 
					            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', []))
 | 
					            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')])
 | 
					            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
 | 
					                    continue
 | 
				
			||||||
                nb_feeds_parsers += 1
 | 
					                nb_feeds_parsers += 1
 | 
				
			||||||
                address = super_hit['remote_addr']
 | 
					                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:
 | 
					                if super_hit['feed_parser'] == IWLAPostAnalysisFeeds.MERGED_FEED_PARSER:
 | 
				
			||||||
                    address += ' *'
 | 
					                    address += ' *'
 | 
				
			||||||
                pages = super_hit['not_viewed_pages'][0] + super_hit['viewed_pages'][0]
 | 
					                pages = super_hit['not_viewed_pages'][0] + super_hit['viewed_pages'][0]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,7 +33,6 @@ Plugin requirements :
 | 
				
			|||||||
    None
 | 
					    None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Conf values needed :
 | 
					Conf values needed :
 | 
				
			||||||
    display_visitor_ip*
 | 
					 | 
				
			||||||
    create_all_robot_bandwidth_page*
 | 
					    create_all_robot_bandwidth_page*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Output files :
 | 
					Output files :
 | 
				
			||||||
@@ -54,7 +53,6 @@ class IWLADisplayRobotBandwidth(IPlugin):
 | 
				
			|||||||
    def __init__(self, iwla):
 | 
					    def __init__(self, iwla):
 | 
				
			||||||
        super(IWLADisplayRobotBandwidth, self).__init__(iwla)
 | 
					        super(IWLADisplayRobotBandwidth, self).__init__(iwla)
 | 
				
			||||||
        self.API_VERSION = 1
 | 
					        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)
 | 
					        self.create_all_pages = self.iwla.getConfValue('create_all_robot_bandwidth_page', True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def load(self):
 | 
					    def load(self):
 | 
				
			||||||
@@ -93,10 +91,6 @@ class IWLADisplayRobotBandwidth(IPlugin):
 | 
				
			|||||||
            table.setColsCSSClass(['', 'iwla_bandwidth', '', ''])
 | 
					            table.setColsCSSClass(['', 'iwla_bandwidth', '', ''])
 | 
				
			||||||
            for (super_hit, bandwidth) in bandwidths:
 | 
					            for (super_hit, bandwidth) in bandwidths:
 | 
				
			||||||
                address = super_hit['remote_addr']
 | 
					                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 = [
 | 
					                row = [
 | 
				
			||||||
                    address,
 | 
					                    address,
 | 
				
			||||||
                    bandwidth,
 | 
					                    bandwidth,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										83
									
								
								plugins/display/visitor_ip.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								plugins/display/visitor_ip.py
									
									
									
									
									
										Normal file
									
								
							@@ -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 <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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()
 | 
				
			||||||
		Reference in New Issue
	
	Block a user