2015-01-13 18:57:26 +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 *
|
|
|
|
|
|
|
|
import awstats_data
|
|
|
|
|
|
|
|
"""
|
|
|
|
Display hook
|
|
|
|
|
|
|
|
Track users
|
|
|
|
|
|
|
|
Plugin requirements :
|
|
|
|
None
|
|
|
|
|
|
|
|
Conf values needed :
|
|
|
|
tracked_ip
|
|
|
|
create_tracked_page*
|
|
|
|
|
|
|
|
Output files :
|
|
|
|
OUTPUT_ROOT/year/month/index.html
|
|
|
|
OUTPUT_ROOT/year/month/tracked_users.html
|
|
|
|
|
|
|
|
Statistics creation :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics update :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics deletion :
|
|
|
|
None
|
|
|
|
"""
|
|
|
|
|
|
|
|
class IWLADisplayTrackUsers(IPlugin):
|
|
|
|
def __init__(self, iwla):
|
|
|
|
super(IWLADisplayTrackUsers, self).__init__(iwla)
|
|
|
|
self.API_VERSION = 1
|
|
|
|
self.conf_requires = ['tracked_ip']
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
self.create_tracked_page = self.iwla.getConfValue('create_tracked_page', True)
|
|
|
|
self.tracked_ip = self.iwla.getConfValue('tracked_ip', [])
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def hook(self):
|
|
|
|
display = self.iwla.getDisplay()
|
|
|
|
hits = self.iwla.getCurrentVisists()
|
2015-02-07 15:28:24 +01:00
|
|
|
stats = {}
|
2015-01-13 18:57:26 +01:00
|
|
|
|
|
|
|
# All in a page
|
|
|
|
if self.create_tracked_page:
|
|
|
|
title = createCurTitle(self.iwla, u'Tracked users')
|
|
|
|
filename = 'tracked_users.html'
|
|
|
|
path = self.iwla.getCurDisplayPath(filename)
|
|
|
|
|
|
|
|
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
|
2015-03-02 18:32:15 +01:00
|
|
|
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Tracked users'), [self.iwla._(u'Pages'), self.iwla._(u'Last Access')])
|
|
|
|
table.setColsCSSClass(['iwla_page', ''])
|
2015-01-13 18:57:26 +01:00
|
|
|
for ip in self.tracked_ip:
|
|
|
|
if not ip in hits.keys(): continue
|
|
|
|
if 'dns_name_replaced' in hits[ip].keys():
|
2015-01-14 20:19:19 +01:00
|
|
|
ip_title = '<b>%s [%s]</b>' % (hits[ip]['remote_addr'], ip)
|
2015-01-13 18:57:26 +01:00
|
|
|
else:
|
|
|
|
ip_title = '<b>%s</b>' % (ip)
|
|
|
|
table.appendRow([ip_title, ''])
|
2015-02-07 15:28:24 +01:00
|
|
|
nb_hits = 0
|
|
|
|
nb_pages = 0
|
2015-01-13 18:57:26 +01:00
|
|
|
for r in hits[ip]['requests'][::-1]:
|
|
|
|
uri = r['extract_request']['extract_uri'].lower()
|
2015-02-07 15:28:24 +01:00
|
|
|
if not self.iwla.hasBeenViewed(r): continue
|
2015-01-13 18:57:26 +01:00
|
|
|
if not self.iwla.isPage(uri) or\
|
2015-02-07 15:28:24 +01:00
|
|
|
self.iwla.isMultimediaFile(uri):
|
|
|
|
nb_hits += 1
|
2015-01-13 18:57:26 +01:00
|
|
|
continue
|
|
|
|
|
2015-02-07 15:28:24 +01:00
|
|
|
nb_pages += 1
|
2015-01-13 18:57:26 +01:00
|
|
|
uri = "%s%s" % (r.get('server_name', ''),
|
|
|
|
r['extract_request']['extract_uri'])
|
|
|
|
table.appendRow([generateHTMLLink(uri), time.asctime(r['time_decoded'])])
|
2015-02-07 15:28:24 +01:00
|
|
|
stats[ip] = (nb_pages, nb_hits)
|
2015-01-13 18:57:26 +01:00
|
|
|
page.appendBlock(table)
|
|
|
|
|
|
|
|
display.addPage(page)
|
|
|
|
|
|
|
|
# Last access in index
|
|
|
|
title = self.iwla._(u'Tracked users')
|
|
|
|
if self.create_tracked_page:
|
|
|
|
link = '<a href=\'%s\'>%s</a>' % (filename, self.iwla._(u'Details'))
|
|
|
|
title = '%s - %s' % (title, link)
|
|
|
|
|
|
|
|
index = self.iwla.getDisplayIndex()
|
|
|
|
|
2015-02-07 15:28:24 +01:00
|
|
|
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'IP'), self.iwla._(u'Last Access'), self.iwla._(u'Pages'), self.iwla._(u'Hits')])
|
2015-03-02 18:32:15 +01:00
|
|
|
table.setColsCSSClass(['', '', 'iwla_page', 'iwla_hit'])
|
2015-01-13 18:57:26 +01:00
|
|
|
for ip in self.tracked_ip:
|
|
|
|
if not ip in hits.keys(): continue
|
|
|
|
if 'dns_name_replaced' in hits[ip].keys():
|
2015-01-14 20:19:19 +01:00
|
|
|
ip_title = '%s [%s]' % (hits[ip]['remote_addr'], ip)
|
|
|
|
else:
|
|
|
|
ip_title = ip
|
2015-02-07 15:28:24 +01:00
|
|
|
table.appendRow([ip_title, time.asctime(hits[ip]['last_access']), stats[ip][0], stats[ip][1]])
|
2015-01-13 18:57:26 +01:00
|
|
|
index.appendBlock(table)
|