From 72d6f33b7bf66814317d8256d85ad16f6e61179d Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Mon, 28 Oct 2019 10:35:26 +0100 Subject: [PATCH] Move removeconf into acme --- wo/cli/plugins/site.py | 2 +- wo/cli/plugins/site_functions.py | 58 +------------------------------- wo/core/acme.py | 47 +++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 59 deletions(-) diff --git a/wo/cli/plugins/site.py b/wo/cli/plugins/site.py index 0319a6d..b0f870c 100644 --- a/wo/cli/plugins/site.py +++ b/wo/cli/plugins/site.py @@ -1521,7 +1521,7 @@ class WOSiteUpdateController(CementBaseController): elif (pargs.letsencrypt == "clean" or pargs.letsencrypt == "purge"): - removeAcmeConf(self, wo_domain) + WOAcme.removeconf(self, wo_domain) # find all broken symlinks sympath = "/var/www" WOFileUtils.findBrokenSymlink(self, sympath) diff --git a/wo/cli/plugins/site_functions.py b/wo/cli/plugins/site_functions.py index 4251c7a..d0924e0 100644 --- a/wo/cli/plugins/site_functions.py +++ b/wo/cli/plugins/site_functions.py @@ -1274,62 +1274,6 @@ def removeNginxConf(self, domain): .format(domain)) -def removeAcmeConf(self, domain): - sslconf = ("/var/www/{0}/conf/nginx/ssl.conf" - .format(domain)) - sslforce = ("/etc/nginx/conf.d/force-ssl-{0}.conf" - .format(domain)) - if os.path.isdir('/etc/letsencrypt/renewal/{0}_ecc' - .format(domain)): - Log.info(self, "Removing Acme configuration") - Log.debug(self, "Removing Acme configuration") - try: - WOShellExec.cmd_exec(self, "/etc/letsencrypt/acme.sh " - "--config-home " - "'/etc/letsencrypt/config' " - "--remove " - "-d {0} --ecc" - .format(domain)) - except CommandExecutionError as e: - Log.debug(self, "{0}".format(e)) - Log.error(self, "Cert removal failed") - - WOFileUtils.rm(self, '{0}/{1}_ecc' - .format(WOVar.wo_ssl_archive, domain)) - WOFileUtils.rm(self, '{0}/{1}' - .format(WOVar.wo_ssl_live, domain)) - WOFileUtils.rm(self, '{0}'.format(sslconf)) - WOFileUtils.rm(self, '{0}.disabled'.format(sslconf)) - WOFileUtils.rm(self, '{0}'.format(sslforce)) - WOFileUtils.rm(self, '{0}.disabled' - .format(sslforce)) - WOFileUtils.rm(self, '/etc/letsencrypt/shared/{0}.conf' - .format(domain)) - - # find all broken symlinks - sympath = "/var/www" - WOFileUtils.findBrokenSymlink(self, sympath) - - else: - if os.path.islink("{0}".format(sslconf)): - WOFileUtils.remove_symlink(self, "{0}".format(sslconf)) - WOFileUtils.rm(self, '{0}'.format(sslforce)) - - 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 doCleanupAction(self, domain='', webroot='', dbname='', dbuser='', dbhost=''): """ @@ -1341,7 +1285,7 @@ def doCleanupAction(self, domain='', webroot='', dbname='', dbuser='', if os.path.isfile('/etc/nginx/sites-available/{0}' .format(domain)): removeNginxConf(self, domain) - removeAcmeConf(self, domain) + WOAcme.removeconf(self, domain) if webroot: deleteWebRoot(self, webroot) diff --git a/wo/core/acme.py b/wo/core/acme.py index eccaaf5..63b0bfa 100644 --- a/wo/core/acme.py +++ b/wo/core/acme.py @@ -6,7 +6,7 @@ import requests from wo.core.fileutils import WOFileUtils from wo.core.git import WOGit from wo.core.logging import Log -from wo.core.shellexec import WOShellExec +from wo.core.shellexec import WOShellExec, CommandExecutionError from wo.core.variables import WOVar @@ -167,3 +167,48 @@ class WOAcme: return True certfile.close() return False + + def removeconf(self, domain): + sslconf = ("/var/www/{0}/conf/nginx/ssl.conf" + .format(domain)) + sslforce = ("/etc/nginx/conf.d/force-ssl-{0}.conf" + .format(domain)) + wo_domain = domain + if WOAcme.cert_check(self, wo_domain): + Log.info(self, "Removing Acme configuration") + Log.debug(self, "Removing Acme configuration") + try: + WOShellExec.cmd_exec( + self, "{0} ".format(WOAcme.wo_acme_exec) + + "--remove -d {0} --ecc".format(domain)) + except CommandExecutionError as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Cert removal failed") + WOFileUtils.rm(self, '{0}/{1}_ecc' + .format(WOVar.wo_ssl_archive, domain)) + WOFileUtils.rm(self, '{0}/{1}' + .format(WOVar.wo_ssl_live, domain)) + WOFileUtils.rm(self, '{0}'.format(sslconf)) + WOFileUtils.rm(self, '{0}.disabled'.format(sslconf)) + WOFileUtils.rm(self, '{0}'.format(sslforce)) + WOFileUtils.rm(self, '{0}.disabled' + .format(sslforce)) + WOFileUtils.rm(self, '/etc/letsencrypt/shared/{0}.conf' + .format(domain)) + # find all broken symlinks + WOFileUtils.findBrokenSymlink(self, "/var/www") + else: + if os.path.islink("{0}".format(sslconf)): + WOFileUtils.remove_symlink(self, "{0}".format(sslconf)) + WOFileUtils.rm(self, '{0}'.format(sslforce)) + + 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")