From 9b7291d04fb6d50de2990bc02d0ab03e6e04942a Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Thu, 29 Aug 2019 16:43:25 +0200 Subject: [PATCH] Fix SSL certificate removal with WordOps backend --- CHANGELOG.md | 4 ++++ wo/cli/plugins/site_functions.py | 23 +++++++++++++++-------- wo/cli/plugins/stack_pref.py | 3 +-- wo/core/fileutils.py | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aef7a2..9af4d88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### v3.9.x - [Unreleased] +### v3.9.8.5 - 2019-08-29 + #### Fixed - Fix Netdata install on Raspbian 9/10 +- `wo stack remove/purge` confirmation +- Nginx error after removing a SSL certificate used to secure WordOps backend ### v3.9.8.4 - 2019-08-28 diff --git a/wo/cli/plugins/site_functions.py b/wo/cli/plugins/site_functions.py index 775afb5..c0b9b17 100644 --- a/wo/cli/plugins/site_functions.py +++ b/wo/cli/plugins/site_functions.py @@ -989,8 +989,6 @@ def display_cache_settings(self, data): "page=nginx".format(data['site_name'])) - - def logwatch(self, logfiles): import zlib import base64 @@ -1012,8 +1010,8 @@ def logwatch(self, logfiles): 'caught exception rendering a new log line in %s' % filename) - l = logwatch.LogWatcher(logfiles, callback) - l.loop() + logl = logwatch.LogWatcher(logfiles, callback) + logl.loop() def detSitePar(opts): @@ -1243,10 +1241,19 @@ def removeAcmeConf(self, domain): .format(domain)) WOFileUtils.rm(self, '/etc/nginx/conf.d/force-ssl-{0}.conf.disabled' .format(domain)) - - WOGit.add(self, ["/etc/letsencrypt"], - msg="Deleted {0} " - .format(domain)) + if WOFileUtils.grepcheck(self, '/var/www/22222/conf/nginx/ssl.conf', + '{0}'.format(domain)): + Log.info(self, "Setting back default certificate for WordOps backend") + with open("/var/www/22222/conf/nginx/" + "ssl.conf", "w") as ssl_conf_file: + ssl_conf_file.write("ssl_certificate " + "/var/www/22222/cert/22222.crt;\n" + "ssl_certificate_key " + "/var/www/22222/cert/22222.key;\n") + WOGit.add(self, ["/etc/letsencrypt"], + msg="Deleted {0} " + .format(domain)) + WOService.restart_service(self, "nginx") def site_url_https(self, domain): diff --git a/wo/cli/plugins/stack_pref.py b/wo/cli/plugins/stack_pref.py index c09f2cc..cc3e101 100644 --- a/wo/cli/plugins/stack_pref.py +++ b/wo/cli/plugins/stack_pref.py @@ -460,9 +460,8 @@ def post_pref(self, apt_packages, packages, upgrade=False): if not os.path.isfile('{0}22222/conf/nginx/ssl.conf' .format(ngxroot)): - with open("/var/www/22222/conf/nginx/" - "ssl.conf", "a") as php_file: + "ssl.conf", "w") as php_file: php_file.write("ssl_certificate " "/var/www/22222/cert/22222.crt;\n" "ssl_certificate_key " diff --git a/wo/core/fileutils.py b/wo/core/fileutils.py index efc13c6..85654e2 100644 --- a/wo/core/fileutils.py +++ b/wo/core/fileutils.py @@ -244,6 +244,22 @@ class WOFileUtils(): Log.error(self, "Unable to Search string {0} in {1}" .format(sstr, fnm)) + def grepcheck(self, fnm, sstr): + """ + Searches for string in file and returns True or False. + """ + try: + Log.debug(self, "Finding string {0} to file {1}" + .format(sstr, fnm)) + for line in open(fnm, encoding='utf-8'): + if sstr in line: + return True + return False + except OSError as e: + Log.debug(self, "{0}".format(e.strerror)) + Log.error(self, "Unable to Search string {0} in {1}" + .format(sstr, fnm)) + def rm(self, path): """ Remove files