Files
WPIQ/wo/cli/plugins/stack.py

2258 lines
118 KiB
Python
Raw Normal View History

2018-11-13 21:55:59 +01:00
"""Stack Plugin for WordOps"""
2019-04-25 01:34:33 +02:00
from cement.core import handler, hook
from cement.core.controller import CementBaseController, expose
import codecs
2018-11-13 21:55:59 +01:00
import configparser
import os
import pwd
import random
import shutil
import string
import re
2019-08-04 12:36:42 +02:00
import requests
2019-06-19 21:18:32 +02:00
import psutil
# from pynginxconfig import NginxConfig
from wo.cli.plugins.site_functions import *
from wo.cli.plugins.sitedb import *
2018-11-13 21:55:59 +01:00
from wo.cli.plugins.stack_migrate import WOStackMigrateController
from wo.cli.plugins.stack_services import WOStackStatusController
2018-11-13 21:55:59 +01:00
from wo.cli.plugins.stack_upgrade import WOStackUpgradeController
from wo.core.addswap import WOSwap
from wo.core.apt_repo import WORepo
from wo.core.aptget import WOAptGet
from wo.core.cron import WOCron
from wo.core.download import WODownload
from wo.core.extract import WOExtract
from wo.core.fileutils import WOFileUtils
from wo.core.git import WOGit
2018-11-13 21:55:59 +01:00
from wo.core.logging import Log
from wo.core.mysql import WOMysql
from wo.core.services import WOService
from wo.core.shellexec import CommandExecutionError, WOShellExec
from wo.core.variables import WOVariables
2018-11-13 21:55:59 +01:00
def wo_stack_hook(app):
pass
class WOStackController(CementBaseController):
class Meta:
label = 'stack'
stacked_on = 'base'
stacked_type = 'nested'
description = 'Stack command manages stack operations'
arguments = [
(['--all'],
dict(help='Install all stacks at once', action='store_true')),
(['--web'],
dict(help='Install web stack', action='store_true')),
(['--admin'],
dict(help='Install admin tools stack', action='store_true')),
2019-07-19 15:21:17 +02:00
(['--security'],
dict(help='Install security tools stack', action='store_true')),
2018-11-13 21:55:59 +01:00
(['--nginx'],
dict(help='Install Nginx stack', action='store_true')),
(['--php'],
dict(help='Install PHP 7.2 stack', action='store_true')),
(['--php73'],
dict(help='Install PHP 7.3 stack', action='store_true')),
2018-11-13 21:55:59 +01:00
(['--mysql'],
dict(help='Install MySQL stack', action='store_true')),
(['--wpcli'],
dict(help='Install WPCLI stack', action='store_true')),
(['--phpmyadmin'],
dict(help='Install PHPMyAdmin stack', action='store_true')),
2019-04-01 20:59:53 +02:00
(['--composer'],
dict(help='Install Composer stack', action='store_true')),
(['--netdata'],
2019-04-02 01:59:40 +02:00
dict(help='Install Netdata monitoring suite',
action='store_true')),
2019-04-23 19:03:42 +02:00
(['--dashboard'],
dict(help='Install WordOps dashboard', action='store_true')),
2018-11-13 21:55:59 +01:00
(['--adminer'],
dict(help='Install Adminer stack', action='store_true')),
2019-04-25 01:38:14 +02:00
(['--fail2ban'],
dict(help='Install Fail2ban stack', action='store_true')),
2018-11-13 21:55:59 +01:00
(['--utils'],
dict(help='Install Utils stack', action='store_true')),
(['--redis'],
dict(help='Install Redis', action='store_true')),
(['--phpredisadmin'],
dict(help='Install phpRedisAdmin', action='store_true')),
2019-07-19 13:47:29 +02:00
(['--proftpd'],
dict(help='Install ProFTPd', action='store_true')),
]
usage = "wo stack (command) [options]"
2018-11-13 21:55:59 +01:00
@expose(hide=True)
def default(self):
"""default action of wo stack command"""
self.app.args.print_help()
@expose(hide=True)
def pre_pref(self, apt_packages):
"""Pre settings to do before installation packages"""
if set(WOVariables.wo_mysql).issubset(set(apt_packages)):
# add mariadb repository excepted on raspbian and ubuntu 19.04
if (not WOVariables.wo_distro == 'raspbian'):
2019-04-29 13:13:44 +02:00
Log.info(self, "Adding repository for MySQL, please wait...")
mysql_pref = ("Package: *\nPin: origin "
"sfo1.mirrors.digitalocean.com"
"\nPin-Priority: 1000\n")
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)
Log.debug(self, 'Adding key for {0}'
.format(WOVariables.wo_mysql_repo))
WORepo.add_key(self, '0xcbcb082a1bb943db',
keyserver="keyserver.ubuntu.com")
WORepo.add_key(self, '0xF1656F24C74CD1D8',
keyserver="keyserver.ubuntu.com")
# generate random 24 characters root password
2019-04-29 13:13:44 +02:00
chars = ''.join(random.sample(string.ascii_letters, 24))
# configure MySQL non-interactive install
if (not WOVariables.wo_distro == 'raspbian'):
2019-05-01 00:16:46 +02:00
Log.debug(self, "Pre-seeding MySQL")
Log.debug(self, "echo \"mariadb-server-10.3 "
"mysql-server/root_password "
"password \" | "
"debconf-set-selections")
try:
WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.3 "
"mysql-server/root_password "
"password {chars}\" | "
"debconf-set-selections"
.format(chars=chars),
log=False)
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
2019-05-01 00:16:46 +02:00
Log.error("Failed to initialize MySQL package")
2018-11-13 21:55:59 +01:00
2019-05-01 00:16:46 +02:00
Log.debug(self, "echo \"mariadb-server-10.3 "
"mysql-server/root_password_again "
"password \" | "
"debconf-set-selections")
try:
WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.3 "
"mysql-server/root_password_again "
"password {chars}\" | "
"debconf-set-selections"
.format(chars=chars),
log=False)
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
2019-05-01 00:16:46 +02:00
Log.error("Failed to initialize MySQL package")
else:
Log.debug(self, "Pre-seeding MySQL")
Log.debug(self, "echo \"mariadb-server-10.1 "
"mysql-server/root_password "
"password \" | "
"debconf-set-selections")
try:
WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.1 "
"mysql-server/root_password "
"password {chars}\" | "
"debconf-set-selections"
.format(chars=chars),
log=False)
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
2019-05-01 00:16:46 +02:00
Log.error("Failed to initialize MySQL package")
Log.debug(self, "echo \"mariadb-server-10.1 "
"mysql-server/root_password_again "
"password \" | "
"debconf-set-selections")
try:
WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.1 "
"mysql-server/root_password_again "
"password {chars}\" | "
"debconf-set-selections"
.format(chars=chars),
log=False)
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
2019-07-29 15:08:49 +02:00
Log.error(self, "Failed to initialize MySQL package")
# generate my.cnf root credentials
2018-11-13 21:55:59 +01:00
mysql_config = """
[client]
user = root
password = {chars}
""".format(chars=chars)
config = configparser.ConfigParser()
config.read_string(mysql_config)
Log.debug(self, 'Writting configuration into MySQL file')
conf_path = "/etc/mysql/conf.d/my.cnf"
os.makedirs(os.path.dirname(conf_path), exist_ok=True)
with open(conf_path, encoding='utf-8',
mode='w') as configfile:
config.write(configfile)
Log.debug(self, 'Setting my.cnf permission')
WOFileUtils.chmod(self, "/etc/mysql/conf.d/my.cnf", 0o600)
# add nginx repository
2018-11-13 21:55:59 +01:00
if set(WOVariables.wo_nginx).issubset(set(apt_packages)):
if (WOVariables.wo_distro == 'ubuntu'):
2019-07-09 04:07:27 +02:00
Log.info(self, "Adding repository for NGINX, please wait...")
WORepo.add(self, ppa=WOVariables.wo_nginx_repo)
Log.debug(self, 'Adding ppa for Nginx')
else:
Log.info(self, "Adding repository for NGINX, please wait...")
2019-07-09 04:07:27 +02:00
WORepo.add(self, repo_url=WOVariables.wo_nginx_repo)
Log.debug(self, 'Adding repository for Nginx')
WORepo.add_key(self, WOVariables.wo_nginx_key)
2018-11-13 21:55:59 +01:00
# add php repository
2019-03-16 10:30:52 +01:00
if (set(WOVariables.wo_php73).issubset(set(apt_packages)) or
set(WOVariables.wo_php).issubset(set(apt_packages))):
if (WOVariables.wo_distro == 'ubuntu'):
Log.info(self, "Adding repository for PHP, please wait...")
2018-11-13 21:55:59 +01:00
Log.debug(self, 'Adding ppa for PHP')
WORepo.add(self, ppa=WOVariables.wo_php_repo)
2019-03-16 10:30:52 +01:00
else:
Log.info(self, "Adding repository for PHP, please wait...")
2018-11-13 21:55:59 +01:00
# Add repository for php
2019-07-20 00:58:08 +02:00
if (WOVariables.wo_platform_codename == 'buster'):
php_pref = ("Package: *\nPin: origin "
"packages.sury.org"
"\nPin-Priority: 1000\n")
with open('/etc/apt/preferences.d/'
'PHP.pref', 'w') as php_pref_file:
php_pref_file.write(php_pref)
2019-03-15 16:45:10 +01:00
Log.debug(self, 'Adding repo_url of php for debian')
WORepo.add(self, repo_url=WOVariables.wo_php_repo)
Log.debug(self, 'Adding deb.sury GPG key')
WORepo.add_key(self, WOVariables.wo_php_key)
# add redis repository
2018-11-13 21:55:59 +01:00
if set(WOVariables.wo_redis).issubset(set(apt_packages)):
Log.info(self, "Adding repository for Redis, please wait...")
if WOVariables.wo_distro == 'ubuntu':
2018-11-13 21:55:59 +01:00
Log.debug(self, 'Adding ppa for redis')
WORepo.add(self, ppa=WOVariables.wo_redis_repo)
2019-03-16 10:30:52 +01:00
else:
Log.debug(self, 'Adding repo_url of redis for debian')
2018-11-13 21:55:59 +01:00
@expose(hide=True)
def post_pref(self, apt_packages, packages):
"""Post activity after installation of packages"""
2019-04-30 18:50:30 +02:00
if (apt_packages):
2018-11-13 21:55:59 +01:00
2019-07-25 11:40:12 +02:00
# Nginx configuration
2018-11-13 21:55:59 +01:00
if set(WOVariables.wo_nginx).issubset(set(apt_packages)):
2019-07-28 21:23:07 +02:00
# Fix for white screen death with NGINX PLUS
if not WOFileUtils.grep(self, '/etc/nginx/fastcgi_params',
'SCRIPT_FILENAME'):
with open('/etc/nginx/fastcgi_params',
encoding='utf-8', mode='a') as wo_nginx:
wo_nginx.write('fastcgi_param \tSCRIPT_FILENAME '
'\t$request_filename;\n')
2018-11-13 21:55:59 +01:00
2019-07-25 11:40:12 +02:00
if os.path.isfile('/etc/nginx/nginx.conf'):
2019-03-20 02:49:46 +01:00
data = dict(php="9000", debug="9001",
2019-03-23 18:05:30 +01:00
php7="9070", debug7="9170")
2019-03-20 02:49:46 +01:00
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/upstream.conf')
wo_nginx = open('/etc/nginx/conf.d/upstream.conf',
encoding='utf-8', mode='w')
self.app.render(
(data), 'upstream.mustache', out=wo_nginx)
wo_nginx.close()
data = dict(phpconf=True if
WOAptGet.is_installed(self, 'php7.2-fpm')
else False)
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/stub_status.conf')
wo_nginx = open('/etc/nginx/conf.d/stub_status.conf',
encoding='utf-8', mode='w')
self.app.render(
(data), 'stub_status.mustache', out=wo_nginx)
wo_nginx.close()
data = dict()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/webp.conf')
wo_nginx = open('/etc/nginx/conf.d/webp.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'webp.mustache',
out=wo_nginx)
wo_nginx.close()
2019-03-06 15:32:07 +01:00
2019-03-20 21:59:56 +01:00
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/'
'map-wp-fastcgi-cache.conf')
wo_nginx = open('/etc/nginx/conf.d/'
'map-wp-fastcgi-cache.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'map-wp.mustache',
out=wo_nginx)
wo_nginx.close()
2019-07-27 22:08:16 +02:00
# Setup Nginx common directory
2019-03-20 02:49:46 +01:00
if not os.path.exists('/etc/nginx/common'):
Log.debug(self, 'Creating directory'
'/etc/nginx/common')
os.makedirs('/etc/nginx/common')
2019-07-25 11:40:12 +02:00
if os.path.exists('/etc/nginx/common'):
2019-03-20 02:49:46 +01:00
data = dict(webroot=WOVariables.wo_webroot)
2019-07-27 22:08:16 +02:00
# Common Configuration
2019-03-20 02:49:46 +01:00
Log.debug(self, 'Writting the nginx configuration to '
2019-03-27 04:58:25 +01:00
'file /etc/nginx/common/locations-wo.conf')
wo_nginx = open('/etc/nginx/common/locations-wo.conf',
2019-03-20 02:49:46 +01:00
encoding='utf-8', mode='w')
self.app.render((data), 'locations.mustache',
out=wo_nginx)
wo_nginx.close()
2019-07-27 22:08:16 +02:00
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpsubdir.conf')
wo_nginx = open('/etc/nginx/common/wpsubdir.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpsubdir.mustache',
out=wo_nginx)
wo_nginx.close()
# PHP 7.2 conf
2019-03-20 02:49:46 +01:00
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/php72.conf')
wo_nginx = open('/etc/nginx/common/php72.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'php.mustache',
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpcommon-php72.conf')
wo_nginx = open('/etc/nginx/common/wpcommon-php72.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpcommon.mustache',
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpfc-php72.conf')
wo_nginx = open('/etc/nginx/common/wpfc-php72.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpfc.mustache',
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpsc-php72.conf')
wo_nginx = open('/etc/nginx/common/wpsc-php72.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpsc.mustache',
out=wo_nginx)
wo_nginx.close()
2019-07-27 22:08:16 +02:00
# PHP 7.3 conf
if os.path.isdir("/etc/nginx/common"):
data = dict()
2018-11-13 21:55:59 +01:00
2019-03-20 02:49:46 +01:00
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/php73.conf')
wo_nginx = open('/etc/nginx/common/php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'php7.mustache',
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpcommon-php73.conf')
wo_nginx = open('/etc/nginx/common/wpcommon-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpcommon-php7.mustache',
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpfc-php73.conf')
wo_nginx = open('/etc/nginx/common/wpfc-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpfc-php7.mustache',
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpsc-php73.conf')
wo_nginx = open('/etc/nginx/common/wpsc-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpsc-php7.mustache',
out=wo_nginx)
wo_nginx.close()
2019-07-25 11:40:12 +02:00
# create redis conf
data = dict()
2019-03-27 04:58:25 +01:00
Log.debug(self, 'Writting the nginx configuration to '
2019-07-25 11:40:12 +02:00
'file /etc/nginx/common/redis-php72.conf')
wo_nginx = open('/etc/nginx/common/redis-php72.conf',
2019-03-27 04:58:25 +01:00
encoding='utf-8', mode='w')
2019-07-25 11:40:12 +02:00
self.app.render((data), 'redis.mustache',
out=wo_nginx)
wo_nginx.close()
data = dict()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/redis-php73.conf')
wo_nginx = open('/etc/nginx/common/redis-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'redis-php7.mustache',
2019-03-27 04:58:25 +01:00
out=wo_nginx)
wo_nginx.close()
2019-04-27 03:02:26 +02:00
2019-03-31 17:14:17 +02:00
with open("/etc/nginx/common/release",
"a") as release_file:
2019-04-27 03:02:26 +02:00
release_file.write("v{0}"
.format(WOVariables.wo_version))
2019-04-01 20:59:53 +02:00
release_file.close()
2019-03-27 04:58:25 +01:00
2019-07-25 11:40:12 +02:00
# Following files should not be overwrited
if not os.path.isfile('/etc/nginx/common/acl.conf'):
data = dict(webroot=WOVariables.wo_webroot)
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/acl.conf')
wo_nginx = open('/etc/nginx/common/acl.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'acl.mustache',
out=wo_nginx)
wo_nginx.close()
2019-07-27 22:08:16 +02:00
if not os.path.isfile('/etc/nginx/conf.d/blockips.conf'):
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/blockips.conf')
wo_nginx = open('/etc/nginx/conf.d/blockips.conf',
encoding='utf-8', mode='w')
self.app.render(
(data), 'blockips.mustache', out=wo_nginx)
wo_nginx.close()
if not os.path.isfile('/etc/nginx/conf.d/fastcgi.conf'):
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/fastcgi.conf')
wo_nginx = open('/etc/nginx/conf.d/fastcgi.conf',
encoding='utf-8', mode='w')
self.app.render(
(data), 'fastcgi.mustache', out=wo_nginx)
wo_nginx.close()
2019-07-25 11:40:12 +02:00
# add redis cache format if not already done
if (os.path.isfile("/etc/nginx/nginx.conf") and
not os.path.isfile("/etc/nginx/conf.d"
"/redis.conf")):
with open("/etc/nginx/conf.d/"
"redis.conf", "a") as redis_file:
redis_file.write("# Log format Settings\n"
"log_format rt_cache_redis "
"'$remote_addr "
"$upstream_response_time "
"$srcache_fetch_status "
"[$time_local] '\n"
"'$http_host \"$request\" $status"
" $body_bytes_sent '\n"
"'\"$http_referer\" "
"\"$http_user_agent\"';\n")
2019-03-15 16:51:58 +01:00
# Nginx-Plus does not have nginx
# package structure like this
2018-11-13 21:55:59 +01:00
# So creating directories
2019-03-29 17:20:59 +01:00
if not os.path.exists('/etc/nginx/sites-available'):
Log.debug(self, 'Creating directory'
2019-03-29 17:58:50 +01:00
'/etc/nginx/sites-available')
2019-03-29 17:20:59 +01:00
os.makedirs('/etc/nginx/sites-available')
2019-03-20 04:47:00 +01:00
2019-03-29 17:20:59 +01:00
if not os.path.exists('/etc/nginx/sites-enabled'):
Log.debug(self, 'Creating directory'
2019-03-29 17:58:50 +01:00
'/etc/nginx/sites-available')
2019-03-29 17:20:59 +01:00
os.makedirs('/etc/nginx/sites-enabled')
2018-11-13 21:55:59 +01:00
# 22222 port settings
2019-03-29 17:20:59 +01:00
if not os.path.isfile("/etc/nginx/sites-available/22222"):
2018-11-13 21:55:59 +01:00
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/sites-available/'
'22222')
wo_nginx = open('/etc/nginx/sites-available/22222',
encoding='utf-8', mode='w')
self.app.render((data), '22222.mustache',
out=wo_nginx)
wo_nginx.close()
passwd = ''.join([random.choice
(string.ascii_letters + string.digits)
2019-08-04 12:24:10 +02:00
for n in range(16)])
2018-11-13 21:55:59 +01:00
try:
WOShellExec.cmd_exec(self, "printf \"WordOps:"
"$(openssl passwd -crypt "
"{password} 2> /dev/null)\n\""
"> /etc/nginx/htpasswd-wo "
"2>/dev/null"
.format(password=passwd))
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
2018-11-13 21:55:59 +01:00
Log.error(self, "Failed to save HTTP Auth")
# Create Symbolic link for 22222
WOFileUtils.create_symlink(self, ['/etc/nginx/'
'sites-available/'
'22222',
'/etc/nginx/'
'sites-enabled/'
'22222'])
# Create log and cert folder and softlinks
if not os.path.exists('{0}22222/logs'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Creating directory "
"{0}22222/logs "
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/logs'
.format(WOVariables.wo_webroot))
if not os.path.exists('{0}22222/cert'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Creating directory "
"{0}22222/cert"
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/cert'
.format(WOVariables.wo_webroot))
2019-04-12 02:43:41 +02:00
if not os.path.exists('{0}22222/conf/nginx'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Creating directory "
"{0}22222/conf/nginx"
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/conf/nginx'
.format(WOVariables.wo_webroot))
2018-11-13 21:55:59 +01:00
WOFileUtils.create_symlink(self, ['/var/log/nginx/'
'22222.access.log',
'{0}22222/'
'logs/access.log'
.format(WOVariables.wo_webroot)]
2018-11-13 21:55:59 +01:00
)
WOFileUtils.create_symlink(self, ['/var/log/nginx/'
'22222.error.log',
'{0}22222/'
'logs/error.log'
.format(WOVariables.wo_webroot)]
2018-11-13 21:55:59 +01:00
)
try:
WOShellExec.cmd_exec(self, "openssl genrsa -out "
"{0}22222/cert/22222.key 2048"
.format(WOVariables.wo_webroot))
WOShellExec.cmd_exec(self, "openssl req -new -batch "
2019-03-13 05:02:53 +01:00
"-subj /commonName=localhost/ "
2018-11-13 21:55:59 +01:00
"-key {0}22222/cert/22222.key "
"-out {0}22222/cert/"
"22222.csr"
.format(WOVariables.wo_webroot))
WOFileUtils.mvfile(self, "{0}22222/cert/22222.key"
.format(WOVariables.wo_webroot),
"{0}22222/cert/"
"22222.key.org"
.format(WOVariables.wo_webroot))
WOShellExec.cmd_exec(self, "openssl rsa -in "
"{0}22222/cert/"
"22222.key.org -out "
"{0}22222/cert/22222.key"
.format(WOVariables.wo_webroot))
WOShellExec.cmd_exec(self, "openssl x509 -req -days "
"3652 -in {0}22222/cert/"
"22222.csr -signkey {0}"
"22222/cert/22222.key -out "
"{0}22222/cert/22222.crt"
.format(WOVariables.wo_webroot))
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error(
2019-04-11 20:35:03 +02:00
self, "Failed to generate HTTPS "
"certificate for 22222")
2019-08-04 19:21:53 +02:00
server_ip = requests.get('http://v4.wordops.eu')
2018-11-13 21:55:59 +01:00
2019-04-12 02:43:41 +02:00
if not os.path.isfile('{0}22222/conf/nginx/ssl.conf'
.format(WOVariables.wo_webroot)):
2019-08-04 19:21:53 +02:00
2019-04-21 00:56:05 +02:00
with open("/var/www/22222/conf/nginx/"
"ssl.conf", "a") as php_file:
2019-04-12 02:43:41 +02:00
php_file.write("ssl_certificate "
"/var/www/22222/cert/22222.crt;\n"
"ssl_certificate_key "
"/var/www/22222/cert/22222.key;\n")
2018-11-13 21:55:59 +01:00
# Nginx Configation into GIT
WOGit.add(self,
["/etc/nginx"], msg="Adding Nginx into Git")
WOService.reload_service(self, 'nginx')
2019-08-04 19:21:53 +02:00
2019-03-20 21:59:56 +01:00
if set(["nginx"]).issubset(set(apt_packages)):
2019-08-04 16:51:17 +02:00
print("WordOps backend configuration was successful\n"
2019-08-04 12:24:10 +02:00
"You can access it on : https://{0}:22222"
.format(server_ip))
2019-03-20 21:59:56 +01:00
print("HTTP Auth User Name: WordOps" +
"\nHTTP Auth Password : {0}".format(passwd))
2018-11-13 21:55:59 +01:00
WOService.reload_service(self, 'nginx')
else:
2019-03-20 02:12:13 +01:00
self.msg = (self.msg + ["HTTP Auth User "
"Name: WordOps"] +
2019-04-23 19:03:42 +02:00
["HTTP Auth Password : {0}"
.format(passwd)])
2019-08-04 16:51:17 +02:00
self.msg = (self.msg + ["WordOps backend is available "
2019-08-04 18:43:38 +02:00
"on https://{0}:22222 "
"or https://{1}:22222"
.format(server_ip.text,
WOVariables.wo_fqdn)])
2018-11-13 21:55:59 +01:00
else:
WOService.restart_service(self, 'nginx')
# create nginx configuration for redis
2018-11-13 21:55:59 +01:00
if set(WOVariables.wo_redis).issubset(set(apt_packages)):
2019-07-25 11:40:12 +02:00
if os.path.isdir('/etc/nginx/common'):
2018-11-13 21:55:59 +01:00
data = dict()
Log.debug(self, 'Writting the nginx configuration to '
2019-03-05 17:03:23 +01:00
'file /etc/nginx/common/redis-php72.conf')
wo_nginx = open('/etc/nginx/common/redis-php72.conf',
2018-11-13 21:55:59 +01:00
encoding='utf-8', mode='w')
self.app.render((data), 'redis.mustache',
out=wo_nginx)
wo_nginx.close()
if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
if not WOFileUtils.grep(self, "/etc/nginx/conf.d/"
"upstream.conf",
"redis"):
with open("/etc/nginx/conf.d/upstream.conf",
"a") as redis_file:
redis_file.write("upstream redis {\n"
" server 127.0.0.1:6379;\n"
" keepalive 10;\n}\n")
2019-03-15 17:16:49 +01:00
if os.path.isfile("/etc/nginx/nginx.conf"):
if not os.path.isfile("/etc/nginx/conf.d/redis.conf"):
with open("/etc/nginx/conf.d/redis.conf",
"a") as redis_file:
redis_file.write("# Log format Settings\n"
"log_format rt_cache_redis "
"'$remote_addr "
"$upstream_response_time "
"$srcache_fetch_status "
"[$time_local]"
" '\n '$http_host"
" \"$request\" "
"$status $body_bytes_sent '\n"
"'\"$http_referer\" "
"\"$http_user_agent\"';\n")
2018-11-13 21:55:59 +01:00
2019-03-15 17:28:08 +01:00
if set(WOVariables.wo_php).issubset(set(apt_packages)):
2018-11-13 21:55:59 +01:00
# Create log directories
2018-12-03 20:17:22 +01:00
if not os.path.exists('/var/log/php/7.2/'):
Log.debug(self, 'Creating directory /var/log/php/7.2/')
os.makedirs('/var/log/php/7.2/')
2018-11-13 21:55:59 +01:00
2018-12-03 20:17:22 +01:00
# Parse etc/php/7.2/fpm/php.ini
2018-11-13 21:55:59 +01:00
config = configparser.ConfigParser()
2019-03-20 02:12:13 +01:00
Log.debug(self, "configuring php file "
"/etc/php/7.2/fpm/php.ini")
2018-12-03 20:17:22 +01:00
config.read('/etc/php/7.2/fpm/php.ini')
2018-11-13 21:55:59 +01:00
config['PHP']['expose_php'] = 'Off'
config['PHP']['post_max_size'] = '100M'
config['PHP']['upload_max_filesize'] = '100M'
config['PHP']['max_execution_time'] = '300'
2019-07-31 20:50:56 +02:00
config['PHP']['max_input_time'] = '300'
2019-03-20 02:12:13 +01:00
config['PHP']['max_input_vars'] = '20000'
config['Date']['date.timezone'] = WOVariables.wo_timezone
config['opcache']['opcache.enable'] = '1'
config['opcache']['opcache.interned_strings_buffer'] = '8'
config['opcache']['opcache.max_accelerated_files'] = '10000'
config['opcache']['opcache.memory_consumption'] = '256'
config['opcache']['opcache.save_comments'] = '1'
2019-07-31 20:50:56 +02:00
config['opcache']['opcache.revalidate_freq'] = '5'
config['opcache']['opcache.consistency_checks'] = '0'
2019-03-20 02:12:13 +01:00
config['opcache']['opcache.validate_timestamps'] = '1'
2018-12-03 20:17:22 +01:00
with open('/etc/php/7.2/fpm/php.ini',
2018-11-13 21:55:59 +01:00
encoding='utf-8', mode='w') as configfile:
Log.debug(self, "Writting php configuration into "
2018-12-03 20:17:22 +01:00
"/etc/php/7.2/fpm/php.ini")
2018-11-13 21:55:59 +01:00
config.write(configfile)
2018-12-03 20:17:22 +01:00
# Parse /etc/php/7.2/fpm/php-fpm.conf
data = dict(pid="/run/php/php7.2-fpm.pid",
error_log="/var/log/php/7.2/fpm.log",
include="/etc/php/7.2/fpm/pool.d/*.conf")
Log.debug(self, "writting php7.2 configuration into "
"/etc/php/7.2/fpm/php-fpm.conf")
2018-12-03 20:17:22 +01:00
wo_php_fpm = open('/etc/php/7.2/fpm/php-fpm.conf',
encoding='utf-8', mode='w')
2018-11-13 21:55:59 +01:00
self.app.render((data), 'php-fpm.mustache', out=wo_php_fpm)
wo_php_fpm.close()
2018-12-03 20:17:22 +01:00
# Parse /etc/php/7.2/fpm/pool.d/www.conf
2018-11-13 21:55:59 +01:00
config = configparser.ConfigParser()
2019-03-20 02:12:13 +01:00
config.read_file(codecs.open('/etc/php/7.2/fpm/'
'pool.d/www.conf',
2018-11-13 21:55:59 +01:00
"r", "utf8"))
config['www']['ping.path'] = '/ping'
config['www']['pm.status_path'] = '/status'
2019-03-20 02:12:13 +01:00
config['www']['pm.max_requests'] = '1500'
config['www']['pm.max_children'] = '50'
config['www']['pm.start_servers'] = '10'
config['www']['pm.min_spare_servers'] = '5'
config['www']['pm.max_spare_servers'] = '15'
2019-03-21 17:27:51 +01:00
config['www']['request_terminate_timeout'] = '300'
2018-11-13 21:55:59 +01:00
config['www']['pm'] = 'ondemand'
config['www']['chdir'] = '/'
config['www']['prefix'] = '/var/run/php'
config['www']['listen'] = 'php72-fpm.sock'
2019-03-21 17:27:51 +01:00
config['www']['listen.mode'] = '0660'
config['www']['listen.backlog'] = '32768'
2019-03-21 17:27:51 +01:00
config['www']['catch_workers_output'] = 'yes'
2018-12-03 20:17:22 +01:00
with codecs.open('/etc/php/7.2/fpm/pool.d/www.conf',
2018-11-13 21:55:59 +01:00
encoding='utf-8', mode='w') as configfile:
2018-12-03 20:17:22 +01:00
Log.debug(self, "Writing PHP 7.2 configuration into "
"/etc/php/7.2/fpm/pool.d/www.conf")
2018-11-13 21:55:59 +01:00
config.write(configfile)
2019-05-02 10:07:37 +02:00
with open("/etc/php/7.2/fpm/pool.d/www.conf",
encoding='utf-8', mode='a') as myfile:
myfile.write("\nphp_admin_value[open_basedir] "
2019-05-02 15:12:26 +02:00
"= \"/var/www/:/usr/share/php/:"
2019-08-04 12:24:10 +02:00
"/tmp/:/var/run/nginx-cache/:"
"/dev/shm:/dev/urandom\"\n")
2019-05-02 10:07:37 +02:00
2019-03-20 02:12:13 +01:00
# Generate /etc/php/7.2/fpm/pool.d/www-two.conf
WOFileUtils.copyfile(self, "/etc/php/7.2/fpm/pool.d/www.conf",
"/etc/php/7.2/fpm/pool.d/www-two.conf")
WOFileUtils.searchreplace(self, "/etc/php/7.2/fpm/pool.d/"
"www-two.conf", "[www]", "[www-two]")
config = configparser.ConfigParser()
config.read('/etc/php/7.2/fpm/pool.d/www-two.conf')
config['www-two']['listen'] = 'php72-two-fpm.sock'
with open('/etc/php/7.2/fpm/pool.d/www-two.conf',
encoding='utf-8', mode='w') as confifile:
Log.debug(self, "writting PHP7.2 configuration into "
"/etc/php/7.2/fpm/pool.d/www-two.conf")
config.write(confifile)
2018-12-03 20:17:22 +01:00
# Generate /etc/php/7.2/fpm/pool.d/debug.conf
WOFileUtils.copyfile(self, "/etc/php/7.2/fpm/pool.d/www.conf",
"/etc/php/7.2/fpm/pool.d/debug.conf")
WOFileUtils.searchreplace(self, "/etc/php/7.2/fpm/pool.d/"
2018-11-13 21:55:59 +01:00
"debug.conf", "[www]", "[debug]")
config = configparser.ConfigParser()
2018-12-03 20:17:22 +01:00
config.read('/etc/php/7.2/fpm/pool.d/debug.conf')
config['debug']['listen'] = '127.0.0.1:9172'
2018-11-13 21:55:59 +01:00
config['debug']['rlimit_core'] = 'unlimited'
2018-12-03 20:17:22 +01:00
config['debug']['slowlog'] = '/var/log/php/7.2/slow.log'
2018-11-13 21:55:59 +01:00
config['debug']['request_slowlog_timeout'] = '10s'
2018-12-03 20:17:22 +01:00
with open('/etc/php/7.2/fpm/pool.d/debug.conf',
2018-11-13 21:55:59 +01:00
encoding='utf-8', mode='w') as confifile:
2019-03-13 05:02:53 +01:00
Log.debug(self, "writting PHP7.2 configuration into "
2018-12-03 20:17:22 +01:00
"/etc/php/7.2/fpm/pool.d/debug.conf")
2018-11-13 21:55:59 +01:00
config.write(confifile)
2018-12-03 20:17:22 +01:00
with open("/etc/php/7.2/fpm/pool.d/debug.conf",
2018-11-13 21:55:59 +01:00
encoding='utf-8', mode='a') as myfile:
myfile.write("php_admin_value[xdebug.profiler_output_dir] "
"= /tmp/ \nphp_admin_value[xdebug.profiler_"
"output_name] = cachegrind.out.%p-%H-%R "
"\nphp_admin_flag[xdebug.profiler_enable"
"_trigger] = on \nphp_admin_flag[xdebug."
"profiler_enable] = off\n")
# Disable xdebug
2019-03-20 02:12:13 +01:00
if not WOShellExec.cmd_exec(self, "grep -q \';zend_extension\'"
" /etc/php/7.2/mods-available/"
"xdebug.ini"):
WOFileUtils.searchreplace(self, "/etc/php/7.2/"
"mods-available/"
"xdebug.ini",
"zend_extension",
";zend_extension")
2018-11-13 21:55:59 +01:00
# PHP and Debug pull configuration
if not os.path.exists('{0}22222/htdocs/fpm/status/'
.format(WOVariables.wo_webroot)):
Log.debug(self, 'Creating directory '
'{0}22222/htdocs/fpm/status/ '
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/htdocs/fpm/status/'
.format(WOVariables.wo_webroot))
2019-04-01 01:43:59 +02:00
open('{0}22222/htdocs/fpm/status/debug72'
2018-11-13 21:55:59 +01:00
.format(WOVariables.wo_webroot),
encoding='utf-8', mode='a').close()
2019-04-01 01:43:59 +02:00
open('{0}22222/htdocs/fpm/status/php72'
.format(WOVariables.wo_webroot),
encoding='utf-8', mode='a').close()
2018-11-13 21:55:59 +01:00
# Write info.php
if not os.path.exists('{0}22222/htdocs/php/'
.format(WOVariables.wo_webroot)):
Log.debug(self, 'Creating directory '
'{0}22222/htdocs/php/ '
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/htdocs/php'
.format(WOVariables.wo_webroot))
with open("{0}22222/htdocs/php/info.php"
.format(WOVariables.wo_webroot),
encoding='utf-8', mode='w') as myfile:
myfile.write("<?php\nphpinfo();\n?>")
WOFileUtils.chown(self, "{0}22222"
.format(WOVariables.wo_webroot),
WOVariables.wo_php_user,
WOVariables.wo_php_user, recursive=True)
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
2018-12-03 20:17:22 +01:00
WOService.restart_service(self, 'php7.2-fpm')
2018-11-13 21:55:59 +01:00
2019-03-15 17:28:08 +01:00
# PHP7.3 configuration
if set(WOVariables.wo_php73).issubset(set(apt_packages)):
2019-03-04 07:12:57 +01:00
# Create log directories
if not os.path.exists('/var/log/php/7.3/'):
Log.debug(self, 'Creating directory /var/log/php/7.3/')
os.makedirs('/var/log/php/7.3/')
2018-11-13 21:55:59 +01:00
# Parse etc/php/7.3/fpm/php.ini
2018-11-13 21:55:59 +01:00
config = configparser.ConfigParser()
2019-03-20 02:12:13 +01:00
Log.debug(self, "configuring php file /etc/php/7.3/"
"fpm/php.ini")
config.read('/etc/php/7.3/fpm/php.ini')
2018-11-13 21:55:59 +01:00
config['PHP']['expose_php'] = 'Off'
config['PHP']['post_max_size'] = '100M'
config['PHP']['upload_max_filesize'] = '100M'
config['PHP']['max_execution_time'] = '300'
2019-07-31 20:50:56 +02:00
config['PHP']['max_input_time'] = '300'
2019-03-20 02:12:13 +01:00
config['PHP']['max_input_vars'] = '20000'
config['Date']['date.timezone'] = WOVariables.wo_timezone
config['opcache']['opcache.enable'] = '1'
config['opcache']['opcache.interned_strings_buffer'] = '8'
config['opcache']['opcache.max_accelerated_files'] = '10000'
config['opcache']['opcache.memory_consumption'] = '256'
config['opcache']['opcache.save_comments'] = '1'
2019-07-31 20:50:56 +02:00
config['opcache']['opcache.revalidate_freq'] = '5'
config['opcache']['opcache.consistency_checks'] = '0'
2019-03-20 02:12:13 +01:00
config['opcache']['opcache.validate_timestamps'] = '1'
with open('/etc/php/7.3/fpm/php.ini',
2018-11-13 21:55:59 +01:00
encoding='utf-8', mode='w') as configfile:
Log.debug(self, "Writting php configuration into "
"/etc/php/7.3/fpm/php.ini")
2018-11-13 21:55:59 +01:00
config.write(configfile)
# Parse /etc/php/7.3/fpm/php-fpm.conf
2019-04-11 20:35:03 +02:00
data = dict(pid="/run/php/php7.3-fpm.pid",
error_log="/var/log/php7.3-fpm.log",
include="/etc/php/7.3/fpm/pool.d/*.conf")
Log.debug(self, "writting php 7.3 configuration into "
"/etc/php/7.3/fpm/php-fpm.conf")
wo_php_fpm = open('/etc/php/7.3/fpm/php-fpm.conf',
encoding='utf-8', mode='w')
2018-11-13 21:55:59 +01:00
self.app.render((data), 'php-fpm.mustache', out=wo_php_fpm)
wo_php_fpm.close()
# Parse /etc/php/7.3/fpm/pool.d/www.conf
2018-11-13 21:55:59 +01:00
config = configparser.ConfigParser()
2019-03-20 03:17:41 +01:00
config.read_file(codecs.open('/etc/php/7.3/fpm/'
2019-03-20 02:12:13 +01:00
'pool.d/www.conf',
2018-11-13 21:55:59 +01:00
"r", "utf8"))
config['www']['ping.path'] = '/ping'
config['www']['pm.status_path'] = '/status'
2019-03-20 02:12:13 +01:00
config['www']['pm.max_requests'] = '1500'
2019-03-20 03:21:39 +01:00
config['www']['pm.max_children'] = '50'
config['www']['pm.start_servers'] = '10'
config['www']['pm.min_spare_servers'] = '5'
config['www']['pm.max_spare_servers'] = '15'
2018-11-13 21:55:59 +01:00
config['www']['request_terminate_timeout'] = '300'
config['www']['pm'] = 'ondemand'
config['www']['chdir'] = '/'
config['www']['prefix'] = '/var/run/php'
config['www']['listen'] = 'php73-fpm.sock'
2019-03-21 17:27:51 +01:00
config['www']['listen.mode'] = '0660'
config['www']['listen.backlog'] = '32768'
2019-03-21 17:27:51 +01:00
config['www']['catch_workers_output'] = 'yes'
with codecs.open('/etc/php/7.3/fpm/pool.d/www.conf',
2018-11-13 21:55:59 +01:00
encoding='utf-8', mode='w') as configfile:
Log.debug(self, "writting PHP 7.3 configuration into "
"/etc/php/7.3/fpm/pool.d/www.conf")
2018-11-13 21:55:59 +01:00
config.write(configfile)
2019-03-20 04:47:00 +01:00
2019-05-02 10:07:37 +02:00
with open("/etc/php/7.3/fpm/pool.d/www.conf",
encoding='utf-8', mode='a') as myfile:
myfile.write("\nphp_admin_value[open_basedir] "
2019-05-02 15:12:26 +02:00
"= \"/var/www/:/usr/share/php/:"
2019-08-04 12:24:10 +02:00
"/tmp/:/var/run/nginx-cache/:"
"/dev/shm:/dev/urandom\"\n")
2019-05-02 10:07:37 +02:00
2019-03-20 03:21:39 +01:00
# Generate /etc/php/7.3/fpm/pool.d/www-two.conf
WOFileUtils.copyfile(self, "/etc/php/7.3/fpm/pool.d/www.conf",
"/etc/php/7.3/fpm/pool.d/www-two.conf")
WOFileUtils.searchreplace(self, "/etc/php/7.3/fpm/pool.d/"
"www-two.conf", "[www]", "[www-two]")
config = configparser.ConfigParser()
config.read('/etc/php/7.3/fpm/pool.d/www-two.conf')
config['www-two']['listen'] = 'php73-two-fpm.sock'
with open('/etc/php/7.3/fpm/pool.d/www-two.conf',
encoding='utf-8', mode='w') as confifile:
Log.debug(self, "writting PHP7.3 configuration into "
"/etc/php/7.3/fpm/pool.d/www-two.conf")
config.write(confifile)
2018-11-13 21:55:59 +01:00
# Generate /etc/php/7.3/fpm/pool.d/debug.conf
WOFileUtils.copyfile(self, "/etc/php/7.3/fpm/pool.d/www.conf",
"/etc/php/7.3/fpm/pool.d/debug.conf")
WOFileUtils.searchreplace(self, "/etc/php/7.3/fpm/pool.d/"
2018-11-13 21:55:59 +01:00
"debug.conf", "[www]", "[debug]")
config = configparser.ConfigParser()
config.read('/etc/php/7.3/fpm/pool.d/debug.conf')
config['debug']['listen'] = '127.0.0.1:9173'
2018-11-13 21:55:59 +01:00
config['debug']['rlimit_core'] = 'unlimited'
config['debug']['slowlog'] = '/var/log/php/7.3/slow.log'
2018-11-13 21:55:59 +01:00
config['debug']['request_slowlog_timeout'] = '10s'
with open('/etc/php/7.3/fpm/pool.d/debug.conf',
2018-11-13 21:55:59 +01:00
encoding='utf-8', mode='w') as confifile:
Log.debug(self, "writting PHP 7.3 configuration into "
"/etc/php/7.3/fpm/pool.d/debug.conf")
2018-11-13 21:55:59 +01:00
config.write(confifile)
with open("/etc/php/7.3/fpm/pool.d/debug.conf",
2018-11-13 21:55:59 +01:00
encoding='utf-8', mode='a') as myfile:
myfile.write("php_admin_value[xdebug.profiler_output_dir] "
"= /tmp/ \nphp_admin_value[xdebug.profiler_"
"output_name] = cachegrind.out.%p-%H-%R "
"\nphp_admin_flag[xdebug.profiler_enable"
"_trigger] = on \nphp_admin_flag[xdebug."
"profiler_enable] = off\n")
# Disable xdebug
2019-03-20 21:59:56 +01:00
if not WOShellExec.cmd_exec(self, "grep -q \';zend_extension\'"
" /etc/php/7.3/mods-available"
"/xdebug.ini"):
WOFileUtils.searchreplace(self, "/etc/php/7.3/"
"mods-available/"
"xdebug.ini",
"zend_extension",
";zend_extension")
2018-11-13 21:55:59 +01:00
# PHP and Debug pull configuration
if not os.path.exists('{0}22222/htdocs/fpm/status/'
.format(WOVariables.wo_webroot)):
Log.debug(self, 'Creating directory '
'{0}22222/htdocs/fpm/status/ '
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/htdocs/fpm/status/'
.format(WOVariables.wo_webroot))
2019-04-01 20:59:53 +02:00
open('{0}22222/htdocs/fpm/status/debug73'
2018-11-13 21:55:59 +01:00
.format(WOVariables.wo_webroot),
encoding='utf-8', mode='a').close()
2019-04-01 20:59:53 +02:00
open('{0}22222/htdocs/fpm/status/php73'
2018-11-13 21:55:59 +01:00
.format(WOVariables.wo_webroot),
encoding='utf-8', mode='a').close()
# Write info.php
if not os.path.exists('{0}22222/htdocs/php/'
.format(WOVariables.wo_webroot)):
Log.debug(self, 'Creating directory '
'{0}22222/htdocs/php/ '
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/htdocs/php'
.format(WOVariables.wo_webroot))
with open("{0}22222/htdocs/php/info.php"
.format(WOVariables.wo_webroot),
encoding='utf-8', mode='w') as myfile:
myfile.write("<?php\nphpinfo();\n?>")
WOFileUtils.chown(self, "{0}22222"
.format(WOVariables.wo_webroot),
WOVariables.wo_php_user,
WOVariables.wo_php_user, recursive=True)
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
WOService.restart_service(self, 'php7.3-fpm')
2018-11-13 21:55:59 +01:00
# create mysql config if it doesn't exist
2018-11-13 21:55:59 +01:00
if set(WOVariables.wo_mysql).issubset(set(apt_packages)):
if not os.path.isfile("/etc/mysql/my.cnf"):
config = ("[mysqld]\nwait_timeout = 30\n"
"interactive_timeout=60\nperformance_schema = 0"
"\nquery_cache_type = 1")
config_file = open("/etc/mysql/my.cnf",
encoding='utf-8', mode='w')
config_file.write(config)
config_file.close()
WOFileUtils.chmod(self, "/usr/bin/mysqltuner", 0o775)
WOCron.setcron_weekly(self, 'mysqlcheck -Aos --auto-repair '
'> /dev/null 2>&1',
comment='MySQL optimization cronjob '
'added by WordOps')
2018-11-13 21:55:59 +01:00
WOGit.add(self, ["/etc/mysql"], msg="Adding MySQL into Git")
WOService.reload_service(self, 'mysql')
# create fail2ban configuration files
if set(WOVariables.wo_fail2ban).issubset(set(apt_packages)):
if not os.path.isfile("/etc/fail2ban/jail.d/custom.conf"):
2019-07-28 20:28:02 +02:00
data = dict()
Log.debug(self, "Setting up fail2ban jails configuration")
2019-07-18 17:54:45 +02:00
fail2ban_config = open('/etc/fail2ban/jail.d/custom.conf',
2019-07-18 18:19:04 +02:00
encoding='utf-8', mode='w')
self.app.render((data), 'fail2ban.mustache',
2019-07-18 18:19:04 +02:00
out=fail2ban_config)
2019-07-18 17:54:45 +02:00
fail2ban_config.close()
Log.debug(self, "Setting up fail2ban wp filter")
2019-07-18 17:54:45 +02:00
fail2ban_config = open('/etc/fail2ban/filter.d/'
2019-07-18 18:19:04 +02:00
'wo-wordpress.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'fail2ban-wp.mustache',
2019-07-18 18:19:04 +02:00
out=fail2ban_config)
2019-07-18 17:54:45 +02:00
fail2ban_config.close()
2019-04-25 01:38:14 +02:00
2019-07-18 14:32:41 +02:00
Log.debug(self, "Setting up fail2ban wp filter")
2019-07-18 17:54:45 +02:00
fail2ban_config = open('/etc/fail2ban/filter.d/'
2019-07-18 18:19:04 +02:00
'nginx-forbidden.conf',
encoding='utf-8', mode='w')
2019-07-18 14:32:41 +02:00
self.app.render((data), 'fail2ban-forbidden.mustache',
2019-07-18 18:19:04 +02:00
out=fail2ban_config)
2019-07-18 17:54:45 +02:00
fail2ban_config.close()
2019-07-18 14:32:41 +02:00
WOGit.add(self, ["/etc/fail2ban"],
msg="Adding Fail2ban into Git")
WOService.reload_service(self, 'fail2ban')
2019-07-19 15:21:17 +02:00
# Proftpd configuration
2019-07-19 13:47:29 +02:00
if set(["proftpd-basic"]).issubset(set(apt_packages)):
if os.path.isfile("/etc/proftpd/proftpd.conf"):
Log.debug(self, "Setting up Proftpd configuration")
WOFileUtils.searchreplace(self, "/etc/proftpd/"
"proftpd.conf",
"# DefaultRoot",
"DefaultRoot")
WOFileUtils.searchreplace(self, "/etc/proftpd/"
"proftpd.conf",
"# RequireValidShell",
"RequireValidShell")
WOFileUtils.searchreplace(self, "/etc/proftpd/"
"proftpd.conf",
"# PassivePorts "
" "
"49152 65534",
"PassivePorts "
" "
" 49000 50000")
2019-07-30 11:34:27 +02:00
# proftpd TLS configuration
if not os.path.isdir("/etc/proftpd/ssl"):
2019-07-30 12:24:56 +02:00
WOFileUtils.mkdir(self, "/etc/proftpd/ssl")
2019-07-30 12:27:27 +02:00
2019-07-30 12:24:56 +02:00
try:
WOShellExec.cmd_exec(self, "openssl genrsa -out "
"/etc/proftpd/ssl/proftpd.key 2048")
2019-07-30 12:27:27 +02:00
WOShellExec.cmd_exec(self, "openssl req -new -batch "
"-subj /commonName=localhost/ "
"-key /etc/proftpd/ssl/proftpd.key "
"-out /etc/proftpd/ssl/proftpd.csr")
WOFileUtils.mvfile(self, "/etc/proftpd/ssl/proftpd.key",
"/etc/proftpd/ssl/proftpd.key.org")
WOShellExec.cmd_exec(self, "openssl rsa -in "
2019-07-30 14:17:24 +02:00
"/etc/proftpd/ssl/proftpd.key.org "
2019-07-30 12:24:56 +02:00
"-out /etc/proftpd/ssl/proftpd.key")
WOShellExec.cmd_exec(self, "openssl x509 -req -days "
2019-07-30 14:17:24 +02:00
"3652 -in /etc/proftpd/ssl/proftpd.csr "
"-signkey /etc/proftpd/ssl/proftpd.key "
2019-07-30 12:24:56 +02:00
" -out /etc/proftpd/ssl/proftpd.crt")
2019-07-30 12:27:27 +02:00
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error(
self, "Failed to generate SSL "
"certificate for Proftpd")
2019-07-30 12:24:56 +02:00
WOFileUtils.chmod(self, "/etc/proftpd/ssl/proftpd.key", 0o700)
WOFileUtils.chmod(self, "/etc/proftpd/ssl/proftpd.crt", 0o700)
2019-07-30 11:34:27 +02:00
data = dict()
Log.debug(self, 'Writting the proftpd configuration to '
'file /etc/proftpd/tls.conf')
wo_proftpdconf = open('/etc/proftpd/tls.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'proftpd-tls.mustache',
out=wo_proftpdconf)
wo_proftpdconf.close()
WOFileUtils.searchreplace(self, "/etc/proftpd/"
"proftpd.conf",
"#Include /etc/proftpd/tls.conf",
"Include /etc/proftpd/tls.conf")
WOService.restart_service(self, 'proftpd')
2019-07-19 15:21:17 +02:00
# add rule for proftpd with UFW
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'ufw'):
try:
WOShellExec.cmd_exec(self, "ufw allow "
"49000:50000/tcp")
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
2019-07-19 15:21:17 +02:00
Log.error(self, "Unable to add UFW rule")
if os.path.isfile("/etc/fail2ban/jail.d/custom.conf"):
with open("/etc/fail2ban/jail.d/custom.conf",
encoding='utf-8', mode='a') as f2bproftpd:
f2bproftpd.write("\n\n[proftpd]\nenabled = true\n")
WOService.reload_service(self, 'fail2ban')
2019-07-19 13:47:29 +02:00
WOGit.add(self, ["/etc/proftpd"],
msg="Adding ProFTPd into Git")
WOService.reload_service(self, 'proftpd')
2019-04-30 18:50:30 +02:00
if (packages):
if any('/usr/local/bin/wp' == x[1] for x in packages):
2019-04-23 19:03:42 +02:00
Log.debug(self, "Setting Privileges"
" to /usr/local/bin/wp file ")
WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)
2018-11-13 21:55:59 +01:00
if any('/var/lib/wo/tmp/pma.tar.gz' == x[1]
2018-11-13 21:55:59 +01:00
for x in packages):
2019-05-02 10:07:37 +02:00
WOExtract.extract(
self, '/var/lib/wo/tmp/pma.tar.gz', '/var/lib/wo/tmp/')
Log.debug(self, 'Extracting file /var/lib/wo/tmp/pma.tar.gz to '
'location /var/lib/wo/tmp/')
2018-11-13 21:55:59 +01:00
if not os.path.exists('{0}22222/htdocs/db'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Creating new directory "
"{0}22222/htdocs/db"
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/htdocs/db'
.format(WOVariables.wo_webroot))
2019-04-23 19:03:42 +02:00
if not os.path.exists('{0}22222/htdocs/db/pma/'
2019-04-03 07:10:46 +02:00
.format(WOVariables.wo_webroot)):
shutil.move('/var/lib/wo/tmp/phpmyadmin-STABLE/',
2019-04-03 07:10:46 +02:00
'{0}22222/htdocs/db/pma/'
2018-11-13 21:55:59 +01:00
.format(WOVariables.wo_webroot))
2019-04-11 20:35:03 +02:00
shutil.copyfile('{0}22222/htdocs/db/pma'
'/config.sample.inc.php'
2019-04-03 07:10:46 +02:00
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/db/pma/config.inc.php'
.format(WOVariables.wo_webroot))
2019-04-11 20:35:03 +02:00
Log.debug(self, 'Setting Blowfish Secret Key '
'FOR COOKIE AUTH to '
2019-04-03 07:10:46 +02:00
'{0}22222/htdocs/db/pma/config.inc.php file '
.format(WOVariables.wo_webroot))
blowfish_key = ''.join([random.choice
2019-04-11 20:35:03 +02:00
(string.ascii_letters +
string.digits)
2019-04-03 07:10:46 +02:00
for n in range(25)])
WOFileUtils.searchreplace(self,
2019-04-11 20:35:03 +02:00
'{0}22222/htdocs/db/pma'
'/config.inc.php'
2019-04-03 07:10:46 +02:00
.format(WOVariables.wo_webroot),
2019-04-11 20:35:03 +02:00
"$cfg[\'blowfish_secret\']"
" = \'\';",
"$cfg[\'blowfish_secret\']"
" = \'{0}\';"
2019-04-03 07:10:46 +02:00
.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))
WOFileUtils.searchreplace(self,
2019-04-11 20:35:03 +02:00
'{0}22222/htdocs/db/pma'
'/config.inc.php'
2019-04-03 07:10:46 +02:00
.format(WOVariables.wo_webroot),
2019-04-11 20:35:03 +02:00
"$cfg[\'Servers\'][$i][\'host\']"
" = \'localhost\';", "$cfg"
"[\'Servers\'][$i][\'host\'] = \'{0}\';"
2019-04-03 07:10:46 +02:00
.format(WOVariables.wo_mysql_host))
2018-11-13 21:55:59 +01:00
Log.debug(self, 'Setting Privileges of webroot permission to '
2019-04-23 19:03:42 +02:00
'{0}22222/htdocs/db/pma file '.format(WOVariables.wo_webroot))
WOFileUtils.chown(self, '{0}22222'.format(WOVariables.wo_webroot),
2018-11-13 21:55:59 +01:00
WOVariables.wo_php_user,
WOVariables.wo_php_user,
recursive=True)
2019-04-23 19:03:42 +02:00
2019-04-03 07:57:36 +02:00
# composer install and phpmyadmin update
if any('/var/lib/wo/tmp/composer-install' == x[1]
2019-03-31 19:04:51 +02:00
for x in packages):
2019-04-11 20:35:03 +02:00
Log.info(self, "Installing composer, please wait...")
2019-05-10 15:04:36 +02:00
WOShellExec.cmd_exec(self, "php -q /var/lib/wo"
"/tmp/composer-install "
"--install-dir=/var/lib/wo/tmp/")
shutil.copyfile('/var/lib/wo/tmp/composer.phar',
2019-03-31 17:14:17 +02:00
'/usr/local/bin/composer')
2019-03-31 19:17:27 +02:00
WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)
2019-04-11 20:35:03 +02:00
Log.info(self, "Updating phpMyAdmin, please wait...")
2019-03-31 19:17:27 +02:00
WOShellExec.cmd_exec(self, "sudo -u www-data -H composer "
2019-04-12 10:43:34 +02:00
"update -n --no-dev -d "
2019-03-31 19:17:27 +02:00
"/var/www/22222/htdocs/db/pma/")
2019-04-23 19:03:42 +02:00
2019-07-11 18:39:32 +02:00
# netdata install
if any('/var/lib/wo/tmp/kickstart.sh' == x[1]
for x in packages):
if ((not os.path.exists('/opt/netdata')) and
(not os.path.exists('/etc/netdata'))):
Log.info(self, "Installing Netdata, please wait...")
WOShellExec.cmd_exec(self, "bash /var/lib/wo/tmp/"
"kickstart.sh "
"--dont-wait")
# disable mail notifications
WOFileUtils.searchreplace(self, "/opt/netdata/usr/"
"lib/netdata/conf.d/"
"health_alarm_notify.conf",
'SEND_EMAIL="YES"',
'SEND_EMAIL="NO"')
2019-07-13 15:15:52 +02:00
# make changes persistant
WOFileUtils.copyfile(self, "/opt/netdata/usr/"
"lib/netdata/conf.d/"
"health_alarm_notify.conf",
"/opt/netdata/etc/netdata/"
"health_alarm_notify.conf")
2019-07-11 18:39:32 +02:00
# check if mysql credentials are available
if os.path.isfile('/etc/mysql/conf.d/my.cnf'):
try:
WOMysql.execute(self,
"create user "
"'netdata'@'localhost';",
log=False)
WOMysql.execute(self,
"grant usage on *.* to "
"'netdata'@'localhost';",
log=False)
WOMysql.execute(self,
"flush privileges;",
log=False)
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
2019-07-11 18:39:32 +02:00
Log.info(
self, "fail to setup mysql user for netdata")
WOService.restart_service(self, 'netdata')
2019-04-23 19:03:42 +02:00
# WordOps Dashboard
if any('/var/lib/wo/tmp/wo-dashboard.tar.gz' == x[1]
2019-04-23 19:03:42 +02:00
for x in packages):
if not os.path.isfile('{0}22222/htdocs/index.php'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Extracting wo-dashboard.tar.gz "
"to location {0}22222/htdocs/"
.format(WOVariables.wo_webroot))
2019-07-11 18:13:23 +02:00
WOExtract.extract(self, '/var/lib/wo/tmp/'
'wo-dashboard.tar.gz',
2019-04-23 19:03:42 +02:00
'{0}22222/htdocs'
.format(WOVariables.wo_webroot))
wo_wan = os.popen("/sbin/ip -4 route get 8.8.8.8 | "
"grep -oP \"dev [^[:space:]]+ \" "
"| cut -d ' ' -f 2").read()
2019-07-30 15:55:48 +02:00
if (wo_wan != 'eth0' and wo_wan != ''):
WOFileUtils.searchreplace(self,
"{0}22222/htdocs/index.php"
.format(WOVariables.wo_webroot),
"eth0",
2019-07-30 17:55:24 +02:00
"{0}".format(wo_wan))
2019-04-23 19:03:42 +02:00
Log.debug(self, "Setting Privileges to "
"{0}22222/htdocs"
.format(WOVariables.wo_webroot))
WOFileUtils.chown(self, '{0}22222'
.format(WOVariables.wo_webroot),
WOVariables.wo_php_user,
WOVariables.wo_php_user,
recursive=True)
# Extplorer FileManager
if any('/var/lib/wo/tmp/extplorer.tar.gz' == x[1]
2019-04-23 19:03:42 +02:00
for x in packages):
if not os.path.exists('{0}22222/htdocs/files'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Extracting explorer.tar.gz "
2019-04-23 19:23:16 +02:00
"to location {0}22222/htdocs/files"
2019-04-23 19:03:42 +02:00
.format(WOVariables.wo_webroot))
WOExtract.extract(self, '/var/lib/wo/tmp/extplorer.tar.gz',
'/var/lib/wo/tmp/')
2019-07-27 23:11:19 +02:00
shutil.move('/var/lib/wo/tmp/extplorer-{0}'
.format(WOVariables.wo_extplorer),
2019-04-23 19:23:16 +02:00
'{0}22222/htdocs/files'
.format(WOVariables.wo_webroot))
2019-04-23 19:03:42 +02:00
Log.debug(self, "Setting Privileges to "
"{0}22222/htdocs/files"
.format(WOVariables.wo_webroot))
WOFileUtils.chown(self, '{0}22222'
.format(WOVariables.wo_webroot),
WOVariables.wo_php_user,
WOVariables.wo_php_user,
recursive=True)
2019-03-31 17:14:17 +02:00
2019-04-21 00:56:05 +02:00
# webgrind
if any('/var/lib/wo/tmp/webgrind.tar.gz' == x[1]
2018-11-13 21:55:59 +01:00
for x in packages):
Log.debug(self, "Extracting file webgrind.tar.gz to "
"location /var/lib/wo/tmp/ ")
2019-05-02 10:07:37 +02:00
WOExtract.extract(
2019-07-09 04:07:27 +02:00
self, '/var/lib/wo/tmp/webgrind.tar.gz',
'/var/lib/wo/tmp/')
2018-11-13 21:55:59 +01:00
if not os.path.exists('{0}22222/htdocs/php'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Creating directroy "
"{0}22222/htdocs/php"
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/htdocs/php'
.format(WOVariables.wo_webroot))
2019-04-03 07:15:17 +02:00
if not os.path.exists('{0}22222/htdocs/php/webgrind'
.format(WOVariables.wo_webroot)):
shutil.move('/var/lib/wo/tmp/webgrind-master/',
2019-04-03 07:15:17 +02:00
'{0}22222/htdocs/php/webgrind'
.format(WOVariables.wo_webroot))
2018-11-13 21:55:59 +01:00
WOFileUtils.searchreplace(self, "{0}22222/htdocs/php/webgrind/"
"config.php"
.format(WOVariables.wo_webroot),
"/usr/local/bin/dot", "/usr/bin/dot")
WOFileUtils.searchreplace(self, "{0}22222/htdocs/php/webgrind/"
"config.php"
.format(WOVariables.wo_webroot),
"Europe/Copenhagen",
WOVariables.wo_timezone)
WOFileUtils.searchreplace(self, "{0}22222/htdocs/php/webgrind/"
"config.php"
.format(WOVariables.wo_webroot),
"90", "100")
Log.debug(self, "Setting Privileges of webroot permission to "
"{0}22222/htdocs/php/webgrind/ file "
.format(WOVariables.wo_webroot))
WOFileUtils.chown(self, '{0}22222'
.format(WOVariables.wo_webroot),
WOVariables.wo_php_user,
WOVariables.wo_php_user,
recursive=True)
2019-04-21 00:56:05 +02:00
# anemometer
if any('/var/lib/wo/tmp/anemometer.tar.gz' == x[1]
2018-11-13 21:55:59 +01:00
for x in packages):
Log.debug(self, "Extracting file anemometer.tar.gz to "
"location /var/lib/wo/tmp/ ")
2019-05-02 10:07:37 +02:00
WOExtract.extract(
2019-07-03 15:09:58 +02:00
self, '/var/lib/wo/tmp/anemometer.tar.gz',
'/var/lib/wo/tmp/')
2018-11-13 21:55:59 +01:00
if not os.path.exists('{0}22222/htdocs/db/'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Creating directory")
os.makedirs('{0}22222/htdocs/db/'
.format(WOVariables.wo_webroot))
2019-04-03 07:15:17 +02:00
if not os.path.exists('{0}22222/htdocs/db/anemometer'
.format(WOVariables.wo_webroot)):
shutil.move('/var/lib/wo/tmp/Anemometer-master',
2019-04-03 07:15:17 +02:00
'{0}22222/htdocs/db/anemometer'
.format(WOVariables.wo_webroot))
2019-04-03 07:27:11 +02:00
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))
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
2019-04-03 07:27:11 +02:00
raise SiteError("Unable to import Anemometer database")
WOMysql.execute(self, 'grant select on'
' *.* to \'anemometer\''
'@\'{0}\' IDENTIFIED'
' BY \'{1}\''.format(self.app.config.get
2019-04-23 19:03:42 +02:00
('mysql',
'grant-host'),
2019-04-03 07:27:11 +02:00
chars))
Log.debug(self, "grant all on slow-query-log.*"
" to anemometer@root_user"
" IDENTIFIED BY password ")
WOMysql.execute(self, 'grant all on slow_query_log.* to'
'\'anemometer\'@\'{0}\' IDENTIFIED'
' BY \'{1}\''.format(self.app.config.get(
'mysql', 'grant-host'),
chars),
2019-04-11 20:35:03 +02:00
errormsg="cannot grant priviledges",
log=False)
2019-04-03 07:27:11 +02:00
# Custom Anemometer configuration
Log.debug(self, "configration Anemometer")
data = dict(host=WOVariables.wo_mysql_host, port='3306',
user='anemometer', password=chars)
wo_anemometer = open('{0}22222/htdocs/db/anemometer'
'/conf/config.inc.php'
.format(WOVariables.wo_webroot),
encoding='utf-8', mode='w')
self.app.render((data), 'anemometer.mustache',
out=wo_anemometer)
wo_anemometer.close()
2018-11-13 21:55:59 +01:00
if any('/usr/bin/pt-query-advisor' == x[1]
for x in packages):
WOFileUtils.chmod(self, "/usr/bin/pt-query-advisor", 0o775)
2019-07-13 04:50:28 +02:00
# phpredisadmin
if any('/var/lib/wo/tmp/pra.tar.gz' == x[1]
2018-11-13 21:55:59 +01:00
for x in packages):
2019-08-01 17:02:39 +02:00
if not os.path.exists('{0}22222/htdocs/cache/'
'redis/phpRedisAdmin'
2018-11-13 21:55:59 +01:00
.format(WOVariables.wo_webroot)):
Log.debug(self, "Creating new directory "
"{0}22222/htdocs/cache/redis"
.format(WOVariables.wo_webroot))
2019-06-19 17:14:26 +02:00
os.makedirs('{0}22222/htdocs/cache/redis/phpRedisAdmin'
2018-11-13 21:55:59 +01:00
.format(WOVariables.wo_webroot))
2019-06-19 17:14:26 +02:00
WOFileUtils.chown(self, '{0}22222'
.format(WOVariables.wo_webroot),
WOVariables.wo_php_user,
WOVariables.wo_php_user,
recursive=True)
2019-04-12 10:43:34 +02:00
if os.path.isfile("/usr/local/bin/composer"):
WOShellExec.cmd_exec(self, "sudo -u www-data -H "
"composer "
"create-project -n -s dev "
"erik-dubbelboer/php-redis-admin "
"/var/www/22222/htdocs/cache"
2019-06-19 17:14:26 +02:00
"/redis/phpRedisAdmin ")
2018-11-13 21:55:59 +01:00
Log.debug(self, 'Setting Privileges of webroot permission to '
2019-04-12 10:43:34 +02:00
'{0}22222/htdocs/cache/file '
2018-11-13 21:55:59 +01:00
.format(WOVariables.wo_webroot))
WOFileUtils.chown(self, '{0}22222'
.format(WOVariables.wo_webroot),
WOVariables.wo_php_user,
WOVariables.wo_php_user,
recursive=True)
@expose(help="Install packages")
def install(self, packages=[], apt_packages=[], disp_msg=True):
"""Start installation of packages"""
self.msg = []
try:
# Default action for stack installation
if ((not self.app.pargs.web) and (not self.app.pargs.admin) and
(not self.app.pargs.nginx) and (not self.app.pargs.php) and
(not self.app.pargs.mysql) and (not self.app.pargs.wpcli) and
2019-03-08 00:43:25 +01:00
(not self.app.pargs.phpmyadmin) and
2019-04-03 07:53:25 +02:00
(not self.app.pargs.composer) and
(not self.app.pargs.netdata) and
2019-04-23 19:03:42 +02:00
(not self.app.pargs.dashboard) and
2019-07-18 17:04:20 +02:00
(not self.app.pargs.fail2ban) and
2019-07-19 15:21:17 +02:00
(not self.app.pargs.security) and
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and
2019-07-19 13:47:29 +02:00
(not self.app.pargs.redis) and (not self.app.pargs.proftpd) and
2019-03-08 00:43:25 +01:00
(not self.app.pargs.phpredisadmin) and
(not self.app.pargs.php73)):
2018-11-13 21:55:59 +01:00
self.app.pargs.web = True
self.app.pargs.admin = True
2019-07-19 15:21:17 +02:00
self.app.pargs.security = True
2018-11-13 21:55:59 +01:00
if self.app.pargs.all:
self.app.pargs.web = True
self.app.pargs.admin = True
self.app.pargs.php73 = True
2019-07-14 22:50:34 +02:00
self.app.pargs.redis = True
2019-07-19 13:47:29 +02:00
self.app.pargs.proftpd = True
2018-11-13 21:55:59 +01:00
if self.app.pargs.web:
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
self.app.pargs.wpcli = True
if self.app.pargs.admin:
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
self.app.pargs.adminer = True
self.app.pargs.phpmyadmin = True
2019-04-01 22:19:44 +02:00
self.app.pargs.composer = True
2018-11-13 21:55:59 +01:00
self.app.pargs.utils = True
2019-04-03 07:41:29 +02:00
self.app.pargs.netdata = True
2019-04-23 19:03:42 +02:00
self.app.pargs.dashboard = True
2019-06-19 17:14:26 +02:00
self.app.pargs.phpredisadmin = True
2019-07-19 15:21:17 +02:00
if self.app.pargs.security:
2019-07-18 17:04:20 +02:00
self.app.pargs.fail2ban = True
2018-11-13 21:55:59 +01:00
2019-04-23 19:03:42 +02:00
# Redis
2018-11-13 21:55:59 +01:00
if self.app.pargs.redis:
if not WOAptGet.is_installed(self, 'redis-server'):
apt_packages = apt_packages + WOVariables.wo_redis
self.app.pargs.php = True
else:
Log.info(self, "Redis already installed")
2019-04-23 19:03:42 +02:00
# Nginx
2018-11-13 21:55:59 +01:00
if self.app.pargs.nginx:
Log.debug(self, "Setting apt_packages variable for Nginx")
if not (WOAptGet.is_installed(self, 'nginx-custom')):
2019-03-08 00:43:25 +01:00
if not (WOAptGet.is_installed(self, 'nginx-plus') or
WOAptGet.is_installed(self, 'nginx')):
2018-11-13 21:55:59 +01:00
apt_packages = apt_packages + WOVariables.wo_nginx
else:
if WOAptGet.is_installed(self, 'nginx-plus'):
Log.info(self, "NGINX PLUS Detected ...")
apt = ["nginx-plus"] + WOVariables.wo_nginx
self.post_pref(apt, packages)
elif WOAptGet.is_installed(self, 'nginx'):
2019-04-03 07:53:25 +02:00
Log.info(self, "WordOps detected an already "
"installed nginx package."
"It may or may not have "
"required modules.\n")
2018-11-13 21:55:59 +01:00
apt = ["nginx"] + WOVariables.wo_nginx
self.post_pref(apt, packages)
else:
Log.debug(self, "Nginx Stable already installed")
2019-03-15 16:45:10 +01:00
# PHP 7.2
2018-11-13 21:55:59 +01:00
if self.app.pargs.php:
Log.debug(self, "Setting apt_packages variable for PHP 7.2")
2019-03-08 00:43:25 +01:00
if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
2019-03-16 09:18:15 +01:00
if not (WOAptGet.is_installed(self, 'php7.3-fpm')):
2019-04-01 20:59:53 +02:00
apt_packages = apt_packages + WOVariables.wo_php + \
2019-04-01 22:19:44 +02:00
WOVariables.wo_php_extra
2019-03-16 09:18:15 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php
2018-11-13 21:55:59 +01:00
else:
Log.debug(self, "PHP 7.2 already installed")
Log.info(self, "PHP 7.2 already installed")
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# PHP 7.3
if self.app.pargs.php73:
2019-03-08 00:43:25 +01:00
Log.debug(self, "Setting apt_packages variable for PHP 7.3")
if not WOAptGet.is_installed(self, 'php7.3-fpm'):
2019-03-16 09:18:15 +01:00
if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
2019-04-01 20:59:53 +02:00
apt_packages = apt_packages + WOVariables.wo_php + \
WOVariables.wo_php73 + WOVariables.wo_php_extra
2019-03-16 09:18:15 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php73
2018-11-13 21:55:59 +01:00
else:
2019-03-08 00:43:25 +01:00
Log.debug(self, "PHP 7.3 already installed")
Log.info(self, "PHP 7.3 already installed")
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# MariaDB 10.3
2018-11-13 21:55:59 +01:00
if self.app.pargs.mysql:
Log.debug(self, "Setting apt_packages variable for MySQL")
if not WOShellExec.cmd_exec(self, "mysqladmin ping"):
apt_packages = apt_packages + WOVariables.wo_mysql
packages = packages + [["https://raw."
"githubusercontent.com/"
"major/MySQLTuner-perl"
"/master/mysqltuner.pl",
"/usr/bin/mysqltuner",
"MySQLTuner"]]
2019-07-29 11:23:23 +02:00
2018-11-13 21:55:59 +01:00
else:
Log.debug(self, "MySQL connection is already alive")
Log.info(self, "MySQL connection is already alive")
2019-03-15 16:45:10 +01:00
# WP-CLI
2018-11-13 21:55:59 +01:00
if self.app.pargs.wpcli:
Log.debug(self, "Setting packages variable for WP-CLI")
if not WOShellExec.cmd_exec(self, "command -v wp"):
2018-11-13 21:55:59 +01:00
packages = packages + [["https://github.com/wp-cli/wp-cli/"
"releases/download/v{0}/"
"wp-cli-{0}.phar"
"".format(WOVariables.wo_wp_cli),
2019-03-04 07:12:57 +01:00
"/usr/local/bin/wp",
2018-11-13 21:55:59 +01:00
"WP-CLI"]]
else:
Log.debug(self, "WP-CLI is already installed")
Log.info(self, "WP-CLI is already installed")
2019-03-15 16:45:10 +01:00
2019-04-25 01:38:14 +02:00
# fail2ban
if self.app.pargs.fail2ban:
Log.debug(self, "Setting apt_packages variable for Fail2ban")
if not WOAptGet.is_installed(self, 'fail2ban'):
apt_packages = apt_packages + WOVariables.wo_fail2ban
else:
Log.debug(self, "Fail2ban already installed")
Log.info(self, "Fail2ban already installed")
2019-07-19 13:47:29 +02:00
# proftpd
if self.app.pargs.proftpd:
Log.debug(self, "Setting apt_packages variable for ProFTPd")
if not WOAptGet.is_installed(self, 'proftpd-basic'):
apt_packages = apt_packages + ["proftpd-basic"]
else:
Log.debug(self, "ProFTPd already installed")
Log.info(self, "ProFTPd already installed")
2019-03-15 16:45:10 +01:00
# PHPMYADMIN
2018-11-13 21:55:59 +01:00
if self.app.pargs.phpmyadmin:
2019-07-16 17:15:17 +02:00
if not os.path.isdir('/var/www/22222/htdocs/db/pma'):
Log.debug(self, "Setting packages variable "
"for phpMyAdmin ")
self.app.pargs.composer = True
packages = packages + [["https://github.com/phpmyadmin/"
"phpmyadmin/archive/STABLE.tar.gz",
"/var/lib/wo/tmp/pma.tar.gz",
"phpMyAdmin"]]
else:
Log.debug(self, "phpMyAdmin already installed")
Log.info(self, "phpMyAdmin already installed")
2019-04-01 20:59:53 +02:00
# Composer
if self.app.pargs.composer:
if not os.path.isfile('/usr/local/bin/composer'):
Log.debug(self, "Setting packages variable for Composer ")
packages = packages + [["https://getcomposer.org/"
"installer",
"/var/lib/wo/tmp/composer-install",
"Composer"]]
else:
Log.debug(self, "Composer already installed")
Log.info(self, "Composer already installed")
2019-03-15 16:45:10 +01:00
# PHPREDISADMIN
2018-11-13 21:55:59 +01:00
if self.app.pargs.phpredisadmin:
if not os.path.isdir('/var/www/22222/htdocs/'
'cache/redis/phpRedisAdmin'):
2019-07-16 17:15:17 +02:00
Log.debug(
self, "Setting packages variable for phpRedisAdmin")
self.app.pargs.composer = True
packages = packages + [["https://github.com/"
"erikdubbelboer/"
"phpRedisAdmin/archive"
"/v1.11.3.tar.gz",
2019-07-16 17:15:17 +02:00
"/var/lib/wo/tmp/pra.tar.gz",
"phpRedisAdmin"]]
else:
Log.debug(self, "phpRedisAdmin already installed")
Log.info(self, "phpRedisAdmin already installed")
2019-03-15 16:45:10 +01:00
# ADMINER
2018-11-13 21:55:59 +01:00
if self.app.pargs.adminer:
2019-07-27 22:08:16 +02:00
Log.debug(self, "Setting packages variable for Adminer ")
packages = packages + [["https://github.com/vrana/adminer/"
"releases/download/v{0}"
"/adminer-{0}.php"
.format(WOVariables.wo_adminer),
"{0}22222/"
"htdocs/db/adminer/index.php"
.format(WOVariables.wo_webroot),
"Adminer"],
["https://raw.githubusercontent.com"
"/vrana/adminer/master/designs/"
"pepa-linha/adminer.css",
"{0}22222/"
"htdocs/db/adminer/adminer.css"
.format(WOVariables.wo_webroot),
"Adminer theme"]]
2019-04-16 08:50:15 +02:00
2019-04-02 01:59:40 +02:00
# Netdata
if self.app.pargs.netdata:
Log.debug(self, "Setting packages variable for Netdata")
2019-04-03 07:53:25 +02:00
if not os.path.exists('/opt/netdata'):
packages = packages + [['https://my-netdata.io/'
2019-04-23 19:03:42 +02:00
'kickstart-static64.sh',
'/var/lib/wo/tmp/kickstart.sh',
2019-04-03 07:53:25 +02:00
'Netdata']]
else:
Log.debug(self, "Netdata already installed")
Log.info(self, "Netdata already installed")
2019-04-02 01:59:40 +02:00
2019-04-23 19:03:42 +02:00
# WordOps Dashboard
if self.app.pargs.dashboard:
2019-07-16 17:15:17 +02:00
if not os.path.isfile('/var/www/22222/htdocs/index.php'):
Log.debug(
self, "Setting packages variable for WO-Dashboard")
packages = packages + \
[["https://github.com/WordOps/"
"wordops-dashboard/releases/"
"download/v1.0/wo-dashboard.tar.gz",
"/var/lib/wo/tmp/wo-dashboard.tar.gz",
"WordOps Dashboard"],
["https://github.com/soerennb/"
2019-07-27 22:08:16 +02:00
"extplorer/archive/v{0}.tar.gz"
.format(WOVariables.wo_extplorer),
2019-07-16 17:15:17 +02:00
"/var/lib/wo/tmp/extplorer.tar.gz",
"eXtplorer"]]
else:
Log.debug(self, "WordOps dashboard already installed")
Log.info(self, "WordOps dashboard already installed")
2019-04-23 19:03:42 +02:00
2019-03-15 16:45:10 +01:00
# UTILS
2018-11-13 21:55:59 +01:00
if self.app.pargs.utils:
Log.debug(self, "Setting packages variable for utils")
2019-07-13 04:16:36 +02:00
packages = packages + [["https://raw.githubusercontent.com"
2018-11-13 21:55:59 +01:00
"/rtCamp/eeadmin/master/cache/nginx/"
"clean.php",
"{0}22222/htdocs/cache/"
"nginx/clean.php"
.format(WOVariables.wo_webroot),
"clean.php"],
["https://raw.github.com/rlerdorf/"
"opcache-status/master/opcache.php",
"{0}22222/htdocs/cache/"
"opcache/opcache.php"
.format(WOVariables.wo_webroot),
"opcache.php"],
["https://raw.github.com/amnuts/"
"opcache-gui/master/index.php",
"{0}22222/htdocs/"
"cache/opcache/opgui.php"
.format(WOVariables.wo_webroot),
"Opgui"],
["https://gist.github.com/ck-on/4959032"
"/raw/0b871b345fd6cfcd6d2be030c1f33d1"
"ad6a475cb/ocp.php",
"{0}22222/htdocs/cache/"
"opcache/ocp.php"
.format(WOVariables.wo_webroot),
"OCP.php"],
["https://github.com/jokkedk/webgrind/"
"archive/master.tar.gz",
2019-05-02 13:45:45 +02:00
'/var/lib/wo/tmp/webgrind.tar.gz',
'Webgrind'],
2019-07-13 04:50:28 +02:00
["https://www.percona.com/"
"get/pt-query-digest",
2018-11-13 21:55:59 +01:00
"/usr/bin/pt-query-advisor",
"pt-query-advisor"],
["https://github.com/box/Anemometer/"
"archive/master.tar.gz",
2019-05-02 13:45:45 +02:00
'/var/lib/wo/tmp/anemometer.tar.gz',
'Anemometer']
2018-11-13 21:55:59 +01:00
]
except Exception as e:
2019-07-29 15:08:49 +02:00
Log.debug(self, "{0}".format(e))
2018-11-13 21:55:59 +01:00
2019-04-30 18:50:30 +02:00
if (apt_packages) or (packages):
2019-07-17 03:00:53 +02:00
Log.debug(self, "Calling pre_pref")
self.pre_pref(apt_packages)
2019-04-30 18:50:30 +02:00
if (apt_packages):
2019-07-30 12:24:56 +02:00
meminfo = (os.popen('cat /proc/meminfo '
2019-07-30 13:42:17 +02:00
'| grep MemTotal').read()).split(":")
memsplit = re.split(" kB", meminfo[1])
2019-07-30 13:42:57 +02:00
wo_mem = int(memsplit[0])
2019-07-30 13:26:39 +02:00
if (wo_mem < 4000000):
2019-07-30 12:24:56 +02:00
WOSwap.add(self)
2018-11-13 21:55:59 +01:00
Log.info(self, "Updating apt-cache, please wait...")
WOAptGet.update(self)
Log.info(self, "Installing packages, please wait...")
2019-07-17 03:00:53 +02:00
WOAptGet.install(self, apt_packages)
2019-04-30 18:50:30 +02:00
if (packages):
2018-11-13 21:55:59 +01:00
Log.debug(self, "Downloading following: {0}".format(packages))
WODownload.download(self, packages)
2019-07-17 03:00:53 +02:00
Log.debug(self, "Calling post_pref")
self.post_pref(apt_packages, packages)
2018-11-13 21:55:59 +01:00
if 'redis-server' in apt_packages:
# set redis.conf parameter
# set maxmemory 10% for ram below 512MB and 20% for others
# set maxmemory-policy allkeys-lru
2019-03-27 12:49:17 +01:00
# enable systemd service
Log.debug(self, "Enabling redis systemd service")
WOShellExec.cmd_exec(self, "systemctl enable redis-server")
2018-11-13 21:55:59 +01:00
if os.path.isfile("/etc/redis/redis.conf"):
2019-06-19 21:18:32 +02:00
wo_ram = psutil.virtual_memory().total / (1024 * 1024)
if wo_ram < 1024:
2019-04-11 20:35:03 +02:00
Log.debug(self, "Setting maxmemory variable to "
"{0} in redis.conf"
2019-06-19 21:18:32 +02:00
.format(int(wo_ram*1024*1024*0.1)))
WOFileUtils.searchreplace(self,
"/etc/redis/redis.conf",
"# maxmemory <bytes>",
"maxmemory {0}"
.format
(int(wo_ram*1024*1024*0.1)))
Log.debug(
2019-04-11 20:35:03 +02:00
self, "Setting maxmemory-policy variable to "
"allkeys-lru in redis.conf")
WOFileUtils.searchreplace(self,
"/etc/redis/redis.conf",
"# maxmemory-policy "
"noeviction",
"maxmemory-policy "
"allkeys-lru")
Log.debug(
self, "Setting tcp-backlog variable to "
"in redis.conf")
WOFileUtils.searchreplace(self,
"/etc/redis/redis.conf",
"tcp-backlog 511",
"tcp-backlog 32768")
2019-03-27 12:49:17 +01:00
2018-11-13 21:55:59 +01:00
WOService.restart_service(self, 'redis-server')
else:
2019-04-11 20:35:03 +02:00
Log.debug(self, "Setting maxmemory variable to {0} "
"in redis.conf"
2019-06-19 21:18:32 +02:00
.format(int(wo_ram*1024*1024*0.2)))
WOFileUtils.searchreplace(self,
"/etc/redis/redis.conf",
"# maxmemory <bytes>",
"maxmemory {0}"
.format
(int(wo_ram*1024*1024*0.1)))
Log.debug(
2019-04-11 20:35:03 +02:00
self, "Setting maxmemory-policy variable "
"to allkeys-lru in redis.conf")
WOFileUtils.searchreplace(self,
"/etc/redis/redis.conf",
"# maxmemory-policy "
"noeviction",
"maxmemory-policy "
"allkeys-lru")
2018-11-13 21:55:59 +01:00
WOService.restart_service(self, 'redis-server')
if 'mariadb-server' in apt_packages:
# setting innodb memory usage
wo_ram = psutil.virtual_memory().total / (1024 * 1024)
wo_ram_innodb = int(wo_ram*0.3)
wo_ram_log_buffer = int(wo_ram_innodb*0.25)
wo_ram_log_size = int(wo_ram_log_buffer*0.5)
# replacing default values
if os.path.isfile("/etc/mysql/my.cnf"):
Log.debug(self, "Tuning MySQL configuration")
WOFileUtils.searchreplace(self, "/etc/mysql/my.cnf",
2019-07-25 13:10:33 +02:00
"innodb_buffer_pool_size = 256M",
"innodb_buffer_pool_size = {0}M"
.format(wo_ram_innodb))
WOFileUtils.searchreplace(self, "/etc/mysql/my.cnf",
2019-07-25 13:10:33 +02:00
"innodb_log_buffer_size = 8M",
"innodb_log_buffer_size = {0}M"
.format(wo_ram_log_buffer))
WOFileUtils.searchreplace(self, "/etc/mysql/my.cnf",
2019-07-25 13:10:33 +02:00
"#innodb_log_file_size = 50M",
"innodb_log_file_size = {0}M"
.format(wo_ram_log_size))
WOFileUtils.searchreplace(self,
"/etc/mysql/my.cnf",
2019-07-25 13:10:33 +02:00
"wait_timeout "
2019-07-25 16:47:26 +02:00
"= 600",
2019-07-25 13:10:33 +02:00
"wait_timeout "
2019-07-25 16:47:26 +02:00
"= 120")
# disabling mariadb binlog
WOFileUtils.searchreplace(self,
"/etc/mysql/my.cnf",
2019-07-25 13:10:33 +02:00
"log_bin "
"= /var/log/mysql/"
"mariadb-bin",
"#log_bin "
" = /var/log/"
"mysql/mariadb-bin")
WOFileUtils.searchreplace(self, "/etc/mysql/my.cnf",
2019-07-25 13:10:33 +02:00
'log_bin_index '
"= /var/log/mysql/"
"mariadb-bin.index",
2019-07-25 13:10:33 +02:00
"#log_bin_index "
"= /var/log/mysql/"
"mariadb-bin.index")
WOFileUtils.searchreplace(self, "/etc/mysql/my.cnf",
2019-07-25 13:10:33 +02:00
"expire_logs_days = 10",
"#expire_logs_days "
"= 10")
WOFileUtils.searchreplace(self, "/etc/mysql/my.cnf",
"max_binlog_size "
"= 100M",
"#max_binlog_size "
"= 100M")
2019-07-25 16:47:26 +02:00
WOFileUtils.searchreplace(self, "/etc/mysql/my.cnf",
"innodb_open_files ="
" 400",
"innodb_open_files ="
" 16000")
WOFileUtils.searchreplace(self, "/etc/mysql/my.cnf",
"innodb_io_capacity ="
" 400",
"innodb_io_capacity ="
" 16000")
WOService.stop_service(self, 'mysql')
WOFileUtils.mvfile(self, '/var/lib/mysql/ib_logfile0',
'/var/lib/mysql/ib_logfile0.bak')
WOFileUtils.mvfile(self, '/var/lib/mysql/ib_logfile1',
'/var/lib/mysql/ib_logfile1.bak')
WOService.start_service(self, 'mysql')
2019-07-25 11:40:12 +02:00
2018-11-13 21:55:59 +01:00
if disp_msg:
2019-04-30 18:50:30 +02:00
if (self.msg):
2018-11-13 21:55:59 +01:00
for msg in self.msg:
Log.info(self, Log.ENDC + msg)
Log.info(self, "Successfully installed packages")
else:
return self.msg
@expose(help="Remove packages")
def remove(self):
"""Start removal of packages"""
apt_packages = []
packages = []
if ((not self.app.pargs.web) and (not self.app.pargs.admin) and
(not self.app.pargs.nginx) and (not self.app.pargs.php) and
(not self.app.pargs.php73) and (not self.app.pargs.mysql) and
(not self.app.pargs.wpcli) and (not self.app.pargs.phpmyadmin) and
2019-03-13 05:02:53 +01:00
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and
2019-04-03 06:59:13 +02:00
(not self.app.pargs.composer) and (not self.app.pargs.netdata) and
2019-07-19 13:47:29 +02:00
(not self.app.pargs.fail2ban) and (not self.app.pargs.proftpd) and
2019-07-19 15:21:17 +02:00
(not self.app.pargs.security) and
2019-03-13 05:02:53 +01:00
(not self.app.pargs.all) and (not self.app.pargs.redis) and
2019-03-08 00:43:25 +01:00
(not self.app.pargs.phpredisadmin)):
2018-11-13 21:55:59 +01:00
self.app.pargs.web = True
self.app.pargs.admin = True
2019-07-19 15:21:17 +02:00
self.app.pargs.security = True
2018-11-13 21:55:59 +01:00
if self.app.pargs.all:
self.app.pargs.web = True
self.app.pargs.admin = True
2019-03-15 16:45:10 +01:00
self.app.pargs.php73 = True
2018-11-13 21:55:59 +01:00
if self.app.pargs.web:
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
self.app.pargs.wpcli = True
if self.app.pargs.admin:
self.app.pargs.adminer = True
self.app.pargs.phpmyadmin = True
2019-04-01 20:59:53 +02:00
self.app.pargs.composer = True
2018-11-13 21:55:59 +01:00
self.app.pargs.utils = True
self.app.pargs.netdata = True
self.app.pargs.dashboard = True
self.app.pargs.phpredisadmin = True
2019-07-19 15:21:17 +02:00
if self.app.pargs.security:
2019-07-18 17:04:20 +02:00
self.app.pargs.fail2ban = True
2019-03-15 16:45:10 +01:00
# NGINX
2018-11-13 21:55:59 +01:00
if self.app.pargs.nginx:
if WOAptGet.is_installed(self, 'nginx-custom'):
Log.debug(self, "Removing apt_packages variable of Nginx")
apt_packages = apt_packages + WOVariables.wo_nginx
else:
2019-04-11 20:35:03 +02:00
Log.error(self, "Cannot Remove! Nginx Stable "
"version not found.")
2019-03-15 16:45:10 +01:00
# PHP 7.2
2018-11-13 21:55:59 +01:00
if self.app.pargs.php:
Log.debug(self, "Removing apt_packages variable of PHP")
2019-03-27 12:49:17 +01:00
if WOAptGet.is_installed(self, 'php7.2-fpm'):
if not WOAptGet.is_installed(self, 'php7.3-fpm'):
2019-04-01 20:59:53 +02:00
apt_packages = apt_packages + WOVariables.wo_php + \
WOVariables.wo_php_extra
2019-03-27 12:49:17 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php
else:
Log.error(self, "PHP 7.2 not found")
2018-11-13 21:55:59 +01:00
2019-03-08 00:43:25 +01:00
# PHP7.3
if self.app.pargs.php73:
2019-03-15 16:45:10 +01:00
Log.debug(self, "Removing apt_packages variable of PHP 7.3")
2019-03-27 12:49:17 +01:00
if WOAptGet.is_installed(self, 'php7.3-fpm'):
2019-03-16 09:18:15 +01:00
if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
2019-04-01 20:59:53 +02:00
apt_packages = apt_packages + WOVariables.wo_php73 + \
2019-04-01 22:19:44 +02:00
WOVariables.wo_php_extra
2019-03-16 09:18:15 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php73
2019-03-27 12:49:17 +01:00
else:
Log.error(self, "PHP 7.3 not found")
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# REDIS
2018-11-13 21:55:59 +01:00
if self.app.pargs.redis:
Log.debug(self, "Remove apt_packages variable of Redis")
apt_packages = apt_packages + WOVariables.wo_redis
2019-03-15 16:45:10 +01:00
# MariaDB
2018-11-13 21:55:59 +01:00
if self.app.pargs.mysql:
Log.debug(self, "Removing apt_packages variable of MySQL")
apt_packages = apt_packages + WOVariables.wo_mysql
packages = packages + ['/usr/bin/mysqltuner']
2019-07-18 17:04:20 +02:00
# fail2ban
2019-07-18 18:19:04 +02:00
if self.app.pargs.fail2ban:
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'fail2ban'):
Log.debug(self, "Remove apt_packages variable of Fail2ban")
apt_packages = apt_packages + WOVariables.wo_fail2ban
else:
Log.error(self, "Fail2ban not found")
# proftpd
if self.app.pargs.proftpd:
if WOAptGet.is_installed(self, 'proftpd-basic'):
Log.debug(self, "Remove apt_packages variable for ProFTPd")
apt_packages = apt_packages + ["proftpd-basic"]
else:
Log.error(self, "ProFTPd not found")
2019-07-18 17:04:20 +02:00
2019-03-15 16:45:10 +01:00
# WPCLI
2018-11-13 21:55:59 +01:00
if self.app.pargs.wpcli:
Log.debug(self, "Removing package variable of WPCLI ")
2019-03-04 07:12:57 +01:00
if os.path.isfile('/usr/local/bin/wp'):
packages = packages + ['/usr/local/bin/wp']
2018-11-13 21:55:59 +01:00
else:
Log.warn(self, "WP-CLI is not installed with WordOps")
2019-03-15 16:45:10 +01:00
# PHPMYADMIN
2018-11-13 21:55:59 +01:00
if self.app.pargs.phpmyadmin:
Log.debug(self, "Removing package variable of phpMyAdmin ")
packages = packages + ['{0}22222/htdocs/db/pma'
.format(WOVariables.wo_webroot)]
# Composer
if self.app.pargs.composer:
Log.debug(self, "Removing package variable of Composer ")
if os.path.isfile('/usr/local/bin/composer'):
packages = packages + ['/usr/local/bin/composer']
else:
Log.warn(self, "Composer is not installed with WordOps")
2019-03-15 16:45:10 +01:00
# PHPREDISADMIN
2018-11-13 21:55:59 +01:00
if self.app.pargs.phpredisadmin:
Log.debug(self, "Removing package variable of phpRedisAdmin ")
if os.path.isdir('{0}22222/htdocs/cache/redis'
.format(WOVariables.wo_webroot)):
packages = packages + ['{0}22222/htdocs/'
'cache/redis/phpRedisAdmin'
.format(WOVariables.wo_webroot)]
2019-03-15 16:45:10 +01:00
# ADMINER
2018-11-13 21:55:59 +01:00
if self.app.pargs.adminer:
Log.debug(self, "Removing package variable of Adminer ")
packages = packages + ['{0}22222/htdocs/db/adminer'
.format(WOVariables.wo_webroot)]
if self.app.pargs.utils:
Log.debug(self, "Removing package variable of utils ")
packages = packages + ['{0}22222/htdocs/php/webgrind/'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/cache/opcache'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/cache/nginx/'
'clean.php'.format(WOVariables.wo_webroot),
'/usr/bin/pt-query-advisor',
'{0}22222/htdocs/db/anemometer'
.format(WOVariables.wo_webroot)]
if self.app.pargs.netdata:
Log.debug(self, "Removing Netdata")
if os.path.isfile('/opt/netdata/usr/'
'libexec/netdata-uninstaller.sh'):
packages = packages + ['/var/lib/wo/tmp/kickstart.sh']
if self.app.pargs.dashboard:
Log.debug(self, "Removing Wo-Dashboard")
packages = packages + ['{0}22222/htdocs/assets/'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/index.php'
.format(WOVariables.wo_webroot)]
2019-04-30 18:50:30 +02:00
if (packages) or (apt_packages):
2018-11-13 21:55:59 +01:00
wo_prompt = input('Are you sure you to want to'
' remove from server.'
'\nPackage configuration will remain'
' on server after this operation.\n'
'Any answer other than '
'"yes" will be stop this'
' operation : ')
if wo_prompt == 'YES' or wo_prompt == 'yes':
if (set(["nginx-custom"]).issubset(set(apt_packages))):
2018-11-13 21:55:59 +01:00
WOService.stop_service(self, 'nginx')
# Netdata uninstaller
if (set(['/var/lib/wo/tmp/'
'kickstart.sh']).issubset(set(packages))):
WOShellExec.cmd_exec(self, "bash /opt/netdata/usr/"
"libexec/netdata-"
"uninstaller.sh -y -f")
2019-04-30 18:50:30 +02:00
if (packages):
2018-11-13 21:55:59 +01:00
WOFileUtils.remove(self, packages)
WOAptGet.auto_remove(self)
2019-04-30 18:50:30 +02:00
if (apt_packages):
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing apt_packages")
Log.info(self, "Removing packages, please wait...")
WOAptGet.remove(self, apt_packages)
WOAptGet.auto_remove(self)
Log.info(self, "Successfully removed packages")
@expose(help="Purge packages")
def purge(self):
"""Start purging of packages"""
apt_packages = []
packages = []
# Default action for stack purge
if ((not self.app.pargs.web) and (not self.app.pargs.admin) and
(not self.app.pargs.nginx) and (not self.app.pargs.php) and
(not self.app.pargs.php73) and (not self.app.pargs.mysql) and
(not self.app.pargs.wpcli) and (not self.app.pargs.phpmyadmin) and
2019-03-13 05:02:53 +01:00
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and
2019-04-03 06:59:13 +02:00
(not self.app.pargs.composer) and (not self.app.pargs.netdata) and
2019-07-19 15:21:17 +02:00
(not self.app.pargs.fail2ban) and (not self.app.pargs.proftpd) and
(not self.app.pargs.security) and
2019-03-13 05:02:53 +01:00
(not self.app.pargs.all) and (not self.app.pargs.redis) and
2019-03-15 16:45:10 +01:00
(not self.app.pargs.phpredisadmin)):
2018-11-13 21:55:59 +01:00
self.app.pargs.web = True
self.app.pargs.admin = True
2019-07-19 15:21:17 +02:00
self.app.pargs.security = True
2018-11-13 21:55:59 +01:00
if self.app.pargs.all:
self.app.pargs.web = True
self.app.pargs.admin = True
2019-03-15 16:45:10 +01:00
self.app.pargs.php73 = True
2018-11-13 21:55:59 +01:00
if self.app.pargs.web:
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
self.app.pargs.wpcli = True
if self.app.pargs.admin:
self.app.pargs.adminer = True
self.app.pargs.phpmyadmin = True
self.app.pargs.utils = True
self.app.pargs.composer = True
self.app.pargs.netdata = True
self.app.pargs.dashboard = True
self.app.pargs.phpredisadmin = True
2018-11-13 21:55:59 +01:00
2019-07-19 15:21:17 +02:00
if self.app.pargs.security:
self.app.pargs.fail2ban = True
2019-03-15 16:45:10 +01:00
# NGINX
2018-11-13 21:55:59 +01:00
if self.app.pargs.nginx:
if WOAptGet.is_installed(self, 'nginx-custom'):
Log.debug(self, "Purge apt_packages variable of Nginx")
apt_packages = apt_packages + WOVariables.wo_nginx
else:
2019-04-23 19:03:42 +02:00
Log.error(self, "Cannot Purge! "
"Nginx Stable version not found.")
2019-03-15 16:45:10 +01:00
# PHP
2018-11-13 21:55:59 +01:00
if self.app.pargs.php:
Log.debug(self, "Purge apt_packages variable PHP")
2019-03-27 12:49:17 +01:00
if WOAptGet.is_installed(self, 'php7.2-fpm'):
if not (WOAptGet.is_installed(self, 'php7.3-fpm')):
2019-04-11 20:35:03 +02:00
apt_packages = apt_packages + WOVariables.wo_php + \
WOVariables.wo_php_extra
2019-03-27 12:49:17 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php
2018-11-13 21:55:59 +01:00
else:
2019-03-15 16:45:10 +01:00
Log.error(self, "Cannot Purge PHP 7.2. not found.")
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# PHP 7.3
if self.app.pargs.php73:
2019-03-15 16:45:10 +01:00
Log.debug(self, "Removing apt_packages variable of PHP 7.3")
2019-03-27 12:49:17 +01:00
if WOAptGet.is_installed(self, 'php7.3-fpm'):
2019-03-16 09:18:15 +01:00
if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
2019-04-11 20:35:03 +02:00
apt_packages = apt_packages + WOVariables.wo_php73 + \
WOVariables.wo_php_extra
2019-03-16 09:18:15 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php73
2019-03-27 12:49:17 +01:00
2019-07-18 17:04:20 +02:00
# fail2ban
2019-07-18 18:19:04 +02:00
if self.app.pargs.fail2ban:
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'fail2ban'):
Log.debug(self, "Purge apt_packages variable of Fail2ban")
apt_packages = apt_packages + WOVariables.wo_fail2ban
# proftpd
if self.app.pargs.proftpd:
if WOAptGet.is_installed(self, 'proftpd-basic'):
Log.debug(self, "Purge apt_packages variable for ProFTPd")
apt_packages = apt_packages + ["proftpd-basic"]
2019-07-18 17:04:20 +02:00
2019-03-15 16:45:10 +01:00
# WP-CLI
if self.app.pargs.wpcli:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Purge package variable WPCLI")
2019-03-04 07:12:57 +01:00
if os.path.isfile('/usr/local/bin/wp'):
packages = packages + ['/usr/local/bin/wp']
2018-11-13 21:55:59 +01:00
else:
Log.warn(self, "WP-CLI is not installed with WordOps")
2019-03-15 16:45:10 +01:00
# PHPMYADMIN
2018-11-13 21:55:59 +01:00
if self.app.pargs.phpmyadmin:
packages = packages + ['{0}22222/htdocs/db/pma'.
format(WOVariables.wo_webroot)]
Log.debug(self, "Purge package variable phpMyAdmin")
2019-03-15 16:45:10 +01:00
# Composer
if self.app.pargs.composer:
Log.debug(self, "Removing package variable of Composer ")
if os.path.isfile('/usr/local/bin/composer'):
packages = packages + ['/usr/local/bin/composer']
else:
Log.warn(self, "Composer is not installed with WordOps")
2019-03-15 16:45:10 +01:00
# PHPREDISADMIN
2018-11-13 21:55:59 +01:00
if self.app.pargs.phpredisadmin:
Log.debug(self, "Removing package variable of phpRedisAdmin ")
if os.path.isdir('{0}22222/htdocs/cache/redis'
.format(WOVariables.wo_webroot)):
packages = packages + ['{0}22222/htdocs/'
'cache/redis/phpRedisAdmin'
.format(WOVariables.wo_webroot)]
2019-03-15 16:45:10 +01:00
# Adminer
2018-11-13 21:55:59 +01:00
if self.app.pargs.adminer:
Log.debug(self, "Purge package variable Adminer")
packages = packages + ['{0}22222/htdocs/db/adminer'
.format(WOVariables.wo_webroot)]
2019-03-15 16:45:10 +01:00
# utils
2018-11-13 21:55:59 +01:00
if self.app.pargs.utils:
Log.debug(self, "Purge package variable utils")
packages = packages + ['{0}22222/htdocs/php/webgrind/'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/cache/opcache'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/cache/nginx/'
'clean.php'.format(WOVariables.wo_webroot),
'/usr/bin/pt-query-advisor',
'{0}22222/htdocs/db/anemometer'
.format(WOVariables.wo_webroot)
]
if self.app.pargs.netdata:
Log.debug(self, "Removing Netdata")
if os.path.isfile('/opt/netdata/usr/'
'libexec/netdata-uninstaller.sh'):
packages = packages + ['/var/lib/wo/tmp/kickstart.sh']
if self.app.pargs.dashboard:
Log.debug(self, "Removing Wo-Dashboard")
packages = packages + ['{0}22222/htdocs/assets/'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/index.php'
.format(WOVariables.wo_webroot)]
2019-04-30 18:50:30 +02:00
if (packages) or (apt_packages):
2018-11-13 21:55:59 +01:00
wo_prompt = input('Are you sure you to want to purge '
'from server '
'along with their configuration'
' packages,\nAny answer other than '
'"yes" will be stop this '
'operation :')
if wo_prompt == 'YES' or wo_prompt == 'yes':
if (set(["nginx-custom"]).issubset(set(apt_packages))):
2018-11-13 21:55:59 +01:00
WOService.stop_service(self, 'nginx')
# Netdata uninstaller
if (set(['/var/lib/wo/tmp/'
'kickstart.sh']).issubset(set(packages))):
WOShellExec.cmd_exec(self, "bash /opt/netdata/usr/"
"libexec/netdata-"
"uninstaller.sh -y -f")
if (set(["fail2ban"]).issubset(set(apt_packages))):
WOService.stop_service(self, 'fail2ban')
2019-04-30 18:50:30 +02:00
if (apt_packages):
2018-11-13 21:55:59 +01:00
Log.info(self, "Purging packages, please wait...")
WOAptGet.remove(self, apt_packages, purge=True)
WOAptGet.auto_remove(self)
2019-04-30 18:50:30 +02:00
if (packages):
2018-11-13 21:55:59 +01:00
WOFileUtils.remove(self, packages)
WOAptGet.auto_remove(self)
Log.info(self, "Successfully purged packages")
2019-03-07 18:38:19 +01:00
2018-11-13 21:55:59 +01:00
def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(WOStackController)
handler.register(WOStackStatusController)
handler.register(WOStackMigrateController)
handler.register(WOStackUpgradeController)
# register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', wo_stack_hook)