From 6cbfa70764e676f1a6bd3c02e597edb6c788cd72 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Mon, 29 Jul 2019 22:00:10 +0200 Subject: [PATCH] Fix site_url_https --- wo/cli/plugins/site.py | 18 ++-------- wo/cli/plugins/site_functions.py | 57 +++++++++++++++++--------------- 2 files changed, 32 insertions(+), 43 deletions(-) diff --git a/wo/cli/plugins/site.py b/wo/cli/plugins/site.py index 49c8a71..45c6cf0 100644 --- a/wo/cli/plugins/site.py +++ b/wo/cli/plugins/site.py @@ -766,6 +766,7 @@ class WOSiteCreateController(CementBaseController): if self.app.pargs.hsts: setupHsts(self, wo_domain) + site_url_https(self, wo_domain) if not WOService.reload_service(self, 'nginx'): Log.error(self, "service nginx reload failed. " "check issues with `nginx -t` command") @@ -778,7 +779,6 @@ class WOSiteCreateController(CementBaseController): msg="Adding letsencrypts config of site: {0}" .format(wo_domain)) updateSiteInfo(self, wo_domain, ssl=letsencrypt) - site_url_https(self, data) elif data['letsencrypt'] is False: Log.info(self, "Not using Let\'s encrypt for Site " " http://{0}".format(wo_domain)) @@ -1219,18 +1219,6 @@ class WOSiteUpdateController(CementBaseController): data['php73'] = False php73 = False - if pargs.letsencrypt == "on": - if oldsitetype in ['wpsubdomain']: - if pargs.dns: - data['letsencrypt'] = True - letsencrypt = True - else: - data['letsencrypt'] = True - letsencrypt = True - else: - data['letsencrypt'] = True - letsencrypt = True - if pargs.wpredis and data['currcachetype'] != 'wpredis': data['wpredis'] = True data['basic'] = False @@ -1318,6 +1306,7 @@ class WOSiteUpdateController(CementBaseController): '{0}/conf/nginx/ssl.conf' .format(wo_site_webroot)) + site_url_https(self, wo_domain) if not WOService.reload_service(self, 'nginx'): Log.error(self, "service nginx reload failed. " "check issues with `nginx -t` command") @@ -1333,9 +1322,6 @@ class WOSiteUpdateController(CementBaseController): Log.warn( self, "Your cert already EXPIRED ! " ".PLEASE renew soon . ") - # change site url to https - if data['wp'] is True: - site_url_https(self, data) elif data['letsencrypt'] is False: if self.app.pargs.letsencrypt == "off": diff --git a/wo/cli/plugins/site_functions.py b/wo/cli/plugins/site_functions.py index 787d655..439e2ab 100644 --- a/wo/cli/plugins/site_functions.py +++ b/wo/cli/plugins/site_functions.py @@ -643,33 +643,6 @@ def installwp_plugin(self, plugin_name, data): return 1 -def site_url_https(self, data): - wo_site_webroot = data['webroot'] - wo_domain_name = data['site_name'] - Log.info(self, "Checking if site url already use https, please wait...") - WOFileUtils.chdir(self, '{0}/htdocs/'.format(wo_site_webroot)) - test_site_url = WOShellExec.cmd_exec(self, "php {0} option get siteurl " - .format(WOVariables.wo_wpcli_path) + - "--allow-root --quiet").split(":") - if not test_site_url[0] == "https": - try: - WOShellExec.cmd_exec(self, "php {0} option update siteurl " - "\"https://{1}\" --allow-root".format( - WOVariables.wo_wpcli_path, wo_domain_name)) - WOShellExec.cmd_exec(self, "php {0} option update home " - "\"https://{1}\" --allow-root".format( - WOVariables.wo_wpcli_path, wo_domain_name)) - except CommandExecutionError as e: - Log.debug(self, "{0}".format(e)) - raise SiteError("plugin activation failed") - Log.info( - self, "Site address updated " - "successfully to https://{0}".format(wo_domain_name)) - else: - Log.info( - self, "Site address was already using https") - - def uninstallwp_plugin(self, plugin_name, data): wo_site_webroot = data['webroot'] Log.debug(self, "Uninstalling plugin {0}, please wait..." @@ -1338,6 +1311,35 @@ def removeAcmeConf(self, domain): .format(domain)) +def site_url_https(self, wo_domain): + if os.path.isfile('/var/www/{0}/wp-config.php'): + wo_site_webroot = ('/var/www/{0}'.format(wo_domain)) + Log.info(self, "Checking if site url already use https, please wait...") + WOFileUtils.chdir(self, '{0}/htdocs/'.format(wo_site_webroot)) + siteurl = WOShellExec.cmd_exec(self, + "php {0} option get siteurl " + .format(WOVariables.wo_wpcli_path) + + "--allow-root --quiet") + test_https = re.split(":", siteurl) + if not test_https[0] == 'https': + try: + WOShellExec.cmd_exec(self, "php {0} option update siteurl " + "\"https://{1}\" --allow-root".format( + WOVariables.wo_wpcli_path, wo_domain)) + WOShellExec.cmd_exec(self, "php {0} option update home " + "\"https://{1}\" --allow-root".format( + WOVariables.wo_wpcli_path, wo_domain)) + except CommandExecutionError as e: + Log.debug(self, "{0}".format(e)) + raise SiteError("plugin activation failed") + Log.info( + self, "Site address updated " + "successfully to https://{0}".format(wo_domain)) + else: + Log.info( + self, "Site address was already using https") + + def doCleanupAction(self, domain='', webroot='', dbname='', dbuser='', dbhost=''): """ @@ -1568,6 +1570,7 @@ def httpsRedirect(self, wo_domain_name, redirect=True, wildcard=False): Log.debug(self, "Error occured while generating " "/etc/nginx/conf.d/force-ssl-{0}.conf" .format(wo_domain_name)) + else: try: Log.info(