Update install and refactor site.py

This commit is contained in:
VirtuBox
2019-09-19 14:07:34 +02:00
parent 0873ea2555
commit 9b1853b25b
7 changed files with 81 additions and 58 deletions

View File

@@ -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))

View File

@@ -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 = ''