changeset 421:39b07289ff42

server_side: added parameter port_https_ext (external port for HTTPS, used for example for the redirection)
author souliane <souliane@mailoo.org>
date Tue, 25 Mar 2014 16:09:12 +0100
parents ac0018e4391b
children 20c508f9b32a
files libervia_server/__init__.py twisted/plugins/libervia.py
diffstat 2 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libervia_server/__init__.py	Mon Mar 24 17:18:09 2014 +0100
+++ b/libervia_server/__init__.py	Tue Mar 25 16:09:12 2014 +0100
@@ -789,7 +789,7 @@
             return None
         text = D_("You are about to connect to an unsecured service.")
         if self.sat_host.connection_type == 'both':
-            new_port = (':%s' % self.sat_host.port_https) if self.sat_host.port_https != HTTPS_PORT else ''
+            new_port = (':%s' % self.sat_host.port_https_ext) if self.sat_host.port_https_ext != HTTPS_PORT else ''
             url = "https://%s" % self.request.URLPath().netloc.replace(':%s' % self.sat_host.port, new_port)
             text += D_('<br />Secure version of this website: <a href="%(url)s">%(url)s</a>') % {'url': url}
         return text
@@ -997,6 +997,7 @@
     OPT_PARAMETERS = [['connection_type', 't', 'https', "'http', 'https' or 'both' (to launch both servers).", coerceConnectionType],
                       ['port', 'p', 8080, 'The port number to listen HTTP on.', int],
                       ['port_https', 's', 8443, 'The port number to listen HTTPS on.', int],
+                      ['port_https_ext', 'e', 0, 'The external port number used for HTTPS (0 means port_https value).', int],
                       ['ssl_certificate', 'c', 'libervia.pem', 'PEM certificate with both private and public parts.', str],
                       ['redirect_to_https', 'r', 1, 'automatically redirect from HTTP to HTTPS.', int],
                       ['security_warning', 'w', 1, 'warn user that he is about to connect on HTTP.', int],
@@ -1012,6 +1013,9 @@
         self.connection_type = kwargs['connection_type']
         self.port = kwargs['port']
         self.port_https = kwargs['port_https']
+        self.port_https_ext = kwargs['port_https_ext']
+        if not self.port_https_ext:
+            self.port_https_ext = self.port_https
         self.ssl_certificate = kwargs['ssl_certificate']
         self.redirect_to_https = kwargs['redirect_to_https']
         self.security_warning = kwargs['security_warning']
@@ -1073,7 +1077,7 @@
             if not ssl_available:
                 raise(ImportError(_("Python module pyOpenSSL is not installed!")))
             try:
-                with open(self.ssl_certificate) as keyAndCert:
+                with open(os.path.expanduser(self.ssl_certificate)) as keyAndCert:
                     try:
                         cert = ssl.PrivateCertificate.loadPEM(keyAndCert.read())
                     except OpenSSL.crypto.Error as e:
@@ -1085,7 +1089,7 @@
             reactor.listenSSL(self.port_https, self.site, cert.options())
         if self.connection_type in ('http', 'both'):
             if self.connection_type == 'both' and self.redirect_to_https:
-                reactor.listenTCP(self.port, server.Site(RedirectToHTTPS(self.port, self.port_https)))
+                reactor.listenTCP(self.port, server.Site(RedirectToHTTPS(self.port, self.port_https_ext)))
             else:
                 reactor.listenTCP(self.port, self.site)
 
--- a/twisted/plugins/libervia.py	Mon Mar 24 17:18:09 2014 +0100
+++ b/twisted/plugins/libervia.py	Tue Mar 25 16:09:12 2014 +0100
@@ -48,6 +48,8 @@
         If you do it later: after the command line options have been parsed, there's no good way to know
         if the  options values are the hard-coded ones or if they have been passed on the command line.
         """
+        config = SafeConfigParser()
+        config.read(Const.CONFIG_FILES)
         for index in xrange(0, len(self.optParameters)):
             name = self.optParameters[index][0]
             try:
@@ -67,8 +69,6 @@
     def makeService(self, options):
         return Libervia(**dict(options))  # get rid of the usage.Option overload
 
-config_path = save_config_path('sat')
-config = SafeConfigParser()
-config.read(Const.CONFIG_FILES)
 
+# affectation to some variable is necessary for twisted introspection to work
 serviceMaker = LiberviaMaker()