def clean_fastcgi(self): if(os.path.isdir("/var/run/nginx-cache")): Log.info(self, "Cleaning NGINX FastCGI cache") WOShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*") WOService.restart_service(self, 'nginx') else: Log.error(self, "Unable to clean FastCGI cache", False)
def clean_memcache(self): try: if (WOAptGet.is_installed(self, "memcached")): WOService.restart_service(self, "memcached") Log.info(self, "Cleaning MemCache") else: Log.info(self, "Memcache not installed") except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "Unable to restart Memcached", False)
def default(self): pargs = self.app.pargs if not pargs.site_name: try: while not pargs.site_name: pargs.site_name = (input('Enter site name : ').strip()) except IOError as e: Log.debug(self, str(e)) Log.error(self, 'Unable to read input, Please try again') pargs.site_name = pargs.site_name.strip() wo_domain = WODomain.validate(self, pargs.site_name) if not check_domain_exists(self, wo_domain): Log.error(self, "site {0} does not exist".format(wo_domain)) if os.path.isfile('/etc/nginx/sites-available/{0}'.format(wo_domain)): try: WOShellExec.invoke_editor( self, '/etc/nginx/sites-availa' 'ble/{0}'.format(wo_domain)) except CommandExecutionError as e: Log.debug(self, str(e)) Log.error(self, "Failed invoke editor") if (WOGit.checkfilestatus( self, "/etc/nginx", '/etc/nginx/sites-available/{0}'.format(wo_domain))): WOGit.add(self, ["/etc/nginx"], msg="Edit website: {0}".format(wo_domain)) # Reload NGINX if not WOService.reload_service(self, 'nginx'): Log.error( self, "service nginx reload failed. " "check issues with `nginx -t` command") else: Log.error(self, "nginx configuration file does not exists")
def enable(self): pargs = self.app.pargs if not pargs.site_name: try: while not pargs.site_name: pargs.site_name = (input('Enter site name : ').strip()) except IOError as e: Log.debug(self, str(e)) Log.error(self, 'could not input site name') pargs.site_name = pargs.site_name.strip() # validate domain name wo_domain = WODomain.validate(self, pargs.site_name) # check if site exists if not check_domain_exists(self, wo_domain): Log.error(self, "site {0} does not exist".format(wo_domain)) if os.path.isfile('/etc/nginx/sites-available/{0}'.format(wo_domain)): Log.info(self, "Enable domain {0:10} \t".format(wo_domain), end='') WOFileUtils.create_symlink(self, [ '/etc/nginx/sites-available/{0}'.format(wo_domain), '/etc/nginx/sites-enabled/{0}'.format(wo_domain) ]) WOGit.add(self, ["/etc/nginx"], msg="Enabled {0} ".format(wo_domain)) updateSiteInfo(self, wo_domain, enabled=True) Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]") if not WOService.reload_service(self, 'nginx'): Log.error( self, "service nginx reload failed. " "check issues with `nginx -t` command") else: Log.error(self, 'nginx configuration file does not exist')
def secure_port(self): """This function Secures port""" WOGit.add(self, ["/etc/nginx"], msg="Add Nginx to into Git") pargs = self.app.pargs if pargs.user_input: while ((not pargs.user_input.isdigit()) and (not pargs.user_input < 65536)): Log.info(self, "Please enter a valid port number ") pargs.user_input = input("WordOps " "admin port [22222]:") else: port = input("WordOps admin port [22222]:") if port == "": port = 22222 while ((not port.isdigit()) and (not port != "") and (not port < 65536)): Log.info(self, "Please Enter valid port number :") port = input("WordOps admin port [22222]:") pargs.user_input = port WOShellExec.cmd_exec( self, "sed -i \"s/listen.*/listen " "{port} default_server ssl http2;/\" " "/etc/nginx/sites-available/22222".format(port=pargs.user_input)) WOGit.add(self, ["/etc/nginx"], msg="Adding changed secure port into Git") if not WOService.reload_service(self, 'nginx'): Log.error( self, "service nginx reload failed. " "check issues with `nginx -t` command") Log.info( self, "Successfully port changed {port}".format(port=pargs.user_input))
def secure_port(self): """This function Secures port""" WOGit.add(self, ["/etc/nginx"], msg="Add Nginx to into Git") pargs = self.app.pargs if pargs.user_input: while ((not pargs.user_input.isdigit()) and (not pargs.user_input < 65536)): Log.info(self, "Please enter a valid port number ") pargs.user_input = input("WordOps " "admin port [22222]:") else: port = input("WordOps admin port [22222]:") if port == "": port = 22222 while ((not port.isdigit()) and (not port != "") and (not port < 65536)): Log.info(self, "Please Enter valid port number :") port = input("WordOps admin port [22222]:") pargs.user_input = port data = dict(release=WOVar.wo_version, port=pargs.user_input, webroot='/var/www/') WOTemplate.deploy(self, '/etc/nginx/sites-available/22222', '22222.mustache', data) WOGit.add(self, ["/etc/nginx"], msg="Adding changed secure port into Git") if not WOService.reload_service(self, 'nginx'): Log.error( self, "service nginx reload failed. " "check issues with `nginx -t` command") Log.info( self, "Successfully port changed {port}".format(port=pargs.user_input))
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 secure_ssh_port(self): """Change SSH port""" WOGit.add(self, ["/etc/ssh"], msg="Adding changed SSH port into Git") pargs = self.app.pargs if pargs.user_input: while ((not pargs.user_input.isdigit()) and (not pargs.user_input < 65536)): Log.info(self, "Please enter a valid port number ") pargs.user_input = input("Server " "SSH port [22]:") if not pargs.user_input: port = input("Server SSH port [22]:") if port == "": port = 22 while (not port.isdigit()) and (port != "") and (not port < 65536): Log.info(self, "Please Enter valid port number :") port = input("Server SSH port [22]:") pargs.user_input = port if WOFileUtils.grepcheck(self, '/etc/ssh/sshd_config', '#Port'): WOShellExec.cmd_exec(self, "sed -i \"s/#Port.*/Port " "{port}/\" /etc/ssh/sshd_config" .format(port=pargs.user_input)) else: WOShellExec.cmd_exec(self, "sed -i \"s/Port.*/Port " "{port}/\" /etc/ssh/sshd_config" .format(port=pargs.user_input)) # allow new ssh port if ufw is enabled if os.path.isfile('/etc/ufw/ufw.conf'): # add rule for proftpd with UFW if WOFileUtils.grepcheck( self, '/etc/ufw/ufw.conf', 'ENABLED=yes'): try: WOShellExec.cmd_exec( self, 'ufw limit {0}'.format(pargs.user_input)) WOShellExec.cmd_exec( self, 'ufw reload') except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "Unable to add UFW rule") # add ssh into git WOGit.add(self, ["/etc/ssh"], msg="Adding changed SSH port into Git") # restart ssh service if not WOService.restart_service(self, 'ssh'): Log.error(self, "service SSH restart failed.") Log.info(self, "Successfully changed SSH port to {port}" .format(port=pargs.user_input))
def secure_ssh(self): """Harden ssh security""" pargs = self.app.pargs if not pargs.force and not pargs.allowpassword: start_secure = input('Are you sure you to want to' ' harden SSH security ?' '\nSSH login with password will not ' 'be possible anymore. Please make sure ' 'you are already using SSH Keys.\n' 'Harden SSH security [y/N]') if start_secure != "Y" and start_secure != "y": Log.error(self, "Not hardening SSH security") if os.path.exists('/etc/ssh'): WOGit.add(self, ["/etc/ssh"], msg="Adding SSH into Git") Log.debug(self, "check if /etc/ssh/sshd_config exist") if os.path.isfile('/etc/ssh/sshd_config'): Log.debug(self, "looking for the current ssh port") for line in open('/etc/ssh/sshd_config', encoding='utf-8'): if 'Port' in line: ssh_line = line.strip() break port = (ssh_line).split(' ') current_ssh_port = (port[1]).strip() if os.getenv('SUDO_USER'): sudo_user = os.getenv('SUDO_USER') else: sudo_user = '' if pargs.allowpassword: wo_allowpassword = '******' else: wo_allowpassword = '******' data = dict(sshport=current_ssh_port, allowpass=wo_allowpassword, user=sudo_user) WOTemplate.deploy(self, '/etc/ssh/sshd_config', 'sshd.mustache', data) WOGit.add(self, ["/etc/ssh"], msg="Adding changed SSH port into Git") if not WOService.restart_service(self, 'ssh'): Log.error(self, "service SSH restart failed.") Log.info(self, "Successfully harden SSH security") else: Log.error(self, "SSH config file not found")
def secure_port(self): """This function Secures port""" if self.app.pargs.user_input: while not self.app.pargs.user_input.isdigit(): Log.info(self, "Please enter a valid port number ") self.app.pargs.user_input = input("WordOps " "admin port [22222]:") if not self.app.pargs.user_input: port = input("WordOps admin port [22222]:") if port == "": self.app.pargs.user_input = 22222 while not port.isdigit() and port != "": Log.info(self, "Please Enter valid port number :") port = input("WordOps admin port [22222]:") self.app.pargs.user_input = port if WOVariables.wo_platform_distro == 'ubuntu': WOShellExec.cmd_exec( self, "sed -i \"s/listen.*/listen " "{port} default_server ssl http2;/\" " "/etc/nginx/sites-available/22222".format( port=self.app.pargs.user_input)) if WOVariables.wo_platform_distro == 'debian': WOShellExec.cmd_exec( self, "sed -i \"s/listen.*/listen " "{port} default_server ssl http2;/\" " "/etc/nginx/sites-available/22222".format( port=self.app.pargs.user_input)) WOGit.add(self, ["/etc/nginx"], msg="Adding changed secure port into Git") if not WOService.reload_service(self, 'nginx'): Log.error( self, "service nginx reload failed. " "check issues with `nginx -t` command") Log.info( self, "Successfully port changed {port}".format( port=self.app.pargs.user_input))
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 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 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 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 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 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 default(self): # All package update apt_packages = [] packages = [] if ((not self.app.pargs.web) and (not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.mysql) and (not self.app.pargs.all) and (not self.app.pargs.wpcli) and (not self.app.pargs.netdata) and (not self.app.pargs.composer) and (not self.app.pargs.phpmyadmin) and (not self.app.pargs.redis)): self.app.pargs.web = True if self.app.pargs.all: self.app.pargs.web = True if self.app.pargs.web: if WOAptGet.is_installed(self, 'nginx-custom'): self.app.pargs.nginx = True else: Log.info(self, "Nginx is not already installed") self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.wpcli = True self.app.pargs.netdata = True if self.app.pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): apt_packages = apt_packages + WOVariables.wo_nginx else: Log.info(self, "Nginx Stable is not already installed") if self.app.pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): if not WOAptGet.is_installed(self, 'php7.3-fpm'): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php else: Log.info(self, "PHP 7.2 is not installed") if self.app.pargs.mysql: if WOAptGet.is_installed(self, 'mariadb-server'): apt_packages = apt_packages + WOVariables.wo_mysql else: Log.info(self, "MariaDB is not installed") if self.app.pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): apt_packages = apt_packages + WOVariables.wo_redis else: Log.info(self, "Redis is not installed") if self.app.pargs.wpcli: if os.path.isfile('/usr/local/bin/wp'): packages = packages + [["https://github.com/wp-cli/wp-cli/" "releases/download/v{0}/" "wp-cli-{0}.phar" "".format(WOVariables.wo_wp_cli), "/usr/local/bin/wp", "WP-CLI"]] else: Log.info(self, "WPCLI is not installed with WordOps") if self.app.pargs.netdata: if os.path.isdir('/opt/netdata'): packages = packages + [['https://my-netdata.io/' 'kickstart-static64.sh', '/var/lib/wo/tmp/kickstart.sh', 'Netdata']] if self.app.pargs.phpmyadmin: if os.path.isdir('/var/www/22222/htdocs/db/pma'): packages = packages + \ [["https://files.phpmyadmin.net" "/phpMyAdmin/{0}/" "phpMyAdmin-{0}-" "all-languages" ".tar.gz".format(WOVariables.wo_phpmyadmin), "/var/lib/wo/tmp/pma.tar.gz", "PHPMyAdmin"]] else: Log.error(self, "phpMyAdmin isn't installed") if self.app.pargs.composer: if os.path.isfile('/usr/local/bin/composer'): packages = packages + [["https://getcomposer.org/installer", "/var/lib/wo/tmp/composer-install", "Composer"]] else: Log.error(self, "Composer isn't installed") if len(packages) or len(apt_packages): Log.info(self, "During package update process non nginx-cached" " parts of your site may remain down") # Check prompt if (not self.app.pargs.no_prompt): start_upgrade = input("Do you want to continue:[y/N]") if start_upgrade != "Y" and start_upgrade != "y": Log.error(self, "Not starting package update") Log.info(self, "Updating packages, please wait...") if len(apt_packages): # apt-get update WOAptGet.update(self) # Update packages WOAptGet.install(self, apt_packages) # Post Actions after package updates if (set(WOVariables.wo_nginx).issubset(set(apt_packages))): WOService.restart_service(self, 'nginx') if set(WOVariables.wo_php).issubset(set(apt_packages)): WOService.restart_service(self, 'php7.2-fpm') if set(WOVariables.wo_mysql).issubset(set(apt_packages)): WOService.restart_service(self, 'mysql') if set(WOVariables.wo_redis).issubset(set(apt_packages)): WOService.restart_service(self, 'redis-server') if len(packages): if self.app.pargs.wpcli: WOFileUtils.remove(self, ['/usr/local/bin/wp']) if self.app.pargs.netdata: WOFileUtils.remove(self, ['/var/lib/wo/tmp/kickstart.sh']) Log.debug(self, "Downloading following: {0}".format(packages)) WODownload.download(self, packages) if self.app.pargs.wpcli: WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775) if self.app.pargs.netdata: Log.info(self, "Upgrading Netdata, please wait...") WOShellExec.cmd_exec(self, "/bin/bash /var/lib/wo/tmp/" "kickstart.sh " "--dont-wait") if self.app.pargs.composer: Log.info(self, "Upgrading Composer, please wait...") WOShellExec.cmd_exec(self, "php -q /var/lib/wo" "/tmp/composer-install " "--install-dir=/var/lib/wo/tmp/") shutil.copyfile('/var/lib/wo/tmp/composer.phar', '/usr/local/bin/composer') WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775) if self.app.pargs.phpmyadmin: Log.info(self, "Upgrading phpMyAdmin, please wait...") WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz', '/var/lib/wo/tmp/') shutil.copyfile(('{0}22222/htdocs/db/pma' '/config.inc.php' .format(WOVariables.wo_webroot)), ('/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/config.inc.php' .format(WOVariables.wo_phpmyadmin)) ) WOFileUtils.rm(self, '{0}22222/htdocs/db/pma' .format(WOVariables.wo_webroot)) shutil.move('/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/' .format(WOVariables.wo_phpmyadmin), '{0}22222/htdocs/db/pma/' .format(WOVariables.wo_webroot)) Log.info(self, "Successfully updated packages") else: self.app.args.print_help()
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 purge(self): """Start purging of packages""" apt_packages = [] packages = [] pargs = self.app.pargs # Default action for stack purge if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx) and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli) and (not pargs.phpmyadmin) and (not pargs.composer) and (not pargs.netdata) and (not pargs.dashboard) and (not pargs.fail2ban) and (not pargs.security) and (not pargs.mysqlclient) and (not pargs.mysqltuner) and (not pargs.adminer) and (not pargs.utils) and (not pargs.redis) and (not pargs.proftpd) and (not pargs.extplorer) and (not pargs.cheat) and (not pargs.clamav) and (not pargs.phpredisadmin) and (not pargs.php73)): pargs.web = True pargs.admin = True pargs.security = True if pargs.all: pargs.web = True pargs.admin = True pargs.php73 = True pargs.fail2ban = True pargs.proftpd = True pargs.utils = True pargs.redis = True packages = packages + ['/var/www/22222/htdocs/*'] if pargs.web: pargs.nginx = True pargs.php = True pargs.mysql = True pargs.wpcli = True if pargs.admin: pargs.utils = True pargs.composer = True pargs.netdata = True pargs.mysqltuner = True pargs.cheat = True if pargs.security: pargs.fail2ban = True pargs.clamav = True # NGINX if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): Log.debug(self, "Purge apt_packages variable of Nginx") apt_packages = apt_packages + WOVariables.wo_nginx # PHP if pargs.php: Log.debug(self, "Purge apt_packages variable PHP") if WOAptGet.is_installed(self, 'php7.2-fpm'): if not (WOAptGet.is_installed(self, 'php7.3-fpm')): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php # PHP 7.3 if pargs.php73: Log.debug(self, "Removing apt_packages variable of PHP 7.3") if WOAptGet.is_installed(self, 'php7.3-fpm'): if not (WOAptGet.is_installed(self, 'php7.2-fpm')): apt_packages = apt_packages + WOVariables.wo_php73 + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php73 # REDIS if pargs.redis: Log.debug(self, "Remove apt_packages variable of Redis") apt_packages = apt_packages + WOVariables.wo_redis # MariaDB if pargs.mysql: Log.debug(self, "Removing apt_packages variable of MySQL") apt_packages = apt_packages + WOVariables.wo_mysql # mysqlclient if pargs.mysqlclient: Log.debug(self, "Removing apt_packages variable " "for MySQL Client") if WOShellExec.cmd_exec(self, "mysqladmin ping"): apt_packages = apt_packages + WOVariables.wo_mysql_client # fail2ban if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): Log.debug(self, "Remove apt_packages variable of Fail2ban") apt_packages = apt_packages + WOVariables.wo_fail2ban # ClamAV if pargs.clamav: Log.debug(self, "Setting apt_packages variable for ClamAV") if WOAptGet.is_installed(self, 'clamav'): apt_packages = apt_packages + ["clamav"] # proftpd if pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): Log.debug(self, "Purge apt_packages variable for ProFTPd") apt_packages = apt_packages + ["proftpd-basic"] # WP-CLI if pargs.wpcli: Log.debug(self, "Purge package variable WPCLI") if os.path.isfile('/usr/local/bin/wp'): packages = packages + ['/usr/local/bin/wp'] # PHPMYADMIN if pargs.phpmyadmin: packages = packages + [ '{0}22222/htdocs/db/pma'.format(WOVariables.wo_webroot) ] Log.debug(self, "Purge package variable phpMyAdmin") # Composer if pargs.composer: Log.debug(self, "Removing package variable of Composer ") if os.path.isfile('/usr/local/bin/composer'): packages = packages + ['/usr/local/bin/composer'] if pargs.mysqltuner: Log.debug(self, "Removing packages for MySQLTuner ") packages = packages + ['/usr/bin/mysqltuner'] # PHPREDISADMIN if pargs.phpredisadmin: Log.debug(self, "Removing package variable of phpRedisAdmin ") if os.path.isdir('{0}22222/htdocs/cache/redis'.format( WOVariables.wo_webroot)): packages = packages + [ '{0}22222/htdocs/' 'cache/redis'.format(WOVariables.wo_webroot) ] # Adminer if pargs.adminer: Log.debug(self, "Purge package variable Adminer") packages = packages + [ '{0}22222/htdocs/db/adminer'.format(WOVariables.wo_webroot) ] # utils if pargs.utils: Log.debug(self, "Purge package variable utils") packages = packages + [ '{0}22222/htdocs/php/webgrind/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/cache/opcache'.format( WOVariables.wo_webroot), '{0}22222/htdocs/cache/nginx/' 'clean.php'.format( WOVariables.wo_webroot), '/usr/bin/pt-query-advisor', '{0}22222/htdocs/db/anemometer'.format(WOVariables.wo_webroot) ] if pargs.netdata: Log.debug(self, "Removing Netdata") if os.path.isfile('/opt/netdata/usr/' 'libexec/netdata-uninstaller.sh'): packages = packages + ['/var/lib/wo/tmp/kickstart.sh'] if pargs.dashboard: Log.debug(self, "Removing Wo-Dashboard") packages = packages + [ '{0}22222/htdocs/assets/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/index.php'.format(WOVariables.wo_webroot) ] if (packages) or (apt_packages): if (not pargs.force): start_purge = input('Are you sure you to want to' ' purge stacks from this server ?' '\nPackage configuration and data ' 'will not remain' ' on this server after this operation.\n' 'Purge stacks [y/N]') if start_purge != "Y" and start_purge != "y": Log.error(self, "Not starting stack purge") if (set(["nginx-custom"]).issubset(set(apt_packages))): WOService.stop_service(self, 'nginx') if (set(["fail2ban"]).issubset(set(apt_packages))): WOService.stop_service(self, 'fail2ban') # Netdata uninstaller if (set(['/var/lib/wo/tmp/' 'kickstart.sh']).issubset(set(packages))): if WOVariables.wo_distro == 'Raspbian': WOShellExec.cmd_exec( self, "bash /usr/" "libexec/netdata-" "uninstaller.sh -y -f") else: WOShellExec.cmd_exec( self, "bash /opt/netdata/usr/" "libexec/netdata-" "uninstaller.sh -y -f") if (apt_packages): Log.info(self, "Purging apt packages, please wait...") WOAptGet.remove(self, apt_packages, purge=True) WOAptGet.auto_remove(self) if (packages): Log.info(self, "Purging packages, please wait...") WOFileUtils.remove(self, packages) WOAptGet.auto_remove(self) Log.info(self, "Successfully purged packages")
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 remove(self): """Start removal of packages""" apt_packages = [] packages = [] pargs = self.app.pargs if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx) and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli) and (not pargs.phpmyadmin) and (not pargs.composer) and (not pargs.netdata) and (not pargs.dashboard) and (not pargs.fail2ban) and (not pargs.security) and (not pargs.mysqlclient) and (not pargs.mysqltuner) and (not pargs.adminer) and (not pargs.utils) and (not pargs.redis) and (not pargs.proftpd) and (not pargs.extplorer) and (not pargs.clamav) and (not pargs.ufw) and (not pargs.phpredisadmin) and (not pargs.sendmail) and (not pargs.php73)): pargs.web = True pargs.admin = True if pargs.all: pargs.web = True pargs.admin = True pargs.php73 = True pargs.fail2ban = True pargs.proftpd = True pargs.utils = True pargs.redis = True pargs.security = True packages = packages + ['/var/www/22222/htdocs'] if pargs.web: pargs.nginx = True pargs.php = True pargs.mysql = True pargs.wpcli = True pargs.sendmail = True if pargs.admin: pargs.composer = True pargs.utils = True pargs.netdata = True pargs.mysqltuner = True if pargs.security: pargs.fail2ban = True pargs.clamav = True pargs.ufw = True # NGINX if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): Log.debug(self, "Removing apt_packages variable of Nginx") apt_packages = apt_packages + WOVariables.wo_nginx # PHP 7.2 if pargs.php: Log.debug(self, "Removing apt_packages variable of PHP") if WOAptGet.is_installed(self, 'php7.2-fpm'): if not WOAptGet.is_installed(self, 'php7.3-fpm'): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php # PHP7.3 if pargs.php73: Log.debug(self, "Removing apt_packages variable of PHP 7.3") if WOAptGet.is_installed(self, 'php7.3-fpm'): if not (WOAptGet.is_installed(self, 'php7.2-fpm')): apt_packages = apt_packages + WOVariables.wo_php73 + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php73 # REDIS if pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): Log.debug(self, "Remove apt_packages variable of Redis") apt_packages = apt_packages + ["redis-server"] # MariaDB if pargs.mysql: if WOAptGet.is_installed(self, 'mariadb-server'): Log.debug(self, "Removing apt_packages variable of MySQL") apt_packages = apt_packages + [ 'mariadb-server', 'mysql-common', 'mariadb-client' ] # mysqlclient if pargs.mysqlclient: Log.debug(self, "Removing apt_packages variable " "for MySQL Client") if WOShellExec.cmd_exec(self, "mysqladmin ping"): apt_packages = apt_packages + WOVariables.wo_mysql_client # fail2ban if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): Log.debug(self, "Remove apt_packages variable of Fail2ban") apt_packages = apt_packages + WOVariables.wo_fail2ban # ClamAV if pargs.clamav: Log.debug(self, "Setting apt_packages variable for ClamAV") if WOAptGet.is_installed(self, 'clamav'): apt_packages = apt_packages + WOVariables.wo_clamav # sendmail if pargs.sendmail: Log.debug(self, "Setting apt_packages variable for Sendmail") if WOAptGet.is_installed(self, 'sendmail'): apt_packages = apt_packages + ["sendmail"] # proftpd if pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): Log.debug(self, "Remove apt_packages variable for ProFTPd") apt_packages = apt_packages + ["proftpd-basic"] # UFW if pargs.ufw: if WOAptGet.is_installed(self, 'ufw'): Log.debug(self, "Remove apt_packages variable for UFW") apt_packages = apt_packages + ["ufw"] # WPCLI if pargs.wpcli: Log.debug(self, "Removing package variable of WPCLI ") if os.path.isfile('/usr/local/bin/wp'): packages = packages + ['/usr/local/bin/wp'] # PHPMYADMIN if pargs.phpmyadmin: if os.path.isdir('{0}22222/htdocs/db/pma'.format( WOVariables.wo_webroot)): Log.debug(self, "Removing package of phpMyAdmin ") packages = packages + [ '{0}22222/htdocs/db/pma'.format(WOVariables.wo_webroot) ] # Composer if pargs.composer: Log.debug(self, "Removing package of Composer ") if os.path.isfile('/usr/local/bin/composer'): packages = packages + ['/usr/local/bin/composer'] # MySQLTuner if pargs.mysqltuner: if os.path.isfile('/usr/bin/mysqltuner'): Log.debug(self, "Removing packages for MySQLTuner ") packages = packages + ['/usr/bin/mysqltuner'] # PHPREDISADMIN if pargs.phpredisadmin: Log.debug(self, "Removing package variable of phpRedisAdmin ") if os.path.isdir('{0}22222/htdocs/cache/redis'.format( WOVariables.wo_webroot)): packages = packages + [ '{0}22222/htdocs/' 'cache/redis'.format(WOVariables.wo_webroot) ] # ADMINER if pargs.adminer: if os.path.isdir('{0}22222/htdocs/db/adminer'.format( WOVariables.wo_webroot)): Log.debug(self, "Removing package variable of Adminer ") packages = packages + [ '{0}22222/htdocs/db/adminer'.format(WOVariables.wo_webroot) ] if pargs.utils: Log.debug(self, "Removing package variable of utils ") packages = packages + [ '{0}22222/htdocs/php/webgrind/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/cache/opcache'.format( WOVariables.wo_webroot), '{0}22222/htdocs/cache/nginx/' 'clean.php'.format( WOVariables.wo_webroot), '/usr/bin/pt-query-advisor', '{0}22222/htdocs/db/anemometer'.format(WOVariables.wo_webroot) ] if pargs.netdata: Log.debug(self, "Removing Netdata") if os.path.isfile('/opt/netdata/usr/' 'libexec/netdata/netdata-uninstaller.sh'): packages = packages + ['/var/lib/wo/tmp/kickstart.sh'] if pargs.dashboard: if (os.path.isfile('{0}22222/htdocs/index.php'.format( WOVariables.wo_webroot)) or os.path.isfile('{0}22222/htdocs/index.html'.format( WOVariables.wo_webroot))): Log.debug(self, "Removing Wo-Dashboard") packages = packages + [ '{0}22222/htdocs/assets'.format(WOVariables.wo_webroot), '{0}22222/htdocs/index.php'.format(WOVariables.wo_webroot), '{0}22222/htdocs/index.html'.format(WOVariables.wo_webroot) ] if (packages) or (apt_packages): if (not pargs.force): start_remove = input('Are you sure you to want to' ' remove from server.' '\nPackage configuration will remain' ' on server after this operation.\n' 'Remove stacks [y/N]?') if start_remove != "Y" and start_remove != "y": Log.error(self, "Not starting stack removal") if 'nginx-custom' in apt_packages: WOService.stop_service(self, 'nginx') if 'mariadb-server' in apt_packages: WOMysql.backupAll(self) WOService.stop_service(self, 'mysql') # Netdata uninstaller if (set(['/var/lib/wo/tmp/' 'kickstart.sh']).issubset(set(packages))): if WOVariables.wo_distro == 'Raspbian': WOShellExec.cmd_exec( self, "bash /usr/" "libexec/netdata/" "netdata-uninstaller.sh -y -f") else: WOShellExec.cmd_exec(self, "bash /opt/netdata/usr/" "libexec/netdata/" "netdata-uninstaller.sh - y - f", errormsg='', log=False) if (packages): Log.wait(self, "Removing packages ") WOFileUtils.remove(self, packages) Log.valide(self, "Removing packages ") if (apt_packages): Log.debug(self, "Removing apt_packages") Log.wait(self, "Removing APT packages ") WOAptGet.remove(self, apt_packages) WOAptGet.auto_remove(self) Log.valide(self, "Removing APT packages ") Log.info(self, "Successfully removed packages")
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 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 purge(self): """Start purging of packages""" apt_packages = [] packages = [] pargs = self.app.pargs # Default action for stack purge if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx) and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli) and (not pargs.phpmyadmin) and (not pargs.composer) and (not pargs.netdata) and (not pargs.dashboard) and (not pargs.fail2ban) and (not pargs.security) and (not pargs.mysqlclient) and (not pargs.mysqltuner) and (not pargs.adminer) and (not pargs.utils) and (not pargs.redis) and (not pargs.proftpd) and (not pargs.extplorer) and (not pargs.clamav) and (not pargs.ufw) and (not pargs.phpredisadmin) and (not pargs.sendmail) and (not pargs.php73)): pargs.web = True pargs.admin = True pargs.security = True if pargs.all: pargs.web = True pargs.admin = True pargs.php73 = True pargs.fail2ban = True pargs.proftpd = True pargs.utils = True pargs.redis = True packages = packages + ['/var/www/22222/htdocs'] if pargs.web: pargs.nginx = True pargs.php = True pargs.mysql = True pargs.wpcli = True pargs.sendmail = True if pargs.admin: pargs.utils = True pargs.composer = True pargs.netdata = True pargs.mysqltuner = True if pargs.security: pargs.fail2ban = True pargs.clamav = True pargs.ufw = True # NGINX if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): Log.debug(self, "Add Nginx to apt_packages list") apt_packages = apt_packages + WOVariables.wo_nginx else: Log.info(self, "Nginx is not installed") # PHP if pargs.php: Log.debug(self, "Add PHP to apt_packages list") if WOAptGet.is_installed(self, 'php7.2-fpm'): if not (WOAptGet.is_installed(self, 'php7.3-fpm')): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php # PHP 7.3 if pargs.php73: Log.debug(self, "Removing apt_packages variable of PHP 7.3") if WOAptGet.is_installed(self, 'php7.3-fpm'): if not (WOAptGet.is_installed(self, 'php7.2-fpm')): apt_packages = apt_packages + WOVariables.wo_php73 + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php73 # REDIS if pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): Log.debug(self, "Remove apt_packages variable of Redis") apt_packages = apt_packages + ["redis-server"] else: Log.info(self, "Redis is not installed") # MariaDB if pargs.mysql: if WOAptGet.is_installed(self, 'mariadb-server'): Log.debug(self, "Add MySQL to apt_packages list") apt_packages = apt_packages + [ 'mariadb-server', 'mysql-common', 'mariadb-client' ] packages = packages + ['/etc/mysql', '/var/lib/mysql'] else: Log.info(self, "MariaDB is not installed") # mysqlclient if pargs.mysqlclient: if WOShellExec.cmd_exec(self, "mysqladmin ping"): Log.debug(self, "Add MySQL client to apt_packages list") apt_packages = apt_packages + WOVariables.wo_mysql_client # fail2ban if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): Log.debug(self, "Add Fail2ban to apt_packages list") apt_packages = apt_packages + WOVariables.wo_fail2ban # ClamAV if pargs.clamav: if WOAptGet.is_installed(self, 'clamav'): Log.debug(self, "Add ClamAV to apt_packages list") apt_packages = apt_packages + WOVariables.wo_clamav # UFW if pargs.ufw: if WOAptGet.is_installed(self, 'ufw'): Log.debug(self, "Add UFW to apt_packages list") apt_packages = apt_packages + ["ufw"] # sendmail if pargs.sendmail: if WOAptGet.is_installed(self, 'sendmail'): Log.debug(self, "Add sendmail to apt_packages list") apt_packages = apt_packages + ["sendmail"] # proftpd if pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): Log.debug(self, "Add Proftpd to apt_packages list") apt_packages = apt_packages + ["proftpd-basic"] # WP-CLI if pargs.wpcli: if os.path.isfile('/usr/local/bin/wp'): Log.debug(self, "Purge package variable WPCLI") packages = packages + ['/usr/local/bin/wp'] # PHPMYADMIN if pargs.phpmyadmin: if os.path.isdir('{0}22222/htdocs/db/pma'.format( WOVariables.wo_webroot)): Log.debug(self, "Removing package of phpMyAdmin ") packages = packages + [ '{0}22222/htdocs/db/pma'.format(WOVariables.wo_webroot) ] # Composer if pargs.composer: if os.path.isfile('/usr/local/bin/composer'): Log.debug(self, "Removing package variable of Composer ") packages = packages + ['/usr/local/bin/composer'] # MySQLTuner if pargs.mysqltuner: if os.path.isfile('/usr/bin/mysqltuner'): Log.debug(self, "Removing packages for MySQLTuner ") packages = packages + ['/usr/bin/mysqltuner'] # PHPREDISADMIN if pargs.phpredisadmin: Log.debug(self, "Removing package variable of phpRedisAdmin ") if os.path.isdir('{0}22222/htdocs/cache/redis'.format( WOVariables.wo_webroot)): packages = packages + [ '{0}22222/htdocs/' 'cache/redis'.format(WOVariables.wo_webroot) ] # ADMINER if pargs.adminer: if os.path.isdir('{0}22222/htdocs/db/adminer'.format( WOVariables.wo_webroot)): Log.debug(self, "Removing package variable of Adminer ") packages = packages + [ '{0}22222/htdocs/db/adminer'.format(WOVariables.wo_webroot) ] # utils if pargs.utils: Log.debug(self, "Purge package variable utils") packages = packages + [ '{0}22222/htdocs/php/webgrind/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/cache/opcache'.format( WOVariables.wo_webroot), '{0}22222/htdocs/cache/nginx/' 'clean.php'.format( WOVariables.wo_webroot), '/usr/bin/pt-query-advisor', '{0}22222/htdocs/db/anemometer'.format(WOVariables.wo_webroot) ] if pargs.netdata: Log.debug(self, "Removing Netdata") if os.path.isfile('/opt/netdata/usr/' 'libexec/netdata/netdata-uninstaller.sh'): packages = packages + ['/var/lib/wo/tmp/kickstart.sh'] if pargs.dashboard: Log.debug(self, "Removing Wo-Dashboard") packages = packages + [ '{0}22222/htdocs/assets/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/index.php'.format(WOVariables.wo_webroot) ] if (packages) or (apt_packages): if (not pargs.force): start_purge = input('Are you sure you to want to' ' purge stacks from this server ?' '\nPackage configuration and data ' 'will not remain' ' on this server after this operation.\n' 'Purge stacks [y/N]') if start_purge != "Y" and start_purge != "y": Log.error(self, "Not starting stack purge") if (set(["nginx-custom"]).issubset(set(apt_packages))): WOService.stop_service(self, 'nginx') if (set(["fail2ban"]).issubset(set(apt_packages))): WOService.stop_service(self, 'fail2ban') if (set(["mariadb-server"]).issubset(set(apt_packages))): if (os.path.isfile('/usr/bin/mysql') and os.path.isdir('/var/lib/mysql')): WOMysql.backupAll(self) WOService.stop_service(self, 'mysql') # Netdata uninstaller if (set(['/var/lib/wo/tmp/' 'kickstart.sh']).issubset(set(packages))): if WOVariables.wo_distro == 'Raspbian': WOShellExec.cmd_exec(self, "bash /usr/" "libexec/netdata/netdata-" "uninstaller.sh -y -f", errormsg='', log=False) else: WOShellExec.cmd_exec( self, "bash /opt/netdata/usr/" "libexec/netdata/netdata-" "uninstaller.sh -y -f") if (apt_packages): Log.wait(self, "Purging APT Packages ") WOAptGet.remove(self, apt_packages, purge=True) WOAptGet.auto_remove(self) Log.valide(self, "Purging APT Packages ") if (packages): Log.wait(self, "Purging Packages ") WOFileUtils.remove(self, packages) Log.valide(self, "Purging Packages ") Log.info(self, "Successfully purged packages")
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"))
def default(self): # All package update apt_packages = [] packages = [] if ((not self.app.pargs.web) and (not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.mysql) and (not self.app.pargs.hhvm) and (not self.app.pargs.all) and (not self.app.pargs.wpcli) and (not self.app.pargs.redis) and (not self.app.pargs.nginxmainline)): self.app.pargs.web = True if self.app.pargs.all: self.app.pargs.web = True if self.app.pargs.web: if WOAptGet.is_installed(self, 'nginx-custom'): self.app.pargs.nginx = True else: Log.info(self, "Nginx is not already installed") self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.wpcli = True if self.app.pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): apt_packages = apt_packages + WOVariables.wo_nginx else: Log.info(self, "Nginx Stable is not already installed") if self.app.pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): apt_packages = apt_packages + WOVariables.wo_php + WOVariables.wo_php_extra else: Log.info(self, "PHP 7.2 is not installed") if self.app.pargs.hhvm: if WOAptGet.is_installed(self, 'hhvm'): apt_packages = apt_packages + WOVariables.wo_hhvm else: Log.info(self, "HHVM is not installed") if self.app.pargs.mysql: if WOAptGet.is_installed(self, 'mariadb-server'): apt_packages = apt_packages + WOVariables.wo_mysql else: Log.info(self, "MariaDB is not installed") if self.app.pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): apt_packages = apt_packages + WOVariables.wo_redis else: Log.info(self, "Redis is not installed") if self.app.pargs.wpcli: if os.path.isfile('/usr/local/bin/wp'): packages = packages + [["https://github.com/wp-cli/wp-cli/" "releases/download/v{0}/" "wp-cli-{0}.phar" "".format(WOVariables.wo_wp_cli), "/usr/local/bin/wp", "WP-CLI"]] else: Log.info(self, "WPCLI is not installed with WordOps") if len(packages) or len(apt_packages): Log.info(self, "During package update process non nginx-cached" " parts of your site may remain down") # Check prompt if (not self.app.pargs.no_prompt): start_upgrade = input("Do you want to continue:[y/N]") if start_upgrade != "Y" and start_upgrade != "y": Log.error(self, "Not starting package update") Log.info(self, "Updating packages, please wait...") if len(apt_packages): # apt-get update WOAptGet.update(self) # Update packages WOAptGet.install(self, apt_packages) # Post Actions after package updates if (set(WOVariables.wo_nginx).issubset(set(apt_packages))): WOService.restart_service(self, 'nginx') if set(WOVariables.wo_php).issubset(set(apt_packages)): WOService.restart_service(self, 'php7.2-fpm') if set(WOVariables.wo_hhvm).issubset(set(apt_packages)): WOService.restart_service(self, 'hhvm') if set(WOVariables.wo_mysql).issubset(set(apt_packages)): WOService.restart_service(self, 'mysql') if set(WOVariables.wo_redis).issubset(set(apt_packages)): WOService.restart_service(self, 'redis-server') if len(packages): if self.app.pargs.wpcli: WOFileUtils.remove(self, ['/usr/local/bin/wp']) Log.debug(self, "Downloading following: {0}".format(packages)) WODownload.download(self, packages) if self.app.pargs.wpcli: WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775) Log.info(self, "Successfully updated packages") else: self.app.args.print_help()
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)