Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 182 lines (146 sloc) 6.176 kb
ff20af9 @alobbs Adds the new admin
alobbs authored
1 # -*- coding: utf-8 -*-
2 #
3 # Cherokee-admin
4 #
5 # Authors:
6 # Alvaro Lopez Ortega <alvaro@alobbs.com>
5364b9c git-svn-id: svn://cherokee-project.com/cherokee/trunk@5147 5dc97367-97f1...
taher authored
7 # Taher Shihadeh <taher@octality.com>
ff20af9 @alobbs Adds the new admin
alobbs authored
8 #
920e20b @alobbs Happy new year!
alobbs authored
9 # Copyright (C) 2001-2011 Alvaro Lopez Ortega
ff20af9 @alobbs Adds the new admin
alobbs authored
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of version 2 of the GNU General Public
13 # License as published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 # 02110-1301, USA.
24 #
25
26 import CTK
27 import Cherokee
28 import validations
29
ceaf427 @alobbs Clean up: The constants file was definitely not the right place for a
alobbs authored
30 from util import *
ff20af9 @alobbs Adds the new admin
alobbs authored
31 from consts import *
32 from configured import *
33
34
35 URL_APPLY = '/graph/apply'
36
37 GRAPH_VSERVER = '/graphs/%(prefix)s_%(type)s_%(vserver)s_%(interval)s.png'
38 GRAPH_SERVER = '/graphs/%(prefix)s_%(type)s_%(interval)s.png'
39
40 GRAPH_TYPES = [('traffic', N_('Server Traffic')),
41 ('accepts', N_('Connections / Requests')),
42 ('timeouts', N_('Connection Timeouts')),]
43
44 GRAPH_INTERVALS = [('1h', N_('1 Hour')),
45 ('6h', N_('6 Hours')),
46 ('1d', N_('1 Day')),
47 ('1w', N_('1 Week')),
48 ('1m', N_('1 Month'))]
49
50 URL_RRD = '/general#Network-1'
71e2082 Gettext was having trouble with some rough edges
taher authored
51 RRD_NOTICE = N_('You need to enable the <a href="%s">Information Collector</a> setting in order to render usage graphics.')
ff20af9 @alobbs Adds the new admin
alobbs authored
52 NOTE_COLLECTOR = N_('Whether or not it should collect statistics about the traffic of this virtual server.')
53
54 UPDATE_JS = """
55 function updateGraph() {
56 var timeout = $(window).data('graph-timeout');
57
58 if ((timeout != null) &&
59 (timeout != undefined))
60 {
61 clearTimeout (timeout);
62 $(window).data('graph-timeout', null);
63 }
64
65 %s
66 }
67
68 var tmp = setTimeout (updateGraph, 60000);
69 $(window).data('graph-timeout', tmp);
70 """ #%(JS_to_refresh)
71
72 def apply ():
73 graph_type = CTK.post.get_val('graph_type')
74 if graph_type:
75 CTK.cfg['tmp!graph_type'] = graph_type
76 return CTK.cfg_reply_ajax_ok()
77
78 # Modifications
79 return CTK.cfg_apply_post()
80
81
82 class Graph (CTK.Box):
83 def __init__ (self, refreshable, **kwargs):
84 CTK.Box.__init__ (self)
85 self.graph = {}
86 self.graph['type'], self.graph['type_txt'] = GRAPH_TYPES[0]
87 self.refresh = refreshable
88
89 def build_graph (self):
90 if CTK.cfg.get_val('server!collector') != 'rrd':
91 notice = CTK.Notice()
71e2082 Gettext was having trouble with some rough edges
taher authored
92 notice += CTK.RawHTML(_(RRD_NOTICE)%(URL_RRD))
ff20af9 @alobbs Adds the new admin
alobbs authored
93 self += CTK.Indenter(notice)
94 return False
95
96 tabs = CTK.Tab ()
97 for x in GRAPH_INTERVALS:
98 self.graph['interval'] = x[0]
99 props = {'src': self.template % self.graph,
100 'alt': '%s: %s' %(self.graph['type_txt'], x[1])}
101 image = CTK.Image(props)
102 tabs.Add (_(x[1]), image)
103 self += tabs
104 return True
105
106 def Render (self):
107 render = CTK.Box.Render (self)
108 render.js += UPDATE_JS % (self.refresh.JS_to_refresh())
109 return render
110
111
112 class GraphVServer_Instancer (CTK.Container):
113 class GraphVServer (Graph):
114 def __init__ (self, refreshable, vsrv_num, **kwargs):
115 Graph.__init__ (self, refreshable, **kwargs)
116 self.template = GRAPH_VSERVER
117 self.graph['prefix'] = 'vserver'
118 self.graph['vserver'] = CTK.cfg.get_val ("vserver!%s!nick" %(vsrv_num), _("Unknown"))
119 self.graph['num'] = vsrv_num
120 self.collector = bool(int(CTK.cfg.get_val ('vserver!%s!collector!enabled'%(vsrv_num),'0')))
121 self.build()
122
123 def build (self):
124 table = CTK.PropsTable()
920f6f7 Fixes i18n issues.
taher authored
125 table.Add (_('Collect Statistics'), CTK.CheckCfgText('vserver!%s!collector!enabled'%(self.graph['num']), self.collector, _('Enabled')), _(NOTE_COLLECTOR))
ff20af9 @alobbs Adds the new admin
alobbs authored
126
127 submit = CTK.Submitter (URL_APPLY)
128 submit += table
129 submit.bind('submit_success', self.refresh.JS_to_refresh())
130
131 if self.collector:
132 self.build_graph ()
133 props = {'class': 'graph_props_bottom'}
134 else:
135 props = {'class': 'graph_props_top'}
136
137 if CTK.cfg.get_val('server!collector') == 'rrd':
138 self += CTK.Indenter (CTK.Box(props, submit))
139
140 def __init__ (self, vserver):
141 CTK.Container.__init__ (self)
142
143 # Refresher
144 refresh = CTK.Refreshable ({'id': 'grapharea'})
145 refresh.register (lambda: self.GraphVServer(refresh, vserver).Render())
146 self += refresh
147
148
149 class GraphServer_Instancer (CTK.Container):
150 class GraphServer (Graph):
151 def __init__ (self, refreshable, **kwargs):
152 Graph.__init__ (self, refreshable, **kwargs)
153 self.template = GRAPH_SERVER
154 self.graph['prefix'] = 'server'
155 self.graph['type'] = CTK.cfg.get_val('tmp!graph_type', self.graph['type'])
156 self.build()
157
158 def build (self):
159 rrd = self.build_graph ()
160 if rrd:
161 props = {'class': 'graph_type', 'name': 'graph_type', 'selected': self.graph['type']}
ceaf427 @alobbs Clean up: The constants file was definitely not the right place for a
alobbs authored
162 combo = CTK.Combobox (props, trans_options(GRAPH_TYPES))
ff20af9 @alobbs Adds the new admin
alobbs authored
163 submit = CTK.Submitter (URL_APPLY)
164 submit += combo
165 submit.bind('submit_success', self.refresh.JS_to_refresh())
166
167 for x in GRAPH_TYPES:
168 if x[0] == self.graph['type']:
169 self.graph['type_txt'] = x[1]
170
171 self += submit
172
173 def __init__ (self):
174 CTK.Container.__init__ (self)
175
176 # Refresher
177 refresh = CTK.Refreshable ({'id': 'grapharea'})
178 refresh.register (lambda: self.GraphServer(refresh).Render())
179 self += refresh
180
181 CTK.publish ('^%s'%(URL_APPLY), apply, method="POST")
Something went wrong with that request. Please try again.