iwla

iwla Commit Details

Date:2015-01-13 18:57:26 (6 years 6 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:511ca4939798a6ae11f455053bb1aaa67fe7aa2f
Parents: 616b0d80527bc0c3ab2bb799c7c8fb3e66be3afa
Message:Add track users plugin

Changes:
Aplugins/display/track_users.py (full)

File differences

plugins/display/track_users.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- 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()
# 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', []))
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Tracked users'), [self.iwla._(u'Page'), self.iwla._(u'Last Access')])
for ip in self.tracked_ip:
if not ip in hits.keys(): continue
if 'dns_name_replaced' in hits[ip].keys():
ip_title = '<b>%s [%s]</b>' % (ip, hits[ip][remote_addr])
else:
ip_title = '<b>%s</b>' % (ip)
table.appendRow([ip_title, ''])
for r in hits[ip]['requests'][::-1]:
uri = r['extract_request']['extract_uri'].lower()
if not self.iwla.isPage(uri) or\
self.iwla.isMultimediaFile(uri) or\
not self.iwla.hasBeenViewed(r):
continue
uri = "%s%s" % (r.get('server_name', ''),
r['extract_request']['extract_uri'])
table.appendRow([generateHTMLLink(uri), time.asctime(r['time_decoded'])])
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()
table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'IP'), self.iwla._(u'Last Access')])
for ip in self.tracked_ip:
if not ip in hits.keys(): continue
if 'dns_name_replaced' in hits[ip].keys():
ip = '%s [%s]' % (ip, hits[ip][remote_addr])
table.appendRow([ip, time.asctime(hits[ip]['last_access'])])
index.appendBlock(table)

Archive Download the corresponding diff file

Branches

Tags