Browse Source

added sqlite db model

bugfixes
harshadyeola 10 years ago
parent
commit
5748abc5de
  1. 326
      ee/cli/plugins/site.py
  2. 30
      ee/cli/plugins/site_functions.py
  3. 124
      ee/cli/plugins/sitedb.py
  4. 2
      ee/cli/plugins/stack.py
  5. 19
      ee/core/database.py
  6. 40
      ee/core/models.py
  7. 2
      ee/core/services.py
  8. 2
      ee/core/variables.py

326
ee/cli/plugins/site.py

@ -17,7 +17,8 @@ from subprocess import Popen
def ee_site_hook(app): def ee_site_hook(app):
# do something with the ``app`` object here. # do something with the ``app`` object here.
pass from ee.core.database import init_db
init_db()
class EESiteController(CementBaseController): class EESiteController(CementBaseController):
@ -48,8 +49,7 @@ class EESiteController(CementBaseController):
'/etc/nginx/sites-enabled/{0}.conf' '/etc/nginx/sites-enabled/{0}.conf'
.format(ee_domain_name)]) .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))
sys.exit(1)
@expose(help="disable site example.com") @expose(help="disable site example.com")
def disable(self): def disable(self):
@ -62,8 +62,7 @@ class EESiteController(CementBaseController):
'/etc/nginx/sites-enabled/{0}.conf' '/etc/nginx/sites-enabled/{0}.conf'
.format(ee_domain_name)]) .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))
sys.exit(1)
@expose(help="get example.com information") @expose(help="get example.com information")
def info(self): def info(self):
@ -95,8 +94,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))
sys.exit(1)
@expose(help="Monitor example.com logs") @expose(help="Monitor example.com logs")
def log(self): def log(self):
@ -106,8 +104,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))
sys.exit(1)
@expose(help="Edit example.com's nginx configuration") @expose(help="Edit example.com's nginx configuration")
def edit(self): def edit(self):
@ -123,8 +120,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))
sys.exit(1)
@expose(help="Display example.com's nginx configuration") @expose(help="Display example.com's nginx configuration")
def show(self): def show(self):
@ -139,8 +135,7 @@ 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))
sys.exit(1)
@expose(help="list sites currently available") @expose(help="list sites currently available")
def list(self): def list(self):
@ -158,9 +153,8 @@ class EESiteController(CementBaseController):
try: try:
subprocess.call(['bash']) subprocess.call(['bash'])
except OSError as e: except OSError as e:
Log.error(self, "Unable to edit file \ {0}{1}" Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
.format(e.errno, e.strerror)) Log.error(self, "!! cannot change directory")
sys.exit(1)
class EESiteCreateController(CementBaseController): class EESiteCreateController(CementBaseController):
@ -205,9 +199,8 @@ 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)):
self.app.log.error(self, "site {0} already exists" Log.error(self, "!! site {0} already exists"
.format(ee_domain)) .format(ee_domain))
sys.exit(1)
# setup nginx configuration for site # setup nginx configuration for site
# HTML # HTML
@ -425,12 +418,12 @@ class EESiteCreateController(CementBaseController):
data['ee_db_pass'], data['ee_db_pass'],
data['ee_db_host'])) data['ee_db_host']))
eedbconfig.close() eedbconfig.close()
stype = mysql stype = 'mysql'
except IOError as e: except IOError as e:
self.app.log.error("Unable to create ee-config.php for " Log.debug(self, "{2} ({0}): {1}"
"{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 ")
sys.exit(1)
# 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)
@ -492,11 +485,13 @@ 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
print(oldsitetype, oldcachetype)
if (self.app.pargs.html and not (self.app.pargs.php or if (self.app.pargs.html and not (self.app.pargs.php or
self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc or or self.app.pargs.wpfc or self.app.pargs.wpsc or
@ -510,14 +505,17 @@ class EESiteUpdateController(CementBaseController):
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)): self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
if oldsitetype != 'html': if oldsitetype != 'html':
Log.error("Cannot update {0} to php".format(ee_domain))
sys.exit(1) Log.error(self, "!! Cannot update {0} {1} to php"
.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,
static=False, basic=True, wp=False, w3tc=False, static=False, basic=True, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot, wpsubdir=False, webroot=ee_site_webroot,
currsitetype=oldsitetype, currcachetype=oldcachetype) currsitetype=oldsitetype, currcachetype=oldcachetype)
stype = 'php'
cache = 'basic'
#MySQL #MySQL
if (self.app.pargs.mysql and not (self.app.pargs.html or if (self.app.pargs.mysql and not (self.app.pargs.html or
@ -525,9 +523,9 @@ class EESiteUpdateController(CementBaseController):
or self.app.pargs.wpfc or self.app.pargs.wpsc or or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)): self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
if oldsitetype != 'html' or oldsitetype != 'php': if oldsitetype not in ['html', 'php']:
Log.error("Cannot update {0} to mysql".format(ee_domain)) Log.error(self, "!! Cannot update {0}, {1} to mysql"
sys.exit(1) .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,
static=False, basic=True, wp=False, w3tc=False, static=False, basic=True, wp=False, w3tc=False,
@ -536,6 +534,8 @@ class EESiteUpdateController(CementBaseController):
ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'mysql'
cache = 'basic'
#WP #WP
if ((self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or if ((self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or
@ -545,11 +545,11 @@ class EESiteUpdateController(CementBaseController):
if (self.app.pargs.wp and not (self.app.pargs.w3tc if (self.app.pargs.wp and not (self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc)): or self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp'] if ((oldsitetype in ['html', 'php', 'mysql', 'wp'])
and oldsitetype not in ['w3tc', 'wpfc', 'wpsc']): and (oldcachetype not in ['w3tc', 'wpfc', 'wpsc'])):
Log.error("Cannot update {0} to wp basic" print(oldsitetype, oldcachetype)
.format(ee_domain)) Log.error(self, "!! Cannot update {0}, {1} {2} to wp basic"
sys.exit(1) .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,
static=False, basic=True, wp=True, w3tc=False, static=False, basic=True, wp=True, w3tc=False,
@ -558,14 +558,16 @@ class EESiteUpdateController(CementBaseController):
ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wp'
cache = 'basic'
if (self.app.pargs.w3tc and not if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)): (self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp'] if (oldsitetype in ['html', 'php', 'mysql', 'wp']
and oldsitetype not in ['basic', 'wpfc', 'wpsc']): and oldcachetype not in ['basic', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wp w3tc".format(ee_domain)) Log.error(self, "!! Cannot update {0}, {1} {2}to wp w3tc"
sys.exit(1) .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,
static=False, basic=False, wp=True, w3tc=True, static=False, basic=False, wp=True, w3tc=True,
@ -575,13 +577,16 @@ class EESiteUpdateController(CementBaseController):
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wp'
cache = 'w3tc'
if (self.app.pargs.wpfc and not if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)): (self.app.pargs.wpsc or self.app.pargs.w3tc)):
if (oldsitetype not in ['html', 'php', 'wp'] if (oldsitetype in ['html', 'php', 'mysql', 'wp']
and oldsitetype not in ['basic', 'w3tc', 'wpsc']): and oldcachetype not in ['basic', 'w3tc', 'wpsc']):
Log.error("Cannot update {0} to wp wpfc".format(ee_domain)) Log.error(self, "Cannot update {0}, {1} {2} to wp wpfc"
sys.exit(1) .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,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
@ -590,14 +595,16 @@ class EESiteUpdateController(CementBaseController):
ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wp'
cache = 'wpfc'
if (self.app.pargs.wpsc and not if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)): (self.app.pargs.w3tc or self.app.pargs.wpfc)):
if (oldsitetype not in ['html', 'php', 'wp'] if (oldsitetype in ['html', 'php', 'mysql', 'wp']
and oldsitetype not in ['basic', 'w3tc', 'wpfc']): and oldcachetype not in ['basic', 'w3tc', 'wpfc']):
Log.error("Cannot update {0} to wp wpsc".format(ee_domain)) Log.error(self, "Cannot update {0}, {1} {2} to wp wpsc"
sys.exit(1) .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,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
@ -606,6 +613,8 @@ class EESiteUpdateController(CementBaseController):
ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wp'
cache = 'wpsc'
#WPSUBDIR #WPSUBDIR
if (self.app.pargs.wpsubdir and not (self.app.pargs.html or if (self.app.pargs.wpsubdir and not (self.app.pargs.html or
@ -614,11 +623,11 @@ class EESiteUpdateController(CementBaseController):
if (self.app.pargs.wpsubdir and not (self.app.pargs.w3tc if (self.app.pargs.wpsubdir and not (self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc)): or self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir']
and oldsitetype not in ['w3tc', 'wpfc', 'wpsc']): and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdir basic" Log.error(self, "!! Cannot update {0}, {1} {2} "
.format(ee_domain)) "to wpsubdir basic"
sys.exit(1) .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,
static=False, basic=True, wp=True, w3tc=False, static=False, basic=True, wp=True, w3tc=False,
@ -627,15 +636,17 @@ class EESiteUpdateController(CementBaseController):
ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wpsubdir'
cache = 'basic'
if (self.app.pargs.w3tc and not if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)): (self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir']
and oldsitetype not in ['basic', 'wpfc', 'wpsc']): and oldcachetype not in ['basic', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdir w3tc" Log.error(self, "!! Cannot update {0} {1} {2}"
.format(ee_domain)) "to wpsubdir w3tc"
sys.exit(1) .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,
static=False, basic=False, wp=True, w3tc=True, static=False, basic=False, wp=True, w3tc=True,
@ -645,14 +656,17 @@ class EESiteUpdateController(CementBaseController):
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wpsubdir'
cache = 'w3tc'
if (self.app.pargs.wpfc and not if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)): (self.app.pargs.wpsc or self.app.pargs.w3tc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir']
and oldsitetype not in ['basic', 'w3tc', 'wpsc']): and oldcachetype not in ['basic', 'w3tc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdir wpfc" Log.error(self, "!! Cannot update {0} {1} {2}"
.format(ee_domain)) " to wpsubdir wpfc"
sys.exit(1) .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,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
@ -661,15 +675,17 @@ class EESiteUpdateController(CementBaseController):
ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wpsubdir'
cache = 'wpfc'
if (self.app.pargs.wpsc and not if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)): (self.app.pargs.w3tc or self.app.pargs.wpfc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir']
and oldsitetype not in ['basic', 'w3tc', 'wpfc']): and oldcachetype not in ['basic', 'w3tc', 'wpfc']):
Log.error("Cannot update {0} to wpsubdir wpsc" Log.error(self, "!! Cannot update {0} {1} {2}"
.format(ee_domain)) " to wpsubdir wpsc"
sys.exit(1) .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,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
@ -678,16 +694,18 @@ class EESiteUpdateController(CementBaseController):
ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wpsubdir'
cache = 'wpsc'
if (self.app.pargs.wpsubdomain and not (self.app.pargs.html or if (self.app.pargs.wpsubdomain and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.php or self.app.pargs.mysql or
self.app.pargs.wpsubdir or self.app.pargs.wp)): self.app.pargs.wpsubdir or self.app.pargs.wp)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain'] if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdomain']
and oldsitetype not in ['w3tc', 'wpfc', 'wpsc']): and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdomain basic" Log.error(self, "!! Cannot update {0} {1} {2}"
.format(ee_domain)) " to wpsubdomain basic"
sys.exit(1) .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,
static=False, basic=True, wp=True, w3tc=False, static=False, basic=True, wp=True, w3tc=False,
@ -697,14 +715,18 @@ class EESiteUpdateController(CementBaseController):
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wpsubdomain'
cache = 'basic'
if (self.app.pargs.w3tc and not if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)): (self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain'] if (oldsitetype in ['html', 'php', 'mysql', 'wp',
and oldsitetype not in ['basic', 'wpfc', 'wpsc']): 'wpsubdomain']
Log.error("Cannot update {0} to wpsubdomain w3tc" and oldcachetype not in ['basic', 'wpfc', 'wpsc']):
.format(ee_domain)) Log.error(self, "!! Cannot update {0}, {1} {2}"
sys.exit(1) " to wpsubdomain w3tc"
.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,
static=False, basic=False, wp=True, w3tc=True, static=False, basic=False, wp=True, w3tc=True,
@ -714,14 +736,18 @@ class EESiteUpdateController(CementBaseController):
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wpsubdomain'
cache = 'w3tc'
if (self.app.pargs.wpfc and not if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)): (self.app.pargs.wpsc or self.app.pargs.w3tc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain'] if (oldsitetype in ['html', 'php', 'mysql', 'wp',
and oldsitetype not in ['basic', 'w3tc', 'wpsc']): 'wpsubdomain']
Log.error("Cannot update {0} to wpsubdomain wpfc" and oldcachetype not in ['basic', 'w3tc', 'wpsc']):
.format(ee_domain)) Log.error(self, "!! Cannot update {0}, {1} {2} "
sys.exit(1) "to wpsubdomain wpfc"
.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,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
@ -731,14 +757,18 @@ class EESiteUpdateController(CementBaseController):
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
stype = 'wpsubdomain'
cache = 'wpfc'
if (self.app.pargs.wpsc and not if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)): (self.app.pargs.w3tc or self.app.pargs.wpfc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain'] if (oldsitetype in ['html', 'php', 'mysql', 'wp',
and oldsitetype not in ['basic', 'w3tc', 'wpfc']): 'wpsubdomain']
Log.error("Cannot update {0} to wpsubdomain wpsc" and oldcachetype not in ['basic', 'w3tc', 'wpfc']):
.format(ee_domain)) Log.error(self, "!! Cannot update {0}, {1} {2}"
sys.exit(1) " to wpsubdomain wpsc"
.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,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
@ -748,7 +778,12 @@ class EESiteUpdateController(CementBaseController):
ee_db_host='', currsitetype=oldsitetype, ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype) currcachetype=oldcachetype)
# TODO take site backup before site update stype = 'wpsubdomain'
cache = 'wpsc'
if not data:
Log.error(self, "!! Cannot update"
.format(ee_domain))
siteBackup(self, data) siteBackup(self, data)
# TODO Check for required packages before update # TODO Check for required packages before update
@ -769,12 +804,11 @@ class EESiteUpdateController(CementBaseController):
data['ee_db_pass'], data['ee_db_pass'],
data['ee_db_host'])) data['ee_db_host']))
eedbconfig.close() eedbconfig.close()
stype = mysql
except IOError as e: except IOError as e:
self.app.log.error("Unable to create ee-config.php for " Log.error(self, "!! Unable to create ee-config.php for "
"{2} ({0}): {1}" "{0}"
.format(e.errno, e.strerror, ee_domain)) .format(ee_domain))
sys.exit(1) Log.debug(self, "{0} {1}".format(e.errno, e.strerror))
if oldsitetype == 'mysql': if oldsitetype == 'mysql':
config_file = (ee_site_webroot + '/backup/{0}/ee-config.php' config_file = (ee_site_webroot + '/backup/{0}/ee-config.php'
@ -795,24 +829,41 @@ class EESiteUpdateController(CementBaseController):
.split(',')[1] .split(',')[1]
.split(')')[0].strip()) .split(')')[0].strip())
# Setup WordPress if Wordpress site # Setup WordPress if old sites are html/php/mysql sites
if data['wp']: 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)
if (oldcachetype == 'w3tc' or oldcachetype == 'wpfc' and
not data['w3tc', 'wpfc']):
UnInstallWP_Plugin(self, 'w3-total-cache', data)
if oldcachetype == 'wpsc' and not data['wpsc']:
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 != 'wpsc' and data['wpsc']:
InstallWP_Plugin(self, 'wp-super-cache', data)
# Service Nginx Reload # Service Nginx Reload
EEService.reload_service(self, 'nginx') EEService.reload_service(self, 'nginx')
EEGit.add(self, ["/etc/nginx"], EEGit.add(self, ["/etc/nginx"],
msg="{0} created with {1} {2}" msg="{0} updated with {1} {2}"
.format(ee_www_domain, stype, cache)) .format(ee_www_domain, stype, cache))
# Setup Permissions for webroot # Setup Permissions for webroot
SetWebrootPermissions(self, data['webroot']) #SetWebrootPermissions(self, data['webroot'])
if data['wp']:
Log.info(self, '\033[94m'+"WordPress Admin User :" updateSiteInfo(self, ee_www_domain, stype=stype, cache=cache)
" {0}".format(ee_wp_creds['wp_user'])+'\033[0m') Log.info(self, "Successfully updated site"
Log.info(self, "WordPress Admin User Password : {0}"
.format(ee_wp_creds['wp_pass']))
addNewSite(self, ee_www_domain, stype, cache, ee_site_webroot)
Log.info(self, "Successfully created site"
" http://{0}".format(ee_domain)) " http://{0}".format(ee_domain))
@ -836,7 +887,7 @@ class EESiteDeleteController(CementBaseController):
dict(help="delete webroot only", action='store_true')), dict(help="delete webroot only", action='store_true')),
] ]
@expose(help="update example.com") @expose(help="delete example.com")
def default(self): def default(self):
# TODO Write code for ee site update here # TODO Write code for ee site update here
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
@ -851,43 +902,48 @@ class EESiteDeleteController(CementBaseController):
if self.app.pargs.db: if self.app.pargs.db:
if not ee_prompt: if not ee_prompt:
ee_db_prompt = input('Do you want to delete database:[Y/N]' ee_db_prompt = input('Do you want to delete database:'
) '[Y/N] ')
else: else:
ee_db_prompt = 'Y' ee_db_prompt = 'Y'
if ee_db_prompt == 'Y': if ee_db_prompt == 'Y':
deleteDB(ee_site_webroot) self.deleteDB(ee_site_webroot)
if self.app.pargs.files: if self.app.pargs.files:
if not ee_prompt: if not ee_prompt:
ee_web_prompt = input('Do you want to delete webroot:[Y/N]' ee_web_prompt = input('Do you want to delete webroot:'
) '[Y/N] ')
else: else:
ee_web_prompt = 'Y' ee_web_prompt = 'Y'
if ee_web_prompt == 'Y': if ee_web_prompt == 'Y':
deleteWebRoot(ee_site_webroot) self.deleteWebRoot(ee_site_webroot)
if self.app.pargs.all: if self.app.pargs.all:
if not ee_prompt: if not ee_prompt:
ee_db_prompt = input('Do you want to delete database:[Y/N]' ee_db_prompt = input('Do you want to delete database:'
'[Y/N] '
) )
ee_web_prompt = input('Do you want to delete webroot:[Y/N]' ee_web_prompt = input('Do you want to delete webroot:'
) '[Y/N] ')
ee_nginx_prompt = input('Do you want to delete NGINX' ee_nginx_prompt = input('Do you want to delete NGINX'
' configuration:[Y/N]') ' configuration:[Y/N] ')
else: else:
ee_db_prompt = 'Y' ee_db_prompt = 'Y'
ee_web_prompt = 'Y' ee_web_prompt = 'Y'
ee_nginx_prompt = 'Y' ee_nginx_prompt = 'Y'
if ee_db_prompt: if ee_db_prompt == 'Y':
deleteDB(self, ee_site_webroot) self.deleteDB(ee_site_webroot)
if ee_web_prompt: if ee_web_prompt == 'Y':
deleteWebRoot(ee_site_webroot) self.deleteWebRoot(ee_site_webroot)
if ee_nginx_prompt: if ee_nginx_prompt == 'Y':
EEFileutils.delete(self, '/etc/nginx/sites-available/{0}' EEFileUtils.rm(self, '/etc/nginx/sites-available/{0}'
.format(ee_domain)) .format(ee_domain))
deleteSiteInfo(self, ee_domain)
else:
Log.error(self, "!! site {0} does not exists".format(ee_domain))
@expose(hide=True)
def deleteDB(self, webroot): def deleteDB(self, webroot):
configfiles = glob.glob(webroot + '/*-config.php') configfiles = glob.glob(webroot + '/*-config.php')
if configfiles: if configfiles:
@ -904,19 +960,23 @@ class EESiteDeleteController(CementBaseController):
ee_db_host = (EEFileUtils.grep(self, configfiles[0], ee_db_host = (EEFileUtils.grep(self, configfiles[0],
'DB_HOST').split(',')[1] 'DB_HOST').split(',')[1]
.split(')')[0].strip().replace('\'', '')) .split(')')[0].strip().replace('\'', ''))
try:
EEMysql.execute(self,
"drop database {0}"
.format(ee_db_name))
if ee_db_user != 'root':
EEMysql.execute(self,
"drop user {0}@{1}"
.format(ee_db_user, ee_db_host))
EEMysql.execute(self, EEMysql.execute(self,
"flush privileges") "drop database {0}".format(ee_db_name),
errormsg='Unable to drop database {0}'
.format(ee_db_name))
if ee_db_user != 'root':
EEMysql.execute(self,
"drop user {0}@{1}"
.format(ee_db_user, ee_db_host))
EEMysql.execute(self,
"flush privileges")
except Exception as e:
Log.error(self, "!! Error occured while deleting database")
def deleteWebRoot(webroot): @expose(hide=True)
EEFileutils.delete(self, webroot) def deleteWebRoot(self, webroot):
EEFileUtils.rm(self, webroot)
def load(app): def load(app):

30
ee/cli/plugins/site_functions.py

@ -15,7 +15,7 @@ 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("Creating {0} ...".format(ee_domain_name)) self.app.log.info("Setting up NGINX config {0} ...".format(ee_domain_name))
# 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}'
@ -138,9 +138,10 @@ def SetupWordpress(self, data):
ee_wp_user = '' ee_wp_user = ''
ee_wp_pass = '' ee_wp_pass = ''
self.app.log.info("Downloading Wordpress...") 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("[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)
@ -248,8 +249,9 @@ def SetupWordpress(self, data):
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")
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 ''))
@ -271,6 +273,16 @@ def InstallWP_Plugin(self, plugin_name, data):
.format(plugin_name)) .format(plugin_name))
def UnInstallWP_Plugin(self, plugin_name, data):
ee_site_webroot = data['webroot']
self.app.log.debug("Uninstalling plugin {0}".format(plugin_name))
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root uninstall "
"{0}".format(plugin_name),
errormsg="Unable to Install plugin {0}"
.format(plugin_name))
def SetWebrootPermissions(self, webroot): def SetWebrootPermissions(self, webroot):
self.app.log.debug("Setting Up Permissions...") self.app.log.debug("Setting Up Permissions...")
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user, EEFileUtils.chown(self, webroot, EEVariables.ee_php_user,
@ -284,20 +296,24 @@ def siteBackup(self, data):
EEFileUtils.mkdir(self, backup_path) EEFileUtils.mkdir(self, backup_path)
Log.info(self, "Backup Location : {0}".format(backup_path)) Log.info(self, "Backup Location : {0}".format(backup_path))
EEFileUtils.copyfile(self, '/etc/nginx/sites-available/{0}' EEFileUtils.copyfile(self, '/etc/nginx/sites-available/{0}'
.format(data['ee_domain']), 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, "Backup Webroot ...")
EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path) EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path)
configfiles = glob(ee_site_webroot + '/*-config.php') configfiles = glob.glob(ee_site_webroot + '/*-config.php')
if EEFileUtils.isexist(self, configfiles[0]): if EEFileUtils.isexist(self, configfiles[0]):
ee_db_name = (EEFileUtils.grep(self, file, 'DB_NAME').split(',')[1] ee_db_name = (EEFileUtils.grep(self, configfiles[0],
'DB_NAME').split(',')[1]
.split(')')[0].strip().replace('\'', '')) .split(')')[0].strip().replace('\'', ''))
Log.info(self, 'Backup Database, please wait') Log.info(self, 'Backup Database, please wait')
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") "Failed: Backup Database")
# move wp-config.php/ee-config.php to backup # move wp-config.php/ee-config.php to backup
EEFileUtils.mvfile(self, file, backup_path) if data['currsitetype'] in ['mysql']:
EEFileUtils.mvfile(self, configfiles[0], backup_path)
else:
EEFileUtils.copyfile(self, configfiles[0], backup_path)

124
ee/cli/plugins/sitedb.py

@ -4,96 +4,66 @@ from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from ee.core.logging import Log from ee.core.logging import Log
import sys import sys
from ee.core.database import db_session
from ee.core.models import SiteDB
Base = declarative_base()
def addNewSite(self, site, stype, cache, path,
enabled=True, ssl=False, fs='ext4', db='mysql'):
try:
newRec = SiteDB(site, stype, cache, path, enabled, ssl, fs, db)
db_session.add(newRec)
db_session.commit()
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to add site to database")
class SiteDB(Base):
__tablename__ = 'Site'
id = Column(Integer, primary_key=True)
sitename = Column(String, unique=True)
site_type = Column(String) def getSiteInfo(self, site):
cache_type = Column(String) try:
site_path = Column(String) q = SiteDB.query.filter(SiteDB.sitename == site).first()
return q
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database for site info")
# Use default=func.now() to set the default created time
# of a site to be the current time when a
# Site record was created
created_on = Column(DateTime, default=func.now()) def updateSiteInfo(self, site, stype='', cache='',
site_enabled = Column(Boolean, unique=False, default=True, nullable=False) enabled=True, ssl=False, fs='', db=''):
is_ssl = Column(Boolean, unique=False, default=False) try:
storage_fs = Column(String) q = SiteDB.query.filter(SiteDB.sitename == site).first()
storage_db = Column(String) except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database for site info")
if stype and q.site_type != stype:
q.site_type = stype
def __init__(self): if cache and q.cache_type != cache:
# from sqlalchemy import create_engine q.cache_type = cache
# self.engine = create_engine('sqlite:///orm_in_detail.sqlite')
self.sitename = sitename
self.site_type = site_type
self.cache_type = cache_type
self.site_path = site_path
self.created_on = created_on
self.site_enabled = site_enabled
self.is_ssl = is_ssl
self.storage_fs = storage_fs
self.storage_db = storage_db
# if __name__ == "__main__": if enabled and q.is_enabled != enabled:
# q.is_enabled = enabled
# from sqlalchemy import create_engine
# engine = create_engine('sqlite:///orm_in_detail.sqlite')
# from sqlalchemy.orm import sessionmaker
# session = sessionmaker()
# session.configure(bind=engine)
# Base.metadata.create_all(engine)
# s = session()
# newRec = SiteDB(sitename='exa.in', site_type='wp', cache_type='basic',
# site_path='/var/www', site_enabled=True, is_ssl=False, storage_fs='ext4',
# storage_db='mysql')
# s.add(newRec)
# s.commit()
# s.flush()
if ssl and q.is_ssl != ssl:
q.is_ssl = ssl
def addNewSite(self, site, stype, cache, path,
enabled=True, ssl=False, fs='ext4', db='mysql'):
db_path = self.app.config.get('site', 'db_path')
try: try:
from sqlalchemy import create_engine q.created_on = func.now()
engine = create_engine(db_path) db_session.commit()
from sqlalchemy.orm import sessionmaker
session = sessionmaker()
session.configure(bind=engine)
Base.metadata.create_all(engine)
s = session()
newRec = SiteDB(sitename=site, site_type=stype, cache_type=cache,
site_path=path, site_enabled=enabled, is_ssl=ssl,
storage_fs=fs, storage_db=db)
s.add(newRec)
s.commit()
s.flush()
except Exception as e: except Exception as e:
Log.error(self, "Unable to add site to database : {0}" Log.debug(self, "{0}".format(e))
.format(e)) Log.error(self, "Unable to update site info in application database.")
sys.exit(1)
def getSiteInfo(self, site): def deleteSiteInfo(self, site):
db_path = self.app.config.get('site', 'db_path')
try: try:
from sqlalchemy import create_engine q = SiteDB.query.filter(SiteDB.sitename == site).first()
engine = create_engine(db_path) except Exception as e:
from sqlalchemy.orm import sessionmaker Log.debug(self, "{0}".format(e))
session = sessionmaker() Log.error(self, "Unable to query database :")
session.configure(bind=engine) try:
Base.metadata.create_all(engine) db_session.delete(q)
s = session() db_session.commit()
q = s.query(SiteDB).filter_by(sitename=site).first()
s.flush()
return q
except Exception as e: except Exception as e:
Log.error(self, "Unable to add site to database : {0}" Log.debug(self, "{0}".format(e))
.format(e)) Log.error(self, "Unable to delete site from application database.")
sys.exit(1)

2
ee/cli/plugins/stack.py

@ -1042,7 +1042,7 @@ class EEStackController(CementBaseController):
if len(self.msg): if len(self.msg):
for msg in self.msg: for msg in self.msg:
Log.info(self, msg) Log.info(self, msg)
Log.info(self, "Successfully installed packages") Log.info(self, "Successfully installed packages")
@expose() @expose()
def remove(self): def remove(self):

19
ee/core/database.py

@ -0,0 +1,19 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
#db_path = self.app.config.get('site', 'db_path')
engine = create_engine('sqlite:////var/lib/ee/ee.sqlite', convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()
def init_db():
# import all modules here that might define models so that
# they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db()
import ee.core.models
Base.metadata.create_all(bind=engine)

40
ee/core/models.py

@ -0,0 +1,40 @@
from sqlalchemy import Column, DateTime, String, Integer, Boolean, func
from ee.core.database import Base
class SiteDB(Base):
__tablename__ = 'sites'
id = Column(Integer, primary_key=True)
sitename = Column(String, unique=True)
site_type = Column(String)
cache_type = Column(String)
site_path = Column(String)
# Use default=func.now() to set the default created time
# of a site to be the current time when a
# Site record was created
created_on = Column(DateTime, default=func.now())
is_enabled = Column(Boolean, unique=False, default=True, nullable=False)
is_ssl = Column(Boolean, unique=False, default=False)
storage_fs = Column(String)
storage_db = Column(String)
def __init__(self, sitename=None, site_type=None, cache_type=None,
site_path=None, site_enabled=None,
is_ssl=None, storage_fs=None, storage_db=None):
self.sitename = sitename
self.site_type = site_type
self.cache_type = cache_type
self.site_path = site_path
self.is_enabled = site_enabled
self.is_ssl = is_ssl
self.storage_fs = storage_fs
self.storage_db = storage_db
# def __repr__(self):
# return '<Site %r>' % (self.site_type)
#
# def getType(self):
# return '%r>' % (self.site_type)

2
ee/core/services.py

@ -67,7 +67,7 @@ class EEService():
.format(service_name, "[OK]")) .format(service_name, "[OK]"))
return True return True
else: else:
Log.debug("{0}".format(retcode[1])) Log.debug(self, "{0}".format(retcode[1]))
Log.error(self, "reload : {0}".format(service_name)) Log.error(self, "reload : {0}".format(service_name))
return False return False

2
ee/core/variables.py

@ -77,7 +77,7 @@ class EEVariables():
ee_mail = ["dovecot-core", "dovecot-imapd", "dovecot-pop3d", ee_mail = ["dovecot-core", "dovecot-imapd", "dovecot-pop3d",
"dovecot-lmtpd", "dovecot-mysql", "dovecot-sieve", "dovecot-lmtpd", "dovecot-mysql", "dovecot-sieve",
"dovecot-managesieved", "postfix-mysql", "php5-cgi", "dovecot-managesieved", "postfix-mysql", "php5-cgi",
"php5-json", "php-gettext"] "php-gettext"]
# Mailscanner repo and packages # Mailscanner repo and packages
ee_mailscanner_repo = () ee_mailscanner_repo = ()

Loading…
Cancel
Save