2015-02-17 19:11:04 +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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
from iwla import IWLA
|
|
|
|
from iplugin import IPlugin
|
|
|
|
from display import *
|
|
|
|
|
|
|
|
"""
|
|
|
|
Display hook
|
|
|
|
|
|
|
|
Display feeds parsers
|
|
|
|
|
|
|
|
Plugin requirements :
|
2015-03-02 19:46:08 +01:00
|
|
|
post_analysis/feeds
|
2015-02-17 19:11:04 +01:00
|
|
|
|
|
|
|
Conf values needed :
|
|
|
|
create_all_feeds_page*
|
|
|
|
|
|
|
|
Output files :
|
|
|
|
OUTPUT_ROOT/year/month/index.html
|
|
|
|
OUTPUT_ROOT/year/month/all_feeds.html
|
|
|
|
|
|
|
|
Statistics creation :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics update :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics deletion :
|
|
|
|
None
|
|
|
|
"""
|
|
|
|
|
|
|
|
class IWLADisplayFeeds(IPlugin):
|
|
|
|
def __init__(self, iwla):
|
|
|
|
super(IWLADisplayFeeds, self).__init__(iwla)
|
|
|
|
self.API_VERSION = 1
|
|
|
|
self.requires = ['IWLAPostAnalysisFeeds']
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
self.create_all_feeds_page = self.iwla.getConfValue('create_all_feeds_page', True)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def hook(self):
|
2015-04-06 17:54:44 +02:00
|
|
|
from plugins.post_analysis.feeds import IWLAPostAnalysisFeeds
|
|
|
|
|
2015-02-17 19:11:04 +01:00
|
|
|
display = self.iwla.getDisplay()
|
2016-02-04 20:44:36 +01:00
|
|
|
hits = self.iwla.getCurrentVisits()
|
2015-02-17 19:11:04 +01:00
|
|
|
nb_feeds_parsers = 0
|
|
|
|
|
|
|
|
# All in a page
|
|
|
|
if self.create_all_feeds_page:
|
2015-02-18 20:32:04 +01:00
|
|
|
title = createCurTitle(self.iwla, self.iwla._(u'All Feeds parsers'))
|
2015-02-17 19:11:04 +01:00
|
|
|
filename = 'all_feeds.html'
|
|
|
|
path = self.iwla.getCurDisplayPath(filename)
|
|
|
|
|
|
|
|
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
|
2024-07-28 09:25:06 +02:00
|
|
|
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'Domain'), self.iwla._(u'Subscribers'), self.iwla._(u'Last Access')])
|
|
|
|
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', '', '', ''])
|
|
|
|
rows = []
|
2015-02-17 19:11:04 +01:00
|
|
|
for super_hit in hits.values():
|
2024-07-28 09:25:06 +02:00
|
|
|
if super_hit.get('feed_parser', None) not in (IWLAPostAnalysisFeeds.FEED_PARSER,\
|
|
|
|
IWLAPostAnalysisFeeds.MERGED_FEED_PARSER):
|
2016-08-20 13:08:02 +02:00
|
|
|
continue
|
2015-02-17 19:11:04 +01:00
|
|
|
nb_feeds_parsers += 1
|
|
|
|
address = super_hit['remote_addr']
|
2015-02-18 20:56:03 +01:00
|
|
|
if super_hit['feed_parser'] == IWLAPostAnalysisFeeds.MERGED_FEED_PARSER:
|
2023-01-28 09:35:48 +01:00
|
|
|
address += ' *'
|
2022-11-16 21:09:23 +01:00
|
|
|
pages = super_hit['not_viewed_pages'][0] + super_hit['viewed_pages'][0]
|
|
|
|
hits = super_hit['not_viewed_hits'][0] + super_hit['viewed_hits'][0]
|
2024-07-28 09:25:06 +02:00
|
|
|
last_access = super_hit.get('feed_parser_last_access', super_hit['last_access'])
|
|
|
|
feed_domain = super_hit.get('feed_domain', '')
|
|
|
|
if feed_domain:
|
|
|
|
link = '<a href=\'https://%s/%s\'>%s</a>' % (feed_domain, super_hit.get('feed_uri', ''), feed_domain)
|
|
|
|
else:
|
|
|
|
link = ''
|
|
|
|
subscribers = super_hit.get('feed_subscribers', '')
|
|
|
|
# Don't overload interface
|
|
|
|
if subscribers <= 1: subscribers = ''
|
|
|
|
row = [address, pages, hits, link, subscribers, time.asctime(last_access),
|
|
|
|
super_hit['remote_ip'], last_access]
|
|
|
|
rows.append(row)
|
|
|
|
rows = sorted(rows, key=lambda t: t[7], reverse=True)
|
|
|
|
for row in rows:
|
|
|
|
table.appendRow(row[:6], row[6])
|
2015-02-17 19:11:04 +01:00
|
|
|
page.appendBlock(table)
|
2015-04-06 17:54:44 +02:00
|
|
|
note = DisplayHTMLRaw(self.iwla, ('<small>*%s</small>' % (self.iwla._(u'Merged feeds parsers'))))
|
2015-02-18 20:56:03 +01:00
|
|
|
page.appendBlock(note)
|
2015-02-17 19:11:04 +01:00
|
|
|
display.addPage(page)
|
|
|
|
|
|
|
|
# Found in index
|
|
|
|
title = self.iwla._(u'Feeds parsers')
|
|
|
|
if self.create_all_feeds_page:
|
|
|
|
link = '<a href=\'%s\'>%s</a>' % (filename, self.iwla._(u'Details'))
|
|
|
|
title = '%s - %s' % (title, link)
|
|
|
|
|
|
|
|
index = self.iwla.getDisplayIndex()
|
|
|
|
|
|
|
|
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Found')])
|
|
|
|
table.appendRow([nb_feeds_parsers])
|
|
|
|
index.appendBlock(table)
|