Exemple #1
0
    def upgrade_php56(self):
        if WOVariables.wo_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(WOVariables.wo_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not(os.path.isfile(WOVariables.wo_repo_file_path) and
                   WOFileUtils.grep(self, WOVariables.wo_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 WOVariables.wo_platform_distro == "ubuntu":
            WORepo.remove(self, ppa="ppa:ondrej/php5")
            WORepo.add(self, ppa=WOVariables.wo_php_repo)

        Log.info(self, "Updating apt-cache, please wait...")
        WOAptGet.update(self)
        Log.info(self, "Installing packages, please wait ...")
        if (WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic'):
            WOAptGet.install(self, WOVariables.wo_php + WOVariables.wo_php_extra)
        else:
            WOAptGet.install(self, WOVariables.wo_php)

        if WOVariables.wo_platform_distro == "debian":
            WOShellExec.cmd_exec(self, "pecl install xdebug")
Exemple #2
0
    def deploycert(self, wo_domain_name):
        """Deploy Let's Encrypt certificates with acme.sh"""
        if not os.path.isfile('/etc/letsencrypt/renewal/{0}_ecc/fullchain.cer'.
                              format(wo_domain_name)):
            Log.error(self, 'Certificate not found. Deployment canceled')

        Log.debug(self,
                  "Cert deployment for domain: {0}".format(wo_domain_name))

        try:
            Log.wait(self, "Deploying SSL cert")
            if WOShellExec.cmd_exec(
                    self,
                    "mkdir -p {0}/{1} && {2} --install-cert -d {1} --ecc "
                    "--cert-file {0}/{1}/cert.pem --key-file {0}/{1}/key.pem "
                    "--fullchain-file {0}/{1}/fullchain.pem "
                    "--ca-file {0}/{1}/ca.pem --reloadcmd \"nginx -t && "
                    "service nginx restart\" ".format(WOVar.wo_ssl_live,
                                                      wo_domain_name,
                                                      WOAcme.wo_acme_exec)):
                Log.valide(self, "Deploying SSL cert")
            else:
                Log.failed(self, "Deploying SSL cert")
                Log.error(self, "Unable to deploy certificate")

            if os.path.isdir('/var/www/{0}/conf/nginx'.format(wo_domain_name)):

                sslconf = open(
                    "/var/www/{0}/conf/nginx/ssl.conf".format(wo_domain_name),
                    encoding='utf-8',
                    mode='w')
                sslconf.write("listen 443 ssl http2;\n"
                              "listen [::]:443 ssl http2;\n"
                              "ssl_certificate     {0}/{1}/fullchain.pem;\n"
                              "ssl_certificate_key     {0}/{1}/key.pem;\n"
                              "ssl_trusted_certificate {0}/{1}/ca.pem;\n"
                              "ssl_stapling_verify on;\n".format(
                                  WOVar.wo_ssl_live, wo_domain_name))
                sslconf.close()

            if not WOFileUtils.grep(self, '/var/www/22222/conf/nginx/ssl.conf',
                                    '/etc/letsencrypt'):
                Log.info(self, "Securing WordOps backend with current cert")
                sslconf = open("/var/www/22222/conf/nginx/ssl.conf",
                               encoding='utf-8',
                               mode='w')
                sslconf.write("ssl_certificate     {0}/{1}/fullchain.pem;\n"
                              "ssl_certificate_key     {0}/{1}/key.pem;\n"
                              "ssl_trusted_certificate {0}/{1}/ca.pem;\n"
                              "ssl_stapling_verify on;\n".format(
                                  WOVar.wo_ssl_live, wo_domain_name))
                sslconf.close()

            WOGit.add(self, ["/etc/letsencrypt"],
                      msg="Adding letsencrypt folder")

        except IOError as e:
            Log.debug(self, str(e))
            Log.debug(self, "Error occured while generating " "ssl.conf")
        return 0
Exemple #3
0
def hashbucket(self):
    # Check Nginx Hashbucket error
    sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE, shell=True)
    output, error_output = sub.communicate()
    if 'server_names_hash_bucket_size' not in str(error_output):
        return True

    count = 0
    # Get the list of sites-availble
    sites_list = os.listdir("/etc/nginx/sites-enabled/")

    # Count the number of characters in site names
    for site in sites_list:
        count = sum([count, len(site)])

    # Calculate Nginx hash bucket size
    ngx_calc = math.trunc(sum([math.log(count, 2), 2]))
    ngx_hash = math.trunc(math.pow(2, ngx_calc))

    # Replace hashbucket in Nginx.conf file
    if WOFileUtils.grep(self, "/etc/nginx/nginx.conf",
                        "server_names_hash_bucket_size"):
        for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1):
            if "server_names_hash_bucket_size" in line:
                print("\tserver_names_hash_bucket_size {0};".format(ngx_hash))
            else:
                print(line, end='')

    else:
        WOFileUtils.searchreplace(self, '/etc/nginx/nginx.conf',
                                  "gzip_disable \"msie6\";",
                                  "gzip_disable \"msie6\";\n"
                                  "\tserver_names_hash_bucket_size {0};\n"
                                  .format(ngx_hash))
Exemple #4
0
    def upgrade_php56(self):
        if WOVariables.wo_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(WOVariables.wo_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not(os.path.isfile(WOVariables.wo_repo_file_path) and
                   WOFileUtils.grep(self, WOVariables.wo_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 WOVariables.wo_platform_distro == "ubuntu":
            WORepo.remove(self, ppa="ppa:ondrej/php5")
            WORepo.add(self, ppa=WOVariables.wo_php_repo)
        else:
            WOAptGet.remove(self, ["php5-xdebug"])
            WOFileUtils.searchreplace(self, WOVariables.wo_repo_file_path,
                                      "php55", "php56")

        Log.info(self, "Updating apt-cache, please wait...")
        WOAptGet.update(self)
        Log.info(self, "Installing packages, please wait ...")
        if (WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic'):
            WOAptGet.install(self, WOVariables.wo_php5_6 + WOVariables.wo_php_extra)
        else:
            WOAptGet.install(self, WOVariables.wo_php)

        if WOVariables.wo_platform_distro == "debian":
            WOShellExec.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")

            WOFileUtils.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")
Exemple #5
0
    def sync(self):
        """
        1. reads database information from wp/wo-config.php
        2. updates records into wo database accordingly.
        """
        Log.info(self, "Synchronizing wo database, please wait...")
        sites = getAllsites(self)
        if not sites:
            pass
        for site in sites:
            if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
                wo_site_webroot = site.site_path
                # Read config files
                configfiles = glob.glob(wo_site_webroot + '/*-config.php')

                # search for wp-config.php inside htdocs/
                if not configfiles:
                    Log.debug(
                        self, "Config files not found in {0}/ ".format(
                            wo_site_webroot))
                    if site.site_type != 'mysql':
                        Log.debug(
                            self,
                            "Searching wp-config.php in {0}/htdocs/".format(
                                wo_site_webroot))
                        configfiles = glob.glob(wo_site_webroot +
                                                '/htdocs/wp-config.php')

                if configfiles:
                    if WOFileUtils.isexist(self, configfiles[0]):
                        wo_db_name = (WOFileUtils.grep(self, configfiles[0],
                                                       'DB_NAME').split(',')
                                      [1].split(')')[0].strip().replace(
                                          '\'', ''))
                        wo_db_user = (WOFileUtils.grep(self, configfiles[0],
                                                       'DB_USER').split(',')
                                      [1].split(')')[0].strip().replace(
                                          '\'', ''))
                        wo_db_pass = (WOFileUtils.grep(
                            self, configfiles[0],
                            'DB_PASSWORD').split(',')[1].split(')')
                                      [0].strip().replace('\'', ''))
                        wo_db_host = (WOFileUtils.grep(self, configfiles[0],
                                                       'DB_HOST').split(',')
                                      [1].split(')')[0].strip().replace(
                                          '\'', ''))

                        # Check if database really exist
                        try:
                            if not WOMysql.check_db_exists(self, wo_db_name):
                                # Mark it as deleted if not exist
                                wo_db_name = 'deleted'
                                wo_db_user = '******'
                                wo_db_pass = '******'
                        except StatementExcecutionError as e:
                            Log.debug(self, str(e))
                        except Exception as e:
                            Log.debug(self, str(e))

                        if site.db_name != wo_db_name:
                            # update records if any mismatch found
                            Log.debug(
                                self, "Updating wo db record for {0}".format(
                                    site.sitename))
                            updateSiteInfo(self,
                                           site.sitename,
                                           db_name=wo_db_name,
                                           db_user=wo_db_user,
                                           db_password=wo_db_pass,
                                           db_host=wo_db_host)
                else:
                    Log.debug(
                        self, "Config files not found for {0} ".format(
                            site.sitename))