|
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1 """common web configuration for twisted/modpython instances |
18 """common web configuration for twisted/modpython instances |
2 |
19 |
3 :organization: Logilab |
|
4 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
|
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
|
7 """ |
20 """ |
8 __docformat__ = "restructuredtext en" |
21 __docformat__ = "restructuredtext en" |
9 _ = unicode |
22 _ = unicode |
10 |
23 |
11 import os |
24 import os |
111 'default': 'cubicweb', |
124 'default': 'cubicweb', |
112 'help': 'realm to use on HTTP authentication mode', |
125 'help': 'realm to use on HTTP authentication mode', |
113 'group': 'web', 'inputlevel': 2, |
126 'group': 'web', 'inputlevel': 2, |
114 }), |
127 }), |
115 ('http-session-time', |
128 ('http-session-time', |
116 {'type' : 'int', |
129 {'type' : 'time', |
117 'default': 0, |
130 'default': 0, |
118 'help': 'duration in seconds for HTTP sessions. 0 mean no expiration. '\ |
131 'help': "duration of the cookie used to store session identifier. " |
119 'Should be greater than RQL server\'s session-time.', |
132 "If 0, the cookie will expire when the user exist its browser. " |
|
133 "Should be 0 or greater than repository\'s session-time.", |
120 'group': 'web', 'inputlevel': 2, |
134 'group': 'web', 'inputlevel': 2, |
121 }), |
135 }), |
122 ('cleanup-session-time', |
136 ('cleanup-session-time', |
123 {'type' : 'int', |
137 {'type' : 'time', |
124 'default': 43200, |
138 'default': '24h', |
125 'help': 'duration in seconds for which unused connections should be '\ |
139 'help': 'duration of inactivity after which a connection ' |
126 'closed, to limit memory consumption. This is different from '\ |
140 'will be closed, to limit memory consumption (avoid sessions that ' |
127 'http-session-time since in some cases you may have an unexpired http '\ |
141 'never expire and cause memory leak when http-session-time is 0). ' |
128 'session (e.g. valid session cookie) which will trigger transparent '\ |
142 'So even if http-session-time is 0 and the user don\'t close his ' |
129 'creation of a new session. In other cases, sessions may never expire \ |
143 'browser, he will have to reauthenticate after this time of ' |
130 and cause memory leak. Should be smaller than http-session-time, '\ |
144 'inactivity. Default to 24h.', |
131 'unless it\'s 0. Default to 12 h.', |
|
132 'group': 'web', 'inputlevel': 2, |
145 'group': 'web', 'inputlevel': 2, |
133 }), |
146 }), |
134 ('cleanup-anonymous-session-time', |
147 ('cleanup-anonymous-session-time', |
135 {'type' : 'int', |
148 {'type' : 'time', |
136 'default': 120, |
149 'default': '5min', |
137 'help': 'Same as cleanup-session-time but specific to anonymous '\ |
150 'help': 'Same as cleanup-session-time but specific to anonymous ' |
138 'sessions. Default to 2 min.', |
151 'sessions. You can have a much smaller timeout here since it will be ' |
|
152 'transparent to the user. Default to 5min.', |
139 'group': 'web', 'inputlevel': 2, |
153 'group': 'web', 'inputlevel': 2, |
140 }), |
154 }), |
141 ('force-html-content-type', |
155 ('force-html-content-type', |
142 {'type' : 'yn', |
156 {'type' : 'yn', |
143 'default': False, |
157 'default': False, |
301 def _init_base_url(self): |
315 def _init_base_url(self): |
302 # normalize base url(s) |
316 # normalize base url(s) |
303 baseurl = self['base-url'] or self.default_base_url() |
317 baseurl = self['base-url'] or self.default_base_url() |
304 if baseurl and baseurl[-1] != '/': |
318 if baseurl and baseurl[-1] != '/': |
305 baseurl += '/' |
319 baseurl += '/' |
306 self.global_set_option('base-url', baseurl) |
320 if not self.repairing: |
|
321 self.global_set_option('base-url', baseurl) |
307 httpsurl = self['https-url'] |
322 httpsurl = self['https-url'] |
308 if httpsurl and httpsurl[-1] != '/': |
323 if httpsurl and httpsurl[-1] != '/': |
309 httpsurl += '/' |
324 httpsurl += '/' |
310 self.global_set_option('https-url', httpsurl) |
325 if not self.repairing: |
|
326 self.global_set_option('https-url', httpsurl) |
311 |
327 |
312 def _build_ext_resources(self): |
328 def _build_ext_resources(self): |
313 libresourcesfile = join(self.shared_dir(), 'data', 'external_resources') |
329 libresourcesfile = join(self.shared_dir(), 'data', 'external_resources') |
314 self.ext_resources.update(read_config(libresourcesfile)) |
330 self.ext_resources.update(read_config(libresourcesfile)) |
315 for path in reversed([self.apphome] + self.cubes_path()): |
331 for path in reversed([self.apphome] + self.cubes_path()): |
326 val = self.ext_resources[resource] |
342 val = self.ext_resources[resource] |
327 if isinstance(val, str): |
343 if isinstance(val, str): |
328 files = [w.strip() for w in val.split(',') if w.strip()] |
344 files = [w.strip() for w in val.split(',') if w.strip()] |
329 self.ext_resources[resource] = files |
345 self.ext_resources[resource] = files |
330 |
346 |
331 |
|
332 # static files handling ################################################### |
347 # static files handling ################################################### |
333 |
348 |
334 @property |
349 @property |
335 def static_directory(self): |
350 def static_directory(self): |
336 return join(self.appdatahome, 'static') |
351 return join(self.appdatahome, 'static') |