2019-08-16 23:26:23 +02:00
|
|
|
"""WordOps core variable module"""
|
|
|
|
|
import configparser
|
2019-09-04 20:36:15 +02:00
|
|
|
import os
|
2019-10-02 13:13:32 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
from re import match
|
|
|
|
|
from socket import getfqdn
|
2019-10-23 12:24:30 +02:00
|
|
|
from shutil import copy2
|
2019-09-04 20:36:15 +02:00
|
|
|
|
2019-10-02 13:13:32 +02:00
|
|
|
from distro import linux_distribution
|
|
|
|
|
from sh import git
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
|
2019-10-02 13:13:32 +02:00
|
|
|
class WOVar():
|
2019-08-16 23:26:23 +02:00
|
|
|
"""Intialization of core variables"""
|
|
|
|
|
|
|
|
|
|
# WordOps version
|
2019-11-11 19:06:11 +01:00
|
|
|
wo_version = "3.10.3"
|
2019-08-16 23:26:23 +02:00
|
|
|
# WordOps packages versions
|
2019-09-17 01:30:58 +02:00
|
|
|
wo_wp_cli = "2.3.0"
|
2019-09-26 15:45:38 +02:00
|
|
|
wo_adminer = "4.7.3"
|
2019-09-23 12:24:10 +02:00
|
|
|
wo_phpmyadmin = "4.9.1"
|
2019-08-16 23:26:23 +02:00
|
|
|
wo_extplorer = "2.1.13"
|
2019-09-22 14:11:12 +02:00
|
|
|
wo_dashboard = "1.2"
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
# Get WPCLI path
|
|
|
|
|
wo_wpcli_path = '/usr/local/bin/wp'
|
|
|
|
|
|
|
|
|
|
# Current date and time of System
|
2019-10-02 13:13:32 +02:00
|
|
|
wo_date = datetime.now().strftime('%d%b%Y-%H-%M-%S')
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
# WordOps core variables
|
2019-10-23 12:24:30 +02:00
|
|
|
# linux distribution
|
2019-10-02 13:13:32 +02:00
|
|
|
wo_distro = linux_distribution(
|
2019-08-19 12:22:16 +02:00
|
|
|
full_distribution_name=False)[0].lower()
|
2019-10-02 13:13:32 +02:00
|
|
|
wo_platform_version = linux_distribution(
|
2019-08-19 12:22:16 +02:00
|
|
|
full_distribution_name=False)[1].lower()
|
2019-10-23 12:24:30 +02:00
|
|
|
# distro codename (bionic, xenial, stretch ...)
|
2019-10-02 13:13:32 +02:00
|
|
|
wo_platform_codename = linux_distribution(
|
2019-08-19 12:22:16 +02:00
|
|
|
full_distribution_name=False)[2].lower()
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
# Get timezone of system
|
|
|
|
|
if os.path.isfile('/etc/timezone'):
|
2019-10-23 12:24:30 +02:00
|
|
|
with open("/etc/timezone", mode='r', encoding='utf-8') as tzfile:
|
2019-08-16 23:26:23 +02:00
|
|
|
wo_timezone = tzfile.read().replace('\n', '')
|
|
|
|
|
if wo_timezone == "Etc/UTC":
|
|
|
|
|
wo_timezone = "UTC"
|
|
|
|
|
else:
|
|
|
|
|
wo_timezone = "Europe/Amsterdam"
|
|
|
|
|
|
|
|
|
|
# Get FQDN of system
|
2019-10-02 13:13:32 +02:00
|
|
|
wo_fqdn = getfqdn()
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
# WordOps default webroot path
|
|
|
|
|
wo_webroot = '/var/www/'
|
|
|
|
|
|
|
|
|
|
# WordOps default renewal SSL certificates path
|
|
|
|
|
wo_ssl_archive = '/etc/letsencrypt/renewal'
|
|
|
|
|
|
|
|
|
|
# WordOps default live SSL certificates path
|
|
|
|
|
wo_ssl_live = '/etc/letsencrypt/live'
|
|
|
|
|
|
|
|
|
|
# PHP user
|
|
|
|
|
wo_php_user = 'www-data'
|
|
|
|
|
|
2019-10-23 12:24:30 +02:00
|
|
|
# WordOps git configuration management
|
2019-08-16 23:26:23 +02:00
|
|
|
config = configparser.ConfigParser()
|
2019-10-30 04:23:20 +01:00
|
|
|
config.read(os.path.expanduser("~") + '/.gitconfig')
|
2019-08-16 23:26:23 +02:00
|
|
|
try:
|
|
|
|
|
wo_user = config['user']['name']
|
|
|
|
|
wo_email = config['user']['email']
|
|
|
|
|
except Exception:
|
2019-10-02 13:13:32 +02:00
|
|
|
print("WordOps (wo) require an username & and an email "
|
|
|
|
|
"address to configure Git (used to save server configurations)")
|
|
|
|
|
print("Your informations will ONLY be stored locally")
|
|
|
|
|
|
2019-08-16 23:26:23 +02:00
|
|
|
wo_user = input("Enter your name: ")
|
2019-10-02 13:13:32 +02:00
|
|
|
while wo_user == "":
|
|
|
|
|
print("Unfortunately, this can't be left blank")
|
|
|
|
|
wo_user = input("Enter your name: ")
|
|
|
|
|
|
2019-08-16 23:26:23 +02:00
|
|
|
wo_email = input("Enter your email: ")
|
2019-10-02 13:13:32 +02:00
|
|
|
|
|
|
|
|
while not match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
|
|
|
|
|
wo_email):
|
|
|
|
|
print("Whoops, seems like you made a typo - "
|
|
|
|
|
"the e-mailaddress is invalid...")
|
|
|
|
|
wo_email = input("Enter your email: ")
|
|
|
|
|
|
|
|
|
|
git.config("--global", "user.name", "{0}".format(wo_user))
|
|
|
|
|
git.config("--global", "user.email", "{0}".format(wo_email))
|
2019-08-16 23:26:23 +02:00
|
|
|
|
2019-10-23 12:24:30 +02:00
|
|
|
if not os.path.isfile('/root/.gitconfig'):
|
2019-10-30 04:23:20 +01:00
|
|
|
copy2(os.path.expanduser("~") + '/.gitconfig', '/root/.gitconfig')
|
2019-10-23 12:24:30 +02:00
|
|
|
|
2019-08-16 23:26:23 +02:00
|
|
|
# MySQL hostname
|
|
|
|
|
wo_mysql_host = ""
|
|
|
|
|
config = configparser.RawConfigParser()
|
|
|
|
|
if os.path.exists('/etc/mysql/conf.d/my.cnf'):
|
|
|
|
|
cnfpath = "/etc/mysql/conf.d/my.cnf"
|
|
|
|
|
else:
|
2019-10-30 04:23:20 +01:00
|
|
|
cnfpath = os.path.expanduser("~") + "/.my.cnf"
|
2019-08-16 23:26:23 +02:00
|
|
|
if [cnfpath] == config.read(cnfpath):
|
|
|
|
|
try:
|
|
|
|
|
wo_mysql_host = config.get('client', 'host')
|
|
|
|
|
except configparser.NoOptionError:
|
|
|
|
|
wo_mysql_host = "localhost"
|
|
|
|
|
else:
|
|
|
|
|
wo_mysql_host = "localhost"
|
|
|
|
|
|
|
|
|
|
# WordOps stack installation variables
|
|
|
|
|
# Nginx repo and packages
|
|
|
|
|
if wo_distro == 'ubuntu':
|
|
|
|
|
wo_nginx_repo = "ppa:wordops/nginx-wo"
|
2019-08-27 22:21:22 +02:00
|
|
|
else:
|
|
|
|
|
if wo_distro == 'debian':
|
|
|
|
|
if wo_platform_codename == 'jessie':
|
|
|
|
|
wo_deb_repo = "Debian_8.0"
|
|
|
|
|
elif wo_platform_codename == 'stretch':
|
|
|
|
|
wo_deb_repo = "Debian_9.0"
|
|
|
|
|
elif wo_platform_codename == 'buster':
|
|
|
|
|
wo_deb_repo = "Debian_10"
|
|
|
|
|
elif wo_distro == 'raspbian':
|
|
|
|
|
if wo_platform_codename == 'stretch':
|
|
|
|
|
wo_deb_repo = "Raspbian_9.0"
|
|
|
|
|
elif wo_platform_codename == 'buster':
|
|
|
|
|
wo_deb_repo = "Raspbian_10"
|
|
|
|
|
# debian/raspbian nginx repository
|
|
|
|
|
wo_nginx_repo = ("deb http://download.opensuse.org"
|
|
|
|
|
"/repositories/home:"
|
|
|
|
|
"/virtubox:/WordOps/{0}/ /"
|
|
|
|
|
.format(wo_deb_repo))
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
wo_nginx = ["nginx-custom", "nginx-wo"]
|
2019-09-06 12:07:34 +02:00
|
|
|
wo_nginx_key = '188C9FB063F0247A'
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
wo_php = ["php7.2-fpm", "php7.2-curl", "php7.2-gd", "php7.2-imap",
|
|
|
|
|
"php7.2-readline", "php7.2-common", "php7.2-recode",
|
2019-08-30 00:01:05 +02:00
|
|
|
"php7.2-cli", "php7.2-mbstring", "php7.2-intl",
|
2019-08-16 23:26:23 +02:00
|
|
|
"php7.2-bcmath", "php7.2-mysql", "php7.2-opcache",
|
|
|
|
|
"php7.2-zip", "php7.2-xml", "php7.2-soap"]
|
|
|
|
|
wo_php73 = ["php7.3-fpm", "php7.3-curl", "php7.3-gd", "php7.3-imap",
|
|
|
|
|
"php7.3-readline", "php7.3-common", "php7.3-recode",
|
2019-08-30 00:01:05 +02:00
|
|
|
"php7.3-cli", "php7.3-mbstring", "php7.3-intl",
|
2019-08-16 23:26:23 +02:00
|
|
|
"php7.3-bcmath", "php7.3-mysql", "php7.3-opcache",
|
|
|
|
|
"php7.3-zip", "php7.3-xml", "php7.3-soap"]
|
|
|
|
|
wo_php_extra = ["php-memcached", "php-imagick",
|
|
|
|
|
"graphviz", "php-xdebug", "php-msgpack", "php-redis"]
|
|
|
|
|
|
2019-10-12 11:07:25 +02:00
|
|
|
wo_mysql = ["mariadb-server", "percona-toolkit"]
|
|
|
|
|
if wo_distro == 'raspbian':
|
|
|
|
|
wo_mysql = wo_mysql + ["python3-mysqldb"]
|
2019-11-05 16:11:43 +01:00
|
|
|
if wo_platform_codename == 'stretch':
|
|
|
|
|
mariadb_ver = '10.1'
|
|
|
|
|
else:
|
|
|
|
|
mariadb_ver = '10.3'
|
2019-09-06 13:17:37 +02:00
|
|
|
else:
|
2019-11-05 16:11:43 +01:00
|
|
|
mariadb_ver = '10.3'
|
2019-10-12 11:07:25 +02:00
|
|
|
if wo_platform_codename == 'jessie':
|
|
|
|
|
wo_mysql = wo_mysql + ["python3-mysql.connector"]
|
|
|
|
|
else:
|
|
|
|
|
wo_mysql = wo_mysql + ["python3-mysqldb", "mariadb-backup"]
|
2019-09-06 13:17:37 +02:00
|
|
|
|
2019-10-12 11:07:25 +02:00
|
|
|
wo_mysql_client = ["mariadb-client"]
|
2019-08-30 20:33:33 +02:00
|
|
|
if wo_platform_codename == 'jessie':
|
2019-10-12 11:07:25 +02:00
|
|
|
wo_mysql_client = wo_mysql_client + ["python3-mysqldb"]
|
2019-08-30 20:33:33 +02:00
|
|
|
else:
|
2019-10-12 11:07:25 +02:00
|
|
|
wo_mysql_client = wo_mysql_client + ["python3-mysql.connector"]
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
wo_fail2ban = ["fail2ban"]
|
2019-08-31 12:18:16 +02:00
|
|
|
wo_clamav = ["clamav", "clamav-freshclam"]
|
2019-10-31 15:42:42 +01:00
|
|
|
wo_ubuntu_backports = 'ppa:jonathonf/backports'
|
2019-08-16 23:26:23 +02:00
|
|
|
|
2019-11-11 19:06:11 +01:00
|
|
|
# APT repositories
|
|
|
|
|
wo_mysql_repo = ("deb [arch=amd64,ppc64el] "
|
|
|
|
|
"http://mariadb.mirrors.ovh.net/MariaDB/repo/"
|
|
|
|
|
"10.3/{distro} {codename} main"
|
|
|
|
|
.format(distro=wo_distro,
|
|
|
|
|
codename=wo_platform_codename))
|
2019-08-16 23:26:23 +02:00
|
|
|
if wo_distro == 'ubuntu':
|
2019-09-23 12:24:10 +02:00
|
|
|
wo_php_repo = "ppa:ondrej/php"
|
2019-08-16 23:26:23 +02:00
|
|
|
wo_redis_repo = ("ppa:chris-lea/redis-server")
|
2019-09-23 12:24:10 +02:00
|
|
|
wo_goaccess_repo = ("ppa:alex-p/goaccess")
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
else:
|
2019-09-23 12:24:10 +02:00
|
|
|
wo_php_repo = (
|
|
|
|
|
"deb https://packages.sury.org/php/ {codename} main"
|
|
|
|
|
.format(codename=wo_platform_codename))
|
|
|
|
|
wo_php_key = 'AC0E47584A7A714D'
|
2019-08-16 23:26:23 +02:00
|
|
|
wo_redis_repo = ("deb https://packages.sury.org/php/ {codename} all"
|
|
|
|
|
.format(codename=wo_platform_codename))
|
|
|
|
|
|
2019-09-04 16:55:58 +02:00
|
|
|
wo_redis = ['redis-server']
|
2019-08-16 23:26:23 +02:00
|
|
|
|
|
|
|
|
# Repo path
|
|
|
|
|
wo_repo_file = "wo-repo.list"
|
|
|
|
|
wo_repo_file_path = ("/etc/apt/sources.list.d/" + wo_repo_file)
|
|
|
|
|
|
|
|
|
|
# Application dabase file path
|
|
|
|
|
basedir = os.path.abspath(os.path.dirname('/var/lib/wo/'))
|
|
|
|
|
wo_db_uri = 'sqlite:///' + os.path.join(basedir, 'dbase.db')
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pass
|