Simplify several functions
This commit is contained in:
@@ -70,7 +70,7 @@ class WOSecureController(CementBaseController):
|
|||||||
WOGit.add(self, ["/etc/nginx"],
|
WOGit.add(self, ["/etc/nginx"],
|
||||||
msg="Add Nginx to into Git")
|
msg="Add Nginx to into Git")
|
||||||
pargs = self.app.pargs
|
pargs = self.app.pargs
|
||||||
passwd = RANDOM.long(self)
|
passwd = RANDOM.gen(self, length='24')
|
||||||
if not pargs.user_input:
|
if not pargs.user_input:
|
||||||
username = input("Provide HTTP authentication user "
|
username = input("Provide HTTP authentication user "
|
||||||
"name [{0}] :".format(WOVariables.wo_user))
|
"name [{0}] :".format(WOVariables.wo_user))
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class WOSiteController(CementBaseController):
|
|||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
# validate domain name
|
# validate domain name
|
||||||
(wo_domain,
|
(wo_domain,
|
||||||
wo_www_domain) = WODomain.validatedomain(self, pargs.site_name)
|
wo_www_domain) = WODomain.validate(self, pargs.site_name)
|
||||||
|
|
||||||
# check if site exists
|
# check if site exists
|
||||||
if not check_domain_exists(self, wo_domain):
|
if not check_domain_exists(self, wo_domain):
|
||||||
@@ -94,8 +94,8 @@ class WOSiteController(CementBaseController):
|
|||||||
Log.debug(self, str(e))
|
Log.debug(self, str(e))
|
||||||
Log.error(self, 'could not input site name')
|
Log.error(self, 'could not input site name')
|
||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
(wo_domain, wo_www_domain) = WODomain.validatedomain(self,
|
(wo_domain, wo_www_domain) = WODomain.validate(self,
|
||||||
pargs.site_name)
|
pargs.site_name)
|
||||||
# check if site exists
|
# check if site exists
|
||||||
if not check_domain_exists(self, wo_domain):
|
if not check_domain_exists(self, wo_domain):
|
||||||
Log.error(self, "site {0} does not exist".format(wo_domain))
|
Log.error(self, "site {0} does not exist".format(wo_domain))
|
||||||
@@ -136,8 +136,8 @@ class WOSiteController(CementBaseController):
|
|||||||
Log.error(self, 'could not input site name')
|
Log.error(self, 'could not input site name')
|
||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
(wo_domain,
|
(wo_domain,
|
||||||
wo_www_domain) = WODomain.validatedomain(self, pargs.site_name)
|
wo_www_domain) = WODomain.validate(self, pargs.site_name)
|
||||||
(wo_domain_type, wo_root_domain) = WODomain.getdomainlevel(
|
(wo_domain_type, wo_root_domain) = WODomain.getlevel(
|
||||||
self, wo_domain)
|
self, wo_domain)
|
||||||
wo_db_name = ''
|
wo_db_name = ''
|
||||||
wo_db_user = ''
|
wo_db_user = ''
|
||||||
@@ -190,7 +190,7 @@ class WOSiteController(CementBaseController):
|
|||||||
pargs = self.app.pargs
|
pargs = self.app.pargs
|
||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
(wo_domain,
|
(wo_domain,
|
||||||
wo_www_domain) = WODomain.validatedomain(self, pargs.site_name)
|
wo_www_domain) = WODomain.validate(self, pargs.site_name)
|
||||||
wo_site_webroot = getSiteInfo(self, wo_domain).site_path
|
wo_site_webroot = getSiteInfo(self, wo_domain).site_path
|
||||||
|
|
||||||
if not check_domain_exists(self, wo_domain):
|
if not check_domain_exists(self, wo_domain):
|
||||||
@@ -213,7 +213,7 @@ class WOSiteController(CementBaseController):
|
|||||||
# TODO Write code for wo site edit command here
|
# TODO Write code for wo site edit command here
|
||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
(wo_domain,
|
(wo_domain,
|
||||||
wo_www_domain) = WODomain.validatedomain(self, pargs.site_name)
|
wo_www_domain) = WODomain.validate(self, pargs.site_name)
|
||||||
|
|
||||||
if not check_domain_exists(self, wo_domain):
|
if not check_domain_exists(self, wo_domain):
|
||||||
Log.error(self, "site {0} does not exist".format(wo_domain))
|
Log.error(self, "site {0} does not exist".format(wo_domain))
|
||||||
@@ -245,7 +245,7 @@ class WOSiteController(CementBaseController):
|
|||||||
|
|
||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
(wo_domain,
|
(wo_domain,
|
||||||
wo_www_domain) = WODomain.validatedomain(self, pargs.site_name)
|
wo_www_domain) = WODomain.validate(self, pargs.site_name)
|
||||||
|
|
||||||
if not check_domain_exists(self, wo_domain):
|
if not check_domain_exists(self, wo_domain):
|
||||||
Log.error(self, "site {0} does not exist".format(wo_domain))
|
Log.error(self, "site {0} does not exist".format(wo_domain))
|
||||||
@@ -286,7 +286,7 @@ class WOSiteEditController(CementBaseController):
|
|||||||
|
|
||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
(wo_domain,
|
(wo_domain,
|
||||||
wo_www_domain) = WODomain.validatedomain(self, pargs.site_name)
|
wo_www_domain) = WODomain.validate(self, pargs.site_name)
|
||||||
|
|
||||||
if not check_domain_exists(self, wo_domain):
|
if not check_domain_exists(self, wo_domain):
|
||||||
Log.error(self, "site {0} does not exist".format(wo_domain))
|
Log.error(self, "site {0} does not exist".format(wo_domain))
|
||||||
@@ -437,7 +437,7 @@ class WOSiteCreateController(CementBaseController):
|
|||||||
|
|
||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
(wo_domain,
|
(wo_domain,
|
||||||
wo_www_domain) = WODomain.validatedomain(self, pargs.site_name)
|
wo_www_domain) = WODomain.validate(self, pargs.site_name)
|
||||||
if not wo_domain.strip():
|
if not wo_domain.strip():
|
||||||
Log.error(self, "Invalid domain name, "
|
Log.error(self, "Invalid domain name, "
|
||||||
"Provide valid domain name")
|
"Provide valid domain name")
|
||||||
@@ -731,11 +731,14 @@ class WOSiteCreateController(CementBaseController):
|
|||||||
|
|
||||||
if pargs.letsencrypt:
|
if pargs.letsencrypt:
|
||||||
acme_domains = []
|
acme_domains = []
|
||||||
(wo_domain_type, wo_root_domain) = WODomain.getdomainlevel(
|
(wo_domain_type, wo_root_domain) = WODomain.getlevel(
|
||||||
self, wo_domain)
|
self, wo_domain)
|
||||||
data['letsencrypt'] = True
|
data['letsencrypt'] = True
|
||||||
letsencrypt = True
|
letsencrypt = True
|
||||||
if data['letsencrypt'] is True:
|
if os.path.isfile('/etc/letsencrypt/live/{0}/fullchain.pem'
|
||||||
|
.format(wo_domain)):
|
||||||
|
archivedCertificateHandle(self, wo_domain)
|
||||||
|
else:
|
||||||
Log.debug(self, "Going to issue Let's Encrypt certificate")
|
Log.debug(self, "Going to issue Let's Encrypt certificate")
|
||||||
acmedata = dict(acme_domains, dns=False, acme_dns='dns_cf',
|
acmedata = dict(acme_domains, dns=False, acme_dns='dns_cf',
|
||||||
dnsalias=False, acme_alias='', keylength='')
|
dnsalias=False, acme_alias='', keylength='')
|
||||||
@@ -788,9 +791,7 @@ class WOSiteCreateController(CementBaseController):
|
|||||||
# check if a wildcard cert for the root domain exist
|
# check if a wildcard cert for the root domain exist
|
||||||
Log.debug(self, "checkWildcardExist on *.{0}"
|
Log.debug(self, "checkWildcardExist on *.{0}"
|
||||||
.format(wo_root_domain))
|
.format(wo_root_domain))
|
||||||
iswildcard = SSL.checkwildcardexist(self, wo_root_domain)
|
if SSL.checkwildcardexist(self, wo_root_domain):
|
||||||
Log.debug(self, "iswildcard = {0}".format(iswildcard))
|
|
||||||
if iswildcard:
|
|
||||||
Log.info(self, "Using existing Wildcard SSL "
|
Log.info(self, "Using existing Wildcard SSL "
|
||||||
"certificate from {0} to secure {1}"
|
"certificate from {0} to secure {1}"
|
||||||
.format(wo_root_domain, wo_domain))
|
.format(wo_root_domain, wo_domain))
|
||||||
@@ -839,9 +840,6 @@ class WOSiteCreateController(CementBaseController):
|
|||||||
msg="Adding letsencrypts config of site: {0}"
|
msg="Adding letsencrypts config of site: {0}"
|
||||||
.format(wo_domain))
|
.format(wo_domain))
|
||||||
updateSiteInfo(self, wo_domain, ssl=letsencrypt)
|
updateSiteInfo(self, wo_domain, ssl=letsencrypt)
|
||||||
elif data['letsencrypt'] is False:
|
|
||||||
Log.info(self, "Not using Let\'s encrypt for Site "
|
|
||||||
" http://{0}".format(wo_domain))
|
|
||||||
|
|
||||||
|
|
||||||
class WOSiteUpdateController(CementBaseController):
|
class WOSiteUpdateController(CementBaseController):
|
||||||
@@ -995,7 +993,7 @@ class WOSiteUpdateController(CementBaseController):
|
|||||||
|
|
||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
(wo_domain,
|
(wo_domain,
|
||||||
wo_www_domain) = WODomain.validatedomain(self, pargs.site_name)
|
wo_www_domain) = WODomain.validate(self, pargs.site_name)
|
||||||
wo_site_webroot = WOVariables.wo_webroot + wo_domain
|
wo_site_webroot = WOVariables.wo_webroot + wo_domain
|
||||||
check_site = getSiteInfo(self, wo_domain)
|
check_site = getSiteInfo(self, wo_domain)
|
||||||
|
|
||||||
@@ -1243,7 +1241,7 @@ class WOSiteUpdateController(CementBaseController):
|
|||||||
acme_domains = []
|
acme_domains = []
|
||||||
acmedata = dict(acme_domains, dns=False, acme_dns='dns_cf',
|
acmedata = dict(acme_domains, dns=False, acme_dns='dns_cf',
|
||||||
dnsalias=False, acme_alias='', keylength='')
|
dnsalias=False, acme_alias='', keylength='')
|
||||||
(wo_domain_type, wo_root_domain) = WODomain.getdomainlevel(
|
(wo_domain_type, wo_root_domain) = WODomain.getlevel(
|
||||||
self, wo_domain)
|
self, wo_domain)
|
||||||
acmedata['keylength'] = self.app.config.get('letsencrypt',
|
acmedata['keylength'] = self.app.config.get('letsencrypt',
|
||||||
'keylength')
|
'keylength')
|
||||||
@@ -2035,7 +2033,7 @@ class WOSiteDeleteController(CementBaseController):
|
|||||||
Log.error(self, 'could not input site name')
|
Log.error(self, 'could not input site name')
|
||||||
|
|
||||||
pargs.site_name = pargs.site_name.strip()
|
pargs.site_name = pargs.site_name.strip()
|
||||||
(wo_domain, wo_www_domain) = WODomain.validatedomain(self, pargs.site_name)
|
(wo_domain, wo_www_domain) = WODomain.validate(self, pargs.site_name)
|
||||||
wo_db_name = ''
|
wo_db_name = ''
|
||||||
wo_prompt = ''
|
wo_prompt = ''
|
||||||
wo_nginx_prompt = ''
|
wo_nginx_prompt = ''
|
||||||
|
|||||||
@@ -848,7 +848,7 @@ def site_package_check(self, stype):
|
|||||||
apt = ["nginx"] + WOVariables.wo_nginx
|
apt = ["nginx"] + WOVariables.wo_nginx
|
||||||
# apt_packages = apt_packages + WOVariables.wo_nginx
|
# apt_packages = apt_packages + WOVariables.wo_nginx
|
||||||
post_pref(self, apt, packages)
|
post_pref(self, apt, packages)
|
||||||
elif os.file.isfile('/usr/sbin/nginx'):
|
elif os.path.isfile('/usr/sbin/nginx'):
|
||||||
post_pref(self, WOVariables.wo_nginx, [])
|
post_pref(self, WOVariables.wo_nginx, [])
|
||||||
else:
|
else:
|
||||||
apt_packages = apt_packages + WOVariables.wo_nginx
|
apt_packages = apt_packages + WOVariables.wo_nginx
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ class WOAcme:
|
|||||||
Log.debug(self, str(e))
|
Log.debug(self, str(e))
|
||||||
Log.debug(self, "Error occured while generating "
|
Log.debug(self, "Error occured while generating "
|
||||||
"ssl.conf")
|
"ssl.conf")
|
||||||
|
return 0
|
||||||
|
|
||||||
def check_dns(self, acme_domains):
|
def check_dns(self, acme_domains):
|
||||||
"""Check if a list of domains point to the server IP"""
|
"""Check if a list of domains point to the server IP"""
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import os
|
|||||||
class WODomain():
|
class WODomain():
|
||||||
"""WordOps domain validation utilities"""
|
"""WordOps domain validation utilities"""
|
||||||
|
|
||||||
def validatedomain(self, url):
|
def validate(self, url):
|
||||||
"""
|
"""
|
||||||
This function returns domain name removing http:// and https://
|
This function returns domain name removing http:// and https://
|
||||||
returns domain name only with or without www as user provided.
|
returns domain name only with or without www as user provided.
|
||||||
@@ -26,7 +26,7 @@ class WODomain():
|
|||||||
|
|
||||||
return (final_domain, domain_name)
|
return (final_domain, domain_name)
|
||||||
|
|
||||||
def getdomainlevel(self, domain):
|
def getlevel(self, domain):
|
||||||
"""
|
"""
|
||||||
Returns the domain type : domain, subdomain and the root domain
|
Returns the domain type : domain, subdomain and the root domain
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -3,15 +3,10 @@ import string
|
|||||||
|
|
||||||
|
|
||||||
class RANDOM:
|
class RANDOM:
|
||||||
|
"""Random strings generator"""
|
||||||
|
|
||||||
def short(self):
|
def gen(self, length='24'):
|
||||||
short_random = ''.join([random.choice
|
short_random = ''.join([random.choice
|
||||||
(string.ascii_letters + string.digits)
|
(string.ascii_letters + string.digits)
|
||||||
for n in range(8)])
|
for n in range(length)])
|
||||||
return short_random
|
return short_random
|
||||||
|
|
||||||
def long(self):
|
|
||||||
long_random = ''.join([random.choice
|
|
||||||
(string.ascii_letters + string.digits)
|
|
||||||
for n in range(24)])
|
|
||||||
return long_random
|
|
||||||
|
|||||||
Reference in New Issue
Block a user