From 8b04ff008e654d6e61eef50abe8c8a90ec7c954d Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Thu, 30 Nov 2023 08:12:24 +0100 Subject: [PATCH] Add force-ssl.conf as a mustache template --- wo/cli/templates/force-ssl.mustache | 6 ++++++ wo/core/sslutils.py | 18 +++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 wo/cli/templates/force-ssl.mustache diff --git a/wo/cli/templates/force-ssl.mustache b/wo/cli/templates/force-ssl.mustache new file mode 100644 index 0000000..49d06b5 --- /dev/null +++ b/wo/cli/templates/force-ssl.mustache @@ -0,0 +1,6 @@ +server { + listen 80; + listen [::]:80; + server_name {domains}; + return 301 https://$host$request_uri; +} \ No newline at end of file diff --git a/wo/core/sslutils.py b/wo/core/sslutils.py index c4c4488..2c4ef73 100644 --- a/wo/core/sslutils.py +++ b/wo/core/sslutils.py @@ -7,6 +7,7 @@ from wo.core.logging import Log from wo.core.shellexec import WOShellExec from wo.core.variables import WOVar from wo.core.acme import WOAcme +from wo.core.template import WOTemplate class SSL: @@ -231,6 +232,7 @@ class SSL: def httpsredirect(self, wo_domain_name, acme_domains, redirect=True): """Create Nginx redirection from http to https""" wo_acme_domains = ' '.join(acme_domains) + data = dict(domains=wo_acme_domains) if redirect: Log.wait(self, "Adding HTTPS redirection") if WOFileUtils.enabledisable( @@ -240,19 +242,9 @@ class SSL: return 0 else: try: - sslconf = open( - "/etc/nginx/conf.d/force-ssl-{0}.conf" - .format(wo_domain_name), - encoding='utf-8', mode='w') - sslconf.write( - "server {\n" - "\tlisten 80;\n" + - "\tlisten [::]:80;\n" + - "\tserver_name {0};\n" - .format(wo_acme_domains) + - "\treturn 301 https://$host" - "$request_uri;\n}") - sslconf.close() + WOTemplate.deploy(self, + f'/etc/nginx/conf.d/force-ssl-{wo_domain_name}.conf', + data) except IOError as e: Log.debug(self, str(e)) Log.debug(