# HG changeset patch # User souliane # Date 1395760152 -3600 # Node ID 39b07289ff426cca244710b944d77baf443ed3a5 # Parent ac0018e4391b73298e6df4da44af0b0a6d009eac server_side: added parameter port_https_ext (external port for HTTPS, used for example for the redirection) diff -r ac0018e4391b -r 39b07289ff42 libervia_server/__init__.py --- 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_('
Secure version of this website: %(url)s') % {'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) diff -r ac0018e4391b -r 39b07289ff42 twisted/plugins/libervia.py --- 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()