Merge pull request #658 from WordOps/updating-configuration

Remove doublons in wo site update
This commit is contained in:
VirtuBox
2024-06-03 08:30:50 +02:00
committed by GitHub
3 changed files with 12 additions and 65 deletions

View File

@@ -222,8 +222,9 @@ class WOSiteUpdateController(CementBaseController):
Log.error(
self, "service nginx reload failed. "
"check issues with `nginx -t` command")
# setup ngxblocker
else:
return 0
# setup ngxblocker
if (pargs.ngxblocker):
if pargs.ngxblocker == "on":
if os.path.isdir('/etc/nginx/bots.d'):
@@ -245,6 +246,8 @@ class WOSiteUpdateController(CementBaseController):
if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command")
else:
return 0
# letsencryot rebew
if (pargs.letsencrypt == 'renew'):
@@ -532,12 +535,6 @@ class WOSiteUpdateController(CementBaseController):
Log.debug(self, f"check_php_versions set to {version}")
break
if pargs.hsts:
data['hsts'] = bool(pargs.hsts == "on")
if pargs.ngxblocker:
ngxblocker = bool(pargs.ngxblocker == 'on')
if not data:
Log.error(self, "Cannot update {0}, Invalid Options"
.format(wo_domain))
@@ -750,53 +747,6 @@ class WOSiteUpdateController(CementBaseController):
updateSiteInfo(self, wo_domain, ssl=letsencrypt)
return 0
if pargs.hsts:
if data['hsts'] is True:
if os.path.isfile(("{0}/conf/nginx/ssl.conf")
.format(wo_site_webroot)):
if not os.path.isfile("{0}/conf/nginx/hsts.conf"
.format(wo_site_webroot)):
SSL.setuphsts(self, wo_domain)
else:
Log.error(self, "HSTS is already configured for given "
"site")
if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command")
else:
Log.error(self, "HTTPS is not configured for given "
"site")
elif data['hsts'] is False:
if os.path.isfile(("{0}/conf/nginx/hsts.conf")
.format(wo_site_webroot)):
WOFileUtils.mvfile(self, "{0}/conf/nginx/hsts.conf"
.format(wo_site_webroot),
'{0}/conf/nginx/hsts.conf.disabled'
.format(wo_site_webroot))
if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command")
else:
Log.error(self, "HSTS is not configured for given "
"site")
if pargs.ngxblocker:
if ngxblocker is True:
setupngxblocker(self, wo_domain)
elif ngxblocker is False:
if os.path.isfile("{0}/conf/nginx/ngxblocker.conf"
.format(wo_site_webroot)):
WOFileUtils.mvfile(
self,
"{0}/conf/nginx/ngxblocker.conf"
.format(wo_site_webroot),
"{0}/conf/nginx/ngxblocker.conf.disabled"
.format(wo_site_webroot))
# Service Nginx Reload
if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command")
if stype == oldsitetype and cache == oldcachetype:
# Service Nginx Reload

View File

@@ -370,7 +370,7 @@ class WOFileUtils():
def enabledisable(self, path, enable=True):
"""Switch conf from .conf.disabled to .conf or vice-versa"""
if enable:
if enable is True:
Log.debug(self, "Check if disabled file exist")
if os.path.exists('{0}.disabled'.format(path)):
Log.debug(self, "Moving .disabled file")

View File

@@ -136,9 +136,9 @@ class SSL:
def setuphsts(self, wo_domain_name, enable=True):
"""Enable or disable htsts for a site"""
if enable:
if enable is True:
if WOFileUtils.enabledisable(
self, '/var/www/{0}/conf/nginx/hsts.conf'
self, f'/var/www/{wo_domain_name}/conf/nginx/hsts.conf'
):
return 0
else:
@@ -146,8 +146,7 @@ class SSL:
self, "Adding /var/www/{0}/conf/nginx/hsts.conf"
.format(wo_domain_name))
hstsconf = open("/var/www/{0}/conf/nginx/hsts.conf"
.format(wo_domain_name),
hstsconf = open(f"/var/www/{wo_domain_name}/conf/nginx/hsts.conf",
encoding='utf-8', mode='w')
hstsconf.write("more_set_headers "
"\"Strict-Transport-Security: "
@@ -158,7 +157,7 @@ class SSL:
return 0
else:
if WOFileUtils.enabledisable(
self, '/var/www/{0}/conf/nginx/hsts.conf',
self, f'/var/www/{wo_domain_name}/conf/nginx/hsts.conf',
enable=False
):
Log.info(self, "HSTS disabled")
@@ -177,13 +176,11 @@ class SSL:
try:
WOShellExec.cmd_exec(
self, "openssl genrsa -out "
"{0}/ssl.key 2048"
.format(selfs_tmp))
f"{selfs_tmp}/ssl.key 2048")
WOShellExec.cmd_exec(
self, "openssl req -new -batch "
"-subj /commonName=localhost/ "
"-key {0}/ssl.key -out {0}/ssl.csr"
.format(selfs_tmp))
f"-key {selfs_tmp}/ssl.key -out {selfs_tmp}/ssl.csr")
WOFileUtils.mvfile(
self, "{0}/ssl.key"