def export_cert(self): """Export acme.sh csv certificate list""" if not WOShellExec.cmd_exec( self, "{0} ".format(WOAcme.wo_acme_exec) + "--list --listraw > /var/lib/wo/cert.csv"): Log.error(self, "Unable to export certs list") WOFileUtils.chmod(self, '/var/lib/wo/cert.csv', 0o600)
def check_acme(self): """ Check if acme.sh is properly installed, and install it if required """ if not os.path.exists('/etc/letsencrypt/acme.sh'): if os.path.exists('/opt/acme.sh'): WOFileUtils.rm(self, '/opt/acme.sh') WOGit.clone(self, 'https://github.com/Neilpang/acme.sh.git', '/opt/acme.sh', branch='master') WOFileUtils.mkdir(self, '/etc/letsencrypt/config') WOFileUtils.mkdir(self, '/etc/letsencrypt/renewal') WOFileUtils.mkdir(self, '/etc/letsencrypt/live') try: WOFileUtils.chdir(self, '/opt/acme.sh') WOShellExec.cmd_exec( self, './acme.sh --install --home /etc/letsencrypt' '--config-home /etc/letsencrypt/config' '--cert-home /etc/letsencrypt/renewal') WOShellExec.cmd_exec( self, "{0} --upgrade --auto-upgrade".format(WOAcme.wo_acme_exec)) except CommandExecutionError as e: Log.debug(self, str(e)) Log.error(self, "acme.sh installation failed") if not os.path.exists('/etc/letsencrypt/acme.sh'): Log.error(self, 'acme.sh ')
def export_cert(self): """Export acme.sh csv certificate list""" # check acme.sh is installed WOAcme.check_acme(self) acme_list = WOShellExec.cmd_exec_stdout( self, "{0} ".format(WOAcme.wo_acme_exec) + "--list --listraw") if acme_list: WOFileUtils.textwrite(self, '/var/lib/wo/cert.csv', acme_list) WOFileUtils.chmod(self, '/var/lib/wo/cert.csv', 0o600) else: Log.error(self, "Unable to export certs list")
def httpsredirect(self, wo_domain_name, acme_domains, redirect=True): """Create Nginx redirection from http to https""" wo_acme_domains = ' '.join(acme_domains) if redirect: Log.wait(self, "Adding HTTPS redirection") if WOFileUtils.enabledisable( self, '/etc/nginx/conf.d/force-ssl-{0}.conf'.format( wo_domain_name), enable=True): Log.valide(self, "Adding HTTPS redirection") return 0 else: try: sslconf = open( "/etc/nginx/conf.d/force-ssl-{0}.conf".format( wo_domain_name), encoding='utf-8', mode='w') sslconf.write( "server {\n" "\tlisten 80;\n" + "\tlisten [::]:80;\n" + "\tserver_name {0};\n".format(wo_acme_domains) + "\treturn 301 https://$host" "$request_uri;\n}") sslconf.close() except IOError as e: Log.debug(self, str(e)) Log.debug( self, "Error occured while generating " "/etc/nginx/conf.d/force-ssl-{0}.conf".format( wo_domain_name)) return 1 Log.valide(self, "Adding HTTPS redirection") return 0 else: if WOFileUtils.enabledisable( self, "/etc/nginx/conf.d/force-ssl-{0}.conf".format( wo_domain_name), enable=False): Log.info( self, "Disabled HTTPS Force Redirection for site " "{0}".format(wo_domain_name)) else: Log.info( self, "HTTPS redirection already disabled for site" "{0}".format(wo_domain_name)) return 0
def upgrade_php56(self): if WOVariables.wo_platform_distro == "ubuntu": if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}." "list".format(WOVariables.wo_platform_codename)): Log.error(self, "Unable to find PHP 5.5") else: if not(os.path.isfile(WOVariables.wo_repo_file_path) and WOFileUtils.grep(self, WOVariables.wo_repo_file_path, "php55")): Log.error(self, "Unable to find PHP 5.5") Log.info(self, "During PHP update process non nginx-cached" " parts of your site may remain down.") # Check prompt if (not self.app.pargs.no_prompt): start_upgrade = input("Do you want to continue:[y/N]") if start_upgrade != "Y" and start_upgrade != "y": Log.error(self, "Not starting PHP package update") if WOVariables.wo_platform_distro == "ubuntu": WORepo.remove(self, ppa="ppa:ondrej/php5") WORepo.add(self, ppa=WOVariables.wo_php_repo) else: WOAptGet.remove(self, ["php5-xdebug"]) WOFileUtils.searchreplace(self, WOVariables.wo_repo_file_path, "php55", "php56") Log.info(self, "Updating apt-cache, please wait...") WOAptGet.update(self) Log.info(self, "Installing packages, please wait ...") if (WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic'): WOAptGet.install(self, WOVariables.wo_php5_6 + WOVariables.wo_php_extra) else: WOAptGet.install(self, WOVariables.wo_php) if WOVariables.wo_platform_distro == "debian": WOShellExec.cmd_exec(self, "pecl install xdebug") with open("/etc/php5/mods-available/xdebug.ini", encoding='utf-8', mode='a') as myfile: myfile.write(";zend_extension=/usr/lib/php5/20131226/" "xdebug.so\n") WOFileUtils.create_symlink(self, ["/etc/php5/mods-available/" "xdebug.ini", "/etc/php5/fpm/conf.d" "/20-xedbug.ini"]) Log.info(self, "Successfully upgraded from PHP 5.5 to PHP 5.6")
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 deploycert(self, wo_domain_name): """Deploy Let's Encrypt certificates with acme.sh""" if not os.path.isfile('/etc/letsencrypt/renewal/{0}_ecc/fullchain.cer'. format(wo_domain_name)): Log.error(self, 'Certificate not found. Deployment canceled') Log.debug(self, "Cert deployment for domain: {0}".format(wo_domain_name)) try: Log.wait(self, "Deploying SSL cert") if WOShellExec.cmd_exec( self, "mkdir -p {0}/{1} && {2} --install-cert -d {1} --ecc " "--cert-file {0}/{1}/cert.pem --key-file {0}/{1}/key.pem " "--fullchain-file {0}/{1}/fullchain.pem " "--ca-file {0}/{1}/ca.pem --reloadcmd \"nginx -t && " "service nginx restart\" ".format(WOVar.wo_ssl_live, wo_domain_name, WOAcme.wo_acme_exec)): Log.valide(self, "Deploying SSL cert") else: Log.failed(self, "Deploying SSL cert") Log.error(self, "Unable to deploy certificate") if os.path.isdir('/var/www/{0}/conf/nginx'.format(wo_domain_name)): sslconf = open( "/var/www/{0}/conf/nginx/ssl.conf".format(wo_domain_name), encoding='utf-8', mode='w') sslconf.write("listen 443 ssl http2;\n" "listen [::]:443 ssl http2;\n" "ssl_certificate {0}/{1}/fullchain.pem;\n" "ssl_certificate_key {0}/{1}/key.pem;\n" "ssl_trusted_certificate {0}/{1}/ca.pem;\n" "ssl_stapling_verify on;\n".format( WOVar.wo_ssl_live, wo_domain_name)) sslconf.close() if not WOFileUtils.grep(self, '/var/www/22222/conf/nginx/ssl.conf', '/etc/letsencrypt'): Log.info(self, "Securing WordOps backend with current cert") sslconf = open("/var/www/22222/conf/nginx/ssl.conf", encoding='utf-8', mode='w') sslconf.write("ssl_certificate {0}/{1}/fullchain.pem;\n" "ssl_certificate_key {0}/{1}/key.pem;\n" "ssl_trusted_certificate {0}/{1}/ca.pem;\n" "ssl_stapling_verify on;\n".format( WOVar.wo_ssl_live, wo_domain_name)) sslconf.close() WOGit.add(self, ["/etc/letsencrypt"], msg="Adding letsencrypt folder") except IOError as e: Log.debug(self, str(e)) Log.debug(self, "Error occured while generating " "ssl.conf") return 0
def upgrade_php56(self): if WOVariables.wo_platform_distro == "ubuntu": if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}." "list".format(WOVariables.wo_platform_codename)): Log.error(self, "Unable to find PHP 5.5") else: if not(os.path.isfile(WOVariables.wo_repo_file_path) and WOFileUtils.grep(self, WOVariables.wo_repo_file_path, "php55")): Log.error(self, "Unable to find PHP 5.5") Log.info(self, "During PHP update process non nginx-cached" " parts of your site may remain down.") # Check prompt if (not self.app.pargs.no_prompt): start_upgrade = input("Do you want to continue:[y/N]") if start_upgrade != "Y" and start_upgrade != "y": Log.error(self, "Not starting PHP package update") if WOVariables.wo_platform_distro == "ubuntu": WORepo.remove(self, ppa="ppa:ondrej/php5") WORepo.add(self, ppa=WOVariables.wo_php_repo) Log.info(self, "Updating apt-cache, please wait...") WOAptGet.update(self) Log.info(self, "Installing packages, please wait ...") if (WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic'): WOAptGet.install(self, WOVariables.wo_php + WOVariables.wo_php_extra) else: WOAptGet.install(self, WOVariables.wo_php) if WOVariables.wo_platform_distro == "debian": WOShellExec.cmd_exec(self, "pecl install xdebug")
def archivedcertificatehandle(self, domain, acme_domains): Log.warn( self, "You already have an existing certificate " "for the domain requested.\n" "(ref: {0}/" "{1}_ecc/{1}.conf)".format(WOVar.wo_ssl_archive, domain) + "\nPlease select an option from below?" "\n\t1: Reinstall existing certificate" "\n\t2: Issue a new certificate to replace " "the current one (limit ~5 per 7 days)" "") check_prompt = input( "\nType the appropriate number [1-2] or any other key to cancel: ") if not os.path.isfile("{0}/{1}/fullchain.pem".format( WOVar.wo_ssl_live, domain)): Log.debug( self, "{0}/{1}/fullchain.pem file is missing.".format( WOVar.wo_ssl_live, domain)) check_prompt = "2" if check_prompt == "1": Log.info(self, "Reinstalling SSL cert with acme.sh") ssl = WOAcme.deploycert(self, domain) if ssl: SSL.httpsredirect(self, domain, acme_domains) elif (check_prompt == "2"): Log.info(self, "Issuing new SSL cert with acme.sh") ssl = WOShellExec.cmd_exec( self, "/etc/letsencrypt/acme.sh " "--config-home '/etc/letsencrypt/config' " "--renew -d {0} --ecc --force".format(domain)) if ssl: WOAcme.deploycert(self, domain) else: Log.error(self, "Operation cancelled by user.") if os.path.isfile("{0}/conf/nginx/ssl.conf".format(domain)): Log.info(self, "Existing ssl.conf . Backing it up ..") WOFileUtils.mvfile( self, "/var/www/{0}/conf/nginx/ssl.conf".format(domain), '/var/www/{0}/conf/nginx/ssl.conf.bak'.format(domain)) return ssl
def hashbucket(self): # Check Nginx Hashbucket error sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) output, error_output = sub.communicate() if 'server_names_hash_bucket_size' not in str(error_output): return True count = 0 # Get the list of sites-availble sites_list = os.listdir("/etc/nginx/sites-enabled/") # Count the number of characters in site names for site in sites_list: count = sum([count, len(site)]) # Calculate Nginx hash bucket size ngx_calc = math.trunc(sum([math.log(count, 2), 2])) ngx_hash = math.trunc(math.pow(2, ngx_calc)) # Replace hashbucket in Nginx.conf file if WOFileUtils.grepcheck(self, "/etc/nginx/nginx.conf", "# server_names_hash_bucket_size 64;"): ngxconf = open("/etc/nginx/conf.d/hashbucket.conf", encoding='utf-8', mode='w') ngxconf.write("\tserver_names_hash_bucket_size {0};".format(ngx_hash)) ngxconf.close() elif WOFileUtils.grepcheck(self, "/etc/nginx/nginx/conf", "server_names_hash_bucket_size"): for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1): if "server_names_hash_bucket_size" in line: print("\tserver_names_hash_bucket_size {0};".format(ngx_hash)) else: print(line, end='') else: ngxconf = open("/etc/nginx/conf.d/hashbucket.conf", encoding='utf-8', mode='w') ngxconf.write("\tserver_names_hash_bucket_size {0};".format(ngx_hash)) ngxconf.close()
def removeconf(self, domain): sslconf = ("/var/www/{0}/conf/nginx/ssl.conf" .format(domain)) sslforce = ("/etc/nginx/conf.d/force-ssl-{0}.conf" .format(domain)) acmedir = [ '{0}'.format(sslforce), '{0}'.format(sslconf), '{0}/{1}_ecc'.format(WOVar.wo_ssl_archive, domain), '{0}.disabled'.format(sslconf), '{0}.disabled' .format(sslforce), '{0}/{1}' .format(WOVar.wo_ssl_live, domain), '/etc/letsencrypt/shared/{0}.conf'.format(domain)] wo_domain = domain # check acme.sh is installed WOAcme.check_acme(self) if WOAcme.cert_check(self, wo_domain): Log.info(self, "Removing Acme configuration") Log.debug(self, "Removing Acme configuration") try: WOShellExec.cmd_exec( self, "{0} ".format(WOAcme.wo_acme_exec) + "--remove -d {0} --ecc".format(domain)) except CommandExecutionError as e: Log.debug(self, "{0}".format(e)) Log.error(self, "Cert removal failed") # remove all files and directories for dir in acmedir: if os.path.exists('{0}'.format(dir)): WOFileUtils.rm(self, '{0}'.format(dir)) # find all broken symlinks WOFileUtils.findBrokenSymlink(self, "/var/www") else: if os.path.islink("{0}".format(sslconf)): WOFileUtils.remove_symlink(self, "{0}".format(sslconf)) WOFileUtils.rm(self, '{0}'.format(sslforce)) if WOFileUtils.grepcheck(self, '/var/www/22222/conf/nginx/ssl.conf', '{0}'.format(domain)): Log.info( self, "Setting back default certificate for WordOps backend") with open("/var/www/22222/conf/nginx/" "ssl.conf", "w") as ssl_conf_file: ssl_conf_file.write("ssl_certificate " "/var/www/22222/cert/22222.crt;\n" "ssl_certificate_key " "/var/www/22222/cert/22222.key;\n")
def add(self): """Swap addition with WordOps""" # Get System RAM and SWAP details wo_ram = psutil.virtual_memory().total / (1024 * 1024) wo_swap = psutil.swap_memory().total / (1024 * 1024) if wo_ram < 512: if wo_swap < 1000: Log.info(self, "Adding SWAP file, please wait...") # Install dphys-swapfile WOAptGet.update(self) WOAptGet.install(self, ["dphys-swapfile"]) # Stop service WOShellExec.cmd_exec(self, "service dphys-swapfile stop") # Remove Default swap created WOShellExec.cmd_exec(self, "/sbin/dphys-swapfile uninstall") # Modify Swap configuration if os.path.isfile("/etc/dphys-swapfile"): WOFileUtils.searchreplace(self, "/etc/dphys-swapfile", "#CONF_SWAPFILE=/var/swap", "CONF_SWAPFILE=/wo-swapfile") WOFileUtils.searchreplace(self, "/etc/dphys-swapfile", "#CONF_MAXSWAP=2048", "CONF_MAXSWAP=1024") WOFileUtils.searchreplace(self, "/etc/dphys-swapfile", "#CONF_SWAPSIZE=", "CONF_SWAPSIZE=1024") else: with open("/etc/dphys-swapfile", 'w') as conffile: conffile.write("CONF_SWAPFILE=/wo-swapfile\n" "CONF_SWAPSIZE=1024\n" "CONF_MAXSWAP=1024\n") # Create swap file WOShellExec.cmd_exec(self, "service dphys-swapfile start")
def disable(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() 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, "Disable domain {0:10} \t" .format(wo_domain), end='') if not os.path.isfile('/etc/nginx/sites-enabled/{0}' .format(wo_domain)): Log.debug(self, "Site {0} already disabled".format(wo_domain)) Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE + "]") else: WOFileUtils.remove_symlink(self, '/etc/nginx/sites-enabled/{0}' .format(wo_domain)) WOGit.add(self, ["/etc/nginx"], msg="Disabled {0} " .format(wo_domain)) updateSiteInfo(self, wo_domain, enabled=False) 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 hashbucket(self): # Check Nginx Hashbucket error sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) output, error_output = sub.communicate() if 'server_names_hash_bucket_size' not in str(error_output): return True count = 0 # Get the list of sites-availble sites_list = os.listdir("/etc/nginx/sites-enabled/") # Count the number of characters in site names for site in sites_list: count = sum([count, len(site)]) # Calculate Nginx hash bucket size ngx_calc = math.trunc(sum([math.log(count, 2), 2])) ngx_hash = math.trunc(math.pow(2, ngx_calc)) # Replace hashbucket in Nginx.conf file if WOFileUtils.grep(self, "/etc/nginx/nginx.conf", "server_names_hash_bucket_size"): for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1): if "server_names_hash_bucket_size" in line: print("\tserver_names_hash_bucket_size {0};".format(ngx_hash)) else: print(line, end='') else: WOFileUtils.searchreplace( self, '/etc/nginx/nginx.conf', "gzip_disable \"msie6\";", "gzip_disable \"msie6\";\n" "\tserver_names_hash_bucket_size {0};\n".format(ngx_hash))
def setupletsencrypt(self, acme_domains, acmedata): """Issue SSL certificates with acme.sh""" # check acme.sh is installed WOAcme.check_acme(self) # define variables all_domains = '\' -d \''.join(acme_domains) wo_acme_dns = acmedata['acme_dns'] keylenght = acmedata['keylength'] if acmedata['dns'] is True: acme_mode = "--dns {0}".format(wo_acme_dns) validation_mode = "DNS mode with {0}".format(wo_acme_dns) if acmedata['dnsalias'] is True: acme_mode = acme_mode + \ " --challenge-alias {0}".format(acmedata['acme_alias']) else: acme_mode = "-w /var/www/html" validation_mode = "Webroot challenge" Log.debug(self, "Validation : Webroot mode") if not os.path.isdir('/var/www/html/.well-known/acme-challenge'): WOFileUtils.mkdir(self, '/var/www/html/.well-known/acme-challenge') WOFileUtils.chown(self, '/var/www/html/.well-known', 'www-data', 'www-data', recursive=True) WOFileUtils.chmod(self, '/var/www/html/.well-known', 0o750, recursive=True) Log.info(self, "Validation mode : {0}".format(validation_mode)) Log.wait(self, "Issuing SSL cert with acme.sh") if not WOShellExec.cmd_exec( self, "{0} ".format(WOAcme.wo_acme_exec) + "--issue -d '{0}' {1} -k {2} -f".format( all_domains, acme_mode, keylenght)): Log.failed(self, "Issuing SSL cert with acme.sh") if acmedata['dns'] is True: Log.error( self, "Please make sure your properly " "set your DNS API credentials for acme.sh\n" "If you are using sudo, use \"sudo -E wo\"") return False else: Log.error( self, "Your domain is properly configured " "but acme.sh was unable to issue certificate.\n" "You can find more informations in " "/var/log/wo/wordops.log") return False else: Log.valide(self, "Issuing SSL cert with acme.sh") return True
def default(self, disp_msg=False): # All package update apt_packages = [] packages = [] self.msg = [] pargs = self.app.pargs if ((not pargs.web) and (not pargs.nginx) and (not pargs.php) and (not pargs.php73) and (not pargs.mysql) and (not pargs.ngxblocker) and (not pargs.all) and (not pargs.wpcli) and (not pargs.netdata) and (not pargs.composer) and (not pargs.phpmyadmin) and (not pargs.dashboard) and (not pargs.redis)): pargs.web = True pargs.admin = True if pargs.all: pargs.web = True pargs.admin = True pargs.redis = True pargs.php73 = True pargs.ngxblocker = True if pargs.web: pargs.nginx = True pargs.php = True pargs.mysql = True pargs.wpcli = True if pargs.admin: pargs.netdata = True pargs.composer = True pargs.dashboard = True pargs.phpmyadmin = True pargs.wpcli = True # nginx if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): apt_packages = apt_packages + WOVar.wo_nginx else: if os.path.isfile('/usr/sbin/nginx'): Log.info(self, "Updating Nginx templates") post_pref(self, WOVar.wo_nginx, []) else: Log.info(self, "Nginx Stable is not already installed") # php 7.2 if pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): apt_packages = apt_packages + WOVar.wo_php + \ WOVar.wo_php_extra else: Log.info(self, "PHP 7.2 is not installed") # php 7.3 if pargs.php73: if WOAptGet.is_installed(self, 'php7.3-fpm'): apt_packages = apt_packages + WOVar.wo_php73 + \ WOVar.wo_php_extra else: Log.info(self, "PHP 7.3 is not installed") # mysql if pargs.mysql: if WOShellExec.cmd_exec(self, 'mysqladmin ping'): apt_packages = apt_packages + ['mariadb-server'] else: Log.info(self, "MariaDB is not installed") # redis if pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): apt_packages = apt_packages + ['redis-server'] else: Log.info(self, "Redis is not installed") # wp-cli if pargs.wpcli: if os.path.isfile('/usr/local/bin/wp'): packages = packages + [[ "https://github.com/wp-cli/wp-cli/" "releases/download/v{0}/" "wp-cli-{0}.phar".format(WOVar.wo_wp_cli), "/usr/local/bin/wp", "WP-CLI"]] else: Log.info(self, "WPCLI is not installed with WordOps") # netdata if pargs.netdata: # detect static binaries install if os.path.isdir('/opt/netdata'): packages = packages + [[ 'https://my-netdata.io/kickstart-static64.sh', '/var/lib/wo/tmp/kickstart.sh', 'Netdata']] # detect install from source elif os.path.isdir('/etc/netdata'): packages = packages + [[ 'https://my-netdata.io/kickstart.sh', '/var/lib/wo/tmp/kickstart.sh', 'Netdata']] else: Log.info(self, 'Netdata us not installed') # wordops dashboard if pargs.dashboard: if (os.path.isfile('/var/www/22222/htdocs/index.php') or os.path.isfile('/var/www/22222/htdocs/index.html')): packages = packages + [[ "https://github.com/WordOps/wordops-dashboard/" "releases/download/v{0}/wordops-dashboard.tar.gz" .format(WOVar.wo_dashboard), "/var/lib/wo/tmp/wo-dashboard.tar.gz", "WordOps Dashboard"]] else: Log.info(self, 'WordOps dashboard is not installed') # phpmyadmin if pargs.phpmyadmin: if os.path.isdir('/var/www/22222/htdocs/db/pma'): packages = packages + [[ "https://files.phpmyadmin.net" "/phpMyAdmin/{0}/phpMyAdmin-{0}-" "all-languages.tar.gz" .format(WOVar.wo_phpmyadmin), "/var/lib/wo/tmp/pma.tar.gz", "PHPMyAdmin"]] else: Log.info(self, "phpMyAdmin isn't installed") # composer if pargs.composer: if os.path.isfile('/usr/local/bin/composer'): packages = packages + [[ "https://getcomposer.org/installer", "/var/lib/wo/tmp/composer-install", "Composer"]] else: Log.info(self, "Composer isn't installed") # ngxblocker if pargs.ngxblocker: if os.path.exists('/usr/local/sbin/install-ngxblocker'): packages = packages + [[ 'https://raw.githubusercontent.com/mitchellkrogza/' 'nginx-ultimate-bad-bot-blocker/master/update-ngxblocker', '/usr/local/sbin/update-ngxblocker', 'ngxblocker' ]] else: Log.info(self, "ngxblocker is not installed") if ((not (apt_packages)) and (not(packages))): self.app.args.print_help() else: pre_stack(self) if (apt_packages): if (("php7.2-fpm" not in apt_packages) and ("php7.3-fpm" not in apt_packages) and ("nginx-custom" not in apt_packages) and ("mariadb-server" not in apt_packages)): pass else: Log.info( self, "Your sites may be down for few seconds if " "you are upgrading Nginx, PHP-FPM, MariaDB or Redis") # Check prompt if ((not pargs.no_prompt) and (not pargs.force)): start_upgrade = input("Do you want to continue:[y/N]") if start_upgrade != "Y" and start_upgrade != "y": Log.error(self, "Not starting package update") Log.wait(self, "Updating APT packages") # apt-get update WOAptGet.update(self) Log.valide(self, "Updating APT packages") # additional pre_pref if "nginx-custom" in apt_packages: pre_pref(self, WOVar.wo_nginx) if "php7.2-fpm" in apt_packages: WOAptGet.remove(self, ['php7.2-fpm'], auto=False, purge=True) if "php7.3-fpm" in apt_packages: WOAptGet.remove(self, ['php7.3-fpm'], auto=False, purge=True) # check if nginx upgrade is blocked if os.path.isfile( '/etc/apt/preferences.d/nginx-block'): post_pref(self, WOVar.wo_nginx, [], True) # upgrade packages WOAptGet.install(self, apt_packages) Log.wait(self, "Configuring APT Packages") post_pref(self, apt_packages, [], True) if "mariadb-server" in apt_packages: WOShellExec.cmd_exec(self, 'mysql_upgrade') Log.valide(self, "Configuring APT Packages") # Post Actions after package updates if (packages): if pargs.wpcli: WOFileUtils.rm(self, '/usr/local/bin/wp') if pargs.netdata: WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh') if pargs.ngxblocker: WOFileUtils.rm(self, '/usr/local/sbin/update-ngxblocker') if pargs.dashboard: if os.path.isfile('/var/www/22222/htdocs/index.php'): WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php') if os.path.isfile('/var/www/22222/htdocs/index.html'): WOFileUtils.rm( self, '/var/www/22222/htdocs/index.html') Log.debug(self, "Downloading following: {0}".format(packages)) WODownload.download(self, packages) if pargs.wpcli: WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775) if pargs.ngxblocker: WOFileUtils.chmod( self, '/usr/local/sbin/update-ngxblocker', 0o700) WOShellExec.cmd_exec( self, '/usr/local/sbin/update-ngxblocker -nq' ) # Netdata if pargs.netdata: Log.wait(self, "Upgrading Netdata") # detect static binaries install if os.path.isdir('/opt/netdata'): if os.path.exists( '/opt/netdata/usr/libexec/' 'netdata/netdata-updater.sh'): WOShellExec.cmd_exec( self, "bash /opt/netdata/usr/" "libexec/netdata/netdata-" "updater.sh") else: WOShellExec.cmd_exec( self, "bash /var/lib/wo/tmp/kickstart.sh") # detect install from source elif os.path.isdir('/etc/netdata'): if os.path.exists( '/usr/libexec/netdata/netdata-updater.sh'): WOShellExec.cmd_exec( self, 'bash /usr/libexec/netdata/netdata-updater.sh') else: WOShellExec.cmd_exec( self, "bash /var/lib/wo/tmp/kickstart.sh") Log.valide(self, "Upgrading Netdata") if pargs.dashboard: post_pref( self, [], [["https://github.com/WordOps" "/wordops-dashboard/" "releases/download/v{0}/" "wordops-dashboard.tar.gz" .format(WOVar.wo_dashboard), "/var/lib/wo/tmp/wo-dashboard.tar.gz", "WordOps Dashboard"]]) if pargs.composer: Log.wait(self, "Upgrading Composer") if WOShellExec.cmd_exec( self, '/usr/bin/php -v'): WOShellExec.cmd_exec( self, "php -q /var/lib/wo" "/tmp/composer-install " "--install-dir=/var/lib/wo/tmp/") shutil.copyfile('/var/lib/wo/tmp/composer.phar', '/usr/local/bin/composer') WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775) Log.valide(self, "Upgrading Composer ") if pargs.phpmyadmin: Log.wait(self, "Upgrading phpMyAdmin") WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz', '/var/lib/wo/tmp/') shutil.copyfile(('{0}22222/htdocs/db/pma' '/config.inc.php' .format(WOVar.wo_webroot)), ('/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/config.inc.php' .format(WOVar.wo_phpmyadmin)) ) WOFileUtils.rm(self, '{0}22222/htdocs/db/pma' .format(WOVar.wo_webroot)) shutil.move('/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/' .format(WOVar.wo_phpmyadmin), '{0}22222/htdocs/db/pma/' .format(WOVar.wo_webroot)) WOFileUtils.chown(self, "{0}22222/htdocs" .format(WOVar.wo_webroot), 'www-data', 'www-data', recursive=True) Log.valide(self, "Upgrading phpMyAdmin") Log.info(self, "Successfully updated packages")
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 debug_php(self): """Start/Stop PHP debug""" # PHP global debug start if (self.app.pargs.php == 'on' and not self.app.pargs.site_name): if not (WOShellExec.cmd_exec( self, "sed -n \"/upstream php" "{/,/}/p \" /etc/nginx/" "conf.d/upstream.conf " "| grep 9001")): Log.info(self, "Enabling PHP debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([( 'upstream', 'php', ), 'server'], '127.0.0.1:9001') nc.savef('/etc/nginx/conf.d/upstream.conf') # Enable xdebug WOFileUtils.searchreplace( self, "/etc/{0}/mods-available/".format("php/7.2" if ( WOVariables.wo_platform_distro == 'ubuntu' ) else "php/7.2") + "xdebug.ini", ";zend_extension", "zend_extension") # Fix slow log is not enabled default in PHP5.6 config = configparser.ConfigParser() config.read( '/etc/{0}/fpm/pool.d/debug.conf'.format("php/7.2" if ( WOVariables.wo_platform_distro == 'ubuntu' ) else "php5")) config['debug']['slowlog'] = '/var/log/{0}/slow.log'.format( "php/7.2" if (WOVariables.wo_platform_distro == 'ubuntu' ) else "php5") config['debug']['request_slowlog_timeout'] = '10s' with open( '/etc/{0}/fpm/pool.d/debug.conf'.format("php/7.2" if ( WOVariables.wo_platform_distro == 'ubuntu' ) else "php5"), encoding='utf-8', mode='w') as confifile: Log.debug( self, "Writting debug.conf configuration into " "/etc/{0}/fpm/pool.d/debug.conf".format("php/7.2" if ( WOVariables.wo_platform_distro == 'ubuntu' ) else "php5")) config.write(confifile) self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP debug is already enabled") self.msg = self.msg + [ '/var/log/{0}/slow.log'.format("php/7.2" if ( WOVariables.wo_platform_distro == 'ubuntu') else "php5") ] # PHP global debug stop elif (self.app.pargs.php == 'off' and not self.app.pargs.site_name): if WOShellExec.cmd_exec( self, " sed -n \"/upstream php {/,/}/p\" " "/etc/nginx/conf.d/upstream.conf " "| grep 9001"): Log.info(self, "Disabling PHP debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([( 'upstream', 'php', ), 'server'], '127.0.0.1:9000') nc.savef('/etc/nginx/conf.d/upstream.conf') # Disable xdebug WOFileUtils.searchreplace( self, "/etc/{0}/mods-available/".format("php/7.2" if ( WOVariables.wo_platform_distro == 'ubuntu' ) else "php5") + "xdebug.ini", "zend_extension", ";zend_extension") self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP debug is already disabled")
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 default(self): """Default function of log show""" self.msg = [] if self.app.pargs.php: self.app.pargs.nginx = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (not self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.fpm = True self.app.pargs.mysql = True self.app.pargs.access = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.wp = True self.app.pargs.access = True self.app.pargs.mysql = True if self.app.pargs.nginx and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*error.log"] if self.app.pargs.access and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*access.log"] if self.app.pargs.fpm: open('/var/log/php/7.2/slow.log', 'a').close() open('/var/log/php7.2-fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log' ] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if WOVar.wo_mysql_host == "localhost": if os.path.isfile('/var/log/mysql/mysql-slow.log'): self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] else: Log.info(self, "MySQL slow-log not found, skipped") else: Log.warn( self, "Remote MySQL found, WordOps does not support" "remote MySQL servers or log files") if self.app.pargs.site_name: webroot = "{0}{1}".format(WOVar.wo_webroot, self.app.pargs.site_name) if not os.path.isdir(webroot): Log.error(self, "Site not present, quitting") if self.app.pargs.access: self.msg = self.msg + [ "{0}/{1}/logs/access.log".format(WOVar.wo_webroot, self.app.pargs.site_name) ] if self.app.pargs.nginx: self.msg = self.msg + [ "{0}/{1}/logs/error.log".format(WOVar.wo_webroot, self.app.pargs.site_name) ] if self.app.pargs.wp: if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)): if not os.path.isfile( '{0}/logs/debug.log'.format(webroot)): if not os.path.isfile('{0}/htdocs/wp-content/debug.log' .format(webroot)): open("{0}/htdocs/wp-content/debug.log".format( webroot), encoding='utf-8', mode='a').close() WOShellExec.cmd_exec( self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, WOVar.wo_php_user)) # create symbolic link for debug log WOFileUtils.create_symlink(self, [ "{0}/htdocs/wp-content/" "debug.log".format(webroot), '{0}/logs/debug.log'.format(webroot) ]) self.msg = self.msg + [ "{0}/{1}/logs/debug.log".format( WOVar.wo_webroot, self.app.pargs.site_name) ] else: Log.info( self, "Site is not WordPress site, skipping " "WordPress logs") watch_list = [] for w_list in self.msg: watch_list = watch_list + glob.glob(w_list) logwatch(self, watch_list)
def default(self): """Default function of log Mail""" self.msg = [] if self.app.pargs.php: self.app.pargs.nginx = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (not self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.fpm = True self.app.pargs.mysql = True self.app.pargs.access = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.wp = True self.app.pargs.access = True self.app.pargs.mysql = True if self.app.pargs.nginx and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*error.log"] if self.app.pargs.access and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*access.log"] if self.app.pargs.fpm: open('/var/log/php/7.2/slow.log', 'a').close() open('/var/log/php7.2-fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log' ] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if WOVar.wo_mysql_host == "localhost": if os.path.isfile('/var/log/mysql/mysql-slow.log'): self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] else: Log.info(self, "MySQL slow-log not found, skipped") else: Log.warn( self, "Remote MySQL found, WordOps does not support" "remote MySQL servers or log files") if self.app.pargs.site_name: webroot = "{0}{1}".format(WOVar.wo_webroot, self.app.pargs.site_name) if not os.path.isdir(webroot): Log.error(self, "Site not present, quitting") if self.app.pargs.access: self.msg = self.msg + [ "{0}/{1}/logs/access.log".format(WOVar.wo_webroot, self.app.pargs.site_name) ] if self.app.pargs.nginx: self.msg = self.msg + [ "{0}/{1}/logs/error.log".format(WOVar.wo_webroot, self.app.pargs.site_name) ] if self.app.pargs.wp: if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)): if not os.path.isfile( '{0}/logs/debug.log'.format(webroot)): if not os.path.isfile('{0}/htdocs/wp-content/debug.log' .format(webroot)): open("{0}/htdocs/wp-content/debug.log".format( webroot), encoding='utf-8', mode='a').close() WOShellExec.cmd_exec( self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, WOVar.wo_php_user)) # create symbolic link for debug log WOFileUtils.create_symlink(self, [ "{0}/htdocs/wp-content/" "debug.log".format(webroot), '{0}/logs/debug.log'.format(webroot) ]) self.msg = self.msg + [ "{0}/{1}/logs/debug.log".format( WOVar.wo_webroot, self.app.pargs.site_name) ] else: Log.info( self, "Site is not WordPress site, skipping " "WordPress logs") mail_list = [] for m_list in self.msg: mail_list = mail_list + glob.glob(m_list) for tomail in self.app.pargs.to: Log.info(self, "Sending mail to {0}".format(tomail[0])) WOSendMail("wordops", tomail[0], "{0} Log Files".format(WOVar.wo_fqdn), "Hi,\n The requested logfiles are attached." "\n\nBest regards,\nYour WordOps worker", files=mail_list, port=25, isTls=False)
def sync(self): """ 1. reads database information from wp/wo-config.php 2. updates records into wo database accordingly. """ Log.info(self, "Synchronizing wo database, please wait...") sites = getAllsites(self) if not sites: pass for site in sites: if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: wo_site_webroot = site.site_path # Read config files configfiles = glob.glob(wo_site_webroot + '/*-config.php') # search for wp-config.php inside htdocs/ if not configfiles: Log.debug( self, "Config files not found in {0}/ ".format( wo_site_webroot)) if site.site_type != 'mysql': Log.debug( self, "Searching wp-config.php in {0}/htdocs/".format( wo_site_webroot)) configfiles = glob.glob(wo_site_webroot + '/htdocs/wp-config.php') if configfiles: if WOFileUtils.isexist(self, configfiles[0]): wo_db_name = (WOFileUtils.grep(self, configfiles[0], 'DB_NAME').split(',') [1].split(')')[0].strip().replace( '\'', '')) wo_db_user = (WOFileUtils.grep(self, configfiles[0], 'DB_USER').split(',') [1].split(')')[0].strip().replace( '\'', '')) wo_db_pass = (WOFileUtils.grep( self, configfiles[0], 'DB_PASSWORD').split(',')[1].split(')') [0].strip().replace('\'', '')) wo_db_host = (WOFileUtils.grep(self, configfiles[0], 'DB_HOST').split(',') [1].split(')')[0].strip().replace( '\'', '')) # Check if database really exist try: if not WOMysql.check_db_exists(self, wo_db_name): # Mark it as deleted if not exist wo_db_name = 'deleted' wo_db_user = '******' wo_db_pass = '******' except StatementExcecutionError as e: Log.debug(self, str(e)) except Exception as e: Log.debug(self, str(e)) if site.db_name != wo_db_name: # update records if any mismatch found Log.debug( self, "Updating wo db record for {0}".format( site.sitename)) updateSiteInfo(self, site.sitename, db_name=wo_db_name, db_user=wo_db_user, db_password=wo_db_pass, db_host=wo_db_host) else: Log.debug( self, "Config files not found for {0} ".format( site.sitename))
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 debug_php73(self): """Start/Stop PHP debug""" # PHP global debug start if (self.app.pargs.php73 == 'on' and not self.app.pargs.site_name): if not (WOShellExec.cmd_exec( self, "sed -n \"/upstream php73" "{/,/}/p \" /etc/nginx/" "conf.d/upstream.conf " "| grep 9173")): Log.info(self, "Enabling PHP 7.3 debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([( 'upstream', 'php73', ), 'server'], '127.0.0.1:9173') nc.savef('/etc/nginx/conf.d/upstream.conf') # Enable xdebug WOFileUtils.searchreplace( self, "/etc/php/7.3/mods-available/" "xdebug.ini", ";zend_extension", "zend_extension") # Fix slow log is not enabled default in PHP5.6 config = configparser.ConfigParser() config.read('/etc/php/7.3/fpm/pool.d/debug.conf') config['debug']['slowlog'] = '/var/log/php/7.3/slow.log' config['debug']['request_slowlog_timeout'] = '10s' with open('/etc/php/7.3/fpm/pool.d/debug.conf', encoding='utf-8', mode='w') as confifile: Log.debug( self, "Writting debug.conf configuration into " "/etc/php/7.3/fpm/pool.d/debug.conf") config.write(confifile) self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP debug is already enabled") self.msg = self.msg + ['/var/log/php/7.3/slow.log'] # PHP global debug stop elif (self.app.pargs.php73 == 'off' and not self.app.pargs.site_name): if WOShellExec.cmd_exec( self, " sed -n \"/upstream " "php72 {/,/}/p\" " "/etc/nginx/conf.d/upstream.conf " "| grep 9172"): Log.info(self, "Disabling PHP 7.2 debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([( 'upstream', 'php72', ), 'server'], 'unix:/var/run/php/php72-fpm.sock') nc.savef('/etc/nginx/conf.d/upstream.conf') # Disable xdebug WOFileUtils.searchreplace( self, "/etc/php/7.2/mods-available/" "xdebug.ini", "zend_extension", ";zend_extension") self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP 7.2 debug is already disabled")
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.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 = [] nginx_packages = [] empty_packages = [] pargs = self.app.pargs if ((not pargs.web) and (not pargs.nginx) and (not pargs.php) and (not pargs.php73) and (not pargs.mysql) and (not pargs.all) and (not pargs.wpcli) and (not pargs.netdata) and (not pargs.composer) and (not pargs.phpmyadmin) and (not pargs.dashboard) and (not pargs.redis)): pargs.web = True if pargs.all: pargs.web = True pargs.netdata = True pargs.composer = True pargs.dashboard = True pargs.phpmyadmin = True pargs.redis = True pargs.wpcli = True pargs.php73 = True if pargs.web: if WOAptGet.is_installed(self, 'nginx-custom'): pargs.nginx = True else: Log.info(self, "Nginx is not already installed") pargs.php = True pargs.mysql = True pargs.wpcli = True if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): apt_packages = apt_packages + WOVariables.wo_nginx nginx_packages = nginx_packages + WOVariables.wo_nginx else: Log.info(self, "Nginx Stable is not already installed") if pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): if not WOAptGet.is_installed(self, 'php7.3-fpm'): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php else: Log.info(self, "PHP 7.2 is not installed") if pargs.php73: if WOAptGet.is_installed(self, 'php7.3-fpm'): if not WOAptGet.is_installed(self, 'php7.2-fpm'): apt_packages = apt_packages + WOVariables.wo_php73 + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php73 else: Log.info(self, "PHP 7.3 is not installed") if pargs.mysql: if WOAptGet.is_installed(self, 'mariadb-server'): apt_packages = apt_packages + WOVariables.wo_mysql else: Log.info(self, "MariaDB is not installed") if pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): apt_packages = apt_packages + WOVariables.wo_redis else: Log.info(self, "Redis is not installed") if pargs.wpcli: if os.path.isfile('/usr/local/bin/wp'): packages = packages + [[ "https://github.com/wp-cli/wp-cli/" "releases/download/v{0}/" "wp-cli-{0}.phar" "".format(WOVariables.wo_wp_cli), "/usr/local/bin/wp", "WP-CLI" ]] else: Log.info(self, "WPCLI is not installed with WordOps") if pargs.netdata: if os.path.isdir('/opt/netdata'): packages = packages + [[ 'https://my-netdata.io/' 'kickstart-static64.sh', '/var/lib/wo/tmp/kickstart.sh', 'Netdata' ]] if pargs.dashboard: if os.path.isfile('/var/www/22222/htdocs/index.php'): packages = packages + \ [["https://github.com/WordOps/wordops-dashboard/" "releases/download/v{0}/wordops-dashboard.tar.gz" .format(WOVariables.wo_dashboard), "/var/lib/wo/tmp/wo-dashboard.tar.gz", "WordOps Dashboard"]] if pargs.phpmyadmin: if os.path.isdir('/var/www/22222/htdocs/db/pma'): packages = packages + \ [["https://files.phpmyadmin.net" "/phpMyAdmin/{0}/" "phpMyAdmin-{0}-" "all-languages" ".tar.gz".format(WOVariables.wo_phpmyadmin), "/var/lib/wo/tmp/pma.tar.gz", "PHPMyAdmin"]] else: Log.error(self, "phpMyAdmin isn't installed") if pargs.composer: if os.path.isfile('/usr/local/bin/composer'): packages = packages + [[ "https://getcomposer.org/installer", "/var/lib/wo/tmp/composer-install", "Composer" ]] else: Log.error(self, "Composer isn't installed") if len(apt_packages) or len(packages): if len(apt_packages): Log.info( self, "Your site may be down for few seconds if " "you are upgrading Nginx, PHP-FPM, MariaDB or Redis") # Check prompt if ((not pargs.no_prompt) and (not pargs.force)): start_upgrade = input("Do you want to continue:[y/N]") if start_upgrade != "Y" and start_upgrade != "y": Log.error(self, "Not starting package update") Log.info(self, "Updating APT packages, please wait...") if set(WOVariables.wo_nginx).issubset(set(apt_packages)): pre_pref(self, ["nginx-custom", "nginx-wo"]) # apt-get update WOAptGet.update(self) if set(WOVariables.wo_php).issubset(set(apt_packages)): WOAptGet.remove(self, ['php7.2-fpm'], auto=False, purge=True) if set(WOVariables.wo_php73).issubset(set(apt_packages)): WOAptGet.remove(self, ['php7.3-fpm'], auto=False, purge=True) # Update packages WOAptGet.install(self, apt_packages) post_pref(self, apt_packages, empty_packages, True) # Post Actions after package updates if len(packages): if pargs.wpcli: WOFileUtils.rm(self, '/usr/local/bin/wp') if pargs.netdata: WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh') if pargs.dashboard: WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php') Log.debug(self, "Downloading following: {0}".format(packages)) WODownload.download(self, packages) if pargs.wpcli: WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775) if pargs.netdata: Log.info(self, "Upgrading Netdata, please wait...") WOShellExec.cmd_exec( self, "/bin/bash /var/lib/wo/tmp/" "kickstart.sh " "--dont-wait") if pargs.dashboard: Log.debug( self, "Extracting wo-dashboard.tar.gz " "to location {0}22222/htdocs/".format( WOVariables.wo_webroot)) WOExtract.extract( self, '/var/lib/wo/tmp/' 'wo-dashboard.tar.gz', '{0}22222/htdocs'.format(WOVariables.wo_webroot)) WOFileUtils.chown(self, "{0}22222/htdocs".format( WOVariables.wo_webroot), WOVariables.wo_php_user, WOVariables.wo_php_user, recursive=True) if pargs.composer: Log.info(self, "Upgrading Composer, please wait...") WOShellExec.cmd_exec( self, "php -q /var/lib/wo" "/tmp/composer-install " "--install-dir=/var/lib/wo/tmp/") shutil.copyfile('/var/lib/wo/tmp/composer.phar', '/usr/local/bin/composer') WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775) if pargs.phpmyadmin: Log.info(self, "Upgrading phpMyAdmin, please wait...") WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz', '/var/lib/wo/tmp/') shutil.copyfile( ('{0}22222/htdocs/db/pma' '/config.inc.php'.format(WOVariables.wo_webroot)), ('/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/config.inc.php'.format( WOVariables.wo_phpmyadmin))) WOFileUtils.rm( self, '{0}22222/htdocs/db/pma'.format( WOVariables.wo_webroot)) shutil.move( '/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/'.format(WOVariables.wo_phpmyadmin), '{0}22222/htdocs/db/pma/'.format( WOVariables.wo_webroot)) WOFileUtils.chown(self, "{0}22222/htdocs".format( WOVariables.wo_webroot), WOVariables.wo_php_user, WOVariables.wo_php_user, recursive=True) Log.info(self, "Successfully updated packages") else: self.app.args.print_help()
def default(self): """Default function of log reset""" self.msg = [] if self.app.pargs.php: self.app.pargs.nginx = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (not self.app.pargs.site_name) and (not self.app.pargs.slow_log_db)): self.app.pargs.nginx = True self.app.pargs.fpm = True self.app.pargs.mysql = True self.app.pargs.access = True self.app.pargs.slow_log_db = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (self.app.pargs.site_name) and (not self.app.pargs.slow_log_db)): self.app.pargs.nginx = True self.app.pargs.wp = True self.app.pargs.access = True self.app.pargs.mysql = True if self.app.pargs.slow_log_db: if os.path.isdir("/var/www/22222/htdocs/db/anemometer"): Log.info(self, "Resetting MySQL slow_query_log database table") WOMysql.execute( self, "TRUNCATE TABLE " "slow_query_log.global_query_review_history") WOMysql.execute( self, "TRUNCATE TABLE " "slow_query_log.global_query_review") if self.app.pargs.nginx and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*error.log"] if self.app.pargs.access and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*access.log"] if self.app.pargs.fpm: open('/var/log/php/7.2/slow.log', 'a').close() open('/var/log/php7.2-fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log' ] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if WOVar.wo_mysql_host == "localhost": if os.path.isfile('/var/log/mysql/mysql-slow.log'): self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] else: Log.info(self, "MySQL slow-log not found, skipped") else: Log.warn( self, "Remote MySQL found, WordOps does not support" "remote MySQL servers or log files") if self.app.pargs.site_name: webroot = "{0}{1}".format(WOVar.wo_webroot, self.app.pargs.site_name) if not os.path.isdir(webroot): Log.error(self, "Site not present, quitting") if self.app.pargs.access: self.msg = self.msg + [ "{0}/{1}/logs/access.log".format(WOVar.wo_webroot, self.app.pargs.site_name) ] if self.app.pargs.nginx: self.msg = self.msg + [ "{0}/{1}/logs/error.log".format(WOVar.wo_webroot, self.app.pargs.site_name) ] if self.app.pargs.wp: if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)): if not os.path.isfile( '{0}/logs/debug.log'.format(webroot)): if not os.path.isfile('{0}/htdocs/wp-content/debug.log' .format(webroot)): open("{0}/htdocs/wp-content/debug.log".format( webroot), encoding='utf-8', mode='a').close() WOShellExec.cmd_exec( self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, WOVar.wo_php_user)) # create symbolic link for debug log WOFileUtils.create_symlink(self, [ "{0}/htdocs/wp-content/" "debug.log".format(webroot), '{0}/logs/debug.log'.format(webroot) ]) self.msg = self.msg + [ "{0}/{1}/logs/debug.log".format( WOVar.wo_webroot, self.app.pargs.site_name) ] else: Log.info( self, "Site is not WordPress site, skipping " "WordPress logs") reset_list = [] for r_list in self.msg: reset_list = reset_list + glob.glob(r_list) # Clearing content of file for r_list in reset_list: Log.info(self, "Resetting file {file}".format(file=r_list)) open(r_list, 'w').close()
def 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 default(self): """Default function of log GZip""" self.msg = [] if self.app.pargs.php: self.app.pargs.nginx = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (not self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.fpm = True self.app.pargs.mysql = True self.app.pargs.access = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.wp = True self.app.pargs.access = True self.app.pargs.mysql = True if self.app.pargs.nginx and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*error.log"] if self.app.pargs.access and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*access.log"] if self.app.pargs.fpm: open('/var/log/php5/slow.log', 'a').close() open('/var/log/php5/fpm.log', 'a').close() self.msg = self.msg + ['/var/log/php5/slow.log', '/var/log/php5/fpm.log'] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if WOVariables.wo_mysql_host is "localhost": if os.path.isfile('/var/log/mysql/mysql-slow.log'): self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] else: Log.info(self, "MySQL slow-log not found, skipped") else: Log.warn(self, "Remote MySQL found, WordOps does not support" "remote MySQL servers or log files") if self.app.pargs.site_name: webroot = "{0}{1}".format(WOVariables.wo_webroot, self.app.pargs.site_name) if not os.path.isdir(webroot): Log.error(self, "Site not present, quitting") if self.app.pargs.access: self.msg = self.msg + ["{0}/{1}/logs/access.log" .format(WOVariables.wo_webroot, self.app.pargs.site_name)] if self.app.pargs.nginx: self.msg = self.msg + ["{0}/{1}/logs/error.log" .format(WOVariables.wo_webroot, self.app.pargs.site_name)] if self.app.pargs.wp: if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)): if not os.path.isfile('{0}/logs/debug.log' .format(webroot)): if not os.path.isfile('{0}/htdocs/wp-content/debug.log' .format(webroot)): open("{0}/htdocs/wp-content/debug.log" .format(webroot), encoding='utf-8', mode='a').close() WOShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, WOVariables .wo_php_user) ) # create symbolic link for debug log WOFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/" "debug.log" .format(webroot), '{0}/logs/debug.log' .format(webroot)]) self.msg = self.msg + ["{0}/{1}/logs/debug.log" .format(WOVariables.wo_webroot, self.app.pargs.site_name)] else: Log.info(self, "Site is not WordPress site, skipping " "WordPress logs") gzip_list = [] for g_list in self.msg: gzip_list = gzip_list + glob.glob(g_list) # Gzip content of file for g_list in gzip_list: Log.info(self, "Gzipping file {file}".format(file=g_list)) in_file = g_list in_data = open(in_file, "rb").read() out_gz = g_list + ".gz" gzf = gzip.open(out_gz, "wb") gzf.write(in_data) gzf.close()