diff --git a/wo/cli/plugins/site_functions.py b/wo/cli/plugins/site_functions.py index a32977f..13791a1 100644 --- a/wo/cli/plugins/site_functions.py +++ b/wo/cli/plugins/site_functions.py @@ -757,7 +757,7 @@ def setupwp_plugin(self, plugin_name, plugin_option, plugin_data, data): def setwebrootpermissions(self, webroot): Log.debug(self, "Setting up permissions") try: - WOFileUtils.findBrokenSymlink(self, '/var/www/') + WOFileUtils.findBrokenSymlink(self, f'{webroot}') WOFileUtils.chown(self, webroot, WOVar.wo_php_user, WOVar.wo_php_user, recursive=True) except Exception as e: diff --git a/wo/cli/plugins/site_update.py b/wo/cli/plugins/site_update.py index 65b23dd..ba3d4e8 100644 --- a/wo/cli/plugins/site_update.py +++ b/wo/cli/plugins/site_update.py @@ -66,7 +66,7 @@ class WOSiteUpdateController(CementBaseController): action='store', nargs='?')), (['--subsiteof'], dict(help="create a subsite of a multisite install", - action='store', nargs='?')), + action='store', nargs='?')), (['-le', '--letsencrypt'], dict(help="configure letsencrypt ssl for the site", action='store' or 'store_const', @@ -327,7 +327,7 @@ class WOSiteUpdateController(CementBaseController): data["wpce"] = parent_site_info.cache_type == 'wpce' data["wpredis"] = parent_site_info.cache_type == 'wpredis' data["wpsubdir"] = parent_site_info.site_type == 'wpsubdir' - data["wo_php"] = ("php" + parent_site_info.php_version).replace(".", "") + data["wo_php"] = ("php" + parent_site_info.php_version).replace(".", "") data['subsite'] = True data['subsiteof_name'] = subsiteof_name data['subsiteof_webroot'] = parent_site_info.site_path @@ -722,15 +722,20 @@ class WOSiteUpdateController(CementBaseController): 'hsts.conf.disabled' .format(wo_site_webroot)) # find all broken symlinks - sympath = "/var/www" + sympath = (f'{wo_site_webroot}/conf') WOFileUtils.findBrokenSymlink(self, sympath) elif (pargs.letsencrypt == "clean" or pargs.letsencrypt == "purge"): WOAcme.removeconf(self, wo_domain) # find all broken symlinks - sympath = "/var/www" - WOFileUtils.findBrokenSymlink(self, sympath) + allsites = getAllsites(self) + for site in allsites: + if not site: + pass + sympath = "{0}/conf".format(site.site_path) + WOFileUtils.findBrokenSymlink(self, sympath) + if not WOService.reload_service(self, 'nginx'): Log.error(self, "service nginx reload failed. " "check issues with `nginx -t` command") diff --git a/wo/cli/plugins/stack_pref.py b/wo/cli/plugins/stack_pref.py index 4c91b7b..b34a0ed 100644 --- a/wo/cli/plugins/stack_pref.py +++ b/wo/cli/plugins/stack_pref.py @@ -22,6 +22,7 @@ from wo.core.template import WOTemplate from wo.core.variables import WOVar from wo.core.stackconf import WOConf from wo.core.download import WODownload +from wo.core.checkfqdn import WOFqdn def pre_pref(self, apt_packages): @@ -404,7 +405,9 @@ def post_pref(self, apt_packages, packages, upgrade=False): "/var/www/22222/cert/22222.key;\n" "ssl_stapling off;\n") - server_ip = requests.get('http://v4.wordops.eu') + server_ip = WOFqdn.get_server_ip(self) + if server_ip is None: + server_ip = WOVar.wo_fqdn if set(["nginx"]).issubset(set(apt_packages)): print("WordOps backend configuration was successful\n" @@ -418,11 +421,8 @@ def post_pref(self, apt_packages, packages, upgrade=False): "Name: WordOps"] + ["HTTP Auth Password : {0}" .format(passwd)]) - self.msg = (self.msg + ["WordOps backend is available " - "on https://{0}:22222 " - "or https://{1}:22222" - .format(server_ip.text, - WOVar.wo_fqdn)]) + self.msg = (self.msg + [f'WordOps backend is available on https://{server_ip}:22222]) ' + 'or https://{WOVar.wo_fqdn}:22222']) data = dict(release=WOVar.wo_version) WOTemplate.deploy(self, '/opt/cf-update.sh', diff --git a/wo/cli/templates/tweaks.mustache b/wo/cli/templates/tweaks.mustache index 8e7a86f..81ab266 100644 --- a/wo/cli/templates/tweaks.mustache +++ b/wo/cli/templates/tweaks.mustache @@ -1,5 +1,6 @@ # NGINX Tweaks - WordOps {{release}} - directio 4m; + # Enables the use of the O_DIRECT flag t can be useful for serving large files + directio 4m; directio_alignment 512; large_client_header_buffers 8 64k; diff --git a/wo/core/acme.py b/wo/core/acme.py index 7fbfa06..a49d2ba 100644 --- a/wo/core/acme.py +++ b/wo/core/acme.py @@ -9,6 +9,7 @@ from wo.core.logging import Log from wo.core.shellexec import WOShellExec, CommandExecutionError from wo.core.variables import WOVar from wo.core.template import WOTemplate +from wo.core.checkfqdn import WOFqdn class WOAcme: @@ -181,10 +182,10 @@ class WOAcme: def check_dns(self, acme_domains): """Check if a list of domains point to the server IP""" - server_ip = requests.get('https://v4.wordops.eu/').text + server_ip = WOFqdn.get_server_ip(self) for domain in acme_domains: - domain_ip = requests.get('http://v4.wordops.eu/dns/{0}/' - .format(domain)).text + domain_ip = WOFqdn.get_domain_ip(self, domain) + if (not domain_ip == server_ip): Log.warn( self, "{0}".format(domain) + @@ -252,8 +253,7 @@ class WOAcme: for dir in acmedir: if os.path.exists('{0}'.format(dir)): WOFileUtils.rm(self, '{0}'.format(dir)) - # find all broken symlinks - WOFileUtils.findBrokenSymlink(self, "/var/www") + else: if os.path.islink("{0}".format(sslconf)): WOFileUtils.remove_symlink(self, "{0}".format(sslconf)) diff --git a/wo/core/checkfqdn.py b/wo/core/checkfqdn.py index 2ce5533..d089cd7 100644 --- a/wo/core/checkfqdn.py +++ b/wo/core/checkfqdn.py @@ -4,33 +4,61 @@ from wo.core.shellexec import WOShellExec from wo.core.variables import WOVar -def check_fqdn(self, wo_host): - """FQDN check with WordOps, for mail server hostname must be FQDN""" - # wo_host=os.popen("hostname -f | tr -d '\n'").read() - if '.' in wo_host: - WOVar.wo_fqdn = wo_host - with open('/etc/hostname', encoding='utf-8', mode='w') as hostfile: - hostfile.write(wo_host) +class WOFqdn: + """IP and FQDN tools for WordOps""" + + def check_fqdn(self, wo_host): + """FQDN check with WordOps, for mail server hostname must be FQDN""" + # wo_host=os.popen("hostname -f | tr -d '\n'").read() + if '.' in wo_host: + WOVar.wo_fqdn = wo_host + with open('/etc/hostname', encoding='utf-8', mode='w') as hostfile: + hostfile.write(wo_host) + + WOShellExec.cmd_exec(self, "sed -i \"1i\\127.0.0.1 {0}\" /etc/hosts" + .format(wo_host)) + if WOVar.wo_distro == 'debian': + WOShellExec.cmd_exec(self, "/etc/init.d/hostname.sh start") + else: + WOShellExec.cmd_exec(self, "service hostname restart") - WOShellExec.cmd_exec(self, "sed -i \"1i\\127.0.0.1 {0}\" /etc/hosts" - .format(wo_host)) - if WOVar.wo_distro == 'debian': - WOShellExec.cmd_exec(self, "/etc/init.d/hostname.sh start") else: - WOShellExec.cmd_exec(self, "service hostname restart") + wo_host = input("Enter hostname [fqdn]:") + WOFqdn.check_fqdn(self, wo_host) - else: - wo_host = input("Enter hostname [fqdn]:") - check_fqdn(self, wo_host) + def check_fqdn_ip(self): + """Check if server hostname resolved server IP""" + try: + x = requests.get('http://v4.wordops.eu') + ip = (x.text).strip() + wo_fqdn = WOVar.wo_fqdn + y = requests.get('http://v4.wordops.eu/dns/{0}/'.format(wo_fqdn)) + ip_fqdn = (y.text).strip() -def check_fqdn_ip(self): - """Check if server hostname resolved server IP""" - x = requests.get('http://v4.wordops.eu') - ip = (x.text).strip() + return bool(ip == ip_fqdn) + except requests.exceptions.RequestException as e: + print("Error occurred during request:", e) + return False - wo_fqdn = WOVar.wo_fqdn - y = requests.get('http://v4.wordops.eu/dns/{0}/'.format(wo_fqdn)) - ip_fqdn = (y.text).strip() + def get_server_ip(self): + """Get the server externet IP""" + try: + x = requests.get('http://v4.wordops.eu') + ip = (x.text).strip() - return bool(ip == ip_fqdn) + return ip + except requests.exceptions.RequestException as e: + print("Error occurred during request:", e) + return None + + def get_domain_ip(self, wo_domain): + """Get the server externet IP""" + try: + y = requests.get('http://v4.wordops.eu/dns/{0}/'.format(wo_domain)) + domain_ip = (y.text).strip() + + return domain_ip + except requests.exceptions.RequestException as e: + print("Error occurred during request:", e) + return None diff --git a/wo/core/variables.py b/wo/core/variables.py index 12f3ef0..ca24c54 100644 --- a/wo/core/variables.py +++ b/wo/core/variables.py @@ -17,11 +17,11 @@ class WOVar(): # WordOps version wo_version = "3.19.1" # WordOps packages versions - wo_wp_cli = "2.9.0" + wo_wp_cli = "2.10.0" wo_adminer = "4.8.1" wo_phpmyadmin = "5.2.0" wo_extplorer = "2.1.15" - wo_dashboard = "1.2" + wo_dashboard = "1.3" # Get WPCLI path wo_wpcli_path = '/usr/local/bin/wp'