/usr/share/cherokee/admin/Graph.py is in cherokee-admin 1.2.101-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | # -*- coding: utf-8 -*-
#
# Cherokee-admin
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
# Taher Shihadeh <taher@octality.com>
#
# Copyright (C) 2001-2011 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
import CTK
import Cherokee
import validations
from util import *
from consts import *
from configured import *
URL_APPLY = '/graph/apply'
GRAPH_VSERVER = '/graphs/%(prefix)s_%(type)s_%(vserver)s_%(interval)s.png'
GRAPH_SERVER = '/graphs/%(prefix)s_%(type)s_%(interval)s.png'
GRAPH_TYPES = [('traffic', N_('Server Traffic')),
('accepts', N_('Connections / Requests')),
('timeouts', N_('Connection Timeouts')),]
GRAPH_INTERVALS = [('1h', N_('1 Hour')),
('6h', N_('6 Hours')),
('1d', N_('1 Day')),
('1w', N_('1 Week')),
('1m', N_('1 Month'))]
URL_RRD = '/general#Network-1'
RRD_NOTICE = N_('You need to enable the <a href="%s">Information Collector</a> setting in order to render usage graphics.')
NOTE_COLLECTOR = N_('Whether or not it should collect statistics about the traffic of this virtual server.')
UPDATE_JS = """
function updateGraph() {
var timeout = $(window).data('graph-timeout');
if ((timeout != null) &&
(timeout != undefined))
{
clearTimeout (timeout);
$(window).data('graph-timeout', null);
}
%s
}
var tmp = setTimeout (updateGraph, 60000);
$(window).data('graph-timeout', tmp);
""" #%(JS_to_refresh)
def apply ():
graph_type = CTK.post.get_val('graph_type')
if graph_type:
CTK.cfg['tmp!graph_type'] = graph_type
return CTK.cfg_reply_ajax_ok()
# Modifications
return CTK.cfg_apply_post()
class Graph (CTK.Box):
def __init__ (self, refreshable, **kwargs):
CTK.Box.__init__ (self)
self.graph = {}
self.graph['type'], self.graph['type_txt'] = GRAPH_TYPES[0]
self.refresh = refreshable
def build_graph (self):
if CTK.cfg.get_val('server!collector') != 'rrd':
notice = CTK.Notice()
notice += CTK.RawHTML(_(RRD_NOTICE)%(URL_RRD))
self += CTK.Indenter(notice)
return False
tabs = CTK.Tab ()
for x in GRAPH_INTERVALS:
self.graph['interval'] = x[0]
props = {'src': self.template % self.graph,
'alt': '%s: %s' %(self.graph['type_txt'], x[1])}
image = CTK.Image(props)
tabs.Add (_(x[1]), image)
self += tabs
return True
def Render (self):
render = CTK.Box.Render (self)
render.js += UPDATE_JS % (self.refresh.JS_to_refresh())
return render
class GraphVServer_Instancer (CTK.Container):
class GraphVServer (Graph):
def __init__ (self, refreshable, vsrv_num, **kwargs):
Graph.__init__ (self, refreshable, **kwargs)
self.template = GRAPH_VSERVER
self.graph['prefix'] = 'vserver'
self.graph['vserver'] = CTK.cfg.get_val ("vserver!%s!nick" %(vsrv_num), _("Unknown"))
self.graph['num'] = vsrv_num
self.collector = bool(int(CTK.cfg.get_val ('vserver!%s!collector!enabled'%(vsrv_num),'0')))
self.build()
def build (self):
table = CTK.PropsTable()
table.Add (_('Collect Statistics'), CTK.CheckCfgText('vserver!%s!collector!enabled'%(self.graph['num']), self.collector, _('Enabled')), _(NOTE_COLLECTOR))
submit = CTK.Submitter (URL_APPLY)
submit += table
submit.bind('submit_success', self.refresh.JS_to_refresh())
if self.collector:
self.build_graph ()
props = {'class': 'graph_props_bottom'}
else:
props = {'class': 'graph_props_top'}
if CTK.cfg.get_val('server!collector') == 'rrd':
self += CTK.Indenter (CTK.Box(props, submit))
def __init__ (self, vserver):
CTK.Container.__init__ (self)
# Refresher
refresh = CTK.Refreshable ({'id': 'grapharea'})
refresh.register (lambda: self.GraphVServer(refresh, vserver).Render())
self += refresh
class GraphServer_Instancer (CTK.Container):
class GraphServer (Graph):
def __init__ (self, refreshable, **kwargs):
Graph.__init__ (self, refreshable, **kwargs)
self.template = GRAPH_SERVER
self.graph['prefix'] = 'server'
self.graph['type'] = CTK.cfg.get_val('tmp!graph_type', self.graph['type'])
self.build()
def build (self):
rrd = self.build_graph ()
if rrd:
props = {'class': 'graph_type', 'name': 'graph_type', 'selected': self.graph['type']}
combo = CTK.Combobox (props, trans_options(GRAPH_TYPES))
submit = CTK.Submitter (URL_APPLY)
submit += combo
submit.bind('submit_success', self.refresh.JS_to_refresh())
for x in GRAPH_TYPES:
if x[0] == self.graph['type']:
self.graph['type_txt'] = x[1]
self += submit
def __init__ (self):
CTK.Container.__init__ (self)
# Refresher
refresh = CTK.Refreshable ({'id': 'grapharea'})
refresh.register (lambda: self.GraphServer(refresh).Render())
self += refresh
CTK.publish ('^%s'%(URL_APPLY), apply, method="POST")
|