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

@@ -23,7 +23,7 @@ from wo.core.services import WOService
from wo.core.shellexec import CommandExecutionError, WOShellExec
from wo.core.sslutils import SSL
from wo.core.template import WOTemplate
from wo.core.variables import WOVariables
from wo.core.variables import WOVar
from wo.core.nginxhashbucket import hashbucket
@@ -32,7 +32,7 @@ def pre_pref(self, apt_packages):
if ("mariadb-server" in apt_packages or "mariadb-client" in apt_packages):
# add mariadb repository excepted on raspbian and ubuntu 19.04
if (not WOVariables.wo_distro == 'raspbian'):
if (not WOVar.wo_distro == 'raspbian'):
Log.info(self, "Adding repository for MySQL, please wait...")
mysql_pref = ("Package: *\nPin: origin "
"sfo1.mirrors.digitalocean.com"
@@ -40,7 +40,7 @@ def pre_pref(self, apt_packages):
with open('/etc/apt/preferences.d/'
'MariaDB.pref', 'w') as mysql_pref_file:
mysql_pref_file.write(mysql_pref)
WORepo.add(self, repo_url=WOVariables.wo_mysql_repo)
WORepo.add(self, repo_url=WOVar.wo_mysql_repo)
WORepo.add_key(self, '0xcbcb082a1bb943db',
keyserver='keys.gnupg.net')
WORepo.add_key(self, '0xF1656F24C74CD1D8',
@@ -50,8 +50,8 @@ def pre_pref(self, apt_packages):
chars = ''.join(random.sample(string.ascii_letters, 24))
# configure MySQL non-interactive install
if ((WOVariables.wo_distro == 'raspbian') and
(WOVariables.wo_platform_codename == 'stretch')):
if ((WOVar.wo_distro == 'raspbian') and
(WOVar.wo_platform_codename == 'stretch')):
mariadb_ver = '10.1'
else:
mariadb_ver = '10.3'
@@ -106,26 +106,26 @@ def pre_pref(self, apt_packages):
WOFileUtils.chmod(self, "/etc/mysql/conf.d/my.cnf", 0o600)
# add nginx repository
if set(WOVariables.wo_nginx).issubset(set(apt_packages)):
if set(WOVar.wo_nginx).issubset(set(apt_packages)):
Log.info(self, "Adding repository for NGINX, please wait...")
if (WOVariables.wo_distro == 'ubuntu'):
WORepo.add(self, ppa=WOVariables.wo_nginx_repo)
if (WOVar.wo_distro == 'ubuntu'):
WORepo.add(self, ppa=WOVar.wo_nginx_repo)
Log.debug(self, 'Adding ppa for Nginx')
else:
WORepo.add(self, repo_url=WOVariables.wo_nginx_repo)
WORepo.add(self, repo_url=WOVar.wo_nginx_repo)
Log.debug(self, 'Adding repository for Nginx')
WORepo.add_key(self, WOVariables.wo_nginx_key)
WORepo.add_key(self, WOVar.wo_nginx_key)
# add php repository
if (set(WOVariables.wo_php73).issubset(set(apt_packages)) or
set(WOVariables.wo_php).issubset(set(apt_packages))):
if (set(WOVar.wo_php73).issubset(set(apt_packages)) or
set(WOVar.wo_php).issubset(set(apt_packages))):
Log.info(self, "Adding repository for PHP, please wait...")
if (WOVariables.wo_distro == 'ubuntu'):
if (WOVar.wo_distro == 'ubuntu'):
Log.debug(self, 'Adding ppa for PHP')
WORepo.add(self, ppa=WOVariables.wo_php_repo)
WORepo.add(self, ppa=WOVar.wo_php_repo)
else:
# Add repository for php
if (WOVariables.wo_platform_codename == 'buster'):
if (WOVar.wo_platform_codename == 'buster'):
php_pref = ("Package: *\nPin: origin "
"packages.sury.org"
"\nPin-Priority: 1000\n")
@@ -133,22 +133,22 @@ def pre_pref(self, apt_packages):
'PHP.pref', 'w') as php_pref_file:
php_pref_file.write(php_pref)
Log.debug(self, 'Adding repo_url of php for debian')
WORepo.add(self, repo_url=WOVariables.wo_php_repo)
WORepo.add(self, repo_url=WOVar.wo_php_repo)
Log.debug(self, 'Adding deb.sury GPG key')
WORepo.add_key(self, WOVariables.wo_php_key)
WORepo.add_key(self, WOVar.wo_php_key)
# add redis repository
if set(WOVariables.wo_redis).issubset(set(apt_packages)):
if set(WOVar.wo_redis).issubset(set(apt_packages)):
Log.info(self, "Adding repository for Redis, please wait...")
if WOVariables.wo_distro == 'ubuntu':
if WOVar.wo_distro == 'ubuntu':
Log.debug(self, 'Adding ppa for redis')
WORepo.add(self, ppa=WOVariables.wo_redis_repo)
WORepo.add(self, ppa=WOVar.wo_redis_repo)
def post_pref(self, apt_packages, packages, upgrade=False):
"""Post activity after installation of packages"""
if (apt_packages):
# Nginx configuration
if set(WOVariables.wo_nginx).issubset(set(apt_packages)):
if set(WOVar.wo_nginx).issubset(set(apt_packages)):
Log.info(self, "Applying Nginx configuration templates")
# Nginx main configuration
ngxcnf = '/etc/nginx/conf.d'
@@ -306,7 +306,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
with open("/etc/nginx/common/release",
"w") as release_file:
release_file.write("v{0}"
.format(WOVariables.wo_version))
.format(WOVar.wo_version))
release_file.close()
# Following files should not be overwrited
@@ -459,7 +459,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
"on https://{0}:22222 "
"or https://{1}:22222"
.format(server_ip.text,
WOVariables.wo_fqdn)])
WOVar.wo_fqdn)])
if not os.path.isfile("/opt/cf-update.sh"):
data = dict()
@@ -493,7 +493,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
"Use the command nginx -t to identify "
"the cause of this issue", False)
if set(WOVariables.wo_php).issubset(set(apt_packages)):
if set(WOVar.wo_php).issubset(set(apt_packages)):
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
Log.info(self, "Configuring php7.2-fpm")
ngxroot = '/var/www/'
@@ -517,7 +517,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
config['PHP']['max_execution_time'] = '300'
config['PHP']['max_input_time'] = '300'
config['PHP']['max_input_vars'] = '20000'
config['Date']['date.timezone'] = WOVariables.wo_timezone
config['Date']['date.timezone'] = WOVar.wo_timezone
config['opcache']['opcache.enable'] = '1'
config['opcache']['opcache.interned_strings_buffer'] = '8'
config['opcache']['opcache.max_accelerated_files'] = '10000'
@@ -627,7 +627,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
WOService.restart_service(self, 'php7.2-fpm')
# PHP7.3 configuration
if set(WOVariables.wo_php73).issubset(set(apt_packages)):
if set(WOVar.wo_php73).issubset(set(apt_packages)):
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
Log.info(self, "Configuring php7.3-fpm")
ngxroot = '/var/www/'
@@ -651,7 +651,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
config['PHP']['max_execution_time'] = '300'
config['PHP']['max_input_time'] = '300'
config['PHP']['max_input_vars'] = '20000'
config['Date']['date.timezone'] = WOVariables.wo_timezone
config['Date']['date.timezone'] = WOVar.wo_timezone
config['opcache']['opcache.enable'] = '1'
config['opcache']['opcache.interned_strings_buffer'] = '8'
config['opcache']['opcache.max_accelerated_files'] = '10000'
@@ -815,7 +815,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
WOGit.add(self, ["/etc/mysql"], msg="Adding MySQL into Git")
# create fail2ban configuration files
if set(WOVariables.wo_fail2ban).issubset(set(apt_packages)):
if set(WOVar.wo_fail2ban).issubset(set(apt_packages)):
WOGit.add(self, ["/etc/fail2ban"],
msg="Adding Fail2ban into Git")
if not os.path.isfile("/etc/fail2ban/jail.d/custom.conf"):
@@ -1004,7 +1004,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
WOService.restart_service(self, 'redis-server')
# ClamAV configuration
if set(WOVariables.wo_clamav).issubset(set(apt_packages)):
if set(WOVar.wo_clamav).issubset(set(apt_packages)):
Log.debug(self, "Setting up freshclam cronjob")
if not os.path.isfile("/opt/freshclam.sh"):
data = dict()
@@ -1032,26 +1032,26 @@ def post_pref(self, apt_packages, packages, upgrade=False):
Log.debug(self, 'Extracting file /var/lib/wo/tmp/pma.tar.gz to '
'location /var/lib/wo/tmp/')
if not os.path.exists('{0}22222/htdocs/db'
.format(WOVariables.wo_webroot)):
.format(WOVar.wo_webroot)):
Log.debug(self, "Creating new directory "
"{0}22222/htdocs/db"
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
os.makedirs('{0}22222/htdocs/db'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
if not os.path.exists('{0}22222/htdocs/db/pma/'
.format(WOVariables.wo_webroot)):
.format(WOVar.wo_webroot)):
shutil.move('/var/lib/wo/tmp/phpmyadmin-STABLE/',
'{0}22222/htdocs/db/pma/'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
shutil.copyfile('{0}22222/htdocs/db/pma'
'/config.sample.inc.php'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
'{0}22222/htdocs/db/pma/config.inc.php'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
Log.debug(self, 'Setting Blowfish Secret Key '
'FOR COOKIE AUTH to '
'{0}22222/htdocs/db/pma/config.inc.php file '
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
blowfish_key = ''.join([random.choice
(string.ascii_letters +
string.digits)
@@ -1059,7 +1059,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
WOFileUtils.searchreplace(self,
'{0}22222/htdocs/db/pma'
'/config.inc.php'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
"$cfg[\'blowfish_secret\']"
" = \'\';",
"$cfg[\'blowfish_secret\']"
@@ -1067,21 +1067,21 @@ def post_pref(self, apt_packages, packages, upgrade=False):
.format(blowfish_key))
Log.debug(self, 'Setting HOST Server For Mysql to '
'{0}22222/htdocs/db/pma/config.inc.php file '
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
WOFileUtils.searchreplace(self,
'{0}22222/htdocs/db/pma'
'/config.inc.php'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
"$cfg[\'Servers\'][$i][\'host\']"
" = \'localhost\';", "$cfg"
"[\'Servers\'][$i][\'host\'] "
"= \'{0}\';"
.format(WOVariables.wo_mysql_host))
.format(WOVar.wo_mysql_host))
Log.debug(self, 'Setting Privileges of webroot permission to '
'{0}22222/htdocs/db/pma file '
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
WOFileUtils.chown(self, '{0}22222/htdocs'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
'www-data',
'www-data',
recursive=True)
@@ -1107,19 +1107,19 @@ def post_pref(self, apt_packages, packages, upgrade=False):
"/var/www/22222/htdocs/db/pma/")
WOFileUtils.chown(
self, '{0}22222/htdocs/db/pma'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
'www-data',
'www-data',
recursive=True)
Log.valide(self, "Updating phpMyAdmin")
if not os.path.exists('{0}22222/htdocs/cache/'
'redis/phpRedisAdmin'
.format(WOVariables.wo_webroot)):
.format(WOVar.wo_webroot)):
Log.debug(self, "Creating new directory "
"{0}22222/htdocs/cache/redis"
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
os.makedirs('{0}22222/htdocs/cache/redis/phpRedisAdmin'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
if not os.path.isfile('/var/www/22222/htdocs/cache/redis/'
'phpRedisAdmin/composer.lock'):
WOShellExec.cmd_exec(
@@ -1128,7 +1128,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
"erik-dubbelboer/php-redis-admin "
"/var/www/22222/htdocs/cache/redis/phpRedisAdmin")
WOFileUtils.chown(self, '{0}22222/htdocs'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
'www-data',
'www-data',
recursive=True)
@@ -1194,25 +1194,25 @@ def post_pref(self, apt_packages, packages, upgrade=False):
for x in packages):
Log.debug(self, "Extracting wo-dashboard.tar.gz "
"to location {0}22222/htdocs/"
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
WOExtract.extract(self, '/var/lib/wo/tmp/'
'wo-dashboard.tar.gz',
'{0}22222/htdocs'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
wo_wan = os.popen("/sbin/ip -4 route get 8.8.8.8 | "
"grep -oP \"dev [^[:space:]]+ \" "
"| cut -d ' ' -f 2").read()
if (wo_wan != 'eth0' and wo_wan != ''):
WOFileUtils.searchreplace(self,
"{0}22222/htdocs/index.html"
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
"eth0",
"{0}".format(wo_wan))
Log.debug(self, "Setting Privileges to "
"{0}22222/htdocs"
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
WOFileUtils.chown(self, '{0}22222/htdocs'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
'www-data',
'www-data',
recursive=True)
@@ -1222,18 +1222,18 @@ def post_pref(self, apt_packages, packages, upgrade=False):
for x in packages):
Log.debug(self, "Extracting extplorer.tar.gz "
"to location {0}22222/htdocs/files"
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
WOExtract.extract(self, '/var/lib/wo/tmp/extplorer.tar.gz',
'/var/lib/wo/tmp/')
shutil.move('/var/lib/wo/tmp/extplorer-{0}'
.format(WOVariables.wo_extplorer),
.format(WOVar.wo_extplorer),
'{0}22222/htdocs/files'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
Log.debug(self, "Setting Privileges to "
"{0}22222/htdocs/files"
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
WOFileUtils.chown(self, '{0}22222/htdocs'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
'www-data',
'www-data',
recursive=True)
@@ -1247,41 +1247,41 @@ def post_pref(self, apt_packages, packages, upgrade=False):
self, '/var/lib/wo/tmp/webgrind.tar.gz',
'/var/lib/wo/tmp/')
if not os.path.exists('{0}22222/htdocs/php'
.format(WOVariables.wo_webroot)):
.format(WOVar.wo_webroot)):
Log.debug(self, "Creating directroy "
"{0}22222/htdocs/php"
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
os.makedirs('{0}22222/htdocs/php'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
if not os.path.exists('{0}22222/htdocs/php/webgrind'
.format(WOVariables.wo_webroot)):
.format(WOVar.wo_webroot)):
shutil.move('/var/lib/wo/tmp/webgrind-master/',
'{0}22222/htdocs/php/webgrind'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
WOFileUtils.searchreplace(
self, "{0}22222/htdocs/php/webgrind/"
"config.php"
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
"/usr/local/bin/dot", "/usr/bin/dot")
WOFileUtils.searchreplace(
self, "{0}22222/htdocs/php/webgrind/"
"config.php"
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
"Europe/Copenhagen",
WOVariables.wo_timezone)
WOVar.wo_timezone)
WOFileUtils.searchreplace(
self, "{0}22222/htdocs/php/webgrind/"
"config.php"
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
"90", "100")
Log.debug(self, "Setting Privileges of webroot permission to "
"{0}22222/htdocs/php/webgrind/ file "
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
WOFileUtils.chown(self, '{0}22222/htdocs'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
'www-data',
'www-data',
recursive=True)
@@ -1294,20 +1294,20 @@ def post_pref(self, apt_packages, packages, upgrade=False):
self, '/var/lib/wo/tmp/anemometer.tar.gz',
'/var/lib/wo/tmp/')
if not os.path.exists('{0}22222/htdocs/db/'
.format(WOVariables.wo_webroot)):
.format(WOVar.wo_webroot)):
Log.debug(self, "Creating directory")
os.makedirs('{0}22222/htdocs/db/'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
if not os.path.exists('{0}22222/htdocs/db/anemometer'
.format(WOVariables.wo_webroot)):
.format(WOVar.wo_webroot)):
shutil.move('/var/lib/wo/tmp/Anemometer-master',
'{0}22222/htdocs/db/anemometer'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
chars = ''.join(random.sample(string.ascii_letters, 8))
try:
WOShellExec.cmd_exec(self, 'mysql < {0}22222/htdocs/db'
'/anemometer/install.sql'
.format(WOVariables.wo_webroot))
.format(WOVar.wo_webroot))
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "failed to configure Anemometer",
@@ -1334,11 +1334,11 @@ def post_pref(self, apt_packages, packages, upgrade=False):
# Custom Anemometer configuration
Log.debug(self, "configration Anemometer")
data = dict(host=WOVariables.wo_mysql_host, port='3306',
data = dict(host=WOVar.wo_mysql_host, port='3306',
user='anemometer', password=chars)
WOTemplate.deploy(self, '{0}22222/htdocs/db/anemometer'
'/conf/config.inc.php'
.format(WOVariables.wo_webroot),
.format(WOVar.wo_webroot),
'anemometer.mustache', data)
# pt-query-advisor