diff --git a/dockerManager/Dockerfile b/dockerManager/Dockerfile new file mode 100644 index 000000000..c61ec1dc7 --- /dev/null +++ b/dockerManager/Dockerfile @@ -0,0 +1,41 @@ +# Use Debian as the base image +FROM debian:11.0 + +# Install required dependencies +RUN apt-get update && \ + apt-get install -y wget gnupg ca-certificates + +# Install OpenLiteSpeed +RUN wget -O - http://rpms.litespeedtech.com/debian/enable_lst_debian_repo.sh | bash + +RUN apt-get install -y openlitespeed + +# Install PHP and required PHP extensions for WordPress +RUN apt-get install -y lsphp82* + +### + +RUN rm -rf /usr/local/lsws/Example/html/* + +# Install WP CLI + +RUN wget https://github.com/wp-cli/wp-cli/releases/download/v2.7.1/wp-cli-2.7.1.phar +RUN chmod +x wp-cli-2.7.1.phar +RUN mv wp-cli-2.7.1.phar /usr/bin/wp + +## set up vh conf + +RUN rm -f /usr/local/lsws/conf/vhosts/Example/vhconf.conf +COPY ./vhconf.conf /usr/local/lsws/conf/vhosts/Example/vhconf.conf + +# Expose necessary ports +EXPOSE 8088 + +# Copy entrypoint script +COPY entrypoint.sh /usr/local/bin/entrypoint.sh + +# Set execute permissions +RUN chmod +x /usr/local/bin/entrypoint.sh + +# Define entrypoint +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/dockerManager/docker-compose.yml b/dockerManager/docker-compose.yml new file mode 100644 index 000000000..697fa1f77 --- /dev/null +++ b/dockerManager/docker-compose.yml @@ -0,0 +1,29 @@ +version: '3.8' + +services: + wordpress: + image: cyberpanel/openlitespeed:latest + ports: + - "8000:8088" +# - "443:443" + environment: + DB_NAME: "wordpress" + DB_USER: "wpuser" + DB_PASSWORD: "wppassword" + WP_ADMIN_EMAIL: "admin@example.com" + WP_ADMIN_USER: "admin" + WP_ADMIN_PASSWORD: "adminpass" + WP_URL: docker.cyberpanel.net + DB_Host: mariadb:3306 + SITE_NAME: "CyberPanel Docker Site" + depends_on: + - mariadb + mariadb: + image: mariadb + restart: always + environment: + ALLOW_EMPTY_PASSWORD=no + MYSQL_DATABASE: 'wordpress' + MYSQL_USER: 'wpuser' + MYSQL_PASSWORD: 'wppassword' + MYSQL_ROOT_PASSWORD: 'rootpassword' diff --git a/dockerManager/entrypoint.sh b/dockerManager/entrypoint.sh new file mode 100644 index 000000000..d0fae37b1 --- /dev/null +++ b/dockerManager/entrypoint.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Environment variables for WordPress installation +DB_NAME=${DB_NAME:-"wordpress"} +DB_USER=${DB_USER:-"wpuser"} +DB_PASSWORD=${DB_PASSWORD:-"wppassword"} +WP_ADMIN_EMAIL=${WP_ADMIN_EMAIL:-"admin@example.com"} +WP_ADMIN_USER=${WP_ADMIN_USER:-"admin"} +WP_ADMIN_PASSWORD=${WP_ADMIN_PASSWORD:-"adminpass"} +WP_URL=${WP_URL:-"docker.cyberpanel.net"} +DB_Host=${DB_Host:-"mariadb:3306"} +SITE_NAME=${SITE_NAME:-"CyberPanel Site"} + +# Install WordPress using WP CLI +/usr/local/lsws/lsphp82/bin/php /usr/bin/wp core download --path=/usr/local/lsws/Example/html --allow-root + +# Set up WP config +/usr/local/lsws/lsphp82/bin/php /usr/bin/wp core config --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASSWORD" --path="/usr/local/lsws/Example/html" --dbhost="$DB_Host" --skip-check --allow-root + +# Install WordPress +/usr/local/lsws/lsphp82/bin/php /usr/bin/wp core install --title="$SITE_NAME" --url="$WP_URL" --title="My WordPress Site" --admin_user="$WP_ADMIN_USER" --admin_password="$WP_ADMIN_PASSWORD" --admin_email="$WP_ADMIN_EMAIL" --path="/usr/local/lsws/Example/html" --skip-email --allow-root + +### Install LSCache plugin + +/usr/local/lsws/lsphp82/bin/php /usr/bin/wp plugin install litespeed-cache --allow-root --path="/usr/local/lsws/Example/html" + +# Start OpenLiteSpeed +/usr/local/lsws/bin/lswsctrl start + +# Keep container running +tail -f /dev/null \ No newline at end of file diff --git a/dockerManager/vhconf.conf b/dockerManager/vhconf.conf new file mode 100644 index 000000000..5cb8db85b --- /dev/null +++ b/dockerManager/vhconf.conf @@ -0,0 +1,100 @@ +docRoot $VH_ROOT/html/ +enableGzip 1 + + +context / { + allowBrowse 1 + location $DOC_ROOT/ + rewrite { + RewriteFile .htaccess + } +} + +expires { + enableExpires 1 +} + +index { + indexFiles index.php + autoIndex 0 + useServer 0 +} + +errorPage 404{ + url /error404.html +} + +errorlog $VH_ROOT/logs/error.log{ + logLevel DEBUG + rollingSize 10M + useServer 1 +} + +accessLog $VH_ROOT/logs/access.log{ + compressArchive 0 + logReferer 1 + keepDays 30 + rollingSize 10M + logUserAgent 1 + useServer 0 +} + +rewrite { + enable 1 + logLevel 0 +} + +hotlinkCtrl { + suffixes gif, jpeg, jpg + allowedHosts + allowDirectAccess 1 + enableHotlinkCtrl 0 + onlySelf 1 +} + +accessControl { + deny + allow * +} + +realm SampleProtectedArea { + userDB { + cacheTimeout 60 + maxCacheSize 200 + location conf/vhosts/$VH_NAME/htpasswd + } + + groupDB { + cacheTimeout 60 + maxCacheSize 200 + location conf/vhosts/$VH_NAME/htgroup + } +} + +general { + enableContextAC 0 +} + +scripthandler { + add lsapi:cyberpanel php +} + +extprocessor cyberpanel { + type lsapi + address UDS://tmp/lshttpd/cyberpanel.sock + maxConns 10 + env LSAPI_CHILDREN=10 + initTimeout 600 + retryTimeout 0 + persistConn 1 + pcKeepAliveTimeout 1 + respBuffer 0 + autoStart 1 + path /usr/local/lsws/lsphp82/bin/lsphp +# extUser nobody +# extGroup nobody + memSoftLimit 2047M + memHardLimit 2047M + procSoftLimit 400 + procHardLimit 500 +} \ No newline at end of file diff --git a/plogical/DockerSites.py b/plogical/DockerSites.py index a2d883dec..5ca79a67e 100644 --- a/plogical/DockerSites.py +++ b/plogical/DockerSites.py @@ -1,10 +1,11 @@ #!/usr/local/CyberCP/bin/python +import os import sys sys.path.append('/usr/local/CyberCP') import django from plogical.processUtilities import ProcessUtilities from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging - +import argparse class DockerSites: @@ -23,16 +24,64 @@ def InstallDocker(self): else: return 0, ReturnCode + @staticmethod + def SetupProxy(port): + ConfPath = '/usr/local/lsws/conf/httpd_config.conf' + data = open(ConfPath, 'r').read() + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + StringCheck = f"127.0.0.1:{port}" + if data.find(StringCheck) == -1: + ProxyContent = f""" +extprocessor docker{port} {{ + type proxy + address 127.0.0.1:{port} + maxConns 100 + pcKeepAliveTimeout 60 + initTimeout 60 + retryTimeout 0 + respBuffer 0 +}} +""" + + WriteToFile = open(ConfPath, 'a') + WriteToFile.write(ProxyContent) + WriteToFile.close() + + @staticmethod + def SetupHTAccess(port, htaccess): + ### Update htaccess + + StringCheck = f'docker{port}' + + try: + Content = open(htaccess, 'r').read() + except: + Content = '' + + print(f'value of content {Content}') + + if Content.find(StringCheck) == -1: + HTAccessContent = f''' +RewriteEngine On +REWRITERULE ^(.*)$ HTTP://docker{port}/$1 [P] +''' + WriteToFile = open(htaccess, 'a') + WriteToFile.write(HTAccessContent) + WriteToFile.close() + + ProcessUtilities.restartLitespeed() + + # Takes # ComposePath, MySQLPath, MySQLRootPass, MySQLDBName, MySQLDBNUser, MySQLPassword, CPUsMySQL, MemoryMySQL, # port, SitePath, CPUsSite, MemorySite, ComposePath, SiteName - # finalURL, blogTitle, adminUser, adminPassword, adminEmail + # finalURL, blogTitle, adminUser, adminPassword, adminEmail, htaccessPath, externalApp def DeployWPContainer(self): + try: logging.statusWriter(self.JobID, 'Checking if Docker is installed..,0') - command = 'docker --help' result = ProcessUtilities.outputExecutioner(command) print(f'return code of docker install {result}') @@ -44,51 +93,177 @@ def DeployWPContainer(self): logging.statusWriter(self.JobID, 'Docker is ready to use..,10') - WPSite = f""" -version: "3.8" +# WPSite = f""" +# version: "3.8" +# +# services: +# db: +# image: mysql:5.7 +# restart: always +# volumes: +# - "{self.data['MySQLPath']}:/var/lib/mysql" +# environment: +# MYSQL_ROOT_PASSWORD: {self.data['MySQLRootPass']} +# MYSQL_DATABASE: {self.data['MySQLDBName']} +# MYSQL_USER: {self.data['MySQLDBNUser']} +# MYSQL_PASSWORD: {self.data['MySQLPassword']} +# deploy: +# resources: +# limits: +# cpus: '{self.data['CPUsMySQL']}' # Use 50% of one CPU core +# memory: {self.data['MemoryMySQL']}M # Limit memory to 512 megabytes +# wordpress: +# depends_on: +# - db +# image: wordpress:latest +# restart: always +# ports: +# - "{self.data['port']}:80" +# environment: +# WORDPRESS_DB_HOST: db:3306 +# WORDPRESS_DB_USER: {self.data['MySQLDBNUser']} +# WORDPRESS_DB_PASSWORD: {self.data['MySQLPassword']} +# WORDPRESS_DB_NAME: {self.data['MySQLDBName']} +# volumes: +# - "{self.data['SitePath']}:/var/www/html" +# deploy: +# resources: +# limits: +# cpus: '{self.data['CPUsSite']}' # Use 50% of one CPU core +# memory: {self.data['MemorySite']}M # Limit memory to 512 megabytes +# +# volumes: +# mysql: {{}} +# """ +# +# WPSite = f""" +# # Copyright VMware, Inc. +# # SPDX-License-Identifier: APACHE-2.0 +# +# version: '2' +# services: +# mariadb: +# image: mariadb:10.5.9 +# user: root +# command: --max_allowed_packet=256M +# volumes: +# - "{self.data['MySQLPath']}:/var/lib/mysql:delegated" +# environment: +# - ALLOW_EMPTY_PASSWORD=no +# - MYSQL_USER={self.data['MySQLDBNUser']} +# - MYSQL_PASSWORD={self.data['MySQLPassword']} +# - MYSQL_DATABASE={self.data['MySQLDBName']} +# - MYSQL_ROOT_PASSWORD={self.data['MySQLPassword']} +# deploy: +# resources: +# limits: +# cpus: '{self.data['CPUsMySQL']}' # Use 50% of one CPU core +# memory: {self.data['MemoryMySQL']}M # Limit memory to 512 megabytes +# wordpress: +# image: litespeedtech/openlitespeed:latest +# user: root +# ports: +# - "{self.data['port']}:80" +# # - '443:8443' +# volumes: +# - {self.data['docRoot']}/lsws/conf:/usr/local/lsws/conf +# - {self.data['docRoot']}/lsws/admin-conf:/usr/local/lsws/admin/conf +# - {self.data['docRoot']}/bin:/usr/local/bin +# - {self.data['SitePath']}:/var/www/vhosts/ +# - {self.data['docRoot']}/acme:/root/.acme.sh/ +# - {self.data['docRoot']}/logs:/usr/local/lsws/logs/ +# depends_on: +# - mariadb +# environment: +# - TZ=America/New_York +# - PHP_VERSION=lsphp82 +# - MYSQL_ROOT_PASSWORD={self.data['MySQLPassword']} +# - DOMAIN={self.data['finalURL']} +# - MYSQL_USER={self.data['MySQLDBNUser']} +# - MYSQL_DATABASE={self.data['MySQLDBName']} +# - MYSQL_PASSWORD={self.data['MySQLPassword']} +# # - ALLOW_EMPTY_PASSWORD=no +# # - WORDPRESS_DATABASE_HOST=mariadb +# # - WORDPRESS_DATABASE_PORT_NUMBER=3306 +# # - WORDPRESS_USERNAME={self.data['adminUser']} +# # - WORDPRESS_PASSWORD={self.data["adminPassword"]} +# # - WORDPRESS_EMAIL={self.data["adminEmail"]} +# # - WORDPRESS_BLOG_NAME={self.data["blogTitle"]} +# # - WORDPRESS_ENABLE_REVERSE_PROXY=yes +# deploy: +# resources: +# limits: +# cpus: '{self.data['CPUsSite']}' # Use 50% of one CPU core +# memory: {self.data['MemorySite']}M # Limit memory to 512 megabytes +# # phpmyadmin: +# # image: bitnami/phpmyadmin:latest +# # ports: +# # # - 8080:8080 +# # # - 8443:8443 +# # environment: +# # DATABASE_HOST: mysql +# # restart: always +# # networks: +# # - default +# +# volumes: +# mariadb_data: +# driver: local +# wordpress_data: +# driver: local +# """ + + WPSite = f''' +version: '3.8' services: - db: - image: mysql:5.7 - restart: always - volumes: - - "{self.data['MySQLPath']}:/var/lib/mysql" + wordpress: + user: root + image: cyberpanel/openlitespeed:latest + ports: + - "{self.data['port']}:8088" +# - "443:443" environment: - MYSQL_ROOT_PASSWORD: {self.data['MySQLRootPass']} - MYSQL_DATABASE: {self.data['MySQLDBName']} - MYSQL_USER: {self.data['MySQLDBNUser']} - MYSQL_PASSWORD: {self.data['MySQLPassword']} + DB_NAME: "{self.data['MySQLDBName']}" + DB_USER: "{self.data['MySQLDBNUser']}" + DB_PASSWORD: "{self.data['MySQLPassword']}" + WP_ADMIN_EMAIL: "{self.data['adminEmail']}" + WP_ADMIN_USER: "{self.data['adminUser']}" + WP_ADMIN_PASSWORD: "{self.data['adminPassword']}" + WP_URL: {self.data['finalURL']} + DB_Host: mariadb:3306 + SITE_NAME: '{self.data['SiteName']}' + volumes: +# - "/home/docker/{self.data['finalURL']}:/usr/local/lsws/Example/html" + - "/home/docker/{self.data['finalURL']}/data:/usr/local/lsws/Example/html" + depends_on: + - mariadb deploy: resources: limits: - cpus: '{self.data['CPUsMySQL']}' # Use 50% of one CPU core - memory: {self.data['MemoryMySQL']}M # Limit memory to 512 megabytes - wordpress: - depends_on: - - db - image: wordpress:latest + cpus: '{self.data['CPUsSite']}' # Use 50% of one CPU core + memory: {self.data['MemorySite']}M # Limit memory to 512 megabytes + mariadb: + image: mariadb restart: always - ports: - - "{self.data['port']}:80" environment: - WORDPRESS_DB_HOST: db:3306 - WORDPRESS_DB_USER: {self.data['MySQLDBNUser']} - WORDPRESS_DB_PASSWORD: {self.data['MySQLPassword']} - WORDPRESS_DB_NAME: {self.data['MySQLDBName']} +# ALLOW_EMPTY_PASSWORD=no + MYSQL_DATABASE: '{self.data['MySQLDBName']}' + MYSQL_USER: '{self.data['MySQLDBNUser']}' + MYSQL_PASSWORD: '{self.data['MySQLPassword']}' + MYSQL_ROOT_PASSWORD: '{self.data['MySQLPassword']}' volumes: - - "{self.data['SitePath']}:/var/www/html" + - "/home/docker/{self.data['finalURL']}/db:/var/lib/mysql" deploy: resources: limits: - cpus: '{self.data['CPUsSite']}' # Use 50% of one CPU core - memory: {self.data['MemorySite']}M # Limit memory to 512 megabytes - -volumes: - mysql: {{}} -""" + cpus: '{self.data['CPUsMySQL']}' # Use 50% of one CPU core + memory: {self.data['MemoryMySQL']}M # Limit memory to 512 megabytes +''' ### WriteConfig to compose-file + WriteToFile = open(self.data['ComposePath'], 'w') WriteToFile.write(WPSite) WriteToFile.close() @@ -96,62 +271,119 @@ def DeployWPContainer(self): #### command = f"docker-compose -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d" - ReturnCode = ProcessUtilities.executioner(command) + result = ProcessUtilities.outputExecutioner(command) + + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(result) - command = f"docker-compose -f {self.data['ComposePath']} ps -q wordpress" - stdout = ProcessUtilities.outputExecutioner(command) - self.ContainerID = stdout.rstrip('\n') + ### Set up Proxy + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py" + execPath = execPath + f" SetupProxy --port {self.data['port']}" + ProcessUtilities.executioner(execPath) + ### Set up ht access - command = f'docker-compose -f {self.data["ComposePath"]} exec {self.ContainerID} curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar' - ReturnCode = ProcessUtilities.executioner(command) + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py" + execPath = execPath + f" SetupHTAccess --port {self.data['port']} --htaccess {self.data['htaccessPath']}" + ProcessUtilities.executioner(execPath, self.data['externalApp']) - command = f"docker-compose -f {self.data['ComposePath']} exec {self.ContainerID} chmod + wp-cli.phar" - ReturnCode = ProcessUtilities.executioner(command) + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + group = 'nobody' + else: + group = 'nogroup' - command = f"docker-compose -f {self.data['ComposePath']} exec {self.ContainerID} mv wp-cli.phar /bin/wp" - ReturnCode = ProcessUtilities.executioner(command) + command = f"chown -R nobody:{group} /home/docker/{self.data['finalURL']}/data" + ProcessUtilities.executioner(command) - command = f'docker-compose -f {self.data["ComposePath"]} exec {self.ContainerID} wp core install --url="http://{self.data["finalURL"]}" --title="{self.data["blogTitle"]}" --admin_user="{self.data["adminUser"]}" --admin_password="{self.data["adminPassword"]}" --admin_email="{self.data["adminEmail"]}" --path=. --allow-root' - ReturnCode = ProcessUtilities.executioner(command) + # command = f"docker-compose -f {self.data['ComposePath']} ps -q wordpress" + # stdout = ProcessUtilities.outputExecutioner(command) + # + # self.ContainerID = stdout.rstrip('\n') + + + + # command = f'docker-compose -f {self.data["ComposePath"]} exec {self.ContainerID} curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar' + # result = ProcessUtilities.outputExecutioner(command) + # + # if os.path.exists(ProcessUtilities.debugPath): + # logging.writeToFile(result) + # + # command = f"docker-compose -f {self.data['ComposePath']} exec {self.ContainerID} chmod + wp-cli.phar" + # result = ProcessUtilities.outputExecutioner(command) + # + # if os.path.exists(ProcessUtilities.debugPath): + # logging.writeToFile(result) + # + # command = f"docker-compose -f {self.data['ComposePath']} exec {self.ContainerID} mv wp-cli.phar /bin/wp" + # result = ProcessUtilities.outputExecutioner(command) + # + # if os.path.exists(ProcessUtilities.debugPath): + # logging.writeToFile(result) + + # command = f'docker-compose -f {self.data["ComposePath"]} exec {self.ContainerID} wp core install --url="http://{self.data["finalURL"]}" --title="{self.data["blogTitle"]}" --admin_user="{self.data["adminUser"]}" --admin_password="{self.data["adminPassword"]}" --admin_email="{self.data["adminEmail"]}" --path=. --allow-root' + # result = ProcessUtilities.outputExecutioner(command) + # + # if os.path.exists(ProcessUtilities.debugPath): + # logging.writeToFile(result) except BaseException as msg: + logging.writeToFile(f'{str(msg)}. [DeployWPContainer]') print(str(msg)) pass + def Main(): try: - # Takes - # ComposePath, MySQLPath, MySQLRootPass, MySQLDBName, MySQLDBNUser, MySQLPassword, CPUsMySQL, MemoryMySQL, - # port, SitePath, CPUsSite, MemorySite, SiteName - # finalURL, blogTitle, adminUser, adminPassword, adminEmail - data = { - "JobID": '/home/cyberpanel/error-logs.txt', - "ComposePath": "/home/cyberpanel.net/docker-compose.yml", - "MySQLPath": '/home/cyberpanel.net/public_html/sqldocker', - "MySQLRootPass": 'testdbwp12345', - "MySQLDBName": 'testdbwp', - "MySQLDBNUser": 'testdbwp', - "MySQLPassword": 'testdbwp12345', - "CPUsMySQL": '2', - "MemoryMySQL": '512', - "port": '8000', - "SitePath": '/home/cyberpanel.net/public_html/wpdocker', - "CPUsSite": '2', - "MemorySite": '512', - "SiteName": 'wp docker test', - "finalURL": '95.217.125.218:8001', - "blogTitle": 'testdbwp', - "adminUser": 'testdbwp', - "adminPassword": 'testdbwp', - "adminEmail": 'testdbwp', - } - ds = DockerSites(data) - - ds.DeployWPContainer() + + + parser = argparse.ArgumentParser(description='CyberPanel Docker Sites') + parser.add_argument('function', help='Specify a function to call!') + parser.add_argument('--port', help='') + parser.add_argument('--htaccess', help='') + parser.add_argument('--externalApp', help='') + + args = parser.parse_args() + + if args.function == "SetupProxy": + DockerSites.SetupProxy(args.port) + elif args.function == 'SetupHTAccess': + DockerSites.SetupHTAccess(args.port, args.htaccess) + elif args.function == 'DeployWPDocker': + # Takes + # ComposePath, MySQLPath, MySQLRootPass, MySQLDBName, MySQLDBNUser, MySQLPassword, CPUsMySQL, MemoryMySQL, + # port, SitePath, CPUsSite, MemorySite, SiteName + # finalURL, blogTitle, adminUser, adminPassword, adminEmail, htaccessPath, externalApp + data = { + "JobID": '/home/cyberpanel/error-logs.txt', + "ComposePath": "/home/docker.cyberpanel.net/docker-compose.yml", + "MySQLPath": '/home/docker.cyberpanel.net/public_html/sqldocker', + "MySQLRootPass": 'testdbwp12345', + "MySQLDBName": 'testdbwp', + "MySQLDBNUser": 'testdbwp', + "MySQLPassword": 'testdbwp12345', + "CPUsMySQL": '2', + "MemoryMySQL": '512', + "port": '8000', + "SitePath": '/home/docker.cyberpanel.net/public_html/wpdocker', + "CPUsSite": '2', + "MemorySite": '512', + "SiteName": 'wp docker test', + "finalURL": 'docker.cyberpanel.net', + "blogTitle": 'docker site', + "adminUser": 'testdbwp', + "adminPassword": 'testdbwp', + "adminEmail": 'usman@cyberpersons.com', + "htaccessPath": '/home/docker.cyberpanel.net/public_html/.htaccess', + "externalApp": 'docke3339', + "docRoot": "/home/docker.cyberpanel.net" + } + ds = DockerSites(data) + ds.DeployWPContainer() + + except BaseException as msg: print(str(msg)) pass diff --git a/plogical/dnsUtilities.py b/plogical/dnsUtilities.py index 3dd073f48..46b0deb59 100755 --- a/plogical/dnsUtilities.py +++ b/plogical/dnsUtilities.py @@ -18,6 +18,7 @@ from manageServices.models import PDNSStatus, SlaveServers except: pass + import CloudFlare from plogical.processUtilities import ProcessUtilities diff --git a/plogical/mysqlUtilities.py b/plogical/mysqlUtilities.py index c115cb690..bb9f2c2a3 100755 --- a/plogical/mysqlUtilities.py +++ b/plogical/mysqlUtilities.py @@ -1069,6 +1069,28 @@ def UpdateWPTempPassword(dbname, password): logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[deleteDatabase]") return str(msg) + @staticmethod + def UpgradeMariaDB(tempStatusPath): + + logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Creating backup of MySQL..,10') + + MySQLBackupDir = '/var/lib/mysql-backupcp' + from os import getuid + if getuid() != 0: + logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'This function should run as root. [404]') + return 0, 'This function should run as root.' + + + if not os.path.exists(MySQLBackupDir): + command = 'rsync -av /var/lib/mysql/ /var/lib/mysql-backupcp/' + ProcessUtilities.executioner(command) + + logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'MySQL backup created..,20') + + + + + def main(): parser = argparse.ArgumentParser(description='CyberPanel') parser.add_argument('function', help='Specific a function to call!') diff --git a/plogical/phpUtilities.py b/plogical/phpUtilities.py index 0d2150c6c..0518c6f5d 100755 --- a/plogical/phpUtilities.py +++ b/plogical/phpUtilities.py @@ -248,6 +248,10 @@ def GetPHPVersionFromFile(vhFile, domainName=None): @staticmethod def WrapGetPHPVersionFromFileToGetVersionWithPHP(vhFile): result = phpUtilities.GetPHPVersionFromFile(vhFile) + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(result) + command = result + " -v | awk '/^PHP/ {print $2}'" php_version = ProcessUtilities.outputExecutioner(command, None, True).rstrip('\n') return f"PHP {php_version}" diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index fae88ce84..17ed5d5a7 100755 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -297,6 +297,8 @@ def executioner(command, user=None, shell=False): @staticmethod def outputExecutioner(command, user=None, shell = None, dir = None, retRequired = None): try: + if os.path.exists('/usr/local/CyberCP/debug'): + logging.writeToFile(command) if getpass.getuser() == 'root': if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(command) diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 1106bc9fa..ab47f5235 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -2354,11 +2354,29 @@ def fetchWebsitesList(self, userID=None, data=None): pageNumber = int(data['page']) recordsToShow = int(data['recordsToShow']) + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'Fetch sites step 1..') + endPageNumber, finalPageNumber = self.recordsPointer(pageNumber, recordsToShow) + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'Fetch sites step 2..') + websites = ACLManager.findWebsiteObjects(currentACL, userID) + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'Fetch sites step 3..') + pagination = self.getPagination(len(websites), recordsToShow) + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'Fetch sites step 4..') + json_data = self.findWebsitesListJson(websites[finalPageNumber:endPageNumber]) + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'Fetch sites step 5..') + final_dic = {'status': 1, 'listWebSiteStatus': 1, 'error_message': "None", "data": json_data, 'pagination': pagination} final_json = json.dumps(final_dic) @@ -2415,9 +2433,14 @@ def findWebsitesListJson(self, websites): from plogical.phpUtilities import phpUtilities + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'findWebsitesListJson 1') + for items in websites: + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'findWebsitesListJson 2') if items.state == 0: state = "Suspended" else: @@ -2425,10 +2448,25 @@ def findWebsitesListJson(self, websites): vhFile = f'/usr/local/lsws/conf/vhosts/{items.domain}/vhost.conf' - PHPVersionActual = phpUtilities.WrapGetPHPVersionFromFileToGetVersionWithPHP(vhFile) + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(vhFile) + + try: + PHPVersionActual = phpUtilities.WrapGetPHPVersionFromFileToGetVersionWithPHP(vhFile) + except: + PHPVersionActual = 'PHP 8.1' + + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'findWebsitesListJson 3') DiskUsage, DiskUsagePercentage, bwInMB, bwUsage = virtualHostUtilities.FindStats(items) - diskUsed = "%sMB" % str(DiskUsage) + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'findWebsitesListJson 4') + try: + diskUsed = "%sMB" % str(DiskUsage) + except: + diskUsed = "%sMB" % str(0) dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress, 'admin': items.admin.userName, 'package': items.package.packageName, 'state': state,