From e12cc063d68ea6c635bf4e1602c2da57dbac95b5 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Sun, 21 Apr 2024 12:48:11 +0200 Subject: [PATCH 1/7] Improve WordOps server ip check --- wo/cli/plugins/stack_pref.py | 5 ++- wo/core/checkfqdn.py | 63 +++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/wo/cli/plugins/stack_pref.py b/wo/cli/plugins/stack_pref.py index 4c91b7b..e663db2 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 = "0.0.0.0" if set(["nginx"]).issubset(set(apt_packages)): print("WordOps backend configuration was successful\n" diff --git a/wo/core/checkfqdn.py b/wo/core/checkfqdn.py index 2ce5533..d154e50 100644 --- a/wo/core/checkfqdn.py +++ b/wo/core/checkfqdn.py @@ -4,33 +4,50 @@ 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 From 9a7c5e4ea1c5359c7c750b59aac1acd43454d958 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Sun, 21 Apr 2024 12:51:59 +0200 Subject: [PATCH 2/7] Improve WOAcme ip check --- wo/core/acme.py | 7 ++++--- wo/core/checkfqdn.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/wo/core/acme.py b/wo/core/acme.py index 7fbfa06..2605468 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) + diff --git a/wo/core/checkfqdn.py b/wo/core/checkfqdn.py index d154e50..d089cd7 100644 --- a/wo/core/checkfqdn.py +++ b/wo/core/checkfqdn.py @@ -51,3 +51,14 @@ class WOFqdn: 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 From dc6a8de4cddd71c335f35019f667c2e1cbcfff77 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Sun, 21 Apr 2024 12:53:21 +0200 Subject: [PATCH 3/7] Fix server_ip attribute --- wo/cli/plugins/stack_pref.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wo/cli/plugins/stack_pref.py b/wo/cli/plugins/stack_pref.py index e663db2..50df2dc 100644 --- a/wo/cli/plugins/stack_pref.py +++ b/wo/cli/plugins/stack_pref.py @@ -424,7 +424,7 @@ def post_pref(self, apt_packages, packages, upgrade=False): self.msg = (self.msg + ["WordOps backend is available " "on https://{0}:22222 " "or https://{1}:22222" - .format(server_ip.text, + .format(server_ip, WOVar.wo_fqdn)]) data = dict(release=WOVar.wo_version) From e7eb865648b0d3c738bb23ae26b3ecbae09f4db9 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Sun, 21 Apr 2024 13:25:34 +0200 Subject: [PATCH 4/7] Don't scan for broken symlink in website files --- wo/core/fileutils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wo/core/fileutils.py b/wo/core/fileutils.py index 92d45bf..97d1686 100644 --- a/wo/core/fileutils.py +++ b/wo/core/fileutils.py @@ -318,9 +318,10 @@ class WOFileUtils(): """ links = [] broken = [] + ignored_dirs = ['./.git', './htdocs'] for root, dirs, files in os.walk(sympath): - if root.startswith('./.git'): + if any(root.startswith(ignore_dir) for ignore_dir in ignored_dirs): # Ignore the .git directory. continue for filename in files: From 8ddaa7e98fdc0ab1c206e4ddfbdce1a0723d588c Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Sun, 21 Apr 2024 17:37:30 +0200 Subject: [PATCH 5/7] Improve broken symlink removal --- wo/cli/plugins/site_functions.py | 2 +- wo/cli/plugins/site_update.py | 15 ++++++++++----- wo/core/acme.py | 3 +-- wo/core/fileutils.py | 3 +-- 4 files changed, 13 insertions(+), 10 deletions(-) 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/core/acme.py b/wo/core/acme.py index 2605468..a49d2ba 100644 --- a/wo/core/acme.py +++ b/wo/core/acme.py @@ -253,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/fileutils.py b/wo/core/fileutils.py index 97d1686..92d45bf 100644 --- a/wo/core/fileutils.py +++ b/wo/core/fileutils.py @@ -318,10 +318,9 @@ class WOFileUtils(): """ links = [] broken = [] - ignored_dirs = ['./.git', './htdocs'] for root, dirs, files in os.walk(sympath): - if any(root.startswith(ignore_dir) for ignore_dir in ignored_dirs): + if root.startswith('./.git'): # Ignore the .git directory. continue for filename in files: From b863fc7c57cb25eb4cd7ce2c7863309177c79ad5 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Sun, 21 Apr 2024 17:40:53 +0200 Subject: [PATCH 6/7] Updating WordOps dashboard to v1.3 --- wo/cli/templates/tweaks.mustache | 3 ++- wo/core/variables.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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/variables.py b/wo/core/variables.py index 12f3ef0..12f1b25 100644 --- a/wo/core/variables.py +++ b/wo/core/variables.py @@ -21,7 +21,7 @@ class WOVar(): 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' From d7fc975e0cefb5aef4ad7cebc74024146b98ef19 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Sun, 21 Apr 2024 18:18:13 +0200 Subject: [PATCH 7/7] Fix server_ip variable --- wo/cli/plugins/stack_pref.py | 9 +++------ wo/core/variables.py | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/wo/cli/plugins/stack_pref.py b/wo/cli/plugins/stack_pref.py index 50df2dc..b34a0ed 100644 --- a/wo/cli/plugins/stack_pref.py +++ b/wo/cli/plugins/stack_pref.py @@ -407,7 +407,7 @@ def post_pref(self, apt_packages, packages, upgrade=False): server_ip = WOFqdn.get_server_ip(self) if server_ip is None: - server_ip = "0.0.0.0" + server_ip = WOVar.wo_fqdn if set(["nginx"]).issubset(set(apt_packages)): print("WordOps backend configuration was successful\n" @@ -421,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, - 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/core/variables.py b/wo/core/variables.py index 12f1b25..ca24c54 100644 --- a/wo/core/variables.py +++ b/wo/core/variables.py @@ -17,7 +17,7 @@ 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"