2015-01-08 21:01:33 +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
|
|
|
|
|
|
|
|
Create browsers page
|
|
|
|
|
|
|
|
Plugin requirements :
|
|
|
|
post_analysis/browsers
|
|
|
|
|
|
|
|
Conf values needed :
|
|
|
|
max_browsers_displayed*
|
|
|
|
create_browsers_page*
|
|
|
|
|
|
|
|
Output files :
|
|
|
|
OUTPUT_ROOT/year/month/browsers.html
|
|
|
|
OUTPUT_ROOT/year/month/index.html
|
|
|
|
|
|
|
|
Statistics creation :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics update :
|
|
|
|
None
|
|
|
|
|
|
|
|
Statistics deletion :
|
|
|
|
None
|
|
|
|
"""
|
|
|
|
|
2023-03-23 21:16:54 +01:00
|
|
|
browser_icons = {
|
|
|
|
'Android':'android',
|
|
|
|
'Android browser (PDA/Phone browser)':'android',
|
|
|
|
'iPhone':'pdaphone',
|
|
|
|
'IPhone (PDA/Phone browser)':'pdaphone',
|
|
|
|
'Edge':'edge',
|
|
|
|
'Chrome':'chrome',
|
|
|
|
'Safari':'safari',
|
|
|
|
'Firefox':'firefox',
|
|
|
|
'Mozilla':'mozilla',
|
2023-04-18 20:30:40 +02:00
|
|
|
'Internet Explorer':'msie',
|
|
|
|
'Opera':'opera',
|
2023-03-23 21:16:54 +01:00
|
|
|
}
|
|
|
|
|
2015-01-08 21:01:33 +01:00
|
|
|
class IWLADisplayBrowsers(IPlugin):
|
|
|
|
def __init__(self, iwla):
|
|
|
|
super(IWLADisplayBrowsers, self).__init__(iwla)
|
|
|
|
self.API_VERSION = 1
|
|
|
|
self.requires = ['IWLAPostAnalysisBrowsers']
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
self.icon_path = self.iwla.getConfValue('icon_path', '/')
|
|
|
|
self.max_browsers = self.iwla.getConfValue('max_browsers_displayed', 0)
|
|
|
|
self.create_browsers = self.iwla.getConfValue('create_browsers_page', True)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def hook(self):
|
|
|
|
display = self.iwla.getDisplay()
|
|
|
|
browsers = self.iwla.getMonthStats()['browsers']
|
|
|
|
browsers = sorted(browsers.items(), key=lambda t: t[1], reverse=True)
|
|
|
|
|
|
|
|
# All in a file
|
|
|
|
if self.create_browsers:
|
|
|
|
title = createCurTitle(self.iwla, u'Browsers')
|
|
|
|
filename = 'browsers.html'
|
|
|
|
path = self.iwla.getCurDisplayPath(filename)
|
|
|
|
|
|
|
|
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
|
|
|
|
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Browsers'), ['', self.iwla._(u'Browser'), self.iwla._(u'Entrance')])
|
|
|
|
table.setColsCSSClass(['', '', 'iwla_hit'])
|
|
|
|
total_browsers = [0]*3
|
|
|
|
new_list = self.max_browsers and browsers[:self.max_browsers] or browsers
|
|
|
|
for (browser, entrance) in new_list:
|
2023-03-23 21:16:54 +01:00
|
|
|
if browser in browser_icons.keys():
|
|
|
|
name = browser_icons[browser]
|
|
|
|
icon = f'<img alt="{browser} icon" src="/{self.icon_path}/browser/{name}.png"/>'
|
2015-01-08 21:01:33 +01:00
|
|
|
else:
|
2023-03-23 21:16:54 +01:00
|
|
|
icon = f'<img alt="Unknown browser icon" src="/{self.icon_path}/browser/unknown.png"/>'
|
|
|
|
browser = self.iwla._(browser)
|
2015-01-08 21:01:33 +01:00
|
|
|
table.appendRow([icon, browser, entrance])
|
2015-01-11 18:06:18 +01:00
|
|
|
total_browsers[2] += entrance
|
2015-01-08 21:01:33 +01:00
|
|
|
if self.max_browsers:
|
|
|
|
others = 0
|
|
|
|
for (browser, entrance) in browsers[self.max_browsers:]:
|
|
|
|
others += entrance
|
|
|
|
table.appendRow(['', self.iwla._(u'Others'), others])
|
|
|
|
table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')
|
|
|
|
|
|
|
|
page.appendBlock(table)
|
|
|
|
|
|
|
|
display.addPage(page)
|
|
|
|
|
2015-04-08 14:04:59 +02:00
|
|
|
title = self.iwla._(u'Top Browsers')
|
2015-01-08 21:01:33 +01:00
|
|
|
if self.create_browsers:
|
|
|
|
link = '<a href=\'%s\'>%s</a>' % (filename, self.iwla._(u'All Browsers'))
|
|
|
|
title = '%s - %s' % (title, link)
|
|
|
|
|
|
|
|
# Top in index
|
|
|
|
index = self.iwla.getDisplayIndex()
|
|
|
|
|
|
|
|
table = display.createBlock(DisplayHTMLBlockTable, title, ['', self.iwla._(u'Browser'), self.iwla._(u'Entrance')])
|
|
|
|
table.setColsCSSClass(['', '', 'iwla_hit'])
|
|
|
|
for (browser, entrance) in browsers[:10]:
|
2023-03-23 21:16:54 +01:00
|
|
|
if browser in browser_icons.keys():
|
|
|
|
name = browser_icons[browser]
|
|
|
|
icon = f'<img alt="{browser} icon" src="/{self.icon_path}/browser/{name}.png"/>'
|
2015-01-08 21:01:33 +01:00
|
|
|
else:
|
2023-03-23 21:16:54 +01:00
|
|
|
icon = f'<img alt="Unknown browser icon" src="/{self.icon_path}/browser/unknown.png"/>'
|
|
|
|
browser = self.iwla._(browser)
|
2015-01-08 21:01:33 +01:00
|
|
|
table.appendRow([icon, browser, entrance])
|
2015-01-11 18:06:18 +01:00
|
|
|
total_browsers[2] -= entrance
|
|
|
|
if total_browsers[2]:
|
|
|
|
total_browsers[0] = u''
|
|
|
|
total_browsers[1] = self.iwla._(u'Others')
|
2015-01-08 21:01:33 +01:00
|
|
|
table.appendRow(total_browsers)
|
|
|
|
table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')
|
2015-01-13 18:55:46 +01:00
|
|
|
table.computeRatio(2)
|
2015-01-08 21:01:33 +01:00
|
|
|
index.appendBlock(table)
|