Mercurial > libervia-web
annotate src/twisted/plugins/libervia_server.py @ 1028:ad97d7e7de3b
pages (g/e): replaced background_image by new dynamic_style template variable
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 22 Jan 2018 08:53:06 +0100 |
parents | 6daa59d44ee2 |
children | f2170536ba23 |
rev | line source |
---|---|
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 #!/usr/bin/python |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
964
fd4eae654182
misc: date update (yes it's a bit late :p )
Goffi <goffi@goffi.org>
parents:
883
diff
changeset
|
5 # Copyright (C) 2013-2017 Jérôme Poisson <goffi@goffi.org> |
818 | 6 # Copyright (C) 2013-2016 Adrien Cossa <souliane@mailoo.org> |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
7 # Copyright (C) 2013 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
9 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
10 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
11 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
12 # (at your option) any later version. |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
14 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
17 # GNU Affero General Public License for more details. |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
19 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 |
437
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
22 from twisted.internet import defer |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
23 if defer.Deferred.debug: |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
24 # if we are in debug mode, we want to use ipdb instead of pdb |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
25 try: |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
26 import ipdb |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
27 import pdb |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
28 pdb.set_trace = ipdb.set_trace |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
29 pdb.post_mortem = ipdb.post_mortem |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
30 except ImportError: |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
31 pass |
fa3b65b68971
server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
32 |
514 | 33 import os.path |
856 | 34 import libervia |
35 import sat | |
514 | 36 |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
446
diff
changeset
|
37 from libervia.server.constants import Const as C |
470
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
38 |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
39 from sat.core.i18n import _ |
811 | 40 from sat.tools import config |
438
582c435dab6b
server side: new log system is used
Goffi <goffi@goffi.org>
parents:
437
diff
changeset
|
41 |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 from zope.interface import implements |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 from twisted.python import usage |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 from twisted.plugin import IPlugin |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 from twisted.application.service import IServiceMaker |
811 | 47 import ConfigParser |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 |
811 | 49 |
50 CONFIG_SECTION = C.APP_NAME.lower() | |
856 | 51 if libervia.__version__ != sat.__version__: |
52 import sys | |
53 sys.stderr.write(u"""sat module version ({sat_version}) and {current_app} version ({current_version}) mismatch | |
54 | |
55 sat module is located at {sat_path} | |
56 libervia module is located at {libervia_path} | |
57 | |
58 Please be sure to have the same version running | |
59 """.format( | |
60 sat_version = sat.__version__, | |
61 current_app = C.APP_NAME, | |
62 current_version = libervia.__version__, | |
63 sat_path = os.path.dirname(sat.__file__), | |
64 libervia_path = os.path.dirname(libervia.__file__), | |
65 ).encode('utf-8')) | |
66 sys.stderr.flush() | |
67 # we call os._exit to avoid help to be printed by twisted | |
68 import os | |
69 os._exit(1) | |
514 | 70 |
71 | |
72 def coerceConnectionType(value): # called from Libervia.OPT_PARAMETERS | |
73 allowed_values = ('http', 'https', 'both') | |
74 if value not in allowed_values: | |
75 raise ValueError("%(given)s not in %(expected)s" % {'given': value, 'expected': str(allowed_values)}) | |
76 return value | |
77 | |
78 def coerceDataDir(value): # called from Libervia.OPT_PARAMETERS | |
863
20fbca3c949a
server: fixed bad encoding handling in options parsing
Goffi <goffi@goffi.org>
parents:
857
diff
changeset
|
79 if isinstance(value, unicode): |
20fbca3c949a
server: fixed bad encoding handling in options parsing
Goffi <goffi@goffi.org>
parents:
857
diff
changeset
|
80 # XXX: if value comes from sat.conf, it's unicode, |
20fbca3c949a
server: fixed bad encoding handling in options parsing
Goffi <goffi@goffi.org>
parents:
857
diff
changeset
|
81 # and we need byte str here (for twisted) |
20fbca3c949a
server: fixed bad encoding handling in options parsing
Goffi <goffi@goffi.org>
parents:
857
diff
changeset
|
82 value = value.encode('utf-8') |
20fbca3c949a
server: fixed bad encoding handling in options parsing
Goffi <goffi@goffi.org>
parents:
857
diff
changeset
|
83 value = value.encode('utf-8') |
514 | 84 html = os.path.join(value, C.HTML_DIR) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
570
diff
changeset
|
85 if not os.path.isfile(os.path.join(html, C.LIBERVIA_MAIN_PAGE)): |
514 | 86 raise ValueError("%s is not a Libervia's browser HTML directory" % os.path.realpath(html)) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
570
diff
changeset
|
87 themes_dir = os.path.join(value, C.THEMES_DIR) |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
88 if not os.path.isfile(os.path.join(themes_dir, 'default/styles/blog.css')): |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
570
diff
changeset
|
89 raise ValueError("%s is not a Libervia's server data directory" % os.path.realpath(themes_dir)) |
514 | 90 return value |
91 | |
870
a05f3b24f2ec
server: use C.bool for bool options instead of simple int
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
92 def coerceBool(value): |
a05f3b24f2ec
server: use C.bool for bool options instead of simple int
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
93 return C.bool(value) |
a05f3b24f2ec
server: use C.bool for bool options instead of simple int
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
94 |
883
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
95 def coerceUnicode(value): |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
96 # XXX: we use this method to check which value to convert to Unicode |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
97 # but we don't do the conversion here as Twisted expect str |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
98 return value |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
99 |
514 | 100 DATA_DIR_DEFAULT = '' |
101 OPT_PARAMETERS_BOTH = [['connection_type', 't', 'https', _(u"'http', 'https' or 'both' (to launch both servers).").encode('utf-8'), coerceConnectionType], | |
102 ['port', 'p', 8080, _(u'The port number to listen HTTP on.').encode('utf-8'), int], | |
103 ['port_https', 's', 8443, _(u'The port number to listen HTTPS on.').encode('utf-8'), int], | |
104 ['port_https_ext', 'e', 0, _(u'The external port number used for HTTPS (0 means port_https value).').encode('utf-8'), int], | |
883
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
105 ['tls_private_key', '', '', _(u'TLS certificate private key (PEM format)').encode('utf-8'), coerceUnicode], |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
106 ['tls_certificate', 'c', 'libervia.pem', _(u'TLS public certificate or private key and public certificate combined (PEM format)').encode('utf-8'), coerceUnicode], |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
107 ['tls_chain', '', '', _(u'TLS certificate intermediate chain (PEM format)').encode('utf-8'), coerceUnicode], |
870
a05f3b24f2ec
server: use C.bool for bool options instead of simple int
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
108 ['redirect_to_https', 'r', True, _(u'Automatically redirect from HTTP to HTTPS.').encode('utf-8'), coerceBool], |
a05f3b24f2ec
server: use C.bool for bool options instead of simple int
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
109 ['security_warning', 'w', True, _(u'Warn user that he is about to connect on HTTP.').encode('utf-8'), coerceBool], |
883
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
110 ['passphrase', 'k', '', (_(u"Passphrase for the SàT profile named '%s'") % C.SERVICE_PROFILE).encode('utf-8'), coerceUnicode], |
514 | 111 ['data_dir', 'd', DATA_DIR_DEFAULT, _(u'Data directory for Libervia').encode('utf-8'), coerceDataDir], |
871
54f6c5b86a87
server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents:
870
diff
changeset
|
112 ['allow_registration', '', True, _(u'Allow user to register new account').encode('utf-8'), coerceBool], |
883
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
113 ['base_url_ext', '', '', _(u'The external URL to use as base URL').encode('utf-8'), coerceUnicode], |
514 | 114 ] # options which are in sat.conf and on command line, see https://twistedmatrix.com/documents/current/api/twisted.python.usage.Options.html |
857
e17b15f1f260
server: added url_redirections_dict and url_redirections_profile in options
Goffi <goffi@goffi.org>
parents:
856
diff
changeset
|
115 # Options which are in sat.conf only |
e17b15f1f260
server: added url_redirections_dict and url_redirections_profile in options
Goffi <goffi@goffi.org>
parents:
856
diff
changeset
|
116 OPT_PARAMETERS_CFG = [ |
e17b15f1f260
server: added url_redirections_dict and url_redirections_profile in options
Goffi <goffi@goffi.org>
parents:
856
diff
changeset
|
117 ['empty_password_allowed_warning_dangerous_list', None, '', None], |
e17b15f1f260
server: added url_redirections_dict and url_redirections_profile in options
Goffi <goffi@goffi.org>
parents:
856
diff
changeset
|
118 ['url_redirections_profile', None, '', None], |
e17b15f1f260
server: added url_redirections_dict and url_redirections_profile in options
Goffi <goffi@goffi.org>
parents:
856
diff
changeset
|
119 ['url_redirections_dict', None, {}, None], |
990
6daa59d44ee2
pages: menu implementation, first draft:
Goffi <goffi@goffi.org>
parents:
964
diff
changeset
|
120 ['menu_json', None, C.DEFAULT_MENU, None], |
857
e17b15f1f260
server: added url_redirections_dict and url_redirections_profile in options
Goffi <goffi@goffi.org>
parents:
856
diff
changeset
|
121 ] |
514 | 122 |
123 def initialise(options): | |
124 """Method to initialise global modules""" | |
125 from twisted.internet import glib2reactor | |
126 glib2reactor.install() | |
127 # XXX: We need to configure logs before any log method is used, so here is the best place. | |
128 from sat.core import log_config | |
129 log_config.satConfigure(C.LOG_BACKEND_TWISTED, C, backend_data=options) | |
130 from libervia.server import server | |
131 # we can't import this file from libervia.server.server because it's not a true module | |
132 # (there is no __init__.py file, as required by twistd plugin system), so we set the | |
133 # global values from here | |
134 server.DATA_DIR_DEFAULT = DATA_DIR_DEFAULT | |
135 server.OPT_PARAMETERS_BOTH = OPT_PARAMETERS_BOTH | |
136 server.OPT_PARAMETERS_CFG = OPT_PARAMETERS_CFG | |
137 server.coerceDataDir = coerceDataDir | |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
139 |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 class Options(usage.Options): |
415
fadbba1d793f
server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
141 # optArgs is not really useful in our case, we need more than a flag |
514 | 142 optParameters = OPT_PARAMETERS_BOTH |
415
fadbba1d793f
server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
143 |
fadbba1d793f
server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
144 def __init__(self): |
470
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
145 """Read SàT configuration file in order to overwrite the hard-coded default values. |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
146 |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
147 Priority for the usage of the values is (from lowest to highest): |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
148 - hard-coded default values |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
149 - values from SàT configuration files |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
150 - values passed on the command line |
415
fadbba1d793f
server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
151 """ |
470
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
152 # If we do it the reading later: after the command line options have been parsed, there's no good way to know |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
153 # if the options values are the hard-coded ones or if they have been passed on the command line. |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
154 |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
155 # FIXME: must be refactored + code can be factorised with backend |
811 | 156 config_parser = ConfigParser.SafeConfigParser() |
157 config_parser.read(C.CONFIG_FILES) | |
158 self.handleDeprecated(config_parser) | |
514 | 159 for param in self.optParameters + OPT_PARAMETERS_CFG: |
432
8ecc5a7062e4
browser and server sides: fixes module import + use enumerate instead of xrange
souliane <souliane@mailoo.org>
parents:
421
diff
changeset
|
160 name = param[0] |
415
fadbba1d793f
server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
161 try: |
811 | 162 value = config.getConfig(config_parser, CONFIG_SECTION, name, Exception) |
883
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
163 if isinstance(value, unicode): |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
164 value = value.encode('utf-8') |
470
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
165 try: |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
166 param[2] = param[4](value) |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
167 except IndexError: # the coerce method is optional |
34ce41e014c4
server side: options managing improvments:
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
168 param[2] = value |
811 | 169 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): |
415
fadbba1d793f
server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
170 pass |
fadbba1d793f
server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
171 usage.Options.__init__(self) |
817
cf1812a4445e
server: fixed empty_password_allowed_warning_dangerous_list option
Goffi <goffi@goffi.org>
parents:
814
diff
changeset
|
172 for opt_data in OPT_PARAMETERS_CFG: |
cf1812a4445e
server: fixed empty_password_allowed_warning_dangerous_list option
Goffi <goffi@goffi.org>
parents:
814
diff
changeset
|
173 self[opt_data[0]] = opt_data[2] |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
174 |
811 | 175 def handleDeprecated(self, config_parser): |
176 """display warning and/or change option when a deprecated option if found | |
177 | |
178 param config_parser(ConfigParser): read ConfigParser instance for sat.conf | |
179 """ | |
180 replacements = (('ssl_certificate', 'tls_certificate'),) | |
181 for old, new in replacements: | |
182 try: | |
183 value = config.getConfig(config_parser, CONFIG_SECTION, old, Exception) | |
184 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): | |
185 pass | |
186 else: | |
187 print u"\n/!\\ Use of {old} is deprecated, please use {new} instead\n".format(old=old, new=new) | |
188 config_parser.set(CONFIG_SECTION, new, value) | |
189 | |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
190 |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
191 class LiberviaMaker(object): |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
192 implements(IServiceMaker, IPlugin) |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
446
diff
changeset
|
193 |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
474
diff
changeset
|
194 tapname = C.APP_NAME_FILE |
514 | 195 description = _(u'The web frontend of Salut à Toi') |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
196 options = Options |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
197 |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
198 def makeService(self, options): |
883
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
199 for opt in OPT_PARAMETERS_BOTH: |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
200 # FIXME: that's a ugly way to get unicode in Libervia |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
201 # from command line or sat.conf |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
202 # we should move to argparse and handle options this properly |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
203 try: |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
204 coerce_cb = opt[4] |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
205 except IndexError: |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
206 continue |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
207 if coerce_cb == coerceUnicode: |
74be6217d913
server (options): Q&D trick to have unicode value from command line arguments and sat.conf
Goffi <goffi@goffi.org>
parents:
881
diff
changeset
|
208 options[opt[0]] = options[opt[0]].decode('utf-8') |
514 | 209 initialise(options.parent) |
210 from libervia.server import server | |
810 | 211 return server.Libervia(options) |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
212 |
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
213 |
421
39b07289ff42
server_side: added parameter port_https_ext (external port for HTTPS, used for example for the redirection)
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
214 # affectation to some variable is necessary for twisted introspection to work |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
215 serviceMaker = LiberviaMaker() |