Browse Source

merge conflict resolved python => master

bugfixes
harshadyeola 10 years ago
parent
commit
1ac085d0f6
  1. 8
      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

8
README.md

@ -21,10 +21,16 @@ sudo ee site create example.com --wp # Install required packages & setup
## 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
wget -qO ee rt.cx/ee && sudo bash ee
```
#### Current version is 3.0.6
```
ee update
```
## More Site Creation Commands

4
config/bash_completion.d/ee_auto.rc

@ -11,7 +11,7 @@ _ee_complete()
# SETUP THE BASE LEVEL (everything after "ee")
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen \
-W "stack site debug clean secure import-slow-log log" \
-W "stack site debug clean secure import-slow-log log update" \
-- $cur) )
@ -74,7 +74,7 @@ _ee_complete()
# HANDLE EVERYTHING AFTER THE THIRD LEVEL NAMESPACE
"install" | "purge" | "remove" )
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) )
;;
"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
ee site delete example.com [--db | --files | --all | --no-prompt ]
.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
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
ee secure [ --auth | --port | --ip ]
.SH DESCRIPTION
EasyEngine aka ee is the opensource project developed with the purpose to automate web-server configuration.
.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
installation, site creation, services debugging & monitoring.
.SH OPTIONS
@ -95,7 +95,7 @@ Change directory to webroot of specified site in subshell.
.br
monitor access and error logs for site specified.
.TP
.B list [ enable | available ]
.B list [ --enabled | --disabled ]
.br
Lists all available sites from /etc/nginx/sites-enabled/
.br
@ -143,21 +143,21 @@ Update site configuration according to specified options.
.br
Delete site i.e webroot, database, ad configuration permenantly.
.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
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
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
Debugging if used with --stop argument.
Debugging if used with --all=off argument.
.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
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
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
if used with --stop argument.
if used with --all=off argument.
.TP
.B secure [ --auth | --port ]
.br
@ -174,35 +174,35 @@ Clean NGINX fastCGI cache if no option specified.
.br
setup intractive mode while used with debug.
.TP
.B --nginx
.B --nginx=on/off
.br
used with ee debug command. used to start or stop nginx debugging.
.TP
.B --php
.B --php=on/off
.br
used with ee debug command. used to start or stop php debugging.
.TP
.B --mysql
.B --mysql=on/off
.br
used with ee debug command. used to start or stop mysql debugging.
.TP
.B --rewrite
.B --rewrite=on/off
.br
used with ee debug command. used to start or stop nginx rewrite rules debugging.
.TP
.B --fpm
.B --fpm=on/off
.br
used with ee debug command. used to start or stop fpm debugging.
.TP
.B --wp
.B --wp=on/off
.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
.B --start
.B --all=on/off
.br
used with ee debug command. used to stop debugging.
.TP
.B --stop
.B --all=off
.br
used with ee debug command. used to stop debugging.
.TP

5
ee/cli/plugins/clean.py

@ -10,7 +10,7 @@ import os
import urllib.request
def clean_plugin_hook(app):
def ee_clean_hook(app):
# do something with the ``app`` object here.
pass
@ -31,6 +31,7 @@ class EECleanController(CementBaseController):
(['--opcache'],
dict(help='Clean OpCache', action='store_true'))
]
usage = "ee clean [options]"
@expose(hide=True)
def default(self):
@ -86,4 +87,4 @@ def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(EECleanController)
# 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 subprocess
usage = """
Usage: ee debug {<sitename>} {arguments}
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):
def ee_debug_hook(app):
# do something with the ``app`` object here.
pass
@ -89,6 +68,7 @@ class EEDebugController(CementBaseController):
(['site_name'],
dict(help='Website Name', nargs='?', default=None))
]
usage = "ee debug [<site_name>] [options] "
@expose(hide=True)
def debug_nginx(self):
@ -493,9 +473,10 @@ class EEDebugController(CementBaseController):
and (not self.app.pargs.all)
and (not self.app.pargs.site_name)):
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:
print(usage)
self.app.args.print_help()
if self.app.pargs.all == 'on':
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.wp) and (not self.app.pargs.rewrite)
and self.app.pargs.site_name):
print(usage)
self.app.args.print_help()
# self.app.pargs.nginx = 'on'
# self.app.pargs.wp = '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
handler.register(EEDebugController)
# 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
def import_slow_log_plugin_hook(app):
def ee_import_slow_log_hook(app):
pass
@ -16,6 +16,7 @@ class EEImportslowlogController(CementBaseController):
stacked_on = 'base'
stacked_type = 'nested'
description = 'Import MySQL slow log to Anemometer database'
usage = "ee import-slow-log"
@expose(hide=True)
def default(self):
@ -67,4 +68,4 @@ def load(app):
handler.register(EEImportslowlogController)
# 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
def info_plugin_hook(app):
def ee_info_hook(app):
# do something with the ``app`` object here.
pass
@ -33,6 +33,7 @@ class EEInfoController(CementBaseController):
dict(help='Get Nginx configuration information',
action='store_true')),
]
usage = "ee info [options]"
@expose(hide=True)
def info_nginx(self):
@ -199,4 +200,4 @@ def load(app):
handler.register(EEInfoController)
# 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
def log_plugin_hook(app):
def ee_log_hook(app):
# do something with the ``app`` object here.
pass
@ -43,6 +43,7 @@ class EELogController(CementBaseController):
(['site_name'],
dict(help='Website Name', nargs='?', default=None))
]
usage = "ee log [<site_name>] [options]"
@expose(hide=True)
def default(self):
@ -137,4 +138,4 @@ def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(EELogController)
# 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
"""
__tablename__ = 'sites'
__table_args__ = {'extend_existing': True}
id = Column(Integer, primary_key=True)
sitename = Column(String, unique=True)
@ -23,10 +24,18 @@ class SiteDB(Base):
is_ssl = Column(Boolean, unique=False, default=False)
storage_fs = 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,
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.site_type = site_type
self.cache_type = cache_type
@ -35,7 +44,12 @@ class SiteDB(Base):
self.is_ssl = is_ssl
self.storage_fs = storage_fs
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):
# return '<Site %r>' % (self.site_type)
#

5
ee/cli/plugins/secure.py

@ -12,7 +12,7 @@ import hashlib
import getpass
def secure_plugin_hook(app):
def ee_secure_hook(app):
# do something with the ``app`` object here.
pass
@ -34,6 +34,7 @@ class EESecureController(CementBaseController):
dict(help='user input', nargs='?', default=None)),
(['user_pass'],
dict(help='user pass', nargs='?', default=None))]
usage = "ee secure [options]"
@expose(hide=True)
def default(self):
@ -138,4 +139,4 @@ def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(EESecureController)
# 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.core.fileutils import EEFileUtils
from ee.core.mysql import EEMysql
from ee.core.shellexec import EEShellExec
from ee.core.mysql import *
from ee.core.shellexec import *
from ee.core.variables import EEVariables
from ee.cli.plugins.sitedb import *
from ee.core.aptget import EEAptGet
from ee.core.git import EEGit
from ee.core.logging import Log
import subprocess
from subprocess import CalledProcessError
import os
import random
import string
@ -14,10 +18,32 @@ import glob
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):
ee_domain_name = data['site_name']
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='')
# write nginx config for file
try:
@ -30,11 +56,24 @@ def setupdomain(self, data):
ee_site_nginx_conf.close()
except IOError as 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:
Log.debug(self, "{0}".format(e))
Log.error(self, "\nUnable to create NGINX configuration")
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
raise SiteError("create nginx configuration failed for site")
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
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))
if not os.path.exists('{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:
Log.debug(self, "{0}".format(e))
Log.error(self, "\nUnable to setup 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)])
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
raise SiteError("setup webroot failed for site")
finally:
# TODO Check if directories are setup
if (os.path.exists('{0}/htdocs'.format(ee_site_webroot)) and
os.path.exists('{0}/logs'.format(ee_site_webroot))):
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
else:
Log.info(self, "[" + Log.ENDC + "Fail" + Log.OKBLUE + "]")
raise SiteError("setup webroot failed for site")
def setupdatabase(self, data):
@ -82,7 +128,7 @@ def setupdatabase(self, data):
.format(ee_replace_dot))
except EOFError as 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:
ee_db_name = ee_replace_dot
@ -96,7 +142,7 @@ def setupdatabase(self, data):
.format(ee_random))
except EOFError as 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:
ee_db_username = ee_replace_dot
@ -106,31 +152,49 @@ def setupdatabase(self, data):
if len(ee_db_username) > 16:
Log.debug(self, 'Autofix MySQL username (ERROR 1470 (HY000)),'
' please wait')
ee_random10 = (''.join(random.sample(string.ascii_uppercase +
string.ascii_lowercase + string.digits, 10)))
ee_db_username = (ee_db_name[0:6] + ee_random10)
ee_db_username = (ee_db_name[0:6] + generate_random())
# create MySQL database
Log.info(self, "Setting up database\t\t", end='')
Log.debug(self, "Creating databse {0}".format(ee_db_name))
EEMysql.execute(self, "create database `{0}`"
.format(ee_db_name), errormsg="Cannot create database")
Log.debug(self, "Creating database {0}".format(ee_db_name))
try:
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
Log.debug(self, "Creating user {0}".format(ee_db_username))
Log.debug(self, "create user `{0}`@`{1}` identified by ''"
.format(ee_db_username, ee_mysql_grant_host))
EEMysql.execute(self,
"create user `{0}`@`{1}` identified by '{2}'"
.format(ee_db_username, ee_mysql_grant_host,
ee_db_password),
errormsg="Cannot setup database user", log=False)
try:
EEMysql.execute(self,
"create user `{0}`@`{1}` identified by '{2}'"
.format(ee_db_username, ee_mysql_grant_host,
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
Log.debug(self, "Setting up user privileges")
EEMysql.execute(self,
"grant all privileges on `{0}`.* to `{1}`@`{2}`"
.format(ee_db_name, ee_db_username, ee_mysql_grant_host),
errormsg="Cannot setup database user privileges")
try:
EEMysql.execute(self,
"grant all privileges on `{0}`.* to `{1}`@`{2}`"
.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 + "]")
data['ee_db_name'] = ee_db_name
@ -156,7 +220,13 @@ def setupwordpress(self, data):
Log.info(self, "Downloading Wordpress \t\t", end='')
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 + "]")
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:
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:
ee_wp_prefix = 'wp_'
@ -192,20 +262,22 @@ def setupwordpress(self, data):
"--extra-php<<PHP \n {1}\nPHP\""
.format(data['ee_db_pass'],
"\n\ndefine(\'WP_DEBUG\', false);"))
EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root "
+ "core config "
+ "--dbname=\'{0}\' --dbprefix=\'{1}\' "
"--dbuser=\'{2}\' --dbhost=\'{3}\' "
.format(data['ee_db_name'], ee_wp_prefix,
data['ee_db_user'], data['ee_db_host'])
+ "--dbpass=\'{0}\' "
"--extra-php<<PHP \n {1}\nPHP\""
.format(data['ee_db_pass'],
"\n\ndefine(\'WP_DEBUG\', false);"),
log=False
) or Log.error(self,
"Unable to Generate "
"wp-config")
try:
EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root"
+ " core config "
+ "--dbname=\'{0}\' --dbprefix=\'{1}\' "
"--dbuser=\'{2}\' --dbhost=\'{3}\' "
.format(data['ee_db_name'], ee_wp_prefix,
data['ee_db_user'], data['ee_db_host']
)
+ "--dbpass=\'{0}\' "
"--extra-php<<PHP \n {1}\nPHP\""
.format(data['ee_db_pass'],
"\n\ndefine(\'WP_DEBUG\', false);"),
log=False
)
except CommandExecutionError as e:
raise SiteError("generate wp-config failed for wp single site")
else:
Log.debug(self, "Generating wp-config for WordPress multisite")
Log.debug(self, "bash -c \"php /usr/bin/wp --allow-root "
@ -220,24 +292,27 @@ def setupwordpress(self, data):
"\ndefine(\'WPMU_ACCEL_REDIRECT\',"
" true);",
"\n\ndefine(\'WP_DEBUG\', false);"))
EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root "
+ "core config "
+ "--dbname=\'{0}\' --dbprefix=\'{1}\' "
"--dbhost=\'{2}\' "
.format(data['ee_db_name'], ee_wp_prefix,
data['ee_db_host'])
+ "--dbuser=\'{0}\' --dbpass=\'{1}\' "
"--extra-php<<PHP \n {2} {3} {4}\nPHP\""
.format(data['ee_db_user'], data['ee_db_pass'],
"\ndefine(\'WP_ALLOW_MULTISITE\', "
"true);",
"\ndefine(\'WPMU_ACCEL_REDIRECT\',"
" true);",
"\n\ndefine(\'WP_DEBUG\', false);"),
log=False
) or Log.error(self,
"Unable to Generate "
"wp-config")
try:
EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root"
+ " core config "
+ "--dbname=\'{0}\' --dbprefix=\'{1}\' "
"--dbhost=\'{2}\' "
.format(data['ee_db_name'], ee_wp_prefix,
data['ee_db_host'])
+ "--dbuser=\'{0}\' --dbpass=\'{1}\' "
"--extra-php<<PHP \n {2} {3} {4}\nPHP\""
.format(data['ee_db_user'],
data['ee_db_pass'],
"\ndefine(\'WP_ALLOW_MULTISITE\', "
"true);",
"\ndefine(\'WPMU_ACCEL_REDIRECT\',"
" true);",
"\n\ndefine(\'WP_DEBUG\', false);"),
log=False
)
except CommandExecutionError as e:
raise SiteError("generate wp-config failed for wp multi site")
EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php',
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: ')
except EOFError as 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:
ee_wp_pass = ee_random
@ -263,7 +337,7 @@ def setupwordpress(self, data):
ee_wp_email = input('Enter WordPress email: ')
except EOFError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to input WordPress user email")
raise SiteError("input wordpress username failed")
try:
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: ")
except EOFError as 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")
@ -284,16 +358,17 @@ def setupwordpress(self, data):
.format(data['www_domain'], ee_wp_user)
+ "--admin_password= --admin_email=\'{1}\'"
.format(ee_wp_pass, ee_wp_email))
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core install "
"--url=\'{0}\' --title=\'{0}\' "
"--admin_name=\'{1}\' "
.format(data['www_domain'], ee_wp_user)
+ "--admin_password=\'{0}\' --admin_email=\'{1}\'"
.format(ee_wp_pass, ee_wp_email),
errormsg="Unable to setup WordPress Tables",
log=False) or Log.error(self,
"Unable to setup "
"WordPress Tables")
try:
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core "
"install --url=\'{0}\' --title=\'{0}\' "
"--admin_name=\'{1}\' "
.format(data['www_domain'], ee_wp_user)
+ "--admin_password=\'{0}\' "
"--admin_email=\'{1}\'"
.format(ee_wp_pass, ee_wp_email),
log=False)
except CommandExceutionError as e:
raise SiteError("setup wordpress tables failed for single site")
else:
Log.debug(self, "Creating tables for WordPress multisite")
Log.debug(self, "php /usr/bin/wp --allow-root "
@ -305,27 +380,29 @@ def setupwordpress(self, data):
.format(ee_wp_pass, ee_wp_email,
subdomains='--subdomains'
if not data['wpsubdir'] else ''))
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root "
"core multisite-install "
"--url=\'{0}\' --title=\'{0}\' "
"--admin_name=\'{1}\' "
.format(data['www_domain'], ee_wp_user)
+ "--admin_password=\'{0}\' "
"--admin_email=\'{1}\' "
"{subdomains}"
.format(ee_wp_pass, ee_wp_email,
subdomains='--subdomains'
if not data['wpsubdir'] else ''),
errormsg="Unable to setup WordPress Tables",
log=False) or Log.error(self,
"Unable to setup "
"WordPress Tables")
try:
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root "
"core multisite-install "
"--url=\'{0}\' --title=\'{0}\' "
"--admin_name=\'{1}\' "
.format(data['www_domain'], ee_wp_user)
+ "--admin_password=\'{0}\' "
"--admin_email=\'{1}\' "
"{subdomains}"
.format(ee_wp_pass, ee_wp_email,
subdomains='--subdomains'
if not data['wpsubdir'] else ''),
log=False)
except CommandExecutionError as e:
raise SiteError("setup wordpress tables failed for wp multi site")
Log.debug(self, "Updating WordPress permalink")
EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root "
"rewrite structure "
"/%year%/%monthnum%/%day%/%postname%/",
errormsg="Unable to Update WordPress permalink")
try:
EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root "
"rewrite structure "
"/%year%/%monthnum%/%day%/%postname%/")
except CommandExecutionError as e:
raise SiteError("Update wordpress permalinks failed")
"""Install nginx-helper plugin """
installwp_plugin(self, 'nginx-helper', data)
@ -348,44 +425,63 @@ def setupwordpressnetwork(self, data):
ee_site_webroot = data['webroot']
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
Log.info(self, "Setting up WordPress Network \t", end='')
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert'
' --title=\'{0}\' {subdomains}'
.format(data['www_domain'], subdomains='--subdomains'
if not data['wpsubdir'] else ''))
try:
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert'
' --title=\'{0}\' {subdomains}'
.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 + "]")
def installwp_plugin(self, plugin_name, data):
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))
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root install "
"{0}".format(plugin_name),
errormsg="Unable to Install plugin {0}"
.format(plugin_name))
try:
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin "
"--allow-root install "
"{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 "
"{0} {na}"
.format(plugin_name,
na='--network' if data['multisite'] else ''),
errormsg="Unable to Activate plugin {0}"
.format(plugin_name))
try:
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin "
"--allow-root activate "
"{0} {na}"
.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):
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))
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root uninstall "
"{0}".format(plugin_name),
errormsg="Unable to UnInstall plugin {0}"
.format(plugin_name))
try:
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin "
"--allow-root uninstall "
"{0}".format(plugin_name))
except CommandExecutionError as e:
raise SiteError("plugin uninstall failed")
def setwebrootpermissions(self, webroot):
Log.debug(self, "Setting up permissions")
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
try:
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):
@ -409,9 +505,12 @@ def sitebackup(self, data):
'DB_NAME').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
Log.info(self, 'Backing up database \t\t', end='')
EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql"
.format(ee_db_name, backup_path),
errormsg="\nFailed: Backup Database")
try:
EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql"
.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 + "]")
# move wp-config.php/ee-config.php to backup
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))
# Check if ee_domain is wordpress install
is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core"
" version",
errormsg="{0} : Unable to check if wp install"
.format(ee_domain))
try:
is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core"
" version")
except CommandExecutionError as e:
raise SiteError("is wordpress site? check command failed ")
# Exit if ee_domain is not wordpress install
if not is_wp:
@ -482,16 +582,21 @@ def updatewpuserpassword(self, ee_domain, ee_site_webroot):
if ee_wp_user == "?":
Log.info(self, "Fetching WordPress user list")
EEShellExec.cmd_exec(self, "wp --allow-root user list "
"--fields=user_login | grep -v user_login",
errormsg="Unable to Fetch users list")
try:
EEShellExec.cmd_exec(self, "wp --allow-root user list "
"--fields=user_login | grep -v user_login")
except CommandExecutionError as e:
raise SiteError("fetch wp userlist command failed")
if not ee_wp_user:
ee_wp_user = 'admin'
is_user_exist = EEShellExec.cmd_exec(self, "wp --allow-root user list "
"--fields=user_login | grep {0}$ "
.format(ee_wp_user))
try:
is_user_exist = EEShellExec.cmd_exec(self, "wp --allow-root user list "
"--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:
try:
@ -500,16 +605,18 @@ def updatewpuserpassword(self, ee_domain, ee_site_webroot):
.format(ee_wp_user))
except Exception as 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}"
" --user_pass={1}"
.format(ee_wp_user, ee_wp_pass))
Log.info(self, "Password updated successfully")
else:
Log.error(self, "Password Unchanged. Hint : Your password must be "
"8 characters long")
except CommandExecutionError as e:
raise SiteError("wp user password update command failed")
Log.info(self, "Password updated successfully")
if len(ee_wp_pass) < 8:
Log.warn(self, "Warning: You have provided a "
"weak password")
else:
Log.error(self, "Invalid WordPress user {0} for {1}."
.format(ee_wp_user, ee_domain))
@ -579,3 +686,125 @@ def logwatch(self, logfiles):
l = logwatch.LogWatcher(logfiles, callback)
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 ee.core.logging import Log
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 glob
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.
"""
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.commit()
except Exception as e:
@ -34,8 +39,9 @@ def getSiteInfo(self, site):
Log.error(self, "Unable to query database for site info")
def updateSiteInfo(self, site, stype='', cache='',
enabled=True, ssl=False, fs='', db=''):
def updateSiteInfo(self, site, stype='', cache='', webroot='',
enabled=True, ssl=False, fs='', db='', db_name=None,
db_user=None, db_password=None, db_host=None):
"""updates site record in database"""
try:
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:
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:
q.created_on = func.now()
db_session.commit()
@ -87,10 +108,56 @@ def deleteSiteInfo(self, site):
def getAllsites(self):
"""
1. returns all records from ee database
"""
try:
q = SiteDB.query.all()
return q
except Exception as e:
Log.debug(self, "{0}".format(e))
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'],
dict(help='Install Utils stack', action='store_true')),
]
usage = "ee stack (command) [options]"
@expose(hide=True)
def default(self):
@ -80,11 +81,16 @@ class EEStackController(CementBaseController):
"""Pre settings to do before installation packages"""
if set(EEVariables.ee_postfix).issubset(set(apt_packages)):
Log.debug(self, "Pre-seeding Postfix")
EEShellExec.cmd_exec(self, "echo \"postfix postfix"
"/main_mailer_type string \'Internet Site\'\""
" | debconf-set-selections")
EEShellExec.cmd_exec(self, "echo \"postfix postfix/mailname string"
" $(hostname -f)\" | debconf-set-selections")
try:
EEShellExec.cmd_exec(self, "echo \"postfix postfix"
"/main_mailer_type string \'Internet Site"
"\'\""
" | 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)):
Log.info(self, "Adding repository for MySQL, please wait ...")
@ -104,20 +110,30 @@ class EEStackController(CementBaseController):
"mysql-server/root_password "
"password \" | "
"debconf-set-selections")
EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
"mysql-server/root_password "
"password {chars}\" | "
"debconf-set-selections".format(chars=chars),
log=False)
try:
EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
"mysql-server/root_password "
"password {chars}\" | "
"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 "
"mysql-server/root_password_again "
"password \" | "
"debconf-set-selections")
EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
"mysql-server/root_password_again "
"password {chars}\" | "
"debconf-set-selections".format(chars=chars),
log=False)
try:
EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
"mysql-server/root_password_again "
"password {chars}\" | "
"debconf-set-selections"
.format(chars=chars),
log=False)
except CommandExecutionError as e:
Log.error("Failed to initialize MySQL package")
mysql_config = """
[client]
user = root
@ -151,17 +167,16 @@ class EEStackController(CementBaseController):
EERepo.add(self, ppa=EEVariables.ee_php_repo)
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.')
EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core/"
"create-ssl-cert boolean yes\" "
"| debconf-set-selections")
EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core"
"/ssl-cert-name string $(hostname -f)\""
" | debconf-set-selections")
try:
EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core/"
"create-ssl-cert boolean yes\" "
"| debconf-set-selections")
EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core"
"/ssl-cert-name string $(hostname -f)\""
" | debconf-set-selections")
except CommandExecutionError as e:
Log.error("Failed to initialize dovecot packages")
@expose(hide=True)
def post_pref(self, apt_packages, packages):
@ -173,7 +188,7 @@ class EEStackController(CementBaseController):
EEService.reload_service(self, 'postfix')
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')):
nc = NginxConfig()
Log.debug(self, 'Loading file /etc/nginx/nginx.conf ')
@ -306,11 +321,15 @@ class EEStackController(CementBaseController):
passwd = ''.join([random.choice
(string.ascii_letters + string.digits)
for n in range(6)])
EEShellExec.cmd_exec(self, "printf \"easyengine:"
"$(openssl passwd -crypt "
"{password} 2> /dev/null)\n\""
"> /etc/nginx/htpasswd-ee 2>/dev/null"
.format(password=passwd))
try:
EEShellExec.cmd_exec(self, "printf \"easyengine:"
"$(openssl passwd -crypt "
"{password} 2> /dev/null)\n\""
"> /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
EEFileUtils.create_symlink(self, ['/etc/nginx/'
@ -350,40 +369,46 @@ class EEStackController(CementBaseController):
.format(EEVariables.ee_webroot)]
)
EEShellExec.cmd_exec(self, "openssl genrsa -out "
"{0}22222/cert/22222.key 2048"
.format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "openssl req -new -batch -subj "
"/commonName=127.0.0.1/ -key "
"{0}22222/cert/22222.key "
"-out {0}22222/cert/"
"22222.csr"
.format(EEVariables.ee_webroot))
EEFileUtils.mvfile(self, "{0}22222/cert/22222.key"
.format(EEVariables.ee_webroot),
try:
EEShellExec.cmd_exec(self, "openssl genrsa -out "
"{0}22222/cert/22222.key 2048"
.format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "openssl req -new -batch "
"-subj /commonName=127.0.0.1/ "
"-key {0}22222/cert/22222.key "
"-out {0}22222/cert/"
"22222.csr"
.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/"
"22222.key.org"
.format(EEVariables.ee_webroot))
"22222.key.org -out "
"{0}22222/cert/22222.key"
.format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "openssl rsa -in "
"{0}22222/cert/"
"22222.key.org -out "
"{0}22222/cert/22222.key"
.format(EEVariables.ee_webroot))
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))
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
EEGit.add(self,
["/etc/nginx"], msg="Adding Nginx into Git")
EEService.reload_service(self, 'nginx')
self.msg = (self.msg + ["HTTP Auth User Name: easyengine"]
+ ["HTTP Auth Password : {0}".format(passwd)])
if set(EEVariables.ee_php).issubset(set(apt_packages)):
# Create log directories
if not os.path.exists('/var/log/php5/'):
@ -513,37 +538,49 @@ class EEStackController(CementBaseController):
# config.write(configfile)
if not os.path.isfile("/etc/mysql/my.cnf"):
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",
encoding='utf-8', mode='w')
config_file.write(config)
config_file.close()
else:
EEShellExec.cmd_exec(self, "sed -i \"/#max_connections/a "
"wait_timeout = 30 \\n"
"interactive_timeout = 60 \\n"
"performance_schema = 0\" "
"/etc/mysql/my.cnf")
try:
EEShellExec.cmd_exec(self, "sed -i \"/#max_conn"
"ections/a wait_timeout = 30 \\n"
"interactive_timeout = 60 \\n"
"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")
EEService.reload_service(self, 'mysql')
if set(EEVariables.ee_mail).issubset(set(apt_packages)):
Log.debug(self, "Adding user")
EEShellExec.cmd_exec(self, "adduser --uid 5000 --home /var"
"/vmail --disabled-password --gecos ''"
" vmail")
EEShellExec.cmd_exec(self, "openssl req -new -x509 -days 3650 "
"-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))
try:
EEShellExec.cmd_exec(self, "adduser --uid 5000 --home /var"
"/vmail --disabled-password --gecos "
"'' vmail")
except CommandExecutionError as e:
Log.error(self, "Unable to add vmail user for mail server")
try:
EEShellExec.cmd_exec(self, "openssl req -new -x509 -days"
" 3650 "
"-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 "
"/etc/ssl/private/dovecot.pem file ")
EEShellExec.cmd_exec(self, "chmod 0600 /etc/ssl/private"
"/dovecot.pem")
EEFileUtils.chmod(self, "/etc/ssl/private/dovecot.pem", 0o600)
# Custom Dovecot configuration by EasyEngine
data = dict()
@ -562,82 +599,95 @@ class EEStackController(CementBaseController):
encoding='utf-8', mode='w')
self.app.render((data), 'dovecot.mustache', out=ee_dovecot)
ee_dovecot.close()
EEShellExec.cmd_exec(self, "sed -i \"s/\\!include "
"auth-system.conf.ext/#\\!include "
"auth-system.conf.ext/\" "
"/etc/dovecot/conf.d/10-auth.conf")
EEShellExec.cmd_exec(self, "sed -i \"s\'/etc/dovecot/"
"dovecot.pem\'/etc/ssl/certs/dovecot.pem"
"\'\" /etc/dovecot/conf.d/10-ssl.conf")
EEShellExec.cmd_exec(self, "sed -i \"s\'/etc/dovecot/"
"private/dovecot.pem\'/etc/ssl/private"
"/dovecot.pem\'\" /etc/dovecot/conf.d/"
"10-ssl.conf")
# Custom Postfix configuration needed with Dovecot
# Changes in master.cf
# TODO: Find alternative for sed in Python
EEShellExec.cmd_exec(self, "sed -i \'s/#submission/submission"
"/\'"
" /etc/postfix/master.cf")
EEShellExec.cmd_exec(self, "sed -i \'s/#smtps/smtps/\'"
" /etc/postfix/master.cf")
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_type = "
"dovecot\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_path = "
"private/auth\"")
EEShellExec.cmd_exec(self, "postconf -e \""
"smtpd_sasl_auth_enable = "
"yes\"")
EEShellExec.cmd_exec(self, "postconf -e \""
" smtpd_relay_restrictions ="
" permit_sasl_authenticated, "
" permit_mynetworks, "
" reject_unauth_destination\"")
EEShellExec.cmd_exec(self, "postconf -e \""
"smtpd_tls_mandatory_"
"protocols = !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtp_tls_mandatory_"
"protocols = !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_tls_protocols "
" = !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtp_tls_protocols "
"= !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec(self, "postconf -e \"mydestination "
"= localhost\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_transport "
"= lmtp:unix:private/dovecot-lmtp\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_uid_maps "
"= static:5000\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_gid_maps "
"= static:5000\"")
EEShellExec.cmd_exec(self, "postconf -e \""
" virtual_mailbox_domains = "
"mysql:/etc/postfix/mysql/virtual_"
"domains_maps.cf\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_mailbox_maps"
" = mysql:/etc/postfix/mysql/virtual_"
"mailbox_maps.cf\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_alias_maps "
"= mysql:/etc/postfix/mysql/virtual_"
"alias_maps.cf\"")
EEShellExec.cmd_exec(self, "openssl req -new -x509 -days "
" 3650 -nodes -subj /commonName="
"{HOSTNAME}/emailAddress={EMAIL}"
" -out /etc/ssl/certs/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\"")
try:
EEShellExec.cmd_exec(self, "sed -i \"s/\\!include "
"auth-system.conf.ext/#\\!include "
"auth-system.conf.ext/\" "
"/etc/dovecot/conf.d/10-auth.conf")
EEShellExec.cmd_exec(self, "sed -i \"s\'/etc/dovecot/"
"dovecot.pem\'/etc/ssl/certs/"
"dovecot.pem"
"\'\" /etc/dovecot/conf.d/"
"10-ssl.conf")
EEShellExec.cmd_exec(self, "sed -i \"s\'/etc/dovecot/"
"private/dovecot.pem\'/etc/ssl/"
"private"
"/dovecot.pem\'\" /etc/dovecot/"
"conf.d/"
"10-ssl.conf")
# Custom Postfix configuration needed with Dovecot
# Changes in master.cf
# TODO: Find alternative for sed in Python
EEShellExec.cmd_exec(self, "sed -i \'s/#submission/"
"submission/\'"
" /etc/postfix/master.cf")
EEShellExec.cmd_exec(self, "sed -i \'s/#smtps/smtps/\'"
" /etc/postfix/master.cf")
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_type "
"= dovecot\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_path "
"= private/auth\"")
EEShellExec.cmd_exec(self, "postconf -e \""
"smtpd_sasl_auth_enable = "
"yes\"")
EEShellExec.cmd_exec(self, "postconf -e \""
" smtpd_relay_restrictions ="
" permit_sasl_authenticated, "
" permit_mynetworks, "
" reject_unauth_destination\"")
EEShellExec.cmd_exec(self, "postconf -e \""
"smtpd_tls_mandatory_"
"protocols = !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtp_tls_"
"mandatory_protocols = !SSLv2,"
"!SSLv3\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtpd_tls"
"_protocols = !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec(self, "postconf -e \"smtp_tls"
"_protocols = !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec(self, "postconf -e \"mydestination "
"= localhost\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual"
"_transport "
"= lmtp:unix:private/dovecot-lmtp\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_uid_"
"maps = static:5000\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_gid_"
"maps = static:5000\"")
EEShellExec.cmd_exec(self, "postconf -e \""
" virtual_mailbox_domains = "
"mysql:/etc/postfix/mysql/virtual_"
"domains_maps.cf\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_mailbox"
"_maps"
" = mysql:/etc/postfix/mysql/virtual_"
"mailbox_maps.cf\"")
EEShellExec.cmd_exec(self, "postconf -e \"virtual_alias"
"_maps "
"= mysql:/etc/postfix/mysql/virtual_"
"alias_maps.cf\"")
EEShellExec.cmd_exec(self, "openssl req -new -x509 -days "
" 3650 -nodes -subj /commonName="
"{hostname}/emailAddress={email}"
" -out /etc/ssl/certs/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
if not os.path.exists('/var/lib/dovecot/sieve/'):
@ -661,8 +711,12 @@ class EEStackController(CementBaseController):
# "/dovecot")
EEFileUtils.chown(self, "/var/lib/dovecot", 'vmail', 'vmail',
recursive=True)
EEShellExec.cmd_exec(self, "sievec /var/lib/dovecot/sieve/"
"default.sieve")
try:
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"],
msg="Installed mail server")
EEService.restart_service(self, 'dovecot')
@ -695,13 +749,17 @@ class EEStackController(CementBaseController):
vm_config.close()
# Amavis postfix configuration
EEShellExec.cmd_exec(self, "postconf -e \"content_filter = "
"smtp-amavis:[127.0.0.1]:10024\"")
EEShellExec.cmd_exec(self, "sed -i \"s/1 pickup/1 "
"pickup"
"\\n -o content_filter=\\n -o"
" receive_override_options=no_header_body"
"_checks/\" /etc/postfix/master.cf")
try:
EEShellExec.cmd_exec(self, "postconf -e \"content_filter ="
" smtp-amavis:[127.0.0.1]:10024\"")
EEShellExec.cmd_exec(self, "sed -i \"s/1 pickup/1 "
" pickup"
"\\n -o content_filter=\\n "
" -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
-o smtp_data_done_timeout=1200
@ -730,19 +788,22 @@ class EEStackController(CementBaseController):
encoding='utf-8', mode='a') as am_config:
am_config.write(amavis_master)
# Amavis ClamAV configuration
Log.debug(self, "Adding new user clamav amavis")
EEShellExec.cmd_exec(self, "adduser clamav amavis")
Log.debug(self, "Adding new user amavis clamav")
EEShellExec.cmd_exec(self, "adduser amavis clamav")
Log.debug(self, "Setting Privileges to /var/lib/amavis/tmp ")
EEShellExec.cmd_exec(self, "chmod -R 775 /var/lib/amavis/tmp")
# Update ClamAV database
Log.debug(self, "Updating database")
EEShellExec.cmd_exec(self, "freshclam")
Log.debug(self, "Restarting clamav-daemon service")
EEShellExec.cmd_exec(self, "service clamav-daemon restart")
try:
# Amavis ClamAV configuration
Log.debug(self, "Adding new user clamav amavis")
EEShellExec.cmd_exec(self, "adduser clamav amavis")
Log.debug(self, "Adding new user amavis clamav")
EEShellExec.cmd_exec(self, "adduser amavis clamav")
Log.debug(self, "Setting Privileges to /var/lib/amavis"
"/tmp")
EEFileUtils.chmod(self, "/var/lib/amavis/tmp", 0o755)
# Update ClamAV database
Log.debug(self, "Updating database")
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")
EEService.restart_service(self, 'dovecot')
EEService.reload_service(self, 'postfix')
@ -751,7 +812,8 @@ class EEStackController(CementBaseController):
if len(packages):
if any('/usr/bin/wp' == x[1] for x in packages):
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]
for x in packages):
EEExtract.extract(self, '/tmp/pma.tar.gz', '/tmp/')
@ -834,9 +896,13 @@ class EEStackController(CementBaseController):
'{0}22222/htdocs/db/anemometer'
.format(EEVariables.ee_webroot))
chars = ''.join(random.sample(string.ascii_letters, 8))
EEShellExec.cmd_exec(self, 'mysql < {0}22222/htdocs/db'
'/anemometer/install.sql'
.format(EEVariables.ee_webroot))
try:
EEShellExec.cmd_exec(self, 'mysql < {0}22222/htdocs/db'
'/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\''
'@\'{0}\''.format(self.app.config.get('mysql',
'grant-host')))
@ -863,8 +929,7 @@ class EEStackController(CementBaseController):
if any('/usr/bin/pt-query-advisor' == x[1]
for x in packages):
EEShellExec.cmd_exec(self, "chmod +x /usr/bin/pt-query"
"-advisor")
EEFileUtils.chmod(self, "/usr/bin/pt-query-advisor", 0o775)
if any('/tmp/vimbadmin.tar.gz' == x[1] for x in packages):
# Extract ViMbAdmin
@ -886,18 +951,23 @@ class EEStackController(CementBaseController):
# Donwload composer and install ViMbAdmin
Log.debug(self, "Downloading composer "
"https://getcomposer.org/installer | php ")
EEShellExec.cmd_exec(self, "cd {0}22222/htdocs"
"/vimbadmin; curl"
" -sS https://getcomposer.org/installer |"
" php".format(EEVariables.ee_webroot))
Log.debug(self, "installation of composer")
EEShellExec.cmd_exec(self, "cd {0}22222/htdocs"
"/vimbadmin && "
"php composer.phar install --prefer-dist"
" --no-dev && rm -f {1}22222/htdocs"
"/vimbadmin/composer.phar"
.format(EEVariables.ee_webroot,
EEVariables.ee_webroot))
try:
EEShellExec.cmd_exec(self, "cd {0}22222/htdocs"
"/vimbadmin; curl"
" -sS https://getcomposer.org/"
"installer |"
" php".format(EEVariables.ee_webroot))
Log.debug(self, "Installating of composer")
EEShellExec.cmd_exec(self, "cd {0}22222/htdocs"
"/vimbadmin && "
"php composer.phar install "
"--prefer-dist"
" --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
vm_passwd = ''.join(random.sample(string.ascii_letters, 8))
@ -942,9 +1012,13 @@ class EEStackController(CementBaseController):
"{0}22222/htdocs/vimbadmin/bin"
"/doctrine2-cli.php orm:schema-tool:"
"create".format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "{0}22222/htdocs/vimbadmin"
"/bin/doctrine2-cli.php orm:schema-tool:"
"create".format(EEVariables.ee_webroot))
try:
EEShellExec.cmd_exec(self, "{0}22222/htdocs/vimbadmin"
"/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'
.format(EEVariables.ee_webroot),

12
ee/core/database.py

@ -13,12 +13,16 @@ Base = declarative_base()
Base.query = db_session.query_property()
def init_db():
def init_db(app):
"""
Initializes and creates all tables from models into the database
"""
# 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)
# # you will have to import them first before calling init_db()
# import ee.core.models
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
"""
print(Log.WARNING + msg + Log.ENDC)
self.app.log.warn(Log.BOLD + msg + Log.ENDC)
def debug(self, msg):

117
ee/core/mysql.py

@ -1,5 +1,6 @@
"""EasyEngine MySQL core classes."""
import pymysql
from pymysql import connections, DatabaseError, Error
import configparser
from os.path import expanduser
import sys
@ -8,59 +9,71 @@ from ee.core.logging import Log
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():
"""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):
"""Get login details from ~/.my.cnf & Execute MySQL query"""
config = configparser.RawConfigParser()
cnfpath = expanduser("~")+"/.my.cnf"
if [cnfpath] == config.read(cnfpath):
user = config.get('client', 'user')
passwd = config.get('client', 'password')
try:
host = config.get('client', 'host')
except configparser.NoOptionError as e:
host = 'localhost'
try:
port = config.get('client', 'port')
except configparser.NoOptionError as e:
port = '3306'
try:
conn = pymysql.connect(host=host, port=int(port),
user=user, passwd=passwd)
cur = conn.cursor()
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))
connection = EEMysql.connect(self)
log and Log.debug(self, "Exceuting MySQL Statement : {0}"
.format(statement))
try:
cursor = connection.cursor()
sql = statement
cursor.execute(sql)
# connection is not autocommit by default.
# So you must commit to save your changes.
connection.commit()
except AttributeError as e:
Log.debug(self, str(e))
raise StatementExcecutionError
except Error as e:
Log.debug(self, str(e))
raise StatementExcecutionError
finally:
connection.close()
def backupAll(self):
import subprocess
@ -101,3 +114,11 @@ class EEMysql():
except Exception as e:
Log.error(self, "Error: process exited with status %s"
% 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
class CommandExecutionError(Exception):
"""custom Exception for command execution"""
pass
class EEShellExec():
"""Method to run shell commands"""
def __init__():
@ -13,8 +18,8 @@ class EEShellExec():
def cmd_exec(self, command, errormsg='', log=True):
"""Run shell command from Python"""
try:
if log:
Log.debug(self, "Running command: {0}".format(command))
log and Log.debug(self, "Running command: {0}".format(command))
with subprocess.Popen([command], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True) as proc:
(cmd_stdout_bytes, cmd_stderr_bytes) = proc.communicate()
@ -26,25 +31,15 @@ class EEShellExec():
if proc.returncode == 0:
return True
else:
Log.debug(self, "Command Output: {0}, Command Error: {1}"
Log.debug(self, "Command Output: {0}, \nCommand Error: {1}"
.format(cmd_stdout, cmd_stderr))
return False
except OSError as e:
if errormsg:
Log.error(self, errormsg)
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")
Log.debug(self, str(e))
raise CommandExecutionError
except Exception as e:
if errormsg:
Log.error(self, errormsg)
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")
Log.debug(self, str(e))
raise CommandExecutionError
def invoke_editor(self, filepath, errormsg=''):
"""
@ -53,8 +48,5 @@ class EEShellExec():
try:
subprocess.call(['sensible-editor', filepath])
except OSError as e:
if errormsg:
Log.error(self, errormsg)
else:
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"""
# EasyEngine version
ee_version = "3.0.6"
ee_version = "3.0.7"
# EasyEngine packages versions
ee_wp_cli = "0.18.0"
ee_adminer = "4.1.0"
ee_roundcube = "1.1.0"
ee_roundcube = "1.1.1"
ee_vimbadmin = "3.0.11"
# Current date and time of System

181
install

@ -48,7 +48,7 @@ fi
# Define variables for later use
ee_branch=$1
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_install_log=/var/log/ee/install.log
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
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,
sitename UNIQUE,
site_type CHAR,
@ -117,87 +118,102 @@ function ee_sync_db()
storage_db CHAR
);" | sqlite3 /var/lib/ee/ee.db
# Check site is enable/live or disable
for site in $(ls /etc/nginx/sites-available/ | grep -v default);
do
if [ -f /etc/nginx/sites-enabled/$site ]; then
ee_site_status='1'
else
ee_site_status='0'
fi
# Check site is enable/live or disable
for site in $(ls /etc/nginx/sites-available/ | grep -v default);
do
if [ -f /etc/nginx/sites-enabled/$site ]; then
ee_site_status='1'
else
ee_site_status='0'
fi
# 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)
# Detect current website type and cache
if [ "$ee_site_current_type" = "HTML" ]; then
ee_site_current="html"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "PHP" ]; then
ee_site_current="php"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "MYSQL" ]; then
ee_site_current="mysql"
ee_site_current_cache="basic"
# Single WordPress
elif [ "$ee_site_current_type" = "WPSINGLE BASIC" ]; then
ee_site_current="wp"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "WPSINGLE WP SUPER CACHE" ]; then
ee_site_current="wp"
ee_site_current_cache="wpsc"
elif [ "$ee_site_current_type" = "WPSINGLE W3 TOTAL CACHE" ]; then
ee_site_current="wp"
ee_site_current_cache="w3tc"
elif [ "$ee_site_current_type" = "WPSINGLE FAST CGI" ] || [ "$ee_site_current_type" = "WPSINGLE FASTCGI" ]; then
ee_site_current="wp"
ee_site_current_cache="wpfc"
# WordPress subdirectory
elif [ "$ee_site_current_type" = "WPSUBDIR BASIC" ]; then
ee_site_current="wpsubdir"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "WPSUBDIR WP SUPER CACHE" ]; then
ee_site_current="wpsubdir"
ee_site_current_cache="wpsc"
elif [ "$ee_site_current_type" = "WPSUBDIR W3 TOTAL CACHE" ]; then
ee_site_current="wpsubdir"
ee_site_current_cache="w3tc"
elif [ "$ee_site_current_type" = "WPSUBDIR FAST CGI" ] || [ "$ee_site_current_type" = "WPSUBDIR FASTCGI" ]; then
ee_site_current="wpsubdir"
ee_site_current_cache="wpfc"
# WordPress subdomain
elif [ "$ee_site_current_type" = "WPSUBDOMAIN BASIC" ]; then
ee_site_current="wpsubdomain"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "WPSUBDOMAIN WP SUPER CACHE" ]; then
ee_site_current="wpsubdomain"
ee_site_current_cache="wpsc"
elif [ "$ee_site_current_type" = "WPSUBDOMAIN W3 TOTAL CACHE" ]; then
ee_site_current="wpsubdomain"
ee_site_current_cache="w3tc"
elif [ "$ee_site_current_type" = "WPSUBDOMAIN FAST CGI" ] || [ "$ee_site_current_type" = "WPSUBDOMAIN FASTCGI" ]; then
ee_site_current="wpsubdomain"
ee_site_current_cache="wpfc"
fi
# 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)
# Detect current website type and cache
if [ "$ee_site_current_type" = "HTML" ]; then
ee_site_current="html"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "PHP" ]; then
ee_site_current="php"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "MYSQL" ]; then
ee_site_current="mysql"
ee_site_current_cache="basic"
# Single WordPress
elif [ "$ee_site_current_type" = "WPSINGLE BASIC" ]; then
ee_site_current="wp"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "WPSINGLE WP SUPER CACHE" ]; then
ee_site_current="wp"
ee_site_current_cache="wpsc"
elif [ "$ee_site_current_type" = "WPSINGLE W3 TOTAL CACHE" ]; then
ee_site_current="wp"
ee_site_current_cache="w3tc"
elif [ "$ee_site_current_type" = "WPSINGLE FAST CGI" ] || [ "$ee_site_current_type" = "WPSINGLE FASTCGI" ]; then
ee_site_current="wp"
ee_site_current_cache="wpfc"
# WordPress subdirectory
elif [ "$ee_site_current_type" = "WPSUBDIR BASIC" ]; then
ee_site_current="wpsubdir"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "WPSUBDIR WP SUPER CACHE" ]; then
ee_site_current="wpsubdir"
ee_site_current_cache="wpsc"
elif [ "$ee_site_current_type" = "WPSUBDIR W3 TOTAL CACHE" ]; then
ee_site_current="wpsubdir"
ee_site_current_cache="w3tc"
elif [ "$ee_site_current_type" = "WPSUBDIR FAST CGI" ] || [ "$ee_site_current_type" = "WPSUBDIR FASTCGI" ]; then
ee_site_current="wpsubdir"
ee_site_current_cache="wpfc"
# WordPress subdomain
elif [ "$ee_site_current_type" = "WPSUBDOMAIN BASIC" ]; then
ee_site_current="wpsubdomain"
ee_site_current_cache="basic"
elif [ "$ee_site_current_type" = "WPSUBDOMAIN WP SUPER CACHE" ]; then
ee_site_current="wpsubdomain"
ee_site_current_cache="wpsc"
elif [ "$ee_site_current_type" = "WPSUBDOMAIN W3 TOTAL CACHE" ]; then
ee_site_current="wpsubdomain"
ee_site_current_cache="w3tc"
elif [ "$ee_site_current_type" = "WPSUBDOMAIN FAST CGI" ] || [ "$ee_site_current_type" = "WPSUBDOMAIN FASTCGI" ]; then
ee_site_current="wpsubdomain"
ee_site_current_cache="wpfc"
fi
ee_webroot="/var/www/$site"
ee_webroot="/var/www/$site"
# 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)
VALUES (\"$site\", \"$ee_site_current\", \"$ee_site_current_cache\", \"$ee_webroot\", \"$ee_site_status\", 0, 'ext4', 'mysql');" | sqlite3 /var/lib/ee/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)
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
ee_install_dep | 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_update | tee -ai $ee_install_log
ee_git_init | tee -ai $ee_install_log
elif [ ! -f /usr/local/bin/ee ]; then
ee_install_dep | 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
else
ee -v 2>&1 | grep $ee_version_new &>> /dev/null
if [[ $? -ne 0 ]];then
read -p "Update EasyEngine to $ee_version_new (y/n): " ee_ans
if [ "$ee_ans" = "y" ] || [ "$ee_ans" = "Y" ]; then
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_install | 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))
setup(name='ee',
version='3.0.6',
version='3.0.7',
description=long_description,
long_description=long_description,
classifiers=[],

Loading…
Cancel
Save