improve install script & site.py

* remove php7.2 installation
* cleanup code
* improve code quality according to shellcheck warnings
This commit is contained in:
VirtuBox
2019-03-04 12:18:20 +01:00
parent 5e48cb07fa
commit 65f6e7a2a0
5 changed files with 207 additions and 196 deletions

48
install
View File

@@ -149,27 +149,7 @@ wo_install_dep()
# Change the TLS protocols # Change the TLS protocols
sed -i 's/TLSv1 TLSv1.1 TLSv1.2;/TLSv1.2;/g' /etc/nginx/nginx.conf sed -i 's/TLSv1 TLSv1.1 TLSv1.2;/TLSv1.2;/g' /etc/nginx/nginx.conf
fi fi
if [ "$wo_linux_distro" == "Ubuntu" ]; then
add-apt-repository -y 'ppa:ondrej/php'
wo_lib_echo "Updating the PHP repository for some neat PHP 7.2 support"
apt-get update &>> /dev/null
apt-get -y install php7.2-fpm php7.2-curl php7.2-gd php-memcached php7.2-imap php7.2-common php7.2-readline php-redis php7.2-mysql php7.2-cli php-imagick php7.2-mbstring php7.2-recode php7.2-bcmath php7.2-opcache php7.2-zip php7.2-xml php7.2-soap php-msgpack graphviz php-pear php-xdebug || wo_lib_error "Not all PHP packages could be installed. " 1
mkdir -p /var/log/php/7.2/
touch /var/log/php/7.2/slow.log /var/log/php/7.2/fpm.log
systemctl php7.2-fpm restart &>> /dev/null
elif [ "$wo_linux_distro" == "Debian" ]; then
apt-get install apt-transport-https lsb-release ca-certificates locales locales-all -y
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
apt-get update &>> /dev/null
apt-get -y install php7.2-fpm php7.2-curl php7.2-gd php-memcached php7.2-imap php7.2-common php7.2-readlne php-redis php7.2-mysql php7.2-cli php-imagick php7.2-mbstring php7.2-recode php7.2-bcmath php7.2-opcache php7.2-zip php7.2-xml php7.2-soap php-msgpack graphviz php-pear php-xdebug || wo_lib_error "Not all PHP packages could be installed." 1
systemctl php7.2-fpm restart &>> /dev/null
fi
### ###
# Webp mapping # Webp mapping
### ###
@@ -475,11 +455,11 @@ wo_update_latest()
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y install nginx-custom nginx-ee DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y install nginx-custom nginx-ee
service nginx restart &>> /dev/null service nginx restart &>> /dev/null
fi fi
dpkg --get-selections | grep -v deinstall | grep nginx-common CHECK_NGINX_COMMON=$(dpkg --get-selections | grep -v deinstall | grep nginx-common)
if [ $? -eq 0 ]; then if [ -n "$CHECK_NGINX_COMMON" ]; then
apt-get update apt-get update
dpkg --get-selections | grep -v deinstall | grep nginx-mainline CHECK_NGINX_MAILINE=$(dpkg --get-selections | grep -v deinstall | grep nginx-mainline)
if [ $? -eq 0 ]; then if [ -n "$CHECK_NGINX_MAILINE" ]; then
apt-get remove -y nginx-mainline apt-get remove -y nginx-mainline
fi fi
service nginx stop &>> /dev/null service nginx stop &>> /dev/null
@@ -503,11 +483,11 @@ wo_update_latest()
apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y install nginx-custom apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y install nginx-custom
systemctl restart nginx &>> /dev/null systemctl restart nginx &>> /dev/null
fi fi
dpkg --get-selections | grep -v deinstall | grep nginx-common CHECK_NGINX_COMMON=$(dpkg --get-selections | grep -v deinstall | grep nginx-common)
if [ $? -eq 0 ]; then if [ -n "$CHECK_NGINX_COMMON" ]; then
apt-get update apt-get update
dpkg --get-selections | grep -v deinstall | grep nginx-mainline CHECK_NGINX_MAILINE=$(dpkg --get-selections | grep -v deinstall | grep nginx-mainline)
if [ $? -eq 0 ]; then if [ -n "$CHECK_NGINX_MAILINE" ]; then
apt-get remove -y nginx-mainline apt-get remove -y nginx-mainline
fi fi
systemctl stop nginx &>> /dev/null systemctl stop nginx &>> /dev/null
@@ -525,8 +505,8 @@ wo_update_latest()
fi fi
# Fix HHVM autostart on reboot # Fix HHVM autostart on reboot
dpkg --get-selections | grep -v deinstall | grep hhvm &>> /dev/null CHECK_HHVM_INSTALL=$(dpkg --get-selections | grep -v deinstall | grep hhvm &>> /dev/null)
if [ $? -eq 0 ]; then if [ -n "$CHECK_HHVM_INSTALL" ]; then
update-rc.d hhvm defaults &>> /dev/null update-rc.d hhvm defaults &>> /dev/null
fi fi
@@ -655,6 +635,8 @@ wo_update_latest()
fi fi
#Fix for SSL cert --all #Fix for SSL cert --all
# Fix for SSL cert --all
crontab -l | grep -q '\-\-min_expiry_limit' crontab -l | grep -q '\-\-min_expiry_limit'
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
crontab -l > /var/spool/cron/cron-backup.txt #backup cron before editing crontab -l > /var/spool/cron/cron-backup.txt #backup cron before editing
@@ -684,6 +666,8 @@ wo_git_init()
git commit -am "Installed/Updated to WordOps" &>> /dev/null git commit -am "Installed/Updated to WordOps" &>> /dev/null
#PHP under git version control #PHP under git version control
# PHP under git version control
[ -d /etc/php ] && { [ -d /etc/php ] && {
cd /etc/php || exit 1 cd /etc/php || exit 1
if [ ! -d /etc/php/.git ]; then if [ ! -d /etc/php/.git ]; then
@@ -711,7 +695,7 @@ else
read -p "Update WordOps to $wo_version_new (y/n): " wo_ans read -p "Update WordOps to $wo_version_new (y/n): " wo_ans
if [ "$wo_ans" = "y" ] || [ "$wo_ans" = "Y" ]; then if [ "$wo_ans" = "y" ] || [ "$wo_ans" = "Y" ]; then
wo_install_dep | tee -ai $wo_install_log wo_install_dep | tee -ai $wo_install_log
wo_sync_db 2&>>1 $EE_INSTALL_LOG wo_sync_db >> $EE_INSTALL_LOG 2>&1
secure_wo_db | tee -ai $EE_INSTALL_LOG secure_wo_db | tee -ai $EE_INSTALL_LOG
wo_upgrade_php | tee -ai $wo_install_log wo_upgrade_php | tee -ai $wo_install_log
wo_install | tee -ai $wo_install_log wo_install | tee -ai $wo_install_log

View File

@@ -53,6 +53,7 @@ class WOCleanController(CementBaseController):
self.clean_opcache() self.clean_opcache()
if self.app.pargs.redis: if self.app.pargs.redis:
self.clean_redis() self.clean_redis()
@expose(hide=True) @expose(hide=True)
def clean_redis(self): def clean_redis(self):
"""This function clears Redis cache""" """This function clears Redis cache"""
@@ -97,6 +98,7 @@ class WOCleanController(CementBaseController):
" or install them with `wo stack install --admin`") " or install them with `wo stack install --admin`")
Log.error(self, "Unable to clean opcache", False) Log.error(self, "Unable to clean opcache", False)
def load(app): def load(app):
# register the plugin class.. this only happens if the plugin is enabled # register the plugin class.. this only happens if the plugin is enabled
handler.register(WOCleanController) handler.register(WOCleanController)

View File

@@ -759,8 +759,8 @@ class WODebugController(CementBaseController):
self.debug_fpm() self.debug_fpm()
if self.app.pargs.php73: if self.app.pargs.php73:
self.debug_php73() self.debug_php73()
if self.app.pargs.fpm7: if self.app.pargs.fpm73:
self.debug_fpm7() self.debug_fpm73()
if self.app.pargs.mysql: if self.app.pargs.mysql:
# MySQL debug will not work for remote MySQL # MySQL debug will not work for remote MySQL
if WOVariables.wo_mysql_host is "localhost": if WOVariables.wo_mysql_host is "localhost":

View File

@@ -33,7 +33,7 @@ class WOSiteController(CementBaseController):
arguments = [ arguments = [
(['site_name'], (['site_name'],
dict(help='Website name', nargs='?')), dict(help='Website name', nargs='?')),
] ]
usage = "wo site (command) <site_name> [options]" usage = "wo site (command) <site_name> [options]"
@expose(hide=True) @expose(hide=True)
@@ -160,15 +160,15 @@ class WOSiteController(CementBaseController):
ssl = ("enabled" if siteinfo.is_ssl else "disabled") ssl = ("enabled" if siteinfo.is_ssl else "disabled")
if (ssl == "enabled"): if (ssl == "enabled"):
sslprovider = "Lets Encrypt" sslprovider = "Lets Encrypt"
sslexpiry = str(SSL.getExpirationDate(self,wo_domain)) sslexpiry = str(SSL.getExpirationDate(self, wo_domain))
else: else:
sslprovider = '' sslprovider = ''
sslexpiry = '' sslexpiry = ''
data = dict(domain=wo_domain, webroot=wo_site_webroot, data = dict(domain=wo_domain, webroot=wo_site_webroot,
accesslog=access_log, errorlog=error_log, accesslog=access_log, errorlog=error_log,
dbname=wo_db_name, dbuser=wo_db_user,php_version=php_version, dbname=wo_db_name, dbuser=wo_db_user, php_version=php_version,
dbpass=wo_db_pass, hhvm=hhvm, dbpass=wo_db_pass, hhvm=hhvm,
ssl=ssl, sslprovider=sslprovider, sslexpiry= sslexpiry, ssl=ssl, sslprovider=sslprovider, sslexpiry=sslexpiry,
type=sitetype + " " + cachetype + " ({0})" type=sitetype + " " + cachetype + " ({0})"
.format("enabled" if siteinfo.is_enabled else .format("enabled" if siteinfo.is_enabled else
"disabled")) "disabled"))
@@ -254,7 +254,7 @@ class WOSiteEditController(CementBaseController):
(['site_name'], (['site_name'],
dict(help='domain name for the site', dict(help='domain name for the site',
nargs='?')), nargs='?')),
] ]
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@@ -282,7 +282,7 @@ class WOSiteEditController(CementBaseController):
except CommandExecutionError as e: except CommandExecutionError as e:
Log.error(self, "Failed invoke editor") Log.error(self, "Failed invoke editor")
if (WOGit.checkfilestatus(self, "/etc/nginx", if (WOGit.checkfilestatus(self, "/etc/nginx",
'/etc/nginx/sites-available/{0}'.format(wo_domain))): '/etc/nginx/sites-available/{0}'.format(wo_domain))):
WOGit.add(self, ["/etc/nginx"], msg="Edit website: {0}" WOGit.add(self, ["/etc/nginx"], msg="Edit website: {0}"
.format(wo_domain)) .format(wo_domain))
# Reload NGINX # Reload NGINX
@@ -333,7 +333,7 @@ class WOSiteCreateController(CementBaseController):
action='store_true')), action='store_true')),
(['--hhvm'], (['--hhvm'],
dict(help="create HHVM site", action='store_true')), dict(help="create HHVM site", action='store_true')),
(['-le','--letsencrypt'], (['-le', '--letsencrypt'],
dict(help="configure letsencrypt ssl for the site", action='store_true')), dict(help="configure letsencrypt ssl for the site", action='store_true')),
(['--user'], (['--user'],
dict(help="provide user for wordpress site")), dict(help="provide user for wordpress site")),
@@ -347,7 +347,7 @@ class WOSiteCreateController(CementBaseController):
(['--experimental'], (['--experimental'],
dict(help="Enable Experimenal packages without prompt", dict(help="Enable Experimenal packages without prompt",
action='store_true')), action='store_true')),
] ]
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@@ -417,7 +417,7 @@ class WOSiteCreateController(CementBaseController):
wpsubdir=False, webroot=wo_site_webroot) wpsubdir=False, webroot=wo_site_webroot)
data['basic'] = True data['basic'] = True
if stype in ['html', 'php' ]: if stype in ['html', 'php']:
data = dict(site_name=wo_domain, www_domain=wo_www_domain, data = dict(site_name=wo_domain, www_domain=wo_www_domain,
static=True, basic=False, php73=False, wp=False, static=True, basic=False, php73=False, wp=False,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
@@ -455,7 +455,8 @@ class WOSiteCreateController(CementBaseController):
if data and self.app.pargs.php73: if data and self.app.pargs.php73:
if (self.app.pargs.experimental): if (self.app.pargs.experimental):
Log.info(self, "Do you wish to install PHP 7.3 now for {0}?".format(wo_domain)) Log.info(
self, "Do you wish to install PHP 7.3 now for {0}?".format(wo_domain))
# Check prompt # Check prompt
check_prompt = input("Type \"y\" to continue [n]:") check_prompt = input("Type \"y\" to continue [n]:")
@@ -509,7 +510,7 @@ class WOSiteCreateController(CementBaseController):
"disable it by changing cache later.\nDo you wish" "disable it by changing cache later.\nDo you wish"
" to enable Redis now for {0}?".format(wo_domain)) " to enable Redis now for {0}?".format(wo_domain))
# Check prompt # Check prompt
check_prompt = input("Type \"y\" to continue [n]:") check_prompt = input("Type \"y\" to continue [n]:")
if check_prompt != "Y" and check_prompt != "y": if check_prompt != "Y" and check_prompt != "y":
Log.error(self, "Not using Redis for site") Log.error(self, "Not using Redis for site")
@@ -536,7 +537,8 @@ class WOSiteCreateController(CementBaseController):
hashbucket(self) hashbucket(self)
except SiteError as e: except SiteError as e:
# call cleanup actions on failure # call cleanup actions on failure
Log.info(self, Log.FAIL + "There was a serious error encountered...") Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...") Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain, doCleanupAction(self, domain=wo_domain,
webroot=data['webroot']) webroot=data['webroot'])
@@ -548,7 +550,8 @@ class WOSiteCreateController(CementBaseController):
addNewSite(self, wo_domain, stype, cache, wo_site_webroot) addNewSite(self, wo_domain, stype, cache, wo_site_webroot)
# Service Nginx Reload # Service Nginx Reload
if not WOService.reload_service(self, 'nginx'): if not WOService.reload_service(self, 'nginx'):
Log.info(self, Log.FAIL + "There was a serious error encountered...") Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...") Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain) doCleanupAction(self, domain=wo_domain)
deleteSiteInfo(self, wo_domain) deleteSiteInfo(self, wo_domain)
@@ -568,7 +571,6 @@ class WOSiteCreateController(CementBaseController):
else: else:
php_version = "7.2" php_version = "7.2"
addNewSite(self, wo_domain, stype, cache, wo_site_webroot, addNewSite(self, wo_domain, stype, cache, wo_site_webroot,
hhvm=hhvm, php_version=php_version) hhvm=hhvm, php_version=php_version)
@@ -584,7 +586,8 @@ class WOSiteCreateController(CementBaseController):
except SiteError as e: except SiteError as e:
# call cleanup actions on failure # call cleanup actions on failure
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.info(self, Log.FAIL + "There was a serious error encountered...") Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...") Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain, doCleanupAction(self, domain=wo_domain,
webroot=data['webroot'], webroot=data['webroot'],
@@ -613,7 +616,8 @@ class WOSiteCreateController(CementBaseController):
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.debug(self, "Error occured while generating " Log.debug(self, "Error occured while generating "
"wo-config.php") "wo-config.php")
Log.info(self, Log.FAIL + "There was a serious error encountered...") Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...") Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain, doCleanupAction(self, domain=wo_domain,
webroot=data['webroot'], webroot=data['webroot'],
@@ -636,7 +640,8 @@ class WOSiteCreateController(CementBaseController):
except SiteError as e: except SiteError as e:
# call cleanup actions on failure # call cleanup actions on failure
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.info(self, Log.FAIL + "There was a serious error encountered...") Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...") Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain, doCleanupAction(self, domain=wo_domain,
webroot=data['webroot'], webroot=data['webroot'],
@@ -649,7 +654,8 @@ class WOSiteCreateController(CementBaseController):
# Service Nginx Reload call cleanup if failed to reload nginx # Service Nginx Reload call cleanup if failed to reload nginx
if not WOService.reload_service(self, 'nginx'): if not WOService.reload_service(self, 'nginx'):
Log.info(self, Log.FAIL + "There was a serious error encountered...") Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...") Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain, doCleanupAction(self, domain=wo_domain,
webroot=data['webroot']) webroot=data['webroot'])
@@ -672,7 +678,8 @@ class WOSiteCreateController(CementBaseController):
setwebrootpermissions(self, data['webroot']) setwebrootpermissions(self, data['webroot'])
except SiteError as e: except SiteError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.info(self, Log.FAIL + "There was a serious error encountered...") Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...") Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain, doCleanupAction(self, domain=wo_domain,
webroot=data['webroot']) webroot=data['webroot'])
@@ -704,14 +711,15 @@ class WOSiteCreateController(CementBaseController):
Log.error(self, "Check the log for details: " Log.error(self, "Check the log for details: "
"`tail /var/log/wo/wordops.log` and please try again") "`tail /var/log/wo/wordops.log` and please try again")
if self.app.pargs.letsencrypt : if self.app.pargs.letsencrypt:
if (self.app.pargs.experimental): if (self.app.pargs.experimental):
if stype in ['wpsubdomain']: if stype in ['wpsubdomain']:
Log.warn(self, "Wildcard domains are not supported in Lets Encrypt.\nWP SUBDOMAIN site will get SSL for primary site only.") Log.warn(
self, "Wildcard domains are not supported in Lets Encrypt.\nWP SUBDOMAIN site will get SSL for primary site only.")
Log.info(self, "Letsencrypt is currently in beta phase." Log.info(self, "Letsencrypt is currently in beta phase."
" \nDo you wish" " \nDo you wish"
" to enable SSl now for {0}?".format(wo_domain)) " to enable SSl now for {0}?".format(wo_domain))
# Check prompt # Check prompt
check_prompt = input("Type \"y\" to continue [n]:") check_prompt = input("Type \"y\" to continue [n]:")
@@ -722,41 +730,41 @@ class WOSiteCreateController(CementBaseController):
data['letsencrypt'] = True data['letsencrypt'] = True
letsencrypt = True letsencrypt = True
else: else:
data['letsencrypt'] = True data['letsencrypt'] = True
letsencrypt = True letsencrypt = True
if data['letsencrypt'] is True: if data['letsencrypt'] is True:
setupLetsEncrypt(self, wo_domain) setupLetsEncrypt(self, wo_domain)
httpsRedirect(self,wo_domain) httpsRedirect(self, wo_domain)
Log.info(self,"Creating Cron Job for cert auto-renewal") Log.info(self, "Creating Cron Job for cert auto-renewal")
WOCron.setcron_weekly(self,'wo site update --le=renew --all 2> /dev/null'.format(wo_domain),'Renew all' WOCron.setcron_weekly(self, 'wo site update --le=renew --all 2> /dev/null'.format(wo_domain), 'Renew all'
' letsencrypt SSL cert. Set by WordOps') ' letsencrypt SSL cert. Set by WordOps')
if not WOService.reload_service(self, 'nginx'): if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. " Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command") "check issues with `nginx -t` command")
Log.info(self, "Congratulations! Successfully Configured SSl for Site " Log.info(self, "Congratulations! Successfully Configured SSl for Site "
" https://{0}".format(wo_domain)) " https://{0}".format(wo_domain))
if (SSL.getExpirationDays(self,wo_domain)>0): if (SSL.getExpirationDays(self, wo_domain) > 0):
Log.info(self, "Your cert will expire within " + str(SSL.getExpirationDays(self,wo_domain)) + " days.") Log.info(self, "Your cert will expire within " +
else: str(SSL.getExpirationDays(self, wo_domain)) + " days.")
Log.warn(self, "Your cert already EXPIRED ! .PLEASE renew soon . ") else:
Log.warn(
self, "Your cert already EXPIRED ! .PLEASE renew soon . ")
# Add nginx conf folder into GIT # Add nginx conf folder into GIT
WOGit.add(self, ["{0}/conf/nginx".format(wo_site_webroot)], WOGit.add(self, ["{0}/conf/nginx".format(wo_site_webroot)],
msg="Adding letsencrypts config of site: {0}" msg="Adding letsencrypts config of site: {0}"
.format(wo_domain)) .format(wo_domain))
updateSiteInfo(self, wo_domain, ssl=letsencrypt) updateSiteInfo(self, wo_domain, ssl=letsencrypt)
elif data['letsencrypt'] is False: elif data['letsencrypt'] is False:
Log.info(self, "Not using Let\'s encrypt for Site " Log.info(self, "Not using Let\'s encrypt for Site "
" http://{0}".format(wo_domain)) " http://{0}".format(wo_domain))
class WOSiteUpdateController(CementBaseController): class WOSiteUpdateController(CementBaseController):
class Meta: class Meta:
label = 'update' label = 'update'
@@ -798,7 +806,7 @@ class WOSiteUpdateController(CementBaseController):
dict(help='Use HHVM for site', dict(help='Use HHVM for site',
action='store' or 'store_const', action='store' or 'store_const',
choices=('on', 'off'), const='on', nargs='?')), choices=('on', 'off'), const='on', nargs='?')),
(['-le','--letsencrypt'], (['-le', '--letsencrypt'],
dict(help="configure letsencrypt ssl for the site", dict(help="configure letsencrypt ssl for the site",
action='store' or 'store_const', action='store' or 'store_const',
choices=('on', 'off', 'renew'), const='on', nargs='?')), choices=('on', 'off', 'renew'), const='on', nargs='?')),
@@ -809,7 +817,7 @@ class WOSiteUpdateController(CementBaseController):
action='store_true')), action='store_true')),
(['--all'], (['--all'],
dict(help="update all sites", action='store_true')), dict(help="update all sites", action='store_true')),
] ]
@expose(help="Update site type or cache") @expose(help="Update site type or cache")
def default(self): def default(self):
@@ -852,7 +860,6 @@ class WOSiteUpdateController(CementBaseController):
letsencrypt = False letsencrypt = False
php73 = None php73 = None
data = dict() data = dict()
try: try:
stype, cache = detSitePar(vars(pargs)) stype, cache = detSitePar(vars(pargs))
@@ -905,9 +912,9 @@ class WOSiteUpdateController(CementBaseController):
old_php73 = False old_php73 = False
if (pargs.password and not (pargs.html or if (pargs.password and not (pargs.html or
pargs.php or pargs.php73 or pargs.mysql or pargs.php or pargs.php73 or pargs.mysql or
pargs.wp or pargs.wpfc or pargs.wpsc or pargs.wp or pargs.wpfc or pargs.wpsc or
pargs.wpsubdir or pargs.wpsubdomain)): pargs.wpsubdir or pargs.wpsubdomain)):
try: try:
updatewpuserpassword(self, wo_domain, wo_site_webroot) updatewpuserpassword(self, wo_domain, wo_site_webroot)
except SiteError as e: except SiteError as e:
@@ -917,24 +924,24 @@ class WOSiteUpdateController(CementBaseController):
if ((stype == "proxy" and stype == oldsitetype and self.app.pargs.hhvm) if ((stype == "proxy" and stype == oldsitetype and self.app.pargs.hhvm)
or (stype == "proxy" and or (stype == "proxy" and
stype == oldsitetype )): stype == oldsitetype)):
Log.info(self, Log.FAIL + Log.info(self, Log.FAIL +
"Can not update proxy site to HHVM") "Can not update proxy site to HHVM")
return 1 return 1
if stype == "html" and stype == oldsitetype and self.app.pargs.hhvm: if stype == "html" and stype == oldsitetype and self.app.pargs.hhvm:
Log.info(self, Log.FAIL + "Can not update HTML site to HHVM") Log.info(self, Log.FAIL + "Can not update HTML site to HHVM")
return 1 return 1
if ((stype == 'php' and oldsitetype not in ['html', 'proxy', 'php73']) or if ((stype == 'php' and oldsitetype not in ['html', 'proxy', 'php73']) or
# (stype == 'php73' and oldsitetype not in ['html', 'mysql', 'php', 'php73', 'wp', 'wpsubdir', 'wpsubdomain', ]) or # (stype == 'php73' and oldsitetype not in ['html', 'mysql', 'php', 'php73', 'wp', 'wpsubdir', 'wpsubdomain', ]) or
(stype == 'mysql' and oldsitetype not in ['html', 'php', (stype == 'mysql' and oldsitetype not in ['html', 'php',
'proxy','php73']) or 'proxy', 'php73']) or
(stype == 'wp' and oldsitetype not in ['html', 'php', 'mysql', (stype == 'wp' and oldsitetype not in ['html', 'php', 'mysql',
'proxy', 'wp', 'php73']) or 'proxy', 'wp', 'php73']) or
(stype == 'wpsubdir' and oldsitetype in ['wpsubdomain']) or (stype == 'wpsubdir' and oldsitetype in ['wpsubdomain']) or
(stype == 'wpsubdomain' and oldsitetype in ['wpsubdir']) or (stype == 'wpsubdomain' and oldsitetype in ['wpsubdir']) or
(stype == oldsitetype and cache == oldcachetype) and (stype == oldsitetype and cache == oldcachetype) and
not pargs.php73): not pargs.php73):
Log.info(self, Log.FAIL + "can not update {0} {1} to {2} {3}". Log.info(self, Log.FAIL + "can not update {0} {1} to {2} {3}".
format(oldsitetype, oldcachetype, stype, cache)) format(oldsitetype, oldcachetype, stype, cache))
return 1 return 1
@@ -1038,10 +1045,10 @@ class WOSiteUpdateController(CementBaseController):
data['hhvm'] = False data['hhvm'] = False
hhvm = False hhvm = False
if pargs.php73 == 'on' : if pargs.php73 == 'on':
data['php73'] = True data['php73'] = True
php73 = True php73 = True
check_php_version= '7.3' check_php_version = '7.3'
elif pargs.php73 == 'off': elif pargs.php73 == 'off':
data['php73'] = False data['php73'] = False
php73 = False php73 = False
@@ -1057,64 +1064,73 @@ class WOSiteUpdateController(CementBaseController):
"site") "site")
pargs.php73 = False pargs.php73 = False
#--letsencrypt=renew code goes here # --letsencrypt=renew code goes here
if pargs.letsencrypt == "renew" and not pargs.all: if pargs.letsencrypt == "renew" and not pargs.all:
expiry_days = SSL.getExpirationDays(self,wo_domain) expiry_days = SSL.getExpirationDays(self, wo_domain)
min_expiry_days = 30 min_expiry_days = 30
if check_ssl: if check_ssl:
if (expiry_days <= min_expiry_days): if (expiry_days <= min_expiry_days):
renewLetsEncrypt(self,wo_domain) renewLetsEncrypt(self, wo_domain)
else: else:
Log.error(self,"You have more than 30 days with the current certificate - refusing to run.") Log.error(
self, "You have more than 30 days with the current certificate - refusing to run.")
else: else:
Log.error(self,"Cannot renew - HTTPS is not configured for the given site. Install LE first...") Log.error(
self, "Cannot renew - HTTPS is not configured for the given site. Install LE first...")
if not WOService.reload_service(self, 'nginx'): if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. " Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command") "check issues with `nginx -t` command")
Log.info(self, "SUCCESS: Certificate was successfully renewed For" Log.info(self, "SUCCESS: Certificate was successfully renewed For"
" https://{0}".format(wo_domain)) " https://{0}".format(wo_domain))
if (SSL.getExpirationDays(self,wo_domain)>0): if (SSL.getExpirationDays(self, wo_domain) > 0):
Log.info(self, "Your cert will expire within " + str(SSL.getExpirationDays(self,wo_domain)) + " days.") Log.info(self, "Your cert will expire within " +
Log.info(self, "Expiration date: " + str(SSL.getExpirationDate(self,wo_domain))) str(SSL.getExpirationDays(self, wo_domain)) + " days.")
Log.info(self, "Expiration date: " +
str(SSL.getExpirationDate(self, wo_domain)))
else: else:
Log.warn(self, "The certificate seems to be already expired. Please renew it as soon as possible...") Log.warn(
self, "The certificate seems to be already expired. Please renew it as soon as possible...")
return 0 return 0
if pargs.all and pargs.letsencrypt == "renew": if pargs.all and pargs.letsencrypt == "renew":
if check_ssl: if check_ssl:
expiry_days = SSL.getExpirationDays(self,wo_domain,True) expiry_days = SSL.getExpirationDays(self, wo_domain, True)
if expiry_days < 0: if expiry_days < 0:
return 0 return 0
min_expiry_days = 30 min_expiry_days = 30
if (expiry_days <= min_expiry_days): if (expiry_days <= min_expiry_days):
renewLetsEncrypt(self,wo_domain) renewLetsEncrypt(self, wo_domain)
if not WOService.reload_service(self, 'nginx'): if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. " Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command") "check issues with `nginx -t` command")
Log.info(self, "SUCCESS: Certificate was successfully renewed For" Log.info(self, "SUCCESS: Certificate was successfully renewed For"
" https://{0}".format(wo_domain)) " https://{0}".format(wo_domain))
else: else:
Log.info(self,"You have more than 30 days with the current certificate - refusing to run.\n") Log.info(
self, "You have more than 30 days with the current certificate - refusing to run.\n")
if (SSL.getExpirationDays(self,wo_domain)>0): if (SSL.getExpirationDays(self, wo_domain) > 0):
Log.info(self, "Your cert will expire within " + str(SSL.getExpirationDays(self,wo_domain)) + " days.") Log.info(self, "Your cert will expire within " +
Log.info(self, "Expiration date: \n\n" + str(SSL.getExpirationDate(self,wo_domain))) str(SSL.getExpirationDays(self, wo_domain)) + " days.")
Log.info(self, "Expiration date: \n\n" +
str(SSL.getExpirationDate(self, wo_domain)))
return 0 return 0
#else: # else:
# Log.warn(self, "Your cert already EXPIRED ! .PLEASE renew soon . ") # Log.warn(self, "Your cert already EXPIRED ! .PLEASE renew soon . ")
else: else:
Log.info(self,"SSL not configured for site http://{0}".format(wo_domain)) Log.info(
self, "SSL not configured for site http://{0}".format(wo_domain))
return 0 return 0
if pargs.all and pargs.letsencrypt == "off": if pargs.all and pargs.letsencrypt == "off":
if letsencrypt is check_ssl: if letsencrypt is check_ssl:
if letsencrypt is False: if letsencrypt is False:
Log.error(self, "HTTPS is not configured for given " Log.error(self, "HTTPS is not configured for given "
"site",False) "site", False)
return 0 return 0
pass pass
@@ -1129,10 +1145,10 @@ class WOSiteUpdateController(CementBaseController):
if letsencrypt is check_ssl: if letsencrypt is check_ssl:
if letsencrypt is False: if letsencrypt is False:
Log.error(self, "SSl is not configured for given " Log.error(self, "SSl is not configured for given "
"site") "site")
elif letsencrypt is True: elif letsencrypt is True:
Log.error(self, "SSl is already configured for given " Log.error(self, "SSl is already configured for given "
"site") "site")
pargs.letsencrypt = False pargs.letsencrypt = False
if pargs.hhvm: if pargs.hhvm:
@@ -1162,10 +1178,11 @@ class WOSiteUpdateController(CementBaseController):
data['php73'] = False data['php73'] = False
php73 = False php73 = False
if pargs.hhvm=="on" or pargs.letsencrypt=="on" or pargs.php73=="on": if pargs.hhvm == "on" or pargs.letsencrypt == "on" or pargs.php73 == "on":
if pargs.php73 == "on": if pargs.php73 == "on":
if (not pargs.experimental): if (not pargs.experimental):
Log.info(self, "Do you wish to enable PHP 7.3 now for {0}?".format(wo_domain)) Log.info(
self, "Do you wish to enable PHP 7.3 now for {0}?".format(wo_domain))
check_prompt = input("Type \"y\" to continue [n]:") check_prompt = input("Type \"y\" to continue [n]:")
if check_prompt != "Y" and check_prompt != "y": if check_prompt != "Y" and check_prompt != "y":
@@ -1204,7 +1221,8 @@ class WOSiteUpdateController(CementBaseController):
if (not pargs.experimental): if (not pargs.experimental):
if oldsitetype in ['wpsubdomain']: if oldsitetype in ['wpsubdomain']:
Log.warn(self, "Wildcard domains are not supported in Lets Encrypt.\nWP SUBDOMAIN site will get SSL for primary site only.") Log.warn(
self, "Wildcard domains are not supported in Lets Encrypt.\nWP SUBDOMAIN site will get SSL for primary site only.")
Log.info(self, "Letsencrypt is currently in beta phase." Log.info(self, "Letsencrypt is currently in beta phase."
" \nDo you wish" " \nDo you wish"
@@ -1222,8 +1240,6 @@ class WOSiteUpdateController(CementBaseController):
data['letsencrypt'] = True data['letsencrypt'] = True
letsencrypt = True letsencrypt = True
if pargs.wpredis and data['currcachetype'] != 'wpredis': if pargs.wpredis and data['currcachetype'] != 'wpredis':
if (not pargs.experimental): if (not pargs.experimental):
Log.info(self, "Redis is experimental feature and it may not" Log.info(self, "Redis is experimental feature and it may not"
@@ -1240,7 +1256,7 @@ class WOSiteUpdateController(CementBaseController):
cache = 'basic' cache = 'basic'
if ((hhvm is old_hhvm) and (php73 is old_php73) and if ((hhvm is old_hhvm) and (php73 is old_php73) and
(stype == oldsitetype and cache == oldcachetype)): (stype == oldsitetype and cache == oldcachetype)):
return 1 return 1
if not data: if not data:
@@ -1265,7 +1281,7 @@ class WOSiteUpdateController(CementBaseController):
except Exception as e: except Exception as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.info(self, Log.FAIL + "Check the log for details: " Log.info(self, Log.FAIL + "Check the log for details: "
"`tail /var/log/wo/wordops.log` and please try again") "`tail /var/log/wo/wordops.log` and please try again")
return 1 return 1
# setup NGINX configuration, and webroot # setup NGINX configuration, and webroot
@@ -1274,13 +1290,13 @@ class WOSiteUpdateController(CementBaseController):
except SiteError as e: except SiteError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.info(self, Log.FAIL + "Update site failed." Log.info(self, Log.FAIL + "Update site failed."
"Check the log for details:" "Check the log for details:"
"`tail /var/log/wo/wordops.log` and please try again") "`tail /var/log/wo/wordops.log` and please try again")
return 1 return 1
if 'proxy' in data.keys() and data['proxy']: if 'proxy' in data.keys() and data['proxy']:
updateSiteInfo(self, wo_domain, stype=stype, cache=cache, updateSiteInfo(self, wo_domain, stype=stype, cache=cache,
hhvm=hhvm,ssl=True if check_site.is_ssl else False) hhvm=hhvm, ssl=True if check_site.is_ssl else False)
Log.info(self, "Successfully updated site" Log.info(self, "Successfully updated site"
" http://{0}".format(wo_domain)) " http://{0}".format(wo_domain))
return 0 return 0
@@ -1288,54 +1304,55 @@ class WOSiteUpdateController(CementBaseController):
if pargs.letsencrypt: if pargs.letsencrypt:
if data['letsencrypt'] is True: if data['letsencrypt'] is True:
if not os.path.isfile("{0}/conf/nginx/ssl.conf.disabled" if not os.path.isfile("{0}/conf/nginx/ssl.conf.disabled"
.format(wo_site_webroot)): .format(wo_site_webroot)):
setupLetsEncrypt(self, wo_domain) setupLetsEncrypt(self, wo_domain)
else: else:
WOFileUtils.mvfile(self, "{0}/conf/nginx/ssl.conf.disabled" WOFileUtils.mvfile(self, "{0}/conf/nginx/ssl.conf.disabled"
.format(wo_site_webroot), .format(wo_site_webroot),
'{0}/conf/nginx/ssl.conf' '{0}/conf/nginx/ssl.conf'
.format(wo_site_webroot)) .format(wo_site_webroot))
httpsRedirect(self,wo_domain) httpsRedirect(self, wo_domain)
Log.info(self,"Creating Cron Job for cert auto-renewal") Log.info(self, "Creating Cron Job for cert auto-renewal")
WOCron.setcron_weekly(self,'wo site update --le=renew --all 2> /dev/null'.format(wo_domain),'Renew all' WOCron.setcron_weekly(self, 'wo site update --le=renew --all 2> /dev/null'.format(wo_domain), 'Renew all'
' letsencrypt SSL cert. Set by WordOps') ' letsencrypt SSL cert. Set by WordOps')
if not WOService.reload_service(self, 'nginx'): if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. " Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command") "check issues with `nginx -t` command")
Log.info(self, "Congratulations! Successfully Configured SSl for Site " Log.info(self, "Congratulations! Successfully Configured SSl for Site "
" https://{0}".format(wo_domain)) " https://{0}".format(wo_domain))
if (SSL.getExpirationDays(self,wo_domain)>0): if (SSL.getExpirationDays(self, wo_domain) > 0):
Log.info(self, "Your cert will expire within " + str(SSL.getExpirationDays(self,wo_domain)) + " days.") Log.info(self, "Your cert will expire within " +
str(SSL.getExpirationDays(self, wo_domain)) + " days.")
else: else:
Log.warn(self, "Your cert already EXPIRED ! .PLEASE renew soon . ") Log.warn(
self, "Your cert already EXPIRED ! .PLEASE renew soon . ")
elif data['letsencrypt'] is False: elif data['letsencrypt'] is False:
if os.path.isfile("{0}/conf/nginx/ssl.conf" if os.path.isfile("{0}/conf/nginx/ssl.conf"
.format(wo_site_webroot)): .format(wo_site_webroot)):
Log.info(self,'Setting Nginx configuration') Log.info(self, 'Setting Nginx configuration')
WOFileUtils.mvfile(self, "{0}/conf/nginx/ssl.conf" WOFileUtils.mvfile(self, "{0}/conf/nginx/ssl.conf"
.format(wo_site_webroot), .format(wo_site_webroot),
'{0}/conf/nginx/ssl.conf.disabled' '{0}/conf/nginx/ssl.conf.disabled'
.format(wo_site_webroot)) .format(wo_site_webroot))
httpsRedirect(self,wo_domain,False) httpsRedirect(self, wo_domain, False)
if not WOService.reload_service(self, 'nginx'): if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. " Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command") "check issues with `nginx -t` command")
#Log.info(self,"Removing Cron Job set for cert auto-renewal") # Log.info(self,"Removing Cron Job set for cert auto-renewal")
#WOCron.remove_cron(self,'wo site update {0} --le=renew --min_expiry_limit 30 2> \/dev\/null'.format(wo_domain)) # WOCron.remove_cron(self,'wo site update {0} --le=renew --min_expiry_limit 30 2> \/dev\/null'.format(wo_domain))
Log.info(self, "Successfully Disabled SSl for Site " Log.info(self, "Successfully Disabled SSl for Site "
" http://{0}".format(wo_domain)) " http://{0}".format(wo_domain))
# Add nginx conf folder into GIT # Add nginx conf folder into GIT
WOGit.add(self, ["{0}/conf/nginx".format(wo_site_webroot)], WOGit.add(self, ["{0}/conf/nginx".format(wo_site_webroot)],
msg="Adding letsencrypts config of site: {0}" msg="Adding letsencrypts config of site: {0}"
.format(wo_domain)) .format(wo_domain))
updateSiteInfo(self, wo_domain, ssl=letsencrypt) updateSiteInfo(self, wo_domain, ssl=letsencrypt)
return 0 return 0
@@ -1353,7 +1370,7 @@ class WOSiteUpdateController(CementBaseController):
" http://{0}".format(wo_domain)) " http://{0}".format(wo_domain))
return 0 return 0
#if data['wo_db_name'] and not data['wp']: # if data['wo_db_name'] and not data['wp']:
if 'wo_db_name' in data.keys() and not data['wp']: if 'wo_db_name' in data.keys() and not data['wp']:
try: try:
data = setupdatabase(self, data) data = setupdatabase(self, data)
@@ -1409,10 +1426,11 @@ class WOSiteUpdateController(CementBaseController):
return 1 return 1
if ((oldcachetype in ['wpsc', 'basic', 'wpredis'] and if ((oldcachetype in ['wpsc', 'basic', 'wpredis'] and
(data['wpfc'])) or (oldsitetype == 'wp' and data['multisite'] and data['wpfc'])): (data['wpfc'])) or (oldsitetype == 'wp' and data['multisite'] and data['wpfc'])):
try: try:
plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_fastcgi","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}' plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_fastcgi","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data) setupwp_plugin(
self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
except SiteError as e: except SiteError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.info(self, Log.FAIL + "Update nginx-helper settings failed. " Log.info(self, Log.FAIL + "Update nginx-helper settings failed. "
@@ -1421,10 +1439,11 @@ class WOSiteUpdateController(CementBaseController):
return 1 return 1
elif ((oldcachetype in ['wpsc', 'basic', 'wpfc'] and elif ((oldcachetype in ['wpsc', 'basic', 'wpfc'] and
(data['wpredis'])) or (oldsitetype == 'wp' and data['multisite'] and data['wpredis'])): (data['wpredis'])) or (oldsitetype == 'wp' and data['multisite'] and data['wpredis'])):
try: try:
plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}' plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data) setupwp_plugin(
self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
except SiteError as e: except SiteError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.info(self, Log.FAIL + "Update nginx-helper settings failed. " Log.info(self, Log.FAIL + "Update nginx-helper settings failed. "
@@ -1434,7 +1453,8 @@ class WOSiteUpdateController(CementBaseController):
else: else:
try: try:
plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":0,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}' plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":0,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data) setupwp_plugin(
self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
except SiteError as e: except SiteError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.info(self, Log.FAIL + "Update nginx-helper settings failed. " Log.info(self, Log.FAIL + "Update nginx-helper settings failed. "
@@ -1475,14 +1495,18 @@ class WOSiteUpdateController(CementBaseController):
if oldcachetype != 'wpredis' and data['wpredis']: if oldcachetype != 'wpredis' and data['wpredis']:
try: try:
if installwp_plugin(self, 'redis-cache', data): if installwp_plugin(self, 'redis-cache', data):
#search for wp-config.php # search for wp-config.php
if WOFileUtils.isexist(self,"{0}/wp-config.php".format(wo_site_webroot)): if WOFileUtils.isexist(self, "{0}/wp-config.php".format(wo_site_webroot)):
config_path = '{0}/wp-config.php'.format(wo_site_webroot) config_path = '{0}/wp-config.php'.format(
elif WOFileUtils.isexist(self,"{0}/htdocs/wp-config.php".format(wo_site_webroot)): wo_site_webroot)
config_path = '{0}/htdocs/wp-config.php'.format(wo_site_webroot) elif WOFileUtils.isexist(self, "{0}/htdocs/wp-config.php".format(wo_site_webroot)):
config_path = '{0}/htdocs/wp-config.php'.format(
wo_site_webroot)
else: else:
Log.debug(self, "Updating wp-config.php failed. File could not be located.") Log.debug(
Log.error(self,"wp-config.php could not be located !!") self, "Updating wp-config.php failed. File could not be located.")
Log.error(
self, "wp-config.php could not be located !!")
raise SiteError raise SiteError
if WOShellExec.cmd_exec(self, "grep -q \"WP_CACHE_KEY_SALT\" {0}" if WOShellExec.cmd_exec(self, "grep -q \"WP_CACHE_KEY_SALT\" {0}"
@@ -1491,7 +1515,7 @@ class WOSiteUpdateController(CementBaseController):
else: else:
try: try:
wpconfig = open("{0}".format(config_path), wpconfig = open("{0}".format(config_path),
encoding='utf-8', mode='a') encoding='utf-8', mode='a')
wpconfig.write("\n\ndefine( \'WP_CACHE_KEY_SALT\', \'{0}:\' );" wpconfig.write("\n\ndefine( \'WP_CACHE_KEY_SALT\', \'{0}:\' );"
.format(wo_domain)) .format(wo_domain))
wpconfig.close() wpconfig.close()
@@ -1543,10 +1567,10 @@ class WOSiteUpdateController(CementBaseController):
db_user=data['wo_db_user'], db_user=data['wo_db_user'],
db_password=data['wo_db_pass'], db_password=data['wo_db_pass'],
db_host=data['wo_db_host'], hhvm=hhvm, db_host=data['wo_db_host'], hhvm=hhvm,
ssl=True if check_site.is_ssl else False,php_version=check_php_version) ssl=True if check_site.is_ssl else False, php_version=check_php_version)
else: else:
updateSiteInfo(self, wo_domain, stype=stype, cache=cache, updateSiteInfo(self, wo_domain, stype=stype, cache=cache,
hhvm=hhvm, ssl=True if check_site.is_ssl else False,php_version=check_php_version) hhvm=hhvm, ssl=True if check_site.is_ssl else False, php_version=check_php_version)
Log.info(self, "Successfully updated site" Log.info(self, "Successfully updated site"
" http://{0}".format(wo_domain)) " http://{0}".format(wo_domain))
return 0 return 0
@@ -1564,7 +1588,7 @@ class WOSiteDeleteController(CementBaseController):
(['--no-prompt'], (['--no-prompt'],
dict(help="doesnt ask permission for delete", dict(help="doesnt ask permission for delete",
action='store_true')), action='store_true')),
(['-f','--force'], (['-f', '--force'],
dict(help="forcefully delete site and configuration", dict(help="forcefully delete site and configuration",
action='store_true')), action='store_true')),
(['--all'], (['--all'],
@@ -1573,7 +1597,7 @@ class WOSiteDeleteController(CementBaseController):
dict(help="delete db only", action='store_true')), dict(help="delete db only", action='store_true')),
(['--files'], (['--files'],
dict(help="delete webroot only", action='store_true')), dict(help="delete webroot only", action='store_true')),
] ]
@expose(help="Delete website configuration and files") @expose(help="Delete website configuration and files")
@expose(hide=True) @expose(hide=True)
@@ -1599,7 +1623,7 @@ class WOSiteDeleteController(CementBaseController):
Log.error(self, "site {0} does not exist".format(wo_domain)) Log.error(self, "site {0} does not exist".format(wo_domain))
if ((not self.app.pargs.db) and (not self.app.pargs.files) and if ((not self.app.pargs.db) and (not self.app.pargs.files) and
(not self.app.pargs.all)): (not self.app.pargs.all)):
self.app.pargs.all = True self.app.pargs.all = True
# Gather information from wo-db for wo_domain # Gather information from wo-db for wo_domain
@@ -1636,7 +1660,8 @@ class WOSiteDeleteController(CementBaseController):
mark_db_delete_prompt = True mark_db_delete_prompt = True
Log.info(self, "Deleting Database, {0}, user {1}" Log.info(self, "Deleting Database, {0}, user {1}"
.format(wo_db_name, wo_db_user)) .format(wo_db_name, wo_db_user))
deleteDB(self, wo_db_name, wo_db_user, wo_mysql_grant_host, False) deleteDB(self, wo_db_name, wo_db_user,
wo_mysql_grant_host, False)
updateSiteInfo(self, wo_domain, updateSiteInfo(self, wo_domain,
db_name='deleted', db_name='deleted',
db_user='deleted', db_user='deleted',
@@ -1676,7 +1701,7 @@ class WOSiteDeleteController(CementBaseController):
removeNginxConf(self, wo_domain) removeNginxConf(self, wo_domain)
deleteSiteInfo(self, wo_domain) deleteSiteInfo(self, wo_domain)
Log.info(self, "Deleted site {0}".format(wo_domain)) Log.info(self, "Deleted site {0}".format(wo_domain))
# else: # else:
# Log.error(self, " site {0} does not exists".format(wo_domain)) # Log.error(self, " site {0} does not exists".format(wo_domain))
else: else:
if (mark_db_delete_prompt or mark_webroot_delete_prompt or (mark_webroot_deleted and mark_db_deleted)): if (mark_db_delete_prompt or mark_webroot_delete_prompt or (mark_webroot_deleted and mark_db_deleted)):
@@ -1697,25 +1722,25 @@ class WOSiteListController(CementBaseController):
dict(help='List enabled websites', action='store_true')), dict(help='List enabled websites', action='store_true')),
(['--disabled'], (['--disabled'],
dict(help="List disabled websites", action='store_true')), dict(help="List disabled websites", action='store_true')),
] ]
@expose(help="Lists websites") @expose(help="Lists websites")
def default(self): def default(self):
sites = getAllsites(self) sites = getAllsites(self)
if not sites: if not sites:
pass pass
if self.app.pargs.enabled: if self.app.pargs.enabled:
for site in sites: for site in sites:
if site.is_enabled: if site.is_enabled:
Log.info(self, "{0}".format(site.sitename)) Log.info(self, "{0}".format(site.sitename))
elif self.app.pargs.disabled: elif self.app.pargs.disabled:
for site in sites: for site in sites:
if not site.is_enabled: if not site.is_enabled:
Log.info(self, "{0}".format(site.sitename)) Log.info(self, "{0}".format(site.sitename))
else: else:
for site in sites: for site in sites:
Log.info(self, "{0}".format(site.sitename)) Log.info(self, "{0}".format(site.sitename))
def load(app): def load(app):

View File

@@ -37,7 +37,7 @@ class WOSyncController(CementBaseController):
# Read config files # Read config files
configfiles = glob.glob(wo_site_webroot + '/*-config.php') configfiles = glob.glob(wo_site_webroot + '/*-config.php')
#search for wp-config.php inside htdocs/ # search for wp-config.php inside htdocs/
if not configfiles: if not configfiles:
Log.debug(self, "Config files not found in {0}/ " Log.debug(self, "Config files not found in {0}/ "
.format(wo_site_webroot)) .format(wo_site_webroot))