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