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

1183 lines
51 KiB
Python
Raw Normal View History

2018-11-13 21:55:59 +01:00
"""Stack Plugin for WordOps"""
import os
2019-09-06 12:07:34 +02:00
2019-09-02 04:37:13 +02:00
from cement.core.controller import CementBaseController, expose
2019-09-05 11:47:04 +02:00
2018-11-13 21:55:59 +01:00
from wo.cli.plugins.stack_migrate import WOStackMigrateController
2019-10-23 01:59:10 +02:00
from wo.cli.plugins.stack_pref import post_pref, pre_pref, pre_stack
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.aptget import WOAptGet
2019-08-28 16:02:42 +02:00
from wo.core.download import WODownload
from wo.core.fileutils import WOFileUtils
2018-11-13 21:55:59 +01:00
from wo.core.logging import Log
2019-08-28 16:02:42 +02:00
from wo.core.mysql import WOMysql
from wo.core.services import WOService
2019-09-22 01:02:04 +02:00
from wo.core.shellexec import WOShellExec
2019-10-02 13:13:32 +02:00
from wo.core.variables import WOVar
from wo.core.nginx import check_config
from wo.core.git import WOGit
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')),
(['--mysql'],
dict(help='Install MySQL stack', action='store_true')),
2020-10-28 12:25:09 +01:00
(['--mariadb'],
dict(help='Install MySQL stack alias', action='store_true')),
2019-08-15 23:46:16 +02:00
(['--mysqlclient'],
dict(help='Install MySQL client for remote MySQL server',
action='store_true')),
2019-08-16 22:44:47 +02:00
(['--mysqltuner'],
dict(help='Install MySQLTuner stack', action='store_true')),
2018-11-13 21:55:59 +01:00
(['--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')),
(['--extplorer'],
2019-08-26 18:33:27 +02:00
dict(help='Install eXtplorer file manager',
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')),
(['--clamav'],
dict(help='Install ClamAV stack', action='store_true')),
2019-09-20 14:21:42 +02:00
(['--ufw'],
dict(help='Install UFW stack', action='store_true')),
2019-09-01 22:02:00 +02:00
(['--sendmail'],
dict(help='Install Sendmail 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')),
2019-09-27 01:19:45 +02:00
(['--ngxblocker'],
dict(help='Install Nginx Ultimate Bad Bot Blocker',
action='store_true')),
2019-10-28 20:07:38 +01:00
(['--cheat'],
dict(help='Install cheat.sh', action='store_true')),
2019-10-31 15:42:42 +01:00
(['--nanorc'],
2019-11-02 15:59:19 +01:00
dict(help='Install nanorc syntax highlighting',
2019-10-31 15:42:42 +01:00
action='store_true')),
(['--brotli'],
dict(help='Enable/Disable Brotli compression for Nginx',
action='store_true')),
2019-08-07 03:05:32 +02:00
(['--force'],
dict(help='Force install/remove/purge without prompt',
action='store_true')),
]
2023-08-12 14:08:05 +02:00
for php_version, php_number in WOVar.wo_php_versions.items():
arguments.append(([f'--{php_version}'],
dict(help=f'Install PHP {php_number} stack',
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(help="Install packages")
def install(self, packages=[], apt_packages=[], disp_msg=True):
"""Start installation of packages"""
self.msg = []
2019-08-07 03:05:32 +02:00
pargs = self.app.pargs
2019-09-04 16:55:58 +02:00
2018-11-13 21:55:59 +01:00
try:
# Default action for stack installation
2023-08-12 16:12:06 +02:00
if all(value is None or value is False for value in vars(pargs).values()):
2019-08-07 03:05:32 +02:00
pargs.web = True
pargs.admin = True
pargs.fail2ban = True
2019-08-07 03:05:32 +02:00
2020-10-28 12:25:09 +01:00
if pargs.mariadb:
pargs.mysql = True
2019-08-07 03:05:32 +02:00
if pargs.all:
pargs.web = True
pargs.admin = True
pargs.php73 = True
pargs.php74 = True
2022-01-23 15:14:24 -03:00
pargs.php80 = True
pargs.php81 = True
2022-12-10 10:37:20 -03:00
pargs.php82 = True
2023-11-23 21:33:09 +01:00
pargs.php83 = True
2019-08-07 03:05:32 +02:00
pargs.redis = True
pargs.proftpd = True
if pargs.web:
2023-08-05 11:41:46 +02:00
pargs.php = True
2019-08-07 03:05:32 +02:00
pargs.nginx = True
pargs.mysql = True
pargs.wpcli = True
2019-09-01 22:02:00 +02:00
pargs.sendmail = True
2019-08-07 03:05:32 +02:00
if pargs.admin:
2019-09-01 22:02:00 +02:00
pargs.web = True
2019-08-07 03:05:32 +02:00
pargs.adminer = True
pargs.phpmyadmin = True
2019-08-29 23:04:46 +02:00
pargs.composer = True
2019-08-07 03:05:32 +02:00
pargs.utils = True
pargs.netdata = True
pargs.dashboard = True
pargs.phpredisadmin = True
2019-08-26 18:33:27 +02:00
pargs.extplorer = True
2019-10-28 20:07:38 +01:00
pargs.cheat = True
pargs.nanorc = True
2019-08-07 03:05:32 +02:00
if pargs.security:
pargs.fail2ban = True
pargs.clamav = True
2019-09-27 11:59:57 +02:00
pargs.ngxblocker = True
2018-11-13 21:55:59 +01:00
2023-08-26 14:33:59 +02:00
if pargs.php:
if self.app.config.has_section('php'):
config_php_ver = self.app.config.get(
'php', 'version')
current_php = config_php_ver.replace(".", "")
setattr(self.app.pargs, 'php{0}'.format(current_php), True)
2019-04-23 19:03:42 +02:00
# Nginx
2019-08-07 03:05:32 +02:00
if pargs.nginx:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Setting apt_packages variable for Nginx")
if not WOAptGet.is_exec(self, 'nginx'):
apt_packages = apt_packages + WOVar.wo_nginx
2018-11-13 21:55:59 +01:00
else:
2019-09-27 14:15:00 +02:00
Log.debug(self, "Nginx already installed")
2018-11-13 21:55:59 +01:00
2019-08-29 20:02:35 +02:00
# Redis
if pargs.redis:
if not WOAptGet.is_installed(self, 'redis-server'):
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_redis
2019-09-01 22:02:00 +02:00
2019-08-29 20:02:35 +02:00
else:
Log.debug(self, "Redis already installed")
2019-08-29 20:02:35 +02:00
2023-08-05 18:02:49 +02:00
wo_vars = {
'php74': WOVar.wo_php74,
'php80': WOVar.wo_php80,
'php81': WOVar.wo_php81,
'php82': WOVar.wo_php82,
2023-11-23 21:33:09 +01:00
'php83': WOVar.wo_php83,
2023-08-05 18:02:49 +02:00
}
for parg_version, version in WOVar.wo_php_versions.items():
if getattr(pargs, parg_version, False):
Log.debug(self, f"Setting apt_packages variable for PHP {version}")
if not WOAptGet.is_installed(self, f'php{version}-fpm'):
apt_packages = apt_packages + wo_vars[parg_version] + WOVar.wo_php_extra
else:
Log.debug(self, f"PHP {version} already installed")
Log.info(self, f"PHP {version} already installed")
2022-12-10 10:37:20 -03:00
2023-08-05 11:41:46 +02:00
# MariaDB
2019-08-07 03:05:32 +02:00
if pargs.mysql:
2019-09-04 17:04:25 +02:00
pargs.mysqltuner = True
Log.debug(self, "Setting apt_packages variable for MySQL")
if not WOShellExec.cmd_exec(self, "mysqladmin ping"):
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_mysql
2019-08-29 20:02:35 +02:00
else:
Log.debug(self, "MySQL already installed and alive")
Log.info(self, "MySQL already installed and alive")
2019-07-29 11:23:23 +02:00
# mysqlclient
2019-08-15 23:46:16 +02:00
if pargs.mysqlclient:
Log.debug(self, "Setting apt_packages variable "
"for MySQL Client")
2019-08-29 20:02:35 +02:00
if not WOShellExec.cmd_exec(self, "mysqladmin ping"):
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_mysql_client
2019-08-29 20:02:35 +02:00
else:
Log.debug(self, "MySQL already installed and alive")
Log.info(self, "MySQL already installed and alive")
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# WP-CLI
2019-08-07 03:05:32 +02:00
if pargs.wpcli:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Setting packages variable for WP-CLI")
if not WOAptGet.is_exec(self, 'wp'):
packages = packages + [[f"{WOVar.wpcli_url}"
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
2019-08-07 03:05:32 +02:00
if pargs.fail2ban:
2019-04-25 01:38:14 +02:00
Log.debug(self, "Setting apt_packages variable for Fail2ban")
if not WOAptGet.is_installed(self, 'fail2ban'):
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_fail2ban
2019-04-25 01:38:14 +02:00
else:
Log.debug(self, "Fail2ban already installed")
Log.info(self, "Fail2ban already installed")
# ClamAV
if pargs.clamav:
Log.debug(self, "Setting apt_packages variable for ClamAV")
2019-08-26 18:59:06 +02:00
if not WOAptGet.is_installed(self, 'clamav'):
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_clamav
else:
2019-08-26 18:59:06 +02:00
Log.debug(self, "ClamAV already installed")
Log.info(self, "ClamAV already installed")
2019-09-20 14:21:42 +02:00
# UFW
if pargs.ufw:
Log.debug(self, "Setting apt_packages variable for UFW")
apt_packages = apt_packages + ["ufw"]
2019-09-20 14:21:42 +02:00
2019-09-01 22:02:00 +02:00
# sendmail
if pargs.sendmail:
Log.debug(self, "Setting apt_packages variable for Sendmail")
if (not WOAptGet.is_installed(self, 'sendmail') and
not WOAptGet.is_installed(self, 'postfix')):
2019-09-01 22:02:00 +02:00
apt_packages = apt_packages + ["sendmail"]
else:
if WOAptGet.is_installed(self, 'sendmail'):
Log.debug(self, "Sendmail already installed")
Log.info(self, "Sendmail already installed")
else:
2019-09-26 11:17:08 +02:00
Log.debug(
self, "Another mta (Postfix) is already installed")
Log.info(
self, "Another mta (Postfix) is already installed")
2019-09-01 22:02:00 +02:00
2019-07-19 13:47:29 +02:00
# proftpd
2019-08-07 03:05:32 +02:00
if pargs.proftpd:
2019-07-19 13:47:29 +02:00
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")
# brotli
if pargs.brotli:
Log.wait(self, "Enabling Brotli")
2024-06-01 22:10:25 +02:00
WOGit.add(self, ["/etc/nginx"], msg="Commiting pending changes")
if os.path.exists('/etc/nginx/conf.d/brotli.conf.disabled'):
WOFileUtils.mvfile(self, '/etc/nginx/conf.d/brotli.conf.disabled',
'/etc/nginx/conf.d/brotli.conf')
else:
Log.failed(self, "Enabling Brotli")
Log.error(self, "Brotli is already enabled")
if os.path.exists('/etc/nginx/conf.d/gzip.conf'):
WOFileUtils.mvfile(self, '/etc/nginx/conf.d/gzip.conf',
'/etc/nginx/conf.d/gzip.conf.disabled')
if check_config(self):
Log.valide(self, "Enabling Brotli")
2024-06-01 22:10:25 +02:00
WOGit.add(self, ["/etc/nginx"], msg="Enabling Brotli")
WOService.reload_service(self, "nginx")
else:
Log.failed(self, "Enabling Brotli")
2024-06-01 22:10:25 +02:00
WOGit.rollback(self, ["/etc/nginx"])
2019-03-15 16:45:10 +01:00
# PHPMYADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpmyadmin:
2019-08-29 15:35:03 +02:00
pargs.composer = True
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 ")
2020-04-23 16:36:30 +02:00
packages = packages + [[
"https://www.phpmyadmin.net/"
"downloads/phpMyAdmin-latest-all-languages.tar.gz",
"/var/lib/wo/tmp/pma.tar.gz",
"PHPMyAdmin"]]
else:
Log.debug(self, "phpMyAdmin already installed")
Log.info(self, "phpMyAdmin already installed")
# PHPREDISADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpredisadmin:
2019-08-29 15:35:03 +02:00
pargs.composer = True
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")
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-08-29 15:35:03 +02:00
# Composer
2019-08-29 18:57:19 +02:00
if pargs.composer:
if not WOAptGet.is_exec(self, 'php'):
2019-09-01 13:59:27 +02:00
pargs.php = True
if not WOAptGet.is_exec(self, 'composer'):
2019-08-29 18:57:19 +02:00
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-08-29 15:35:03 +02:00
2019-03-15 16:45:10 +01:00
# ADMINER
2019-08-29 18:57:19 +02:00
if pargs.adminer:
if not os.path.isfile("{0}22222/htdocs/db/"
"adminer/index.php"
.format(WOVar.wo_webroot)):
2019-08-29 18:57:19 +02:00
Log.debug(self, "Setting packages variable for Adminer ")
2019-10-18 15:28:58 +02:00
packages = packages + [[
"https://www.adminer.org/latest.php",
2019-10-18 15:28:58 +02:00
"{0}22222/"
"htdocs/db/adminer/index.php"
.format(WOVar.wo_webroot),
"Adminer"],
["https://raw.githubusercontent.com"
"/vrana/adminer/master/designs/"
"pepa-linha/adminer.css",
"{0}22222/"
"htdocs/db/adminer/adminer.css"
.format(WOVar.wo_webroot),
"Adminer theme"]]
2019-08-29 20:02:35 +02:00
else:
Log.debug(self, "Adminer already installed")
Log.info(self, "Adminer already installed")
# mysqltuner
2019-08-29 18:57:19 +02:00
if pargs.mysqltuner:
if not os.path.isfile("/usr/bin/mysqltuner"):
Log.debug(self, "Setting packages variable "
"for MySQLTuner ")
packages = packages + [["https://raw."
"githubusercontent.com/"
"major/MySQLTuner-perl"
"/master/mysqltuner.pl",
"/usr/bin/mysqltuner",
"MySQLTuner"]]
2019-08-29 20:02:35 +02:00
else:
Log.debug(self, "MySQLtuner already installed")
Log.info(self, "MySQLtuner already installed")
2019-08-16 22:44:47 +02:00
2019-04-02 01:59:40 +02:00
# Netdata
2019-08-29 18:57:19 +02:00
if pargs.netdata:
if (not os.path.isdir('/opt/netdata') and not
os.path.isdir("/etc/netdata")):
Log.debug(
self, "Setting packages variable for Netdata")
packages = packages + [[f"{WOVar.netdata_script_url}",
2022-02-01 14:46:58 +01:00
'/var/lib/wo/tmp/kickstart.sh',
'Netdata']]
else:
2019-08-29 18:57:19 +02:00
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
2019-08-07 03:05:32 +02:00
if pargs.dashboard:
2019-07-16 17:15:17 +02:00
if not os.path.isfile('/var/www/22222/htdocs/index.php'):
2019-08-28 14:03:40 +02:00
Log.debug(self,
"Setting packages variable for WO-Dashboard")
2019-10-18 15:28:58 +02:00
packages = packages + [[
"https://github.com/WordOps"
"/wordops-dashboard/"
"releases/download/v{0}/"
"wordops-dashboard.tar.gz"
.format(WOVar.wo_dashboard),
"/var/lib/wo/tmp/wo-dashboard.tar.gz",
"WordOps Dashboard"]]
else:
Log.debug(self, "WordOps dashboard already installed")
Log.info(self, "WordOps dashboard already installed")
2019-04-23 19:03:42 +02:00
2019-08-26 18:59:06 +02:00
# eXtplorer
2019-09-01 16:50:13 +02:00
if pargs.extplorer:
if not os.path.isdir('/var/www/22222/htdocs/files'):
Log.debug(self, "Setting packages variable for eXtplorer")
packages = packages + \
[["https://github.com/soerennb/"
"extplorer/archive/v{0}.tar.gz"
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_extplorer),
"/var/lib/wo/tmp/extplorer.tar.gz",
"eXtplorer"]]
else:
Log.debug(self, "eXtplorer is already installed")
Log.info(self, "eXtplorer is already installed")
2019-10-28 20:07:38 +01:00
# ultimate ngx_blocker
2019-09-27 01:19:45 +02:00
if pargs.ngxblocker:
if not WOAptGet.is_exec(self, 'nginx'):
pargs.nginx = True
2019-09-27 01:19:45 +02:00
if not os.path.isdir('/etc/nginx/bots.d'):
Log.debug(self, "Setting packages variable for ngxblocker")
packages = packages + \
[["https://raw.githubusercontent.com/"
"mitchellkrogza/nginx-ultimate-bad-bot-blocker"
"/master/install-ngxblocker",
"/usr/local/sbin/install-ngxblocker",
"ngxblocker"]]
else:
Log.debug(self, "ngxblocker is already installed")
Log.info(self, "ngxblocker is already installed")
2019-10-28 20:07:38 +01:00
# cheat.sh
if pargs.cheat:
if ((not os.path.exists('/usr/local/bin/cht.sh')) and
(not os.path.exists('/usr/bin/cht.sh'))):
Log.debug(self, 'Setting packages variable for cheat.sh')
packages = packages + [[
"https://raw.githubusercontent.com/chubin/cheat.sh"
"/master/share/cht.sh.txt",
"/usr/local/bin/cht.sh",
"cheat.sh"],
["https://raw.githubusercontent.com/chubin/cheat.sh"
"/master/share/bash_completion.txt",
"/etc/bash_completion.d/cht.sh",
2019-10-29 01:10:37 +01:00
"bash_completion"]]
2019-10-28 20:07:38 +01:00
2019-10-31 15:42:42 +01:00
if pargs.nanorc:
if not os.path.exists('/usr/share/nano-syntax-highlighting'):
Log.debug(self, "Setting packages variable for nanorc")
apt_packages = apt_packages + ['nano']
2019-03-15 16:45:10 +01:00
# UTILS
2019-08-07 03:05:32 +02:00
if pargs.utils:
if not WOShellExec.cmd_exec(self, 'mysqladmin ping'):
pargs.mysql = True
if not (WOAptGet.is_installed(self, 'php7.2-fpm') or
WOAptGet.is_installed(self, 'php7.3-fpm') or
2022-01-23 15:14:24 -03:00
WOAptGet.is_installed(self, 'php7.4-fpm') or
WOAptGet.is_installed(self, 'php8.0-fpm') or
2022-12-10 10:37:20 -03:00
WOAptGet.is_installed(self, 'php8.1-fpm') or
2023-11-24 00:11:57 +01:00
WOAptGet.is_installed(self, 'php8.2-fpm') or
WOAptGet.is_installed(self, 'php8.3-fpm')):
2023-08-05 11:41:46 +02:00
pargs.php = True
2018-11-13 21:55:59 +01:00
Log.debug(self, "Setting packages variable for utils")
2019-10-18 15:28:58 +02:00
packages = packages + [[
"https://raw.githubusercontent.com"
"/rtCamp/eeadmin/master/cache/nginx/"
"clean.php",
2019-11-05 16:11:43 +01:00
"{0}22222/htdocs/cache/nginx/clean.php"
2019-10-18 15:28:58 +02:00
.format(WOVar.wo_webroot),
"clean.php"],
["https://raw.github.com/rlerdorf/"
"opcache-status/master/opcache.php",
2019-11-05 16:11:43 +01:00
"{0}22222/htdocs/cache/opcache/opcache.php"
2019-10-18 15:28:58 +02:00
.format(WOVar.wo_webroot),
"opcache.php"],
["https://raw.github.com/amnuts/"
"opcache-gui/master/index.php",
2019-11-05 16:11:43 +01:00
"{0}22222/htdocs/cache/opcache/opgui.php"
2019-10-18 15:28:58 +02:00
.format(WOVar.wo_webroot),
"Opgui"],
["https://raw.githubusercontent.com/"
"mlazarov/ocp/master/ocp.php",
2019-11-05 16:11:43 +01:00
"{0}22222/htdocs/cache/opcache/ocp.php"
2019-10-18 15:28:58 +02:00
.format(WOVar.wo_webroot),
"OCP.php"],
["https://github.com/jokkedk/webgrind/"
"archive/master.tar.gz",
'/var/lib/wo/tmp/webgrind.tar.gz',
'Webgrind'],
["https://www.percona.com/"
"get/pt-query-digest",
"/usr/bin/pt-query-advisor",
2023-09-19 18:30:29 +02:00
"pt-query-advisor"]]
2019-08-29 20:32:45 +02:00
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-08-29 18:45:37 +02:00
if (apt_packages) or (packages):
2019-10-23 01:59:10 +02:00
pre_stack(self)
2019-08-29 18:45:37 +02:00
if (apt_packages):
Log.debug(self, "Calling pre_pref")
pre_pref(self, apt_packages)
# meminfo = (os.popen('/bin/cat /proc/meminfo '
# '| grep MemTotal').read()).split(":")
# memsplit = re.split(" kB", meminfo[1])
# wo_mem = int(memsplit[0])
# if (wo_mem < 4000000):
# WOSwap.add(self)
2019-09-04 04:21:07 +02:00
Log.wait(self, "Updating apt-cache ")
2019-08-29 18:45:37 +02:00
WOAptGet.update(self)
2019-09-04 04:21:07 +02:00
Log.valide(self, "Updating apt-cache ")
2019-09-04 19:27:38 +02:00
Log.wait(self, "Installing APT packages ")
2019-08-29 18:45:37 +02:00
WOAptGet.install(self, apt_packages)
2019-09-04 04:21:07 +02:00
Log.valide(self, "Installing APT packages ")
2019-09-06 14:27:45 +02:00
post_pref(self, apt_packages, [])
2019-08-29 18:45:37 +02:00
if (packages):
2019-08-31 16:46:27 +02:00
Log.debug(self, "Downloading following: {0}".format(packages))
2019-08-29 18:45:37 +02:00
WODownload.download(self, packages)
Log.debug(self, "Calling post_pref")
2019-09-21 19:08:53 +02:00
Log.wait(self, "Configuring packages")
2019-09-06 14:27:45 +02:00
post_pref(self, [], packages)
2019-09-21 19:08:53 +02:00
Log.valide(self, "Configuring packages")
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
return 0
2018-11-13 21:55:59 +01:00
@expose(help="Remove packages")
def remove(self):
"""Start removal of packages"""
apt_packages = []
packages = []
2019-08-07 03:05:32 +02:00
pargs = self.app.pargs
2023-08-12 16:12:06 +02:00
if all(value is None or value is False for value in vars(pargs).values()):
2019-11-05 20:25:44 +01:00
self.app.args.print_help()
2019-08-07 03:05:32 +02:00
if pargs.php:
2023-08-05 11:41:46 +02:00
if self.app.config.has_section('php'):
config_php_ver = self.app.config.get(
'php', 'version')
current_php = config_php_ver.replace(".", "")
setattr(self.app.pargs, 'php{0}'.format(current_php), True)
2020-10-28 12:25:09 +01:00
if pargs.mariadb:
pargs.mysql = True
2019-08-07 03:05:32 +02:00
if pargs.all:
pargs.web = True
pargs.admin = True
pargs.php73 = True
pargs.php74 = True
2023-08-05 11:41:46 +02:00
pargs.php80 = True
pargs.php81 = True
pargs.php82 = True
2023-11-23 21:33:09 +01:00
pargs.php83 = True
2019-08-16 22:44:47 +02:00
pargs.fail2ban = True
pargs.proftpd = True
pargs.utils = True
pargs.redis = True
pargs.security = True
2019-10-31 15:42:42 +01:00
pargs.nanorc = True
2019-09-04 19:10:18 +02:00
packages = packages + ['/var/www/22222/htdocs']
2019-08-07 03:05:32 +02:00
if pargs.web:
pargs.nginx = True
2023-08-05 11:41:46 +02:00
pargs.php = True
2019-08-07 03:05:32 +02:00
pargs.mysql = True
pargs.wpcli = True
2019-09-01 22:02:00 +02:00
pargs.sendmail = True
2019-08-07 03:05:32 +02:00
if pargs.admin:
pargs.composer = True
pargs.utils = True
pargs.netdata = True
2019-08-16 22:44:47 +02:00
pargs.mysqltuner = True
2019-10-28 20:07:38 +01:00
pargs.cheat = True
2018-11-13 21:55:59 +01:00
2019-08-07 03:05:32 +02:00
if pargs.security:
pargs.fail2ban = True
2019-08-29 20:32:45 +02:00
pargs.clamav = True
2019-09-20 14:21:42 +02:00
pargs.ufw = True
2019-10-16 13:09:06 +02:00
pargs.ngxblocker = True
2019-03-15 16:45:10 +01:00
# NGINX
2019-08-07 03:05:32 +02:00
if pargs.nginx:
2018-11-13 21:55:59 +01:00
if WOAptGet.is_installed(self, 'nginx-custom'):
Log.debug(self, "Removing apt_packages variable of Nginx")
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_nginx
2019-08-16 22:44:47 +02:00
2023-08-05 15:30:45 +02:00
# Create a dictionary that maps PHP versions to corresponding variables.
wo_vars = {
'php74': WOVar.wo_php74,
'php80': WOVar.wo_php80,
'php81': WOVar.wo_php81,
'php82': WOVar.wo_php82,
2023-11-23 21:33:09 +01:00
'php83': WOVar.wo_php83,
2023-08-05 15:30:45 +02:00
}
# Loop through all versions.
2023-08-05 15:47:01 +02:00
for parg_version, version in WOVar.wo_php_versions.items():
2023-08-05 15:30:45 +02:00
# Check if this version is present in pargs.
if getattr(pargs, parg_version):
Log.debug(self, f"Setting apt_packages variable for PHP {version}")
if WOAptGet.is_installed(self, f'php{version}-fpm'):
apt_packages += wo_vars[parg_version]
# Check if other versions are installed.
if not any(WOAptGet.is_installed(self, f'php{other_version}-fpm') for
2023-08-05 15:47:01 +02:00
other_version in WOVar.wo_php_versions.values() if other_version != version):
2023-08-05 15:30:45 +02:00
apt_packages += WOVar.wo_php_extra
else:
Log.debug(self, f"PHP {version} is not installed")
Log.info(self, f"PHP {version} is not installed")
2022-12-10 10:37:20 -03:00
2019-03-15 16:45:10 +01:00
# REDIS
2019-08-07 03:05:32 +02:00
if pargs.redis:
2019-09-23 12:11:15 +02:00
if WOAptGet.is_installed(self, 'redis-server'):
Log.debug(self, "Remove apt_packages variable of Redis")
apt_packages = apt_packages + ["redis-server"]
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# MariaDB
2019-08-07 03:05:32 +02:00
if pargs.mysql:
2019-09-23 12:11:15 +02:00
if WOAptGet.is_installed(self, 'mariadb-server'):
Log.debug(self, "Removing apt_packages variable of MySQL")
apt_packages = apt_packages + WOVar.wo_mysql
2019-07-18 17:04:20 +02:00
2019-08-29 20:32:45 +02:00
# mysqlclient
if pargs.mysqlclient:
Log.debug(self, "Removing apt_packages variable "
"for MySQL Client")
if WOShellExec.cmd_exec(self, "mysqladmin ping"):
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_mysql_client
2019-08-29 20:32:45 +02:00
2019-07-18 17:04:20 +02:00
# fail2ban
2019-08-07 03:05:32 +02:00
if 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")
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_fail2ban
2019-07-19 13:47:29 +02:00
2019-08-29 20:32:45 +02:00
# ClamAV
if pargs.clamav:
Log.debug(self, "Setting apt_packages variable for ClamAV")
if WOAptGet.is_installed(self, 'clamav'):
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_clamav
2019-08-29 20:32:45 +02:00
2019-09-01 22:02:00 +02:00
# sendmail
if pargs.sendmail:
Log.debug(self, "Setting apt_packages variable for Sendmail")
if WOAptGet.is_installed(self, 'sendmail'):
apt_packages = apt_packages + ["sendmail"]
2019-07-19 13:47:29 +02:00
# proftpd
2019-08-07 03:05:32 +02:00
if pargs.proftpd:
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'proftpd-basic'):
Log.debug(self, "Remove apt_packages variable for ProFTPd")
apt_packages = apt_packages + ["proftpd-basic"]
2019-07-18 17:04:20 +02:00
# brotli
if pargs.brotli:
Log.wait(self, "Disabling Brotli")
2024-06-01 22:10:25 +02:00
WOGit.add(self, ["/etc/nginx"], msg="Commiting pending changes")
if os.path.exists('/etc/nginx/conf.d/brotli.conf'):
WOFileUtils.mvfile(self, '/etc/nginx/conf.d/brotli.conf',
'/etc/nginx/conf.d/brotli.conf.disabled')
else:
Log.failed(self, "Disabling Brotli")
Log.error(self, "Brotli is already disabled")
if os.path.exists('/etc/nginx/conf.d/gzip.conf.disabled'):
WOFileUtils.mvfile(self, '/etc/nginx/conf.d/gzip.conf.disabled',
'/etc/nginx/conf.d/gzip.conf')
if check_config(self):
Log.valide(self, "Disabling Brotli")
2024-06-01 22:10:25 +02:00
WOGit.add(self, ["/etc/nginx"], msg="Disabling Brotli")
WOService.reload_service(self, "nginx")
else:
Log.failed(self, "Disabling Brotli")
2024-06-01 22:10:25 +02:00
WOGit.rollback(self, ["/etc/nginx"])
2019-09-20 14:21:42 +02:00
# UFW
if pargs.ufw:
2019-09-23 12:11:15 +02:00
if WOAptGet.is_installed(self, 'ufw'):
Log.debug(self, "Remove apt_packages variable for UFW")
2019-11-05 17:37:42 +01:00
WOShellExec.cmd_exec(self, 'ufw disable && ufw --force reset')
# nanorc
if pargs.nanorc:
if os.path.exists('/usr/share/nano-syntax-highlighting'):
Log.debug(self, "Add nano to apt_packages list")
packages = packages + \
["/usr/share/nano-syntax-highlighting"]
2019-09-20 14:21:42 +02:00
2019-03-15 16:45:10 +01:00
# WPCLI
2019-08-07 03:05:32 +02:00
if pargs.wpcli:
2018-11-13 21:55:59 +01:00
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']
2019-08-16 22:44:47 +02:00
2019-03-15 16:45:10 +01:00
# PHPMYADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpmyadmin:
2019-09-23 12:11:15 +02:00
if os.path.isdir('{0}22222/htdocs/db/pma'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Removing package of phpMyAdmin ")
packages = packages + ['{0}22222/htdocs/db/pma'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)]
# Composer
2019-08-07 03:05:32 +02:00
if pargs.composer:
2019-08-16 22:44:47 +02:00
Log.debug(self, "Removing package of Composer ")
if os.path.isfile('/usr/local/bin/composer'):
packages = packages + ['/usr/local/bin/composer']
2019-08-16 22:44:47 +02:00
2019-09-23 12:11:15 +02:00
# MySQLTuner
2019-08-16 22:44:47 +02:00
if pargs.mysqltuner:
2019-09-23 12:24:10 +02:00
if os.path.isfile('/usr/bin/mysqltuner'):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Removing packages for MySQLTuner ")
packages = packages + ['/usr/bin/mysqltuner']
2019-10-28 20:07:38 +01:00
# cheat.sh
if pargs.cheat:
if os.path.isfile('/usr/local/bin/cht.sh'):
Log.debug(self, "Removing packages for cheat.sh ")
packages = packages + [
'/usr/local/bin/cht.sh', '/usr/local/bin/cheat',
'/etc/bash_completion.d/cht.sh']
2019-03-15 16:45:10 +01:00
# PHPREDISADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpredisadmin:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing package variable of phpRedisAdmin ")
if os.path.isdir('{0}22222/htdocs/cache/redis'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)):
packages = packages + ['{0}22222/htdocs/'
2019-08-29 23:04:46 +02:00
'cache/redis'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)]
2019-03-15 16:45:10 +01:00
# ADMINER
2019-08-07 03:05:32 +02:00
if pargs.adminer:
2019-09-23 12:11:15 +02:00
if os.path.isdir('{0}22222/htdocs/db/adminer'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Removing package variable of Adminer ")
packages = packages + ['{0}22222/htdocs/db/adminer'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)]
2019-08-07 03:05:32 +02:00
if pargs.utils:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing package variable of utils ")
packages = packages + ['{0}22222/htdocs/php/webgrind/'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot),
2018-11-13 21:55:59 +01:00
'{0}22222/htdocs/cache/opcache'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot),
2018-11-13 21:55:59 +01:00
'{0}22222/htdocs/cache/nginx/'
2019-10-02 13:13:32 +02:00
'clean.php'.format(WOVar.wo_webroot),
2018-11-13 21:55:59 +01:00
'/usr/bin/pt-query-advisor',
'{0}22222/htdocs/db/anemometer'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)]
2018-11-13 21:55:59 +01:00
2019-10-18 15:28:58 +02:00
# netdata
2019-08-07 03:05:32 +02:00
if pargs.netdata:
2019-12-09 07:28:38 +01:00
if (os.path.exists('/opt/netdata') or
os.path.exists('/etc/netdata')):
Log.debug(self, "Removing Netdata")
packages = packages + ['/var/lib/wo/tmp/kickstart.sh']
2019-10-18 15:28:58 +02:00
# wordops dashboard
2019-08-07 03:05:32 +02:00
if pargs.dashboard:
2019-09-23 12:11:15 +02:00
if (os.path.isfile('{0}22222/htdocs/index.php'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)) or
2019-09-23 12:11:15 +02:00
os.path.isfile('{0}22222/htdocs/index.html'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot))):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Removing Wo-Dashboard")
packages = packages + ['{0}22222/htdocs/assets'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot),
2019-09-23 12:11:15 +02:00
'{0}22222/htdocs/index.php'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot),
2019-09-23 12:11:15 +02:00
'{0}22222/htdocs/index.html'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)]
2019-10-18 15:28:58 +02:00
# ngxblocker
if pargs.ngxblocker:
if os.path.isfile('/usr/local/sbin/setup-ngxblocker'):
packages = packages + [
'/usr/local/sbin/setup-ngxblocker',
'/usr/local/sbin/install-ngxblocker',
'/usr/local/sbin/update-ngxblocker',
'/etc/nginx/conf.d/globalblacklist.conf',
'/etc/nginx/conf.d/botblocker-nginx-settings.conf',
'/etc/nginx/bots.d']
2019-04-30 18:50:30 +02:00
if (packages) or (apt_packages):
2019-08-29 15:35:03 +02:00
if (not pargs.force):
start_remove = input('Are you sure you to want to'
' remove from server.'
'\nPackage configuration will remain'
' on server after this operation.\n'
2019-08-29 23:04:46 +02:00
'Remove stacks [y/N]?')
2019-08-29 15:35:03 +02:00
if start_remove != "Y" and start_remove != "y":
Log.error(self, "Not starting stack removal")
2019-08-29 23:45:36 +02:00
2019-09-23 12:11:15 +02:00
if 'nginx-custom' in apt_packages:
2019-08-16 23:46:44 +02:00
WOService.stop_service(self, 'nginx')
2018-11-13 21:55:59 +01:00
2019-09-23 12:11:15 +02:00
if 'mariadb-server' in apt_packages:
WOMysql.backupAll(self)
WOService.stop_service(self, 'mysql')
2019-08-16 23:46:44 +02:00
# Netdata uninstaller
2019-12-09 07:28:38 +01:00
if '/var/lib/wo/tmp/kickstart.sh' in packages:
if os.path.exists(
'/usr/libexec/netdata/netdata-uninstaller.sh'):
Log.debug(self, "Uninstalling Netdata from /etc/netdata")
2019-10-18 15:28:58 +02:00
WOShellExec.cmd_exec(
2019-12-09 07:28:38 +01:00
self, "bash /usr/libexec/netdata/netdata-"
"uninstaller.sh -y -f",
2019-11-05 16:11:43 +01:00
errormsg='', log=False)
2019-12-09 07:28:38 +01:00
packages = packages + ["/etc/netdata"]
elif os.path.exists(
'/opt/netdata/usr/libexec/'
'netdata/netdata-uninstaller.sh'):
Log.debug(self, "Uninstalling Netdata from /opt/netdata")
2019-10-18 15:28:58 +02:00
WOShellExec.cmd_exec(
2019-12-09 07:28:38 +01:00
self, "bash /opt/netdata/usr/libexec/netdata/netdata-"
"uninstaller.sh -y -f")
packages = packages + ["/opt/netdata"]
else:
Log.debug(self, "Netdata uninstaller not found")
if WOShellExec.cmd_exec(self, 'mysqladmin ping'):
WOMysql.execute(
self, "DELETE FROM mysql.user WHERE User = 'netdata';")
2018-11-13 21:55:59 +01:00
2019-08-16 23:46:44 +02:00
if (packages):
2019-09-04 19:27:38 +02:00
Log.wait(self, "Removing packages ")
2019-08-16 23:46:44 +02:00
WOFileUtils.remove(self, packages)
2019-09-04 19:27:38 +02:00
Log.valide(self, "Removing packages ")
2019-11-05 17:37:42 +01:00
if '/usr/share/nano-syntax-highlighting' in packages:
# removing include line from nanorc
WOShellExec.cmd_exec(
self, 'grep -v "nano-syntax-highlighting" '
'/etc/nanorc > /etc/nanorc.new')
WOFileUtils.rm(self, '/etc/nanorc')
WOFileUtils.mvfile(
self, '/etc/nanorc.new', '/etc/nanorc')
2019-08-16 23:46:44 +02:00
if (apt_packages):
Log.debug(self, "Removing apt_packages")
2019-09-04 04:21:07 +02:00
Log.wait(self, "Removing APT packages ")
2019-08-16 23:46:44 +02:00
WOAptGet.remove(self, apt_packages)
WOAptGet.auto_remove(self)
2019-09-04 04:21:07 +02:00
Log.valide(self, "Removing APT packages ")
2018-11-13 21:55:59 +01:00
2019-08-16 23:46:44 +02:00
Log.info(self, "Successfully removed packages")
2018-11-13 21:55:59 +01:00
@expose(help="Purge packages")
def purge(self):
"""Start purging of packages"""
apt_packages = []
packages = []
2019-08-07 03:05:32 +02:00
pargs = self.app.pargs
2018-11-13 21:55:59 +01:00
# Default action for stack purge
2023-08-12 16:12:06 +02:00
if all(value is None or value is False for value in vars(pargs).values()):
2019-11-05 20:25:44 +01:00
self.app.args.print_help()
2019-08-07 03:05:32 +02:00
if pargs.php:
2023-08-05 11:41:46 +02:00
if self.app.config.has_section('php'):
config_php_ver = self.app.config.get(
'php', 'version')
current_php = config_php_ver.replace(".", "")
setattr(self.app.pargs, 'php{0}'.format(current_php), True)
2020-10-28 12:25:09 +01:00
if pargs.mariadb:
pargs.mysql = True
2019-08-07 03:05:32 +02:00
if pargs.all:
pargs.web = True
pargs.admin = True
pargs.php74 = True
2022-01-23 15:14:24 -03:00
pargs.php80 = True
pargs.php81 = True
2022-12-10 10:37:20 -03:00
pargs.php82 = True
2023-11-23 21:33:09 +01:00
pargs.php83 = True
2019-08-16 22:44:47 +02:00
pargs.fail2ban = True
pargs.proftpd = True
pargs.utils = True
pargs.redis = True
2019-09-04 19:10:18 +02:00
packages = packages + ['/var/www/22222/htdocs']
2019-08-07 03:05:32 +02:00
if pargs.web:
pargs.nginx = True
2023-08-05 11:41:46 +02:00
pargs.php = True
2019-08-07 03:05:32 +02:00
pargs.mysql = True
pargs.wpcli = True
2019-09-01 22:02:00 +02:00
pargs.sendmail = True
2019-08-07 03:05:32 +02:00
if pargs.admin:
pargs.utils = True
pargs.composer = True
pargs.netdata = True
2019-08-16 22:44:47 +02:00
pargs.mysqltuner = True
2019-10-28 20:07:38 +01:00
pargs.cheat = True
packages = packages + ['/var/www/22222/htdocs']
2019-08-07 03:05:32 +02:00
if pargs.security:
pargs.fail2ban = True
2019-08-29 20:32:45 +02:00
pargs.clamav = True
2019-09-20 14:21:42 +02:00
pargs.ufw = True
2019-10-16 13:09:06 +02:00
pargs.ngxblocker = True
2019-08-29 20:32:45 +02:00
2019-03-15 16:45:10 +01:00
# NGINX
2019-08-07 03:05:32 +02:00
if pargs.nginx:
2018-11-13 21:55:59 +01:00
if WOAptGet.is_installed(self, 'nginx-custom'):
2019-09-21 01:08:51 +02:00
Log.debug(self, "Add Nginx to apt_packages list")
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_nginx
2019-09-21 16:42:49 +02:00
else:
Log.info(self, "Nginx is not installed")
2019-03-15 16:45:10 +01:00
2023-11-23 21:33:09 +01:00
wo_vars = {
'php74': WOVar.wo_php74,
'php80': WOVar.wo_php80,
'php81': WOVar.wo_php81,
'php82': WOVar.wo_php82,
'php83': WOVar.wo_php83,
}
2022-12-10 10:37:20 -03:00
2023-11-23 21:33:09 +01:00
for parg_version, version in WOVar.wo_php_versions.items():
if getattr(pargs, parg_version, False):
Log.debug(self, f"Setting apt_packages variable for PHP {version}")
if not WOAptGet.is_installed(self, f'php{version}-fpm'):
apt_packages = apt_packages + wo_vars[parg_version]
else:
Log.debug(self, f"PHP {version} already purged")
Log.info(self, f"PHP {version} already purged")
2022-12-10 10:37:20 -03:00
2019-08-29 23:04:46 +02:00
# REDIS
if pargs.redis:
2019-09-21 01:08:51 +02:00
if WOAptGet.is_installed(self, 'redis-server'):
Log.debug(self, "Remove apt_packages variable of Redis")
apt_packages = apt_packages + ["redis-server"]
2019-09-21 16:42:49 +02:00
else:
Log.info(self, "Redis is not installed")
2019-08-29 23:04:46 +02:00
# MariaDB
if pargs.mysql:
2019-09-21 01:08:51 +02:00
if WOAptGet.is_installed(self, 'mariadb-server'):
2019-09-21 16:42:49 +02:00
Log.debug(self, "Add MySQL to apt_packages list")
2019-09-21 01:08:51 +02:00
apt_packages = apt_packages + ['mariadb-server',
'mysql-common',
'mariadb-client']
packages = packages + ['/etc/mysql', '/var/lib/mysql']
2019-09-21 16:42:49 +02:00
else:
Log.info(self, "MariaDB is not installed")
2019-08-29 23:04:46 +02:00
2019-08-29 20:32:45 +02:00
# mysqlclient
if pargs.mysqlclient:
if WOShellExec.cmd_exec(self, "mysqladmin ping"):
2019-09-21 01:08:51 +02:00
Log.debug(self, "Add MySQL client to apt_packages list")
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_mysql_client
2019-08-29 20:32:45 +02:00
2019-07-18 17:04:20 +02:00
# fail2ban
2019-08-07 03:05:32 +02:00
if pargs.fail2ban:
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'fail2ban'):
2019-09-21 01:08:51 +02:00
Log.debug(self, "Add Fail2ban to apt_packages list")
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_fail2ban
2019-07-19 13:47:29 +02:00
2019-08-29 20:32:45 +02:00
# ClamAV
if pargs.clamav:
if WOAptGet.is_installed(self, 'clamav'):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Add ClamAV to apt_packages list")
2019-10-02 13:13:32 +02:00
apt_packages = apt_packages + WOVar.wo_clamav
2019-08-29 20:32:45 +02:00
2019-09-20 14:21:42 +02:00
# UFW
if pargs.ufw:
2019-09-21 01:08:51 +02:00
if WOAptGet.is_installed(self, 'ufw'):
Log.debug(self, "Add UFW to apt_packages list")
2019-11-05 17:37:42 +01:00
WOShellExec.cmd_exec(self, 'ufw disable && ufw --force reset')
2019-09-20 14:21:42 +02:00
2019-09-01 22:02:00 +02:00
# sendmail
if pargs.sendmail:
if WOAptGet.is_installed(self, 'sendmail'):
2019-09-21 01:08:51 +02:00
Log.debug(self, "Add sendmail to apt_packages list")
2019-09-01 22:02:00 +02:00
apt_packages = apt_packages + ["sendmail"]
2019-07-19 13:47:29 +02:00
# proftpd
2019-08-07 03:05:32 +02:00
if pargs.proftpd:
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'proftpd-basic'):
2019-09-21 01:08:51 +02:00
Log.debug(self, "Add Proftpd to apt_packages list")
2019-07-19 13:47:29 +02:00
apt_packages = apt_packages + ["proftpd-basic"]
2019-07-18 17:04:20 +02:00
2019-11-05 17:37:42 +01:00
# nanorc
if pargs.nanorc:
if os.path.exists('/usr/share/nano-syntax-highlighting'):
Log.debug(self, "Add nano to apt_packages list")
packages = packages + \
["/usr/share/nano-syntax-highlighting"]
2019-03-15 16:45:10 +01:00
# WP-CLI
2019-08-07 03:05:32 +02:00
if pargs.wpcli:
2019-03-04 07:12:57 +01:00
if os.path.isfile('/usr/local/bin/wp'):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Purge package variable WPCLI")
2019-03-04 07:12:57 +01:00
packages = packages + ['/usr/local/bin/wp']
2019-03-15 16:45:10 +01:00
# PHPMYADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpmyadmin:
2019-09-23 12:11:15 +02:00
if os.path.isdir('{0}22222/htdocs/db/pma'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Removing package of phpMyAdmin ")
packages = packages + ['{0}22222/htdocs/db/pma'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)]
2019-03-15 16:45:10 +01:00
# Composer
2019-08-07 03:05:32 +02:00
if pargs.composer:
if os.path.isfile('/usr/local/bin/composer'):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Removing package variable of Composer ")
packages = packages + ['/usr/local/bin/composer']
2019-08-16 22:44:47 +02:00
2019-09-23 12:11:15 +02:00
# MySQLTuner
2019-08-16 22:44:47 +02:00
if pargs.mysqltuner:
2019-09-23 12:24:10 +02:00
if os.path.isfile('/usr/bin/mysqltuner'):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Removing packages for MySQLTuner ")
packages = packages + ['/usr/bin/mysqltuner']
2019-10-28 20:07:38 +01:00
# cheat.sh
if pargs.cheat:
if os.path.isfile('/usr/local/bin/cht.sh'):
Log.debug(self, "Removing packages for cheat.sh ")
packages = packages + [
'/usr/local/bin/cht.sh', '/usr/local/bin/cheat',
'/etc/bash_completion.d/cht.sh']
2019-03-15 16:45:10 +01:00
# PHPREDISADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpredisadmin:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing package variable of phpRedisAdmin ")
if os.path.isdir('{0}22222/htdocs/cache/redis'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)):
packages = packages + ['{0}22222/htdocs/'
2019-08-29 23:04:46 +02:00
'cache/redis'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)]
2019-09-23 12:11:15 +02:00
# ADMINER
2019-08-07 03:05:32 +02:00
if pargs.adminer:
2019-09-23 12:11:15 +02:00
if os.path.isdir('{0}22222/htdocs/db/adminer'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)):
2019-09-23 12:11:15 +02:00
Log.debug(self, "Removing package variable of Adminer ")
packages = packages + ['{0}22222/htdocs/db/adminer'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)]
2019-03-15 16:45:10 +01:00
# utils
2019-08-07 03:05:32 +02:00
if pargs.utils:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Purge package variable utils")
2019-08-29 23:37:23 +02:00
packages = packages + ['{0}22222/htdocs/php/webgrind/'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot),
2019-08-29 23:37:23 +02:00
'{0}22222/htdocs/cache/opcache'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot),
2019-08-29 23:37:23 +02:00
'{0}22222/htdocs/cache/nginx/'
2019-10-02 13:13:32 +02:00
'clean.php'.format(WOVar.wo_webroot),
2019-08-29 23:37:23 +02:00
'/usr/bin/pt-query-advisor',
'{0}22222/htdocs/db/anemometer'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)
2019-08-29 23:37:23 +02:00
]
2019-12-09 07:28:38 +01:00
# netdata
2019-08-07 03:05:32 +02:00
if pargs.netdata:
2019-12-09 07:28:38 +01:00
if (os.path.exists('/opt/netdata') or
os.path.exists('/etc/netdata')):
Log.debug(self, "Removing Netdata")
packages = packages + ['/var/lib/wo/tmp/kickstart.sh']
2019-10-18 15:28:58 +02:00
# wordops dashboard
2019-08-07 03:05:32 +02:00
if pargs.dashboard:
Log.debug(self, "Removing Wo-Dashboard")
packages = packages + ['{0}22222/htdocs/assets/'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot),
'{0}22222/htdocs/index.php'
2019-10-02 13:13:32 +02:00
.format(WOVar.wo_webroot)]
2019-10-18 15:28:58 +02:00
# ngxblocker
if pargs.ngxblocker:
if os.path.isfile('/usr/local/sbin/setup-ngxblocker'):
packages = packages + [
'/usr/local/sbin/setup-ngxblocker',
'/usr/local/sbin/install-ngxblocker',
'/usr/local/sbin/update-ngxblocker',
'/etc/nginx/conf.d/globalblacklist.conf',
'/etc/nginx/conf.d/botblocker-nginx-settings.conf',
'/etc/nginx/bots.d']
2019-04-30 18:50:30 +02:00
if (packages) or (apt_packages):
2019-08-29 15:35:03 +02:00
if (not pargs.force):
start_purge = input('Are you sure you to want to'
' purge stacks from this server ?'
'\nPackage configuration and data '
'will not remain'
' on this server after this operation.\n'
'Purge stacks [y/N]')
if start_purge != "Y" and start_purge != "y":
Log.error(self, "Not starting stack purge")
2019-08-16 23:26:23 +02:00
if "nginx-custom" in apt_packages:
2019-08-16 23:46:44 +02:00
WOService.stop_service(self, 'nginx')
2018-11-13 21:55:59 +01:00
if "fail2ban" in apt_packages:
2019-08-29 23:37:23 +02:00
WOService.stop_service(self, 'fail2ban')
if "mariadb-server" in apt_packages:
if self.app.config.has_section('mysql'):
if self.app.config.get(
'mysql', 'grant-host') == 'localhost':
WOMysql.backupAll(self)
2020-01-07 16:18:17 +01:00
WOService.stop_service(self, 'mysql')
2019-08-16 23:46:44 +02:00
# Netdata uninstaller
2019-12-09 07:28:38 +01:00
if '/var/lib/wo/tmp/kickstart.sh' in packages:
if os.path.exists(
'/usr/libexec/netdata/netdata-uninstaller.sh'):
Log.debug(self, "Uninstalling Netdata from /etc/netdata")
WOShellExec.cmd_exec(
self, "bash /usr/libexec/netdata/netdata-"
"uninstaller.sh -y -f",
errormsg='', log=False)
packages = packages + ["/etc/netdata"]
elif os.path.exists(
'/opt/netdata/usr/libexec/'
'netdata/netdata-uninstaller.sh'):
Log.debug(self, "Uninstalling Netdata from /opt/netdata")
WOShellExec.cmd_exec(
self, "bash /opt/netdata/usr/libexec/netdata/netdata-"
"uninstaller.sh -y -f")
packages = packages + ["/opt/netdata"]
2019-08-29 23:37:23 +02:00
else:
2019-12-09 07:28:38 +01:00
Log.debug(self, "Netdata uninstaller not found")
if WOShellExec.cmd_exec(self, 'mysqladmin ping'):
WOMysql.execute(
self, "DELETE FROM mysql.user WHERE User = 'netdata';")
2019-08-16 23:46:44 +02:00
if (apt_packages):
2019-09-04 04:21:07 +02:00
Log.wait(self, "Purging APT Packages ")
2019-08-16 23:46:44 +02:00
WOAptGet.remove(self, apt_packages, purge=True)
WOAptGet.auto_remove(self)
2019-09-04 04:21:07 +02:00
Log.valide(self, "Purging APT Packages ")
2019-08-16 23:46:44 +02:00
if (packages):
2019-09-04 19:27:38 +02:00
Log.wait(self, "Purging Packages ")
2019-08-16 23:46:44 +02:00
WOFileUtils.remove(self, packages)
2019-09-04 19:27:38 +02:00
Log.valide(self, "Purging Packages ")
2019-11-05 17:37:42 +01:00
if '/usr/share/nano-syntax-highlighting' in packages:
# removing include line from nanorc
WOShellExec.cmd_exec(
self, 'grep -v "nano-syntax-highlighting" '
'/etc/nanorc > /etc/nanorc.new')
WOFileUtils.rm(self, '/etc/nanorc')
WOFileUtils.mvfile(
self, '/etc/nanorc.new', '/etc/nanorc')
2019-08-16 23:46:44 +02:00
Log.info(self, "Successfully purged packages")
2018-11-13 21:55:59 +01:00
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
2019-09-23 23:55:04 +02:00
app.handler.register(WOStackController)
2019-09-24 00:01:20 +02:00
app.handler.register(WOStackStatusController)
app.handler.register(WOStackMigrateController)
app.handler.register(WOStackUpgradeController)
2018-11-13 21:55:59 +01:00
# register a hook (function) to run after arguments are parsed.
2019-09-24 00:04:32 +02:00
app.hook.register('post_argument_parsing', wo_stack_hook)