86 lines
2.2 KiB
Python
86 lines
2.2 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
# Copyright Grégory Soutadé 2022
|
||
|
|
||
|
# 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 iwla import IWLA
|
||
|
from iplugin import IPlugin
|
||
|
from display import *
|
||
|
import logging
|
||
|
import re
|
||
|
|
||
|
"""
|
||
|
Display hook
|
||
|
|
||
|
Enlight users in all visits page if visitor['enlight'] property is True
|
||
|
or user is filtered
|
||
|
Can be set in filter users callback
|
||
|
|
||
|
Plugin requirements :
|
||
|
IWLADisplayAllVisits
|
||
|
|
||
|
Conf values needed :
|
||
|
None
|
||
|
|
||
|
Output files :
|
||
|
None
|
||
|
|
||
|
Statistics creation :
|
||
|
None
|
||
|
|
||
|
Statistics update :
|
||
|
None
|
||
|
|
||
|
Statistics deletion :
|
||
|
None
|
||
|
"""
|
||
|
|
||
|
class IWLADisplayAllVisitsEnlight(IPlugin):
|
||
|
def load(self):
|
||
|
self.ip_re = re.compile(r'.*\[(.*)\].*')
|
||
|
return True
|
||
|
|
||
|
def hook(self):
|
||
|
display = self.iwla.getDisplay()
|
||
|
visitors = self.iwla.getValidVisitors()
|
||
|
|
||
|
path = self.iwla.getCurDisplayPath('all_visits.html')
|
||
|
page = display.getPage(path)
|
||
|
if not page:
|
||
|
self.logger.error('No page for %s' % (path))
|
||
|
return
|
||
|
title = self.iwla._('All visits')
|
||
|
block = page.getBlock(title)
|
||
|
if not block:
|
||
|
self.logger.error('Block %s not found' % (title))
|
||
|
return
|
||
|
|
||
|
for (idx, row) in enumerate(block.rows):
|
||
|
# Direct IP
|
||
|
ip = row[0]
|
||
|
if not ip in visitors.keys():
|
||
|
# name [IP]
|
||
|
ip = self.ip_re.match(row[0])
|
||
|
if not ip: continue
|
||
|
ip = ip[1]
|
||
|
if not ip in visitors.keys():
|
||
|
continue
|
||
|
if visitors[ip].get('enlight', False) or\
|
||
|
visitors[ip].get('filtered', False):
|
||
|
block.setCellCSSClass(idx, 0, 'iwla_enlight')
|