def check_dns(self, acme_domains): """Check if a list of domains point to the server IP""" server_ip = requests.get('https://v4.wordops.eu/').text for domain in acme_domains: url = ( "https://cloudflare-dns.com/dns-query?name={0}&type=A" .format(domain)) headers = { 'accept': 'application/dns-json' } try: response = requests.get(url, headers=headers).json() domain_ip = response["Answer"][0]['data'] except requests.RequestException: Log.error(self, 'Resolving domain IP failed') if(not domain_ip == server_ip): Log.warn( self, "{0}".format(domain) + " point to the IP {0}".format(domain_ip) + " but your server IP is {0}.".format(server_ip) + "\nUse the flag --force to bypass this check.") Log.error( self, "You have to set the " "proper DNS record for your domain", False) return False Log.debug(self, "DNS record are properly set") return True
def signal_handler(self, signal, frame): """Handle Ctrl+c hevent for -i option of debug""" self.start = False if self.app.pargs.nginx: self.app.pargs.nginx = 'off' self.debug_nginx() if self.app.pargs.php: self.app.pargs.php = 'off' self.debug_php() if self.app.pargs.php73: self.app.pargs.php73 = 'off' self.debug_php73() if self.app.pargs.fpm: self.app.pargs.fpm = 'off' self.debug_fpm() if self.app.pargs.fpm73: self.app.pargs.fpm73 = 'off' self.debug_fpm73() if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if WOVariables.wo_mysql_host is "localhost": self.app.pargs.mysql = 'off' self.debug_mysql() else: Log.warn( self, "Remote MySQL found, WordOps does not support " "debugging remote servers") if self.app.pargs.wp: self.app.pargs.wp = 'off' self.debug_wp() if self.app.pargs.rewrite: self.app.pargs.rewrite = 'off' self.debug_rewrite() # Reload Nginx if self.trigger_nginx: WOService.reload_service(self, 'nginx') # Reload PHP if self.trigger_php: if WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic': if WOAptGet.is_installed(self, 'php7.2-fpm'): WOService.reload_service(self, 'php7.2-fpm') if WOAptGet.is_installed(self, 'php7.3-fpm'): WOService.reload_service(self, 'php7.3-fpm') else: WOService.reload_service(self, 'php7.2-fpm') self.app.close(0)
def check_dns(self, acme_domains): """Check if a list of domains point to the server IP""" server_ip = requests.get('http://v4.wordops.eu/').text for domain in acme_domains: domain_ip = requests.get( 'http://v4.wordops.eu/dns/{0}/'.format(domain)).text if (not domain_ip == server_ip): Log.warn( self, "{0} is not pointing to your server IP".format(domain)) Log.error(self, "You have to add the " "proper DNS record", False) return False else: Log.debug(self, "DNS record are properly set") return True
def archivedcertificatehandle(self, domain, acme_domains): Log.warn( self, "You already have an existing certificate " "for the domain requested.\n" "(ref: {0}/" "{1}_ecc/{1}.conf)".format(WOVar.wo_ssl_archive, domain) + "\nPlease select an option from below?" "\n\t1: Reinstall existing certificate" "\n\t2: Issue a new certificate to replace " "the current one (limit ~5 per 7 days)" "") check_prompt = input( "\nType the appropriate number [1-2] or any other key to cancel: ") if not os.path.isfile("{0}/{1}/fullchain.pem".format( WOVar.wo_ssl_live, domain)): Log.debug( self, "{0}/{1}/fullchain.pem file is missing.".format( WOVar.wo_ssl_live, domain)) check_prompt = "2" if check_prompt == "1": Log.info(self, "Reinstalling SSL cert with acme.sh") ssl = WOAcme.deploycert(self, domain) if ssl: SSL.httpsredirect(self, domain, acme_domains) elif (check_prompt == "2"): Log.info(self, "Issuing new SSL cert with acme.sh") ssl = WOShellExec.cmd_exec( self, "/etc/letsencrypt/acme.sh " "--config-home '/etc/letsencrypt/config' " "--renew -d {0} --ecc --force".format(domain)) if ssl: WOAcme.deploycert(self, domain) else: Log.error(self, "Operation cancelled by user.") if os.path.isfile("{0}/conf/nginx/ssl.conf".format(domain)): Log.info(self, "Existing ssl.conf . Backing it up ..") WOFileUtils.mvfile( self, "/var/www/{0}/conf/nginx/ssl.conf".format(domain), '/var/www/{0}/conf/nginx/ssl.conf.bak'.format(domain)) return ssl
def clean_opcache(self): try: Log.info(self, "Cleaning opcache") opgui = requests.get( "https://127.0.0.1:22222/cache/opcache/opgui.php?reset=1") if opgui.status_code != '200': Log.warn(self, 'Cleaning opcache failed') except Exception as e: Log.debug(self, "{0}".format(e)) Log.debug( self, "Unable hit url, " " https://127.0.0.1:22222/cache/opcache/" "opgui.php?reset=1," " please check you have admin tools installed") Log.debug( self, "please check you have admin tools installed," " or install them with `wo stack install --admin`") Log.error(self, "Unable to clean opcache", False)
def check_dns(self, acme_domains): """Check if a list of domains point to the server IP""" server_ip = requests.get('http://v4.wordops.eu/').text for domain in acme_domains: domain_ip = requests.get( 'http://v4.wordops.eu/dns/{0}/'.format(domain)).text if (not domain_ip == server_ip): Log.warn( self, "{0}".format(domain) + " point to the IP {0}".format(domain_ip) + " but your server IP is {0}.".format(server_ip) + "\nUse the flag --force to bypass this check.") Log.error( self, "You have to set the " "proper DNS record for your domain", False) return False Log.debug(self, "DNS record are properly set") return True
def clean_opcache(self): if (os.path.exists('/usr/sbin/nginx') and os.path.exists( '/var/www/22222/htdocs/cache/opcache/php72.php')): try: Log.info(self, "Cleaning opcache") opgui = requests.get( "http://127.0.0.1/cache/opcache/php72.php") if opgui.status_code != '200' or opgui.status_code != '302': Log.warn(self, 'Cleaning opcache failed') except Exception as e: Log.debug(self, "{0}".format(e)) Log.debug( self, "Unable hit url, " " http://127.0.0.1/cache/opcache/" "php72.php," " please check you have admin tools installed") Log.debug( self, "please check you have admin tools installed," " or install them with `wo stack install --admin`") Log.error(self, "Unable to clean opcache", False)
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")
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)
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)
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()
def reload(self): """Reload service""" services = [] wo_system = "/lib/systemd/system/" pargs = self.app.pargs if not (pargs.nginx or pargs.php or pargs.php72 or pargs.php73 or pargs.php74 or pargs.php80 or pargs.php81 or pargs.mysql or pargs.netdata or pargs.proftpd or pargs.redis or pargs.fail2ban): pargs.nginx = True pargs.php = True pargs.mysql = True pargs.fail2ban = True if pargs.nginx: if os.path.exists('{0}'.format(wo_system) + 'nginx.service'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if pargs.php: if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if os.path.exists('{0}'.format(wo_system) + 'php7.4-fpm.service'): services = services + ['php7.4-fpm'] else: Log.info(self, "PHP7.4-FPM is not installed") if os.path.exists('{0}'.format(wo_system) + 'php8.0-fpm.service'): services = services + ['php8.0-fpm'] else: Log.info(self, "PHP8.0-FPM is not installed") if os.path.exists('{0}'.format(wo_system) + 'php8.1-fpm.service'): services = services + ['php8.1-fpm'] else: Log.info(self, "PHP8.1-FPM is not installed") if pargs.php72: if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if pargs.php73: if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if pargs.php74: if os.path.exists('{0}'.format(wo_system) + 'php7.4-fpm.service'): services = services + ['php7.4-fpm'] else: Log.info(self, "PHP7.4-FPM is not installed") if pargs.php80: if os.path.exists('{0}'.format(wo_system) + 'php8.0-fpm.service'): services = services + ['php8.0-fpm'] else: Log.info(self, "PHP8.0-FPM is not installed") if pargs.php81: if os.path.exists('{0}'.format(wo_system) + 'php8.1-fpm.service'): services = services + ['php8.1-fpm'] else: Log.info(self, "PHP8.1-FPM is not installed") if pargs.mysql: if ((WOVar.wo_mysql_host == "localhost") or (WOVar.wo_mysql_host == "127.0.0.1")): if os.path.exists('/lib/systemd/system/mariadb.service'): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn( self, "Remote MySQL found, " "Unable to check MySQL service status") if pargs.redis: if os.path.exists('{0}'.format(wo_system) + 'redis-server.service'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") if pargs.fail2ban: if os.path.exists('{0}'.format(wo_system) + 'fail2ban.service'): services = services + ['fail2ban'] else: Log.info(self, "fail2ban is not installed") # proftpd if pargs.proftpd: if os.path.exists('/etc/init.d/proftpd'): services = services + ['proftpd'] else: Log.info(self, "ProFTPd is not installed") # netdata if pargs.netdata: if os.path.exists('{0}'.format(wo_system) + 'netdata.service'): services = services + ['netdata'] else: Log.info(self, "Netdata is not installed") for service in services: Log.debug(self, "Reloading service: {0}".format(service)) WOService.reload_service(self, service)
def reload(self): """Reload service""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php7 or self.app.pargs.mysql or self.app.pargs.hhvm or self.app.pargs.memcache or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed( self, 'nginx-mainline'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if (WOVariables.wo_platform_distro == 'debian' or WOVariables.wo_platform_codename == 'precise'): if WOAptGet.is_installed(self, 'php5-fpm'): services = services + ['php5-fpm'] else: Log.info(self, "PHP5-FPM is not installed") else: if WOAptGet.is_installed(self, 'php5.6-fpm'): services = services + ['php5.6-fpm'] else: Log.info(self, "PHP5.6-FPM is not installed") if WOAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") if self.app.pargs.php7: if (WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic'): if WOAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") else: Log.info(self, "Your platform does not support PHP 7") if self.app.pargs.mysql: if ((WOVariables.wo_mysql_host is "localhost") or (WOVariables.wo_mysql_host is "127.0.0.1")): if (WOAptGet.is_installed(self, 'mysql-server') or WOAptGet.is_installed(self, 'percona-server-server-5.6') or WOAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn( self, "Remote MySQL found, " "Unable to check MySQL service status") if self.app.pargs.hhvm: Log.info(self, "HHVM does not support to reload") if self.app.pargs.memcache: if WOAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcache is not installed") if self.app.pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") for service in services: Log.debug(self, "Reloading service: {0}".format(service)) WOService.reload_service(self, service)
def stop(self): """Stop services""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73 or self.app.pargs.mysql or self.app.pargs.fail2ban or self.app.pargs.netdata or self.app.pargs.proftpd or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True # nginx if self.app.pargs.nginx: if (WOAptGet.is_installed(self, 'nginx-custom')): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") # php7.2 if self.app.pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") # php7.3 if self.app.pargs.php73: if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") # mysql if self.app.pargs.mysql: if ((WOVariables.wo_mysql_host is "localhost") or (WOVariables.wo_mysql_host is "127.0.0.1")): if (WOAptGet.is_installed(self, 'mysql-server') or WOAptGet.is_installed(self, 'percona-server-server-5.6') or WOAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn( self, "Remote MySQL found, " "Unable to check MySQL service status") # redis if self.app.pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") # fail2ban if self.app.pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): services = services + ['fail2ban'] else: Log.info(self, "fail2ban is not installed") # proftpd if self.app.pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): services = services + ['proftpd'] else: Log.info(self, "ProFTPd is not installed") # netdata if self.app.pargs.netdata: if os.path.isdir("/opt/netdata"): services = services + ['netdata'] else: Log.info(self, "Netdata is not installed") for service in services: Log.debug(self, "Stopping service: {0}".format(service)) WOService.stop_service(self, service)
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)
def status(self): """Status of services""" services = [] wo_system = "/lib/systemd/system/" pargs = self.app.pargs if not (pargs.nginx or pargs.php or pargs.php73 or pargs.mysql or pargs.netdata or pargs.proftpd or pargs.redis or pargs.fail2ban): pargs.nginx = True pargs.php = True pargs.mysql = True pargs.fail2ban = True pargs.netdata = True if pargs.nginx: if os.path.exists('{0}'.format(wo_system) + 'nginx.service'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if pargs.php: if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if pargs.php73: if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if pargs.mysql: if ((WOVar.wo_mysql_host == "localhost") or (WOVar.wo_mysql_host == "127.0.0.1")): if os.path.exists('/etc/systemd/system/mysql.service'): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn( self, "Remote MySQL found, " "Unable to check MySQL service status") if pargs.redis: if os.path.exists('{0}'.format(wo_system) + 'redis-server.service'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") if pargs.fail2ban: if os.path.exists('{0}'.format(wo_system) + 'fail2ban.service'): services = services + ['fail2ban'] else: Log.info(self, "fail2ban is not installed") # proftpd if pargs.proftpd: if os.path.exists('/etc/init.d/proftpd'): services = services + ['proftpd'] else: Log.info(self, "ProFTPd is not installed") # netdata if pargs.netdata: if os.path.exists('{0}'.format(wo_system) + 'netdata.service'): services = services + ['netdata'] else: Log.info(self, "Netdata is not installed") for service in services: if WOService.get_service_status(self, service): Log.info(self, "{0:10}: {1}".format(service, "Running"))
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
def status(self): """Status of services""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73 or self.app.pargs.mysql or self.app.pargs.memcached or self.app.pargs.redis or self.app.pargs.fail2ban): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.nginx: if (WOAptGet.is_installed(self, 'nginx-custom')): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if self.app.pargs.php73: if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if self.app.pargs.mysql: if ((WOVariables.wo_mysql_host is "localhost") or (WOVariables.wo_mysql_host is "127.0.0.1")): if (WOAptGet.is_installed(self, 'mysql-server') or WOAptGet.is_installed(self, 'percona-server-server-5.6') or WOAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn(self, "Remote MySQL found, " "Unable to check MySQL service status") if self.app.pargs.memcached: if WOAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcached is not installed") if self.app.pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") if self.app.pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): services = services + ['fail2ban-client'] else: Log.info(self, "fail2ban is not installed") for service in services: if WOService.get_service_status(self, service): Log.info(self, "{0:10}: {1}".format(service, "Running"))
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 wo 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: Log.debug(self, "{0}".format(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 WOVar.wo_mysql_host == "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)
def reload(self): """Reload service""" services = [] pargs = self.app.pargs if not (pargs.nginx or pargs.php or pargs.php73 or pargs.mysql or pargs.netdata or pargs.proftpd or pargs.redis or pargs.fail2ban): pargs.nginx = True pargs.php = True pargs.mysql = True pargs.fail2ban = True if pargs.nginx: if (WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline')): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if pargs.php73: if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if pargs.mysql: if ((WOVariables.wo_mysql_host == "localhost") or (WOVariables.wo_mysql_host == "127.0.0.1")): if (WOAptGet.is_installed(self, 'mysql-server') or WOAptGet.is_installed(self, 'percona-server-server-5.6') or WOAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn(self, "Remote MySQL found, " "Unable to check MySQL service status") if pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): services = services + ['fail2ban'] else: Log.info(self, "fail2ban is not installed") # proftpd if pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): services = services + ['proftpd'] else: Log.info(self, "ProFTPd is not installed") # netdata if pargs.netdata: if (os.path.isdir("/opt/netdata") or os.path.isdir("/etc/netdata")): services = services + ['netdata'] else: Log.info(self, "Netdata is not installed") for service in services: Log.debug(self, "Reloading service: {0}".format(service)) WOService.reload_service(self, service)
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()
def stop(self): """Stop services""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73 or self.app.pargs.mysql or self.app.pargs.memcached or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.nginx: if (WOAptGet.is_installed(self, 'nginx-custom')): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if self.app.pargs.php73: if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if self.app.pargs.mysql: if ((WOVariables.wo_mysql_host is "localhost") or (WOVariables.wo_mysql_host is "127.0.0.1")): if (WOAptGet.is_installed(self, 'mysql-server') or WOAptGet.is_installed(self, 'percona-server-server-5.6') or WOAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn(self, "Remote MySQL found, " "Unable to check MySQL service status") if self.app.pargs.memcached: if WOAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcached is not installed") if self.app.pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") for service in services: Log.debug(self, "Stopping service: {0}".format(service)) WOService.stop_service(self, service)
def status(self): """Status of services""" services = [] wo_system = "/lib/systemd/system/" pargs = self.app.pargs if not (pargs.nginx or pargs.php or pargs.php72 or pargs.php73 or pargs.php74 or pargs.php80 or pargs.php81 or pargs.mysql or pargs.netdata or pargs.proftpd or pargs.redis or pargs.fail2ban): pargs.nginx = True pargs.php = True pargs.mysql = True pargs.fail2ban = True pargs.netdata = True pargs.ufw = True if pargs.nginx: if os.path.exists('{0}'.format(wo_system) + 'nginx.service'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if pargs.php: if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if os.path.exists('{0}'.format(wo_system) + 'php7.4-fpm.service'): services = services + ['php7.4-fpm'] else: Log.info(self, "PHP7.4-FPM is not installed") if os.path.exists('{0}'.format(wo_system) + 'php8.0-fpm.service'): services = services + ['php8.0-fpm'] else: Log.info(self, "PHP8.0-FPM is not installed") if os.path.exists('{0}'.format(wo_system) + 'php8.1-fpm.service'): services = services + ['php8.1-fpm'] else: Log.info(self, "PHP8.1-FPM is not installed") if pargs.php72: if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if pargs.php73: if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if pargs.php74: if os.path.exists('{0}'.format(wo_system) + 'php7.4-fpm.service'): services = services + ['php7.4-fpm'] else: Log.info(self, "PHP7.4-FPM is not installed") if pargs.php80: if os.path.exists('{0}'.format(wo_system) + 'php8.0-fpm.service'): services = services + ['php8.0-fpm'] else: Log.info(self, "PHP8.0-FPM is not installed") if pargs.php81: if os.path.exists('{0}'.format(wo_system) + 'php8.1-fpm.service'): services = services + ['php8.1-fpm'] else: Log.info(self, "PHP8.1-FPM is not installed") if pargs.mysql: if ((WOVar.wo_mysql_host == "localhost") or (WOVar.wo_mysql_host == "127.0.0.1")): if os.path.exists('/lib/systemd/system/mariadb.service'): services = services + ['mariadb'] else: Log.info(self, "MySQL is not installed") else: Log.warn( self, "Remote MySQL found, " "Unable to check MySQL service status") if pargs.redis: if os.path.exists('{0}'.format(wo_system) + 'redis-server.service'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") if pargs.fail2ban: if os.path.exists('{0}'.format(wo_system) + 'fail2ban.service'): services = services + ['fail2ban'] else: Log.info(self, "fail2ban is not installed") # proftpd if pargs.proftpd: if os.path.exists('/etc/init.d/proftpd'): services = services + ['proftpd'] else: Log.info(self, "ProFTPd is not installed") # netdata if pargs.netdata: if os.path.exists('{0}'.format(wo_system) + 'netdata.service'): services = services + ['netdata'] else: Log.info(self, "Netdata is not installed") # UFW if pargs.ufw: if os.path.exists('/usr/sbin/ufw'): if WOFileUtils.grepcheck(self, '/etc/ufw/ufw.conf', 'ENABLED=yes'): Log.info(self, "UFW Firewall is enabled") else: Log.info(self, "UFW Firewall is disabled") else: Log.info(self, "UFW is not installed") for service in services: if WOService.get_service_status(self, service): Log.info(self, "{0:10}: {1}".format(service, "Running"))