Refactor acme.sh and WOVariables

This commit is contained in:
VirtuBox
2019-10-02 13:13:32 +02:00
parent d9980998fa
commit c731d806d6
22 changed files with 371 additions and 374 deletions

View File

@@ -7,7 +7,7 @@ from wo.core.fileutils import WOFileUtils
from wo.core.git import WOGit
from wo.core.logging import Log
from wo.core.shellexec import WOShellExec
from wo.core.variables import WOVariables
from wo.core.variables import WOVar
class WOAcme:
@@ -77,7 +77,7 @@ class WOAcme:
"--fullchain-file {0}/{1}/fullchain.pem "
"--ca-file {0}/{1}/ca.pem --reloadcmd \"nginx -t && "
"service nginx restart\" "
.format(WOVariables.wo_ssl_live,
.format(WOVar.wo_ssl_live,
wo_domain_name, WOAcme.wo_acme_exec)):
Log.valide(self, "Deploying SSL cert")
else:
@@ -97,7 +97,7 @@ class WOAcme:
"ssl_certificate_key {0}/{1}/key.pem;\n"
"ssl_trusted_certificate {0}/{1}/ca.pem;\n"
"ssl_stapling_verify on;\n"
.format(WOVariables.wo_ssl_live, wo_domain_name))
.format(WOVar.wo_ssl_live, wo_domain_name))
sslconf.close()
if not WOFileUtils.grep(self, '/var/www/22222/conf/nginx/ssl.conf',
@@ -109,7 +109,7 @@ class WOAcme:
"ssl_certificate_key {0}/{1}/key.pem;\n"
"ssl_trusted_certificate {0}/{1}/ca.pem;\n"
"ssl_stapling_verify on;\n"
.format(WOVariables.wo_ssl_live, wo_domain_name))
.format(WOVar.wo_ssl_live, wo_domain_name))
sslconf.close()
WOGit.add(self, ["/etc/letsencrypt"],

View File

@@ -3,7 +3,7 @@ import os
from wo.core.logging import Log
from wo.core.shellexec import WOShellExec
from wo.core.variables import WOVariables
from wo.core.variables import WOVar
class WORepo():
@@ -25,7 +25,7 @@ class WORepo():
if repo_url is not None:
repo_file_path = ("/etc/apt/sources.list.d/" +
WOVariables().wo_repo_file)
WOVar().wo_repo_file)
try:
if not os.path.isfile(repo_file_path):
with open(repo_file_path,
@@ -65,7 +65,7 @@ class WORepo():
.format(ppa_name=ppa))
elif repo_url:
repo_file_path = ("/etc/apt/sources.list.d/" +
WOVariables().wo_repo_file)
WOVar().wo_repo_file)
try:
repofile = open(repo_file_path, "w+")

View File

@@ -1,20 +1,20 @@
import requests
from wo.core.shellexec import WOShellExec
from wo.core.variables import WOVariables
from wo.core.variables import WOVar
def check_fqdn(self, wo_host):
"""FQDN check with WordOps, for mail server hostname must be FQDN"""
# wo_host=os.popen("hostname -f | tr -d '\n'").read()
if '.' in wo_host:
WOVariables.wo_fqdn = wo_host
WOVar.wo_fqdn = wo_host
with open('/etc/hostname', encoding='utf-8', mode='w') as hostfile:
hostfile.write(wo_host)
WOShellExec.cmd_exec(self, "sed -i \"1i\\127.0.0.1 {0}\" /etc/hosts"
.format(wo_host))
if WOVariables.wo_distro == 'debian':
if WOVar.wo_distro == 'debian':
WOShellExec.cmd_exec(self, "/etc/init.d/hostname.sh start")
else:
WOShellExec.cmd_exec(self, "service hostname restart")
@@ -29,7 +29,7 @@ def check_fqdn_ip(self):
x = requests.get('http://v4.wordops.eu')
ip = (x.text).strip()
wo_fqdn = WOVariables.wo_fqdn
wo_fqdn = WOVar.wo_fqdn
y = requests.get('http://v4.wordops.eu/dns/{0}/'.format(wo_fqdn))
ip_fqdn = (y.text).strip()

View File

@@ -3,10 +3,10 @@ from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
from wo.core.variables import WOVariables
from wo.core.variables import WOVar
# db_path = self.app.config.get('site', 'db_path')
engine = create_engine(WOVariables.wo_db_uri, convert_unicode=True)
engine = create_engine(WOVar.wo_db_uri, convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))

View File

@@ -24,7 +24,7 @@ class WODomain():
else:
final_domain = domain_name
return (final_domain, domain_name)
return final_domain
def getlevel(self, domain):
"""
@@ -49,3 +49,4 @@ class WODomain():
root_domain = ('.'.join(domain_name[1:]))
suffix_file.close()
return (domain_type, root_domain)
return ('other', domain)

View File

@@ -6,7 +6,7 @@ import pymysql
from pymysql import DatabaseError, Error, connections
from wo.core.logging import Log
from wo.core.variables import WOVariables
from wo.core.variables import WOVar
class MySQLConnectionError(Exception):
@@ -115,7 +115,7 @@ class WOMysql():
stderr=subprocess.PIPE, shell=True)
p2 = subprocess.Popen("/usr/bin/pigz -c > "
"/var/wo-mysqlbackup/{0}{1}.sql.gz"
.format(dbs, WOVariables.wo_date),
.format(dbs, WOVar.wo_date),
stdin=p1.stdout,
shell=True)

View File

@@ -5,7 +5,7 @@ import re
from wo.core.fileutils import WOFileUtils
from wo.core.logging import Log
from wo.core.shellexec import WOShellExec
from wo.core.variables import WOVariables
from wo.core.variables import WOVar
class SSL:
@@ -63,11 +63,11 @@ class SSL:
self, '{0}/htdocs/'.format(wo_site_webroot))
if WOShellExec.cmd_exec(
self, "{0} --allow-root core is-installed"
.format(WOVariables.wo_wp_cli)):
.format(WOVar.wo_wp_cli)):
wo_siteurl = (
WOShellExec.cmd_exec_stdout(
self, "{0} option get siteurl "
.format(WOVariables.wo_wpcli_path) +
.format(WOVar.wo_wpcli_path) +
"--allow-root --quiet"))
test_url = re.split(":", wo_siteurl)
if not (test_url[0] == 'https'):
@@ -76,11 +76,11 @@ class SSL:
WOShellExec.cmd_exec(
self, "{0} option update siteurl "
"\'https://{1}\' --allow-root".format(
WOVariables.wo_wpcli_path, domain))
WOVar.wo_wpcli_path, domain))
WOShellExec.cmd_exec(
self, "{0} option update home "
"\'https://{1}\' --allow-root".format(
WOVariables.wo_wpcli_path, domain))
WOVar.wo_wpcli_path, domain))
WOShellExec.cmd_exec(
self, "{0} search-replace \'http://{0}\'"
"\'https://{0}\' --skip-columns=guid "

View File

@@ -9,6 +9,8 @@ Render Templates
class WOTemplate():
"""WordOps template utilities"""
def deploy(self, fileconf, template, data, overwrite=True):
"""Deploy template with render()"""
data = dict(data)

View File

@@ -1,13 +1,15 @@
"""WordOps core variable module"""
import configparser
import datetime
import os
import socket
from datetime import datetime
from re import match
from socket import getfqdn
import distro
from distro import linux_distribution
from sh import git
class WOVariables():
class WOVar():
"""Intialization of core variables"""
# WordOps version
@@ -23,14 +25,14 @@ class WOVariables():
wo_wpcli_path = '/usr/local/bin/wp'
# Current date and time of System
wo_date = datetime.datetime.now().strftime('%d%b%Y-%H-%M-%S')
wo_date = datetime.now().strftime('%d%b%Y-%H-%M-%S')
# WordOps core variables
wo_distro = distro.linux_distribution(
wo_distro = linux_distribution(
full_distribution_name=False)[0].lower()
wo_platform_version = distro.linux_distribution(
wo_platform_version = linux_distribution(
full_distribution_name=False)[1].lower()
wo_platform_codename = distro.linux_distribution(
wo_platform_codename = linux_distribution(
full_distribution_name=False)[2].lower()
# Get timezone of system
@@ -43,7 +45,7 @@ class WOVariables():
wo_timezone = "Europe/Amsterdam"
# Get FQDN of system
wo_fqdn = socket.getfqdn()
wo_fqdn = getfqdn()
# WordOps default webroot path
wo_webroot = '/var/www/'
@@ -64,11 +66,25 @@ class WOVariables():
wo_user = config['user']['name']
wo_email = config['user']['email']
except Exception:
print("WordOps (wo) require an username & and an email "
"address to configure Git (used to save server configurations)")
print("Your informations will ONLY be stored locally")
wo_user = input("Enter your name: ")
while wo_user == "":
print("Unfortunately, this can't be left blank")
wo_user = input("Enter your name: ")
wo_email = input("Enter your email: ")
os.system("git config --global user.name {0}".format(wo_user))
os.system(
"git config --global user.email {0}".format(wo_email))
while not match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
wo_email):
print("Whoops, seems like you made a typo - "
"the e-mailaddress is invalid...")
wo_email = input("Enter your email: ")
git.config("--global", "user.name", "{0}".format(wo_user))
git.config("--global", "user.email", "{0}".format(wo_email))
# MySQL hostname
wo_mysql_host = ""