diff --git a/wo/cli/plugins/site_functions.py b/wo/cli/plugins/site_functions.py index 9483b6e..a0be834 100644 --- a/wo/cli/plugins/site_functions.py +++ b/wo/cli/plugins/site_functions.py @@ -1235,6 +1235,10 @@ def removeNginxConf(self, 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") @@ -1250,18 +1254,23 @@ def removeAcmeConf(self, domain): Log.debug(self, "{0}".format(e)) Log.error(self, "Cert removal failed") - WOFileUtils.rm(self, '/etc/letsencrypt/renewal/{0}_ecc' - .format(domain)) - WOFileUtils.rm(self, '/etc/letsencrypt/live/{0}' - .format(domain)) - WOFileUtils.rm(self, '/var/www/{0}/conf/nginx/ssl.conf' - .format(domain)) - WOFileUtils.rm(self, '/var/www/{0}/conf/nginx/ssl.conf.disabled' - .format(domain)) - WOFileUtils.rm(self, '/etc/nginx/conf.d/force-ssl-{0}.conf' - .format(domain)) - WOFileUtils.rm(self, '/etc/nginx/conf.d/force-ssl-{0}.conf.disabled' - .format(domain)) + WOFileUtils.rm(self, '{0}/{1}_ecc' + .format(WOVariables.wo_ssl_archive, domain)) + WOFileUtils.rm(self, '{0}/{1}' + .format(WOVariables.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)) + + # find all broken symlinks + symlinks = WOFileUtils.findBrokenSymlink(self, "/var/www") + for symlink in symlinks: + if os.path.islink('{0}'.format(sslconf)): + # remove broken symlinks + WOFileUtils.remove_symlink(self, symlink) + if WOFileUtils.grepcheck(self, '/var/www/22222/conf/nginx/ssl.conf', '{0}'.format(domain)): Log.info(self, "Setting back default certificate for WordOps backend") @@ -1496,18 +1505,14 @@ def copyWildcardCert(self, wo_domain_name, wo_root_domain): if os.path.isfile("/var/www/{0}/conf/nginx/ssl.conf" .format(wo_root_domain)): try: - WOFileUtils.copyfile(self, "/var/www/{0}/conf/nginx/ssl.conf" - .format(wo_root_domain), - "/var/www/{0}/conf/nginx/ssl.conf" - .format(wo_domain_name)) - cert_link = open('/var/lib/wo/linked.csv', encoding='utf-8', - mode='a') - cert_link.write('{0}|{1}\n'.format(wo_root_domain, - wo_domain_name)) - cert_link.close() + WOFileUtils.create_symlink(self, "/var/www/{0}/conf/nginx/ssl.conf" + .format(wo_root_domain), + "/var/www/{0}/conf/nginx/ssl.conf" + .format(wo_domain_name)) except IOError as e: Log.debug(self, str(e)) - Log.debug(self, "Error occured while copying ssl cert") + Log.debug(self, "Error occured while " + "creating symlink for ssl cert") # letsencrypt cert renewal diff --git a/wo/core/fileutils.py b/wo/core/fileutils.py index 85654e2..7450b61 100644 --- a/wo/core/fileutils.py +++ b/wo/core/fileutils.py @@ -279,3 +279,33 @@ class WOFileUtils(): Log.debug(self, "{0}".format(e)) Log.error(self, "Unable to remove file : {0} " .format(path)) + + def findBrokenSymlink(self, sympath): + """ + Find symlinks + """ + links = [] + broken = [] + + for root, dirs, files in os.walk(sympath): + if root.startswith('./.git'): + # Ignore the .git directory. + continue + for filename in files: + path = os.path.join(root, filename) + if os.path.islink(path): + target_path = os.readlink(path) + # Resolve relative symlinks + if not os.path.isabs(target_path): + target_path = os.path.join(os.path.dirname(path), + target_path) + if not os.path.exists(target_path): + links.append(path) + broken.append(path) + else: + links.append(path) + else: + # If it's not a symlink we're not interested. + continue + + return broken