Exemplo n.º 1
0
    def add(self):
        """Swap addition with EasyEngine"""
        if EEVariables.ee_ram < 512:
            if EEVariables.ee_swap < 1000:
                Log.info(self, "Adding SWAP")

                # Install dphys-swapfile
                EEAptGet.update(self)
                EEAptGet.install(self, ["dphys-swapfile"])
                # Stop service
                EEShellExec.cmd_exec(self, "service dphys-swapfile stop")
                # Remove Default swap created
                EEShellExec.cmd_exec(self, "/sbin/dphys-swapfile uninstall")

                # Modify Swap configuration
                if os.path.isfile("/etc/dphys-swapfile"):
                    EEFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_SWAPFILE=/var/swap",
                                              "CONF_SWAPFILE=/ee-swapfile")
                    EEFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_MAXSWAP=2048",
                                              "CONF_MAXSWAP=1024")
                    EEFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_SWAPSIZE=",
                                              "CONF_SWAPSIZE=1024")
                else:
                    with open("/etc/dphys-swapfile", 'w') as conffile:
                        conffile.write("CONF_SWAPFILE=/ee-swapfile\n"
                                       "CONF_SWAPSIZE=1024\n"
                                       "CONF_MAXSWAP=1024\n")
                # Create swap file
                EEShellExec.cmd_exec(self, "service dphys-swapfile start")
Exemplo n.º 2
0
    def default(self):
        if ((not self.app.pargs.mariadb)):
            self.app.args.print_help()
        if self.app.pargs.mariadb:
            if EEVariables.ee_mysql_host is not "localhost":
                Log.error(
                    self, "Remote MySQL found, EasyEngine will not "
                    "install MariaDB")

            if EEShellExec.cmd_exec(self, "mysqladmin ping") and (
                    not EEAptGet.is_installed(self, 'mariadb-server')):

                Log.info(
                    self, "If your database size is big, "
                    "migration may take some time.")
                Log.info(
                    self, "During migration non nginx-cached parts of "
                    "your site may remain down")
                start_migrate = input("Type \"mariadb\" to continue:")
                if start_migrate != "mariadb":
                    Log.error(self, "Not starting migration")
                self.migrate_mariadb()
            else:
                Log.error(
                    self, "Your current MySQL is not alive or "
                    "you allready installed MariaDB")
Exemplo n.º 3
0
 def clean_redis(self):
     """This function clears Redis cache"""
     if (EEAptGet.is_installed(self, "redis-server")):
         Log.info(self, "Cleaning Redis cache")
         EEShellExec.cmd_exec(self, "redis-cli flushall")
     else:
         Log.info(self, "Redis is not installed")
Exemplo n.º 4
0
 def clean_fastcgi(self):
     """This function clears Fastcgi cache"""
     if (os.path.isdir("/var/run/nginx-cache")):
         Log.info(self, "Cleaning NGINX FastCGI cache")
         EEShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*")
     else:
         Log.error(self, "Unable to clean FastCGI cache", False)
Exemplo n.º 5
0
    def add(self):
        """Swap addition with EasyEngine"""
        if EEVariables.ee_ram < 512:
            if EEVariables.ee_swap < 1000:
                Log.info(self, "Adding SWAP file, please wait...")

                # Install dphys-swapfile
                EEAptGet.update(self)
                EEAptGet.install(self, ["dphys-swapfile"])
                # Stop service
                EEShellExec.cmd_exec(self, "service dphys-swapfile stop")
                # Remove Default swap created
                EEShellExec.cmd_exec(self, "/sbin/dphys-swapfile uninstall")

                # Modify Swap configuration
                if os.path.isfile("/etc/dphys-swapfile"):
                    EEFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_SWAPFILE=/var/swap",
                                              "CONF_SWAPFILE=/ee-swapfile")
                    EEFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_MAXSWAP=2048",
                                              "CONF_MAXSWAP=1024")
                    EEFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_SWAPSIZE=",
                                              "CONF_SWAPSIZE=1024")
                else:
                    with open("/etc/dphys-swapfile", 'w') as conffile:
                        conffile.write("CONF_SWAPFILE=/ee-swapfile\n"
                                       "CONF_SWAPSIZE=1024\n"
                                       "CONF_MAXSWAP=1024\n")
                # Create swap file
                EEShellExec.cmd_exec(self, "service dphys-swapfile start")
Exemplo n.º 6
0
 def clean_pagespeed(self):
     """This function clears Pagespeed cache"""
     if (os.path.isdir("/var/ngx_pagespeed_cache")):
         Log.info(self, "Cleaning PageSpeed cache")
         EEShellExec.cmd_exec(self, "rm -rf /var/ngx_pagespeed_cache/*")
     else:
         Log.error(self, "Unable to clean Pagespeed cache")
Exemplo n.º 7
0
    def remove(self, packages, auto=False, purge=False):
        all_packages = ' '.join(packages)
        try:
            with open('/var/log/ee/ee.log', 'a') as f:
                if purge:
                    proc = subprocess.Popen('apt-get purge -y {0}'
                                            .format(all_packages), shell=True,
                                            stdin=None, stdout=f, stderr=f,
                                            executable="/bin/bash")
                else:
                    proc = subprocess.Popen('apt-get remove -y {0}'
                                            .format(all_packages), shell=True,
                                            stdin=None, stdout=f, stderr=f,
                                            executable="/bin/bash")
                proc.wait()
            if proc.returncode == 0:
                return True
            else:
                Log.info(self, Log.FAIL + "Oops Something went "
                         "wrong!!")
                Log.error(self, "Check logs for reason "
                          "`tail /var/log/ee/ee.log` & Try Again!!!")

        except Exception as e:
            Log.error(self, "Error while installing packages, "
                      "apt-get exited with error")
Exemplo n.º 8
0
 def clean_pagespeed(self):
     """This function clears Pagespeed cache"""
     if(os.path.isdir("/var/ngx_pagespeed_cache")):
         Log.info(self, "Cleaning PageSpeed cache")
         EEShellExec.cmd_exec(self, "rm -rf /var/ngx_pagespeed_cache/*")
     else:
         Log.error(self, "Unable to clean Pagespeed cache")
Exemplo n.º 9
0
 def download(self, packages):
     """Download packages, packges must be list in format of
     [url, path, package name]"""
     for package in packages:
         url = package[0]
         filename = package[1]
         pkg_name = package[2]
         try:
             directory = os.path.dirname(filename)
             if not os.path.exists(directory):
                 os.makedirs(directory)
             Log.info(self, "Downloading {0:20}".format(pkg_name), end=' ')
             urllib.request.urlretrieve(url, filename)
             Log.info(self, "{0}".format("[" + Log.ENDC + "Done"
                                         + Log.OKBLUE + "]"))
         except urllib.error.URLError as e:
             Log.debug(self, "[{err}]".format(err=str(e.reason)))
             Log.error(self, "Unable to download file, {0}"
                       .format(filename))
             return False
         except urllib.error.HTTPError as e:
             Log.error(self, "Package download failed. {0}"
                       .format(pkg_name))
             Log.debug(self, "[{err}]".format(err=str(e.reason)))
             return False
         except urllib.error.ContentTooShortError as e:
             Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
             Log.error(self, "Package download failed. The amount of the"
                       " downloaded data is less than "
                       "the expected amount \{0} ".format(pkg_name))
             return False
Exemplo n.º 10
0
 def clean_fastcgi(self):
     """This function clears Fastcgi cache"""
     if(os.path.isdir("/var/run/nginx-cache")):
         Log.info(self, "Cleaning NGINX FastCGI cache")
         EEShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*")
     else:
         Log.error(self, "Unable to clean FastCGI cache", False)
Exemplo n.º 11
0
 def clean_redis(self):
     """This function clears Redis cache"""
     if(EEAptGet.is_installed(self, "redis-server")):
         Log.info(self, "Cleaning Redis cache")
         EEShellExec.cmd_exec(self, "redis-cli flushall")
     else:
         Log.info(self, "Redis is not installed")
Exemplo n.º 12
0
def sitebackup(self, data):
    ee_site_webroot = data['webroot']
    backup_path = ee_site_webroot + '/backup/{0}'.format(EEVariables.ee_date)
    if not EEFileUtils.isexist(self, backup_path):
        EEFileUtils.mkdir(self, backup_path)
    Log.info(self, "Backup location : {0}".format(backup_path))
    EEFileUtils.copyfile(
        self, '/etc/nginx/sites-available/{0}'.format(data['site_name']),
        backup_path)

    if data['currsitetype'] in ['html', 'php', 'mysql']:
        Log.info(self, "Backing up Webroot \t\t", end='')
        EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path)
        Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")

    configfiles = glob.glob(ee_site_webroot + '/*-config.php')

    if configfiles and EEFileUtils.isexist(self, configfiles[0]):
        ee_db_name = (EEFileUtils.grep(
            self, configfiles[0],
            '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")
        Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
        # move wp-config.php/ee-config.php to backup
        if data['currsitetype'] in ['mysql']:
            EEFileUtils.mvfile(self, configfiles[0], backup_path)
        else:
            EEFileUtils.copyfile(self, configfiles[0], backup_path)
Exemplo n.º 13
0
 def status(self):
     """Status of services"""
     services = []
     if self.app.pargs.nginx:
         Log.debug(self, "nginx service status")
         services = services + ['nginx']
     if self.app.pargs.php:
         Log.debug(self, "php5-fpm service status")
         services = services + ['php5-fpm']
     if self.app.pargs.mysql:
         if EEVariables.ee_mysql_host is "localhost":
             Log.debug(self, "mysql service status")
             services = services + ['mysql']
         else:
             Log.warn(
                 self, "Remote MySQL found, "
                 "unable to get MySQL service status")
     if self.app.pargs.postfix:
         services = services + ['postfix']
         Log.debug(self, "postfix service status")
     if self.app.pargs.memcache:
         Log.debug(self, "memcached service status")
         services = services + ['memcached']
     if self.app.pargs.dovecot:
         Log.debug(self, "dovecot service status")
         services = services + ['dovecot']
     if not services and EEVariables.ee_mysql_host is "localhost":
         services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
         Log.debug(self, "nginx,php5-fpm,mysql,postfix services status")
     elif not services:
         services = services + ['nginx', 'php5-fpm', 'postfix']
         Log.debug(self, "nginx,php5-fpm,postfix services status")
     for service in services:
         if EEService.get_service_status(self, service):
             Log.info(self, "{0:10}:  {1}".format(service, "Running"))
Exemplo n.º 14
0
 def status(self):
     """Status of services"""
     services = []
     if self.app.pargs.nginx:
         Log.debug(self, "nginx service status")
         services = services + ['nginx']
     if self.app.pargs.php:
         Log.debug(self, "php5-fpm service status")
         services = services + ['php5-fpm']
     if self.app.pargs.mysql:
         if EEVariables.ee_mysql_host is "localhost":
             Log.debug(self, "mysql service status")
             services = services + ['mysql']
         else:
             Log.warn(self, "Remote MySQL found, "
                      "unable to get MySQL service status")
     if self.app.pargs.postfix:
         services = services + ['postfix']
         Log.debug(self, "postfix service status")
     if self.app.pargs.memcache:
         Log.debug(self, "memcached service status")
         services = services + ['memcached']
     if self.app.pargs.dovecot:
         Log.debug(self, "dovecot service status")
         services = services + ['dovecot']
     if not services and EEVariables.ee_mysql_host is "localhost":
         services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
         Log.debug(self, "nginx,php5-fpm,mysql,postfix services status")
     elif not services:
         services = services + ['nginx', 'php5-fpm', 'postfix']
         Log.debug(self, "nginx,php5-fpm,postfix services status")
     for service in services:
         if EEService.get_service_status(self, service):
             Log.info(self, "{0:10}:  {1}".format(service, "Running"))
Exemplo n.º 15
0
    def install(self, packages):
        all_packages = ' '.join(packages)
        try:
            with open('/var/log/ee/ee.log', 'a') as f:
                proc = subprocess.Popen("DEBIAN_FRONTEND=noninteractive "
                                        "apt-get install -o "
                                        "Dpkg::Options::=\"--force-confdef\""
                                        " -o "
                                        "Dpkg::Options::=\"--force-confold\""
                                        " -y {0}"
                                        .format(all_packages), shell=True,
                                        stdin=None, stdout=f, stderr=f,
                                        executable="/bin/bash")
                proc.wait()

            if proc.returncode == 0:
                return True
            else:
                Log.info(self, Log.FAIL + "Oops Something went "
                         "wrong!!")
                Log.error(self, "Check logs for reason "
                          "`tail /var/log/ee/ee.log` & Try Again!!!")

        except Exception as e:
            Log.info(self, Log.FAIL + "Oops Something went "
                     "wrong!!")
            Log.error(self, "Check logs for reason "
                      "`tail /var/log/ee/ee.log` & Try Again!!!")
Exemplo n.º 16
0
 def download(self, packages):
     """Download packages, packges must be list in format of
     [url, path, package name]"""
     for package in packages:
         url = package[0]
         filename = package[1]
         pkg_name = package[2]
         try:
             directory = os.path.dirname(filename)
             if not os.path.exists(directory):
                 os.makedirs(directory)
             Log.info(self, "Downloading {0:20}".format(pkg_name), end=' ')
             req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
             with urllib.request.urlopen(req) as response, open(filename, 'wb') as out_file:
                 out_file.write(response.read())
             Log.info(self, "{0}".format("[" + Log.ENDC + "Done"
                                         + Log.OKBLUE + "]"))
         except urllib.error.URLError as e:
             Log.debug(self, "[{err}]".format(err=str(e.reason)))
             Log.error(self, "Unable to download file, {0}"
                       .format(filename))
             return False
         except urllib.error.HTTPError as e:
             Log.error(self, "Package download failed. {0}"
                       .format(pkg_name))
             Log.debug(self, "[{err}]".format(err=str(e.reason)))
             return False
         except urllib.error.ContentTooShortError as e:
             Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
             Log.error(self, "Package download failed. The amount of the"
                       " downloaded data is less than "
                       "the expected amount \{0} ".format(pkg_name))
             return False
Exemplo n.º 17
0
def sitebackup(self, data):
    ee_site_webroot = data['webroot']
    backup_path = ee_site_webroot + '/backup/{0}'.format(EEVariables.ee_date)
    if not EEFileUtils.isexist(self, backup_path):
        EEFileUtils.mkdir(self, backup_path)
    Log.info(self, "Backup location : {0}".format(backup_path))
    EEFileUtils.copyfile(self, '/etc/nginx/sites-available/{0}'
                         .format(data['site_name']), backup_path)

    if data['currsitetype'] in ['html', 'php', 'mysql']:
        Log.info(self, "Backing up Webroot \t\t", end='')
        EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path)
        Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")

    configfiles = glob.glob(ee_site_webroot + '/*-config.php')

    if configfiles and EEFileUtils.isexist(self, configfiles[0]):
        ee_db_name = (EEFileUtils.grep(self, configfiles[0],
                      '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")
        Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
        # move wp-config.php/ee-config.php to backup
        if data['currsitetype'] in ['mysql']:
            EEFileUtils.mvfile(self, configfiles[0], backup_path)
        else:
            EEFileUtils.copyfile(self, configfiles[0], backup_path)
Exemplo n.º 18
0
 def download(self, packages):
     """Download packages, packges must be list in format of
     [url, path, package name]"""
     for package in packages:
         url = package[0]
         filename = package[1]
         pkg_name = package[2]
         try:
             directory = os.path.dirname(filename)
             if not os.path.exists(directory):
                 os.makedirs(directory)
             Log.info(self, "Downloading {0:20}".format(pkg_name), end=' ')
             urllib.request.urlretrieve(url, filename)
             Log.info(
                 self,
                 "{0}".format("[" + Log.ENDC + "Done" + Log.OKBLUE + "]"))
         except urllib.error.URLError as e:
             Log.debug(self, "[{err}]".format(err=str(e.reason)))
             Log.error(self,
                       "Unable to download file, {0}".format(filename))
             return False
         except urllib.error.HTTPError as e:
             Log.error(self,
                       "Package download failed. {0}".format(pkg_name))
             Log.debug(self, "[{err}]".format(err=str(e.reason)))
             return False
         except urllib.error.ContentTooShortError as e:
             Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
             Log.error(
                 self, "Package download failed. The amount of the"
                 " downloaded data is less than "
                 "the expected amount \{0} ".format(pkg_name))
             return False
Exemplo n.º 19
0
    def dist_upgrade(self):
        """
        Similar to `apt-get upgrade`
        """
        try:
            with open('/var/log/ee/ee.log', 'a') as f:
                proc = subprocess.Popen("DEBIAN_FRONTEND=noninteractive "
                                        "apt-get dist-upgrade -o "
                                        "Dpkg::Options::=\"--force-confdef\""
                                        " -o "
                                        "Dpkg::Options::=\"--force-confold\""
                                        " -y ",
                                        shell=True, stdin=None,
                                        stdout=f, stderr=f,
                                        executable="/bin/bash")
                proc.wait()

            if proc.returncode == 0:
                return True
            else:
                Log.info(self, Log.FAIL + "Oops Something went "
                         "wrong!!")
                Log.error(self, "Check logs for reason "
                          "`tail /var/log/ee/ee.log` & Try Again!!!")
        except Exception as e:
            Log.error(self, "Error while installing packages, "
                      "apt-get exited with error")
Exemplo n.º 20
0
def updatewpuserpassword(self, ee_domain, ee_site_webroot):

    ee_wp_user = ""
    ee_wp_pass = ""
    EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot))

    # Check if ee_domain is wordpress install
    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:
        Log.error(self, "{0} does not seem to be a WordPress site".format(ee_domain))

    try:
        ee_wp_user = input("Provide WordPress user name [admin]: ")
    except Exception as e:
        Log.debug(self, "{0}".format(e))
        Log.error(self, "\nCould not update password")

    if ee_wp_user == "?":
        Log.info(self, "Fetching WordPress user 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 = "******"

    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:
            ee_wp_pass = getpass.getpass(prompt="Provide password for " "{0} user: "******"Provide password for " "{0} user: "******"{0}".format(e))
            raise SiteError("failed to read password input ")

        try:
            EEShellExec.cmd_exec(
                self, "wp --allow-root user update {0}" "  --user_pass={1}".format(ee_wp_user, ee_wp_pass)
            )
        except CommandExecutionError as e:
            raise SiteError("wp user password update command failed")
        Log.info(self, "Password updated successfully")

    else:
        Log.error(self, "Invalid WordPress user {0} for {1}.".format(ee_wp_user, ee_domain))
Exemplo n.º 21
0
def updatewpuserpassword(self, ee_domain, ee_site_webroot):

    ee_wp_user = ''
    ee_wp_pass = ''
    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))

    # Exit if ee_domain is not wordpress install
    if not is_wp:
        Log.error(self,
                  "{0} does not seem to be a WordPress site".format(ee_domain))

    try:
        ee_wp_user = input("Provide WordPress user name [admin]: ")
    except Exception as e:
        Log.debug(self, "{0}".format(e))
        Log.error(self, "\nCould not update password")

    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")

    if not ee_wp_user:
        ee_wp_user = '******'

    is_user_exist = EEShellExec.cmd_exec(
        self, "wp --allow-root user list "
        "--fields=user_login | grep {0}$ ".format(ee_wp_user))

    if is_user_exist:
        try:
            ee_wp_pass = getpass.getpass(prompt="Provide password for "
                                         "{0} user: "******"{0}".format(e))
            Log.error(self, "Could not update password")

        if len(ee_wp_pass) > 8:
            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")
    else:
        Log.error(
            self, "Invalid WordPress user {0} for {1}.".format(
                ee_wp_user, ee_domain))
Exemplo n.º 22
0
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 ''))
    Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
Exemplo n.º 23
0
 def clean_pagespeed(self):
     """This function clears Pagespeed cache"""
     if(os.path.isdir("/var/ngx_pagespeed_cache")):
         Log.info(self, "Cleaning PageSpeed cache")
         EEShellExec.cmd_exec(self, "rm -rf /var/ngx_pagespeed_cache/*")
     else:
         Log.debug(self, "/var/ngx_pagespeed_cache does not exist," 
                         " so cache not cleared")
         Log.error(self, "Unable to clean pagespeed cache", False)
Exemplo n.º 24
0
 def clean_opcache(self):
     """This function clears opcache"""
     try:
         Log.info(self, "Cleaning opcache")
         wp = urllib.request.urlopen(" https://127.0.0.1:22222/cache"
                                     "/opcache/opgui.php?page=reset").read()
     except Exception as e:
             Log.debug(self, "{0}".format(e))
             Log.error(self, "Unable to clean OpCache")
Exemplo n.º 25
0
def updatewpuserpassword(self, ee_domain, ee_site_webroot):

    ee_wp_user = ''
    ee_wp_pass = ''
    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))

    # Exit if ee_domain is not wordpress install
    if not is_wp:
        Log.error(self, "{0} does not seem to be a WordPress site"
                  .format(ee_domain))

    try:
        ee_wp_user = input("Provide WordPress user name [admin]: ")
    except Exception as e:
        Log.debug(self, "{0}".format(e))
        Log.error(self, "\nCould not update password")

    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")

    if not ee_wp_user:
        ee_wp_user = '******'

    is_user_exist = EEShellExec.cmd_exec(self, "wp --allow-root user list "
                                         "--fields=user_login | grep {0}$ "
                                         .format(ee_wp_user))

    if is_user_exist:
        try:
            ee_wp_pass = getpass.getpass(prompt="Provide password for "
                                         "{0} user: "******"{0}".format(e))
            Log.error(self, "Could not update password")

        if len(ee_wp_pass) > 8:
            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")
    else:
        Log.error(self, "Invalid WordPress user {0} for {1}."
                  .format(ee_wp_user, ee_domain))
Exemplo n.º 26
0
    def sync(self):
        """
        1. reads database information from wp/ee-config.php
        2. updates records into ee database accordingly.
        """
        Log.info(self, "Synchronizing ee database, please wait...")
        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(
                                          '\'', ''))

                        # Check if database really exist
                        try:
                            if not EEMysql.check_db_exists(self, ee_db_name):
                                # Mark it as deleted if not exist
                                ee_db_name = 'deleted'
                                ee_db_user = '******'
                                ee_db_pass = '******'
                        except StatementExcecutionError as e:
                            Log.debug(self, str(e))
                        except Exception as e:
                            Log.debug(self, str(e))

                        if site.db_name != ee_db_name:
                            # update records if any mismatch found
                            Log.debug(
                                self, "Updating ee db record for {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)
Exemplo n.º 27
0
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 ''))
    Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
Exemplo n.º 28
0
 def callback(filename, lines):
     for line in lines:
         if line.find(":::") == -1:
             print(line)
         else:
             data = line.split(":::")
             try:
                 print(data[0], data[1], zlib.decompress(base64.decodestring(data[2])))
             except Exception as e:
                 Log.info(time.time(), "caught exception rendering a new log line in %s" % filename)
Exemplo n.º 29
0
 def clean_pagespeed(self):
     """This function clears Pagespeed cache"""
     if (os.path.isdir("/var/ngx_pagespeed_cache")):
         Log.info(self, "Cleaning PageSpeed cache")
         EEShellExec.cmd_exec(self, "rm -rf /var/ngx_pagespeed_cache/*")
     else:
         Log.debug(
             self, "/var/ngx_pagespeed_cache does not exist,"
             " so cache not cleared")
         Log.error(self, "Unable to clean pagespeed cache", False)
Exemplo n.º 30
0
def pre_run_checks(self):

    # Check nginx configuration
    Log.info(self, "Running pre-update checks, please wait...")
    try:
        Log.debug(self, "checking NGINX configuration ...")
        FNULL = open("/dev/null", "w")
        ret = subprocess.check_call(["nginx", "-t"], stdout=FNULL, stderr=subprocess.STDOUT)
    except CalledProcessError as e:
        Log.debug(self, "{0}".format(str(e)))
        raise SiteError("nginx configuration check failed.")
Exemplo n.º 31
0
 def clean_memcache(self):
     """This function Clears memcache """
     try:
         if(EEAptGet.is_installed(self, "memcached")):
             EEService.restart_service(self, "memcached")
             Log.info(self, "Cleaning MemCache")
         else:
             Log.info(self, "Memcache not installed")
     except Exception as e:
         Log.debug(self, "{0}".format(e))
         Log.error(self, "Unable to restart Memcached", False)
Exemplo n.º 32
0
 def install(self, packages):
     global apt_get
     apt_get = apt_get.bake("-y")
     try:
         for line in apt_get.install("-o",
                                     "Dpkg::Options::=--force-confold",
                                     *packages, _iter=True):
             Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ')
     except ErrorReturnCode as e:
         Log.debug(self, "{0}".format(e))
         Log.error(self, "Unable to run apt-get install")
Exemplo n.º 33
0
 def clean_memcache(self):
     """This function Clears memcache """
     try:
         if (EEAptGet.is_installed(self, "memcached")):
             EEService.restart_service(self, "memcached")
             Log.info(self, "Cleaning MemCache")
         else:
             Log.info(self, "Memcache not installed")
     except Exception as e:
         Log.debug(self, "{0}".format(e))
         Log.error(self, "Unable to restart Memcached", False)
Exemplo n.º 34
0
    def import_slow_log(self):
        """Default function for import slow log"""
        if os.path.isdir("{0}60089/htdocs/db/anemometer".format(
                EEVariables.ee_webroot)):
            if os.path.isfile("/var/log/mysql/mysql-slow.log"):
                # Get Anemometer user name and password
                Log.info(self, "Importing MySQL slow log to Anemometer")
                host = os.popen("grep -e \"\'host\'\" {0}60089/htdocs/".format(
                    EEVariables.ee_webroot) +
                                "db/anemometer/conf/config.inc.php  "
                                "| head -1 | cut -d\\\' -f4 | "
                                "tr -d '\n'").read()
                user = os.popen("grep -e \"\'user\'\" {0}60089/htdocs/".format(
                    EEVariables.ee_webroot) +
                                "db/anemometer/conf/config.inc.php  "
                                "| head -1 | cut -d\\\' -f4 | "
                                "tr -d '\n'").read()
                password = os.popen("grep -e \"\'password\'\" {0}60089/".
                                    format(EEVariables.ee_webroot) +
                                    "htdocs/www/db/anemometer/conf"
                                    "/config.inc.php "
                                    "| head -1 | cut -d\\\' -f4 | "
                                    "tr -d '\n'").read()

                # Import slow log Anemometer using pt-query-digest
                try:
                    EEShellExec.cmd_exec(
                        self, "pt-query-digest --user={0} "
                        "--password={1} "
                        "--review D=slow_query_log,"
                        "t=global_query_review "
                        "--history D=slow_query_log,t="
                        "global_query_review_history "
                        "--no-report --limit=0% "
                        "--filter=\" \\$event->{{Bytes}} = "
                        "length(\\$event->{{arg}}) "
                        "and \\$event->{{hostname}}=\\\""
                        "{2}\\\"\" "
                        "/var/log/mysql/mysql-slow.log".format(
                            user, password, host))
                except CommandExecutionError as e:
                    Log.debug(self, str(e))
                    Log.error(self, "MySQL slow log import failed.")
            else:
                Log.error(
                    self, "MySQL slow log file not found,"
                    " so not imported slow logs")
        else:
            Log.error(
                self, "Anemometer is not installed." + Log.ENDC +
                "\nYou can install Anemometer with "
                "this command " + Log.BOLD + "\n `ee stack install --utils`" +
                Log.ENDC)
Exemplo n.º 35
0
 def update(self):
     """
     Similar to `apt-get upgrade`
     """
     global apt_get
     apt_get = apt_get.bake("-y")
     try:
         for line in apt_get.update(_iter=True):
             Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ')
     except ErrorReturnCode as e:
         Log.debug(self, "{0}".format(e))
         Log.error(self, "Unable to run apt-get update")
Exemplo n.º 36
0
 def add(self):
     """Swap addition with EasyEngine"""
     if EEVariables.ee_ram < 512:
         if EEVariables.ee_swap < 1000:
             Log.info(self, "Adding SWAP")
             EEShellExec.cmd_exec(self, "dd if=/dev/zero of=/ee-swapfile " "bs=1024 count=1048k")
             EEShellExec.cmd_exec(self, "mkswap /ee-swapfile")
             EEFileUtils.chown(self, "/ee-swapfile", "root", "root")
             EEFileUtils.chmod(self, "/ee-swapfile", 0o600)
             EEShellExec.cmd_exec(self, "swapon /ee-swapfile")
             with open("/etc/fstab", encoding="utf-8", mode="a") as swap_file:
                 swap_file.write("/ee-swapfile\tnone\tswap\tsw\t0 0")
Exemplo n.º 37
0
def pre_run_checks(self):

    # Check nginx configuration
    Log.info(self, "Running pre-update checks, please wait...")
    try:
        Log.debug(self, "checking NGINX configuration ...")
        FNULL = open('/dev/null', 'w')
        ret = subprocess.check_call(["nginx", "-t"], stdout=FNULL,
                                    stderr=subprocess.STDOUT)
    except CalledProcessError as e:
        Log.debug(self, "{0}".format(str(e)))
        raise SiteError("nginx configuration check failed.")
Exemplo n.º 38
0
 def callback(filename, lines):
     for line in lines:
         if line.find(':::') == -1:
             print(line)
         else:
             data = line.split(':::')
             try:
                 print(data[0], data[1],
                       zlib.decompress(base64.decodestring(data[2])))
             except Exception as e:
                 Log.info(time.time(),
                          'caught exception rendering a new log line in %s'
                          % filename)
Exemplo n.º 39
0
 def remove(self, packages, auto=False, purge=False):
     global apt_get
     apt_get = apt_get.bake("-y")
     try:
         if purge:
             for line in apt_get.purge(*packages, _iter=True):
                 Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ')
         else:
             for line in apt_get.remove(*packages, _iter=True):
                 Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ')
     except ErrorReturnCode as e:
         Log.debug(self, "{0}".format(e))
         Log.error(self, "Unable to remove packages")
Exemplo n.º 40
0
    def import_slow_log(self):
        """Default function for import slow log"""
        if os.path.isdir("{0}22222/htdocs/db/anemometer"
                         .format(EEVariables.ee_webroot)):
            if os.path.isfile("/var/log/mysql/mysql-slow.log"):
                # Get Anemometer user name and password
                Log.info(self, "Importing MySQL slow log to Anemometer")
                host = os.popen("grep -e \"\'host\'\" {0}22222/htdocs/"
                                .format(EEVariables.ee_webroot)
                                + "db/anemometer/conf/config.inc.php  "
                                "| head -1 | cut -d\\\' -f4 | "
                                "tr -d '\n'").read()
                user = os.popen("grep -e \"\'user\'\" {0}22222/htdocs/"
                                .format(EEVariables.ee_webroot)
                                + "db/anemometer/conf/config.inc.php  "
                                "| head -1 | cut -d\\\' -f4 | "
                                "tr -d '\n'").read()
                password = os.popen("grep -e \"\'password\'\" {0}22222/"
                                    .format(EEVariables.ee_webroot)
                                    + "htdocs/db/anemometer/conf"
                                    "/config.inc.php "
                                    "| head -1 | cut -d\\\' -f4 | "
                                    "tr -d '\n'").read()

                # Import slow log Anemometer using pt-query-digest
                try:
                    EEShellExec.cmd_exec(self, "pt-query-digest --user={0} "
                                         "--password={1} "
                                         "--review D=slow_query_log,"
                                         "t=global_query_review "
                                         "--history D=slow_query_log,t="
                                         "global_query_review_history "
                                         "--no-report --limit=0% "
                                         "--filter=\" \\$event->{{Bytes}} = "
                                         "length(\\$event->{{arg}}) "
                                         "and \\$event->{{hostname}}=\\\""
                                         "{2}\\\"\" "
                                         "/var/log/mysql/mysql-slow.log"
                                         .format(user, password, host))
                except CommandExecutionError as e:
                    Log.debug(self, str(e))
                    Log.error(self, "MySQL slow log import failed.")
            else:
                Log.error(self, "MySQL slow log file not found,"
                          " so not imported slow logs")
        else:
            Log.error(self, "Anemometer is not installed." +
                      Log.ENDC + "\nYou can install Anemometer with "
                      "this command "
                      + Log.BOLD + "\n `ee stack install --utils`"
                      + Log.ENDC)
Exemplo n.º 41
0
    def debug_mysql(self):
        """Start/Stop MySQL debug"""
        # MySQL start global debug
        if (self.app.pargs.mysql == 'on' and not self.app.pargs.site_name):
            if not EEShellExec.cmd_exec(self, "mysql -e \"show variables like"
                                              " \'slow_query_log\';\" | "
                                              "grep ON"):
                Log.info(self, "Setting up MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = "
                                      "\'ON\';")
                EEMysql.execute(self, "set global slow_query_log_file = "
                                      "\'/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 2;")
                EEMysql.execute(self, "set global log_queries_not_using"
                                      "_indexes = \'ON\';")
            else:
                Log.info(self, "MySQL slow log is already enabled")

            self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']

        # MySQL stop global debug
        elif (self.app.pargs.mysql == 'off' and not self.app.pargs.site_name):
            if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'"
                                    "slow_query_log\';\" | grep ON"):
                Log.info(self, "Disabling MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = \'OFF\';")
                EEMysql.execute(self, "set global slow_query_log_file = \'"
                                "/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 10;")
                EEMysql.execute(self, "set global log_queries_not_using_index"
                                "es = \'OFF\';")
                EEShellExec.cmd_exec(self, "crontab -l | sed \'/#EasyEngine "
                                     "start/,/#EasyEngine end/d\' | crontab -")
            else:
                Log.info(self, "MySQL slow log already disabled")
Exemplo n.º 42
0
 def clean_opcache(self):
     """This function clears opcache"""
     try:
         Log.info(self, "Cleaning opcache")
         wp = urllib.request.urlopen(" https://127.0.0.1:22222/cache"
                                     "/opcache/opgui.php?page=reset").read()
     except Exception as e:
             Log.debug(self, "{0}".format(e))
             Log.debug(self, "Unable hit url, "
                       " https://127.0.0.1:22222/cache/opcache/opgui.php?page=reset,"
                       " please check you have admin tools installed")
             Log.debug(self, "please check you have admin tools installed,"
                      " or install them with `ee stack install --admin`")
             Log.error(self, "Unable to clean opcache", False)
Exemplo n.º 43
0
 def default(self):
     filename = "eeupdate" + time.strftime("%Y%m%d-%H%M%S")
     EEDownload.download(self, [["http://rt.cx/eeup",
                                 "/tmp/{0}".format(filename),
                                 "update script"]])
     try:
         Log.info(self, "updating EasyEngine, please wait ...")
         os.system("bash /tmp/{0}".format(filename))
     except OSError as e:
         Log.debug(self, str(e))
         Log.error(self, "EasyEngine update failed !")
     except Exception as e:
         Log.debug(self, str(e))
         Log.error(self, "EasyEngine update failed !")
Exemplo n.º 44
0
 def add(self):
     """Swap addition with EasyEngine"""
     if EEVariables.ee_ram < 512:
         if EEVariables.ee_swap < 1000:
             Log.info(self, "Adding SWAP")
             EEShellExec.cmd_exec(self, "dd if=/dev/zero of=/ee-swapfile "
                                  "bs=1024 count=1048k")
             EEShellExec.cmd_exec(self, "mkswap /ee-swapfile")
             EEFileUtils.chown(self, "/ee-swapfile", "root", "root")
             EEFileUtils.chmod(self, "/ee-swapfile", 0o600)
             EEShellExec.cmd_exec(self, "swapon /ee-swapfile")
             with open("/etc/fstab",
                       encoding='utf-8', mode='a') as swap_file:
                 swap_file.write("/ee-swapfile\tnone\tswap\tsw\t0 0")
Exemplo n.º 45
0
 def default(self):
     filename = "eeupdate" + time.strftime("%Y%m%d-%H%M%S")
     EEDownload.download(self, [["http://rt.cx/eeup",
                                 "/tmp/{0}".format(filename),
                                 "update script"]])
     try:
         Log.info(self, "updating EasyEngine, please wait...")
         os.system("bash /tmp/{0}".format(filename))
     except OSError as e:
         Log.debug(self, str(e))
         Log.error(self, "EasyEngine update failed !")
     except Exception as e:
         Log.debug(self, str(e))
         Log.error(self, "EasyEngine update failed !")
Exemplo n.º 46
0
    def debug_mysql(self):
        """Start/Stop MySQL debug"""
        # MySQL start global debug
        if (self.app.pargs.mysql == 'on' and not self.app.pargs.site_name):
            if not EEShellExec.cmd_exec(self, "mysql -e \"show variables like"
                                              " \'slow_query_log\';\" | "
                                              "grep ON"):
                Log.info(self, "Setting up MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = "
                                      "\'ON\';")
                EEMysql.execute(self, "set global slow_query_log_file = "
                                      "\'/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 2;")
                EEMysql.execute(self, "set global log_queries_not_using"
                                      "_indexes = \'ON\';")
            else:
                Log.info(self, "MySQL slow log is already enabled")

            self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']

        # MySQL stop global debug
        elif (self.app.pargs.mysql == 'off' and not self.app.pargs.site_name):
            if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'"
                                    "slow_query_log\';\" | grep ON"):
                Log.info(self, "Disabling MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = \'OFF\';")
                EEMysql.execute(self, "set global slow_query_log_file = \'"
                                "/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 10;")
                EEMysql.execute(self, "set global log_queries_not_using_index"
                                "es = \'OFF\';")
                EEShellExec.cmd_exec(self, "crontab -l | sed \'/#EasyEngine "
                                     "start/,/#EasyEngine end/d\' | crontab -")
            else:
                Log.info(self, "MySQL slow log already disabled")
Exemplo n.º 47
0
    def sync(self):
        """
        1. reads database information from wp/ee-config.php
        2. updates records into ee database accordingly.
        """
        Log.info(self, "Synchronizing ee database, please wait...")
        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('\'', ''))

                        # Check if database really exist
                        try:
                            if not EEMysql.check_db_exists(self, ee_db_name):
                                # Mark it as deleted if not exist
                                ee_db_name = 'deleted'
                                ee_db_user = '******'
                                ee_db_pass = '******'
                        except StatementExcecutionError as e:
                            Log.debug(self, str(e))
                        except Exception as e:
                            Log.debug(self, str(e))

                        if site.db_name != ee_db_name:
                            # update records if any mismatch found
                            Log.debug(self, "Updating ee db record for {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)
Exemplo n.º 48
0
def installwp_plugin(self, plugin_name, data):
    ee_site_webroot = data['webroot']
    Log.info(self, "Installing plugin {0}".format(plugin_name))
    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root install "
                         "{0}".format(plugin_name),
                         errormsg="Unable to Install plugin {0}"
                         .format(plugin_name))

    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))
Exemplo n.º 49
0
    def debug_wp(self):
        """Start/Stop WordPress debug"""
        if self.start and self.app.pargs.site_name:
            wp_config = "{0}/{1}/wp-config.php".format(EEVariables.ee_webroot, self.app.pargs.site_name)
            webroot = "{0}{1}".format(EEVariables.ee_webroot, self.app.pargs.site_name)
            if os.path.isfile(wp_config):
                if not EEShellExec.cmd_exec(self, "grep \"'WP_DEBUG'\" {0} |" " grep true".format(wp_config)):
                    Log.info(self, "Starting WordPress debug")
                    open("{0}/htdocs/wp-content/debug.log".format(webroot), encoding="utf-8", mode="a").close()
                    EEShellExec.cmd_exec(
                        self,
                        "chown {1}: {0}/htdocs/wp-" "content/debug.log" "".format(webroot, EEVariables.ee_php_user),
                    )
                    EEShellExec.cmd_exec(
                        self,
                        "sed -i \"s/define('WP_DEBUG'"
                        ".*/define('WP_DEBUG', true);\\n"
                        "define('WP_DEBUG_DISPLAY', false);"
                        "\\ndefine('WP_DEBUG_LOG', true);"
                        "\\ndefine('SAVEQUERIES', true);/\""
                        " {0}".format(wp_config),
                    )
                    EEShellExec.cmd_exec(
                        self,
                        "cd {0}/htdocs/ && wp"
                        " plugin --allow-root install "
                        "developer query-monitor".format(webroot),
                    )
                    EEShellExec.cmd_exec(
                        self, "chown -R {1}: {0}/htdocs/" "wp-content/plugins".format(webroot, EEVariables.ee_php_user)
                    )

                self.msg = self.msg + [
                    "{0}{1}/htdocs/wp-content" "/debug.log".format(EEVariables.ee_webroot, self.app.pargs.site_name)
                ]

            else:
                Log.info(self, "{0} domain not valid".format(self.app.pargs.site_name))

        elif not self.start and self.app.pargs.site_name:
            wp_config = "{0}{1}/wp-config.php".format(EEVariables.ee_webroot, self.app.pargs.site_name)
            webroot = "{0}{1}".format(EEVariables.ee_webroot, self.app.pargs.site_name)
            if os.path.isfile(wp_config):
                if EEShellExec.cmd_exec(self, "grep \"'WP_DEBUG'\" {0} | " "grep true".format(wp_config)):
                    Log.info(self, "Disabling WordPress debug")
                    EEShellExec.cmd_exec(
                        self,
                        "sed -i \"s/define('WP_DEBUG'" ", true);/define('WP_DEBUG', " 'false);/" {0}'.format(wp_config),
                    )
                    EEShellExec.cmd_exec(
                        self, "sed -i \"/define('" "WP_DEBUG_DISPLAY', false);/d\" {0}".format(wp_config)
                    )
                    EEShellExec.cmd_exec(self, "sed -i \"/define('" "WP_DEBUG_LOG', true);/d\" {0}".format(wp_config))
                    EEShellExec.cmd_exec(self, "sed -i \"/define('" "SAVEQUERIES', " 'true);/d" {0}'.format(wp_config))
                else:
                    Log.info(self, "WordPress debug all already disabled")
        else:
            Log.error(self, "Missing argument site name")
Exemplo n.º 50
0
def installwp_plugin(self, plugin_name, data):
    ee_site_webroot = data['webroot']
    Log.info(self, "Installing plugin {0}".format(plugin_name))
    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    EEShellExec.cmd_exec(
        self,
        "php /usr/bin/wp plugin --allow-root install "
        "{0}".format(plugin_name),
        errormsg="Unable to Install plugin {0}".format(plugin_name))

    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))
Exemplo n.º 51
0
    def update(self):
        """
        Similar to `apt-get update`
        """
        try:
            with open('/var/log/ee/ee.log', 'a') as f:
                proc = subprocess.Popen('apt-get update',
                                        shell=True,
                                        stdin=None,
                                        stdout=f,
                                        stderr=subprocess.PIPE,
                                        executable="/bin/bash")
                proc.wait()
                output, error_output = proc.communicate()

                # Check what is error in error_output
                if "NO_PUBKEY" in str(error_output):
                    # Split the output
                    Log.info(self, "Fixing missing GPG keys, please wait...")
                    error_list = str(error_output).split("\\n")

                    # Use a loop to add misising keys
                    for single_error in error_list:
                        if "NO_PUBKEY" in single_error:
                            key = single_error.rsplit(None, 1)[-1]
                            EERepo.add_key(self,
                                           key,
                                           keyserver="hkp://pgp.mit.edu")

                    proc = subprocess.Popen('apt-get update',
                                            shell=True,
                                            stdin=None,
                                            stdout=f,
                                            stderr=f,
                                            executable="/bin/bash")
                    proc.wait()

                if proc.returncode == 0:
                    return True
                else:
                    Log.info(self, Log.FAIL + "Oops Something went wrong!!")
                    Log.error(
                        self, "Check logs for reason "
                        "`tail /var/log/ee/ee.log` & Try Again!!!")

        except Exception as e:
            Log.error(self, "apt-get update exited with error")
Exemplo n.º 52
0
    def upgrade_php56(self):
        if EEVariables.ee_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(EEVariables.ee_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not (os.path.isfile(EEVariables.ee_repo_file_path)
                    and EEFileUtils.grep(self, EEVariables.ee_repo_file_path,
                                         "php55")):
                Log.error(self, "Unable to find PHP 5.5")

        Log.info(
            self, "During PHP update process non nginx-cached"
            " parts of your site may remain down.")

        # Check prompt
        if (not self.app.pargs.no_prompt):
            start_upgrade = input("Do you want to continue:[y/N]")
            if start_upgrade != "Y" and start_upgrade != "y":
                Log.error(self, "Not starting PHP package update")

        if EEVariables.ee_platform_distro == "ubuntu":
            EERepo.remove(self, ppa="ppa:ondrej/php5")
            EERepo.add(self, ppa=EEVariables.ee_php_repo)
        else:
            EEAptGet.remove(self, ["php5-xdebug"])
            EEFileUtils.searchreplace(self, EEVariables.ee_repo_file_path,
                                      "php55", "php56")

        Log.info(self, "Updating apt-cache, please wait...")
        EEAptGet.update(self)
        Log.info(self, "Installing packages, please wait ...")
        if (EEVariables.ee_platform_codename == 'trusty'
                or EEVariables.ee_platform_codename == 'xenial'
                or EEVariables.ee_platform_codename == 'bionic'):
            EEAptGet.install(self,
                             EEVariables.ee_php5_6 + EEVariables.ee_php_extra)
        else:
            EEAptGet.install(self, EEVariables.ee_php)

        if EEVariables.ee_platform_distro == "debian":
            EEShellExec.cmd_exec(self, "pecl install xdebug")

            with open("/etc/php5/mods-available/xdebug.ini",
                      encoding='utf-8',
                      mode='a') as myfile:
                myfile.write(";zend_extension=/usr/lib/php5/20131226/"
                             "xdebug.so\n")

            EEFileUtils.create_symlink(self, [
                "/etc/php5/mods-available/"
                "xdebug.ini", "/etc/php5/fpm/conf.d"
                "/20-xedbug.ini"
            ])

        Log.info(self, "Successfully upgraded from PHP 5.5 to PHP 5.6")
Exemplo n.º 53
0
 def clean_opcache(self):
     """This function clears opcache"""
     try:
         Log.info(self, "Cleaning opcache")
         wp = urllib.request.urlopen(
             " https://127.0.0.1:22222/cache"
             "/opcache/opgui.php?page=reset").read()
     except Exception as e:
         Log.debug(self, "{0}".format(e))
         Log.debug(
             self, "Unable hit url, "
             " https://127.0.0.1:22222/cache/opcache/opgui.php?page=reset,"
             " please check you have admin tools installed")
         Log.debug(
             self, "please check you have admin tools installed,"
             " or install them with `ee stack install --admin`")
         Log.error(self, "Unable to clean opcache", False)
Exemplo n.º 54
0
def uninstallwp_plugin(self, plugin_name, data):
    ee_site_webroot = data["webroot"]
    Log.debug(self, "Uninstalling plugin {0}, please wait...".format(plugin_name))
    EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot))
    Log.info(self, "Uninstalling plugin {0}, please wait...".format(plugin_name))
    try:
        EEShellExec.cmd_exec(
            self,
            "php {0} plugin ".format(EEVariables.ee_wpcli_path) + "--allow-root deactivate " "{0}".format(plugin_name),
        )

        EEShellExec.cmd_exec(
            self,
            "php {0} plugin ".format(EEVariables.ee_wpcli_path) + "--allow-root uninstall " "{0}".format(plugin_name),
        )
    except CommandExecutionError as e:
        raise SiteError("plugin uninstall failed")
Exemplo n.º 55
0
    def check_upgrade(self):
        """
        Similar to `apt-get upgrade`
        """
        try:
            check_update = subprocess.Popen(['apt-get upgrade -s | grep '
                                            '\"^Inst\" | wc -l'],
                                            stdout=subprocess.PIPE,
                                            shell=True).communicate()[0]
            if check_update == b'0\n':
                Log.error(self, "No package updates available")
            Log.info(self, "Following package updates are available:")
            subprocess.Popen("apt-get -s dist-upgrade | grep \"^Inst\"",
                             shell=True, executable="/bin/bash",
                             stdout=sys.stdout).communicate()

        except Exception as e:
            Log.error(self, "Unable to check for packages upgrades")
Exemplo n.º 56
0
def uninstallwp_plugin(self, plugin_name, data):
    ee_site_webroot = data['webroot']
    Log.debug(self, "Uninstalling plugin {0}, please wait..."
              .format(plugin_name))
    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    Log.info(self, "Uninstalling plugin {0}, please wait..."
             .format(plugin_name))
    try:
        EEShellExec.cmd_exec(self, "php {0} plugin "
                             .format(EEVariables.ee_wpcli_path)
                             + "--allow-root deactivate "
                             "{0}".format(plugin_name))

        EEShellExec.cmd_exec(self, "php {0} plugin "
                             .format(EEVariables.ee_wpcli_path)
                             + "--allow-root uninstall "
                             "{0}".format(plugin_name))
    except CommandExecutionError as e:
        raise SiteError("plugin uninstall failed")