Exemple #1
0
    def backupAll(self, fulldump=False):
        import subprocess
        try:
            Log.info(self, "Backing up database at location: "
                     "/var/lib/wo-backup/mysql")
            # Setup Nginx common directory
            if not os.path.exists('/var/lib/wo-backup/mysql'):
                Log.debug(self, 'Creating directory'
                          '/var/lib/wo-backup/mysql')
                os.makedirs('/var/lib/wo-backup/mysql')
            if not fulldump:
                db = subprocess.check_output(
                    ["/usr/bin/mysql "
                     "-Bse \'show databases\'"],
                    universal_newlines=True,
                    shell=True).split('\n')
                for dbs in db:
                    if dbs == "":
                        continue
                    Log.info(self, "Backing up {0} database".format(dbs))
                    p1 = subprocess.Popen(
                        "/usr/bin/mysqldump {0} --max_allowed_packet=1024M "
                        "--single-transaction --hex-blob".format(dbs),
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE, shell=True)
                    p2 = subprocess.Popen(
                        "/usr/bin/zstd -c > "
                        "/var/lib/wo-backup/mysql/{0}{1}.sql.zst"
                        .format(dbs, WOVar.wo_date),
                        stdin=p1.stdout, shell=True)
                    # Allow p1 to receive a SIGPIPE if p2 exits
                    p1.stdout.close()
                    output = p1.stderr.read()
                    p1.wait()
                    if p1.returncode == 0:
                        Log.debug(self, "done")
                    else:
                        Log.error(self, output.decode("utf-8"))
            else:
                Log.info(self, "Backing up all databases")
                p1 = subprocess.Popen(
                    "/usr/bin/mysqldump --all-databases "
                    "--max_allowed_packet=1024M --hex-blob "
                    "--single-transaction --events",
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE, shell=True)
                p2 = subprocess.Popen(
                    "/usr/bin/zstd -c > "
                    "/var/lib/wo-backup/mysql/fulldump-{0}.sql.zst"
                    .format(WOVar.wo_date),
                    stdin=p1.stdout, shell=True)
                p1.stdout.close()
                output = p1.stderr.read()
                p1.wait()
                if p1.returncode == 0:
                    Log.debug(self, "done")
                else:
                    Log.error(self, output.decode("utf-8"))

        except Exception as e:
            Log.error(self, "Error: process exited with status %s"
                            % e)
Exemple #2
0
    def debug_php73(self):
        """Start/Stop PHP debug"""
        # PHP global debug start

        if (self.app.pargs.php73 == 'on' and not self.app.pargs.site_name):
            if (WOVariables.wo_platform_codename == 'wheezy'
                    or WOVariables.wo_platform_codename == 'precise'):
                Log.error(self, "PHP 7.3 not supported.")
            if not (WOShellExec.cmd_exec(
                    self, "sed -n \"/upstream php73"
                    "{/,/}/p \" /etc/nginx/"
                    "conf.d/upstream.conf "
                    "| grep 9173")):

                Log.info(self, "Enabling PHP 7.3 debug")

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([(
                    'upstream',
                    'php73',
                ), 'server'], '127.0.0.1:9173')
                if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"):
                    nc.set([(
                        'upstream',
                        'hhvm',
                    ), 'server'], '127.0.0.1:9173')
                nc.savef('/etc/nginx/conf.d/upstream.conf')

                # Enable xdebug
                WOFileUtils.searchreplace(
                    self, "/etc/php/7.3/mods-available/"
                    "xdebug.ini", ";zend_extension", "zend_extension")

                # Fix slow log is not enabled default in PHP5.6
                config = configparser.ConfigParser()
                config.read('/etc/php/7.3/fpm/pool.d/debug.conf')
                config['debug']['slowlog'] = '/var/log/php/7.3/slow.log'
                config['debug']['request_slowlog_timeout'] = '10s'
                with open('/etc/php/7.3/fpm/pool.d/debug.conf',
                          encoding='utf-8',
                          mode='w') as confifile:
                    Log.debug(
                        self, "Writting debug.conf configuration into "
                        "/etc/php/7.3/fpm/pool.d/debug.conf")
                    config.write(confifile)

                self.trigger_php = True
                self.trigger_nginx = True
            else:
                Log.info(self, "PHP debug is already enabled")

            self.msg = self.msg + ['/var/log/php/7.3/slow.log']

        # PHP global debug stop
        elif (self.app.pargs.php73 == 'off' and not self.app.pargs.site_name):
            if WOShellExec.cmd_exec(
                    self, " sed -n \"/upstream php72 {/,/}/p\" "
                    "/etc/nginx/conf.d/upstream.conf "
                    "| grep 9172"):
                Log.info(self, "Disabling PHP 7.2 debug")

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([(
                    'upstream',
                    'php72',
                ), 'server'], 'unix:/var/run/php/php72-fpm.sock')
                if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"):
                    nc.set([(
                        'upstream',
                        'hhvm',
                    ), 'server'], '127.0.0.1:8000')
                nc.savef('/etc/nginx/conf.d/upstream.conf')

                # Disable xdebug
                WOFileUtils.searchreplace(
                    self, "/etc/php/7.2/mods-available/"
                    "xdebug.ini", "zend_extension", ";zend_extension")

                self.trigger_php = True
                self.trigger_nginx = True
            else:
                Log.info(self, "PHP 7.2 debug is already disabled")
Exemple #3
0
    def default(self, disp_msg=False):
        # All package update
        apt_packages = []
        packages = []
        self.msg = []
        pargs = self.app.pargs

        if ((not pargs.web) and (not pargs.nginx) and
            (not pargs.php) and (not pargs.php73) and
            (not pargs.mysql) and (not pargs.ngxblocker) and
            (not pargs.all) and (not pargs.wpcli) and
            (not pargs.netdata) and (not pargs.composer) and
            (not pargs.phpmyadmin) and (not pargs.dashboard) and
                (not pargs.redis)):
            pargs.web = True
            pargs.admin = True

        if pargs.all:
            pargs.web = True
            pargs.admin = True
            pargs.redis = True
            pargs.php73 = True
            pargs.ngxblocker = True

        if pargs.web:
            pargs.nginx = True
            pargs.php = True
            pargs.mysql = True
            pargs.wpcli = True

        if pargs.admin:
            pargs.netdata = True
            pargs.composer = True
            pargs.dashboard = True
            pargs.phpmyadmin = True
            pargs.wpcli = True

        # nginx
        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVar.wo_nginx
            else:
                if os.path.isfile('/usr/sbin/nginx'):
                    Log.info(self, "Updating Nginx templates")
                    post_pref(self, WOVar.wo_nginx, [])
                else:
                    Log.info(self, "Nginx Stable is not already installed")

        # php 7.2
        if pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                apt_packages = apt_packages + WOVar.wo_php + \
                    WOVar.wo_php_extra
            else:
                Log.info(self, "PHP 7.2 is not installed")

        # php 7.3
        if pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                apt_packages = apt_packages + WOVar.wo_php73 + \
                    WOVar.wo_php_extra
            else:
                Log.info(self, "PHP 7.3 is not installed")

        # mysql
        if pargs.mysql:
            if WOShellExec.cmd_exec(self, 'mysqladmin ping'):
                apt_packages = apt_packages + ['mariadb-server']
            else:
                Log.info(self, "MariaDB is not installed")

        # redis
        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                apt_packages = apt_packages + ['redis-server']
            else:
                Log.info(self, "Redis is not installed")

        # wp-cli
        if pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [[
                    "https://github.com/wp-cli/wp-cli/"
                    "releases/download/v{0}/"
                    "wp-cli-{0}.phar".format(WOVar.wo_wp_cli),
                    "/usr/local/bin/wp",
                    "WP-CLI"]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        # netdata
        if pargs.netdata:
            # detect static binaries install
            if os.path.isdir('/opt/netdata'):
                packages = packages + [[
                    'https://my-netdata.io/kickstart-static64.sh',
                    '/var/lib/wo/tmp/kickstart.sh', 'Netdata']]
            # detect install from source
            elif os.path.isdir('/etc/netdata'):
                packages = packages + [[
                    'https://my-netdata.io/kickstart.sh',
                    '/var/lib/wo/tmp/kickstart.sh', 'Netdata']]
            else:
                Log.info(self, 'Netdata us not installed')

        # wordops dashboard
        if pargs.dashboard:
            if (os.path.isfile('/var/www/22222/htdocs/index.php') or
                    os.path.isfile('/var/www/22222/htdocs/index.html')):
                packages = packages + [[
                    "https://github.com/WordOps/wordops-dashboard/"
                    "releases/download/v{0}/wordops-dashboard.tar.gz"
                    .format(WOVar.wo_dashboard),
                    "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                    "WordOps Dashboard"]]
            else:
                Log.info(self, 'WordOps dashboard is not installed')

        # phpmyadmin
        if pargs.phpmyadmin:
            if os.path.isdir('/var/www/22222/htdocs/db/pma'):
                packages = packages + [[
                    "https://files.phpmyadmin.net"
                    "/phpMyAdmin/{0}/phpMyAdmin-{0}-"
                    "all-languages.tar.gz"
                    .format(WOVar.wo_phpmyadmin),
                    "/var/lib/wo/tmp/pma.tar.gz",
                    "PHPMyAdmin"]]
            else:
                Log.info(self, "phpMyAdmin isn't installed")

        # composer
        if pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + [[
                    "https://getcomposer.org/installer",
                    "/var/lib/wo/tmp/composer-install",
                    "Composer"]]
            else:
                Log.info(self, "Composer isn't installed")

        # ngxblocker
        if pargs.ngxblocker:
            if os.path.exists('/usr/local/sbin/install-ngxblocker'):
                packages = packages + [[
                    'https://raw.githubusercontent.com/mitchellkrogza/'
                    'nginx-ultimate-bad-bot-blocker/master/update-ngxblocker',
                    '/usr/local/sbin/update-ngxblocker',
                    'ngxblocker'
                ]]
            else:
                Log.info(self, "ngxblocker is not installed")

        if ((not (apt_packages)) and (not(packages))):
            self.app.args.print_help()
        else:
            pre_stack(self)
            if (apt_packages):
                if (("php7.2-fpm" not in apt_packages) and
                        ("php7.3-fpm" not in apt_packages) and
                        ("nginx-custom" not in apt_packages) and
                        ("mariadb-server" not in apt_packages)):
                    pass
                else:
                    Log.info(
                        self, "Your sites may be down for few seconds if "
                        "you are upgrading Nginx, PHP-FPM, MariaDB or Redis")
                # Check prompt
                if ((not pargs.no_prompt) and (not pargs.force)):
                    start_upgrade = input("Do you want to continue:[y/N]")
                    if start_upgrade != "Y" and start_upgrade != "y":
                        Log.error(self, "Not starting package update")
                Log.wait(self, "Updating APT packages")
                # apt-get update
                WOAptGet.update(self)
                Log.valide(self, "Updating APT packages")

                # additional pre_pref
                if "nginx-custom" in apt_packages:
                    pre_pref(self, WOVar.wo_nginx)
                if "php7.2-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.2-fpm'],
                                    auto=False, purge=True)
                if "php7.3-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.3-fpm'],
                                    auto=False, purge=True)
                # check if nginx upgrade is blocked
                if os.path.isfile(
                        '/etc/apt/preferences.d/nginx-block'):
                    post_pref(self, WOVar.wo_nginx, [], True)
                # upgrade packages
                WOAptGet.install(self, apt_packages)
                Log.wait(self, "Configuring APT Packages")
                post_pref(self, apt_packages, [], True)
                if "mariadb-server" in apt_packages:
                    WOShellExec.cmd_exec(self, 'mysql_upgrade')
                Log.valide(self, "Configuring APT Packages")
                # Post Actions after package updates

            if (packages):
                if pargs.wpcli:
                    WOFileUtils.rm(self, '/usr/local/bin/wp')

                if pargs.netdata:
                    WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh')

                if pargs.ngxblocker:
                    WOFileUtils.rm(self, '/usr/local/sbin/update-ngxblocker')

                if pargs.dashboard:
                    if os.path.isfile('/var/www/22222/htdocs/index.php'):
                        WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php')
                    if os.path.isfile('/var/www/22222/htdocs/index.html'):
                        WOFileUtils.rm(
                            self, '/var/www/22222/htdocs/index.html')

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if pargs.wpcli:
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

                if pargs.ngxblocker:
                    WOFileUtils.chmod(
                        self, '/usr/local/sbin/update-ngxblocker', 0o700)
                    WOShellExec.cmd_exec(
                        self, '/usr/local/sbin/update-ngxblocker -nq'
                    )

                # Netdata
                if pargs.netdata:
                    Log.wait(self, "Upgrading Netdata")
                    # detect static binaries install
                    if os.path.isdir('/opt/netdata'):
                        if os.path.exists(
                            '/opt/netdata/usr/libexec/'
                                'netdata/netdata-updater.sh'):
                            WOShellExec.cmd_exec(
                                self, "bash /opt/netdata/usr/"
                                "libexec/netdata/netdata-"
                                "updater.sh")
                        else:
                            WOShellExec.cmd_exec(
                                self, "bash /var/lib/wo/tmp/kickstart.sh")
                    # detect install from source
                    elif os.path.isdir('/etc/netdata'):
                        if os.path.exists(
                                '/usr/libexec/netdata/netdata-updater.sh'):
                            WOShellExec.cmd_exec(
                                self,
                                'bash /usr/libexec/netdata/netdata-updater.sh')
                        else:
                            WOShellExec.cmd_exec(
                                self, "bash /var/lib/wo/tmp/kickstart.sh")
                    Log.valide(self, "Upgrading Netdata")

                if pargs.dashboard:
                    post_pref(
                        self, [], [["https://github.com/WordOps"
                                    "/wordops-dashboard/"
                                    "releases/download/v{0}/"
                                    "wordops-dashboard.tar.gz"
                                    .format(WOVar.wo_dashboard),
                                    "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                                    "WordOps Dashboard"]])

                if pargs.composer:
                    Log.wait(self, "Upgrading Composer")
                    if WOShellExec.cmd_exec(
                            self, '/usr/bin/php -v'):
                        WOShellExec.cmd_exec(
                            self, "php -q /var/lib/wo"
                            "/tmp/composer-install "
                            "--install-dir=/var/lib/wo/tmp/")
                    shutil.copyfile('/var/lib/wo/tmp/composer.phar',
                                    '/usr/local/bin/composer')
                    WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)
                    Log.valide(self, "Upgrading Composer    ")

                if pargs.phpmyadmin:
                    Log.wait(self, "Upgrading phpMyAdmin")
                    WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz',
                                      '/var/lib/wo/tmp/')
                    shutil.copyfile(('{0}22222/htdocs/db/pma'
                                     '/config.inc.php'
                                     .format(WOVar.wo_webroot)),
                                    ('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                     '-all-languages/config.inc.php'
                                     .format(WOVar.wo_phpmyadmin))
                                    )
                    WOFileUtils.rm(self, '{0}22222/htdocs/db/pma'
                                   .format(WOVar.wo_webroot))
                    shutil.move('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                '-all-languages/'
                                .format(WOVar.wo_phpmyadmin),
                                '{0}22222/htdocs/db/pma/'
                                .format(WOVar.wo_webroot))
                    WOFileUtils.chown(self, "{0}22222/htdocs"
                                      .format(WOVar.wo_webroot),
                                      'www-data',
                                      'www-data', recursive=True)
                    Log.valide(self, "Upgrading phpMyAdmin")

            Log.info(self, "Successfully updated packages")
Exemple #4
0
    def default(self, disp_msg=False):
        # All package update
        apt_packages = []
        packages = []
        self.msg = []
        pargs = self.app.pargs
        wo_phpmyadmin = WODownload.pma_release(self)
        if not (pargs.web or pargs.nginx or pargs.php or
                pargs.php72 or pargs.php73 or pargs.php74 or pargs.mysql or
                pargs.ngxblocker or pargs.all or pargs.netdata or
                pargs.wpcli or pargs.composer or pargs.phpmyadmin or
                pargs.adminer or pargs.dashboard or pargs.mysqltuner or
                pargs.redis or pargs.fail2ban or pargs.security):
            pargs.web = True
            pargs.admin = True
            pargs.security = True

        if pargs.php:
            pargs.php72 = True

        if pargs.all:
            pargs.web = True
            pargs.admin = True
            pargs.security = True
            pargs.redis = True

        if pargs.web:
            pargs.nginx = True
            pargs.php72 = True
            pargs.php73 = True
            pargs.php74 = True
            pargs.mysql = True
            pargs.wpcli = True

        if pargs.admin:
            pargs.netdata = True
            pargs.composer = True
            pargs.dashboard = True
            pargs.phpmyadmin = True
            pargs.wpcli = True
            pargs.adminer = True
            pargs.mysqltuner = True

        if pargs.security:
            pargs.ngxblocker = True
            pargs.fail2ban = True

        # nginx
        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVar.wo_nginx
            else:
                if os.path.isfile('/usr/sbin/nginx'):
                    Log.info(self, "Updating Nginx templates")
                    post_pref(self, WOVar.wo_nginx, [])
                else:
                    Log.info(self, "Nginx Stable is not already installed")

        # php 7.2
        if pargs.php72:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                apt_packages = apt_packages + WOVar.wo_php72 + \
                    WOVar.wo_php_extra

        # php 7.3
        if pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                apt_packages = apt_packages + WOVar.wo_php73 + \
                    WOVar.wo_php_extra

        # php 7.4
        if pargs.php74:
            if WOAptGet.is_installed(self, 'php7.4-fpm'):
                apt_packages = apt_packages + WOVar.wo_php74 + \
                    WOVar.wo_php_extra

        # mysql
        if pargs.mysql:
            if WOShellExec.cmd_exec(self, 'mysqladmin ping'):
                apt_packages = apt_packages + ['mariadb-server']

        # redis
        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                apt_packages = apt_packages + ['redis-server']

        # fail2ban
        if pargs.fail2ban:
            if WOAptGet.is_installed(self, 'fail2ban'):
                apt_packages = apt_packages + ['fail2ban']

        # wp-cli
        if pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [[
                    "https://github.com/wp-cli/wp-cli/"
                    "releases/download/v{0}/"
                    "wp-cli-{0}.phar".format(WOVar.wo_wp_cli),
                    "/usr/local/bin/wp",
                    "WP-CLI"]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        # netdata
        if pargs.netdata:
            # detect static binaries install
            if os.path.isdir('/opt/netdata'):
                packages = packages + [[
                    'https://my-netdata.io/kickstart-static64.sh',
                    '/var/lib/wo/tmp/kickstart.sh', 'Netdata']]
            # detect install from source
            elif os.path.isdir('/etc/netdata'):
                packages = packages + [[
                    'https://my-netdata.io/kickstart.sh',
                    '/var/lib/wo/tmp/kickstart.sh', 'Netdata']]
            else:
                Log.info(self, 'Netdata is not installed')

        # wordops dashboard
        if pargs.dashboard:
            if (os.path.isfile('/var/www/22222/htdocs/index.php') or
                    os.path.isfile('/var/www/22222/htdocs/index.html')):
                packages = packages + [[
                    "https://github.com/WordOps/wordops-dashboard/"
                    "releases/download/v{0}/wordops-dashboard.tar.gz"
                    .format(WOVar.wo_dashboard),
                    "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                    "WordOps Dashboard"]]
            else:
                Log.info(self, 'WordOps dashboard is not installed')

        # phpmyadmin
        if pargs.phpmyadmin:
            if os.path.isdir('/var/www/22222/htdocs/db/pma'):
                packages = packages + [[
                    "https://files.phpmyadmin.net"
                    "/phpMyAdmin/{0}/phpMyAdmin-{0}-"
                    "all-languages.tar.gz"
                    .format(wo_phpmyadmin),
                    "/var/lib/wo/tmp/pma.tar.gz",
                    "PHPMyAdmin"]]
            else:
                Log.info(self, "phpMyAdmin isn't installed")

        # adminer
        if pargs.adminer:
            if os.path.isfile("{0}22222/htdocs/db/"
                              "adminer/index.php"
                              .format(WOVar.wo_webroot)):
                Log.debug(self, "Setting packages variable for Adminer ")
                packages = packages + [[
                    "https://www.adminer.org/latest.php",
                    "{0}22222/"
                    "htdocs/db/adminer/index.php"
                    .format(WOVar.wo_webroot),
                    "Adminer"],
                    ["https://raw.githubusercontent.com"
                     "/vrana/adminer/master/designs/"
                     "pepa-linha/adminer.css",
                     "{0}22222/"
                     "htdocs/db/adminer/adminer.css"
                     .format(WOVar.wo_webroot),
                     "Adminer theme"]]
            else:
                Log.debug(self, "Adminer isn't installed")
                Log.info(self, "Adminer isn't installed")

        # composer
        if pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + [[
                    "https://getcomposer.org/installer",
                    "/var/lib/wo/tmp/composer-install",
                    "Composer"]]
            else:
                Log.info(self, "Composer isn't installed")

        # mysqltuner
        if pargs.mysqltuner:
            if WOAptGet.is_exec(self, 'mysqltuner'):
                Log.debug(self, "Setting packages variable "
                          "for MySQLTuner ")
                packages = packages + [["https://raw."
                                        "githubusercontent.com/"
                                        "major/MySQLTuner-perl"
                                        "/master/mysqltuner.pl",
                                        "/usr/bin/mysqltuner",
                                        "MySQLTuner"]]

        # ngxblocker
        if pargs.ngxblocker:
            if os.path.exists('/usr/local/sbin/install-ngxblocker'):
                packages = packages + [[
                    'https://raw.githubusercontent.com/mitchellkrogza/'
                    'nginx-ultimate-bad-bot-blocker/master/update-ngxblocker',
                    '/usr/local/sbin/update-ngxblocker',
                    'ngxblocker'
                ]]

        if ((not (apt_packages)) and (not(packages))):
            self.app.args.print_help()
        else:
            pre_stack(self)
            if (apt_packages):
                if not ("php7.2-fpm" in apt_packages or
                        "php7.3-fpm" in apt_packages or
                        "php7.4-fpm" in apt_packages or
                        "redis-server" in apt_packages or
                        "nginx-custom" in apt_packages or
                        "mariadb-server" in apt_packages):
                    pass
                else:
                    Log.warn(
                        self, "Your sites may be down for few seconds if "
                        "you are upgrading Nginx, PHP-FPM, MariaDB or Redis")
                # Check prompt
                if not (pargs.no_prompt or pargs.force):
                    start_upgrade = input("Do you want to continue:[y/N]")
                    if start_upgrade != "Y" and start_upgrade != "y":
                        Log.error(self, "Not starting package update")
                Log.wait(self, "Updating APT cache")
                # apt-get update
                WOAptGet.update(self)
                Log.valide(self, "Updating APT cache")

                # additional pre_pref
                if "nginx-custom" in apt_packages:
                    pre_pref(self, WOVar.wo_nginx)
                if "php7.2-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.2-fpm'],
                                    auto=False, purge=True)
                if "php7.3-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.3-fpm'],
                                    auto=False, purge=True)
                if "php7.4-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.4-fpm'],
                                    auto=False, purge=True)
                # check if nginx upgrade is blocked
                if os.path.isfile(
                        '/etc/apt/preferences.d/nginx-block'):
                    post_pref(self, WOVar.wo_nginx, [], True)
                # upgrade packages
                WOAptGet.install(self, apt_packages)
                Log.wait(self, "Configuring APT Packages")
                post_pref(self, apt_packages, [], True)
                if "mariadb-server" in apt_packages:
                    WOShellExec.cmd_exec(self, 'mysql_upgrade')
                Log.valide(self, "Configuring APT Packages")
                # Post Actions after package updates

            if (packages):
                if WOAptGet.is_selected(self, 'WP-CLI', packages):
                    WOFileUtils.rm(self, '/usr/local/bin/wp')

                if WOAptGet.is_selected(self, 'Netdata', packages):
                    WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh')

                if WOAptGet.is_selected(self, 'ngxblocker', packages):
                    WOFileUtils.rm(self, '/usr/local/sbin/update-ngxblocker')

                if WOAptGet.is_selected(self, 'WordOps Dashboard', packages):
                    if os.path.isfile('/var/www/22222/htdocs/index.php'):
                        WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php')
                    if os.path.isfile('/var/www/22222/htdocs/index.html'):
                        WOFileUtils.rm(
                            self, '/var/www/22222/htdocs/index.html')

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if WOAptGet.is_selected(self, 'WP-CLI', packages):
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

                if WOAptGet.is_selected(self, 'ngxblocker', packages):
                    if os.path.exists('/etc/nginx/conf.d/variables-hash.conf'):
                        WOFileUtils.rm(
                            self, '/etc/nginx/conf.d/variables-hash.conf')
                    WOFileUtils.chmod(
                        self, '/usr/local/sbin/update-ngxblocker', 0o775)
                    WOShellExec.cmd_exec(
                        self, '/usr/local/sbin/update-ngxblocker -nq')

                if WOAptGet.is_selected(self, 'MySQLTuner', packages):
                    WOFileUtils.chmod(self, "/usr/bin/mysqltuner", 0o775)
                    if os.path.exists('/usr/local/bin/mysqltuner'):
                        WOFileUtils.rm(self, '/usr/local/bin/mysqltuner')

                # Netdata
                if WOAptGet.is_selected(self, 'Netdata', packages):
                    WOService.stop_service(self, 'netdata')
                    Log.wait(self, "Upgrading Netdata")
                    # detect static binaries install
                    WOShellExec.cmd_exec(
                        self,
                        "bash /var/lib/wo/tmp/kickstart.sh "
                        "--dont-wait --no-updates",
                        errormsg='', log=False)
                    Log.valide(self, "Upgrading Netdata")

                if WOAptGet.is_selected(self, 'WordOps Dashboard', packages):
                    post_pref(
                        self, [], [["https://github.com/WordOps"
                                    "/wordops-dashboard/"
                                    "releases/download/v{0}/"
                                    "wordops-dashboard.tar.gz"
                                    .format(WOVar.wo_dashboard),
                                    "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                                    "WordOps Dashboard"]])

                if WOAptGet.is_selected(self, 'Composer', packages):
                    Log.wait(self, "Upgrading Composer")
                    if WOShellExec.cmd_exec(
                            self, '/usr/bin/php -v'):
                        WOShellExec.cmd_exec(
                            self, "php -q /var/lib/wo"
                            "/tmp/composer-install "
                            "--install-dir=/var/lib/wo/tmp/")
                    shutil.copyfile('/var/lib/wo/tmp/composer.phar',
                                    '/usr/local/bin/composer')
                    WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)
                    Log.valide(self, "Upgrading Composer    ")

                if WOAptGet.is_selected(self, 'PHPMyAdmin', packages):
                    Log.wait(self, "Upgrading phpMyAdmin")
                    WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz',
                                      '/var/lib/wo/tmp/')
                    shutil.copyfile(('{0}22222/htdocs/db/pma'
                                     '/config.inc.php'
                                     .format(WOVar.wo_webroot)),
                                    ('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                     '-all-languages/config.inc.php'
                                     .format(wo_phpmyadmin))
                                    )
                    WOFileUtils.rm(self, '{0}22222/htdocs/db/pma'
                                   .format(WOVar.wo_webroot))
                    shutil.move('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                '-all-languages/'
                                .format(wo_phpmyadmin),
                                '{0}22222/htdocs/db/pma/'
                                .format(WOVar.wo_webroot))
                    WOFileUtils.chown(self, "{0}22222/htdocs"
                                      .format(WOVar.wo_webroot),
                                      'www-data',
                                      'www-data', recursive=True)
                    Log.valide(self, "Upgrading phpMyAdmin")
                if os.path.exists('{0}22222/htdocs'.format(WOVar.wo_webroot)):
                    WOFileUtils.chown(self, "{0}22222/htdocs"
                                      .format(WOVar.wo_webroot),
                                      'www-data',
                                      'www-data', recursive=True)

            Log.info(self, "Successfully updated packages")
Exemple #5
0
    def migrate_mariadb(self):
        # Backup all database
        WOMysql.backupAll(self)

        # Add MariaDB repo
        Log.info(self, "Adding repository for MariaDB, please wait...")

        mysql_pref = ("Package: *\nPin: origin sfo1.mirrors.digitalocean.com"
                      "\nPin-Priority: 1000\n")
        with open('/etc/apt/preferences.d/'
                  'MariaDB.pref', 'w') as mysql_pref_file:
            mysql_pref_file.write(mysql_pref)

        WORepo.add(self, repo_url=WOVariables.wo_mysql_repo)
        Log.debug(self, 'Adding key for {0}'
                  .format(WOVariables.wo_mysql_repo))
        WORepo.add_key(self, '0xcbcb082a1bb943db',
                       keyserver="keyserver.ubuntu.com")

        config = configparser.ConfigParser()
        if os.path.exists('/etc/mysql/conf.d/my.cnf'):
            config.read('/etc/mysql/conf.d/my.cnf')
        else:
            config.read(os.path.expanduser("~")+'/.my.cnf')

        try:
            chars = config['client']['password']
        except Exception as e:
            Log.error(self, "Error: process exited with error %s"
                            % e)

        Log.debug(self, "Pre-seeding MariaDB")
        Log.debug(self, "echo \"mariadb-server-10.0 "
                        "mysql-server/root_password "
                        "password \" | "
                        "debconf-set-selections")
        WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
                                   "mysql-server/root_password "
                                   "password {chars}\" | "
                                   "debconf-set-selections"
                                   .format(chars=chars),
                                   log=False)
        Log.debug(self, "echo \"mariadb-server-10.0 "
                        "mysql-server/root_password_again "
                        "password \" | "
                        "debconf-set-selections")
        WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
                                   "mysql-server/root_password_again "
                                   "password {chars}\" | "
                                   "debconf-set-selections"
                                   .format(chars=chars),
                                   log=False)

        # Install MariaDB
        apt_packages = WOVariables.wo_mysql

        # If PHP is installed then install php7.2-mysql
        if WOAptGet.is_installed(self, "php7.2-fpm"):
            apt_packages = apt_packages + ["php7.2-mysql"]

        Log.info(self, "Updating apt-cache, hang on...")
        WOAptGet.update(self)
        Log.info(self, "Installing MariaDB, hang on...")
        WOAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        WOAptGet.auto_remove(self)
        WOAptGet.install(self, apt_packages)
Exemple #6
0
    def default(self):
        """Default function of debug"""
        # self.start = True
        self.interactive = False
        self.msg = []
        self.trigger_nginx = False
        self.trigger_php = False

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
                and (not self.app.pargs.php73) and (not self.app.pargs.fpm)
                and (not self.app.pargs.fpm73) and (not self.app.pargs.mysql)
                and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
                and (not self.app.pargs.all) and (not self.app.pargs.site_name)
                and (not self.app.pargs.import_slow_log)
                and (not self.app.pargs.interval)):
            if self.app.pargs.stop or self.app.pargs.start:
                print("--start/stop option is deprecated since ee v3.0.5")
                self.app.args.print_help()
            else:
                self.app.args.print_help()

        if self.app.pargs.import_slow_log:
            self.import_slow_log()

        if self.app.pargs.interval:
            try:
                cron_time = int(self.app.pargs.interval)
            except Exception as e:
                cron_time = 5

            try:
                if not WOShellExec.cmd_exec(
                        self, "crontab -l | grep "
                        "'wo debug --import-slow-log'"):
                    if not cron_time == 0:
                        Log.info(self, "setting up crontab entry,"
                                 " please wait...")
                        WOShellExec.cmd_exec(
                            self, "/bin/bash -c \"crontab -l "
                            "2> /dev/null | {{ cat; echo -e"
                            " \\\"#WordOps start MySQL "
                            "slow log \\n*/{0} * * * * "
                            "/usr/local/bin/wo debug"
                            " --import-slow-log\\n"
                            "#WordOps end MySQL slow log"
                            "\\\"; }} | crontab -\"".format(cron_time))
                else:
                    if not cron_time == 0:
                        Log.info(self, "updating crontab entry,"
                                 " please wait...")
                        if not WOShellExec.cmd_exec(
                                self, "/bin/bash -c "
                                "\"crontab "
                                "-l | sed '/WordOps "
                                "start MySQL slow "
                                "log/!b;n;c\*\/{0} "
                                "\* \* \* "
                                "\* \/usr"
                                "\/local\/bin\/wo debug "
                                "--import\-slow\-log' "
                                "| crontab -\"".format(cron_time)):
                            Log.error(self, "failed to update crontab entry")
                    else:
                        Log.info(self, "removing crontab entry,"
                                 " please wait...")
                        if not WOShellExec.cmd_exec(
                                self, "/bin/bash -c "
                                "\"crontab "
                                "-l | sed '/WordOps "
                                "start MySQL slow "
                                "log/,+2d'"
                                "| crontab -\"".format(cron_time)):
                            Log.error(self, "failed to remove crontab entry")
            except CommandExecutionError as e:
                Log.debug(self, str(e))

        if self.app.pargs.all == 'on':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'on'
            self.app.pargs.nginx = 'on'
            self.app.pargs.php = 'on'
            self.app.pargs.fpm = 'on'
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                self.app.pargs.php73 = 'on'
                self.app.pargs.fpm73 = 'on'
            self.app.pargs.mysql = 'on'
            self.app.pargs.rewrite = 'on'

        if self.app.pargs.all == 'off':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'off'
            self.app.pargs.nginx = 'off'
            self.app.pargs.php = 'off'
            self.app.pargs.fpm = 'off'
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                self.app.pargs.php73 = 'off'
                self.app.pargs.fpm73 = 'off'
            self.app.pargs.mysql = 'off'
            self.app.pargs.rewrite = 'off'

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
                and (not self.app.pargs.php73) and (not self.app.pargs.fpm)
                and (not self.app.pargs.fpm73) and (not self.app.pargs.mysql)
                and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
                and self.app.pargs.site_name):
            self.app.args.print_help()
            # self.app.pargs.nginx = 'on'
            # self.app.pargs.wp = 'on'
            # self.app.pargs.rewrite = 'on'

        if self.app.pargs.nginx:
            self.debug_nginx()
        if self.app.pargs.php:
            self.debug_php()
        if self.app.pargs.fpm:
            self.debug_fpm()
        if self.app.pargs.php73:
            self.debug_php73()
        if self.app.pargs.fpm73:
            self.debug_fpm73()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if WOVariables.wo_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(
                    self, "Remote MySQL found, WordOps does not support "
                    "debugging remote servers")
        if self.app.pargs.wp:
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.debug_rewrite()

        if self.app.pargs.interactive:
            self.interactive = True

        # Reload Nginx
        if self.trigger_nginx:
            WOService.reload_service(self, 'nginx')
        # Reload PHP
        if self.trigger_php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                WOService.restart_service(self, 'php7.2-fpm')
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                WOService.restart_service(self, 'php7.3-fpm')

        if len(self.msg) > 0:
            if not self.app.pargs.interactive:
                disp_msg = ' '.join(self.msg)
                Log.info(
                    self, "Use following command to check debug logs:\n" +
                    Log.ENDC + "tail -f {0}".format(disp_msg))
            else:
                signal.signal(signal.SIGINT, self.signal_handler)
                watch_list = []
                for w_list in self.msg:
                    watch_list = watch_list + glob.glob(w_list)

                logwatch(self, watch_list)
Exemple #7
0
    def default(self):
        # All package update
        apt_packages = []
        packages = []

        if ((not self.app.pargs.web) and (not self.app.pargs.nginx)
                and (not self.app.pargs.php) and (not self.app.pargs.mysql)
                and (not self.app.pargs.all) and (not self.app.pargs.wpcli)
                and (not self.app.pargs.redis)):
            self.app.pargs.web = True

        if self.app.pargs.all:
            self.app.pargs.web = True

        if self.app.pargs.web:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                self.app.pargs.nginx = True
            else:
                Log.info(self, "Nginx is not already installed")
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.wpcli = True

        if self.app.pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVariables.wo_nginx
            else:
                Log.info(self, "Nginx Stable is not already installed")

        if self.app.pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                if not WOAptGet.is_installed(self, 'php7.3-fpm'):
                    apt_packages = apt_packages + WOVariables.wo_php + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php
            else:
                Log.info(self, "PHP 7.2 is not installed")

        if self.app.pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                apt_packages = apt_packages + WOVariables.wo_mysql
            else:
                Log.info(self, "MariaDB is not installed")

        if self.app.pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                apt_packages = apt_packages + WOVariables.wo_redis
            else:
                Log.info(self, "Redis is not installed")

        if self.app.pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [[
                    "https://github.com/wp-cli/wp-cli/"
                    "releases/download/v{0}/"
                    "wp-cli-{0}.phar"
                    "".format(WOVariables.wo_wp_cli), "/usr/local/bin/wp",
                    "WP-CLI"
                ]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        if len(packages) or len(apt_packages):

            Log.info(
                self, "During package 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 package update")

            Log.info(self, "Updating packages, please wait...")
            if len(apt_packages):
                # apt-get update
                WOAptGet.update(self)
                # Update packages
                WOAptGet.install(self, apt_packages)

                # Post Actions after package updates
                if (set(WOVariables.wo_nginx).issubset(set(apt_packages))):
                    WOService.restart_service(self, 'nginx')
                if set(WOVariables.wo_php).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'php7.2-fpm')
                if set(WOVariables.wo_mysql).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'mysql')
                if set(WOVariables.wo_redis).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'redis-server')

            if len(packages):
                if self.app.pargs.wpcli:
                    WOFileUtils.remove(self, ['/usr/local/bin/wp'])

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if self.app.pargs.wpcli:
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

            Log.info(self, "Successfully updated packages")
        else:
            self.app.args.print_help()
Exemple #8
0
    def default(self):
        """Default function of log Mail"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp)
                and (not self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php/7.2/slow.log', 'a').close()
            open('/var/log/php7.2-fpm.log', 'a').close()
            self.msg = self.msg + [
                '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log'
            ]
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if WOVar.wo_mysql_host == "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(
                    self, "Remote MySQL found, WordOps does not support"
                    "remote MySQL servers or log files")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(WOVar.wo_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + [
                    "{0}/{1}/logs/access.log".format(WOVar.wo_webroot,
                                                     self.app.pargs.site_name)
                ]
            if self.app.pargs.nginx:
                self.msg = self.msg + [
                    "{0}/{1}/logs/error.log".format(WOVar.wo_webroot,
                                                    self.app.pargs.site_name)
                ]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile(
                            '{0}/logs/debug.log'.format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log".format(
                                webroot),
                                 encoding='utf-8',
                                 mode='a').close()
                            WOShellExec.cmd_exec(
                                self, "chown {1}: {0}/htdocs/"
                                "wp-content/debug.log"
                                "".format(webroot, WOVar.wo_php_user))
                    # create symbolic link for debug log
                    WOFileUtils.create_symlink(self, [
                        "{0}/htdocs/wp-content/"
                        "debug.log".format(webroot),
                        '{0}/logs/debug.log'.format(webroot)
                    ])

                    self.msg = self.msg + [
                        "{0}/{1}/logs/debug.log".format(
                            WOVar.wo_webroot, self.app.pargs.site_name)
                    ]
                else:
                    Log.info(
                        self, "Site is not WordPress site, skipping "
                        "WordPress logs")

        mail_list = []
        for m_list in self.msg:
            mail_list = mail_list + glob.glob(m_list)

        for tomail in self.app.pargs.to:
            Log.info(self, "Sending mail to {0}".format(tomail[0]))
            WOSendMail("wordops",
                       tomail[0],
                       "{0} Log Files".format(WOVar.wo_fqdn),
                       "Hi,\n  The requested logfiles are attached."
                       "\n\nBest regards,\nYour WordOps worker",
                       files=mail_list,
                       port=25,
                       isTls=False)
Exemple #9
0
    def remove(self):
        """Start removal of packages"""
        apt_packages = []
        packages = []
        pargs = self.app.pargs
        if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx)
                and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli)
                and (not pargs.phpmyadmin) and (not pargs.composer)
                and (not pargs.netdata) and (not pargs.dashboard)
                and (not pargs.fail2ban) and (not pargs.security)
                and (not pargs.mysqlclient) and (not pargs.mysqltuner) and
            (not pargs.adminer) and (not pargs.utils) and (not pargs.redis)
                and (not pargs.proftpd) and (not pargs.extplorer)
                and (not pargs.clamav) and (not pargs.ufw)
                and (not pargs.ngxblocker) and (not pargs.phpredisadmin)
                and (not pargs.sendmail) and (not pargs.php73)):
            pargs.web = True
            pargs.admin = True

        if pargs.all:
            pargs.web = True
            pargs.admin = True
            pargs.php73 = True
            pargs.fail2ban = True
            pargs.proftpd = True
            pargs.utils = True
            pargs.redis = True
            pargs.security = True
            packages = packages + ['/var/www/22222/htdocs']

        if pargs.web:
            pargs.nginx = True
            pargs.php = True
            pargs.mysql = True
            pargs.wpcli = True
            pargs.sendmail = True

        if pargs.admin:
            pargs.composer = True
            pargs.utils = True
            pargs.netdata = True
            pargs.mysqltuner = True

        if pargs.security:
            pargs.fail2ban = True
            pargs.clamav = True
            pargs.ufw = True
            pargs.ngxblocker = True

        # NGINX
        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                Log.debug(self, "Removing apt_packages variable of Nginx")
                apt_packages = apt_packages + WOVar.wo_nginx

        # PHP 7.2
        if pargs.php:
            Log.debug(self, "Removing apt_packages variable of PHP")
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                if not WOAptGet.is_installed(self, 'php7.3-fpm'):
                    apt_packages = apt_packages + WOVar.wo_php + \
                        WOVar.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVar.wo_php

        # PHP7.3
        if pargs.php73:
            Log.debug(self, "Removing apt_packages variable of PHP 7.3")
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
                    apt_packages = apt_packages + WOVar.wo_php73 + \
                        WOVar.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVar.wo_php73

        # REDIS
        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                Log.debug(self, "Remove apt_packages variable of Redis")
                apt_packages = apt_packages + ["redis-server"]

        # MariaDB
        if pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                Log.debug(self, "Removing apt_packages variable of MySQL")
                apt_packages = apt_packages + [
                    'mariadb-server', 'mysql-common', 'mariadb-client'
                ]

        # mysqlclient
        if pargs.mysqlclient:
            Log.debug(self, "Removing apt_packages variable "
                      "for MySQL Client")
            if WOShellExec.cmd_exec(self, "mysqladmin ping"):
                apt_packages = apt_packages + WOVar.wo_mysql_client

        # fail2ban
        if pargs.fail2ban:
            if WOAptGet.is_installed(self, 'fail2ban'):
                Log.debug(self, "Remove apt_packages variable of Fail2ban")
                apt_packages = apt_packages + WOVar.wo_fail2ban

        # ClamAV
        if pargs.clamav:
            Log.debug(self, "Setting apt_packages variable for ClamAV")
            if WOAptGet.is_installed(self, 'clamav'):
                apt_packages = apt_packages + WOVar.wo_clamav

        # sendmail
        if pargs.sendmail:
            Log.debug(self, "Setting apt_packages variable for Sendmail")
            if WOAptGet.is_installed(self, 'sendmail'):
                apt_packages = apt_packages + ["sendmail"]

        # proftpd
        if pargs.proftpd:
            if WOAptGet.is_installed(self, 'proftpd-basic'):
                Log.debug(self, "Remove apt_packages variable for ProFTPd")
                apt_packages = apt_packages + ["proftpd-basic"]

        # UFW
        if pargs.ufw:
            if WOAptGet.is_installed(self, 'ufw'):
                Log.debug(self, "Remove apt_packages variable for UFW")
                apt_packages = apt_packages + ["ufw"]

        # WPCLI
        if pargs.wpcli:
            Log.debug(self, "Removing package variable of WPCLI ")
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + ['/usr/local/bin/wp']

        # PHPMYADMIN
        if pargs.phpmyadmin:
            if os.path.isdir('{0}22222/htdocs/db/pma'.format(
                    WOVar.wo_webroot)):
                Log.debug(self, "Removing package of phpMyAdmin ")
                packages = packages + [
                    '{0}22222/htdocs/db/pma'.format(WOVar.wo_webroot)
                ]
        # Composer
        if pargs.composer:
            Log.debug(self, "Removing package of Composer ")
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + ['/usr/local/bin/composer']

        # MySQLTuner
        if pargs.mysqltuner:
            if os.path.isfile('/usr/bin/mysqltuner'):
                Log.debug(self, "Removing packages for MySQLTuner ")
                packages = packages + ['/usr/bin/mysqltuner']

        # PHPREDISADMIN
        if pargs.phpredisadmin:
            Log.debug(self, "Removing package variable of phpRedisAdmin ")
            if os.path.isdir('{0}22222/htdocs/cache/redis'.format(
                    WOVar.wo_webroot)):
                packages = packages + [
                    '{0}22222/htdocs/'
                    'cache/redis'.format(WOVar.wo_webroot)
                ]
        # ADMINER
        if pargs.adminer:
            if os.path.isdir('{0}22222/htdocs/db/adminer'.format(
                    WOVar.wo_webroot)):
                Log.debug(self, "Removing package variable of Adminer ")
                packages = packages + [
                    '{0}22222/htdocs/db/adminer'.format(WOVar.wo_webroot)
                ]
        if pargs.utils:
            Log.debug(self, "Removing package variable of utils ")
            packages = packages + [
                '{0}22222/htdocs/php/webgrind/'.format(
                    WOVar.wo_webroot), '{0}22222/htdocs/cache/opcache'.format(
                        WOVar.wo_webroot), '{0}22222/htdocs/cache/nginx/'
                'clean.php'.format(
                    WOVar.wo_webroot), '/usr/bin/pt-query-advisor',
                '{0}22222/htdocs/db/anemometer'.format(WOVar.wo_webroot)
            ]

        # netdata
        if pargs.netdata:
            Log.debug(self, "Removing Netdata")
            if os.path.isfile('/opt/netdata/usr/'
                              'libexec/netdata/netdata-uninstaller.sh'):
                packages = packages + ['/var/lib/wo/tmp/kickstart.sh']

        # wordops dashboard
        if pargs.dashboard:
            if (os.path.isfile('{0}22222/htdocs/index.php'.format(
                    WOVar.wo_webroot))
                    or os.path.isfile('{0}22222/htdocs/index.html'.format(
                        WOVar.wo_webroot))):
                Log.debug(self, "Removing Wo-Dashboard")
                packages = packages + [
                    '{0}22222/htdocs/assets'.format(WOVar.wo_webroot),
                    '{0}22222/htdocs/index.php'.format(WOVar.wo_webroot),
                    '{0}22222/htdocs/index.html'.format(WOVar.wo_webroot)
                ]
        # ngxblocker
        if pargs.ngxblocker:
            if os.path.isfile('/usr/local/sbin/setup-ngxblocker'):
                packages = packages + [
                    '/usr/local/sbin/setup-ngxblocker',
                    '/usr/local/sbin/install-ngxblocker',
                    '/usr/local/sbin/update-ngxblocker',
                    '/etc/nginx/conf.d/globalblacklist.conf',
                    '/etc/nginx/conf.d/botblocker-nginx-settings.conf',
                    '/etc/nginx/bots.d'
                ]

        if (packages) or (apt_packages):
            if (not pargs.force):
                start_remove = input('Are you sure you to want to'
                                     ' remove from server.'
                                     '\nPackage configuration will remain'
                                     ' on server after this operation.\n'
                                     'Remove stacks [y/N]?')
                if start_remove != "Y" and start_remove != "y":
                    Log.error(self, "Not starting stack removal")

            if 'nginx-custom' in apt_packages:
                WOService.stop_service(self, 'nginx')

            if 'mariadb-server' in apt_packages:
                WOMysql.backupAll(self)
                WOService.stop_service(self, 'mysql')

            # Netdata uninstaller
            if (set(['/var/lib/wo/tmp/'
                     'kickstart.sh']).issubset(set(packages))):
                if WOVar.wo_distro == 'Raspbian':
                    WOShellExec.cmd_exec(
                        self, "bash /usr/"
                        "libexec/netdata/"
                        "netdata-uninstaller.sh -y -f")
                else:
                    WOShellExec.cmd_exec(self, "bash /opt/netdata/usr/"
                                         "libexec/netdata/"
                                         "netdata-uninstaller.sh - y - f",
                                         errormsg='',
                                         log=False)

            if (packages):
                Log.wait(self, "Removing packages           ")
                WOFileUtils.remove(self, packages)
                Log.valide(self, "Removing packages           ")
            if (apt_packages):
                Log.debug(self, "Removing apt_packages")
                Log.wait(self, "Removing APT packages       ")
                WOAptGet.remove(self, apt_packages)
                WOAptGet.auto_remove(self)
                Log.valide(self, "Removing APT packages       ")

            Log.info(self, "Successfully removed packages")
Exemple #10
0
    def update(self):
        """
        Similar to `apt-get update`
        """
        try:
            with open('/var/log/wo/wordops.log', 'a') as f:
                proc = subprocess.Popen(
                    'DEBIAN_FRONTEND=noninteractive apt-get update -qq '
                    '--allow-releaseinfo-change',
                    shell=True,
                    stdin=None,
                    stdout=f,
                    stderr=subprocess.PIPE,
                    executable="/bin/bash")
                proc.wait()
                output, error_output = proc.communicate()

                if "--allow-releaseinfo-change" in str(error_output):
                    proc = subprocess.Popen(
                        'DEBIAN_FRONTEND=noninteractive apt-get update -qq',
                        shell=True,
                        stdin=None,
                        stdout=f,
                        stderr=f,
                        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]
                            WORepo.add_key(self,
                                           key,
                                           keyserver="hkp://pgp.mit.edu")

                    proc = subprocess.Popen(
                        'DEBIAN_FRONTEND=noninteractive apt-get update -qq',
                        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 + "Whoops, something went wrong...")
                    Log.error(
                        self, "Check the WordOps log for more details "
                        "`tail /var/log/wo/wordops.log` "
                        "and please try again...")

        except Exception:
            Log.error(self, "apt-get update exited with error")
Exemple #11
0
    def doupdatesite(self, pargs):
        pargs = self.app.pargs
        letsencrypt = False
        php73 = False
        php74 = False
        php72 = False

        data = dict()
        try:
            stype, cache = detSitePar(vars(pargs))
        except RuntimeError as e:
            Log.debug(self, str(e))
            Log.error(self, "Please provide valid options combination for"
                      " site update")

        if stype is None and pargs.proxy:
            stype, cache = 'proxy', ''
            proxyinfo = pargs.proxy[0].strip()
            if not proxyinfo:
                Log.error(self, "Please provide proxy server host information")
            proxyinfo = proxyinfo.split(':')
            host = proxyinfo[0].strip()
            port = '80' if len(proxyinfo) < 2 else proxyinfo[1].strip()
        elif stype is None and not (pargs.proxy or pargs.letsencrypt):
            stype, cache = 'html', 'basic'
        elif stype and pargs.proxy:
            Log.error(self, "--proxy can not be used with other site types")

        if not pargs.site_name:
            try:
                while not pargs.site_name:
                    pargs.site_name = (input('Enter site name : ').strip())
            except IOError:
                Log.error(self, 'Unable to input site name, Please try again!')

        pargs.site_name = pargs.site_name.strip()
        wo_domain = WODomain.validate(self, pargs.site_name)
        wo_www_domain = "www.{0}".format(wo_domain)
        (wo_domain_type, wo_root_domain) = WODomain.getlevel(
            self, wo_domain)
        wo_site_webroot = WOVar.wo_webroot + wo_domain
        check_site = getSiteInfo(self, wo_domain)

        if check_site is None:
            Log.error(self, " Site {0} does not exist.".format(wo_domain))
        else:
            oldsitetype = check_site.site_type
            oldcachetype = check_site.cache_type
            check_ssl = check_site.is_ssl
            check_php_version = check_site.php_version

            old_php72 = bool(check_php_version == "7.2")
            old_php73 = bool(check_php_version == "7.3")
            old_php74 = bool(check_php_version == "7.4")

        if ((pargs.password or pargs.hsts or
             pargs.ngxblocker or pargs.letsencrypt == 'renew') and not (
            pargs.html or pargs.php or pargs.php72 or pargs.php73 or
            pargs.php74 or
            pargs.mysql or pargs.wp or pargs.wpfc or pargs.wpsc or
            pargs.wprocket or pargs.wpce or
                pargs.wpsubdir or pargs.wpsubdomain)):

            # update wordpress password
            if (pargs.password):
                try:
                    updatewpuserpassword(self, wo_domain, wo_site_webroot)
                except SiteError as e:
                    Log.debug(self, str(e))
                    Log.info(self, "\nPassword Unchanged.")
                return 0

            # setup hsts
            if (pargs.hsts):
                if pargs.hsts == "on":
                    SSL.setuphsts(self, wo_domain, enable=True)
                elif pargs.hsts == "off":
                    SSL.setuphsts(self, wo_domain, enable=False)
                    # Service Nginx Reload
                if not WOService.reload_service(self, 'nginx'):
                    Log.error(
                        self, "service nginx reload failed. "
                        "check issues with `nginx -t` command")
                return 0

            # setup ngxblocker
            if (pargs.ngxblocker):
                if pargs.ngxblocker == "on":
                    if os.path.isdir('/etc/nginx/bots.d'):
                        try:
                            setupngxblocker(self, wo_domain)
                        except SiteError as e:
                            Log.debug(self, str(e))
                            Log.info(self, "\nngxblocker not enabled.")
                    else:
                        Log.error(self, 'ngxblocker stack is not installed')
                elif pargs.ngxblocker == "off":
                    try:
                        setupngxblocker(self, wo_domain, False)
                    except SiteError as e:
                        Log.debug(self, str(e))
                        Log.info(self, "\nngxblocker not enabled.")

                # Service Nginx Reload
                if not WOService.reload_service(self, 'nginx'):
                    Log.error(self, "service nginx reload failed. "
                              "check issues with `nginx -t` command")
                return 0

            # letsencryot rebew
            if (pargs.letsencrypt == 'renew'):
                if WOAcme.cert_check(self, wo_domain):
                    if not pargs.force:
                        if (SSL.getexpirationdays(self, wo_domain) > 30):
                            Log.error(
                                self, "Your cert will expire in more "
                                "than 30 days ( " +
                                str(SSL.getexpirationdays(self, wo_domain)) +
                                " days).\nAdd \'--force\' to force to renew")
                    Log.wait(self, "Renewing SSL certificate")
                    if WOAcme.renew(self, wo_domain):
                        Log.valide(self, "Renewing SSL certificate")
                else:
                    Log.error(self, "Certificate doesn't exist")
                return 0

        if (((stype == 'php' and
              oldsitetype not in ['html', 'proxy', 'php', 'php72',
                                  'php73', 'php74']) or
             (stype == 'mysql' and oldsitetype not in [
                 'html', 'php', 'php72', 'php73', 'php74', 'proxy']) or
             (stype == 'wp' and oldsitetype not in [
                 'html', 'php', 'php72', 'php73', 'php74', 'mysql',
                 'proxy', 'wp']) or
             (stype == 'wpsubdir' and oldsitetype in ['wpsubdomain']) or
             (stype == 'wpsubdomain' and oldsitetype in ['wpsubdir']) or
             (stype == oldsitetype and cache == oldcachetype)) and
                not (pargs.php72 or pargs.php73 or pargs.php74)):
            Log.info(self, Log.FAIL + "can not update {0} {1} to {2} {3}".
                     format(oldsitetype, oldcachetype, stype, cache))
            return 1

        if stype == 'proxy':
            data['site_name'] = wo_domain
            data['www_domain'] = wo_www_domain
            data['proxy'] = True
            data['host'] = host
            data['port'] = port
            data['webroot'] = wo_site_webroot
            data['currsitetype'] = oldsitetype
            data['currcachetype'] = oldcachetype

        if stype == 'php':
            data = dict(
                site_name=wo_domain, www_domain=wo_www_domain,
                static=False, basic=True, wp=False, wpfc=False,
                php72=False, php73=False, php74=False,
                wpsc=False, wpredis=False, wprocket=False, wpce=False,
                multisite=False, wpsubdir=False, webroot=wo_site_webroot,
                currsitetype=oldsitetype, currcachetype=oldcachetype)

        elif stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
            data = dict(
                site_name=wo_domain, www_domain=wo_www_domain,
                static=False, basic=True, wp=False, wpfc=False,
                wpsc=False, wpredis=False, wprocket=False, wpce=False,
                multisite=False, wpsubdir=False, webroot=wo_site_webroot,
                wo_db_name='', wo_db_user='', wo_db_pass='',
                wo_db_host='',
                currsitetype=oldsitetype, currcachetype=oldcachetype)

        if stype in ['wp', 'wpsubdir', 'wpsubdomain']:
            data['wp'] = True
            data['basic'] = False
            data[cache] = True
            if stype in ['wpsubdir', 'wpsubdomain']:
                data['multisite'] = True
                if stype == 'wpsubdir':
                    data['wpsubdir'] = True

        if ((pargs.php72 or pargs.php73 or
             pargs.php74) and (not data)):
            Log.debug(
                self, "pargs php72, or php73, or php74 enabled")
            data = dict(
                site_name=wo_domain,
                www_domain=wo_www_domain,
                currsitetype=oldsitetype,
                currcachetype=oldcachetype,
                webroot=wo_site_webroot)
            stype = oldsitetype
            cache = oldcachetype
            if oldsitetype == 'html' or oldsitetype == 'proxy':
                data['static'] = False
                data['wp'] = False
                data['multisite'] = False
                data['wpsubdir'] = False
            elif (oldsitetype == 'php' or oldsitetype == 'mysql' or
                  oldsitetype == 'php73'or oldsitetype == 'php74'):
                data['static'] = False
                data['wp'] = False
                data['multisite'] = False
                data['wpsubdir'] = False
            elif oldsitetype == 'wp':
                data['static'] = False
                data['wp'] = True
                data['multisite'] = False
                data['wpsubdir'] = False
            elif oldsitetype == 'wpsubdir':
                data['static'] = False
                data['wp'] = True
                data['multisite'] = True
                data['wpsubdir'] = True
            elif oldsitetype == 'wpsubdomain':
                data['static'] = False
                data['wp'] = True
                data['multisite'] = True
                data['wpsubdir'] = False

            if oldcachetype == 'basic':
                data['basic'] = True
                data['wpfc'] = False
                data['wpsc'] = False
                data['wpredis'] = False
                data['wprocket'] = False
                data['wpce'] = False
            elif oldcachetype == 'wpfc':
                data['basic'] = False
                data['wpfc'] = True
                data['wpsc'] = False
                data['wpredis'] = False
                data['wprocket'] = False
                data['wpce'] = False
            elif oldcachetype == 'wpsc':
                data['basic'] = False
                data['wpfc'] = False
                data['wpsc'] = True
                data['wpredis'] = False
                data['wprocket'] = False
                data['wpce'] = False
            elif oldcachetype == 'wpredis':
                data['basic'] = False
                data['wpfc'] = False
                data['wpsc'] = False
                data['wpredis'] = True
                data['wprocket'] = False
                data['wpce'] = False
            elif oldcachetype == 'wprocket':
                data['basic'] = False
                data['wpfc'] = False
                data['wpsc'] = False
                data['wpredis'] = False
                data['wprocket'] = True
                data['wpce'] = False
            elif oldcachetype == 'wpce':
                data['basic'] = False
                data['wpfc'] = False
                data['wpsc'] = False
                data['wpredis'] = False
                data['wprocket'] = False
                data['wpce'] = True

        if pargs.php72:
            Log.debug(self, "pargs.php72 detected")
            data['php72'] = True
            php72 = True
        elif pargs.php73:
            Log.debug(self, "pargs.php73 detected")
            data['php73'] = True
            php73 = True
        elif pargs.php74:
            Log.debug(self, "pargs.php74 detected")
            data['php74'] = True
            php74 = True

        if pargs.php72:
            if php72 is old_php72:
                Log.info(self, "PHP 7.2 is already enabled for given "
                         "site")
                pargs.php72 = False

        if pargs.php73:
            if php73 is old_php73:
                Log.info(self, "PHP 7.3 is already enabled for given "
                         "site")
                pargs.php73 = False

        if pargs.php74:
            if php74 is old_php74:
                Log.info(self, "PHP 7.4 is already enabled for given "
                         "site")
                pargs.php74 = False

        if (data and (not pargs.php73) and
                (not pargs.php74) and (not pargs.php72)):
            data['php72'] = bool(old_php72 is True)
            Log.debug(self, "data php72 = {0}".format(data['php72']))
            php72 = bool(old_php72 is True)
            data['php73'] = bool(old_php73 is True)
            Log.debug(self, "data php73 = {0}".format(data['php73']))
            php73 = bool(old_php73 is True)
            data['php74'] = bool(old_php74 is True)
            Log.debug(self, "data php74 = {0}".format(data['php74']))
            php74 = bool(old_php74 is True)

        if pargs.letsencrypt:
            acme_domains = []
            acmedata = dict(acme_domains, dns=False, acme_dns='dns_cf',
                            dnsalias=False, acme_alias='', keylength='')
            acmedata['keylength'] = self.app.config.get('letsencrypt',
                                                        'keylength')
            if pargs.letsencrypt == 'on':
                data['letsencrypt'] = True
                letsencrypt = True
                acme_subdomain = bool(wo_domain_type == 'subdomain')
                acme_wildcard = False
            elif pargs.letsencrypt == 'subdomain':
                data['letsencrypt'] = True
                letsencrypt = True
                acme_subdomain = True
                acme_wildcard = False
            elif pargs.letsencrypt == 'wildcard':
                data['letsencrypt'] = True
                letsencrypt = True
                acme_wildcard = True
                acme_subdomain = False
                acmedata['dns'] = True
            elif pargs.letsencrypt == 'off':
                data['letsencrypt'] = False
                letsencrypt = False
                acme_subdomain = False
                acme_wildcard = False
            elif pargs.letsencrypt == 'clean':
                data['letsencrypt'] = False
                letsencrypt = False
                acme_subdomain = False
                acme_wildcard = False
            elif pargs.letsencrypt == 'purge':
                data['letsencrypt'] = False
                letsencrypt = False
                acme_subdomain = False
                acme_wildcard = False
            else:
                data['letsencrypt'] = False
                letsencrypt = False
                acme_subdomain = False
                acme_wildcard = False

            if not (acme_subdomain is True):
                if letsencrypt is check_ssl:
                    if letsencrypt is False:
                        Log.error(self, "SSL is not configured for given "
                                  "site")
                    elif letsencrypt is True:
                        Log.error(self, "SSL is already configured for given "
                                  "site")
                    pargs.letsencrypt = False

        if pargs.all and pargs.letsencrypt == "off":
            if letsencrypt is check_ssl:
                if letsencrypt is False:
                    Log.error(self, "HTTPS is not configured for given "
                              "site", False)
                    return 0

        if pargs.wpredis and data['currcachetype'] != 'wpredis':
            data['wpredis'] = True
            data['basic'] = False
            cache = 'wpredis'

        if pargs.wprocket and data['currcachetype'] != 'wprocket':
            data['wprocket'] = True
            data['basic'] = False
            cache = 'wprocket'

        if pargs.wpce and data['currcachetype'] != 'wpce':
            data['wpce'] = True
            data['basic'] = False
            cache = 'wpce'

        if ((php73 is old_php73) and (php72 is old_php72) and
            (php74 is old_php74) and (stype == oldsitetype and
                                      cache == oldcachetype)):
            Log.debug(self, "Nothing to update")
            return 1

        if php73 is True:
            data['wo_php'] = 'php73'
            check_php_version = '7.3'
        elif php74 is True:
            data['wo_php'] = 'php74'
            check_php_version = '7.4'
        elif php72 is True:
            data['wo_php'] = 'php72'
            check_php_version = '7.2'
        else:
            data['wo_php'] = 'php72'
            check_php_version = '7.2'

        if pargs.hsts:
            data['hsts'] = bool(pargs.hsts == "on")

        if pargs.ngxblocker:
            ngxblocker = bool(pargs.ngxblocker == 'on')

        if not data:
            Log.error(self, "Cannot update {0}, Invalid Options"
                      .format(wo_domain))

        wo_auth = site_package_check(self, stype)
        data['wo_db_name'] = check_site.db_name
        data['wo_db_user'] = check_site.db_user
        data['wo_db_pass'] = check_site.db_password
        data['wo_db_host'] = check_site.db_host

        if not (pargs.letsencrypt or pargs.hsts or pargs.ngxblocker):
            try:
                pre_run_checks(self)
            except SiteError as e:
                Log.debug(self, str(e))
                Log.error(self, "NGINX configuration check failed.")

            try:
                sitebackup(self, data)
            except Exception as e:
                Log.debug(self, str(e))
                Log.info(self, Log.FAIL + "Check the log for details: "
                         "`tail /var/log/wo/wordops.log` and please try again")
                return 1

            # setup NGINX configuration, and webroot
            try:
                setupdomain(self, data)
            except SiteError as e:
                Log.debug(self, str(e))
                Log.info(self, Log.FAIL + "Update site failed."
                         "Check the log for details:"
                         "`tail /var/log/wo/wordops.log` and please try again")
                return 1

        if 'proxy' in data.keys() and data['proxy']:
            updateSiteInfo(self, wo_domain, stype=stype, cache=cache,
                           ssl=(bool(check_site.is_ssl)))
            Log.info(self, "Successfully updated site"
                     " http://{0}".format(wo_domain))
            return 0

        if pargs.letsencrypt:
            if data['letsencrypt'] is True:
                # DNS API configuration
                if pargs.dns:
                    Log.debug(self, "DNS validation enabled")
                    acmedata['dns'] = True
                    if not pargs.dns == 'dns_cf':
                        Log.debug(self, "DNS API : {0}".format(pargs.dns))
                        acmedata['acme_dns'] = pargs.dns
                if pargs.dnsalias:
                    Log.debug(self, "DNS Alias enabled")
                    acmedata['dnsalias'] = True
                    acmedata['acme_alias'] = pargs.dnsalias
                # Set list of domains to secure
                if acme_subdomain is True:
                    Log.info(self, "Certificate type : subdomain")
                    acme_domains = acme_domains + [
                        '{0}'.format(wo_domain)]
                elif acme_wildcard is True:
                    Log.info(self, "Certificate type : wildcard")
                    acme_domains = acme_domains + [
                        '{0}'.format(wo_domain),
                        '*.{0}'.format(wo_domain)]
                else:
                    Log.info(self, "Certificate type : domain")
                    acme_domains = acme_domains + [
                        '{0}'.format(wo_domain),
                        'www.{0}'.format(wo_domain)]

                if WOAcme.cert_check(self, wo_domain):
                    SSL.archivedcertificatehandle(
                        self, wo_domain, acme_domains)
                else:
                    if acme_subdomain:
                        Log.debug(self, "checkWildcardExist on *.{0}"
                                  .format(wo_root_domain))
                        if SSL.checkwildcardexist(self, wo_root_domain):
                            Log.info(
                                self, "Using existing Wildcard SSL "
                                "certificate from {0} to secure {1}"
                                .format(wo_root_domain, wo_domain))
                            Log.debug(
                                self, "symlink wildcard "
                                "cert between {0} & {1}"
                                .format(wo_domain, wo_root_domain))
                            # copy the cert from the root domain
                            copyWildcardCert(self, wo_domain,
                                             wo_root_domain)
                        else:
                            # check DNS records before issuing cert
                            if not acmedata['dns'] is True:
                                if not pargs.force:
                                    if not WOAcme.check_dns(self,
                                                            acme_domains):
                                        Log.error(
                                            self,
                                            "Aborting SSL certificate "
                                            "issuance")
                            Log.debug(
                                self, "Setup Cert with acme.sh for {0}"
                                .format(wo_domain))
                            if WOAcme.setupletsencrypt(
                                    self, acme_domains, acmedata):
                                WOAcme.deploycert(self, wo_domain)
                            else:
                                Log.error(
                                    self, "Unable to issue certificate")
                    else:
                        # check DNS records before issuing cert
                        if not acmedata['dns'] is True:
                            if not pargs.force:
                                if not WOAcme.check_dns(self,
                                                        acme_domains):
                                    Log.error(
                                        self,
                                        "Aborting SSL "
                                        "certificate issuance")
                        if WOAcme.setupletsencrypt(
                                self, acme_domains, acmedata):
                            WOAcme.deploycert(self, wo_domain)
                        else:
                            Log.error(self, "Unable to issue certificate")

                    SSL.httpsredirect(
                        self, wo_domain, acme_domains, redirect=True)
                    SSL.siteurlhttps(self, wo_domain)

                if not WOService.reload_service(self, 'nginx'):
                    Log.error(self, "service nginx reload failed. "
                              "check issues with `nginx -t` command")
                Log.info(self, "Congratulations! Successfully "
                         "Configured SSL on https://{0}".format(wo_domain))
                if (SSL.getexpirationdays(self, wo_domain) > 0):
                    Log.info(self, "Your cert will expire within " +
                             str(SSL.getexpirationdays(self, wo_domain)) +
                             " days.")
                else:
                    Log.warn(
                        self, "Your cert already EXPIRED ! "
                        ".PLEASE renew soon . ")

            elif data['letsencrypt'] is False:
                if pargs.letsencrypt == "off":
                    if os.path.islink("{0}/conf/nginx/ssl.conf"
                                      .format(wo_site_webroot)):
                        WOFileUtils.remove_symlink(self,
                                                   "{0}/conf/nginx/ssl.conf"
                                                   .format(wo_site_webroot))
                    elif os.path.isfile("{0}/conf/nginx/ssl.conf"
                                        .format(wo_site_webroot)):
                        Log.info(self, 'Setting Nginx configuration')
                        WOFileUtils.mvfile(self, "{0}/conf/nginx/ssl.conf"
                                           .format(wo_site_webroot),
                                           '{0}/conf/nginx/ssl.conf.disabled'
                                           .format(wo_site_webroot))
                        SSL.httpsredirect(
                            self, wo_domain, acmedata, redirect=False)
                        if os.path.isfile("{0}/conf/nginx/hsts.conf"
                                          .format(wo_site_webroot)):
                            WOFileUtils.mvfile(self, "{0}/conf/nginx/hsts.conf"
                                               .format(wo_site_webroot),
                                               '{0}/conf/nginx/'
                                               'hsts.conf.disabled'
                                               .format(wo_site_webroot))
                        # find all broken symlinks
                        sympath = "/var/www"
                        WOFileUtils.findBrokenSymlink(self, sympath)

                elif (pargs.letsencrypt == "clean" or
                      pargs.letsencrypt == "purge"):
                    WOAcme.removeconf(self, wo_domain)
                    # find all broken symlinks
                    sympath = "/var/www"
                    WOFileUtils.findBrokenSymlink(self, sympath)
                if not WOService.reload_service(self, 'nginx'):
                    Log.error(self, "service nginx reload failed. "
                              "check issues with `nginx -t` command")
                    # Log.info(self,"Removing Cron Job set for cert
                    # auto-renewal") WOCron.remove_cron(self,'wo site
                    # update {0} --le=renew --min_expiry_limit 30
                    # 2> \/dev\/null'.format(wo_domain))
                    Log.info(self, "Successfully Disabled SSl for Site "
                             " http://{0}".format(wo_domain))

            # Add nginx conf folder into GIT
            WOGit.add(self, ["{0}/conf/nginx".format(wo_site_webroot)],
                      msg="Adding letsencrypts config of site: {0}"
                      .format(wo_domain))
            updateSiteInfo(self, wo_domain, ssl=letsencrypt)
            return 0

        if pargs.hsts:
            if data['hsts'] is True:
                if os.path.isfile(("{0}/conf/nginx/ssl.conf")
                                  .format(wo_site_webroot)):
                    if not os.path.isfile("{0}/conf/nginx/hsts.conf"
                                          .format(wo_site_webroot)):
                        SSL.setuphsts(self, wo_domain)
                    else:
                        Log.error(self, "HSTS is already configured for given "
                                        "site")
                    if not WOService.reload_service(self, 'nginx'):
                        Log.error(self, "service nginx reload failed. "
                                  "check issues with `nginx -t` command")
                else:
                    Log.error(self, "HTTPS is not configured for given "
                              "site")

            elif data['hsts'] is False:
                if os.path.isfile(("{0}/conf/nginx/hsts.conf")
                                  .format(wo_site_webroot)):
                    WOFileUtils.mvfile(self, "{0}/conf/nginx/hsts.conf"
                                       .format(wo_site_webroot),
                                       '{0}/conf/nginx/hsts.conf.disabled'
                                       .format(wo_site_webroot))
                    if not WOService.reload_service(self, 'nginx'):
                        Log.error(self, "service nginx reload failed. "
                                  "check issues with `nginx -t` command")
                else:
                    Log.error(self, "HSTS is not configured for given "
                              "site")
        if pargs.ngxblocker:
            if ngxblocker is True:
                setupngxblocker(self, wo_domain)
            elif ngxblocker is False:
                if os.path.isfile("{0}/conf/nginx/ngxblocker.conf"
                                  .format(wo_site_webroot)):
                    WOFileUtils.mvfile(
                        self,
                        "{0}/conf/nginx/ngxblocker.conf"
                        .format(wo_site_webroot),
                        "{0}/conf/nginx/ngxblocker.conf.disabled"
                        .format(wo_site_webroot))
            # Service Nginx Reload
            if not WOService.reload_service(self, 'nginx'):
                Log.error(self, "service nginx reload failed. "
                          "check issues with `nginx -t` command")

        if stype == oldsitetype and cache == oldcachetype:

            # Service Nginx Reload
            if not WOService.reload_service(self, 'nginx'):
                Log.error(self, "service nginx reload failed. "
                          "check issues with `nginx -t` command")

            updateSiteInfo(self, wo_domain, stype=stype, cache=cache,
                           ssl=(bool(check_site.is_ssl)),
                           php_version=check_php_version)

            Log.info(self, "Successfully updated site"
                     " http://{0}".format(wo_domain))
            return 0

        # if data['wo_db_name'] and not data['wp']:
        if 'wo_db_name' in data.keys() and not data['wp']:
            try:
                data = setupdatabase(self, data)
            except SiteError as e:
                Log.debug(self, str(e))
                Log.info(self, Log.FAIL + "Update site failed."
                         "Check the log for details:"
                         "`tail /var/log/wo/wordops.log` and please try again")
                return 1
            try:
                wodbconfig = open("{0}/wo-config.php".format(wo_site_webroot),
                                  encoding='utf-8', mode='w')
                wodbconfig.write("<?php \ndefine('DB_NAME', '{0}');"
                                 "\ndefine('DB_USER', '{1}'); "
                                 "\ndefine('DB_PASSWORD', '{2}');"
                                 "\ndefine('DB_HOST', '{3}');\n?>"
                                 .format(data['wo_db_name'],
                                         data['wo_db_user'],
                                         data['wo_db_pass'],
                                         data['wo_db_host']))
                wodbconfig.close()
            except IOError as e:
                Log.debug(self, str(e))
                Log.debug(self, "creating wo-config.php failed.")
                Log.info(self, Log.FAIL + "Update site failed. "
                         "Check the log for details: "
                         "`tail /var/log/wo/wordops.log` and please try again")
                return 1

        # Setup WordPress if old sites are html/php/mysql sites
        if data['wp'] and oldsitetype in ['html', 'proxy', 'php', 'php72',
                                          'mysql', 'php73', 'php74']:
            try:
                wo_wp_creds = setupwordpress(self, data)
            except SiteError as e:
                Log.debug(self, str(e))
                Log.info(self, Log.FAIL + "Update site failed."
                         "Check the log for details: "
                         "`tail /var/log/wo/wordops.log` and please try again")
                return 1

        # Uninstall unnecessary plugins
        if oldsitetype in ['wp', 'wpsubdir', 'wpsubdomain']:
            # Setup WordPress Network if update option is multisite
            # and oldsite is WordPress single site
            if data['multisite'] and oldsitetype == 'wp':
                try:
                    setupwordpressnetwork(self, data)
                except SiteError as e:
                    Log.debug(self, str(e))
                    Log.info(self, Log.FAIL + "Update site failed. "
                             "Check the log for details:"
                             " `tail /var/log/wo/wordops.log` "
                             "and please try again")
                    return 1

            if ((oldcachetype in ['wpsc', 'basic', 'wpredis', 'wprocket',
                                  'wpce'] and
                 (data['wpfc'])) or (oldsitetype == 'wp' and
                                     data['multisite'] and data['wpfc'])):
                try:
                    plugin_data_object = {
                        "log_level": "INFO",
                        "log_filesize": 5,
                        "enable_purge": 1,
                        "enable_map": "0",
                        "enable_log": 0,
                        "enable_stamp": 1,
                        "purge_homepage_on_new": 1,
                        "purge_homepage_on_edit": 1,
                        "purge_homepage_on_del": 1,
                        "purge_archive_on_new": 1,
                        "purge_archive_on_edit": 0,
                        "purge_archive_on_del": 0,
                        "purge_archive_on_new_comment": 0,
                        "purge_archive_on_deleted_comment": 0,
                        "purge_page_on_mod": 1,
                        "purge_page_on_new_comment": 1,
                        "purge_page_on_deleted_comment": 1,
                        "cache_method": "enable_fastcgi",
                        "purge_method": "get_request",
                        "redis_hostname": "127.0.0.1",
                                          "redis_port": "6379",
                                          "redis_prefix": "nginx-cache:"}
                    plugin_data = json.dumps(plugin_data_object)
                    setupwp_plugin(self, 'nginx-helper',
                                   'rt_wp_nginx_helper_options',
                                   plugin_data, data)
                except SiteError as e:
                    Log.debug(self, str(e))
                    Log.info(self, Log.FAIL + "Update nginx-helper "
                             "settings failed. "
                             "Check the log for details:"
                             " `tail /var/log/wo/wordops.log` "
                             "and please try again")
                    return 1

            elif ((oldcachetype in ['wpsc', 'basic', 'wpfc',
                                    'wprocket', 'wpce'] and
                   (data['wpredis'])) or (oldsitetype == 'wp' and
                                          data['multisite'] and
                                          data['wpredis'])):
                try:
                    plugin_data_object = {
                        "log_level": "INFO",
                        "log_filesize": 5,
                        "enable_purge": 1,
                        "enable_map": "0",
                        "enable_log": 0,
                        "enable_stamp": 1,
                        "purge_homepage_on_new": 1,
                        "purge_homepage_on_edit": 1,
                        "purge_homepage_on_del": 1,
                        "purge_archive_on_new": 1,
                        "purge_archive_on_edit": 0,
                        "purge_archive_on_del": 0,
                        "purge_archive_on_new_comment": 0,
                        "purge_archive_on_deleted_comment": 0,
                        "purge_page_on_mod": 1,
                        "purge_page_on_new_comment": 1,
                        "purge_page_on_deleted_comment": 1,
                        "cache_method": "enable_redis",
                        "purge_method": "get_request",
                        "redis_hostname": "127.0.0.1",
                                          "redis_port": "6379",
                                          "redis_prefix": "nginx-cache:"}
                    plugin_data = json.dumps(plugin_data_object)
                    setupwp_plugin(self, 'nginx-helper',
                                   'rt_wp_nginx_helper_options',
                                   plugin_data, data)
                except SiteError as e:
                    Log.debug(self, str(e))
                    Log.info(self, Log.FAIL + "Update nginx-helper "
                             "settings failed. "
                             "Check the log for details:"
                             " `tail /var/log/wo/wordops.log` "
                             "and please try again")
                    return 1
            else:
                try:
                    # disable nginx-helper
                    plugin_data_object = {
                        "log_level": "INFO",
                        "log_filesize": 5,
                        "enable_purge": 0,
                        "enable_map": 0,
                        "enable_log": 0,
                        "enable_stamp": 0,
                        "purge_homepage_on_new": 1,
                        "purge_homepage_on_edit": 1,
                        "purge_homepage_on_del": 1,
                        "purge_archive_on_new": 1,
                        "purge_archive_on_edit": 0,
                        "purge_archive_on_del": 0,
                        "purge_archive_on_new_comment": 0,
                        "purge_archive_on_deleted_comment": 0,
                        "purge_page_on_mod": 1,
                        "purge_page_on_new_comment": 1,
                        "purge_page_on_deleted_comment": 1,
                        "cache_method": "enable_redis",
                        "purge_method": "get_request",
                        "redis_hostname": "127.0.0.1",
                                          "redis_port": "6379",
                                          "redis_prefix": "nginx-cache:"}
                    plugin_data = json.dumps(plugin_data_object)
                    setupwp_plugin(
                        self, 'nginx-helper',
                        'rt_wp_nginx_helper_options', plugin_data, data)
                except SiteError as e:
                    Log.debug(self, str(e))
                    Log.info(self, Log.FAIL + "Update nginx-helper "
                             "settings failed. "
                             "Check the log for details:"
                             " `tail /var/log/wo/wordops.log` "
                             "and please try again")
                    return 1

            if ((oldcachetype in ['wpsc', 'basic',
                                  'wpfc', 'wprocket', 'wpredis'] and
                 (data['wpce'])) or (oldsitetype == 'wp' and
                                     data['multisite'] and
                                     data['wpce'])):
                try:
                    installwp_plugin(self, 'cache-enabler', data)
                    # setup cache-enabler
                    plugin_data_object = {
                        "expires": 24,
                        "new_post": 1,
                        "new_comment": 0,
                        "webp": 0,
                        "clear_on_upgrade": 1,
                        "compress": 0,
                        "excl_ids": "",
                        "excl_regexp": "",
                        "excl_cookies": "",
                        "incl_attributes": "",
                        "minify_html": 1}
                    plugin_data = json.dumps(plugin_data_object)
                    setupwp_plugin(self, 'cache-enabler',
                                   'cache-enabler', plugin_data, data)
                except SiteError as e:
                    Log.debug(self, str(e))
                    Log.info(self, Log.FAIL + "Update cache-enabler "
                             "settings failed. "
                             "Check the log for details:"
                             " `tail /var/log/wo/wordops.log` "
                             "and please try again")
                    return 1

            if oldcachetype == 'wpsc' and not data['wpsc']:
                try:
                    uninstallwp_plugin(self, 'wp-super-cache', data)
                except SiteError as e:
                    Log.debug(self, str(e))
                    Log.info(self, Log.FAIL + "Update site failed."
                             "Check the log for details:"
                             " `tail /var/log/wo/wordops.log` "
                             "and please try again")
                    return 1

            if oldcachetype == 'wpredis' and not data['wpredis']:
                try:
                    uninstallwp_plugin(self, 'redis-cache', data)
                except SiteError as e:
                    Log.debug(self, str(e))
                    Log.info(self, Log.FAIL + "Update site failed."
                             "Check the log for details:"
                             " `tail /var/log/wo/wordops.log` "
                             "and please try again")
                    return 1

        if oldcachetype != 'wpsc' and data['wpsc']:
            try:
                installwp_plugin(self, 'wp-super-cache', data)
            except SiteError as e:
                Log.debug(self, str(e))
                Log.info(self, Log.FAIL + "Update site failed."
                         "Check the log for details: "
                         "`tail /var/log/wo/wordops.log` and please try again")
                return 1

        if oldcachetype == 'wprocket' and not data['wprocket']:
            try:
                uninstallwp_plugin(self, 'wp-rocket', data)
            except SiteError as e:
                Log.debug(self, str(e))
                Log.info(self, Log.FAIL + "Update site failed."
                         "Check the log for details: "
                         "`tail /var/log/wo/wordops.log` and please try again")
                return 1

        if oldcachetype == 'wpce' and not data['wpce']:
            try:
                uninstallwp_plugin(self, 'cache-enabler', data)
            except SiteError as e:
                Log.debug(self, str(e))
                Log.info(self, Log.FAIL + "Update site failed."
                         "Check the log for details: "
                         "`tail /var/log/wo/wordops.log` and please try again")
                return 1

        # Service Nginx Reload
        if not WOService.reload_service(self, 'nginx'):
            Log.error(self, "service nginx reload failed. "
                      "check issues with `nginx -t` command")

        WOGit.add(self, ["/etc/nginx"],
                  msg="{0} updated with {1} {2}"
                  .format(wo_www_domain, stype, cache))
        # Setup Permissions for webroot
        try:
            setwebrootpermissions(self, data['webroot'])
        except SiteError as e:
            Log.debug(self, str(e))
            Log.info(self, Log.FAIL + "Update site failed."
                     "Check the log for details: "
                     "`tail /var/log/wo/wordops.log` and please try again")
            return 1

        if wo_auth and len(wo_auth):
            for msg in wo_auth:
                Log.info(self, Log.ENDC + msg)

        display_cache_settings(self, data)
        if data['wp'] and oldsitetype in ['html', 'php', 'mysql']:
            Log.info(self, "\n\n" + Log.ENDC + "WordPress admin user :"******" {0}".format(wo_wp_creds['wp_user']))
            Log.info(self, Log.ENDC + "WordPress admin password : {0}"
                     .format(wo_wp_creds['wp_pass']) + "\n\n")
        if oldsitetype in ['html', 'php'] and stype != 'php':
            updateSiteInfo(self, wo_domain, stype=stype, cache=cache,
                           db_name=data['wo_db_name'],
                           db_user=data['wo_db_user'],
                           db_password=data['wo_db_pass'],
                           db_host=data['wo_db_host'],
                           ssl=bool(check_site.is_ssl),
                           php_version=check_php_version)
        else:
            updateSiteInfo(self, wo_domain, stype=stype, cache=cache,
                           ssl=bool(check_site.is_ssl),
                           php_version=check_php_version)
        Log.info(self, "Successfully updated site"
                 " http://{0}".format(wo_domain))
        return 0
Exemple #12
0
    def default(self, disp_msg=False):
        # All package update
        apt_packages = []
        packages = []
        nginx_packages = []
        empty_packages = []
        self.msg = []
        pargs = self.app.pargs

        if ((not pargs.web) and (not pargs.nginx) and
            (not pargs.php) and (not pargs.php73) and
            (not pargs.mysql) and
            (not pargs.all) and (not pargs.wpcli) and
            (not pargs.netdata) and (not pargs.composer) and
            (not pargs.phpmyadmin) and (not pargs.dashboard) and
                (not pargs.redis)):
            pargs.web = True

        if pargs.all:
            pargs.web = True
            pargs.netdata = True
            pargs.composer = True
            pargs.dashboard = True
            pargs.phpmyadmin = True
            pargs.redis = True
            pargs.wpcli = True
            pargs.php73 = True

        if pargs.web:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                pargs.nginx = True
            else:
                Log.info(self, "Nginx is not already installed")
            pargs.php = True
            pargs.mysql = True
            pargs.wpcli = True

        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVariables.wo_nginx
                nginx_packages = nginx_packages + WOVariables.wo_nginx
            else:
                Log.info(self, "Nginx Stable is not already installed")

        if pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                if not WOAptGet.is_installed(self, 'php7.3-fpm'):
                    apt_packages = apt_packages + WOVariables.wo_php + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php
            else:
                Log.info(self, "PHP 7.2 is not installed")

        if pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                if not WOAptGet.is_installed(self, 'php7.2-fpm'):
                    apt_packages = apt_packages + WOVariables.wo_php73 + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php73
            else:
                Log.info(self, "PHP 7.3 is not installed")

        if pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                apt_packages = apt_packages + WOVariables.wo_mysql
            else:
                Log.info(self, "MariaDB is not installed")

        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                apt_packages = apt_packages + WOVariables.wo_redis
            else:
                Log.info(self, "Redis is not installed")

        if pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [["https://github.com/wp-cli/wp-cli/"
                                        "releases/download/v{0}/"
                                        "wp-cli-{0}.phar"
                                        "".format(WOVariables.wo_wp_cli),
                                        "/usr/local/bin/wp",
                                        "WP-CLI"]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        if pargs.netdata:
            if (os.path.isdir('/opt/netdata') or
                    os.path.isdir('/etc/netdata')):
                packages = packages + [['https://my-netdata.io/'
                                        'kickstart-static64.sh',
                                        '/var/lib/wo/tmp/kickstart.sh',
                                        'Netdata']]

        if pargs.dashboard:
            if os.path.isfile('/var/www/22222/htdocs/index.php'):
                packages = packages + \
                    [["https://github.com/WordOps/wordops-dashboard/"
                      "releases/download/v{0}/wordops-dashboard.tar.gz"
                      .format(WOVariables.wo_dashboard),
                      "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                      "WordOps Dashboard"]]

        if pargs.phpmyadmin:
            if os.path.isdir('/var/www/22222/htdocs/db/pma'):
                packages = packages + \
                    [["https://files.phpmyadmin.net"
                      "/phpMyAdmin/{0}/"
                      "phpMyAdmin-{0}-"
                      "all-languages"
                      ".tar.gz".format(WOVariables.wo_phpmyadmin),
                      "/var/lib/wo/tmp/pma.tar.gz",
                      "PHPMyAdmin"]]
            else:
                Log.error(self, "phpMyAdmin isn't installed")

        if pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + [["https://getcomposer.org/installer",
                                        "/var/lib/wo/tmp/composer-install",
                                        "Composer"]]
            else:
                Log.error(self, "Composer isn't installed")
        if len(apt_packages) or len(packages):
            if len(apt_packages):
                Log.info(self, "Your site may be down for few seconds if "
                         "you are upgrading Nginx, PHP-FPM, MariaDB or Redis")
                # Check prompt
                if ((not pargs.no_prompt) and (not pargs.force)):
                    start_upgrade = input("Do you want to continue:[y/N]")
                    if start_upgrade != "Y" and start_upgrade != "y":
                        Log.error(self, "Not starting package update")
                Log.info(self, "Updating APT packages, please wait...")
                if set(WOVariables.wo_nginx).issubset(set(apt_packages)):
                    pre_pref(self, ["nginx-custom", "nginx-wo"])
                # apt-get update
                WOAptGet.update(self)
                if set(WOVariables.wo_php).issubset(set(apt_packages)):
                    WOAptGet.remove(self, ['php7.2-fpm'],
                                    auto=False, purge=True)
                if set(WOVariables.wo_php73).issubset(set(apt_packages)):
                    WOAptGet.remove(self, ['php7.3-fpm'],
                                    auto=False, purge=True)
                # Update packages
                WOAptGet.install(self, apt_packages)
                post_pref(self, apt_packages, empty_packages, True)
                # Post Actions after package updates

            if len(packages):
                if pargs.wpcli:
                    WOFileUtils.rm(self, '/usr/local/bin/wp')

                if pargs.netdata:
                    WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh')

                if pargs.dashboard:
                    WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php')

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if pargs.wpcli:
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

                if pargs.netdata:
                    Log.info(self, "Upgrading Netdata, please wait...")
                    if os.path.isdir('/opt/netdata'):
                        WOShellExec.cmd_exec(
                            self, "bash /opt/netdata/usr/"
                            "libexec/netdata/netdata-"
                            "updater.sh")
                    elif os.path.isdir('/etc/netdata'):
                        WOShellExec.cmd_exec(
                            self, "bash /usr/"
                            "libexec/netdata/netdata-"
                            "updater.sh")

                if pargs.dashboard:
                    Log.debug(self, "Extracting wo-dashboard.tar.gz "
                              "to location {0}22222/htdocs/"
                              .format(WOVariables.wo_webroot))
                    WOExtract.extract(self, '/var/lib/wo/tmp/'
                                      'wo-dashboard.tar.gz',
                                      '{0}22222/htdocs'
                                      .format(WOVariables.wo_webroot))
                    WOFileUtils.chown(self, "{0}22222/htdocs"
                                      .format(WOVariables.wo_webroot),
                                      WOVariables.wo_php_user,
                                      WOVariables.wo_php_user, recursive=True)

                if pargs.composer:
                    Log.info(self, "Upgrading Composer, please wait...")
                    WOShellExec.cmd_exec(self, "php -q /var/lib/wo"
                                         "/tmp/composer-install "
                                         "--install-dir=/var/lib/wo/tmp/")
                    shutil.copyfile('/var/lib/wo/tmp/composer.phar',
                                    '/usr/local/bin/composer')
                    WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)

                if pargs.phpmyadmin:
                    Log.info(self, "Upgrading phpMyAdmin, please wait...")
                    WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz',
                                      '/var/lib/wo/tmp/')
                    shutil.copyfile(('{0}22222/htdocs/db/pma'
                                     '/config.inc.php'
                                     .format(WOVariables.wo_webroot)),
                                    ('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                     '-all-languages/config.inc.php'
                                     .format(WOVariables.wo_phpmyadmin))
                                    )
                    WOFileUtils.rm(self, '{0}22222/htdocs/db/pma'
                                   .format(WOVariables.wo_webroot))
                    shutil.move('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                '-all-languages/'
                                .format(WOVariables.wo_phpmyadmin),
                                '{0}22222/htdocs/db/pma/'
                                .format(WOVariables.wo_webroot))
                    WOFileUtils.chown(self, "{0}22222/htdocs"
                                      .format(WOVariables.wo_webroot),
                                      WOVariables.wo_php_user,
                                      WOVariables.wo_php_user, recursive=True)

            Log.info(self, "Successfully updated packages")
        else:
            self.app.args.print_help()
Exemple #13
0
    def deploycert(self, wo_domain_name):
        """Deploy Let's Encrypt certificates with acme.sh"""
        # check acme.sh is installed
        WOAcme.check_acme(self)
        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 #14
0
    def default(self):
        """Default function of log GZip"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (not self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php5/slow.log', 'a').close()
            open('/var/log/php5/fpm.log', 'a').close()
            self.msg = self.msg + ['/var/log/php5/slow.log',
                                   '/var/log/php5/fpm.log']
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if WOVariables.wo_mysql_host is "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")

            else:
                Log.warn(self, "Remote MySQL found, WordOps does not support"
                         "remote MySQL servers or log files")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(WOVariables.wo_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + ["{0}/{1}/logs/access.log"
                                       .format(WOVariables.wo_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.nginx:
                self.msg = self.msg + ["{0}/{1}/logs/error.log"
                                       .format(WOVariables.wo_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile('{0}/logs/debug.log'
                                          .format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log"
                                 .format(webroot),
                                 encoding='utf-8', mode='a').close()
                            WOShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/"
                                                 "wp-content/debug.log"
                                                 "".format(webroot,
                                                           WOVariables
                                                           .wo_php_user)
                                                 )
                    # create symbolic link for debug log
                    WOFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/"
                                                      "debug.log"
                                                      .format(webroot),
                                                      '{0}/logs/debug.log'
                                                      .format(webroot)])

                    self.msg = self.msg + ["{0}/{1}/logs/debug.log"
                                           .format(WOVariables.wo_webroot,
                                                   self.app.pargs.site_name)]
                else:
                    Log.info(self, "Site is not WordPress site, skipping "
                             "WordPress logs")

        gzip_list = []
        for g_list in self.msg:
            gzip_list = gzip_list + glob.glob(g_list)

        # Gzip content of file
        for g_list in gzip_list:
            Log.info(self, "Gzipping file {file}".format(file=g_list))
            in_file = g_list
            in_data = open(in_file, "rb").read()
            out_gz = g_list + ".gz"
            gzf = gzip.open(out_gz, "wb")
            gzf.write(in_data)
            gzf.close()
Exemple #15
0
    def default(self):
        pargs = self.app.pargs
        # self.app.render((data), 'default.mustache')
        # Check domain name validation
        data = dict()
        host, port = None, None
        try:
            stype, cache = detSitePar(vars(pargs))
        except RuntimeError as e:
            Log.debug(self, str(e))
            Log.error(self, "Please provide valid options to creating site")

        if stype is None and pargs.proxy:
            stype, cache = 'proxy', ''
            proxyinfo = pargs.proxy[0].strip()
            if not proxyinfo:
                Log.error(self, "Please provide proxy server host information")
            proxyinfo = proxyinfo.split(':')
            host = proxyinfo[0].strip()
            port = '80' if len(proxyinfo) < 2 else proxyinfo[1].strip()
        elif stype is None and not pargs.proxy:
            stype, cache = 'html', 'basic'
        elif stype and pargs.proxy:
            Log.error(self, "proxy should not be used with other site types")

        if not pargs.site_name:
            try:
                while not pargs.site_name:
                    # preprocessing before finalize site name
                    pargs.site_name = (input('Enter site name : ').strip())
            except IOError as e:
                Log.debug(self, str(e))
                Log.error(self, "Unable to input site name, Please try again!")

        pargs.site_name = pargs.site_name.strip()
        wo_domain = WODomain.validate(self, pargs.site_name)
        wo_www_domain = "www.{0}".format(wo_domain)
        (wo_domain_type, wo_root_domain) = WODomain.getlevel(self, wo_domain)
        if not wo_domain.strip():
            Log.error(self, "Invalid domain name, "
                      "Provide valid domain name")

        wo_site_webroot = WOVar.wo_webroot + wo_domain

        if check_domain_exists(self, wo_domain):
            Log.error(self, "site {0} already exists".format(wo_domain))
        elif os.path.isfile(
                '/etc/nginx/sites-available/{0}'.format(wo_domain)):
            Log.error(
                self, "Nginx configuration /etc/nginx/sites-available/"
                "{0} already exists".format(wo_domain))

        if stype == 'proxy':
            data = dict(site_name=wo_domain,
                        www_domain=wo_www_domain,
                        static=True,
                        basic=False,
                        wp=False,
                        wpfc=False,
                        wpsc=False,
                        wprocket=False,
                        wpce=False,
                        multisite=False,
                        wpsubdir=False,
                        webroot=wo_site_webroot)
            data['proxy'] = True
            data['host'] = host
            data['port'] = port
            data['basic'] = True

        if pargs.php72 or pargs.php73 or pargs.php74:
            data = dict(site_name=wo_domain,
                        www_domain=wo_www_domain,
                        static=False,
                        basic=False,
                        wp=False,
                        wpfc=False,
                        wpsc=False,
                        wprocket=False,
                        wpce=False,
                        multisite=False,
                        wpsubdir=False,
                        webroot=wo_site_webroot)
            data['basic'] = True

        if stype in ['html', 'php']:
            data = dict(site_name=wo_domain,
                        www_domain=wo_www_domain,
                        static=True,
                        basic=False,
                        wp=False,
                        wpfc=False,
                        wpsc=False,
                        wprocket=False,
                        wpce=False,
                        multisite=False,
                        wpsubdir=False,
                        webroot=wo_site_webroot)

            if stype == 'php':
                data['static'] = False
                data['basic'] = True

        elif stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:

            data = dict(site_name=wo_domain,
                        www_domain=wo_www_domain,
                        static=False,
                        basic=True,
                        wp=False,
                        wpfc=False,
                        wpsc=False,
                        wpredis=False,
                        wprocket=False,
                        wpce=False,
                        multisite=False,
                        wpsubdir=False,
                        webroot=wo_site_webroot,
                        wo_db_name='',
                        wo_db_user='',
                        wo_db_pass='',
                        wo_db_host='')

            if stype in ['wp', 'wpsubdir', 'wpsubdomain']:
                data['wp'] = True
                data['basic'] = False
                data[cache] = True
                data['wp-user'] = pargs.user
                data['wp-email'] = pargs.email
                data['wp-pass'] = pargs.wppass
                if stype in ['wpsubdir', 'wpsubdomain']:
                    data['multisite'] = True
                    if stype == 'wpsubdir':
                        data['wpsubdir'] = True
        else:
            pass

        if data and pargs.php73:
            data['php73'] = True
            data['php74'] = False
            data['php72'] = False
            data['wo_php'] = 'php73'
        elif data and pargs.php74:
            data['php72'] = False
            data['php74'] = True
            data['php73'] = False
            data['wo_php'] = 'php74'
        else:
            data['php74'] = False
            data['php72'] = True
            data['php73'] = False
            data['wo_php'] = 'php72'

        if ((not pargs.wpfc) and (not pargs.wpsc) and (not pargs.wprocket)
                and (not pargs.wpce) and (not pargs.wpredis)):
            data['basic'] = True

        if (cache == 'wpredis'):
            cache = 'wpredis'
            data['wpredis'] = True
            data['basic'] = False
            pargs.wpredis = True

        # Check rerequired packages are installed or not
        wo_auth = site_package_check(self, stype)

        try:
            pre_run_checks(self)
        except SiteError as e:
            Log.debug(self, str(e))
            Log.error(self, "NGINX configuration check failed.")

        try:
            try:
                # setup NGINX configuration, and webroot
                setupdomain(self, data)

                # Fix Nginx Hashbucket size error
                hashbucket(self)
            except SiteError as e:
                # call cleanup actions on failure
                Log.info(self,
                         Log.FAIL + "There was a serious error encountered...")
                Log.info(self, Log.FAIL + "Cleaning up afterwards...")
                doCleanupAction(self,
                                domain=wo_domain,
                                webroot=data['webroot'])
                Log.debug(self, str(e))
                Log.error(
                    self, "Check the log for details: "
                    "`tail /var/log/wo/wordops.log` "
                    "and please try again")

            if 'proxy' in data.keys() and data['proxy']:
                addNewSite(self, wo_domain, stype, cache, wo_site_webroot)
                # Service Nginx Reload
                if not WOService.reload_service(self, 'nginx'):
                    Log.info(
                        self,
                        Log.FAIL + "There was a serious error encountered...")
                    Log.info(self, Log.FAIL + "Cleaning up afterwards...")
                    doCleanupAction(self, domain=wo_domain)
                    deleteSiteInfo(self, wo_domain)
                    Log.error(
                        self, "service nginx reload failed. "
                        "check issues with `nginx -t` command")
                    Log.error(
                        self, "Check the log for details: "
                        "`tail /var/log/wo/wordops.log` "
                        "and please try again")
                if wo_auth and len(wo_auth):
                    for msg in wo_auth:
                        Log.info(self, Log.ENDC + msg, log=False)
                Log.info(
                    self, "Successfully created site"
                    " http://{0}".format(wo_domain))
                return

            if data['php73']:
                php_version = "7.3"
            elif data['php74']:
                php_version = "7.4"
            else:
                php_version = "7.2"

            addNewSite(self,
                       wo_domain,
                       stype,
                       cache,
                       wo_site_webroot,
                       php_version=php_version)

            # Setup database for MySQL site
            if 'wo_db_name' in data.keys() and not data['wp']:
                try:
                    data = setupdatabase(self, data)
                    # Add database information for site into database
                    updateSiteInfo(self,
                                   wo_domain,
                                   db_name=data['wo_db_name'],
                                   db_user=data['wo_db_user'],
                                   db_password=data['wo_db_pass'],
                                   db_host=data['wo_db_host'])
                except SiteError as e:
                    # call cleanup actions on failure
                    Log.debug(self, str(e))
                    Log.info(
                        self,
                        Log.FAIL + "There was a serious error encountered...")
                    Log.info(self, Log.FAIL + "Cleaning up afterwards...")
                    doCleanupAction(self,
                                    domain=wo_domain,
                                    webroot=data['webroot'],
                                    dbname=data['wo_db_name'],
                                    dbuser=data['wo_db_user'],
                                    dbhost=data['wo_db_host'])
                    deleteSiteInfo(self, wo_domain)
                    Log.error(
                        self, "Check the log for details: "
                        "`tail /var/log/wo/wordops.log` "
                        "and please try again")

                try:
                    wodbconfig = open(
                        "{0}/wo-config.php".format(wo_site_webroot),
                        encoding='utf-8',
                        mode='w')
                    wodbconfig.write("<?php \ndefine('DB_NAME', '{0}');"
                                     "\ndefine('DB_USER', '{1}'); "
                                     "\ndefine('DB_PASSWORD', '{2}');"
                                     "\ndefine('DB_HOST', '{3}');\n?>".format(
                                         data['wo_db_name'],
                                         data['wo_db_user'],
                                         data['wo_db_pass'],
                                         data['wo_db_host']))
                    wodbconfig.close()
                    stype = 'mysql'
                except IOError as e:
                    Log.debug(self, str(e))
                    Log.debug(
                        self, "Error occured while generating "
                        "wo-config.php")
                    Log.info(
                        self,
                        Log.FAIL + "There was a serious error encountered...")
                    Log.info(self, Log.FAIL + "Cleaning up afterwards...")
                    doCleanupAction(self,
                                    domain=wo_domain,
                                    webroot=data['webroot'],
                                    dbname=data['wo_db_name'],
                                    dbuser=data['wo_db_user'],
                                    dbhost=data['wo_db_host'])
                    deleteSiteInfo(self, wo_domain)
                    Log.error(
                        self, "Check the log for details: "
                        "`tail /var/log/wo/wordops.log` "
                        "and please try again")

            # Setup WordPress if Wordpress site
            if data['wp']:
                vhostonly = bool(pargs.vhostonly)
                try:
                    wo_wp_creds = setupwordpress(self, data, vhostonly)
                    # Add database information for site into database
                    updateSiteInfo(self,
                                   wo_domain,
                                   db_name=data['wo_db_name'],
                                   db_user=data['wo_db_user'],
                                   db_password=data['wo_db_pass'],
                                   db_host=data['wo_db_host'])
                except SiteError as e:
                    # call cleanup actions on failure
                    Log.debug(self, str(e))
                    Log.info(
                        self,
                        Log.FAIL + "There was a serious error encountered...")
                    Log.info(self, Log.FAIL + "Cleaning up afterwards...")
                    doCleanupAction(self,
                                    domain=wo_domain,
                                    webroot=data['webroot'],
                                    dbname=data['wo_db_name'],
                                    dbuser=data['wo_db_user'],
                                    dbhost=data['wo_mysql_grant_host'])
                    deleteSiteInfo(self, wo_domain)
                    Log.error(
                        self, "Check the log for details: "
                        "`tail /var/log/wo/wordops.log` "
                        "and please try again")

            # Service Nginx Reload call cleanup if failed to reload nginx
            if not WOService.reload_service(self, 'nginx'):
                Log.info(self,
                         Log.FAIL + "There was a serious error encountered...")
                Log.info(self, Log.FAIL + "Cleaning up afterwards...")
                doCleanupAction(self,
                                domain=wo_domain,
                                webroot=data['webroot'])
                if 'wo_db_name' in data.keys():
                    doCleanupAction(self,
                                    domain=wo_domain,
                                    dbname=data['wo_db_name'],
                                    dbuser=data['wo_db_user'],
                                    dbhost=data['wo_mysql_grant_host'])
                deleteSiteInfo(self, wo_domain)
                Log.info(
                    self, Log.FAIL + "service nginx reload failed."
                    " check issues with `nginx -t` command.")
                Log.error(
                    self, "Check the log for details: "
                    "`tail /var/log/wo/wordops.log` "
                    "and please try again")

            WOGit.add(self, ["/etc/nginx"],
                      msg="{0} created with {1} {2}".format(
                          wo_www_domain, stype, cache))
            # Setup Permissions for webroot
            try:
                setwebrootpermissions(self, data['webroot'])
            except SiteError as e:
                Log.debug(self, str(e))
                Log.info(self,
                         Log.FAIL + "There was a serious error encountered...")
                Log.info(self, Log.FAIL + "Cleaning up afterwards...")
                doCleanupAction(self,
                                domain=wo_domain,
                                webroot=data['webroot'])
                if 'wo_db_name' in data.keys():
                    print("Inside db cleanup")
                    doCleanupAction(self,
                                    domain=wo_domain,
                                    dbname=data['wo_db_name'],
                                    dbuser=data['wo_db_user'],
                                    dbhost=data['wo_mysql_grant_host'])
                deleteSiteInfo(self, wo_domain)
                Log.error(
                    self, "Check the log for details: "
                    "`tail /var/log/wo/wordops.log` and "
                    "please try again")

            if wo_auth and len(wo_auth):
                for msg in wo_auth:
                    Log.info(self, Log.ENDC + msg, log=False)

            if data['wp'] and (not pargs.vhostonly):
                Log.info(self,
                         Log.ENDC + "WordPress admin user :"******" {0}".format(wo_wp_creds['wp_user']),
                         log=False)
                Log.info(self,
                         Log.ENDC + "WordPress admin password : {0}".format(
                             wo_wp_creds['wp_pass']),
                         log=False)

                display_cache_settings(self, data)

            Log.info(
                self, "Successfully created site"
                " http://{0}".format(wo_domain))
        except SiteError:
            Log.error(
                self, "Check the log for details: "
                "`tail /var/log/wo/wordops.log` and please try again")

        if pargs.letsencrypt:
            acme_domains = []
            data['letsencrypt'] = True
            letsencrypt = True
            Log.debug(self, "Going to issue Let's Encrypt certificate")
            acmedata = dict(acme_domains,
                            dns=False,
                            acme_dns='dns_cf',
                            dnsalias=False,
                            acme_alias='',
                            keylength='')
            if self.app.config.has_section('letsencrypt'):
                acmedata['keylength'] = self.app.config.get(
                    'letsencrypt', 'keylength')
            else:
                acmedata['keylength'] = 'ec-384'
            if pargs.dns:
                Log.debug(self, "DNS validation enabled")
                acmedata['dns'] = True
                if not pargs.dns == 'dns_cf':
                    Log.debug(self, "DNS API : {0}".format(pargs.dns))
                    acmedata['acme_dns'] = pargs.dns
            if pargs.dnsalias:
                Log.debug(self, "DNS Alias enabled")
                acmedata['dnsalias'] = True
                acmedata['acme_alias'] = pargs.dnsalias

            # detect subdomain and set subdomain variable
            if pargs.letsencrypt == "subdomain":
                Log.warn(
                    self, 'Flag --letsencrypt=subdomain is '
                    'deprecated and not required anymore.')
                acme_subdomain = True
                acme_wildcard = False
            elif pargs.letsencrypt == "wildcard":
                acme_wildcard = True
                acme_subdomain = False
                acmedata['dns'] = True
            else:
                if ((wo_domain_type == 'subdomain')):
                    Log.debug(self, "Domain type = {0}".format(wo_domain_type))
                    acme_subdomain = True
                else:
                    acme_subdomain = False
                    acme_wildcard = False

            if acme_subdomain is True:
                Log.info(self, "Certificate type : subdomain")
                acme_domains = acme_domains + ['{0}'.format(wo_domain)]
            elif acme_wildcard is True:
                Log.info(self, "Certificate type : wildcard")
                acme_domains = acme_domains + [
                    '{0}'.format(wo_domain), '*.{0}'.format(wo_domain)
                ]
            else:
                Log.info(self, "Certificate type : domain")
                acme_domains = acme_domains + [
                    '{0}'.format(wo_domain), 'www.{0}'.format(wo_domain)
                ]

            if WOAcme.cert_check(self, wo_domain):
                SSL.archivedcertificatehandle(self, wo_domain, acme_domains)
            else:
                if acme_subdomain is True:
                    # check if a wildcard cert for the root domain exist
                    Log.debug(
                        self,
                        "checkWildcardExist on *.{0}".format(wo_root_domain))
                    if SSL.checkwildcardexist(self, wo_root_domain):
                        Log.info(
                            self, "Using existing Wildcard SSL "
                            "certificate from {0} to secure {1}".format(
                                wo_root_domain, wo_domain))
                        Log.debug(
                            self, "symlink wildcard "
                            "cert between {0} & {1}".format(
                                wo_domain, wo_root_domain))
                        # copy the cert from the root domain
                        copyWildcardCert(self, wo_domain, wo_root_domain)
                    else:
                        # check DNS records before issuing cert
                        if not acmedata['dns'] is True:
                            if not pargs.force:
                                if not WOAcme.check_dns(self, acme_domains):
                                    Log.error(
                                        self, "Aborting SSL "
                                        "certificate issuance")
                        Log.debug(
                            self, "Setup Cert with acme.sh for {0}".format(
                                wo_domain))
                        if WOAcme.setupletsencrypt(self, acme_domains,
                                                   acmedata):
                            WOAcme.deploycert(self, wo_domain)
                else:
                    if not acmedata['dns'] is True:
                        if not pargs.force:
                            if not WOAcme.check_dns(self, acme_domains):
                                Log.error(self,
                                          "Aborting SSL certificate issuance")
                    if WOAcme.setupletsencrypt(self, acme_domains, acmedata):
                        WOAcme.deploycert(self, wo_domain)

                if pargs.hsts:
                    SSL.setuphsts(self, wo_domain)

                SSL.httpsredirect(self, wo_domain, acme_domains, True)
                SSL.siteurlhttps(self, wo_domain)
                if not WOService.reload_service(self, 'nginx'):
                    Log.error(
                        self, "service nginx reload failed. "
                        "check issues with `nginx -t` command")
                Log.info(
                    self, "Congratulations! Successfully Configured "
                    "SSL on https://{0}".format(wo_domain))

                # Add nginx conf folder into GIT
                WOGit.add(self, ["{0}/conf/nginx".format(wo_site_webroot)],
                          msg="Adding letsencrypts config of site: {0}".format(
                              wo_domain))
                updateSiteInfo(self, wo_domain, ssl=letsencrypt)
Exemple #16
0
    def default(self):
        """Default function of log reset"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (not self.app.pargs.site_name)
                and (not self.app.pargs.slow_log_db)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True
            self.app.pargs.slow_log_db = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (self.app.pargs.site_name)
                and (not self.app.pargs.slow_log_db)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.slow_log_db:
            if os.path.isdir("/var/www/22222/htdocs/db/anemometer"):
                Log.info(self, "Resetting MySQL slow_query_log database table")
                WOMysql.execute(
                    self, "TRUNCATE TABLE  "
                    "slow_query_log.global_query_review_history")
                WOMysql.execute(
                    self, "TRUNCATE TABLE "
                    "slow_query_log.global_query_review")

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php/7.2/slow.log', 'a').close()
            open('/var/log/php7.2-fpm.log', 'a').close()
            self.msg = self.msg + [
                '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log'
            ]
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if WOVar.wo_mysql_host == "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(
                    self, "Remote MySQL found, WordOps does not support"
                    "remote MySQL servers or log files")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(WOVar.wo_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + [
                    "{0}/{1}/logs/access.log".format(WOVar.wo_webroot,
                                                     self.app.pargs.site_name)
                ]
            if self.app.pargs.nginx:
                self.msg = self.msg + [
                    "{0}/{1}/logs/error.log".format(WOVar.wo_webroot,
                                                    self.app.pargs.site_name)
                ]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile(
                            '{0}/logs/debug.log'.format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log".format(
                                webroot),
                                 encoding='utf-8',
                                 mode='a').close()
                            WOShellExec.cmd_exec(
                                self, "chown {1}: {0}/htdocs/"
                                "wp-content/debug.log"
                                "".format(webroot, WOVar.wo_php_user))
                    # create symbolic link for debug log
                    WOFileUtils.create_symlink(self, [
                        "{0}/htdocs/wp-content/"
                        "debug.log".format(webroot),
                        '{0}/logs/debug.log'.format(webroot)
                    ])

                    self.msg = self.msg + [
                        "{0}/{1}/logs/debug.log".format(
                            WOVar.wo_webroot, self.app.pargs.site_name)
                    ]
                else:
                    Log.info(
                        self, "Site is not WordPress site, skipping "
                        "WordPress logs")

        reset_list = []
        for r_list in self.msg:
            reset_list = reset_list + glob.glob(r_list)

        # Clearing content of file
        for r_list in reset_list:
            Log.info(self, "Resetting file {file}".format(file=r_list))
            open(r_list, 'w').close()
Exemple #17
0
    def default(self):
        pargs = self.app.pargs
        if not pargs.site_name and not pargs.all:
            try:
                while not pargs.site_name:
                    pargs.site_name = (input('Enter site name : ').strip())
            except IOError as e:
                Log.debug(self, str(e))
                Log.error(self, 'could not input site name')

        pargs.site_name = pargs.site_name.strip()
        wo_domain = WODomain.validate(self, pargs.site_name)
        wo_www_domain = "www.{0}".format(wo_domain)
        wo_db_name = ''
        wo_prompt = ''
        wo_nginx_prompt = ''
        mark_db_delete_prompt = False
        mark_webroot_delete_prompt = False
        mark_db_deleted = False
        mark_webroot_deleted = False
        if not check_domain_exists(self, wo_domain):
            Log.error(self, "site {0} does not exist".format(wo_domain))

        if ((not pargs.db) and (not pargs.files) and (not pargs.all)):
            pargs.all = True

        if pargs.force:
            pargs.no_prompt = True

        # Gather information from wo-db for wo_domain
        check_site = getSiteInfo(self, wo_domain)
        wo_site_type = check_site.site_type
        wo_site_webroot = check_site.site_path
        if wo_site_webroot == 'deleted':
            mark_webroot_deleted = True
        if wo_site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
            wo_db_name = check_site.db_name
            wo_db_user = check_site.db_user
            if self.app.config.has_section('mysql'):
                wo_mysql_grant_host = self.app.config.get(
                    'mysql', 'grant-host')
            else:
                wo_mysql_grant_host = 'localhost'
            if wo_db_name == 'deleted':
                mark_db_deleted = True
            if pargs.all:
                pargs.db = True
                pargs.files = True
        else:
            if pargs.all:
                mark_db_deleted = True
                pargs.files = True

        # Delete website database
        if pargs.db:
            if wo_db_name != 'deleted' and wo_db_name != '':
                if not pargs.no_prompt:
                    wo_db_prompt = input('Are you sure, you want to delete'
                                         ' database [y/N]: ')
                else:
                    wo_db_prompt = 'Y'
                    mark_db_delete_prompt = True

                if wo_db_prompt == 'Y' or wo_db_prompt == 'y':
                    mark_db_delete_prompt = True
                    Log.info(
                        self, "Deleting Database, {0}, user {1}".format(
                            wo_db_name, wo_db_user))
                    deleteDB(self, wo_db_name, wo_db_user, wo_mysql_grant_host,
                             False)
                    updateSiteInfo(self,
                                   wo_domain,
                                   db_name='deleted',
                                   db_user='******',
                                   db_password='******')
                    mark_db_deleted = True
                    Log.info(self, "Deleted Database successfully.")
            else:
                mark_db_deleted = True
                Log.info(self,
                         "Does not seems to have database for this site.")

        # Delete webroot
        if pargs.files:
            if wo_site_webroot != 'deleted':
                if not pargs.no_prompt:
                    wo_web_prompt = input('Are you sure, you want to delete '
                                          'webroot [y/N]: ')
                else:
                    wo_web_prompt = 'Y'
                    mark_webroot_delete_prompt = True

                if wo_web_prompt == 'Y' or wo_web_prompt == 'y':
                    mark_webroot_delete_prompt = True
                    Log.info(self,
                             "Deleting Webroot, {0}".format(wo_site_webroot))
                    deleteWebRoot(self, wo_site_webroot)
                    updateSiteInfo(self, wo_domain, webroot='deleted')
                    mark_webroot_deleted = True
                    Log.info(self, "Deleted webroot successfully")
            else:
                mark_webroot_deleted = True
                Log.info(self, "Webroot seems to be already deleted")

        if not pargs.force:
            if (mark_webroot_deleted and mark_db_deleted):
                # TODO Delete nginx conf
                removeNginxConf(self, wo_domain)
                deleteSiteInfo(self, wo_domain)
                Log.info(self, "Deleted site {0}".format(wo_domain))
                # else:
                # Log.error(self, " site {0} does
                # not exists".format(wo_domain))
        else:
            if (mark_db_delete_prompt or mark_webroot_delete_prompt
                    or (mark_webroot_deleted and mark_db_deleted)):
                # TODO Delete nginx conf
                removeNginxConf(self, wo_domain)
                deleteSiteInfo(self, wo_domain)
                Log.info(self, "Deleted site {0}".format(wo_domain))
Exemple #18
0
    def default(self):
        """Default function of log show"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp)
                and (not self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php/7.2/slow.log', 'a').close()
            open('/var/log/php7.2-fpm.log', 'a').close()
            self.msg = self.msg + [
                '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log'
            ]
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if WOVar.wo_mysql_host == "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(
                    self, "Remote MySQL found, WordOps does not support"
                    "remote MySQL servers or log files")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(WOVar.wo_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + [
                    "{0}/{1}/logs/access.log".format(WOVar.wo_webroot,
                                                     self.app.pargs.site_name)
                ]
            if self.app.pargs.nginx:
                self.msg = self.msg + [
                    "{0}/{1}/logs/error.log".format(WOVar.wo_webroot,
                                                    self.app.pargs.site_name)
                ]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile(
                            '{0}/logs/debug.log'.format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log".format(
                                webroot),
                                 encoding='utf-8',
                                 mode='a').close()
                            WOShellExec.cmd_exec(
                                self, "chown {1}: {0}/htdocs/"
                                "wp-content/debug.log"
                                "".format(webroot, WOVar.wo_php_user))
                    # create symbolic link for debug log
                    WOFileUtils.create_symlink(self, [
                        "{0}/htdocs/wp-content/"
                        "debug.log".format(webroot),
                        '{0}/logs/debug.log'.format(webroot)
                    ])

                    self.msg = self.msg + [
                        "{0}/{1}/logs/debug.log".format(
                            WOVar.wo_webroot, self.app.pargs.site_name)
                    ]
                else:
                    Log.info(
                        self, "Site is not WordPress site, skipping "
                        "WordPress logs")

        watch_list = []
        for w_list in self.msg:
            watch_list = watch_list + glob.glob(w_list)

        logwatch(self, watch_list)
Exemple #19
0
    def purge(self):
        """Start purging of packages"""
        apt_packages = []
        packages = []
        pargs = self.app.pargs
        # Default action for stack purge
        if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx)
                and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli)
                and (not pargs.phpmyadmin) and (not pargs.composer)
                and (not pargs.netdata) and (not pargs.dashboard)
                and (not pargs.fail2ban) and (not pargs.security)
                and (not pargs.mysqlclient) and (not pargs.mysqltuner) and
            (not pargs.adminer) and (not pargs.utils) and (not pargs.redis)
                and (not pargs.proftpd) and (not pargs.extplorer)
                and (not pargs.clamav) and (not pargs.phpredisadmin)
                and (not pargs.sendmail) and (not pargs.php73)):
            pargs.web = True
            pargs.admin = True
            pargs.security = True

        if pargs.all:
            pargs.web = True
            pargs.admin = True
            pargs.php73 = True
            pargs.fail2ban = True
            pargs.proftpd = True
            pargs.utils = True
            pargs.redis = True
            packages = packages + ['/var/www/22222/htdocs/*']

        if pargs.web:
            pargs.nginx = True
            pargs.php = True
            pargs.mysql = True
            pargs.wpcli = True
            pargs.sendmail = True

        if pargs.admin:
            pargs.utils = True
            pargs.composer = True
            pargs.netdata = True
            pargs.mysqltuner = True

        if pargs.security:
            pargs.fail2ban = True
            pargs.clamav = True

        # NGINX
        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                Log.debug(self, "Purge apt_packages variable of Nginx")
                apt_packages = apt_packages + WOVariables.wo_nginx

        # PHP
        if pargs.php:
            Log.debug(self, "Purge apt_packages variable PHP")
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                if not (WOAptGet.is_installed(self, 'php7.3-fpm')):
                    apt_packages = apt_packages + WOVariables.wo_php + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php

        # PHP 7.3
        if pargs.php73:
            Log.debug(self, "Removing apt_packages variable of PHP 7.3")
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
                    apt_packages = apt_packages + WOVariables.wo_php73 + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php73

        # REDIS
        if pargs.redis:
            Log.debug(self, "Remove apt_packages variable of Redis")
            apt_packages = apt_packages + WOVariables.wo_redis

        # MariaDB
        if pargs.mysql:
            Log.debug(self, "Removing apt_packages variable of MySQL")
            apt_packages = apt_packages + WOVariables.wo_mysql

        # mysqlclient
        if pargs.mysqlclient:
            Log.debug(self, "Removing apt_packages variable "
                      "for MySQL Client")
            if WOShellExec.cmd_exec(self, "mysqladmin ping"):
                apt_packages = apt_packages + WOVariables.wo_mysql_client

        # fail2ban
        if pargs.fail2ban:
            if WOAptGet.is_installed(self, 'fail2ban'):
                Log.debug(self, "Remove apt_packages variable of Fail2ban")
                apt_packages = apt_packages + WOVariables.wo_fail2ban

        # ClamAV
        if pargs.clamav:
            Log.debug(self, "Setting apt_packages variable for ClamAV")
            if WOAptGet.is_installed(self, 'clamav'):
                apt_packages = apt_packages + WOVariables.wo_clamav

        # sendmail
        if pargs.sendmail:
            Log.debug(self, "Setting apt_packages variable for Sendmail")
            if WOAptGet.is_installed(self, 'sendmail'):
                apt_packages = apt_packages + ["sendmail"]

        # proftpd
        if pargs.proftpd:
            if WOAptGet.is_installed(self, 'proftpd-basic'):
                Log.debug(self, "Purge apt_packages variable for ProFTPd")
                apt_packages = apt_packages + ["proftpd-basic"]

        # WP-CLI
        if pargs.wpcli:
            Log.debug(self, "Purge package variable WPCLI")
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + ['/usr/local/bin/wp']

        # PHPMYADMIN
        if pargs.phpmyadmin:
            packages = packages + [
                '{0}22222/htdocs/db/pma'.format(WOVariables.wo_webroot)
            ]
            Log.debug(self, "Purge package variable phpMyAdmin")

        # Composer
        if pargs.composer:
            Log.debug(self, "Removing package variable of Composer ")
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + ['/usr/local/bin/composer']

        if pargs.mysqltuner:
            Log.debug(self, "Removing packages for MySQLTuner ")
            packages = packages + ['/usr/bin/mysqltuner']

        # PHPREDISADMIN
        if pargs.phpredisadmin:
            Log.debug(self, "Removing package variable of phpRedisAdmin ")
            if os.path.isdir('{0}22222/htdocs/cache/redis'.format(
                    WOVariables.wo_webroot)):
                packages = packages + [
                    '{0}22222/htdocs/'
                    'cache/redis'.format(WOVariables.wo_webroot)
                ]
        # Adminer
        if pargs.adminer:
            Log.debug(self, "Purge  package variable Adminer")
            packages = packages + [
                '{0}22222/htdocs/db/adminer'.format(WOVariables.wo_webroot)
            ]
        # utils
        if pargs.utils:
            Log.debug(self, "Purge package variable utils")
            packages = packages + [
                '{0}22222/htdocs/php/webgrind/'.format(WOVariables.wo_webroot),
                '{0}22222/htdocs/cache/opcache'.format(
                    WOVariables.wo_webroot), '{0}22222/htdocs/cache/nginx/'
                'clean.php'.format(
                    WOVariables.wo_webroot), '/usr/bin/pt-query-advisor',
                '{0}22222/htdocs/db/anemometer'.format(WOVariables.wo_webroot)
            ]

        if pargs.netdata:
            Log.debug(self, "Removing Netdata")
            if os.path.isfile('/opt/netdata/usr/'
                              'libexec/netdata/netdata-uninstaller.sh'):
                packages = packages + ['/var/lib/wo/tmp/kickstart.sh']

        if pargs.dashboard:
            Log.debug(self, "Removing Wo-Dashboard")
            packages = packages + [
                '{0}22222/htdocs/assets/'.format(WOVariables.wo_webroot),
                '{0}22222/htdocs/index.php'.format(WOVariables.wo_webroot)
            ]

        if (packages) or (apt_packages):
            if (not pargs.force):
                start_purge = input('Are you sure you to want to'
                                    ' purge stacks from this server ?'
                                    '\nPackage configuration and data '
                                    'will not remain'
                                    ' on this server after this operation.\n'
                                    'Purge stacks [y/N]')
                if start_purge != "Y" and start_purge != "y":
                    Log.error(self, "Not starting stack purge")

            if (set(["nginx-custom"]).issubset(set(apt_packages))):
                WOService.stop_service(self, 'nginx')

            if (set(["fail2ban"]).issubset(set(apt_packages))):
                WOService.stop_service(self, 'fail2ban')

            if (set(WOVariables.wo_mysql).issubset(set(apt_packages))):
                WOMysql.backupAll(self)
                WOService.stop_service(self, 'mysql')

            # Netdata uninstaller
            if (set(['/var/lib/wo/tmp/'
                     'kickstart.sh']).issubset(set(packages))):
                if WOVariables.wo_distro == 'Raspbian':
                    WOShellExec.cmd_exec(self, "bash /usr/"
                                         "libexec/netdata/netdata-"
                                         "uninstaller.sh -y -f",
                                         errormsg='',
                                         log=False)
                else:
                    WOShellExec.cmd_exec(
                        self, "bash /opt/netdata/usr/"
                        "libexec/netdata/netdata-"
                        "uninstaller.sh -y -f")

            if (apt_packages):
                Log.info(self, "Purging apt packages, please wait...")
                WOAptGet.remove(self, apt_packages, purge=True)
                WOAptGet.auto_remove(self)

            if (packages):
                Log.info(self, "Purging packages, please wait...")
                WOFileUtils.remove(self, packages)
                WOAptGet.auto_remove(self)

            Log.info(self, "Successfully purged packages")
Exemple #20
0
    def debug_wp(self):
        """Start/Stop WordPress debug"""
        if (self.app.pargs.wp == 'on' and self.app.pargs.site_name):
            wp_config = ("{0}/{1}/wp-config.php".format(
                WOVariables.wo_webroot, self.app.pargs.site_name))
            webroot = "{0}{1}".format(WOVariables.wo_webroot,
                                      self.app.pargs.site_name)
            # Check wp-config.php file into htdocs folder
            if not os.path.isfile(wp_config):
                wp_config = ("{0}/{1}/htdocs/wp-config.php".format(
                    WOVariables.wo_webroot, self.app.pargs.site_name))
            if os.path.isfile(wp_config):
                if not WOShellExec.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()
                    WOShellExec.cmd_exec(
                        self, "chown {1}: {0}/htdocs/wp-"
                        "content/debug.log"
                        "".format(webroot, WOVariables.wo_php_user))
                    WOShellExec.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))
                    WOShellExec.cmd_exec(
                        self, "cd {0}/htdocs/ && wp"
                        " plugin --allow-root install "
                        "developer query-monitor".format(webroot))
                    WOShellExec.cmd_exec(
                        self, "chown -R {1}: {0}/htdocs/"
                        "wp-content/plugins".format(webroot,
                                                    WOVariables.wo_php_user))

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

            else:
                Log.info(
                    self, "Unable to find wp-config.php for site: {0}".format(
                        self.app.pargs.site_name))

        elif (self.app.pargs.wp == 'off' and self.app.pargs.site_name):
            wp_config = ("{0}{1}/wp-config.php".format(
                WOVariables.wo_webroot, self.app.pargs.site_name))
            webroot = "{0}{1}".format(WOVariables.wo_webroot,
                                      self.app.pargs.site_name)
            # Check wp-config.php file into htdocs folder
            if not os.path.isfile(wp_config):
                wp_config = ("{0}/{1}/htdocs/wp-config.php".format(
                    WOVariables.wo_webroot, self.app.pargs.site_name))
            if os.path.isfile(wp_config):
                if WOShellExec.cmd_exec(
                        self, "grep \"\'WP_DEBUG\'\" {0} | "
                        "grep true".format(wp_config)):
                    Log.info(self, "Disabling WordPress debug")
                    WOShellExec.cmd_exec(
                        self, "sed -i \"s/define(\'WP_DEBUG\'"
                        ", true);/define(\'WP_DEBUG\', "
                        "false);/\" {0}".format(wp_config))
                    WOShellExec.cmd_exec(
                        self, "sed -i \"/define(\'"
                        "WP_DEBUG_DISPLAY\', false);/d\" {0}".format(
                            wp_config))
                    WOShellExec.cmd_exec(
                        self, "sed -i \"/define(\'"
                        "WP_DEBUG_LOG\', true);/d\" {0}".format(wp_config))
                    WOShellExec.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")
Exemple #21
0
    def info_php(self):
        """Display PHP information"""
        version = os.popen("/usr/bin/php7.2 -v 2>/dev/null | "
                           "head -n1 | cut -d' ' -f2 |"
                           " cut -d'+' -f1 | tr -d '\n'").read
        config = configparser.ConfigParser()
        config.read('/etc/{0}/fpm/php.ini'.format("php/7.2"))
        expose_php = config['PHP']['expose_php']
        memory_limit = config['PHP']['memory_limit']
        post_max_size = config['PHP']['post_max_size']
        upload_max_filesize = config['PHP']['upload_max_filesize']
        max_execution_time = config['PHP']['max_execution_time']

        if os.path.exists('/etc/php/7.2/fpm/pool.d/www.conf'):
            config.read('/etc/php/7.2/fpm/pool.d/www.conf')
        else:
            Log.error(self, 'php-fpm pool config not found')
        if config.has_section('www'):
            wconfig = config['www']
        elif config.has_section('www-php72'):
            wconfig = config['www-php72']
        else:
            Log.error(self, 'Unable to parse configuration')
        www_listen = wconfig['listen']
        www_ping_path = wconfig['ping.path']
        www_pm_status_path = wconfig['pm.status_path']
        www_pm = wconfig['pm']
        www_pm_max_requests = wconfig['pm.max_requests']
        www_pm_max_children = wconfig['pm.max_children']
        www_pm_start_servers = wconfig['pm.start_servers']
        www_pm_min_spare_servers = wconfig['pm.min_spare_servers']
        www_pm_max_spare_servers = wconfig['pm.max_spare_servers']
        www_request_terminate_time = (wconfig['request_terminate_timeout'])
        try:
            www_xdebug = (wconfig['php_admin_flag[xdebug.profiler_enable'
                                  '_trigger]'])
        except Exception as e:
            Log.debug(self, "{0}".format(e))
            www_xdebug = 'off'

        config.read('/etc/{0}/fpm/pool.d/debug.conf'.format("php/7.2"))
        debug_listen = config['debug']['listen']
        debug_ping_path = config['debug']['ping.path']
        debug_pm_status_path = config['debug']['pm.status_path']
        debug_pm = config['debug']['pm']
        debug_pm_max_requests = config['debug']['pm.max_requests']
        debug_pm_max_children = config['debug']['pm.max_children']
        debug_pm_start_servers = config['debug']['pm.start_servers']
        debug_pm_min_spare_servers = config['debug']['pm.min_spare_servers']
        debug_pm_max_spare_servers = config['debug']['pm.max_spare_servers']
        debug_request_terminate = (
            config['debug']['request_terminate_timeout'])
        try:
            debug_xdebug = (config['debug']['php_admin_flag[xdebug.profiler_'
                                            'enable_trigger]'])
        except Exception as e:
            Log.debug(self, "{0}".format(e))
            debug_xdebug = 'off'

        data = dict(version=version,
                    expose_php=expose_php,
                    memory_limit=memory_limit,
                    post_max_size=post_max_size,
                    upload_max_filesize=upload_max_filesize,
                    max_execution_time=max_execution_time,
                    www_listen=www_listen,
                    www_ping_path=www_ping_path,
                    www_pm_status_path=www_pm_status_path,
                    www_pm=www_pm,
                    www_pm_max_requests=www_pm_max_requests,
                    www_pm_max_children=www_pm_max_children,
                    www_pm_start_servers=www_pm_start_servers,
                    www_pm_min_spare_servers=www_pm_min_spare_servers,
                    www_pm_max_spare_servers=www_pm_max_spare_servers,
                    www_request_terminate_timeout=www_request_terminate_time,
                    www_xdebug_profiler_enable_trigger=www_xdebug,
                    debug_listen=debug_listen,
                    debug_ping_path=debug_ping_path,
                    debug_pm_status_path=debug_pm_status_path,
                    debug_pm=debug_pm,
                    debug_pm_max_requests=debug_pm_max_requests,
                    debug_pm_max_children=debug_pm_max_children,
                    debug_pm_start_servers=debug_pm_start_servers,
                    debug_pm_min_spare_servers=debug_pm_min_spare_servers,
                    debug_pm_max_spare_servers=debug_pm_max_spare_servers,
                    debug_request_terminate_timeout=debug_request_terminate,
                    debug_xdebug_profiler_enable_trigger=debug_xdebug)
        self.app.render((data), 'info_php.mustache')
Exemple #22
0
    def default(self):
        # All package update
        apt_packages = []
        packages = []

        if ((not self.app.pargs.web) and (not self.app.pargs.nginx) and
            (not self.app.pargs.php) and (not self.app.pargs.mysql) and
            (not self.app.pargs.all) and (not self.app.pargs.wpcli) and
            (not self.app.pargs.netdata) and (not self.app.pargs.composer) and
            (not self.app.pargs.phpmyadmin) and
                (not self.app.pargs.redis)):
            self.app.pargs.web = True

        if self.app.pargs.all:
            self.app.pargs.web = True

        if self.app.pargs.web:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                self.app.pargs.nginx = True
            else:
                Log.info(self, "Nginx is not already installed")
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.wpcli = True
            self.app.pargs.netdata = True

        if self.app.pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVariables.wo_nginx
            else:
                Log.info(self, "Nginx Stable is not already installed")

        if self.app.pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                if not WOAptGet.is_installed(self, 'php7.3-fpm'):
                    apt_packages = apt_packages + WOVariables.wo_php + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php
            else:
                Log.info(self, "PHP 7.2 is not installed")

        if self.app.pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                apt_packages = apt_packages + WOVariables.wo_mysql
            else:
                Log.info(self, "MariaDB is not installed")

        if self.app.pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                apt_packages = apt_packages + WOVariables.wo_redis
            else:
                Log.info(self, "Redis is not installed")

        if self.app.pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [["https://github.com/wp-cli/wp-cli/"
                                        "releases/download/v{0}/"
                                        "wp-cli-{0}.phar"
                                        "".format(WOVariables.wo_wp_cli),
                                        "/usr/local/bin/wp",
                                        "WP-CLI"]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        if self.app.pargs.netdata:
            if os.path.isdir('/opt/netdata'):
                packages = packages + [['https://my-netdata.io/'
                                        'kickstart-static64.sh',
                                        '/var/lib/wo/tmp/kickstart.sh',
                                        'Netdata']]
        if self.app.pargs.phpmyadmin:
            if os.path.isdir('/var/www/22222/htdocs/db/pma'):
                packages = packages + \
                    [["https://files.phpmyadmin.net"
                      "/phpMyAdmin/{0}/"
                      "phpMyAdmin-{0}-"
                      "all-languages"
                      ".tar.gz".format(WOVariables.wo_phpmyadmin),
                      "/var/lib/wo/tmp/pma.tar.gz",
                      "PHPMyAdmin"]]
            else:
                Log.error(self, "phpMyAdmin isn't installed")

        if self.app.pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + [["https://getcomposer.org/installer",
                                        "/var/lib/wo/tmp/composer-install",
                                        "Composer"]]
            else:
                Log.error(self, "Composer isn't installed")

        if len(packages) or len(apt_packages):

            Log.info(self, "During package 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 package update")

            Log.info(self, "Updating packages, please wait...")
            if len(apt_packages):
                # apt-get update
                WOAptGet.update(self)
                # Update packages
                WOAptGet.install(self, apt_packages)

                # Post Actions after package updates
                if (set(WOVariables.wo_nginx).issubset(set(apt_packages))):
                    WOService.restart_service(self, 'nginx')
                if set(WOVariables.wo_php).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'php7.2-fpm')
                if set(WOVariables.wo_mysql).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'mysql')
                if set(WOVariables.wo_redis).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'redis-server')

            if len(packages):
                if self.app.pargs.wpcli:
                    WOFileUtils.remove(self, ['/usr/local/bin/wp'])

                if self.app.pargs.netdata:
                    WOFileUtils.remove(self, ['/var/lib/wo/tmp/kickstart.sh'])

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if self.app.pargs.wpcli:
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

                if self.app.pargs.netdata:
                    Log.info(self, "Upgrading Netdata, please wait...")
                    WOShellExec.cmd_exec(self, "/bin/bash /var/lib/wo/tmp/"
                                         "kickstart.sh "
                                         "--dont-wait")

                if self.app.pargs.composer:
                    Log.info(self, "Upgrading Composer, please wait...")
                    WOShellExec.cmd_exec(self, "php -q /var/lib/wo"
                                         "/tmp/composer-install "
                                         "--install-dir=/var/lib/wo/tmp/")
                    shutil.copyfile('/var/lib/wo/tmp/composer.phar',
                                    '/usr/local/bin/composer')
                    WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)

                if self.app.pargs.phpmyadmin:
                    Log.info(self, "Upgrading phpMyAdmin, please wait...")
                    WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz',
                                      '/var/lib/wo/tmp/')
                    shutil.copyfile(('{0}22222/htdocs/db/pma'
                                     '/config.inc.php'
                                     .format(WOVariables.wo_webroot)),
                                    ('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                     '-all-languages/config.inc.php'
                                     .format(WOVariables.wo_phpmyadmin))
                                    )
                    WOFileUtils.rm(self, '{0}22222/htdocs/db/pma'
                                   .format(WOVariables.wo_webroot))
                    shutil.move('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                '-all-languages/'
                                .format(WOVariables.wo_phpmyadmin),
                                '{0}22222/htdocs/db/pma/'
                                .format(WOVariables.wo_webroot))

            Log.info(self, "Successfully updated packages")
        else:
            self.app.args.print_help()
Exemple #23
0
    def purge(self):
        """Start purging of packages"""
        apt_packages = []
        packages = []
        pargs = self.app.pargs
        # Default action for stack purge
        if ((not pargs.web) and (not pargs.admin) and
            (not pargs.nginx) and (not pargs.php) and
            (not pargs.mysql) and (not pargs.wpcli) and
            (not pargs.phpmyadmin) and (not pargs.composer) and
                (not pargs.netdata) and (not pargs.dashboard) and
                (not pargs.fail2ban) and (not pargs.security) and
                (not pargs.mysqlclient) and (not pargs.mysqltuner) and
                (not pargs.adminer) and (not pargs.utils) and
                (not pargs.redis) and (not pargs.proftpd) and
                (not pargs.extplorer) and (not pargs.clamav) and
                (not pargs.cheat) and
                (not pargs.ufw) and (not pargs.ngxblocker) and
                (not pargs.phpredisadmin) and (not pargs.sendmail) and
                (not pargs.php73)):
            pargs.web = True
            pargs.admin = True
            pargs.security = True

        if pargs.all:
            pargs.web = True
            pargs.admin = True
            pargs.php73 = True
            pargs.fail2ban = True
            pargs.proftpd = True
            pargs.utils = True
            pargs.redis = True
            packages = packages + ['/var/www/22222/htdocs']

        if pargs.web:
            pargs.nginx = True
            pargs.php = True
            pargs.mysql = True
            pargs.wpcli = True
            pargs.sendmail = True

        if pargs.admin:
            pargs.utils = True
            pargs.composer = True
            pargs.netdata = True
            pargs.mysqltuner = True
            pargs.cheat = True

        if pargs.security:
            pargs.fail2ban = True
            pargs.clamav = True
            pargs.ufw = True
            pargs.ngxblocker = True

        # NGINX
        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                Log.debug(self, "Add Nginx to apt_packages list")
                apt_packages = apt_packages + WOVar.wo_nginx
            else:
                Log.info(self, "Nginx is not installed")

        # PHP
        if pargs.php:
            Log.debug(self, "Add PHP to apt_packages list")
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                if not (WOAptGet.is_installed(self, 'php7.3-fpm')):
                    apt_packages = apt_packages + WOVar.wo_php + \
                        WOVar.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVar.wo_php

        # PHP 7.3
        if pargs.php73:
            Log.debug(self, "Removing apt_packages variable of PHP 7.3")
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
                    apt_packages = apt_packages + WOVar.wo_php73 + \
                        WOVar.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVar.wo_php73

        # REDIS
        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                Log.debug(self, "Remove apt_packages variable of Redis")
                apt_packages = apt_packages + ["redis-server"]
            else:
                Log.info(self, "Redis is not installed")

        # MariaDB
        if pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                Log.debug(self, "Add MySQL to apt_packages list")
                apt_packages = apt_packages + ['mariadb-server',
                                               'mysql-common',
                                               'mariadb-client']
                packages = packages + ['/etc/mysql', '/var/lib/mysql']
            else:
                Log.info(self, "MariaDB is not installed")

        # mysqlclient
        if pargs.mysqlclient:
            if WOShellExec.cmd_exec(self, "mysqladmin ping"):
                Log.debug(self, "Add MySQL client to apt_packages list")
                apt_packages = apt_packages + WOVar.wo_mysql_client

        # fail2ban
        if pargs.fail2ban:
            if WOAptGet.is_installed(self, 'fail2ban'):
                Log.debug(self, "Add Fail2ban to apt_packages list")
                apt_packages = apt_packages + WOVar.wo_fail2ban

        # ClamAV
        if pargs.clamav:
            if WOAptGet.is_installed(self, 'clamav'):
                Log.debug(self, "Add ClamAV to apt_packages list")
                apt_packages = apt_packages + WOVar.wo_clamav

        # UFW
        if pargs.ufw:
            if WOAptGet.is_installed(self, 'ufw'):
                Log.debug(self, "Add UFW to apt_packages list")
                apt_packages = apt_packages + ["ufw"]

        # sendmail
        if pargs.sendmail:
            if WOAptGet.is_installed(self, 'sendmail'):
                Log.debug(self, "Add sendmail to apt_packages list")
                apt_packages = apt_packages + ["sendmail"]

        # proftpd
        if pargs.proftpd:
            if WOAptGet.is_installed(self, 'proftpd-basic'):
                Log.debug(self, "Add Proftpd to apt_packages list")
                apt_packages = apt_packages + ["proftpd-basic"]

        # WP-CLI
        if pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                Log.debug(self, "Purge package variable WPCLI")
                packages = packages + ['/usr/local/bin/wp']

        # PHPMYADMIN
        if pargs.phpmyadmin:
            if os.path.isdir('{0}22222/htdocs/db/pma'
                             .format(WOVar.wo_webroot)):
                Log.debug(self, "Removing package of phpMyAdmin ")
                packages = packages + ['{0}22222/htdocs/db/pma'
                                       .format(WOVar.wo_webroot)]

        # Composer
        if pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                Log.debug(self, "Removing package variable of Composer ")
                packages = packages + ['/usr/local/bin/composer']

        # MySQLTuner
        if pargs.mysqltuner:
            if os.path.isfile('/usr/bin/mysqltuner'):
                Log.debug(self, "Removing packages for MySQLTuner ")
                packages = packages + ['/usr/bin/mysqltuner']

        # cheat.sh
        if pargs.cheat:
            if os.path.isfile('/usr/local/bin/cht.sh'):
                Log.debug(self, "Removing packages for cheat.sh ")
                packages = packages + [
                    '/usr/local/bin/cht.sh', '/usr/local/bin/cheat',
                    '/etc/bash_completion.d/cht.sh']

        # PHPREDISADMIN
        if pargs.phpredisadmin:
            Log.debug(self, "Removing package variable of phpRedisAdmin ")
            if os.path.isdir('{0}22222/htdocs/cache/redis'
                             .format(WOVar.wo_webroot)):
                packages = packages + ['{0}22222/htdocs/'
                                       'cache/redis'
                                       .format(WOVar.wo_webroot)]
        # ADMINER
        if pargs.adminer:
            if os.path.isdir('{0}22222/htdocs/db/adminer'
                             .format(WOVar.wo_webroot)):
                Log.debug(self, "Removing package variable of Adminer ")
                packages = packages + ['{0}22222/htdocs/db/adminer'
                                       .format(WOVar.wo_webroot)]
        # utils
        if pargs.utils:
            Log.debug(self, "Purge package variable utils")
            packages = packages + ['{0}22222/htdocs/php/webgrind/'
                                   .format(WOVar.wo_webroot),
                                   '{0}22222/htdocs/cache/opcache'
                                   .format(WOVar.wo_webroot),
                                   '{0}22222/htdocs/cache/nginx/'
                                   'clean.php'.format(WOVar.wo_webroot),
                                   '/usr/bin/pt-query-advisor',
                                   '{0}22222/htdocs/db/anemometer'
                                   .format(WOVar.wo_webroot)
                                   ]

        if pargs.netdata:
            Log.debug(self, "Removing Netdata")
            if os.path.isfile('/opt/netdata/usr/'
                              'libexec/netdata/netdata-uninstaller.sh'):
                packages = packages + ['/var/lib/wo/tmp/kickstart.sh']

        # wordops dashboard
        if pargs.dashboard:
            Log.debug(self, "Removing Wo-Dashboard")
            packages = packages + ['{0}22222/htdocs/assets/'
                                   .format(WOVar.wo_webroot),
                                   '{0}22222/htdocs/index.php'
                                   .format(WOVar.wo_webroot)]

        # ngxblocker
        if pargs.ngxblocker:
            if os.path.isfile('/usr/local/sbin/setup-ngxblocker'):
                packages = packages + [
                    '/usr/local/sbin/setup-ngxblocker',
                    '/usr/local/sbin/install-ngxblocker',
                    '/usr/local/sbin/update-ngxblocker',
                    '/etc/nginx/conf.d/globalblacklist.conf',
                    '/etc/nginx/conf.d/botblocker-nginx-settings.conf',
                    '/etc/nginx/bots.d']

        if (packages) or (apt_packages):
            if (not pargs.force):
                start_purge = input('Are you sure you to want to'
                                    ' purge stacks from this server ?'
                                    '\nPackage configuration and data '
                                    'will not remain'
                                    ' on this server after this operation.\n'
                                    'Purge stacks [y/N]')
                if start_purge != "Y" and start_purge != "y":
                    Log.error(self, "Not starting stack purge")

            if (set(["nginx-custom"]).issubset(set(apt_packages))):
                WOService.stop_service(self, 'nginx')

            if (set(["fail2ban"]).issubset(set(apt_packages))):
                WOService.stop_service(self, 'fail2ban')

            if (set(["mariadb-server"]).issubset(set(apt_packages))):
                if (os.path.isfile('/usr/bin/mysql') and
                        os.path.isdir('/var/lib/mysql')):
                    WOMysql.backupAll(self)
                    WOService.stop_service(self, 'mysql')

            # Netdata uninstaller
            if (set(['/var/lib/wo/tmp/'
                     'kickstart.sh']).issubset(set(packages))):
                if WOVar.wo_distro == 'Raspbian':
                    WOShellExec.cmd_exec(self, "bash /usr/"
                                         "libexec/netdata/netdata-"
                                         "uninstaller.sh -y -f",
                                         errormsg='', log=False)
                else:
                    WOShellExec.cmd_exec(self, "bash /opt/netdata/usr/"
                                         "libexec/netdata/netdata-"
                                         "uninstaller.sh -y -f")

            if (apt_packages):
                Log.wait(self, "Purging APT Packages        ")
                WOAptGet.remove(self, apt_packages, purge=True)
                WOAptGet.auto_remove(self)
                Log.valide(self, "Purging APT Packages        ")

            if (packages):
                Log.wait(self, "Purging Packages            ")
                WOFileUtils.remove(self, packages)
                Log.valide(self, "Purging Packages            ")
            Log.info(self, "Successfully purged packages")
Exemple #24
0
 def clean_fastcgi(self):
     if (os.path.isdir("/var/run/nginx-cache")):
         Log.info(self, "Cleaning NGINX FastCGI cache")
         WOShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*")
     else:
         Log.error(self, "Unable to clean FastCGI cache", False)
Exemple #25
0
    def default(self):
        filename = "woupdate" + time.strftime("%Y%m%d-%H%M%S")

        if self.app.pargs.travis:
            WODownload.download(self, [[
                "https://raw.githubusercontent.com/"
                "WordOps/WordOps/updating-configuration/install",
                "/tmp/{0}".format(filename), "update script"
            ]])
            try:
                Log.info(self, "updating WordOps, please wait...")
                os.system("bash /tmp/{0} --travis --force".format(filename))
            except OSError as e:
                Log.debug(self, str(e))
                Log.error(self, "WordOps update failed !")
        else:
            WODownload.download(self, [[
                "https://raw.githubusercontent.com/"
                "WordOps/WordOps/master/install", "/tmp/{0}".format(filename),
                "update script"
            ]])
            if self.app.pargs.force:
                try:
                    Log.info(self, "updating WordOps, please wait...")
                    os.system("bash /tmp/{0} --force".format(filename))
                except OSError as e:
                    Log.debug(self, str(e))
                    Log.error(self, "WordOps update failed !")
                except Exception as e:
                    Log.debug(self, str(e))
                    Log.error(self, "WordOps update failed !")
            elif self.app.pargs.preserve:
                try:
                    Log.info(self, "updating WordOps, please wait...")
                    os.system("bash /tmp/{0} --preserve".format(filename))
                except OSError as e:
                    Log.debug(self, str(e))
                    Log.error(self, "WordOps update failed !")
                except Exception as e:
                    Log.debug(self, str(e))
                    Log.error(self, "WordOps update failed !")
            else:
                try:
                    Log.info(self, "updating WordOps, please wait...")
                    os.system("bash /tmp/{0}".format(filename))
                except OSError as e:
                    Log.debug(self, str(e))
                    Log.error(self, "WordOps update failed !")
                except Exception as e:
                    Log.debug(self, str(e))
                    Log.error(self, "WordOps update failed !")
Exemple #26
0
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,
                   hhvm=None,
                   php_version=''):
    """updates site record in database"""
    try:
        q = SiteDB.query.filter(SiteDB.sitename == site).first()
    except Exception as e:
        Log.debug(self, "{0}".format(e))
        Log.error(self, "Unable to query database for site info")

    if not q:
        Log.error(self, "{0} does not exist in database".format(site))

    # Check if new record matches old if not then only update database
    if stype and q.site_type != stype:
        q.site_type = stype

    if cache and q.cache_type != cache:
        q.cache_type = cache

    if q.is_enabled != enabled:
        q.is_enabled = enabled

    if 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

    if (hhvm is not None) and (q.is_hhvm is not hhvm):
        q.is_hhvm = hhvm

    if php_version and q.php_version != php_version:
        q.php_version = php_version

    try:
        q.created_on = func.now()
        db_session.commit()
    except Exception as e:
        Log.debug(self, "{0}".format(e))
        Log.error(self, "Unable to update site info in application database.")
Exemple #27
0
 def export_cert(self):
     """Export acme.sh csv certificate list"""
     if not WOShellExec.cmd_exec(
             self, "{0} ".format(WOAcme.wo_acme_exec) +
             "--list --listraw > /var/lib/wo/cert.csv"):
         Log.error(self, "Unable to export certs list")