Browse Source

merge conflict resolved python => master

bugfixes
harshadyeola 10 years ago
parent
commit
1ac085d0f6
  1. 10
      README.md
  2. 4
      config/bash_completion.d/ee_auto.rc
  3. 8
      config/plugins.d/update.conf
  4. 42
      docs/ee.8
  5. 5
      ee/cli/plugins/clean.py
  6. 35
      ee/cli/plugins/debug.py
  7. 5
      ee/cli/plugins/import_slow_log.py
  8. 5
      ee/cli/plugins/info.py
  9. 5
      ee/cli/plugins/log.py
  10. 18
      ee/cli/plugins/models.py
  11. 5
      ee/cli/plugins/secure.py
  12. 1076
      ee/cli/plugins/site.py
  13. 511
      ee/cli/plugins/site_functions.py
  14. 79
      ee/cli/plugins/sitedb.py
  15. 460
      ee/cli/plugins/stack.py
  16. 12
      ee/core/database.py
  17. 1
      ee/core/logging.py
  18. 117
      ee/core/mysql.py
  19. 34
      ee/core/shellexec.py
  20. 4
      ee/core/variables.py
  21. 181
      install
  22. 2
      setup.py

10
README.md

@ -21,10 +21,16 @@ sudo ee site create example.com --wp # Install required packages & setup
## Update EasyEngine ## Update EasyEngine
Update Procedure For EasyEngine to version 3.0.6 Update procedure for EasyEngine to latest version
#### For current installed version prior to 3.0.6
```bash ```bash
wget -qO ee rt.cx/ee && sudo bash ee wget -qO ee rt.cx/ee && sudo bash ee
```
#### Current version is 3.0.6
```
ee update
``` ```
## More Site Creation Commands ## More Site Creation Commands
@ -85,7 +91,7 @@ ee site create example.com --mysql # create example.com with php & mysql supp
## Careers ## Careers
We are looking for [Python Developers] (https://rtcamp.com/careers/python-developer/) to join our team. We are looking for [Python Developers] (https://rtcamp.com/careers/python-developer/) to join our team.
We offer work from home, so you can join EasyEngine team anywhere! _[Why Python?] (https://rtcamp.com/blog/easyengine-3-roadmap/#whypython)_ We offer work from home, so you can join EasyEngine team anywhere! _[Why Python?] (https://rtcamp.com/blog/easyengine-3-roadmap/#whypython)_

4
config/bash_completion.d/ee_auto.rc

@ -11,7 +11,7 @@ _ee_complete()
# SETUP THE BASE LEVEL (everything after "ee") # SETUP THE BASE LEVEL (everything after "ee")
if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen \ COMPREPLY=( $(compgen \
-W "stack site debug clean secure import-slow-log log" \ -W "stack site debug clean secure import-slow-log log update" \
-- $cur) ) -- $cur) )
@ -74,7 +74,7 @@ _ee_complete()
# HANDLE EVERYTHING AFTER THE THIRD LEVEL NAMESPACE # HANDLE EVERYTHING AFTER THE THIRD LEVEL NAMESPACE
"install" | "purge" | "remove" ) "install" | "purge" | "remove" )
COMPREPLY=( $(compgen \ COMPREPLY=( $(compgen \
-W "--web --admin --mail --nginx --php --mysql --postfix --wpcli --phpmyadmin --adminer --utils --memcache --dovecot --all" \ -W "--web --admin --mail --nginx --php --mysql --postfix --wpcli --phpmyadmin --adminer --utils --memcache --dovecot --all --mailscanner" \
-- $cur) ) -- $cur) )
;; ;;
"start" | "stop" | "reload" | "restart" | "status") "start" | "stop" | "reload" | "restart" | "status")

8
config/plugins.d/update.conf

@ -0,0 +1,8 @@
### Example Plugin Configuration for EasyEngine
[update]
### If enabled, load a plugin named `example` either from the Python module
### `ee.cli.plugins.example` or from the file path
### `/var/lib/ee/plugins/example.py`
enable_plugin = true

42
docs/ee.8

@ -17,15 +17,15 @@ ee site update example.com [ --php | --mysql] [[--wp | --wpsubdir | --wpsubdomai
.TP .TP
ee site delete example.com [--db | --files | --all | --no-prompt ] ee site delete example.com [--db | --files | --all | --no-prompt ]
.TP .TP
ee debug [ -i | --nginx | --rewrite | --php | --fpm | --mysql ] [--stop ] ee debug [ -i | --all=on/off |--nginx=on/off | --rewrite=on/off | --php=on/off | --fpm=on/off | --mysql=on/off ]
.TP .TP
ee debug example.com [ -i | --nginx | --rewrite | --wp ] [--stop ] ee debug example.com [ -i | --all=on/off | --nginx=on/off | --rewrite=on/off | --wp=on/off ]
.TP .TP
ee secure [ --auth | --port | --ip ] ee secure [ --auth | --port | --ip ]
.SH DESCRIPTION .SH DESCRIPTION
EasyEngine aka ee is the opensource project developed with the purpose to automate web-server configuration. EasyEngine aka ee is the opensource project developed with the purpose to automate web-server configuration.
.br .br
EasyEngine is the collection of shell scripts that provides automation for the web-server EasyEngine is the collection of python script that provides automation for the web-server
.br .br
installation, site creation, services debugging & monitoring. installation, site creation, services debugging & monitoring.
.SH OPTIONS .SH OPTIONS
@ -95,7 +95,7 @@ Change directory to webroot of specified site in subshell.
.br .br
monitor access and error logs for site specified. monitor access and error logs for site specified.
.TP .TP
.B list [ enable | available ] .B list [ --enabled | --disabled ]
.br .br
Lists all available sites from /etc/nginx/sites-enabled/ Lists all available sites from /etc/nginx/sites-enabled/
.br .br
@ -143,21 +143,21 @@ Update site configuration according to specified options.
.br .br
Delete site i.e webroot, database, ad configuration permenantly. Delete site i.e webroot, database, ad configuration permenantly.
.TP .TP
.B debug [ -i | --nginx | --php | --mysql | --rewrite | --fpm ] [ --start | --stop ] .B debug [ -i | --nginx=on/off | --php=on/off | --mysql=on/off | --rewrite=on/off | --fpm=on/off ]
.br .br
Starts server level debugging. If used without arguments starts debugging Starts server level debugging. If this is used without arguments it will start debugging
.br .br
all services, else debug only service provided with argument. Stop all services.Else it will debug only service provided with argument.This will Stop
.br .br
Debugging if used with --stop argument. Debugging if used with --all=off argument.
.TP .TP
.B debug example.com [ -i | --nginx | --rewrite | --wp ] [ --start | --stop ] .B debug example.com [ -i | --nginx=on/off | --rewrite=on/off | --wp=on/off | --all=on/off ]
.br .br
Starts site level debugging. If used without arguments starts debugging all Starts site level debugging. If this is used without arguments it will start debugging all
.br .br
services, else debug only service provided with argument. Stop Debugging services.Else it will debug only service provided with argument.This will Stop Debugging
.br .br
if used with --stop argument. if used with --all=off argument.
.TP .TP
.B secure [ --auth | --port ] .B secure [ --auth | --port ]
.br .br
@ -174,35 +174,35 @@ Clean NGINX fastCGI cache if no option specified.
.br .br
setup intractive mode while used with debug. setup intractive mode while used with debug.
.TP .TP
.B --nginx .B --nginx=on/off
.br .br
used with ee debug command. used to start or stop nginx debugging. used with ee debug command. used to start or stop nginx debugging.
.TP .TP
.B --php .B --php=on/off
.br .br
used with ee debug command. used to start or stop php debugging. used with ee debug command. used to start or stop php debugging.
.TP .TP
.B --mysql .B --mysql=on/off
.br .br
used with ee debug command. used to start or stop mysql debugging. used with ee debug command. used to start or stop mysql debugging.
.TP .TP
.B --rewrite .B --rewrite=on/off
.br .br
used with ee debug command. used to start or stop nginx rewrite rules debugging. used with ee debug command. used to start or stop nginx rewrite rules debugging.
.TP .TP
.B --fpm .B --fpm=on/off
.br .br
used with ee debug command. used to start or stop fpm debugging. used with ee debug command. used to start or stop fpm debugging.
.TP .TP
.B --wp .B --wp=on/off
.br .br
used with ee debug command. used to start or stop wordpress site debugging. used with ee debug command. used to start or stop wordpress site debugging.
.TP .TP
.B --start .B --all=on/off
.br .br
used with ee debug command. used to stop debugging. used with ee debug command. used to stop debugging.
.TP .TP
.B --stop .B --all=off
.br .br
used with ee debug command. used to stop debugging. used with ee debug command. used to stop debugging.
.TP .TP

5
ee/cli/plugins/clean.py

@ -10,7 +10,7 @@ import os
import urllib.request import urllib.request
def clean_plugin_hook(app): def ee_clean_hook(app):
# do something with the ``app`` object here. # do something with the ``app`` object here.
pass pass
@ -31,6 +31,7 @@ class EECleanController(CementBaseController):
(['--opcache'], (['--opcache'],
dict(help='Clean OpCache', action='store_true')) dict(help='Clean OpCache', action='store_true'))
] ]
usage = "ee clean [options]"
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@ -86,4 +87,4 @@ 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(EECleanController) handler.register(EECleanController)
# 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', clean_plugin_hook) hook.register('post_argument_parsing', ee_clean_hook)

35
ee/cli/plugins/debug.py

@ -14,29 +14,8 @@ import glob
import signal import signal
import subprocess import subprocess
usage = """
Usage: ee debug {<sitename>} {arguments} def ee_debug_hook(app):
arguments usage:
--all --all=on start debugging all server parameters.
--all=off stop debugging all server parameters
--nginx --nginx=on start debugging nginx server configuration for site
--nginx=off stop debugging nginx server configuration for site
--rewrite --rewrite=on start debugging nginx rewrite rules for site
--rewrite=off stop debugging nginx rewrite rules for site
--php --php=on start debugging server php configuration
--php=off stop debugging server php configuration
--fpm --fpm=on start debugging fastcgi configuration
--fpm=off stop debugging fastcgi configuration
--mysql --mysql=on start debugging mysql server
--mysql=off stop debugging mysql server
--wp --wp=on start wordpress debugging
--wp=off stop wordpress debugging
"""
def debug_plugin_hook(app):
# do something with the ``app`` object here. # do something with the ``app`` object here.
pass pass
@ -89,6 +68,7 @@ class EEDebugController(CementBaseController):
(['site_name'], (['site_name'],
dict(help='Website Name', nargs='?', default=None)) dict(help='Website Name', nargs='?', default=None))
] ]
usage = "ee debug [<site_name>] [options] "
@expose(hide=True) @expose(hide=True)
def debug_nginx(self): def debug_nginx(self):
@ -493,9 +473,10 @@ class EEDebugController(CementBaseController):
and (not self.app.pargs.all) and (not self.app.pargs.all)
and (not self.app.pargs.site_name)): and (not self.app.pargs.site_name)):
if self.app.pargs.stop or self.app.pargs.start: if self.app.pargs.stop or self.app.pargs.start:
print("--start/stop option is deprecated in ee3.0.5", usage) print("--start/stop option is deprecated since ee3.0.5")
self.app.args.print_help()
else: else:
print(usage) self.app.args.print_help()
if self.app.pargs.all == 'on': if self.app.pargs.all == 'on':
if self.app.pargs.site_name: if self.app.pargs.site_name:
@ -519,7 +500,7 @@ class EEDebugController(CementBaseController):
and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql)
and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
and self.app.pargs.site_name): and self.app.pargs.site_name):
print(usage) self.app.args.print_help()
# self.app.pargs.nginx = 'on' # self.app.pargs.nginx = 'on'
# self.app.pargs.wp = 'on' # self.app.pargs.wp = 'on'
# self.app.pargs.rewrite = 'on' # self.app.pargs.rewrite = 'on'
@ -570,4 +551,4 @@ 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(EEDebugController) handler.register(EEDebugController)
# 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', debug_plugin_hook) hook.register('post_argument_parsing', ee_debug_hook)

5
ee/cli/plugins/import_slow_log.py

@ -6,7 +6,7 @@ from ee.core.variables import EEVariables
import os import os
def import_slow_log_plugin_hook(app): def ee_import_slow_log_hook(app):
pass pass
@ -16,6 +16,7 @@ class EEImportslowlogController(CementBaseController):
stacked_on = 'base' stacked_on = 'base'
stacked_type = 'nested' stacked_type = 'nested'
description = 'Import MySQL slow log to Anemometer database' description = 'Import MySQL slow log to Anemometer database'
usage = "ee import-slow-log"
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@ -67,4 +68,4 @@ def load(app):
handler.register(EEImportslowlogController) handler.register(EEImportslowlogController)
# 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', import_slow_log_plugin_hook) hook.register('post_argument_parsing', ee_import_slow_log_hook)

5
ee/cli/plugins/info.py

@ -10,7 +10,7 @@ import os
import configparser import configparser
def info_plugin_hook(app): def ee_info_hook(app):
# do something with the ``app`` object here. # do something with the ``app`` object here.
pass pass
@ -33,6 +33,7 @@ class EEInfoController(CementBaseController):
dict(help='Get Nginx configuration information', dict(help='Get Nginx configuration information',
action='store_true')), action='store_true')),
] ]
usage = "ee info [options]"
@expose(hide=True) @expose(hide=True)
def info_nginx(self): def info_nginx(self):
@ -199,4 +200,4 @@ def load(app):
handler.register(EEInfoController) handler.register(EEInfoController)
# 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', info_plugin_hook) hook.register('post_argument_parsing', ee_info_hook)

5
ee/cli/plugins/log.py

@ -11,7 +11,7 @@ import os
import glob import glob
def log_plugin_hook(app): def ee_log_hook(app):
# do something with the ``app`` object here. # do something with the ``app`` object here.
pass pass
@ -43,6 +43,7 @@ class EELogController(CementBaseController):
(['site_name'], (['site_name'],
dict(help='Website Name', nargs='?', default=None)) dict(help='Website Name', nargs='?', default=None))
] ]
usage = "ee log [<site_name>] [options]"
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@ -137,4 +138,4 @@ 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(EELogController) handler.register(EELogController)
# 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', log_plugin_hook) hook.register('post_argument_parsing', ee_log_hook)

18
ee/core/models.py → ee/cli/plugins/models.py

@ -7,6 +7,7 @@ class SiteDB(Base):
Databse model for site table Databse model for site table
""" """
__tablename__ = 'sites' __tablename__ = 'sites'
__table_args__ = {'extend_existing': True}
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
sitename = Column(String, unique=True) sitename = Column(String, unique=True)
@ -23,10 +24,18 @@ class SiteDB(Base):
is_ssl = Column(Boolean, unique=False, default=False) is_ssl = Column(Boolean, unique=False, default=False)
storage_fs = Column(String) storage_fs = Column(String)
storage_db = Column(String) storage_db = Column(String)
db_name = Column(String)
db_user = Column(String)
db_password = Column(String)
db_host = Column(String)
is_hhvm = Column(Boolean, unique=False, default=False)
is_pagespeed = Column(Boolean, unique=False, default=False)
def __init__(self, sitename=None, site_type=None, cache_type=None, def __init__(self, sitename=None, site_type=None, cache_type=None,
site_path=None, site_enabled=None, site_path=None, site_enabled=None,
is_ssl=None, storage_fs=None, storage_db=None): is_ssl=None, storage_fs=None, storage_db=None, db_name=None,
db_user=None, db_password=None, db_host='localhost',
hhvm=None, pagespeed=None):
self.sitename = sitename self.sitename = sitename
self.site_type = site_type self.site_type = site_type
self.cache_type = cache_type self.cache_type = cache_type
@ -35,7 +44,12 @@ class SiteDB(Base):
self.is_ssl = is_ssl self.is_ssl = is_ssl
self.storage_fs = storage_fs self.storage_fs = storage_fs
self.storage_db = storage_db self.storage_db = storage_db
self.db_name = db_name
self.db_user = db_user
self.db_password = db_password
self.db_host = db_host
self.is_hhvm = hhvm
self.is_pagespeed = pagespeed
# def __repr__(self): # def __repr__(self):
# return '<Site %r>' % (self.site_type) # return '<Site %r>' % (self.site_type)
# #

5
ee/cli/plugins/secure.py

@ -12,7 +12,7 @@ import hashlib
import getpass import getpass
def secure_plugin_hook(app): def ee_secure_hook(app):
# do something with the ``app`` object here. # do something with the ``app`` object here.
pass pass
@ -34,6 +34,7 @@ class EESecureController(CementBaseController):
dict(help='user input', nargs='?', default=None)), dict(help='user input', nargs='?', default=None)),
(['user_pass'], (['user_pass'],
dict(help='user pass', nargs='?', default=None))] dict(help='user pass', nargs='?', default=None))]
usage = "ee secure [options]"
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@ -138,4 +139,4 @@ 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(EESecureController) handler.register(EESecureController)
# 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', secure_plugin_hook) hook.register('post_argument_parsing', ee_secure_hook)

1076
ee/cli/plugins/site.py

File diff suppressed because it is too large

511
ee/cli/plugins/site_functions.py

@ -1,10 +1,14 @@
from ee.cli.plugins.stack import EEStackController from ee.cli.plugins.stack import EEStackController
from ee.core.fileutils import EEFileUtils from ee.core.fileutils import EEFileUtils
from ee.core.mysql import EEMysql from ee.core.mysql import *
from ee.core.shellexec import EEShellExec from ee.core.shellexec import *
from ee.core.variables import EEVariables from ee.core.variables import EEVariables
from ee.cli.plugins.sitedb import *
from ee.core.aptget import EEAptGet from ee.core.aptget import EEAptGet
from ee.core.git import EEGit
from ee.core.logging import Log from ee.core.logging import Log
import subprocess
from subprocess import CalledProcessError
import os import os
import random import random
import string import string
@ -14,10 +18,32 @@ import glob
import re import re
class SiteError(Exception):
"""Custom Exception Occured when setting up site"""
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
def check_domain_exists(self, domain):
if getSiteInfo(self, domain):
return True
else:
return False
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']
# Check if nginx configuration already exists
# if os.path.isfile('/etc/nginx/sites-available/{0}'
# .format(ee_domain_name)):
# raise SiteError("nginx configuration already exists for site")
Log.info(self, "Setting up NGINX configuration \t", end='') Log.info(self, "Setting up NGINX configuration \t", end='')
# write nginx config for file # write nginx config for file
try: try:
@ -30,11 +56,24 @@ def setupdomain(self, data):
ee_site_nginx_conf.close() ee_site_nginx_conf.close()
except IOError as e: except IOError as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "\nUnable to create NGINX configuration") raise SiteError("create nginx configuration failed for site")
except Exception as e: except Exception as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "\nUnable to create NGINX configuration") raise SiteError("create nginx configuration failed for site")
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") finally:
# Check nginx -t and return status over it
try:
Log.debug(self, "Checking generated nginx conf, please wait ...")
FNULL = open('/dev/null', 'w')
ret = subprocess.check_call(["nginx", "-t"], stdout=FNULL,
stderr=subprocess.STDOUT)
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
except CalledProcessError as e:
Log.debug(self, "{0}".format(str(e)))
Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail"
+ Log.OKBLUE + "]")
raise SiteError("created nginx configuration failed for site."
" check with `nginx -t`")
# 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}'
@ -49,19 +88,26 @@ def setupdomain(self, data):
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))
EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log'
.format(ee_domain_name),
'{0}/logs/access.log'
.format(ee_site_webroot)])
EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.error.log'
.format(ee_domain_name),
'{0}/logs/error.log'
.format(ee_site_webroot)])
except Exception as e: except Exception as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "\nUnable to setup webroot") raise SiteError("setup webroot failed for site")
finally:
EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log' # TODO Check if directories are setup
.format(ee_domain_name), if (os.path.exists('{0}/htdocs'.format(ee_site_webroot)) and
'{0}/logs/access.log' os.path.exists('{0}/logs'.format(ee_site_webroot))):
.format(ee_site_webroot)]) Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.error.log' else:
.format(ee_domain_name), Log.info(self, "[" + Log.ENDC + "Fail" + Log.OKBLUE + "]")
'{0}/logs/error.log' raise SiteError("setup webroot failed for site")
.format(ee_site_webroot)])
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
def setupdatabase(self, data): def setupdatabase(self, data):
@ -82,7 +128,7 @@ def setupdatabase(self, data):
.format(ee_replace_dot)) .format(ee_replace_dot))
except EOFError as e: except EOFError as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to input database name") raise SiteError("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
@ -96,7 +142,7 @@ def setupdatabase(self, data):
.format(ee_random)) .format(ee_random))
except EOFError as e: except EOFError as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to input database credentials") raise SiteError("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
@ -106,31 +152,49 @@ def setupdatabase(self, data):
if len(ee_db_username) > 16: if len(ee_db_username) > 16:
Log.debug(self, 'Autofix MySQL username (ERROR 1470 (HY000)),' Log.debug(self, 'Autofix MySQL username (ERROR 1470 (HY000)),'
' please wait') ' please wait')
ee_random10 = (''.join(random.sample(string.ascii_uppercase + ee_db_username = (ee_db_name[0:6] + generate_random())
string.ascii_lowercase + string.digits, 10)))
ee_db_username = (ee_db_name[0:6] + ee_random10)
# create MySQL database # create MySQL database
Log.info(self, "Setting up database\t\t", end='') Log.info(self, "Setting up database\t\t", end='')
Log.debug(self, "Creating databse {0}".format(ee_db_name)) Log.debug(self, "Creating database {0}".format(ee_db_name))
EEMysql.execute(self, "create database `{0}`" try:
.format(ee_db_name), errormsg="Cannot create database") if EEMysql.check_db_exists(self, ee_db_name):
Log.debug(self, "Database already exists, Updating DB_NAME .. ")
ee_db_name = (ee_db_name[0:6] + generate_random())
ee_db_username = (ee_db_name[0:6] + generate_random())
except MySQLConnectionError as e:
raise SiteError("MySQL Connectivity problem occured")
try:
EEMysql.execute(self, "create database `{0}`"
.format(ee_db_name))
except StatementExcecutionError as e:
Log.info(self, "[" + Log.ENDC + Log.FAIL + "Failed" + Log.OKBLUE + "]")
raise SiteError("create database execution failed")
# Create MySQL User # Create MySQL User
Log.debug(self, "Creating user {0}".format(ee_db_username)) Log.debug(self, "Creating user {0}".format(ee_db_username))
Log.debug(self, "create user `{0}`@`{1}` identified by ''" Log.debug(self, "create user `{0}`@`{1}` identified by ''"
.format(ee_db_username, ee_mysql_grant_host)) .format(ee_db_username, ee_mysql_grant_host))
EEMysql.execute(self, try:
"create user `{0}`@`{1}` identified by '{2}'" EEMysql.execute(self,
.format(ee_db_username, ee_mysql_grant_host, "create user `{0}`@`{1}` identified by '{2}'"
ee_db_password), .format(ee_db_username, ee_mysql_grant_host,
errormsg="Cannot setup database user", log=False) ee_db_password), log=False)
except StatementExcecutionError as e:
Log.info(self, "[" + Log.ENDC + Log.FAIL + "Failed" + Log.OKBLUE + "]")
raise SiteError("creating user failed for database")
# Grant permission # Grant permission
Log.debug(self, "Setting up user privileges") Log.debug(self, "Setting up user privileges")
EEMysql.execute(self, try:
"grant all privileges on `{0}`.* to `{1}`@`{2}`" EEMysql.execute(self,
.format(ee_db_name, ee_db_username, ee_mysql_grant_host), "grant all privileges on `{0}`.* to `{1}`@`{2}`"
errormsg="Cannot setup database user privileges") .format(ee_db_name,
ee_db_username, ee_mysql_grant_host))
except StatementExcecutionError as e:
Log.info(self, "[" + Log.ENDC + Log.FAIL + "Failed" + Log.OKBLUE + "]")
SiteError("grant privileges to user failed for database ")
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
data['ee_db_name'] = ee_db_name data['ee_db_name'] = ee_db_name
@ -156,7 +220,13 @@ def setupwordpress(self, data):
Log.info(self, "Downloading Wordpress \t\t", end='') Log.info(self, "Downloading Wordpress \t\t", 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") try:
EEShellExec.cmd_exec(self, "wp --allow-root core"
" download")
except CommandExecutionError as e:
Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]")
raise SiteError(self, "download wordpress core failed")
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
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']):
@ -171,7 +241,7 @@ def setupwordpress(self, data):
) )
except EOFError as e: except EOFError as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to input table prefix") raise SiteError("input table prefix failed")
if not ee_wp_prefix: if not ee_wp_prefix:
ee_wp_prefix = 'wp_' ee_wp_prefix = 'wp_'
@ -192,20 +262,22 @@ def setupwordpress(self, data):
"--extra-php<<PHP \n {1}\nPHP\"" "--extra-php<<PHP \n {1}\nPHP\""
.format(data['ee_db_pass'], .format(data['ee_db_pass'],
"\n\ndefine(\'WP_DEBUG\', false);")) "\n\ndefine(\'WP_DEBUG\', false);"))
EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root " try:
+ "core config " EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root"
+ "--dbname=\'{0}\' --dbprefix=\'{1}\' " + " core config "
"--dbuser=\'{2}\' --dbhost=\'{3}\' " + "--dbname=\'{0}\' --dbprefix=\'{1}\' "
.format(data['ee_db_name'], ee_wp_prefix, "--dbuser=\'{2}\' --dbhost=\'{3}\' "
data['ee_db_user'], data['ee_db_host']) .format(data['ee_db_name'], ee_wp_prefix,
+ "--dbpass=\'{0}\' " data['ee_db_user'], data['ee_db_host']
"--extra-php<<PHP \n {1}\nPHP\"" )
.format(data['ee_db_pass'], + "--dbpass=\'{0}\' "
"\n\ndefine(\'WP_DEBUG\', false);"), "--extra-php<<PHP \n {1}\nPHP\""
log=False .format(data['ee_db_pass'],
) or Log.error(self, "\n\ndefine(\'WP_DEBUG\', false);"),
"Unable to Generate " log=False
"wp-config") )
except CommandExecutionError as e:
raise SiteError("generate wp-config failed for wp single site")
else: else:
Log.debug(self, "Generating wp-config for WordPress multisite") Log.debug(self, "Generating wp-config for WordPress multisite")
Log.debug(self, "bash -c \"php /usr/bin/wp --allow-root " Log.debug(self, "bash -c \"php /usr/bin/wp --allow-root "
@ -220,24 +292,27 @@ def setupwordpress(self, data):
"\ndefine(\'WPMU_ACCEL_REDIRECT\'," "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
" true);", " true);",
"\n\ndefine(\'WP_DEBUG\', false);")) "\n\ndefine(\'WP_DEBUG\', false);"))
EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root " try:
+ "core config " EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root"
+ "--dbname=\'{0}\' --dbprefix=\'{1}\' " + " core config "
"--dbhost=\'{2}\' " + "--dbname=\'{0}\' --dbprefix=\'{1}\' "
.format(data['ee_db_name'], ee_wp_prefix, "--dbhost=\'{2}\' "
data['ee_db_host']) .format(data['ee_db_name'], ee_wp_prefix,
+ "--dbuser=\'{0}\' --dbpass=\'{1}\' " data['ee_db_host'])
"--extra-php<<PHP \n {2} {3} {4}\nPHP\"" + "--dbuser=\'{0}\' --dbpass=\'{1}\' "
.format(data['ee_db_user'], data['ee_db_pass'], "--extra-php<<PHP \n {2} {3} {4}\nPHP\""
"\ndefine(\'WP_ALLOW_MULTISITE\', " .format(data['ee_db_user'],
"true);", data['ee_db_pass'],
"\ndefine(\'WPMU_ACCEL_REDIRECT\'," "\ndefine(\'WP_ALLOW_MULTISITE\', "
" true);", "true);",
"\n\ndefine(\'WP_DEBUG\', false);"), "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
log=False " true);",
) or Log.error(self, "\n\ndefine(\'WP_DEBUG\', false);"),
"Unable to Generate " log=False
"wp-config") )
except CommandExecutionError as e:
raise SiteError("generate wp-config failed for wp multi site")
EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php', EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php',
os.path.abspath(os.path.join(os.getcwd(), os.pardir))) os.path.abspath(os.path.join(os.getcwd(), os.pardir)))
@ -251,8 +326,7 @@ def setupwordpress(self, data):
ee_wp_user = input('Enter WordPress username: ') ee_wp_user = input('Enter WordPress username: ')
except EOFError as e: except EOFError as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to input WordPress user name") raise SiteError("input wordpress username failed")
if not ee_wp_pass: if not ee_wp_pass:
ee_wp_pass = ee_random ee_wp_pass = ee_random
@ -263,7 +337,7 @@ def setupwordpress(self, data):
ee_wp_email = input('Enter WordPress email: ') ee_wp_email = input('Enter WordPress email: ')
except EOFError as e: except EOFError as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to input WordPress user email") raise SiteError("input wordpress username failed")
try: try:
while not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", while not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
@ -273,7 +347,7 @@ def setupwordpress(self, data):
ee_wp_email = input("Enter your email: ") ee_wp_email = input("Enter your email: ")
except EOFError as e: except EOFError as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to input WordPress user email") raise SiteError("input WordPress user email failed")
Log.debug(self, "Setting up WordPress tables") Log.debug(self, "Setting up WordPress tables")
@ -284,16 +358,17 @@ def setupwordpress(self, data):
.format(data['www_domain'], ee_wp_user) .format(data['www_domain'], ee_wp_user)
+ "--admin_password= --admin_email=\'{1}\'" + "--admin_password= --admin_email=\'{1}\'"
.format(ee_wp_pass, ee_wp_email)) .format(ee_wp_pass, ee_wp_email))
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core install " try:
"--url=\'{0}\' --title=\'{0}\' " EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core "
"--admin_name=\'{1}\' " "install --url=\'{0}\' --title=\'{0}\' "
.format(data['www_domain'], ee_wp_user) "--admin_name=\'{1}\' "
+ "--admin_password=\'{0}\' --admin_email=\'{1}\'" .format(data['www_domain'], ee_wp_user)
.format(ee_wp_pass, ee_wp_email), + "--admin_password=\'{0}\' "
errormsg="Unable to setup WordPress Tables", "--admin_email=\'{1}\'"
log=False) or Log.error(self, .format(ee_wp_pass, ee_wp_email),
"Unable to setup " log=False)
"WordPress Tables") except CommandExceutionError as e:
raise SiteError("setup wordpress tables failed for single site")
else: else:
Log.debug(self, "Creating tables for WordPress multisite") Log.debug(self, "Creating tables for WordPress multisite")
Log.debug(self, "php /usr/bin/wp --allow-root " Log.debug(self, "php /usr/bin/wp --allow-root "
@ -305,27 +380,29 @@ def setupwordpress(self, data):
.format(ee_wp_pass, ee_wp_email, .format(ee_wp_pass, ee_wp_email,
subdomains='--subdomains' subdomains='--subdomains'
if not data['wpsubdir'] else '')) if not data['wpsubdir'] else ''))
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root " try:
"core multisite-install " EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root "
"--url=\'{0}\' --title=\'{0}\' " "core multisite-install "
"--admin_name=\'{1}\' " "--url=\'{0}\' --title=\'{0}\' "
.format(data['www_domain'], ee_wp_user) "--admin_name=\'{1}\' "
+ "--admin_password=\'{0}\' " .format(data['www_domain'], ee_wp_user)
"--admin_email=\'{1}\' " + "--admin_password=\'{0}\' "
"{subdomains}" "--admin_email=\'{1}\' "
.format(ee_wp_pass, ee_wp_email, "{subdomains}"
subdomains='--subdomains' .format(ee_wp_pass, ee_wp_email,
if not data['wpsubdir'] else ''), subdomains='--subdomains'
errormsg="Unable to setup WordPress Tables", if not data['wpsubdir'] else ''),
log=False) or Log.error(self, log=False)
"Unable to setup " except CommandExecutionError as e:
"WordPress Tables") raise SiteError("setup wordpress tables failed for wp multi site")
Log.debug(self, "Updating WordPress permalink") Log.debug(self, "Updating WordPress permalink")
EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root " try:
"rewrite structure " EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root "
"/%year%/%monthnum%/%day%/%postname%/", "rewrite structure "
errormsg="Unable to Update WordPress permalink") "/%year%/%monthnum%/%day%/%postname%/")
except CommandExecutionError as e:
raise SiteError("Update wordpress permalinks failed")
"""Install nginx-helper plugin """ """Install nginx-helper plugin """
installwp_plugin(self, 'nginx-helper', data) installwp_plugin(self, 'nginx-helper', data)
@ -348,44 +425,63 @@ 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 \t", end='') Log.info(self, "Setting up WordPress Network \t", end='')
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert' try:
' --title=\'{0}\' {subdomains}' EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert'
.format(data['www_domain'], subdomains='--subdomains' ' --title=\'{0}\' {subdomains}'
if not data['wpsubdir'] else '')) .format(data['www_domain'],
subdomains='--subdomains'
if not data['wpsubdir'] else ''))
except CommandExecutionError as e:
Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]")
raise SiteError("setup wordpress network failed")
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
def installwp_plugin(self, plugin_name, data): def installwp_plugin(self, plugin_name, data):
ee_site_webroot = data['webroot'] ee_site_webroot = data['webroot']
Log.info(self, "Installing plugin {0}".format(plugin_name)) Log.info(self, "Installing plugin {0}, please wait ..."
.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 " try:
"{0}".format(plugin_name), EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin "
errormsg="Unable to Install plugin {0}" "--allow-root install "
.format(plugin_name)) "{0}".format(plugin_name))
except CommandExecutionError as e:
raise SiteError("plugin installation failed")
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root activate " try:
"{0} {na}" EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin "
.format(plugin_name, "--allow-root activate "
na='--network' if data['multisite'] else ''), "{0} {na}"
errormsg="Unable to Activate plugin {0}" .format(plugin_name,
.format(plugin_name)) na='--network' if data['multisite']
else ''
))
except CommandExecutionError as e:
raise SiteError("plugin activation failed")
def uninstallwp_plugin(self, plugin_name, data): def uninstallwp_plugin(self, plugin_name, data):
ee_site_webroot = data['webroot'] ee_site_webroot = data['webroot']
Log.debug(self, "Uninstalling plugin {0}".format(plugin_name)) Log.debug(self, "Uninstalling plugin {0}, please wait ..."
.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 " try:
"{0}".format(plugin_name), EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin "
errormsg="Unable to UnInstall plugin {0}" "--allow-root uninstall "
.format(plugin_name)) "{0}".format(plugin_name))
except CommandExecutionError as e:
raise SiteError("plugin uninstall failed")
def setwebrootpermissions(self, webroot): def setwebrootpermissions(self, webroot):
Log.debug(self, "Setting up permissions") Log.debug(self, "Setting up permissions")
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user, try:
EEVariables.ee_php_user, recursive=True) EEFileUtils.chown(self, webroot, EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
except Exception as e:
Log.debug(self, str(e))
raise SiteError("problem occured while settingup webroot permissions")
def sitebackup(self, data): def sitebackup(self, data):
@ -409,9 +505,12 @@ def sitebackup(self, data):
'DB_NAME').split(',')[1] 'DB_NAME').split(',')[1]
.split(')')[0].strip().replace('\'', '')) .split(')')[0].strip().replace('\'', ''))
Log.info(self, 'Backing up database \t\t', end='') Log.info(self, 'Backing up database \t\t', end='')
EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql" try:
.format(ee_db_name, backup_path), EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql"
errormsg="\nFailed: Backup Database") .format(ee_db_name, backup_path))
except CommandExecutionError as e:
Log.info(self, "[" + Log.ENDC + "Fail" + Log.OKBLUE + "]")
raise SiteError("mysqldump failed to backup database")
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
# 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']:
@ -464,10 +563,11 @@ def updatewpuserpassword(self, ee_domain, ee_site_webroot):
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
# Check if ee_domain is wordpress install # Check if ee_domain is wordpress install
is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core" try:
" version", is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core"
errormsg="{0} : Unable to check if wp install" " version")
.format(ee_domain)) except CommandExecutionError as e:
raise SiteError("is wordpress site? check command failed ")
# Exit if ee_domain is not wordpress install # Exit if ee_domain is not wordpress install
if not is_wp: if not is_wp:
@ -482,16 +582,21 @@ def updatewpuserpassword(self, ee_domain, ee_site_webroot):
if ee_wp_user == "?": if ee_wp_user == "?":
Log.info(self, "Fetching WordPress user list") Log.info(self, "Fetching WordPress user list")
EEShellExec.cmd_exec(self, "wp --allow-root user list " try:
"--fields=user_login | grep -v user_login", EEShellExec.cmd_exec(self, "wp --allow-root user list "
errormsg="Unable to Fetch users list") "--fields=user_login | grep -v user_login")
except CommandExecutionError as e:
raise SiteError("fetch wp userlist command failed")
if not ee_wp_user: if not ee_wp_user:
ee_wp_user = 'admin' ee_wp_user = 'admin'
is_user_exist = EEShellExec.cmd_exec(self, "wp --allow-root user list " try:
"--fields=user_login | grep {0}$ " is_user_exist = EEShellExec.cmd_exec(self, "wp --allow-root user list "
.format(ee_wp_user)) "--fields=user_login | grep {0}$ "
.format(ee_wp_user))
except CommandExecutionError as e:
raise SiteError("if wp user exists check command failed")
if is_user_exist: if is_user_exist:
try: try:
@ -500,16 +605,18 @@ def updatewpuserpassword(self, ee_domain, ee_site_webroot):
.format(ee_wp_user)) .format(ee_wp_user))
except Exception as e: except Exception as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Could not update password") raise SiteError("failed to read password input ")
if len(ee_wp_pass) > 8: try:
EEShellExec.cmd_exec(self, "wp --allow-root user update {0}" EEShellExec.cmd_exec(self, "wp --allow-root user update {0}"
" --user_pass={1}" " --user_pass={1}"
.format(ee_wp_user, ee_wp_pass)) .format(ee_wp_user, ee_wp_pass))
Log.info(self, "Password updated successfully") except CommandExecutionError as e:
else: raise SiteError("wp user password update command failed")
Log.error(self, "Password Unchanged. Hint : Your password must be " Log.info(self, "Password updated successfully")
"8 characters long") if len(ee_wp_pass) < 8:
Log.warn(self, "Warning: You have provided a "
"weak password")
else: else:
Log.error(self, "Invalid WordPress user {0} for {1}." Log.error(self, "Invalid WordPress user {0} for {1}."
.format(ee_wp_user, ee_domain)) .format(ee_wp_user, ee_domain))
@ -579,3 +686,125 @@ def logwatch(self, logfiles):
l = logwatch.LogWatcher(logfiles, callback) l = logwatch.LogWatcher(logfiles, callback)
l.loop() l.loop()
def detSitePar(opts):
"""
Takes dictionary of parsed arguments
1.returns sitetype and cachetype
2. raises RuntimeError when wrong combination is used like
"--wp --wpsubdir" or "--html --wp"
"""
sitetype, cachetype = '', ''
typelist = list()
cachelist = list()
for key, val in opts.items():
if val and key in ['html', 'php', 'mysql', 'wp',
'wpsubdir', 'wpsubdomain']:
typelist.append(key)
elif val and key in ['wpfc', 'wpsc', 'w3tc']:
cachelist.append(key)
if len(typelist) > 1 or len(cachelist) > 1:
raise RuntimeError("could not determine site and cache type")
else:
if not typelist and not cachelist:
sitetype = 'html'
cachetype = 'basic'
elif (not typelist) and cachelist:
sitetype = 'wp'
cachetype = cachelist[0]
elif typelist and (not cachelist):
sitetype = typelist[0]
cachetype = 'basic'
else:
sitetype = typelist[0]
cachetype = cachelist[0]
return (sitetype, cachetype)
def generate_random():
ee_random10 = (''.join(random.sample(string.ascii_uppercase +
string.ascii_lowercase + string.digits, 10)))
return ee_random10
def deleteDB(self, dbname, dbuser, dbhost):
try:
# Check if Database exists
try:
if EEMysql.check_db_exists(self, dbname):
# Drop database if exists
Log.debug(self, "dropping database `{0}`".format(dbname))
EEMysql.execute(self,
"drop database `{0}`".format(dbname),
errormsg='Unable to drop database {0}'
.format(dbname))
except StatementExcecutionError as e:
Log.debug(self, "drop database failed")
Log.info(self, "Database {0} not dropped".format(dbname))
except MySQLConnectionError as e:
Log.debug(self, "Mysql Connection problem occured")
if dbuser != 'root':
Log.debug(self, "dropping user `{0}`".format(dbuser))
try:
EEMysql.execute(self,
"drop user `{0}`@`{1}`"
.format(dbuser, dbhost))
except StatementExcecutionError as e:
Log.debug(self, "drop database user failed")
Log.info(self, "Database {0} not dropped".format(dbuser))
try:
EEMysql.execute(self, "flush privileges")
except StatementExcecutionError as e:
Log.debug(self, "drop database failed")
Log.info(self, "Database {0} not dropped".format(dbname))
except Exception as e:
Log.error(self, "Error occured while deleting database")
def deleteWebRoot(self, webroot):
if os.path.isdir(webroot):
Log.debug(self, "Removing {0}".format(webroot))
EEFileUtils.rm(self, webroot)
return True
else:
Log.debug(self, "{0} does not exist".format(webroot))
return False
def removeNginxConf(self, domain):
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(domain)):
Log.debug(self, "Removing Nginx configuration")
EEFileUtils.rm(self, '/etc/nginx/sites-enabled/{0}'
.format(domain))
EEFileUtils.rm(self, '/etc/nginx/sites-available/{0}'
.format(domain))
EEGit.add(self, ["/etc/nginx"],
msg="Deleted {0} "
.format(domain))
def doCleanupAction(self, domain='', webroot='', dbname='', dbuser='',
dbhost=''):
"""
Removes the nginx configuration and database for the domain provided.
doCleanupAction(self, domain='sitename', webroot='',
dbname='', dbuser='', dbhost='')
"""
if domain:
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(domain)):
removeNginxConf(self, domain)
if webroot:
deleteWebRoot(self, webroot)
if dbname:
if not dbuser:
raise SiteError("dbuser not provided")
if not dbhost:
raise SiteError("dbhost not provided")
deleteDB(self, dbname, dbuser, dbhost)

79
ee/cli/plugins/sitedb.py

@ -4,17 +4,22 @@ 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
from ee.core.database import db_session from ee.core.database import db_session
from ee.core.models import SiteDB from ee.core.fileutils import EEFileUtils
from ee.cli.plugins.models import SiteDB
import sys import sys
import glob
def addNewSite(self, site, stype, cache, path, def addNewSite(self, site, stype, cache, path,
enabled=True, ssl=False, fs='ext4', db='mysql'): enabled=True, ssl=False, fs='ext4', db='mysql',
db_name=None, db_user=None, db_password=None,
db_host='localhost'):
""" """
Add New Site record information into ee database. Add New Site record information into ee database.
""" """
try: try:
newRec = SiteDB(site, stype, cache, path, enabled, ssl, fs, db) newRec = SiteDB(site, stype, cache, path, enabled, ssl, fs, db,
db_name, db_user, db_password, db_host)
db_session.add(newRec) db_session.add(newRec)
db_session.commit() db_session.commit()
except Exception as e: except Exception as e:
@ -34,8 +39,9 @@ def getSiteInfo(self, site):
Log.error(self, "Unable to query database for site info") Log.error(self, "Unable to query database for site info")
def updateSiteInfo(self, site, stype='', cache='', def updateSiteInfo(self, site, stype='', cache='', webroot='',
enabled=True, ssl=False, fs='', db=''): enabled=True, ssl=False, fs='', db='', db_name=None,
db_user=None, db_password=None, db_host=None):
"""updates site record in database""" """updates site record in database"""
try: try:
q = SiteDB.query.filter(SiteDB.sitename == site).first() q = SiteDB.query.filter(SiteDB.sitename == site).first()
@ -59,6 +65,21 @@ def updateSiteInfo(self, site, stype='', cache='',
if ssl and q.is_ssl != ssl: if ssl and q.is_ssl != ssl:
q.is_ssl = ssl q.is_ssl = ssl
if db_name and q.db_name != db_name:
q.db_name = db_name
if db_user and q.db_user != db_user:
q.db_user = db_user
if db_user and q.db_password != db_password:
q.db_password = db_password
if db_host and q.db_host != db_host:
q.db_host = db_host
if webroot and q.site_path != webroot:
q.site_path = webroot
try: try:
q.created_on = func.now() q.created_on = func.now()
db_session.commit() db_session.commit()
@ -87,10 +108,56 @@ def deleteSiteInfo(self, site):
def getAllsites(self): def getAllsites(self):
"""
1. returns all records from ee database
"""
try: try:
q = SiteDB.query.all() q = SiteDB.query.all()
return q return q
except Exception as e: except Exception as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database") Log.error(self, "Unable to query database")
class EESync(object):
def __init__(self, app):
self.app = app
def syncdbinfo(self):
"""
1. reads database information from wp/ee-config.php
2. updates records into ee database accordingly.
"""
sites = getAllsites(self)
if not sites:
pass
for site in sites:
if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
ee_site_webroot = site.site_path
# Read config files
configfiles = glob.glob(ee_site_webroot + '/*-config.php')
if configfiles:
if EEFileUtils.isexist(self, configfiles[0]):
ee_db_name = (EEFileUtils.grep(self, configfiles[0],
'DB_NAME').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_user = (EEFileUtils.grep(self, configfiles[0],
'DB_USER').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_pass = (EEFileUtils.grep(self, configfiles[0],
'DB_PASSWORD').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_host = (EEFileUtils.grep(self, configfiles[0],
'DB_HOST').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
if site.db_name != ee_db_name:
# update records if any mismatch found
Log.debug(self, "Updating {0}"
.format(site.sitename))
updateSiteInfo(self, site.sitename,
db_name=ee_db_name,
db_user=ee_db_user,
db_password=ee_db_pass,
db_host=ee_db_host)

460
ee/cli/plugins/stack.py

@ -69,6 +69,7 @@ class EEStackController(CementBaseController):
(['--utils'], (['--utils'],
dict(help='Install Utils stack', action='store_true')), dict(help='Install Utils stack', action='store_true')),
] ]
usage = "ee stack (command) [options]"
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@ -80,11 +81,16 @@ class EEStackController(CementBaseController):
"""Pre settings to do before installation packages""" """Pre settings to do before installation packages"""
if set(EEVariables.ee_postfix).issubset(set(apt_packages)): if set(EEVariables.ee_postfix).issubset(set(apt_packages)):
Log.debug(self, "Pre-seeding Postfix") Log.debug(self, "Pre-seeding Postfix")
EEShellExec.cmd_exec(self, "echo \"postfix postfix" try:
"/main_mailer_type string \'Internet Site\'\"" EEShellExec.cmd_exec(self, "echo \"postfix postfix"
" | debconf-set-selections") "/main_mailer_type string \'Internet Site"
EEShellExec.cmd_exec(self, "echo \"postfix postfix/mailname string" "\'\""
" $(hostname -f)\" | debconf-set-selections") " | debconf-set-selections")
EEShellExec.cmd_exec(self, "echo \"postfix postfix/mailname"
" string $(hostname -f)\" | "
"debconf-set-selections")
except CommandExecutionError as e:
Log.error(self, "Failed to intialize postfix package")
if set(EEVariables.ee_mysql).issubset(set(apt_packages)): if set(EEVariables.ee_mysql).issubset(set(apt_packages)):
Log.info(self, "Adding repository for MySQL, please wait ...") Log.info(self, "Adding repository for MySQL, please wait ...")
@ -104,20 +110,30 @@ class EEStackController(CementBaseController):
"mysql-server/root_password " "mysql-server/root_password "
"password \" | " "password \" | "
"debconf-set-selections") "debconf-set-selections")
EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 " try:
"mysql-server/root_password " EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
"password {chars}\" | " "mysql-server/root_password "
"debconf-set-selections".format(chars=chars), "password {chars}\" | "
log=False) "debconf-set-selections"
.format(chars=chars),
log=False)
except CommandExecutionError as e:
Log.error("Failed to initialize MySQL package")
Log.debug(self, "echo \"mariadb-server-10.0 " Log.debug(self, "echo \"mariadb-server-10.0 "
"mysql-server/root_password_again " "mysql-server/root_password_again "
"password \" | " "password \" | "
"debconf-set-selections") "debconf-set-selections")
EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 " try:
"mysql-server/root_password_again " EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
"password {chars}\" | " "mysql-server/root_password_again "
"debconf-set-selections".format(chars=chars), "password {chars}\" | "
log=False) "debconf-set-selections"
.format(chars=chars),
log=False)
except CommandExecutionError as e:
Log.error("Failed to initialize MySQL package")
mysql_config = """ mysql_config = """
[client] [client]
user = root user = root
@ -151,17 +167,16 @@ class EEStackController(CementBaseController):
EERepo.add(self, ppa=EEVariables.ee_php_repo) EERepo.add(self, ppa=EEVariables.ee_php_repo)
if set(EEVariables.ee_mail).issubset(set(apt_packages)): if set(EEVariables.ee_mail).issubset(set(apt_packages)):
if EEVariables.ee_platform_codename == 'squeeze':
Log.info(self, "Adding repository for dovecot, "
"please wait ...")
EERepo.add(self, repo_url=EEVariables.ee_dovecot_repo)
Log.debug(self, 'Executing the command debconf-set-selections.') Log.debug(self, 'Executing the command debconf-set-selections.')
EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core/" try:
"create-ssl-cert boolean yes\" " EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core/"
"| debconf-set-selections") "create-ssl-cert boolean yes\" "
EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core" "| debconf-set-selections")
"/ssl-cert-name string $(hostname -f)\"" EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core"
" | debconf-set-selections") "/ssl-cert-name string $(hostname -f)\""
" | debconf-set-selections")
except CommandExecutionError as e:
Log.error("Failed to initialize dovecot packages")
@expose(hide=True) @expose(hide=True)
def post_pref(self, apt_packages, packages): def post_pref(self, apt_packages, packages):
@ -173,7 +188,7 @@ class EEStackController(CementBaseController):
EEService.reload_service(self, 'postfix') EEService.reload_service(self, 'postfix')
if set(EEVariables.ee_nginx).issubset(set(apt_packages)): if set(EEVariables.ee_nginx).issubset(set(apt_packages)):
if ((not EEShellExec.cmd_exec(self, "grep -Hr EasyEngine " if ((not EEShellExec.cmd_exec(self, "grep EasyEngine "
"/etc/nginx")) and os.path.isfile('/etc/nginx/nginx.conf')): "/etc/nginx")) and os.path.isfile('/etc/nginx/nginx.conf')):
nc = NginxConfig() nc = NginxConfig()
Log.debug(self, 'Loading file /etc/nginx/nginx.conf ') Log.debug(self, 'Loading file /etc/nginx/nginx.conf ')
@ -306,11 +321,15 @@ class EEStackController(CementBaseController):
passwd = ''.join([random.choice passwd = ''.join([random.choice
(string.ascii_letters + string.digits) (string.ascii_letters + string.digits)
for n in range(6)]) for n in range(6)])
EEShellExec.cmd_exec(self, "printf \"easyengine:" try:
"$(openssl passwd -crypt " EEShellExec.cmd_exec(self, "printf \"easyengine:"
"{password} 2> /dev/null)\n\"" "$(openssl passwd -crypt "
"> /etc/nginx/htpasswd-ee 2>/dev/null" "{password} 2> /dev/null)\n\""
.format(password=passwd)) "> /etc/nginx/htpasswd-ee "
"2>/dev/null"
.format(password=passwd))
except CommandExecutionError as e:
Log.error(self, "Failed to save HTTP Auth")
# Create Symbolic link for 22222 # Create Symbolic link for 22222
EEFileUtils.create_symlink(self, ['/etc/nginx/' EEFileUtils.create_symlink(self, ['/etc/nginx/'
@ -350,40 +369,46 @@ class EEStackController(CementBaseController):
.format(EEVariables.ee_webroot)] .format(EEVariables.ee_webroot)]
) )
EEShellExec.cmd_exec(self, "openssl genrsa -out " try:
"{0}22222/cert/22222.key 2048" EEShellExec.cmd_exec(self, "openssl genrsa -out "
.format(EEVariables.ee_webroot)) "{0}22222/cert/22222.key 2048"
EEShellExec.cmd_exec(self, "openssl req -new -batch -subj " .format(EEVariables.ee_webroot))
"/commonName=127.0.0.1/ -key " EEShellExec.cmd_exec(self, "openssl req -new -batch "
"{0}22222/cert/22222.key " "-subj /commonName=127.0.0.1/ "
"-out {0}22222/cert/" "-key {0}22222/cert/22222.key "
"22222.csr" "-out {0}22222/cert/"
.format(EEVariables.ee_webroot)) "22222.csr"
.format(EEVariables.ee_webroot))
EEFileUtils.mvfile(self, "{0}22222/cert/22222.key"
.format(EEVariables.ee_webroot), EEFileUtils.mvfile(self, "{0}22222/cert/22222.key"
.format(EEVariables.ee_webroot),
"{0}22222/cert/"
"22222.key.org"
.format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "openssl rsa -in "
"{0}22222/cert/" "{0}22222/cert/"
"22222.key.org" "22222.key.org -out "
.format(EEVariables.ee_webroot)) "{0}22222/cert/22222.key"
.format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "openssl rsa -in " EEShellExec.cmd_exec(self, "openssl x509 -req -days "
"{0}22222/cert/" "3652 -in {0}22222/cert/"
"22222.key.org -out " "22222.csr -signkey {0}"
"{0}22222/cert/22222.key" "22222/cert/22222.key -out "
.format(EEVariables.ee_webroot)) "{0}22222/cert/22222.crt"
.format(EEVariables.ee_webroot))
except CommandExecutionError as e:
Log.error(self, "Failed to generate SSL for 22222")
EEShellExec.cmd_exec(self, "openssl x509 -req -days 3652 "
"-in {0}22222/cert/"
"22222.csr -signkey {0}"
"22222/cert/22222.key -out "
"{0}22222/cert/22222.crt"
.format(EEVariables.ee_webroot))
# Nginx Configation into GIT # Nginx Configation into GIT
EEGit.add(self, EEGit.add(self,
["/etc/nginx"], msg="Adding Nginx into Git") ["/etc/nginx"], msg="Adding Nginx into Git")
EEService.reload_service(self, 'nginx') EEService.reload_service(self, 'nginx')
self.msg = (self.msg + ["HTTP Auth User Name: easyengine"] self.msg = (self.msg + ["HTTP Auth User Name: easyengine"]
+ ["HTTP Auth Password : {0}".format(passwd)]) + ["HTTP Auth Password : {0}".format(passwd)])
if set(EEVariables.ee_php).issubset(set(apt_packages)): if set(EEVariables.ee_php).issubset(set(apt_packages)):
# Create log directories # Create log directories
if not os.path.exists('/var/log/php5/'): if not os.path.exists('/var/log/php5/'):
@ -513,37 +538,49 @@ class EEStackController(CementBaseController):
# config.write(configfile) # config.write(configfile)
if not os.path.isfile("/etc/mysql/my.cnf"): if not os.path.isfile("/etc/mysql/my.cnf"):
config = ("[mysqld]\nwait_timeout = 30\n" config = ("[mysqld]\nwait_timeout = 30\n"
"interactive_timeout=60\nperformance_schema = 0") "interactive_timeout=60\nperformance_schema = 0"
"\nquery_cache_type = 1")
config_file = open("/etc/mysql/my.cnf", config_file = open("/etc/mysql/my.cnf",
encoding='utf-8', mode='w') encoding='utf-8', mode='w')
config_file.write(config) config_file.write(config)
config_file.close() config_file.close()
else: else:
EEShellExec.cmd_exec(self, "sed -i \"/#max_connections/a " try:
"wait_timeout = 30 \\n" EEShellExec.cmd_exec(self, "sed -i \"/#max_conn"
"interactive_timeout = 60 \\n" "ections/a wait_timeout = 30 \\n"
"performance_schema = 0\" " "interactive_timeout = 60 \\n"
"/etc/mysql/my.cnf") "performance_schema = 0\\n"
"query_cache_type = 1 \" "
"/etc/mysql/my.cnf")
except CommandExecutionError as e:
Log.error(self, "Unable to update MySQL file")
EEGit.add(self, ["/etc/mysql"], msg="Adding MySQL into Git") EEGit.add(self, ["/etc/mysql"], msg="Adding MySQL into Git")
EEService.reload_service(self, 'mysql') EEService.reload_service(self, 'mysql')
if set(EEVariables.ee_mail).issubset(set(apt_packages)): if set(EEVariables.ee_mail).issubset(set(apt_packages)):
Log.debug(self, "Adding user") Log.debug(self, "Adding user")
EEShellExec.cmd_exec(self, "adduser --uid 5000 --home /var" try:
"/vmail --disabled-password --gecos ''" EEShellExec.cmd_exec(self, "adduser --uid 5000 --home /var"
" vmail") "/vmail --disabled-password --gecos "
EEShellExec.cmd_exec(self, "openssl req -new -x509 -days 3650 " "'' vmail")
"-nodes -subj /commonName={HOSTNAME}" except CommandExecutionError as e:
"/emailAddress={EMAIL} -out /etc/ssl" Log.error(self, "Unable to add vmail user for mail server")
"/certs/dovecot." try:
"pem -keyout /etc/ssl/private/dovecot.pem" EEShellExec.cmd_exec(self, "openssl req -new -x509 -days"
.format(HOSTNAME=EEVariables.ee_fqdn, " 3650 "
EMAIL=EEVariables.ee_email)) "-nodes -subj /commonName={hostname}"
"/emailAddress={email} -out /etc/ssl"
"/certs/dovecot."
"pem -keyout "
"/etc/ssl/private/dovecot.pem"
.format(hostname=EEVariables.ee_fqdn,
email=EEVariables.ee_email))
except CommandExecutionError as e:
Log.error(self, "Unable to generate PEM key for dovecot")
Log.debug(self, "Setting Privileges to " Log.debug(self, "Setting Privileges to "
"/etc/ssl/private/dovecot.pem file ") "/etc/ssl/private/dovecot.pem file ")
EEShellExec.cmd_exec(self, "chmod 0600 /etc/ssl/private" EEFileUtils.chmod(self, "/etc/ssl/private/dovecot.pem", 0o600)
"/dovecot.pem")
# Custom Dovecot configuration by EasyEngine # Custom Dovecot configuration by EasyEngine
data = dict() data = dict()
@ -562,82 +599,95 @@ class EEStackController(CementBaseController):
encoding='utf-8', mode='w') encoding='utf-8', mode='w')
self.app.render((data), 'dovecot.mustache', out=ee_dovecot) self.app.render((data), 'dovecot.mustache', out=ee_dovecot)
ee_dovecot.close() ee_dovecot.close()
try:
EEShellExec.cmd_exec(self, "sed -i \"s/\\!include " EEShellExec.cmd_exec(self, "sed -i \"s/\\!include "
"auth-system.conf.ext/#\\!include " "auth-system.conf.ext/#\\!include "
"auth-system.conf.ext/\" " "auth-system.conf.ext/\" "
"/etc/dovecot/conf.d/10-auth.conf") "/etc/dovecot/conf.d/10-auth.conf")
EEShellExec.cmd_exec(self, "sed -i \"s\'/etc/dovecot/" EEShellExec.cmd_exec(self, "sed -i \"s\'/etc/dovecot/"
"dovecot.pem\'/etc/ssl/certs/dovecot.pem" "dovecot.pem\'/etc/ssl/certs/"
"\'\" /etc/dovecot/conf.d/10-ssl.conf") "dovecot.pem"
EEShellExec.cmd_exec(self, "sed -i \"s\'/etc/dovecot/" "\'\" /etc/dovecot/conf.d/"
"private/dovecot.pem\'/etc/ssl/private" "10-ssl.conf")
"/dovecot.pem\'\" /etc/dovecot/conf.d/" EEShellExec.cmd_exec(self, "sed -i \"s\'/etc/dovecot/"
"10-ssl.conf") "private/dovecot.pem\'/etc/ssl/"
"private"
# Custom Postfix configuration needed with Dovecot "/dovecot.pem\'\" /etc/dovecot/"
# Changes in master.cf "conf.d/"
# TODO: Find alternative for sed in Python "10-ssl.conf")
EEShellExec.cmd_exec(self, "sed -i \'s/#submission/submission"
"/\'" # Custom Postfix configuration needed with Dovecot
" /etc/postfix/master.cf") # Changes in master.cf
EEShellExec.cmd_exec(self, "sed -i \'s/#smtps/smtps/\'" # TODO: Find alternative for sed in Python
" /etc/postfix/master.cf") EEShellExec.cmd_exec(self, "sed -i \'s/#submission/"
"submission/\'"
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_type = " " /etc/postfix/master.cf")
"dovecot\"") EEShellExec.cmd_exec(self, "sed -i \'s/#smtps/smtps/\'"
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_path = " " /etc/postfix/master.cf")
"private/auth\"")
EEShellExec.cmd_exec(self, "postconf -e \"" EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_type "
"smtpd_sasl_auth_enable = " "= dovecot\"")
"yes\"") EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_path "
EEShellExec.cmd_exec(self, "postconf -e \"" "= private/auth\"")
" smtpd_relay_restrictions =" EEShellExec.cmd_exec(self, "postconf -e \""
" permit_sasl_authenticated, " "smtpd_sasl_auth_enable = "
" permit_mynetworks, " "yes\"")
" reject_unauth_destination\"") EEShellExec.cmd_exec(self, "postconf -e \""
" smtpd_relay_restrictions ="
EEShellExec.cmd_exec(self, "postconf -e \"" " permit_sasl_authenticated, "
"smtpd_tls_mandatory_" " permit_mynetworks, "
"protocols = !SSLv2,!SSLv3\"") " reject_unauth_destination\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtp_tls_mandatory_"
"protocols = !SSLv2,!SSLv3\"") EEShellExec.cmd_exec(self, "postconf -e \""
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_tls_protocols " "smtpd_tls_mandatory_"
" = !SSLv2,!SSLv3\"") "protocols = !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtp_tls_protocols " EEShellExec.cmd_exec(self, "postconf -e \"smtp_tls_"
"= !SSLv2,!SSLv3\"") "mandatory_protocols = !SSLv2,"
EEShellExec.cmd_exec(self, "postconf -e \"mydestination " "!SSLv3\"")
"= localhost\"") EEShellExec.cmd_exec(self, "postconf -e \"smtpd_tls"
EEShellExec.cmd_exec(self, "postconf -e \"virtual_transport " "_protocols = !SSLv2,!SSLv3\"")
"= lmtp:unix:private/dovecot-lmtp\"") EEShellExec.cmd_exec(self, "postconf -e \"smtp_tls"
EEShellExec.cmd_exec(self, "postconf -e \"virtual_uid_maps " "_protocols = !SSLv2,!SSLv3\"")
"= static:5000\"") EEShellExec.cmd_exec(self, "postconf -e \"mydestination "
EEShellExec.cmd_exec(self, "postconf -e \"virtual_gid_maps " "= localhost\"")
"= static:5000\"") EEShellExec.cmd_exec(self, "postconf -e \"virtual"
EEShellExec.cmd_exec(self, "postconf -e \"" "_transport "
" virtual_mailbox_domains = " "= lmtp:unix:private/dovecot-lmtp\"")
"mysql:/etc/postfix/mysql/virtual_" EEShellExec.cmd_exec(self, "postconf -e \"virtual_uid_"
"domains_maps.cf\"") "maps = static:5000\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_mailbox_maps" EEShellExec.cmd_exec(self, "postconf -e \"virtual_gid_"
" = mysql:/etc/postfix/mysql/virtual_" "maps = static:5000\"")
"mailbox_maps.cf\"") EEShellExec.cmd_exec(self, "postconf -e \""
EEShellExec.cmd_exec(self, "postconf -e \"virtual_alias_maps " " virtual_mailbox_domains = "
"= mysql:/etc/postfix/mysql/virtual_" "mysql:/etc/postfix/mysql/virtual_"
"alias_maps.cf\"") "domains_maps.cf\"")
EEShellExec.cmd_exec(self, "openssl req -new -x509 -days " EEShellExec.cmd_exec(self, "postconf -e \"virtual_mailbox"
" 3650 -nodes -subj /commonName=" "_maps"
"{HOSTNAME}/emailAddress={EMAIL}" " = mysql:/etc/postfix/mysql/virtual_"
" -out /etc/ssl/certs/postfix.pem" "mailbox_maps.cf\"")
" -keyout /etc/ssl/private/postfix.pem" EEShellExec.cmd_exec(self, "postconf -e \"virtual_alias"
.format(HOSTNAME=EEVariables.ee_fqdn, "_maps "
EMAIL=EEVariables.ee_email)) "= mysql:/etc/postfix/mysql/virtual_"
EEShellExec.cmd_exec(self, "chmod 0600 /etc/ssl/private" "alias_maps.cf\"")
"/postfix.pem") EEShellExec.cmd_exec(self, "openssl req -new -x509 -days "
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_tls_cert_file " " 3650 -nodes -subj /commonName="
"= /etc/ssl/certs/postfix.pem\"") "{hostname}/emailAddress={email}"
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_tls_key_file " " -out /etc/ssl/certs/postfix.pem"
"= /etc/ssl/private/postfix.pem\"") " -keyout /etc/ssl/private/"
"postfix.pem"
.format(hostname=EEVariables.ee_fqdn,
email=EEVariables.ee_email))
EEShellExec.cmd_exec(self, "chmod 0600 /etc/ssl/private"
"/postfix.pem")
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_tls_cert_"
"file = /etc/ssl/certs/postfix.pem\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_tls_key_"
"file = /etc/ssl/private/"
"postfix.pem\"")
except CommandExecutionError as e:
Log.Error(self, "Failed to update Dovecot configuration")
# Sieve configuration # Sieve configuration
if not os.path.exists('/var/lib/dovecot/sieve/'): if not os.path.exists('/var/lib/dovecot/sieve/'):
@ -661,8 +711,12 @@ class EEStackController(CementBaseController):
# "/dovecot") # "/dovecot")
EEFileUtils.chown(self, "/var/lib/dovecot", 'vmail', 'vmail', EEFileUtils.chown(self, "/var/lib/dovecot", 'vmail', 'vmail',
recursive=True) recursive=True)
EEShellExec.cmd_exec(self, "sievec /var/lib/dovecot/sieve/" try:
"default.sieve") EEShellExec.cmd_exec(self, "sievec /var/lib/dovecot/"
"/sieve/default.sieve")
except CommandExecutionError as e:
raise SiteError("Failed to compile default.sieve")
EEGit.add(self, ["/etc/postfix", "/etc/dovecot"], EEGit.add(self, ["/etc/postfix", "/etc/dovecot"],
msg="Installed mail server") msg="Installed mail server")
EEService.restart_service(self, 'dovecot') EEService.restart_service(self, 'dovecot')
@ -695,13 +749,17 @@ class EEStackController(CementBaseController):
vm_config.close() vm_config.close()
# Amavis postfix configuration # Amavis postfix configuration
EEShellExec.cmd_exec(self, "postconf -e \"content_filter = " try:
"smtp-amavis:[127.0.0.1]:10024\"") EEShellExec.cmd_exec(self, "postconf -e \"content_filter ="
EEShellExec.cmd_exec(self, "sed -i \"s/1 pickup/1 " " smtp-amavis:[127.0.0.1]:10024\"")
"pickup" EEShellExec.cmd_exec(self, "sed -i \"s/1 pickup/1 "
"\\n -o content_filter=\\n -o" " pickup"
" receive_override_options=no_header_body" "\\n -o content_filter=\\n "
"_checks/\" /etc/postfix/master.cf") " -o receive_override_options="
"no_header_body"
"_checks/\" /etc/postfix/master.cf")
except CommandExecutionError as e:
raise SiteError("Failed to update Amavis-Postfix config")
amavis_master = ("""smtp-amavis unix - - n - 2 smtp amavis_master = ("""smtp-amavis unix - - n - 2 smtp
-o smtp_data_done_timeout=1200 -o smtp_data_done_timeout=1200
@ -730,19 +788,22 @@ class EEStackController(CementBaseController):
encoding='utf-8', mode='a') as am_config: encoding='utf-8', mode='a') as am_config:
am_config.write(amavis_master) am_config.write(amavis_master)
# Amavis ClamAV configuration try:
Log.debug(self, "Adding new user clamav amavis") # Amavis ClamAV configuration
EEShellExec.cmd_exec(self, "adduser clamav amavis") Log.debug(self, "Adding new user clamav amavis")
Log.debug(self, "Adding new user amavis clamav") EEShellExec.cmd_exec(self, "adduser clamav amavis")
EEShellExec.cmd_exec(self, "adduser amavis clamav") Log.debug(self, "Adding new user amavis clamav")
Log.debug(self, "Setting Privileges to /var/lib/amavis/tmp ") EEShellExec.cmd_exec(self, "adduser amavis clamav")
EEShellExec.cmd_exec(self, "chmod -R 775 /var/lib/amavis/tmp") Log.debug(self, "Setting Privileges to /var/lib/amavis"
"/tmp")
# Update ClamAV database EEFileUtils.chmod(self, "/var/lib/amavis/tmp", 0o755)
Log.debug(self, "Updating database")
EEShellExec.cmd_exec(self, "freshclam") # Update ClamAV database
Log.debug(self, "Restarting clamav-daemon service") Log.debug(self, "Updating database")
EEShellExec.cmd_exec(self, "service clamav-daemon restart") EEShellExec.cmd_exec(self, "freshclam")
except CommandExecutionError as e:
raise SiteError(" Unable to update ClamAV-Amavis config")
EEGit.add(self, ["/etc/amavis"], msg="Adding Amavis into Git") EEGit.add(self, ["/etc/amavis"], msg="Adding Amavis into Git")
EEService.restart_service(self, 'dovecot') EEService.restart_service(self, 'dovecot')
EEService.reload_service(self, 'postfix') EEService.reload_service(self, 'postfix')
@ -751,7 +812,8 @@ class EEStackController(CementBaseController):
if len(packages): if len(packages):
if any('/usr/bin/wp' == x[1] for x in packages): if any('/usr/bin/wp' == x[1] for x in packages):
Log.debug(self, "Setting Privileges to /usr/bin/wp file ") Log.debug(self, "Setting Privileges to /usr/bin/wp file ")
EEShellExec.cmd_exec(self, "chmod +x /usr/bin/wp") EEFileUtils.chmod(self, "/usr/bin/wp", 0o775)
if any('/tmp/pma.tar.gz' == x[1] if any('/tmp/pma.tar.gz' == x[1]
for x in packages): for x in packages):
EEExtract.extract(self, '/tmp/pma.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/pma.tar.gz', '/tmp/')
@ -834,9 +896,13 @@ class EEStackController(CementBaseController):
'{0}22222/htdocs/db/anemometer' '{0}22222/htdocs/db/anemometer'
.format(EEVariables.ee_webroot)) .format(EEVariables.ee_webroot))
chars = ''.join(random.sample(string.ascii_letters, 8)) chars = ''.join(random.sample(string.ascii_letters, 8))
EEShellExec.cmd_exec(self, 'mysql < {0}22222/htdocs/db' try:
'/anemometer/install.sql' EEShellExec.cmd_exec(self, 'mysql < {0}22222/htdocs/db'
.format(EEVariables.ee_webroot)) '/anemometer/install.sql'
.format(EEVariables.ee_webroot))
except CommandExecutionError as e:
raise SiteError("Unable to import Anemometer database")
EEMysql.execute(self, 'grant select on *.* to \'anemometer\'' EEMysql.execute(self, 'grant select on *.* to \'anemometer\''
'@\'{0}\''.format(self.app.config.get('mysql', '@\'{0}\''.format(self.app.config.get('mysql',
'grant-host'))) 'grant-host')))
@ -863,8 +929,7 @@ class EEStackController(CementBaseController):
if any('/usr/bin/pt-query-advisor' == x[1] if any('/usr/bin/pt-query-advisor' == x[1]
for x in packages): for x in packages):
EEShellExec.cmd_exec(self, "chmod +x /usr/bin/pt-query" EEFileUtils.chmod(self, "/usr/bin/pt-query-advisor", 0o775)
"-advisor")
if any('/tmp/vimbadmin.tar.gz' == x[1] for x in packages): if any('/tmp/vimbadmin.tar.gz' == x[1] for x in packages):
# Extract ViMbAdmin # Extract ViMbAdmin
@ -886,18 +951,23 @@ class EEStackController(CementBaseController):
# Donwload composer and install ViMbAdmin # Donwload composer and install ViMbAdmin
Log.debug(self, "Downloading composer " Log.debug(self, "Downloading composer "
"https://getcomposer.org/installer | php ") "https://getcomposer.org/installer | php ")
EEShellExec.cmd_exec(self, "cd {0}22222/htdocs" try:
"/vimbadmin; curl" EEShellExec.cmd_exec(self, "cd {0}22222/htdocs"
" -sS https://getcomposer.org/installer |" "/vimbadmin; curl"
" php".format(EEVariables.ee_webroot)) " -sS https://getcomposer.org/"
Log.debug(self, "installation of composer") "installer |"
EEShellExec.cmd_exec(self, "cd {0}22222/htdocs" " php".format(EEVariables.ee_webroot))
"/vimbadmin && " Log.debug(self, "Installating of composer")
"php composer.phar install --prefer-dist" EEShellExec.cmd_exec(self, "cd {0}22222/htdocs"
" --no-dev && rm -f {1}22222/htdocs" "/vimbadmin && "
"/vimbadmin/composer.phar" "php composer.phar install "
.format(EEVariables.ee_webroot, "--prefer-dist"
EEVariables.ee_webroot)) " --no-dev && rm -f {1}22222/htdocs"
"/vimbadmin/composer.phar"
.format(EEVariables.ee_webroot,
EEVariables.ee_webroot))
except CommandExecutionError as e:
raise SiteError("Failed to setup ViMbAdmin")
# Configure vimbadmin database # Configure vimbadmin database
vm_passwd = ''.join(random.sample(string.ascii_letters, 8)) vm_passwd = ''.join(random.sample(string.ascii_letters, 8))
@ -942,9 +1012,13 @@ class EEStackController(CementBaseController):
"{0}22222/htdocs/vimbadmin/bin" "{0}22222/htdocs/vimbadmin/bin"
"/doctrine2-cli.php orm:schema-tool:" "/doctrine2-cli.php orm:schema-tool:"
"create".format(EEVariables.ee_webroot)) "create".format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "{0}22222/htdocs/vimbadmin" try:
"/bin/doctrine2-cli.php orm:schema-tool:" EEShellExec.cmd_exec(self, "{0}22222/htdocs/vimbadmin"
"create".format(EEVariables.ee_webroot)) "/bin/doctrine2-cli.php "
"orm:schema-tool:create"
.format(EEVariables.ee_webroot))
except CommandExecutionError as e:
raise SiteError("Unable to create ViMbAdmin schema")
EEFileUtils.chown(self, '{0}22222' EEFileUtils.chown(self, '{0}22222'
.format(EEVariables.ee_webroot), .format(EEVariables.ee_webroot),

12
ee/core/database.py

@ -13,12 +13,16 @@ Base = declarative_base()
Base.query = db_session.query_property() Base.query = db_session.query_property()
def init_db(): def init_db(app):
""" """
Initializes and creates all tables from models into the database Initializes and creates all tables from models into the database
""" """
# import all modules here that might define models so that # import all modules here that might define models so that
# they will be registered properly on the metadata. Otherwise # they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db() # # you will have to import them first before calling init_db()
import ee.core.models # import ee.core.models
Base.metadata.create_all(bind=engine) try:
app.log.info("Initializing EasyEngine Database")
Base.metadata.create_all(bind=engine)
except Exception as e:
app.log.debug("{0}".format(e))

1
ee/core/logging.py

@ -36,6 +36,7 @@ class Log:
""" """
Logs warning into log file Logs warning into log file
""" """
print(Log.WARNING + msg + Log.ENDC)
self.app.log.warn(Log.BOLD + msg + Log.ENDC) self.app.log.warn(Log.BOLD + msg + Log.ENDC)
def debug(self, msg): def debug(self, msg):

117
ee/core/mysql.py

@ -1,5 +1,6 @@
"""EasyEngine MySQL core classes.""" """EasyEngine MySQL core classes."""
import pymysql import pymysql
from pymysql import connections, DatabaseError, Error
import configparser import configparser
from os.path import expanduser from os.path import expanduser
import sys import sys
@ -8,59 +9,71 @@ from ee.core.logging import Log
from ee.core.variables import EEVariables from ee.core.variables import EEVariables
class MySQLConnectionError(Exception):
"""Custom Exception when MySQL server Not Connected"""
pass
class StatementExcecutionError(Exception):
"""Custom Exception when any Query Fails to execute"""
pass
class DatabaseNotExistsError(Exception):
"""Custom Exception when Database not Exist"""
pass
class EEMysql(): class EEMysql():
"""Method for MySQL connection""" """Method for MySQL connection"""
def connect(self):
"""Makes connection with MySQL server"""
try:
connection = pymysql.connect(read_default_file='~/.my.cnf')
return connection
except ValueError as e:
Log.debug(self, str(e))
raise MySQLConnectionError
except pymysql.err.InternalError as e:
Log.debug(self, str(e))
raise MySQLConnectionError
def dbConnection(self, db_name):
try:
connection = pymysql.connect(db=db_name,
read_default_file='~/.my.cnf')
return connection
except DatabaseError as e:
if e.args[1] == '#42000Unknown database \'{0}\''.format(db_name):
raise DatabaseNotExistsError
else:
raise MySQLConnectionError
except pymysql.err.InternalError as e:
Log.debug(self, str(e))
raise MySQLConnectionError
def execute(self, statement, errormsg='', log=True): def execute(self, statement, errormsg='', log=True):
"""Get login details from ~/.my.cnf & Execute MySQL query""" """Get login details from ~/.my.cnf & Execute MySQL query"""
config = configparser.RawConfigParser() connection = EEMysql.connect(self)
cnfpath = expanduser("~")+"/.my.cnf" log and Log.debug(self, "Exceuting MySQL Statement : {0}"
if [cnfpath] == config.read(cnfpath): .format(statement))
user = config.get('client', 'user') try:
passwd = config.get('client', 'password') cursor = connection.cursor()
try: sql = statement
host = config.get('client', 'host') cursor.execute(sql)
except configparser.NoOptionError as e:
host = 'localhost' # connection is not autocommit by default.
# So you must commit to save your changes.
try: connection.commit()
port = config.get('client', 'port') except AttributeError as e:
except configparser.NoOptionError as e: Log.debug(self, str(e))
port = '3306' raise StatementExcecutionError
except Error as e:
try: Log.debug(self, str(e))
conn = pymysql.connect(host=host, port=int(port), raise StatementExcecutionError
user=user, passwd=passwd) finally:
cur = conn.cursor() connection.close()
except Exception as e:
if errormsg:
Log.debug(self, '{0}'
.format(e))
Log.error(self, '{0}'
.format(errormsg))
else:
Log.debug(self, '{0}'
.format(e))
Log.error(self, 'Unable to connect to database: {0}'
.format(e))
try:
if log:
Log.debug(self, "Executing MySQL statement: {0}"
.format(statement))
cur.execute(statement)
cur.close()
conn.close()
except Exception as e:
cur.close()
conn.close()
Log.debug(self, "{0}".format(e))
if not errormsg:
Log.error(self, 'Unable to execute statement')
else:
Log.error(self, '{0}'.format(errormsg))
def backupAll(self): def backupAll(self):
import subprocess import subprocess
@ -101,3 +114,11 @@ class EEMysql():
except Exception as e: except Exception as e:
Log.error(self, "Error: process exited with status %s" Log.error(self, "Error: process exited with status %s"
% e) % e)
def check_db_exists(self, db_name):
try:
if EEMysql.dbConnection(self, db_name):
return True
except DatabaseNotExistsError as e:
Log.debug(self, str(e))
return False

34
ee/core/shellexec.py

@ -5,6 +5,11 @@ import sys
import subprocess import subprocess
class CommandExecutionError(Exception):
"""custom Exception for command execution"""
pass
class EEShellExec(): class EEShellExec():
"""Method to run shell commands""" """Method to run shell commands"""
def __init__(): def __init__():
@ -13,8 +18,8 @@ class EEShellExec():
def cmd_exec(self, command, errormsg='', log=True): def cmd_exec(self, command, errormsg='', log=True):
"""Run shell command from Python""" """Run shell command from Python"""
try: try:
if log: log and Log.debug(self, "Running command: {0}".format(command))
Log.debug(self, "Running command: {0}".format(command))
with subprocess.Popen([command], stdout=subprocess.PIPE, with subprocess.Popen([command], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True) as proc: stderr=subprocess.PIPE, shell=True) as proc:
(cmd_stdout_bytes, cmd_stderr_bytes) = proc.communicate() (cmd_stdout_bytes, cmd_stderr_bytes) = proc.communicate()
@ -26,25 +31,15 @@ class EEShellExec():
if proc.returncode == 0: if proc.returncode == 0:
return True return True
else: else:
Log.debug(self, "Command Output: {0}, Command Error: {1}" Log.debug(self, "Command Output: {0}, \nCommand Error: {1}"
.format(cmd_stdout, cmd_stderr)) .format(cmd_stdout, cmd_stderr))
return False return False
except OSError as e: except OSError as e:
if errormsg: Log.debug(self, str(e))
Log.error(self, errormsg) raise CommandExecutionError
else:
Log.debug(self, "Unable to execute command {0}"
.format(command))
Log.debug(self, "{0}".format(e))
Log.error(self, "Error occured while executing command")
except Exception as e: except Exception as e:
if errormsg: Log.debug(self, str(e))
Log.error(self, errormsg) raise CommandExecutionError
else:
Log.debug(self, "Unable to execute command {0}"
.format(command))
Log.debug(self, "{0}".format(e))
Log.error(self, "Error occurred while executing command")
def invoke_editor(self, filepath, errormsg=''): def invoke_editor(self, filepath, errormsg=''):
""" """
@ -53,8 +48,5 @@ class EEShellExec():
try: try:
subprocess.call(['sensible-editor', filepath]) subprocess.call(['sensible-editor', filepath])
except OSError as e: except OSError as e:
if errormsg:
Log.error(self, errormsg)
else:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror)) Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Unable to edit file {0}".format(filepath)) raise CommandExecutionError

4
ee/core/variables.py

@ -12,12 +12,12 @@ class EEVariables():
"""Intialization of core variables""" """Intialization of core variables"""
# EasyEngine version # EasyEngine version
ee_version = "3.0.6" ee_version = "3.0.7"
# EasyEngine packages versions # EasyEngine packages versions
ee_wp_cli = "0.18.0" ee_wp_cli = "0.18.0"
ee_adminer = "4.1.0" ee_adminer = "4.1.0"
ee_roundcube = "1.1.0" ee_roundcube = "1.1.1"
ee_vimbadmin = "3.0.11" ee_vimbadmin = "3.0.11"
# Current date and time of System # Current date and time of System

181
install

@ -48,7 +48,7 @@ fi
# Define variables for later use # Define variables for later use
ee_branch=$1 ee_branch=$1
readonly ee_version_old="2.2.3" readonly ee_version_old="2.2.3"
readonly ee_version_new="3.0.6" readonly ee_version_new="3.0.7"
readonly ee_log_dir=/var/log/ee/ readonly ee_log_dir=/var/log/ee/
readonly ee_install_log=/var/log/ee/install.log readonly ee_install_log=/var/log/ee/install.log
readonly ee_linux_distro=$(lsb_release -i | awk '{print $3}') readonly ee_linux_distro=$(lsb_release -i | awk '{print $3}')
@ -102,9 +102,10 @@ function ee_install_dep()
# which will be used by EasyEngine 3.x # which will be used by EasyEngine 3.x
function ee_sync_db() function ee_sync_db()
{ {
mkdir -p /var/lib/ee if [ ! -f /var/lib/ee/ee.db ]; then
mkdir -p /var/lib/ee
echo "CREATE TABLE sites ( echo "CREATE TABLE sites (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
sitename UNIQUE, sitename UNIQUE,
site_type CHAR, site_type CHAR,
@ -117,87 +118,102 @@ function ee_sync_db()
storage_db CHAR storage_db CHAR
);" | sqlite3 /var/lib/ee/ee.db );" | sqlite3 /var/lib/ee/ee.db
# Check site is enable/live or disable # Check site is enable/live or disable
for site in $(ls /etc/nginx/sites-available/ | grep -v default); for site in $(ls /etc/nginx/sites-available/ | grep -v default);
do do
if [ -f /etc/nginx/sites-enabled/$site ]; then if [ -f /etc/nginx/sites-enabled/$site ]; then
ee_site_status='1' ee_site_status='1'
else else
ee_site_status='0' ee_site_status='0'
fi fi
# Find out information about current NGINX configuration # Find out information about current NGINX configuration
ee_site_current_type=$(head -n1 /etc/nginx/sites-available/$site | grep "NGINX CONFIGURATION" | rev | cut -d' ' -f3,4,5,6,7 | rev | cut -d ' ' -f2,3,4,5) ee_site_current_type=$(head -n1 /etc/nginx/sites-available/$site | grep "NGINX CONFIGURATION" | rev | cut -d' ' -f3,4,5,6,7 | rev | cut -d ' ' -f2,3,4,5)
# Detect current website type and cache # Detect current website type and cache
if [ "$ee_site_current_type" = "HTML" ]; then if [ "$ee_site_current_type" = "HTML" ]; then
ee_site_current="html" ee_site_current="html"
ee_site_current_cache="basic" ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "PHP" ]; then elif [ "$ee_site_current_type" = "PHP" ]; then
ee_site_current="php" ee_site_current="php"
ee_site_current_cache="basic" ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "MYSQL" ]; then elif [ "$ee_site_current_type" = "MYSQL" ]; then
ee_site_current="mysql" ee_site_current="mysql"
ee_site_current_cache="basic" ee_site_current_cache="basic"
# Single WordPress # Single WordPress
elif [ "$ee_site_current_type" = "WPSINGLE BASIC" ]; then elif [ "$ee_site_current_type" = "WPSINGLE BASIC" ]; then
ee_site_current="wp" ee_site_current="wp"
ee_site_current_cache="basic" ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "WPSINGLE WP SUPER CACHE" ]; then elif [ "$ee_site_current_type" = "WPSINGLE WP SUPER CACHE" ]; then
ee_site_current="wp" ee_site_current="wp"
ee_site_current_cache="wpsc" ee_site_current_cache="wpsc"
elif [ "$ee_site_current_type" = "WPSINGLE W3 TOTAL CACHE" ]; then elif [ "$ee_site_current_type" = "WPSINGLE W3 TOTAL CACHE" ]; then
ee_site_current="wp" ee_site_current="wp"
ee_site_current_cache="w3tc" ee_site_current_cache="w3tc"
elif [ "$ee_site_current_type" = "WPSINGLE FAST CGI" ] || [ "$ee_site_current_type" = "WPSINGLE FASTCGI" ]; then elif [ "$ee_site_current_type" = "WPSINGLE FAST CGI" ] || [ "$ee_site_current_type" = "WPSINGLE FASTCGI" ]; then
ee_site_current="wp" ee_site_current="wp"
ee_site_current_cache="wpfc" ee_site_current_cache="wpfc"
# WordPress subdirectory # WordPress subdirectory
elif [ "$ee_site_current_type" = "WPSUBDIR BASIC" ]; then elif [ "$ee_site_current_type" = "WPSUBDIR BASIC" ]; then
ee_site_current="wpsubdir" ee_site_current="wpsubdir"
ee_site_current_cache="basic" ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "WPSUBDIR WP SUPER CACHE" ]; then elif [ "$ee_site_current_type" = "WPSUBDIR WP SUPER CACHE" ]; then
ee_site_current="wpsubdir" ee_site_current="wpsubdir"
ee_site_current_cache="wpsc" ee_site_current_cache="wpsc"
elif [ "$ee_site_current_type" = "WPSUBDIR W3 TOTAL CACHE" ]; then elif [ "$ee_site_current_type" = "WPSUBDIR W3 TOTAL CACHE" ]; then
ee_site_current="wpsubdir" ee_site_current="wpsubdir"
ee_site_current_cache="w3tc" ee_site_current_cache="w3tc"
elif [ "$ee_site_current_type" = "WPSUBDIR FAST CGI" ] || [ "$ee_site_current_type" = "WPSUBDIR FASTCGI" ]; then elif [ "$ee_site_current_type" = "WPSUBDIR FAST CGI" ] || [ "$ee_site_current_type" = "WPSUBDIR FASTCGI" ]; then
ee_site_current="wpsubdir" ee_site_current="wpsubdir"
ee_site_current_cache="wpfc" ee_site_current_cache="wpfc"
# WordPress subdomain # WordPress subdomain
elif [ "$ee_site_current_type" = "WPSUBDOMAIN BASIC" ]; then elif [ "$ee_site_current_type" = "WPSUBDOMAIN BASIC" ]; then
ee_site_current="wpsubdomain" ee_site_current="wpsubdomain"
ee_site_current_cache="basic" ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "WPSUBDOMAIN WP SUPER CACHE" ]; then elif [ "$ee_site_current_type" = "WPSUBDOMAIN WP SUPER CACHE" ]; then
ee_site_current="wpsubdomain" ee_site_current="wpsubdomain"
ee_site_current_cache="wpsc" ee_site_current_cache="wpsc"
elif [ "$ee_site_current_type" = "WPSUBDOMAIN W3 TOTAL CACHE" ]; then elif [ "$ee_site_current_type" = "WPSUBDOMAIN W3 TOTAL CACHE" ]; then
ee_site_current="wpsubdomain" ee_site_current="wpsubdomain"
ee_site_current_cache="w3tc" ee_site_current_cache="w3tc"
elif [ "$ee_site_current_type" = "WPSUBDOMAIN FAST CGI" ] || [ "$ee_site_current_type" = "WPSUBDOMAIN FASTCGI" ]; then elif [ "$ee_site_current_type" = "WPSUBDOMAIN FAST CGI" ] || [ "$ee_site_current_type" = "WPSUBDOMAIN FASTCGI" ]; then
ee_site_current="wpsubdomain" ee_site_current="wpsubdomain"
ee_site_current_cache="wpfc" ee_site_current_cache="wpfc"
fi fi
ee_webroot="/var/www/$site" ee_webroot="/var/www/$site"
# Insert query to insert old site information into ee.db # Insert query to insert old site information into ee.db
echo "INSERT INTO sites (sitename, site_type, cache_type, site_path, is_enabled, is_ssl, storage_fs, storage_db) echo "INSERT INTO sites (sitename, site_type, cache_type, site_path, is_enabled, is_ssl, storage_fs, storage_db)
VALUES (\"$site\", \"$ee_site_current\", \"$ee_site_current_cache\", \"$ee_webroot\", \"$ee_site_status\", 0, 'ext4', 'mysql');" | sqlite3 /var/lib/ee/ee.db VALUES (\"$site\", \"$ee_site_current\", \"$ee_site_current_cache\", \"$ee_webroot\", \"$ee_site_status\", 0, 'ext4', 'mysql');" | sqlite3 /var/lib/ee/ee.db
done done
else
ee_lib_echo "Updating EasyEngine Database"
echo "ALTER TABLE sites ADD COLUMN db_name varchar; \
ALTER TABLE sites ADD COLUMN db_user varchar; \
ALTER TABLE sites ADD COLUMN db_password varchar; \
ALTER TABLE sites ADD COLUMN db_host varchar; \
ALTER TABLE sites ADD COLUMN is_hhvm INT DEFAULT '0'; \
ALTER TABLE sites ADD COLUMN is_pagespeed INT DEFAULT '0';" | sqlite3 /var/lib/ee/ee.db
fi
}
function secure_ee_db()
{
chown -R root:root /var/lib/ee/
chmod -R 600 /var/lib/ee/
} }
@ -305,19 +321,24 @@ if [ -f /usr/local/sbin/easyengine ]; then
fi fi
ee_install_dep | tee -ai $ee_install_log ee_install_dep | tee -ai $ee_install_log
ee_sync_db | tee -ai $ee_install_log ee_sync_db | tee -ai $ee_install_log
secure_ee_db | tee -ai $EE_INSTALL_LOG
ee_install | tee -ai $ee_install_log ee_install | tee -ai $ee_install_log
ee_update | tee -ai $ee_install_log ee_update | tee -ai $ee_install_log
ee_git_init | tee -ai $ee_install_log ee_git_init | tee -ai $ee_install_log
elif [ ! -f /usr/local/bin/ee ]; then elif [ ! -f /usr/local/bin/ee ]; then
ee_install_dep | tee -ai $ee_install_log ee_install_dep | tee -ai $ee_install_log
ee_install | tee -ai $ee_install_log ee_install | tee -ai $ee_install_log
secure_ee_db | tee -ai $EE_INSTALL_LOG
ee_git_init | tee -ai $ee_install_log ee_git_init | tee -ai $ee_install_log
else else
ee -v 2>&1 | grep $ee_version_new &>> /dev/null ee -v 2>&1 | grep $ee_version_new &>> /dev/null
if [[ $? -ne 0 ]];then if [[ $? -ne 0 ]];then
read -p "Update EasyEngine to $ee_version_new (y/n): " ee_ans read -p "Update EasyEngine to $ee_version_new (y/n): " ee_ans
if [ "$ee_ans" = "y" ] || [ "$ee_ans" = "Y" ]; then if [ "$ee_ans" = "y" ] || [ "$ee_ans" = "Y" ]; then
ee_install_dep | tee -ai $ee_install_log ee_install_dep | tee -ai $ee_install_log
sync_db | tee -ai $EE_INSTALL_LOG
secure_ee_db | tee -ai $EE_INSTALL_LOG
ee_update_latest | tee -ai $ee_install_log ee_update_latest | tee -ai $ee_install_log
ee_install | tee -ai $ee_install_log ee_install | tee -ai $ee_install_log
ee_git_init | tee -ai $ee_install_log ee_git_init | tee -ai $ee_install_log

2
setup.py

@ -54,7 +54,7 @@ except Exception as e:
os.system("git config --global user.email {0}".format(ee_email)) os.system("git config --global user.email {0}".format(ee_email))
setup(name='ee', setup(name='ee',
version='3.0.6', version='3.0.7',
description=long_description, description=long_description,
long_description=long_description, long_description=long_description,
classifiers=[], classifiers=[],

Loading…
Cancel
Save