From 9b1853b25b07c9ef065b6850b247edb28b5f1bcf Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Thu, 19 Sep 2019 14:07:34 +0200 Subject: [PATCH] Update install and refactor site.py --- config/bash_completion.d/wo_auto.rc | 70 ++++++++++++++--------------- install | 1 + wo/cli/plugins/secure.py | 16 ++++--- wo/cli/plugins/site.py | 30 +++++++------ wo/core/domainvalidate.py | 3 +- wo/core/random.py | 17 +++++++ wo/core/variables.py | 2 +- 7 files changed, 81 insertions(+), 58 deletions(-) create mode 100644 wo/core/random.py diff --git a/config/bash_completion.d/wo_auto.rc b/config/bash_completion.d/wo_auto.rc index 56ec872..b0ffd54 100644 --- a/config/bash_completion.d/wo_auto.rc +++ b/config/bash_completion.d/wo_auto.rc @@ -94,7 +94,7 @@ _wo_complete() ;; "edit" | "enable" | "info" | "log" | "show" | "cd" | "delete") - if [ ${COMP_WORDS[1]} == "log" ]; then + if [ ""${COMP_WORDS[1]}"" == "log" ]; then COMPREPLY=( $(compgen \ -W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql --access" \ -- $cur) ) @@ -131,7 +131,7 @@ _wo_complete() ;; esac - if [ ${COMP_WORDS[1]} == "debug" ] && ([ "$prev" != "--start" ] && [ "$prev" != "--nginx" ] && [ "$prev" != "--php" ] && [ "$prev" != "--php73" ] && [ "$prev" != "--fpm" ] && [ "$prev" != "--fpm7" ] && [ "$prev" != "--mysql" ] && [ "$prev" != "-i" ] && [ "$prev" != "--interactive" ] && [ "$prev" != "--import-slow-log" ] && [ "$prev" != "--stop" ]); then + if [ ""${COMP_WORDS[1]}"" == "debug" ] && ([ "$prev" != "--start" ] && [ "$prev" != "--nginx" ] && [ "$prev" != "--php" ] && [ "$prev" != "--php73" ] && [ "$prev" != "--fpm" ] && [ "$prev" != "--fpm7" ] && [ "$prev" != "--mysql" ] && [ "$prev" != "-i" ] && [ "$prev" != "--interactive" ] && [ "$prev" != "--import-slow-log" ] && [ "$prev" != "--stop" ]); then retlist="--all --wp --rewrite -i --all=off --wp=off --rewrite=off" ret="${retlist[@]/$prev}" COMPREPLY=( $(compgen \ @@ -139,7 +139,7 @@ _wo_complete() -- $cur) ) fi - #if [ ${COMP_WORDS[1]} == "log" ] && ([ "$prev" != "--access" ] || [ "$prev" != "--nginx" ] || [ "$prev" != "--php" ] || [ "$prev" != "--fpm" ] || [ "$prev" != "--mysql" ] || [ "$prev" != "-i" ] || ["$prev" != "--interactive" ] || ["$prev" != "--stop" ]); then + #if [ "${COMP_WORDS[1]}" == "log" ] && ([ "$prev" != "--access" ] || [ "$prev" != "--nginx" ] || [ "$prev" != "--php" ] || [ "$prev" != "--fpm" ] || [ "$prev" != "--mysql" ] || [ "$prev" != "-i" ] || ["$prev" != "--interactive" ] || ["$prev" != "--stop" ]); then # retlist="--all --wp --rewrite -i --all=off --wp=off --rewrite=off" # ret="${retlist[@]/$prev}" # COMPREPLY=( $(compgen \ @@ -148,7 +148,7 @@ _wo_complete() #fi - elif [ $COMP_CWORD -eq 4 ]; then + elif [ "$COMP_CWORD" -eq 4 ]; then case "$mprev" in # HANDLE EVERYTHING AFTER THE THIRD LEVEL NAMESPACE @@ -204,11 +204,11 @@ _wo_complete() case "$prev" in "--wp") - if [ ${COMP_WORDS[1]} != "debug" ]; then - if [ ${COMP_WORDS[2]} == "create" ]; then + if [ "${COMP_WORDS[1]}" != "debug" ]; then + if [ "${COMP_WORDS[2]}" == "create" ]; then retlist="--wp --wpsc --wpfc --user --email --pass --wpredis --wprocket --wpce --letsencrypt -le --letsencrypt=wildcard --dns --dns=dns_cf --dns=dns_do --php73" - elif [ ${COMP_WORDS[2]} == "update" ]; then - retlist="--wp --wpfc --wpsc --php73 --php73=off --wpredis --wprocket --wpce -le --letsencrypt --letsencrypt=wildcard --letsencrypt=off --letsencrypt=clean -le=off -le=wildcard --dns --dns=dns_cf --dns=dns_do" + elif [ "${COMP_WORDS[2]}" == "update" ]; then + retlist="--wp --wpfc --wpsc --php73 --php73=off --wpredis --wprocket --wpce -le --letsencrypt --letsencrypt=wildcard -le=wildcard --dns --dns=dns_cf --dns=dns_do" else retlist="" fi @@ -223,11 +223,11 @@ _wo_complete() ;; "--wpsubdir" | "--wpsubdomain") - if [ ${COMP_WORDS[1]} != "debug" ]; then - if [ ${COMP_WORDS[2]} == "create" ]; then + if [ "${COMP_WORDS[1]}" != "debug" ]; then + if [ "${COMP_WORDS[2]}" == "create" ]; then retlist="--wpsc --wpfc --user --email --pass --wpredis --wprocket --wpce -le -le=wildcard --letsencrypt --letsencrypt=wildcard --php73 --dns --dns=dns_cf --dns=dns_do" - elif [ ${COMP_WORDS[2]} == "update" ]; then - retlist="--wpfc --wpsc --php73 --php73=off --wpredis --wprocket --wpce -le -le=off -le=wildcard --letsencrypt --letsencrypt=wildcard --letsencrypt=off --letsencrypt=clean --dns --dns=dns_cf --dns=dns_do" + elif [ "${COMP_WORDS[2]}" == "update" ]; then + retlist="--wpfc --wpsc --php73 --php73=off --wpredis --wprocket --wpce -le -le=wildcard --letsencrypt --letsencrypt=wildcard --dns --dns=dns_cf --dns=dns_do" else retlist="" fi @@ -241,9 +241,9 @@ _wo_complete() -- $cur) ) ;; - "--wpredis --wprocket --wpce" | "--wpfc" | "--wpsc" | "--wpsubdir" | "--wpsubdomain" | "--user" | "--pass" | "--email" | "--wp") - if [ ${COMP_WORDS[2]} == "create" ]; then - retlist="--user --pass --email --wp --wpsubdir --wpsubdomain --wpfc --wpsc --wpredis --wprocket --wpce --php73 -le -le=off -le=wildcard --letsencrypt --letsencrypt=wildcard --dns --dns=dns_cf --dns=dns_do" + "--wpredis" | "--wprocket" | "--wpce" | "--wpfc" | "--wpsc" | "--wpsubdir" | "--wpsubdomain" | "--user" | "--pass" | "--email" | "--wp") + if [ "${COMP_WORDS[2]}" == "create" ]; then + retlist="--user --pass --email --wp --wpsubdir --wpsubdomain --wpfc --wpsc --wpredis --wprocket --wpce --php73 -le -le=wildcard --letsencrypt --letsencrypt=wildcard --dns --dns=dns_cf --dns=dns_do" else retlist="" fi @@ -254,9 +254,9 @@ _wo_complete() -- $cur) ) ;; - "--wpredis --wprocket --wpce" | "--wpfc") - if [ ${COMP_WORDS[2]} == "update" ]; then - retlist="--password --php --php73 --mysql --wp --wpsubdir --wpsubdomain --wpfc --wpsc --wpredis --wprocket --wpce -le -le=off --letsencrypt --letsencrypt=off --letsencrypt=clean --dns --dns=dns_cf --dns=dns_do" + "--wpredis" | "--wprocket" | "--wpce" | "--wpfc") + if [ "${COMP_WORDS[2]}" == "update" ]; then + retlist="--password --php --php73 --mysql --wp --wpsubdir --wpsubdomain -le --letsencrypt --dns --dns=dns_cf --dns=dns_do" else retlist="" fi @@ -268,23 +268,23 @@ _wo_complete() ;; "--web" | "--admin" | "--nginx" | "--php" | "--php73" | "--mysql" | "--wpcli" | "--phpmyadmin" | "--adminer" | "--utils" | "--fail2ban" | "--redis | --phpredisadmin | --netdata") - if [[ ${COMP_WORDS[2]} == "install" || ${COMP_WORDS[2]} == "purge" || ${COMP_WORDS[2]} == "remove" ]]; then + if [[ "${COMP_WORDS[2]}" == "install" || "${COMP_WORDS[2]}" == "purge" || "${COMP_WORDS[2]}" == "remove" ]]; then retlist="--web --admin --security --nginx --php --php73 --mysql --wpcli --phpmyadmin --adminer --utils --redis --fail2ban --phpredisadmin --netdata -f --force" - elif [[ ${COMP_WORDS[2]} == "start" || ${COMP_WORDS[2]} == "reload" || ${COMP_WORDS[2]} == "restart" || ${COMP_WORDS[2]} == "stop" ]]; then + elif [[ "${COMP_WORDS[2]}" == "start" || "${COMP_WORDS[2]}" == "reload" || "${COMP_WORDS[2]}" == "restart" || "${COMP_WORDS[2]}" == "stop" ]]; then retlist="--nginx --php --php73 --mysql --redis --netdata" - elif [[ ${COMP_WORDS[1]} == "debug" ]]; then + elif [[ "${COMP_WORDS[1]}" == "debug" ]]; then retlist="--start --nginx --php --php73 --fpm --fpm7 --mysql -i --interactive -stop --import-slow-log --import-slow-log-interval= -" if [[ $prev == '--mysql' ]]; then retlist="--start --nginx --php --php73 --fpm --fpm7 --mysql -i --interactive --stop --import-slow-log" fi - elif [[ ${COMP_WORDS[1]} == "log" ]]; then - if [ ${COMP_WORDS[2]} == "show" ]; then + elif [[ "${COMP_WORDS[1]}" == "log" ]]; then + if [ "${COMP_WORDS[2]}" == "show" ]; then retlist="--access --nginx --php --mysql --fpm --wp" - elif [ ${COMP_WORDS[2]} == "reset" ]; then + elif [ "${COMP_WORDS[2]}" == "reset" ]; then retlist="--access --nginx --php --mysql --fpm --wp --slow-log-db" - elif [ ${COMP_WORDS[2]} == "mail" ]; then + elif [ "${COMP_WORDS[2]}" == "mail" ]; then retlist="--access --nginx --php --mysql --fpm --wp --to=" fi @@ -304,12 +304,12 @@ _wo_complete() ;; "--all") - if [ ${COMP_WORDS[1]} == "clean" ]; then + if [ "${COMP_WORDS[1]}" == "clean" ]; then retlist="--opcache --fastcgi --redis" - elif [ ${COMP_WORDS[2]} == "delete" ]; then + elif [ "${COMP_WORDS[2]}" == "delete" ]; then retlist="--db --files --force" - elif [ ${COMP_WORDS[2]} == "update" ]; then - retlist="--password --php --mysql --wp --wpsubdir --wpsubdomain --wpfc --wpsc --wpredis --wprocket --wpce -le -le=off -le=wildcard --letsencrypt --letsencrypt=off " + elif [ "${COMP_WORDS[2]}" == "update" ]; then + retlist="--password --php --mysql --wp --wpsubdir --wpsubdomain --wpfc --wpsc --wpredis --wprocket --wpce -le -le=off -le=wildcard --letsencrypt --letsencrypt=off " else retlist="" fi @@ -333,16 +333,16 @@ _wo_complete() -W "$(echo $ret)" \ -- $cur) ) ;; - "--access" | "--fpm" | "--wp" | "--slow-log-db") - if [[ ${COMP_WORDS[1]} == "log" ]]; then - if [ ${COMP_WORDS[2]} == "show" ]; then + "--access" | "--fpm" | "--slow-log-db") + if [[ "${COMP_WORDS[1]}" == "log" ]]; then + if [ "${COMP_WORDS[2]}" == "show" ]; then retlist="--access --nginx --php --mysql --fpm --wp" - elif [ ${COMP_WORDS[2]} == "reset" ]; then + elif [ "${COMP_WORDS[2]}" == "reset" ]; then retlist="--access --nginx --php --mysql --fpm --wp --slow-log-db" - elif [ ${COMP_WORDS[2]} == "mail" ]; then + elif [ "${COMP_WORDS[2]}" == "mail" ]; then retlist="--access --nginx --php --mysql --fpm --wp --to=" fi @@ -357,7 +357,7 @@ _wo_complete() esac case "$mprev" in "--user" | "--email" | "--pass") - if [ ${COMP_WORDS[2]} == "create" ]; then + if [ "${COMP_WORDS[2]}" == "create" ]; then retlist="--user --pass --email --html --php --php73 --mysql --wp --wpsubdir --wpsubdomain --wpfc --wpsc --wpredis --wprocket --wpce -le -le=wildcard --letsencrypt --letsencrypt=wildcard --dns --dns=dns_cf --dns=dns_do" fi ret="${retlist[@]/$prev}" diff --git a/install b/install index bd6cd1d..5c7dd46 100755 --- a/install +++ b/install @@ -797,6 +797,7 @@ wo_cheat_install() { curl -sL https://cht.sh/:cht.sh > /usr/local/bin/cht.sh chmod +x /usr/local/bin/cht.sh [ ! -h /usr/local/bin/cheat ] && { + rm -f /usr/local/bin/cheat ln -s /usr/local/bin/cht.sh /usr/local/bin/cheat } curl -sL https://cheat.sh/:bash_completion > /etc/bash_completion.d/cht.sh diff --git a/wo/cli/plugins/secure.py b/wo/cli/plugins/secure.py index 38f8190..ec3d916 100644 --- a/wo/cli/plugins/secure.py +++ b/wo/cli/plugins/secure.py @@ -10,6 +10,7 @@ from wo.core.logging import Log from wo.core.services import WOService from wo.core.shellexec import WOShellExec from wo.core.variables import WOVariables +from wo.core.random import RANDOM def wo_secure_hook(app): @@ -21,14 +22,17 @@ class WOSecureController(CementBaseController): label = 'secure' stacked_on = 'base' stacked_type = 'nested' - description = ('Secure command secure auth, ip and port') + description = ( + 'Secure command provide the ability to' + 'adjust settings for backend and to harden server security.') arguments = [ (['--auth'], - dict(help='secure auth', action='store_true')), + dict(help='secure backend authentification', + action='store_true')), (['--port'], - dict(help='secure port', action='store_true')), + dict(help='set backend port', action='store_true')), (['--ip'], - dict(help='secure ip', action='store_true')), + dict(help='set backend whitelisted ip', action='store_true')), (['user_input'], dict(help='user input', nargs='?', default=None)), (['user_pass'], @@ -49,9 +53,7 @@ class WOSecureController(CementBaseController): def secure_auth(self): """This function secures authentication""" pargs = self.app.pargs - passwd = ''.join([random.choice - (string.ascii_letters + string.digits) - for n in range(24)]) + passwd = RANDOM.long(self) if not pargs.user_input: username = input("Provide HTTP authentication user " "name [{0}] :".format(WOVariables.wo_user)) diff --git a/wo/cli/plugins/site.py b/wo/cli/plugins/site.py index 2a767b7..f4175b7 100644 --- a/wo/cli/plugins/site.py +++ b/wo/cli/plugins/site.py @@ -11,7 +11,7 @@ from cement.core.controller import CementBaseController, expose from wo.cli.plugins.site_functions import * from wo.cli.plugins.sitedb import (addNewSite, deleteSiteInfo, getAllsites, getSiteInfo, updateSiteInfo) -from wo.core.domainvalidate import DMN +from wo.core.domainvalidate import WODomain from wo.core.fileutils import WOFileUtils from wo.core.git import WOGit from wo.core.logging import Log @@ -58,7 +58,7 @@ class WOSiteController(CementBaseController): pargs.site_name = pargs.site_name.strip() # validate domain name - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) + (wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name) # check if site exists if not check_domain_exists(self, wo_domain): @@ -95,7 +95,7 @@ class WOSiteController(CementBaseController): Log.debug(self, str(e)) Log.error(self, 'could not input site name') pargs.site_name = pargs.site_name.strip() - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) + (wo_domain, wo_www_domain) = WODomain.validatedomain(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)) @@ -135,8 +135,8 @@ class WOSiteController(CementBaseController): Log.debug(self, str(e)) Log.error(self, 'could not input site name') pargs.site_name = pargs.site_name.strip() - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) - (wo_domain_type, wo_root_domain) = DMN.getdomainlevel(self, wo_domain) + (wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name) + (wo_domain_type, wo_root_domain) = WODomain.getdomainlevel(self, wo_domain) wo_db_name = '' wo_db_user = '' wo_db_pass = '' @@ -187,7 +187,7 @@ class WOSiteController(CementBaseController): def log(self): pargs = self.app.pargs pargs.site_name = pargs.site_name.strip() - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) + (wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name) wo_site_webroot = getSiteInfo(self, wo_domain).site_path if not check_domain_exists(self, wo_domain): @@ -209,7 +209,7 @@ class WOSiteController(CementBaseController): Log.error(self, 'could not input site name') # TODO Write code for wo site edit command here pargs.site_name = pargs.site_name.strip() - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) + (wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name) if not check_domain_exists(self, wo_domain): Log.error(self, "site {0} does not exist".format(wo_domain)) @@ -240,7 +240,7 @@ class WOSiteController(CementBaseController): Log.error(self, 'Unable to read input, please try again') pargs.site_name = pargs.site_name.strip() - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) + (wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name) if not check_domain_exists(self, wo_domain): Log.error(self, "site {0} does not exist".format(wo_domain)) @@ -281,7 +281,7 @@ class WOSiteEditController(CementBaseController): Log.error(self, 'Unable to read input, Please try again') pargs.site_name = pargs.site_name.strip() - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) + (wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name) if not check_domain_exists(self, wo_domain): Log.error(self, "site {0} does not exist".format(wo_domain)) @@ -423,7 +423,7 @@ class WOSiteCreateController(CementBaseController): Log.error(self, "Unable to input site name, Please try again!") pargs.site_name = pargs.site_name.strip() - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) + (wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name) if not wo_domain.strip(): Log.error(self, "Invalid domain name, " "Provide valid domain name") @@ -716,7 +716,8 @@ class WOSiteCreateController(CementBaseController): "`tail /var/log/wo/wordops.log` and please try again") if pargs.letsencrypt: - (wo_domain_type, wo_root_domain) = DMN.getdomainlevel(self, wo_domain) + (wo_domain_type, wo_root_domain) = WODomain.getdomainlevel(self, + wo_domain) data['letsencrypt'] = True letsencrypt = True if data['letsencrypt'] is True: @@ -929,7 +930,7 @@ class WOSiteUpdateController(CementBaseController): Log.error(self, 'Unable to input site name, Please try again!') pargs.site_name = pargs.site_name.strip() - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) + (wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name) wo_site_webroot = WOVariables.wo_webroot + wo_domain check_site = getSiteInfo(self, wo_domain) @@ -1127,7 +1128,8 @@ class WOSiteUpdateController(CementBaseController): pargs.php73 = False if pargs.letsencrypt: - (wo_domain_type, wo_root_domain) = DMN.getdomainlevel(self, wo_domain) + (wo_domain_type, wo_root_domain) = WODomain.getdomainlevel(self, + wo_domain) if pargs.letsencrypt == 'on': data['letsencrypt'] = True letsencrypt = True @@ -1856,7 +1858,7 @@ class WOSiteDeleteController(CementBaseController): Log.error(self, 'could not input site name') pargs.site_name = pargs.site_name.strip() - (wo_domain, wo_www_domain) = DMN.validatedomain(self, pargs.site_name) + (wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name) wo_db_name = '' wo_prompt = '' wo_nginx_prompt = '' diff --git a/wo/core/domainvalidate.py b/wo/core/domainvalidate.py index ff7ddd3..de74fce 100644 --- a/wo/core/domainvalidate.py +++ b/wo/core/domainvalidate.py @@ -3,7 +3,8 @@ import os from urllib.parse import urlparse -class DMN(): +class WODomain(): + """WordOps domain validation utilities""" def validatedomain(self, url): """ diff --git a/wo/core/random.py b/wo/core/random.py new file mode 100644 index 0000000..cb7482d --- /dev/null +++ b/wo/core/random.py @@ -0,0 +1,17 @@ +import random +import string + + +class RANDOM: + + def short(self): + short_random = ''.join([random.choice + (string.ascii_letters + string.digits) + for n in range(8)]) + return short_random + + def long(self): + long_random = ''.join([random.choice + (string.ascii_letters + string.digits) + for n in range(24)]) + return long_random diff --git a/wo/core/variables.py b/wo/core/variables.py index fb7b664..aa39058 100644 --- a/wo/core/variables.py +++ b/wo/core/variables.py @@ -11,7 +11,7 @@ class WOVariables(): """Intialization of core variables""" # WordOps version - wo_version = "3.9.8.11" + wo_version = "3.9.8.12" # WordOps packages versions wo_wp_cli = "2.3.0" wo_adminer = "4.7.2"