Browse Source

updated messages

bugfixes
harshadyeola 10 years ago
parent
commit
5d8923e67a
  1. 165
      ee/cli/plugins/site.py
  2. 117
      ee/cli/plugins/site_functions.py

165
ee/cli/plugins/site.py

@ -35,8 +35,7 @@ class EESiteController(CementBaseController):
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
# TODO Default action for ee site command self.app.args.print_help()
print("Inside EESiteController.default().")
@expose(help="enable site example.com") @expose(help="enable site example.com")
def enable(self): def enable(self):
@ -44,12 +43,13 @@ class EESiteController(CementBaseController):
if os.path.isfile('/etc/nginx/sites-available/{0}' if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)): .format(ee_domain)):
EEFileUtils.create_symlink(self, EEFileUtils.create_symlink(self,
['/etc/nginx/sites-available/{0}.conf' ['/etc/nginx/sites-available/{0}'
.format(ee_domain_name), .format(ee_domain),
'/etc/nginx/sites-enabled/{0}.conf' '/etc/nginx/sites-enabled/{0}'
.format(ee_domain_name)]) .format(ee_domain)])
updateSiteInfo(self, ee_domain, enabled=True)
else: else:
Log.error(self, "!! site {0} does not exists".format(ee_domain)) Log.error(self, " site {0} does not exists".format(ee_domain))
@expose(help="disable site example.com") @expose(help="disable site example.com")
def disable(self): def disable(self):
@ -57,12 +57,11 @@ class EESiteController(CementBaseController):
if os.path.isfile('/etc/nginx/sites-available/{0}' if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)): .format(ee_domain)):
EEFileUtils.remove_symlink(self, EEFileUtils.remove_symlink(self,
['/etc/nginx/sites-available/{0}.conf' '/etc/nginx/sites-enabled/{0}'
.format(ee_domain_name), .format(ee_domain))
'/etc/nginx/sites-enabled/{0}.conf' updateSiteInfo(self, ee_domain, enabled=False)
.format(ee_domain_name)])
else: else:
Log.error(self, "!! site {0} does not exists".format(ee_domain)) Log.error(self, " site {0} does not exists".format(ee_domain))
@expose(help="get example.com information") @expose(help="get example.com information")
def info(self): def info(self):
@ -94,7 +93,7 @@ class EESiteController(CementBaseController):
dbpass=ee_db_pass) dbpass=ee_db_pass)
self.app.render((data), 'siteinfo.mustache') self.app.render((data), 'siteinfo.mustache')
else: else:
Log.error(self, "!! site {0} does not exists".format(ee_domain)) Log.error(self, " site {0} does not exists".format(ee_domain))
@expose(help="Monitor example.com logs") @expose(help="Monitor example.com logs")
def log(self): def log(self):
@ -104,7 +103,7 @@ class EESiteController(CementBaseController):
EEShellExec.cmd_exec(self, 'tail -f /var/log/nginx/{0}.*.log' EEShellExec.cmd_exec(self, 'tail -f /var/log/nginx/{0}.*.log'
.format(ee_domain)) .format(ee_domain))
else: else:
Log.error(self, "!! site {0} does not exists".format(ee_domain)) Log.error(self, " site {0} does not exists".format(ee_domain))
@expose(help="Edit example.com's nginx configuration") @expose(help="Edit example.com's nginx configuration")
def edit(self): def edit(self):
@ -120,7 +119,7 @@ class EESiteController(CementBaseController):
# Reload NGINX # Reload NGINX
EEService.reload_service(self, 'nginx') EEService.reload_service(self, 'nginx')
else: else:
Log.error(self, "!! site {0} does not exists".format(ee_domain)) Log.error(self, " site {0} does not exists".format(ee_domain))
@expose(help="Display example.com's nginx configuration") @expose(help="Display example.com's nginx configuration")
def show(self): def show(self):
@ -135,14 +134,9 @@ class EESiteController(CementBaseController):
print(text) print(text)
f.close() f.close()
else: else:
Log.error(self, "!! site {0} does not exists".format(ee_domain)) Log.error(self, " site {0} does not exists".format(ee_domain))
@expose(help="list sites currently available") @expose(help="change directory to site webroot")
def list(self):
# TODO Write code for ee site list command here
print("Inside EESiteController.list().")
@expose(help="change to example.com's webroot")
def cd(self): def cd(self):
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
@ -154,7 +148,7 @@ class EESiteController(CementBaseController):
subprocess.call(['bash']) subprocess.call(['bash'])
except OSError as e: except OSError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror)) Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "!! cannot change directory") Log.error(self, " cannot change directory")
class EESiteCreateController(CementBaseController): class EESiteCreateController(CementBaseController):
@ -166,31 +160,35 @@ class EESiteCreateController(CementBaseController):
help of the following subcommands' help of the following subcommands'
arguments = [ arguments = [
(['site_name'], (['site_name'],
dict(help='the notorious foo option')), dict(help='domain name for the site to be created.')),
(['--html'], (['--html'],
dict(help="html site", action='store_true')), dict(help="create html site", action='store_true')),
(['--php'], (['--php'],
dict(help="php site", action='store_true')), dict(help="create php site", action='store_true')),
(['--mysql'], (['--mysql'],
dict(help="mysql site", action='store_true')), dict(help="create mysql site", action='store_true')),
(['--wp'], (['--wp'],
dict(help="wordpress site", action='store_true')), dict(help="create wordpress single site",
action='store_true')),
(['--wpsubdir'], (['--wpsubdir'],
dict(help="wpsubdir site", action='store_true')), dict(help="create wordpress multisite with subdirectory setup",
action='store_true')),
(['--wpsubdomain'], (['--wpsubdomain'],
dict(help="wpsubdomain site", action='store_true')), dict(help="create wordpress multisite with subdomain setup",
action='store_true')),
(['--w3tc'], (['--w3tc'],
dict(help="w3tc", action='store_true')), dict(help="create wordpress single/multi site with w3tc cache",
action='store_true')),
(['--wpfc'], (['--wpfc'],
dict(help="wpfc", action='store_true')), dict(help="create wordpress single/multi site with wpfc cache",
action='store_true')),
(['--wpsc'], (['--wpsc'],
dict(help="wpsc", action='store_true')), dict(help="create wordpress single/multi site with wpsc cache",
action='store_true')),
] ]
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
# TODO Default action for ee site command
# data = dict(foo='EESiteCreateController.default().')
# self.app.render((data), 'default.mustache') # self.app.render((data), 'default.mustache')
# Check domain name validation # Check domain name validation
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
@ -199,7 +197,7 @@ class EESiteCreateController(CementBaseController):
# Check if doain previously exists or not # Check if doain previously exists or not
if os.path.isfile('/etc/nginx/sites-available/{0}' if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)): .format(ee_domain)):
Log.error(self, "!! site {0} already exists" Log.error(self, " site {0} already exists"
.format(ee_domain)) .format(ee_domain))
# setup nginx configuration for site # setup nginx configuration for site
@ -401,11 +399,15 @@ class EESiteCreateController(CementBaseController):
stype = 'wpsubdomain' stype = 'wpsubdomain'
cache = 'wpsc' cache = 'wpsc'
if not data:
self.app.args.print_help()
self.app.close(1)
# setup NGINX configuration, and webroot # setup NGINX configuration, and webroot
SetupDomain(self, data) setupDomain(self, data)
# Setup database for MySQL site # Setup database for MySQL site
if 'ee_db_name' in data.keys() and not data['wp']: if 'ee_db_name' in data.keys() and not data['wp']:
data = SetupDatabase(self, data) data = setupDatabase(self, data)
try: try:
eedbconfig = open("{0}/ee-config.php".format(ee_site_webroot), eedbconfig = open("{0}/ee-config.php".format(ee_site_webroot),
'w') 'w')
@ -422,11 +424,11 @@ class EESiteCreateController(CementBaseController):
except IOError as e: except IOError as e:
Log.debug(self, "{2} ({0}): {1}" Log.debug(self, "{2} ({0}): {1}"
.format(e.errno, e.strerror, ee_domain)) .format(e.errno, e.strerror, ee_domain))
Log.error(self, "!! Unable to create ee-config.php for ") Log.error(self, " Unable to create ee-config.php for ")
# Setup WordPress if Wordpress site # Setup WordPress if Wordpress site
if data['wp']: if data['wp']:
ee_wp_creds = SetupWordpress(self, data) ee_wp_creds = setupWordpress(self, data)
# Service Nginx Reload # Service Nginx Reload
EEService.reload_service(self, 'nginx') EEService.reload_service(self, 'nginx')
@ -485,7 +487,7 @@ class EESiteUpdateController(CementBaseController):
check_site = getSiteInfo(self, ee_domain) check_site = getSiteInfo(self, ee_domain)
if check_site is None: if check_site is None:
Log.error(self, "!! Site {0} does not exist.".format(ee_domain)) Log.error(self, " Site {0} does not exist.".format(ee_domain))
else: else:
oldsitetype = check_site.site_type oldsitetype = check_site.site_type
oldcachetype = check_site.cache_type oldcachetype = check_site.cache_type
@ -506,7 +508,7 @@ class EESiteUpdateController(CementBaseController):
if oldsitetype != 'html': if oldsitetype != 'html':
Log.error(self, "!! Cannot update {0} {1} to php" Log.error(self, " Cannot update {0} {1} to php"
.format(ee_domain, oldsitetype)) .format(ee_domain, oldsitetype))
data = dict(site_name=ee_domain, www_domain=ee_www_domain, data = dict(site_name=ee_domain, www_domain=ee_www_domain,
@ -524,7 +526,7 @@ class EESiteUpdateController(CementBaseController):
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)): self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
if oldsitetype not in ['html', 'php']: if oldsitetype not in ['html', 'php']:
Log.error(self, "!! Cannot update {0}, {1} to mysql" Log.error(self, " Cannot update {0}, {1} to mysql"
.format(ee_domain, oldsitetype)) .format(ee_domain, oldsitetype))
data = dict(site_name=ee_domain, www_domain=ee_www_domain, data = dict(site_name=ee_domain, www_domain=ee_www_domain,
@ -548,7 +550,7 @@ class EESiteUpdateController(CementBaseController):
if ((oldsitetype in ['html', 'php', 'mysql', 'wp']) if ((oldsitetype in ['html', 'php', 'mysql', 'wp'])
and (oldcachetype not in ['w3tc', 'wpfc', 'wpsc'])): and (oldcachetype not in ['w3tc', 'wpfc', 'wpsc'])):
print(oldsitetype, oldcachetype) print(oldsitetype, oldcachetype)
Log.error(self, "!! Cannot update {0}, {1} {2} to wp basic" Log.error(self, " Cannot update {0}, {1} {2} to wp basic"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
data = dict(site_name=ee_domain, www_domain=ee_www_domain, data = dict(site_name=ee_domain, www_domain=ee_www_domain,
@ -566,7 +568,7 @@ class EESiteUpdateController(CementBaseController):
if (oldsitetype in ['html', 'php', 'mysql', 'wp'] if (oldsitetype in ['html', 'php', 'mysql', 'wp']
and oldcachetype not in ['basic', 'wpfc', 'wpsc']): and oldcachetype not in ['basic', 'wpfc', 'wpsc']):
Log.error(self, "!! Cannot update {0}, {1} {2}to wp w3tc" Log.error(self, " Cannot update {0}, {1} {2}to wp w3tc"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
data = dict(site_name=ee_domain, www_domain=ee_www_domain, data = dict(site_name=ee_domain, www_domain=ee_www_domain,
@ -625,7 +627,7 @@ class EESiteUpdateController(CementBaseController):
if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir']
and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']): and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']):
Log.error(self, "!! Cannot update {0}, {1} {2} " Log.error(self, " Cannot update {0}, {1} {2} "
"to wpsubdir basic" "to wpsubdir basic"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
@ -644,7 +646,7 @@ class EESiteUpdateController(CementBaseController):
if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir']
and oldcachetype not in ['basic', 'wpfc', 'wpsc']): and oldcachetype not in ['basic', 'wpfc', 'wpsc']):
Log.error(self, "!! Cannot update {0} {1} {2}" Log.error(self, " Cannot update {0} {1} {2}"
"to wpsubdir w3tc" "to wpsubdir w3tc"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
@ -664,7 +666,7 @@ class EESiteUpdateController(CementBaseController):
if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir']
and oldcachetype not in ['basic', 'w3tc', 'wpsc']): and oldcachetype not in ['basic', 'w3tc', 'wpsc']):
Log.error(self, "!! Cannot update {0} {1} {2}" Log.error(self, " Cannot update {0} {1} {2}"
" to wpsubdir wpfc" " to wpsubdir wpfc"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
@ -683,7 +685,7 @@ class EESiteUpdateController(CementBaseController):
if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir']
and oldcachetype not in ['basic', 'w3tc', 'wpfc']): and oldcachetype not in ['basic', 'w3tc', 'wpfc']):
Log.error(self, "!! Cannot update {0} {1} {2}" Log.error(self, " Cannot update {0} {1} {2}"
" to wpsubdir wpsc" " to wpsubdir wpsc"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
@ -703,7 +705,7 @@ class EESiteUpdateController(CementBaseController):
if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdomain'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdomain']
and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']): and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']):
Log.error(self, "!! Cannot update {0} {1} {2}" Log.error(self, " Cannot update {0} {1} {2}"
" to wpsubdomain basic" " to wpsubdomain basic"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
@ -724,7 +726,7 @@ class EESiteUpdateController(CementBaseController):
if (oldsitetype in ['html', 'php', 'mysql', 'wp', if (oldsitetype in ['html', 'php', 'mysql', 'wp',
'wpsubdomain'] 'wpsubdomain']
and oldcachetype not in ['basic', 'wpfc', 'wpsc']): and oldcachetype not in ['basic', 'wpfc', 'wpsc']):
Log.error(self, "!! Cannot update {0}, {1} {2}" Log.error(self, " Cannot update {0}, {1} {2}"
" to wpsubdomain w3tc" " to wpsubdomain w3tc"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
@ -745,7 +747,7 @@ class EESiteUpdateController(CementBaseController):
if (oldsitetype in ['html', 'php', 'mysql', 'wp', if (oldsitetype in ['html', 'php', 'mysql', 'wp',
'wpsubdomain'] 'wpsubdomain']
and oldcachetype not in ['basic', 'w3tc', 'wpsc']): and oldcachetype not in ['basic', 'w3tc', 'wpsc']):
Log.error(self, "!! Cannot update {0}, {1} {2} " Log.error(self, " Cannot update {0}, {1} {2} "
"to wpsubdomain wpfc" "to wpsubdomain wpfc"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
@ -766,7 +768,7 @@ class EESiteUpdateController(CementBaseController):
if (oldsitetype in ['html', 'php', 'mysql', 'wp', if (oldsitetype in ['html', 'php', 'mysql', 'wp',
'wpsubdomain'] 'wpsubdomain']
and oldcachetype not in ['basic', 'w3tc', 'wpfc']): and oldcachetype not in ['basic', 'w3tc', 'wpfc']):
Log.error(self, "!! Cannot update {0}, {1} {2}" Log.error(self, " Cannot update {0}, {1} {2}"
" to wpsubdomain wpsc" " to wpsubdomain wpsc"
.format(ee_domain, oldsitetype, oldcachetype)) .format(ee_domain, oldsitetype, oldcachetype))
@ -782,16 +784,16 @@ class EESiteUpdateController(CementBaseController):
cache = 'wpsc' cache = 'wpsc'
if not data: if not data:
Log.error(self, "!! Cannot update" Log.error(self, " Cannot update"
.format(ee_domain)) .format(ee_domain))
siteBackup(self, data) siteBackup(self, data)
# TODO Check for required packages before update # TODO Check for required packages before update
# setup NGINX configuration, and webroot # setup NGINX configuration, and webroot
SetupDomain(self, data) setupDomain(self, data)
if 'ee_db_name' in data.keys() and not data['wp']: if 'ee_db_name' in data.keys() and not data['wp']:
data = SetupDatabase(self, data) data = setupDatabase(self, data)
try: try:
eedbconfig = open("{0}/ee-config.php".format(ee_site_webroot), eedbconfig = open("{0}/ee-config.php".format(ee_site_webroot),
'w') 'w')
@ -805,7 +807,7 @@ class EESiteUpdateController(CementBaseController):
data['ee_db_host'])) data['ee_db_host']))
eedbconfig.close() eedbconfig.close()
except IOError as e: except IOError as e:
Log.error(self, "!! Unable to create ee-config.php for " Log.error(self, " Unable to create ee-config.php for "
"{0}" "{0}"
.format(ee_domain)) .format(ee_domain))
Log.debug(self, "{0} {1}".format(e.errno, e.strerror)) Log.debug(self, "{0} {1}".format(e.errno, e.strerror))
@ -831,27 +833,27 @@ class EESiteUpdateController(CementBaseController):
# Setup WordPress if old sites are html/php/mysql sites # Setup WordPress if old sites are html/php/mysql sites
if data['wp'] and oldsitetype in ['html', 'php', 'mysql']: if data['wp'] and oldsitetype in ['html', 'php', 'mysql']:
ee_wp_creds = SetupWordpress(self, data) ee_wp_creds = setupWordpress(self, data)
# Uninstall unnecessary plugins # Uninstall unnecessary plugins
if oldsitetype in ['wp', 'wpsubdir', 'wpsubdomain']: if oldsitetype in ['wp', 'wpsubdir', 'wpsubdomain']:
# Setup WordPress Network if update option is multisite # Setup WordPress Network if update option is multisite
# and oldsite is WordPress single site # and oldsite is WordPress single site
if data['multisite'] and oldsitetype == 'wp': if data['multisite'] and oldsitetype == 'wp':
SetupWordpressNetwork(self, data) setupWordpressNetwork(self, data)
if (oldcachetype == 'w3tc' or oldcachetype == 'wpfc' and if (oldcachetype == 'w3tc' or oldcachetype == 'wpfc' and
not data['w3tc', 'wpfc']): not data['w3tc', 'wpfc']):
UnInstallWP_Plugin(self, 'w3-total-cache', data) uninstallWP_Plugin(self, 'w3-total-cache', data)
if oldcachetype == 'wpsc' and not data['wpsc']: if oldcachetype == 'wpsc' and not data['wpsc']:
UnInstallWP_Plugin(self, 'wp-super-cache', data) uninstallWP_Plugin(self, 'wp-super-cache', data)
if oldcachetype != 'w3tc' or oldcachetype != 'wpfc'and data['w3tc']: if (oldcachetype != 'w3tc' or oldcachetype != 'wpfc') and data['w3tc']:
InstallWP_Plugin(self, 'w3-total-cache', data) installWP_Plugin(self, 'w3-total-cache', data)
if oldcachetype != 'wpsc' and data['wpsc']: if oldcachetype != 'wpsc' and data['wpsc']:
InstallWP_Plugin(self, 'wp-super-cache', data) installWP_Plugin(self, 'wp-super-cache', data)
# Service Nginx Reload # Service Nginx Reload
EEService.reload_service(self, 'nginx') EEService.reload_service(self, 'nginx')
@ -941,7 +943,7 @@ class EESiteDeleteController(CementBaseController):
.format(ee_domain)) .format(ee_domain))
deleteSiteInfo(self, ee_domain) deleteSiteInfo(self, ee_domain)
else: else:
Log.error(self, "!! site {0} does not exists".format(ee_domain)) Log.error(self, " site {0} does not exists".format(ee_domain))
@expose(hide=True) @expose(hide=True)
def deleteDB(self, webroot): def deleteDB(self, webroot):
@ -972,19 +974,48 @@ class EESiteDeleteController(CementBaseController):
EEMysql.execute(self, EEMysql.execute(self,
"flush privileges") "flush privileges")
except Exception as e: except Exception as e:
Log.error(self, "!! Error occured while deleting database") Log.error(self, " Error occured while deleting database")
@expose(hide=True) @expose(hide=True)
def deleteWebRoot(self, webroot): def deleteWebRoot(self, webroot):
EEFileUtils.rm(self, webroot) EEFileUtils.rm(self, webroot)
class EESiteListController(CementBaseController):
class Meta:
label = 'list'
stacked_on = 'site'
stacked_type = 'nested'
description = 'list websites'
arguments = [
(['--enabled'],
dict(help='list enabled sites', action='store_true')),
(['--disabled'],
dict(help="list disabled sites", action='store_true')),
]
@expose(help="delete example.com")
def default(self):
sites = getAllsites(self)
if not sites:
self.app.close(1)
if self.app.pargs.enabled:
for site in sites:
if site.is_enabled:
Log.info(self, "{0}".format(site.sitename))
elif self.app.pargs.disabled:
for site in sites:
if not site.is_enabled:
Log.info(self, "{0}".format(site.sitename))
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(EESiteController) handler.register(EESiteController)
handler.register(EESiteCreateController) handler.register(EESiteCreateController)
handler.register(EESiteUpdateController) handler.register(EESiteUpdateController)
handler.register(EESiteDeleteController) handler.register(EESiteDeleteController)
handler.register(EESiteListController)
# register a hook (function) to run after arguments are parsed. # register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', ee_site_hook) hook.register('post_argument_parsing', ee_site_hook)

117
ee/cli/plugins/site_functions.py

@ -11,11 +11,11 @@ from ee.core.logging import Log
import glob import glob
def SetupDomain(self, data): def setupDomain(self, data):
ee_domain_name = data['site_name'] ee_domain_name = data['site_name']
ee_site_webroot = data['webroot'] ee_site_webroot = data['webroot']
self.app.log.info("Setting up NGINX config {0} ...".format(ee_domain_name)) Log.info(self, "Setting up NGINX configuration ", end='')
# write nginx config for file # write nginx config for file
try: try:
ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}' ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}'
@ -25,12 +25,12 @@ def SetupDomain(self, data):
out=ee_site_nginx_conf) out=ee_site_nginx_conf)
ee_site_nginx_conf.close() ee_site_nginx_conf.close()
except IOError as e: except IOError as e:
Log.error(self, "Unable to create nginx conf for {2} ({0}): {1}" Log.debug(self, "{0}".format(e))
.format(e.errno, e.strerror, ee_domain_name)) Log.error(self, "\nUnable to create NGINX configuration")
sys.exit(1)
except Exception as e: except Exception as e:
Log.error(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
sys.exit(1) Log.error(self, "\nUnable to create NGINX configuration")
Log.info(self, "[Done]")
# create symbolic link for # create symbolic link for
EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available/{0}' EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available/{0}'
@ -39,14 +39,15 @@ def SetupDomain(self, data):
.format(ee_domain_name)]) .format(ee_domain_name)])
# Creating htdocs & logs directory # Creating htdocs & logs directory
Log.info(self, "Setting up webroot ", end='')
try: try:
if not os.path.exists('{0}/htdocs'.format(ee_site_webroot)): if not os.path.exists('{0}/htdocs'.format(ee_site_webroot)):
os.makedirs('{0}/htdocs'.format(ee_site_webroot)) os.makedirs('{0}/htdocs'.format(ee_site_webroot))
if not os.path.exists('{0}/logs'.format(ee_site_webroot)): if not os.path.exists('{0}/logs'.format(ee_site_webroot)):
os.makedirs('{0}/logs'.format(ee_site_webroot)) os.makedirs('{0}/logs'.format(ee_site_webroot))
except Exception as e: except Exception as e:
Log.error(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
sys.exit(1) Log.error(self, "\nUnable to setup webroot")
EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log' EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log'
.format(ee_domain_name), .format(ee_domain_name),
@ -56,9 +57,10 @@ def SetupDomain(self, data):
.format(ee_domain_name), .format(ee_domain_name),
'{0}/logs/error.log' '{0}/logs/error.log'
.format(ee_site_webroot)]) .format(ee_site_webroot)])
Log.info(self, "[Done]")
def SetupDatabase(self, data): def setupDatabase(self, data):
ee_domain_name = data['site_name'] ee_domain_name = data['site_name']
ee_random = (''.join(random.sample(string.ascii_uppercase + ee_random = (''.join(random.sample(string.ascii_uppercase +
string.ascii_lowercase + string.digits, 15))) string.ascii_lowercase + string.digits, 15)))
@ -75,8 +77,8 @@ def SetupDatabase(self, data):
ee_db_name = input('Enter the MySQL database name [{0}]:' ee_db_name = input('Enter the MySQL database name [{0}]:'
.format(ee_replace_dot)) .format(ee_replace_dot))
except EOFError as e: except EOFError as e:
Log.error(self, "{0} {1}".format(e.errorno, e.strerror)) Log.debug(self, "{0}".format(e))
sys.exit(0) Log.error(self, "Unable to input database name")
if not ee_db_name: if not ee_db_name:
ee_db_name = ee_replace_dot ee_db_name = ee_replace_dot
@ -88,8 +90,8 @@ def SetupDatabase(self, data):
ee_db_password = input('Enter the MySQL database password [{0}]: ' ee_db_password = input('Enter the MySQL database password [{0}]: '
.format(ee_random)) .format(ee_random))
except EOFError as e: except EOFError as e:
Log.error(self, "{0} {1}".format(e.errorno, e.strerror)) Log.debug(self, "{0}".format(e))
sys.exit(1) Log.error(self, "Unable to input database credentials")
if not ee_db_username: if not ee_db_username:
ee_db_username = ee_replace_dot ee_db_username = ee_replace_dot
@ -97,26 +99,31 @@ def SetupDatabase(self, data):
ee_db_password = ee_random ee_db_password = ee_random
if len(ee_db_username) > 16: if len(ee_db_username) > 16:
self.app.log.info('Autofix MySQL username (ERROR 1470 (HY000)),' Log.info(self, 'Autofix MySQL username (ERROR 1470 (HY000)),'
' please wait...') ' please wait...')
ee_random10 = (''.join(random.sample(string.ascii_uppercase + ee_random10 = (''.join(random.sample(string.ascii_uppercase +
string.ascii_lowercase + string.digits, 10))) string.ascii_lowercase + string.digits, 10)))
ee_db_name = (ee_db_name[0:6] + ee_random10) ee_db_name = (ee_db_name[0:6] + ee_random10)
# create MySQL database # create MySQL database
self.app.log.info("Setting Up Database ...") Log.info(self, "Setting Up Database ", end='')
Log.debug(self, "creating databse {0}".format(ee_db_name))
EEMysql.execute(self, "create database {0}" EEMysql.execute(self, "create database {0}"
.format(ee_db_name)) .format(ee_db_name))
# Create MySQL User # Create MySQL User
Log.debug(self, "creating user {0}".format(ee_db_username))
EEMysql.execute(self, EEMysql.execute(self,
"create user {0}@{1} identified by '{2}'" "create user {0}@{1} identified by '{2}'"
.format(ee_db_username, ee_mysql_host, ee_db_password)) .format(ee_db_username, ee_mysql_host, ee_db_password))
# Grant permission # Grant permission
Log.debug(self, "setting up user privileges")
EEMysql.execute(self, EEMysql.execute(self,
"grant all privileges on {0}.* to {1}@{2}" "grant all privileges on {0}.* to {1}@{2}"
.format(ee_db_name, ee_db_username, ee_mysql_host)) .format(ee_db_name, ee_db_username, ee_mysql_host))
Log.info(self, "[Done]")
data['ee_db_name'] = ee_db_name data['ee_db_name'] = ee_db_name
data['ee_db_user'] = ee_db_username data['ee_db_user'] = ee_db_username
data['ee_db_pass'] = ee_db_password data['ee_db_pass'] = ee_db_password
@ -124,7 +131,7 @@ def SetupDatabase(self, data):
return(data) return(data)
def SetupWordpress(self, data): def setupWordpress(self, data):
ee_domain_name = data['site_name'] ee_domain_name = data['site_name']
ee_site_webroot = data['webroot'] ee_site_webroot = data['webroot']
prompt_wpprefix = self.app.config.get('wordpress', 'prefix') prompt_wpprefix = self.app.config.get('wordpress', 'prefix')
@ -138,25 +145,25 @@ def SetupWordpress(self, data):
ee_wp_user = '' ee_wp_user = ''
ee_wp_pass = '' ee_wp_pass = ''
Log.info(self, "Downloading Wordpress...", end='') Log.info(self, "Downloading Wordpress ", end='')
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "wp --allow-root core download") EEShellExec.cmd_exec(self, "wp --allow-root core download")
Log.info(self, "[Done]") Log.info(self, "[Done]")
if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']): if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']):
data = SetupDatabase(self, data) data = setupDatabase(self, data)
if prompt_wpprefix == 'True' or prompt_wpprefix == 'true': if prompt_wpprefix == 'True' or prompt_wpprefix == 'true':
try: try:
ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ' ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: '
.format(ee_replace_dot)) .format(ee_replace_dot))
while re.match('^[A-Za-z0-9_]*$', ee_wp_prefix): while re.match('^[A-Za-z0-9_]*$', ee_wp_prefix):
self.app.log.warn("table prefix can only " Log.warn(self, "table prefix can only "
"contain numbers, letters, and underscores") "contain numbers, letters, and underscores")
ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ' ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: '
) )
except EOFError as e: except EOFError as e:
Log.error(self, "{0} {1}".format(e.errorno, e.strerror)) Log.debug(self, "{0}".format(e))
sys.exit(1) Log.error(self, "Unable to input table prefix")
if not ee_wp_prefix: if not ee_wp_prefix:
ee_wp_prefix = 'wp_' ee_wp_prefix = 'wp_'
@ -164,14 +171,16 @@ def SetupWordpress(self, data):
# Modify wp-config.php & move outside the webroot # Modify wp-config.php & move outside the webroot
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
self.app.log.debug("Setting Up WordPress Configuration...") Log.debug(self, "Setting up wp-config file")
if not data['multisite']: if not data['multisite']:
Log.debug(self, "Generating wp-config for WordPress Single site")
EEShellExec.cmd_exec(self, "wp --allow-root core config " EEShellExec.cmd_exec(self, "wp --allow-root core config "
+ "--dbname={0} --dbprefix={1} --dbuser={2} " + "--dbname={0} --dbprefix={1} --dbuser={2} "
.format(data['ee_db_name'], ee_wp_prefix, .format(data['ee_db_name'], ee_wp_prefix,
data['ee_db_user']) data['ee_db_user'])
+ "--dbpass={0}".format(data['ee_db_pass'])) + "--dbpass={0}".format(data['ee_db_pass']))
else: else:
Log.debug(self, "Generating wp-config for WordPress multisite")
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core config " EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core config "
+ "--dbname={0} --dbprefix={1} " + "--dbname={0} --dbprefix={1} "
.format(data['ee_db_name'], ee_wp_prefix) .format(data['ee_db_name'], ee_wp_prefix)
@ -183,16 +192,19 @@ def SetupWordpress(self, data):
var2= var2=
"\n define('WPMU_ACCEL_REDIRECT', true);") "\n define('WPMU_ACCEL_REDIRECT', true);")
) )
EEFileUtils.mvfile(self, './wp-config.php', '../') EEFileUtils.mvfile(self, './wp-config.php', '../')
if not ee_wp_user: if not ee_wp_user:
ee_wp_user = EEVariables.ee_user ee_wp_user = EEVariables.ee_user
while not ee_wp_user: while not ee_wp_user:
self.app.log.warn("Usernames can have only alphanumeric" Log.warn(self, "Usernames can have only alphanumeric"
"characters, spaces, underscores, hyphens," "characters, spaces, underscores, hyphens,"
"periods and the @ symbol.") "periods and the @ symbol.")
ee_wp_user = input('Enter WordPress username: ') try:
ee_wp_user = input('Enter WordPress username: ')
except EOFError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to input wp user name")
if not ee_wp_pass: if not ee_wp_pass:
ee_wp_pass = ee_random ee_wp_pass = ee_random
@ -200,11 +212,16 @@ def SetupWordpress(self, data):
if not ee_wp_email: if not ee_wp_email:
ee_wp_email = EEVariables.ee_email ee_wp_email = EEVariables.ee_email
while not ee_wp_email: while not ee_wp_email:
ee_wp_email = input('Enter WordPress email: ') try:
ee_wp_email = input('Enter WordPress email: ')
except EOFError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to input wp user email")
self.app.log.debug("Setting up WordPress Tables, please wait...") Log.debug(self, "setting up WordPress Tables")
if not data['multisite']: if not data['multisite']:
Log.debug(self, "creating tables for WordPress Single site")
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core install " EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core install "
"--url={0} --title={0} --admin_name={1} " "--url={0} --title={0} --admin_name={1} "
.format(data['www_domain'], ee_wp_user) .format(data['www_domain'], ee_wp_user)
@ -212,6 +229,7 @@ def SetupWordpress(self, data):
.format(ee_wp_pass, ee_wp_email), .format(ee_wp_pass, ee_wp_email),
errormsg="Unable to setup WordPress Tables") errormsg="Unable to setup WordPress Tables")
else: else:
Log.debug(self, "creating tables for WordPress multisite")
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root " EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root "
"core multisite-install " "core multisite-install "
"--url={0} --title={0} --admin_name={1} " "--url={0} --title={0} --admin_name={1} "
@ -223,22 +241,22 @@ def SetupWordpress(self, data):
if not data['wpsubdir'] else ''), if not data['wpsubdir'] else ''),
errormsg="Unable to setup WordPress Tables") errormsg="Unable to setup WordPress Tables")
self.app.log.debug("Updating WordPress permalink, please wait...") Log.debug(self, "Updating WordPress permalink")
EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root " EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root "
"rewrite structure " "rewrite structure "
"/%year%/%monthnum%/%day%/%postname%/", "/%year%/%monthnum%/%day%/%postname%/",
errormsg="Unable to Update WordPress permalink") errormsg="Unable to Update WordPress permalink")
"""Install nginx-helper plugin """ """Install nginx-helper plugin """
InstallWP_Plugin(self, 'nginx-helper', data) installWP_Plugin(self, 'nginx-helper', data)
"""Install Wp Super Cache""" """Install Wp Super Cache"""
if data['wpsc']: if data['wpsc']:
InstallWP_Plugin(self, 'wp-super-cache', data) installWP_Plugin(self, 'wp-super-cache', data)
"""Install W3 Total Cache""" """Install W3 Total Cache"""
if data['w3tc'] or data['wpfc']: if data['w3tc'] or data['wpfc']:
InstallWP_Plugin(self, 'w3-total-cache', data) installWP_Plugin(self, 'w3-total-cache', data)
wp_creds = dict(wp_user=ee_wp_user, wp_pass=ee_wp_pass, wp_creds = dict(wp_user=ee_wp_user, wp_pass=ee_wp_pass,
wp_email=ee_wp_email) wp_email=ee_wp_email)
@ -246,19 +264,20 @@ def SetupWordpress(self, data):
return(wp_creds) return(wp_creds)
def SetupWordpressNetwork(self, data): def setupWordpressNetwork(self, data):
ee_site_webroot = data['webroot'] ee_site_webroot = data['webroot']
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
Log.info(self, "Setting up WordPress Network") Log.info(self, "Setting up WordPress Network ", end='')
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert' EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert'
' --title={0} {subdomains}' ' --title={0} {subdomains}'
.format(data['www_domain'], subdomains='--subdomains' .format(data['www_domain'], subdomains='--subdomains'
if not data['wpsubdir'] else '')) if not data['wpsubdir'] else ''))
Log.info(self, "Done")
def InstallWP_Plugin(self, plugin_name, data): def installWP_Plugin(self, plugin_name, data):
ee_site_webroot = data['webroot'] ee_site_webroot = data['webroot']
self.app.log.debug("Installing plugin {0}".format(plugin_name)) Log.debug(self, "Installing plugin {0}".format(plugin_name))
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root install " EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root install "
"{0}".format(plugin_name), "{0}".format(plugin_name),
@ -273,18 +292,18 @@ def InstallWP_Plugin(self, plugin_name, data):
.format(plugin_name)) .format(plugin_name))
def UnInstallWP_Plugin(self, plugin_name, data): def uninstallWP_Plugin(self, plugin_name, data):
ee_site_webroot = data['webroot'] ee_site_webroot = data['webroot']
self.app.log.debug("Uninstalling plugin {0}".format(plugin_name)) Log.debug(self, "Uninstalling plugin {0}".format(plugin_name))
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root uninstall " EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root uninstall "
"{0}".format(plugin_name), "{0}".format(plugin_name),
errormsg="Unable to Install plugin {0}" errormsg="Unable to UnInstall plugin {0}"
.format(plugin_name)) .format(plugin_name))
def SetWebrootPermissions(self, webroot): def SetWebrootPermissions(self, webroot):
self.app.log.debug("Setting Up Permissions...") Log.debug(self, "Setting Up Permissions...")
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user, EEFileUtils.chown(self, webroot, EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True) EEVariables.ee_php_user, recursive=True)
@ -299,19 +318,21 @@ def siteBackup(self, data):
.format(data['site_name']), backup_path) .format(data['site_name']), backup_path)
if data['currsitetype'] in ['html', 'php', 'mysql']: if data['currsitetype'] in ['html', 'php', 'mysql']:
Log.info(self, "Backup Webroot ...") Log.info(self, "Backing up Webroot ", end='')
EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path) EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path)
Log.info(self, "[Done]")
configfiles = glob.glob(ee_site_webroot + '/*-config.php') configfiles = glob.glob(ee_site_webroot + '/*-config.php')
if EEFileUtils.isexist(self, configfiles[0]): if configfiles and EEFileUtils.isexist(self, configfiles[0]):
ee_db_name = (EEFileUtils.grep(self, configfiles[0], ee_db_name = (EEFileUtils.grep(self, configfiles[0],
'DB_NAME').split(',')[1] 'DB_NAME').split(',')[1]
.split(')')[0].strip().replace('\'', '')) .split(')')[0].strip().replace('\'', ''))
Log.info(self, 'Backup Database, please wait') Log.info(self, 'Backing up Database ', end='')
EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql" EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql"
.format(ee_db_name, backup_path), .format(ee_db_name, backup_path),
"Failed: Backup Database") errormsg="\nFailed: Backup Database")
Log.info(self, "[Done]")
# move wp-config.php/ee-config.php to backup # move wp-config.php/ee-config.php to backup
if data['currsitetype'] in ['mysql']: if data['currsitetype'] in ['mysql']:
EEFileUtils.mvfile(self, configfiles[0], backup_path) EEFileUtils.mvfile(self, configfiles[0], backup_path)

Loading…
Cancel
Save