diff --git a/.gitignore b/.gitignore index 2c1147f95..99ec4282e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ *.pyc -ApachController/ .idea diff --git a/ApachController/ApacheController.py b/ApachController/ApacheController.py new file mode 100755 index 000000000..f9fca1b8e --- /dev/null +++ b/ApachController/ApacheController.py @@ -0,0 +1,306 @@ +#!/usr/local/CyberCP/bin/python2 +import os +import subprocess +import shlex +import plogical.CyberCPLogFileWriter as logging +from ApacheVhosts import ApacheVhost + + +class ApacheController: + apacheInstallStatusPath = '/home/cyberpanel/apacheInstallStatus' + serverRootPath = '/etc/httpd' + mpmConfigs = """# Select the MPM module which should be used by uncommenting exactly +# one of the following LoadModule lines: + +# prefork MPM: Implements a non-threaded, pre-forking web server +# See: http://httpd.apache.org/docs/2.4/mod/prefork.html +#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so + +# worker MPM: Multi-Processing Module implementing a hybrid +# multi-threaded multi-process web server +# See: http://httpd.apache.org/docs/2.4/mod/worker.html +# +#LoadModule mpm_worker_module modules/mod_mpm_worker.so + +# event MPM: A variant of the worker MPM with the goal of consuming +# threads only for connections with active processing +# See: http://httpd.apache.org/docs/2.4/mod/event.html +# +LoadModule mpm_event_module modules/mod_mpm_event.so + + + StartServers 2 + MinSpareThreads 25 + MaxSpareThreads 75 + ThreadLimit 64 + ThreadsPerChild 25 + MaxRequestWorkers 30 + MaxConnectionsPerChild 1000 +""" + mpmConfigsPath = "/etc/httpd/conf.modules.d/00-mpm.conf" + + @staticmethod + def checkIfApacheInstalled(): + try: + if os.path.exists(ApacheController.serverRootPath): + pass + else: + return 0 + + if os.path.exists(ApacheVhost.php54Path): + pass + else: + return 0 + + if os.path.exists(ApacheVhost.php55Path): + pass + else: + return 0 + + if os.path.exists(ApacheVhost.php56Path): + pass + else: + return 0 + + if os.path.exists(ApacheVhost.php70Path): + pass + else: + return 0 + + if os.path.exists(ApacheVhost.php71Path): + pass + else: + return 0 + + if os.path.exists(ApacheVhost.php72Path): + pass + else: + return 0 + + if os.path.exists(ApacheVhost.php73Path): + return 1 + else: + return 0 + except BaseException, msg: + message = "%s. [%s]" % (str(msg), '[ApacheController.checkIfApacheInstalled]') + logging.CyberCPLogFileWriter.writeToFile(message) + + @staticmethod + def executioner(command): + try: + # subprocess.call(shlex.split(command)) + res = subprocess.call(shlex.split(command)) + if res == 1: + return 0 + else: + return 1 + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return 0 + + @staticmethod + def InstallApache(): + try: + + command = "yum install -y httpd httpd-tools mod_ssl php-fpm" + if ApacheController.executioner(command) == 0: + return "Failed to install Apache and PHP-FPM." + + command = "yum -y install centos-release-scl yum-utils" + if ApacheController.executioner(command) == 0: + return "Failed to centos-release-scl and yum-utils" + + command = "yum-config-manager --enable rhel-server-rhscl-7-rpms" + if ApacheController.executioner(command) == 0: + return "Failed to --enable rhel-server-rhscl-7-rpms" + + + ## Minor Configuration changes. + + sslPath = "/etc/httpd/conf.d/ssl.conf" + + if os.path.exists(sslPath): + os.remove(sslPath) + + confPath = ApacheVhost.serverRootPath + "/conf/httpd.conf" + + data = open(confPath, 'r').readlines() + writeToFile = open(confPath, 'w') + + for items in data: + if items.find("Listen") > -1 and items.find("80") > -1 and items.find('#') == -1: + writeToFile.writelines("Listen 8081\nListen 8082\n") + elif items.find("User") > -1 and items.find('#') == -1: + writeToFile.writelines("User nobody\n") + elif items.find("Group") > -1 and items.find('#') == -1: + writeToFile.writelines("Group nobody\n") + writeToFile.writelines('SetEnv LSWS_EDITION Openlitespeed\nSetEnv X-LSCACHE on\n') + elif items[0] == "#": + continue + else: + writeToFile.writelines(items) + + writeToFile.close() + + # MPM Module Configurations + + writeToFile = open(ApacheController.mpmConfigsPath , 'w') + writeToFile.write(ApacheController.mpmConfigs) + writeToFile.close() + + ### + + command = "systemctl start httpd.service" + ApacheController.executioner(command) + command = "systemctl enable httpd.service" + ApacheController.executioner(command) + + return 1 + + except BaseException, msg: + return str(msg) + + @staticmethod + def phpVersions(): + # Version 5.4 + + command = 'yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm' + ApacheController.executioner(command) + + command = 'yum-config-manager --enable remi-php' + ApacheController.executioner(command) + + + command = 'yum install -y php54-php-fpm php54-php-gd php54-php-xml php54-php-twig php54-php-zstd php54-php-tidy' \ + 'php54-php-suhosin php54-php-soap php54-php-snmp php54-php-snappy php54-php-smbclient' \ + 'php54-php-process php54-php-pimple php54-php-pgsql php54-php-pear.noarch php54-php-pdo' \ + 'php54-php-mysqlnd php54-php-mssql php54-php-mcrypt php54-php-mbstring php54-php-maxminddb' \ + 'php54-php-common php54-php-imap php54-php-intl php54-php-tarantool php54-php-pspell php54-php-oci8' \ + 'php54-php-bcmath php54-php-litespeed php54-php-recode php54-php-odbc' + if ApacheController.executioner(command) == 0: + return "Failed to install php54-fpm" + + # Version 5.5 + command = 'yum install -y php55-php-fpm php55-php-gd php55-php-xml php55-php-twig php55-php-zstd php55-php-tidy' \ + 'php55-php-suhosin php55-php-soap php55-php-snmp php55-php-snappy php55-php-smbclient ' \ + 'php55-php-process php55-php-pimple php55-php-pgsql php55-php-pear.noarch php55-php-pdo' \ + 'php55-php-mysqlnd php55-php-mssql php55-php-mcrypt php55-php-mbstring php55-php-maxminddb' \ + 'php55-php-common php55-php-imap php55-php-intl php55-php-tarantool php55-php-pspell php55-php-oci8' \ + 'php55-php-litespeed php55-php-bcmath php55-php-odbc php55-php-recode' + if ApacheController.executioner(command) == 0: + return "Failed to install php55-fpm" + + # Version 5.6 + command = 'yum install -y php56-php-fpm php56-php-gd php56-php-xml php56-php-twig php56-php-zstd php56-php-tidy' \ + 'php56-php-suhosin php56-php-soap php56-php-snmp php56-php-snappy php56-php-smbclient' \ + 'php56-php-process php56-php-pimple php56-php-pgsql php56-php-pear.noarch php56-php-pdo ' \ + 'php56-php-mysqlnd php56-php-mssql php56-php-mcrypt php56-php-mbstring php56-php-maxminddb' \ + 'php56-php-common php56-php-imap php56-php-intl php56-php-tarantool php56-php-recode' \ + 'php56-php-odbc php56-php-oci8 php56-php-litespeed php56-php-bcmath php56-php-pspell' + if ApacheController.executioner(command) == 0: + return "Failed to install php56-fpm" + + # Version 7.0 + command = 'yum install -y php70-php-fpm php70-php-gd php70-php-xml php70-php-twig php70-php-zstd php70-php-tidy' \ + 'php70-php-suhosin php70-php-soap php70-php-snmp php70-php-snappy php70-php-smbclient' \ + 'php70-php-process php70-php-pimple php70-php-pgsql php70-php-pear.noarch php70-php-pdo ' \ + 'php70-php-mysqlnd php70-php-mssql php70-php-mcrypt php70-php-mbstring php70-php-maxminddb' \ + 'php70-php-common php70-php-imap php70-php-intl php70-php-tarantool php70-php-recode' \ + 'php70-php-odbc php70-php-oci8 php70-php-litespeed php70-php-bcmath php70-php-pspell' + if ApacheController.executioner(command) == 0: + return "Failed to install php70-fpm" + + # Version 7.1 + command = 'yum install -y php71-php-fpm php71-php-gd php71-php-xml php71-php-twig php71-php-zstd php71-php-tidy' \ + 'php71-php-suhosin php71-php-soap php71-php-snmp php71-php-snappy php71-php-smbclient' \ + 'php71-php-process php71-php-pimple php71-php-pgsql php71-php-pear.noarch php71-php-pdo ' \ + 'php71-php-mysqlnd php71-php-mssql php71-php-mcrypt php71-php-mbstring php71-php-maxminddb' \ + 'php71-php-common php71-php-imap php71-php-intl php71-php-tarantool php71-php-recode' \ + 'php71-php-odbc php71-php-oci8 php71-php-litespeed php71-php-bcmath php71-php-pspell' + if ApacheController.executioner(command) == 0: + return "Failed to install php71-fpm" + + # Version 7.2 + command = 'yum install -y php72-php-fpm php72-php-gd php72-php-xml php72-php-twig php72-php-zstd php72-php-tidy' \ + 'php72-php-suhosin php72-php-soap php72-php-snmp php72-php-snappy php72-php-smbclient' \ + 'php72-php-process php72-php-pimple php72-php-pgsql php72-php-pear.noarch php72-php-pdo ' \ + 'php72-php-mysqlnd php72-php-mssql php72-php-mcrypt php72-php-mbstring php72-php-maxminddb' \ + 'php72-php-common php72-php-imap php72-php-intl php72-php-tarantool php72-php-recode' \ + 'php72-php-odbc php72-php-oci8 php72-php-litespeed php72-php-bcmath php72-php-pspell' + if ApacheController.executioner(command) == 0: + return "Failed to install php72-fpm" + + # Version 7.3 + command = 'yum install -y php73-php-fpm php73-php-gd php73-php-xml php73-php-twig php73-php-zstd php73-php-tidy' \ + 'php73-php-suhosin php73-php-soap php73-php-snmp php73-php-snappy php73-php-smbclient' \ + 'php73-php-process php73-php-pimple php73-php-pgsql php73-php-pear.noarch php73-php-pdo ' \ + 'php73-php-mysqlnd php73-php-mssql php73-php-mcrypt php73-php-mbstring php73-php-maxminddb' \ + 'php73-php-common php73-php-imap php73-php-intl php73-php-tarantool php73-php-recode' \ + 'php73-php-odbc php73-php-oci8 php73-php-litespeed php73-php-bcmath php73-php-pspell' + + + if ApacheController.executioner(command) == 0: + return "Failed to install php73-fpm" + + try: + wwwConfPath = ApacheVhost.php54Path + "/www.conf" + + if os.path.exists(wwwConfPath): + os.remove(wwwConfPath) + + wwwConfPath = ApacheVhost.php55Path + "/www.conf" + + if os.path.exists(wwwConfPath): + os.remove(wwwConfPath) + + wwwConfPath = ApacheVhost.php56Path + "/www.conf" + + if os.path.exists(wwwConfPath): + os.remove(wwwConfPath) + + wwwConfPath = ApacheVhost.php70Path + "/www.conf" + + if os.path.exists(wwwConfPath): + os.remove(wwwConfPath) + + wwwConfPath = ApacheVhost.php71Path + "/www.conf" + + if os.path.exists(wwwConfPath): + os.remove(wwwConfPath) + + wwwConfPath = ApacheVhost.php72Path + "/www.conf" + + if os.path.exists(wwwConfPath): + os.remove(wwwConfPath) + + wwwConfPath = ApacheVhost.php73Path + "/www.conf" + + if os.path.exists(wwwConfPath): + os.remove(wwwConfPath) + except: + pass + + return 1 + + @staticmethod + def setupApache(statusFile): + try: + + logging.CyberCPLogFileWriter.statusWriter(statusFile, 'Starting Apache installation. It may take some time..,70') + + result = ApacheController.InstallApache() + + if result != 1: + return [0,result] + + logging.CyberCPLogFileWriter.statusWriter(statusFile, + 'Installing PHP-FPM Versions. It may take some time..,80') + + result = ApacheController.phpVersions() + + if result != 1: + return [0,result] + + return [1, 'None'] + except BaseException, msg: + return [0, str(msg)] \ No newline at end of file diff --git a/ApachController/ApacheVhosts.py b/ApachController/ApacheVhosts.py new file mode 100755 index 000000000..5775771c3 --- /dev/null +++ b/ApachController/ApacheVhosts.py @@ -0,0 +1,388 @@ +#!/usr/local/CyberCP/bin/python2 +import os +import os.path +import sys +import django +sys.path.append('/usr/local/CyberCP') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") +django.setup() +import os +from websiteFunctions.models import Websites, ChildDomains +from plogical.vhostConfs import vhostConfs +from managePHP.phpManager import PHPManager +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging +from plogical.processUtilities import ProcessUtilities +import re + +class ApacheVhost: + apacheInstallStatusPath = '/home/cyberpanel/apacheInstallStatus' + serverRootPath = '/etc/httpd' + configBasePath = '/etc/httpd/conf.d/' + lswsMainConf = "/usr/local/lsws/conf/httpd_config.conf" + php54Path = '/opt/remi/php54/root/etc/php-fpm.d/' + php55Path = '/opt/remi/php55/root/etc/php-fpm.d/' + php56Path = '/etc/opt/remi/php56/php-fpm.d/' + php70Path = '/etc/opt/remi/php70/php-fpm.d/' + php71Path = '/etc/opt/remi/php71/php-fpm.d/' + php72Path = '/etc/opt/remi/php72/php-fpm.d/' + php73Path = '/etc/opt/remi/php73/php-fpm.d/' + count = 0 + sslBasePath = "/etc/httpd/conf.d/ssl/" + + @staticmethod + def DecidePHPPath(php, virtualHostName): + if php == '53' or php == '54': + finalConfPath = ApacheVhost.php54Path + virtualHostName + elif php == '55': + finalConfPath = ApacheVhost.php55Path + virtualHostName + elif php == '56': + finalConfPath = ApacheVhost.php56Path + virtualHostName + elif php == '70': + finalConfPath = ApacheVhost.php70Path + virtualHostName + elif php == '71': + finalConfPath = ApacheVhost.php71Path + virtualHostName + elif php == '72': + finalConfPath = ApacheVhost.php72Path + virtualHostName + elif php == '73': + finalConfPath = ApacheVhost.php73Path + virtualHostName + + return finalConfPath + '.conf' + + @staticmethod + def whichPHPExists(virtualHostName): + + virtualHostName = virtualHostName + ".conf" + + if os.path.exists(ApacheVhost.php54Path + virtualHostName): + return ApacheVhost.php54Path + virtualHostName + + if os.path.exists(ApacheVhost.php55Path + virtualHostName): + return ApacheVhost.php55Path + virtualHostName + + if os.path.exists(ApacheVhost.php56Path + virtualHostName): + return ApacheVhost.php56Path + virtualHostName + + if os.path.exists(ApacheVhost.php70Path + virtualHostName): + return ApacheVhost.php70Path + virtualHostName + + if os.path.exists(ApacheVhost.php71Path + virtualHostName): + return ApacheVhost.php71Path + virtualHostName + + if os.path.exists(ApacheVhost.php72Path + virtualHostName): + return ApacheVhost.php72Path + virtualHostName + + if os.path.exists(ApacheVhost.php73Path + virtualHostName): + return ApacheVhost.php73Path + virtualHostName + + @staticmethod + def GenerateSelfSignedSSL(virtualHostName): + if os.path.exists(ApacheVhost.sslBasePath): + pass + else: + os.mkdir(ApacheVhost.sslBasePath) + + pathToStoreSSLPrivKey = ApacheVhost.sslBasePath + virtualHostName + ".privkey.pem" + pathToStoreSSLFullChain = ApacheVhost.sslBasePath + virtualHostName + ".fullchain.pem" + command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout ' + pathToStoreSSLPrivKey + ' -out ' + pathToStoreSSLFullChain + ProcessUtilities.normalExecutioner(command) + + @staticmethod + def perHostVirtualConf(administratorEmail,externalApp, virtualHostUser, phpVersion, virtualHostName): + try: + + ## Non-SSL Conf + + finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf' + confFile = open(finalConfPath, "w+") + + php = PHPManager.getPHPString(phpVersion) + + currentConf = vhostConfs.apacheConf + currentConf = currentConf.replace('{virtualHostName}', virtualHostName) + currentConf = currentConf.replace('{administratorEmail}', administratorEmail) + currentConf = currentConf.replace('{virtualHostUser}', virtualHostUser) + currentConf = currentConf.replace('{php}', php) + currentConf = currentConf.replace('{adminEmails}', administratorEmail) + currentConf = currentConf.replace('{externalApp}', virtualHostUser) + + confFile.write(currentConf) + confFile.close() + + ## SSL Conf + + finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf' + confFile = open(finalConfPath, "a") + + php = PHPManager.getPHPString(phpVersion) + + currentConf = vhostConfs.apacheConfSSL + currentConf = currentConf.replace('{virtualHostName}', virtualHostName) + currentConf = currentConf.replace('{administratorEmail}', administratorEmail) + currentConf = currentConf.replace('{virtualHostUser}', virtualHostUser) + currentConf = currentConf.replace('{php}', php) + currentConf = currentConf.replace('{adminEmails}', administratorEmail) + currentConf = currentConf.replace('{externalApp}', virtualHostUser) + + confFile.write(currentConf) + confFile.close() + + ## + + finalConfPath = ApacheVhost.DecidePHPPath(php, virtualHostName) + + confFile = open(finalConfPath, "w+") + currentConf = vhostConfs.phpFpmPool + currentConf = currentConf.replace('{www}', virtualHostUser) + currentConf = currentConf.replace('{Sock}', virtualHostName) + currentConf = currentConf.replace('{externalApp}', externalApp) + + confFile.write(currentConf) + + ApacheVhost.GenerateSelfSignedSSL(virtualHostName) + + command = "systemctl restart httpd" + ProcessUtilities.normalExecutioner(command) + + return [1, 'None'] + except BaseException, msg: + return [0, str(msg)] + + @staticmethod + def enableProxyInMainConf(): + try: + data = open(ApacheVhost.lswsMainConf, 'r').readline() + + putProxyConf = 1 + putProxyConfSSL = 1 + + for items in data: + if items.find('apachebackend') > -1: + putProxyConf = 0 + if items.find('proxyApacheBackendSSL') > -1: + putProxyConfSSL = 0 + + if putProxyConf: + confFile = open(ApacheVhost.lswsMainConf, "a") + confFile.write(vhostConfs.proxyApacheBackend) + confFile.close() + + if putProxyConfSSL: + confFile = open(ApacheVhost.lswsMainConf, "a") + confFile.write(vhostConfs.proxyApacheBackendSSL) + confFile.close() + + return [1, 'None'] + except BaseException, msg: + return [0, str(msg)] + + @staticmethod + def reWrite(domain_name): + try: + domainPath = '/home/' + domain_name + '/public_html/.htaccess' + confFile = open(domainPath, "w+") + confFile.write("REWRITERULE ^(.*)$ HTTP://apachebackend/$1 [P]") + confFile.close() + return [1, 'None'] + except BaseException, msg: + return [0, str(msg)] + + @staticmethod + def setupApacheVhost(administratorEmail,externalApp, virtualHostUser, phpVersion, virtualHostName): + result = ApacheVhost.perHostVirtualConf(administratorEmail,externalApp, virtualHostUser, phpVersion, virtualHostName) + if result[0] == 0: + return [0, result[1]] + + result = ApacheVhost.enableProxyInMainConf() + if result[0] == 0: + return [0, result[1]] + + return [1, 'None'] + + @staticmethod + def perHostVirtualConfChild(administratorEmail, externalApp, virtualHostUser, phpVersion, virtualHostName, path): + try: + + ## Non - SSL Conf + + finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf' + confFile = open(finalConfPath, "w+") + + php = PHPManager.getPHPString(phpVersion) + + currentConf = vhostConfs.apacheConfChild + currentConf = currentConf.replace('{virtualHostName}', virtualHostName) + currentConf = currentConf.replace('{administratorEmail}', administratorEmail) + currentConf = currentConf.replace('{php}', php) + currentConf = currentConf.replace('{adminEmails}', administratorEmail) + currentConf = currentConf.replace('{externalApp}', virtualHostUser) + currentConf = currentConf.replace('{path}', path) + + confFile.write(currentConf) + confFile.close() + + ## SSL Conf + + finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf' + confFile = open(finalConfPath, "a") + + php = PHPManager.getPHPString(phpVersion) + + currentConf = vhostConfs.apacheConfChildSSL + currentConf = currentConf.replace('{virtualHostName}', virtualHostName) + currentConf = currentConf.replace('{administratorEmail}', administratorEmail) + currentConf = currentConf.replace('{php}', php) + currentConf = currentConf.replace('{adminEmails}', administratorEmail) + currentConf = currentConf.replace('{externalApp}', virtualHostUser) + currentConf = currentConf.replace('{path}', path) + + confFile.write(currentConf) + confFile.close() + + ## SSL Conf + + finalConfPath = ApacheVhost.DecidePHPPath(php, virtualHostName) + + confFile = open(finalConfPath, "w+") + currentConf = vhostConfs.phpFpmPool + currentConf = currentConf.replace('{www}', "".join(re.findall("[a-zA-Z]+", virtualHostName))[:7]) + currentConf = currentConf.replace('{Sock}', virtualHostName) + currentConf = currentConf.replace('{externalApp}', externalApp) + + confFile.write(currentConf) + + ApacheVhost.GenerateSelfSignedSSL(virtualHostName) + + command = "systemctl restart httpd" + ProcessUtilities.normalExecutioner(command) + + return [1, 'None'] + except BaseException, msg: + return [0, str(msg)] + + @staticmethod + def setupApacheVhostChild(administratorEmail, externalApp, virtualHostUser, phpVersion, virtualHostName, path): + result = ApacheVhost.perHostVirtualConfChild(administratorEmail, externalApp, virtualHostUser, phpVersion, + virtualHostName, path) + if result[0] == 0: + return [0, result[1]] + + result = ApacheVhost.enableProxyInMainConf() + if result[0] == 0: + return [0, result[1]] + + return [1, 'None'] + + @staticmethod + def DeleteApacheVhost(virtualHostName): + try: + finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf' + + if os.path.exists(finalConfPath): + os.remove(finalConfPath) + + ApacheVhost.deletePHPPath(virtualHostName) + + command = "systemctl restart httpd" + ProcessUtilities.normalExecutioner(command) + + except BaseException, msg: + logging.writeToFile(str(msg)) + + @staticmethod + def perHostVirtualConfOLS(vhFile, administratorEmail): + # General Configurations tab + try: + confFile = open(vhFile, "w+") + + currentConf = vhostConfs.OLSLBConf + currentConf = currentConf.replace('{adminEmails}', administratorEmail) + + confFile.write(currentConf) + confFile.close() + + except BaseException, msg: + logging.writeToFile( + str(msg) + " [IO Error with per host config file [ApacheVhosts.perHostVirtualConf]]") + + @staticmethod + def deletePHPPath(virtualHostName): + + phpPath = ApacheVhost.DecidePHPPath('54', virtualHostName) + if os.path.exists(phpPath): + os.remove(phpPath) + command = "systemctl restart php%s-php-fpm" % ('54') + ProcessUtilities.normalExecutioner(command) + + phpPath = ApacheVhost.DecidePHPPath('55', virtualHostName) + if os.path.exists(phpPath): + os.remove(phpPath) + command = "systemctl restart php%s-php-fpm" % ('55') + ProcessUtilities.normalExecutioner(command) + + phpPath = ApacheVhost.DecidePHPPath('56', virtualHostName) + if os.path.exists(phpPath): + os.remove(phpPath) + command = "systemctl restart php%s-php-fpm" % ('56') + ProcessUtilities.normalExecutioner(command) + + phpPath = ApacheVhost.DecidePHPPath('70', virtualHostName) + if os.path.exists(phpPath): + os.remove(phpPath) + command = "systemctl restart php%s-php-fpm" % ('70') + ProcessUtilities.normalExecutioner(command) + + phpPath = ApacheVhost.DecidePHPPath('71', virtualHostName) + if os.path.exists(phpPath): + os.remove(phpPath) + command = "systemctl restart php%s-php-fpm" % ('71') + ProcessUtilities.normalExecutioner(command) + + phpPath = ApacheVhost.DecidePHPPath('72', virtualHostName) + if os.path.exists(phpPath): + os.remove(phpPath) + command = "systemctl restart php%s-php-fpm" % ('72') + ProcessUtilities.normalExecutioner(command) + + phpPath = ApacheVhost.DecidePHPPath('73', virtualHostName) + if os.path.exists(phpPath): + os.remove(phpPath) + command = "systemctl restart php%s-php-fpm" % ('73') + ProcessUtilities.normalExecutioner(command) + + @staticmethod + def changePHP(phpVersion, vhFile): + try: + + virtualHostName = vhFile.split('/')[6] + + finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf' + + if not os.path.exists(finalConfPath): + return 0 + + ApacheVhost.deletePHPPath(virtualHostName) + + website = Websites.objects.get(domain=virtualHostName) + + php = PHPManager.getPHPString(phpVersion) + + finalConfPath = ApacheVhost.DecidePHPPath(php, virtualHostName) + + confFile = open(finalConfPath, "w+") + currentConf = vhostConfs.phpFpmPool + currentConf = currentConf.replace('{www}', website.externalApp) + currentConf = currentConf.replace('{Sock}', virtualHostName) + currentConf = currentConf.replace('{externalApp}', website.externalApp) + + confFile.write(currentConf) + + command = "systemctl stop php%s-php-fpm" % (php) + ProcessUtilities.normalExecutioner(command) + + command = "systemctl restart php%s-php-fpm" % (php) + ProcessUtilities.normalExecutioner(command) + + return 1 + except BaseException, msg: + logging.writeToFile(str(msg)) + return 1 \ No newline at end of file diff --git a/ApachController/BackupUtil.py b/ApachController/BackupUtil.py new file mode 100644 index 000000000..19f76e88d --- /dev/null +++ b/ApachController/BackupUtil.py @@ -0,0 +1,73 @@ +import smtplib +import time +import argparse +import subprocess, shlex +import os + +class BackupUtil: + + @staticmethod + def normalExecutioner(command): + try: + res = subprocess.call(shlex.split(command)) + if res == 0: + return 1 + else: + return 0 + except BaseException, msg: + return 0 + + @staticmethod + def SendEmail(message): + sender = 'info@designti01.cyberhosting.org' + receivers = ['jeanftellier@gmail.com', 'jeanftellier@gmail.com'] + + try: + smtpObj = smtplib.SMTP('127.0.0.1') + smtpObj.sendmail(sender, receivers, message) + print "Successfully sent email" + except BaseException, msg: + print "Error: unable to send email %s" % str(msg) + + @staticmethod + def SyncHome(): + command = 'rsync -avz /home /mnt/HC_Volume_2760413' + BackupUtil.normalExecutioner(command) + message = "/home successfully synced on %s" % (time.strftime("%I-%M-%S-%a-%b-%Y")) + BackupUtil.SendEmail(message) + + @staticmethod + def BackupDBS(): + command = "/usr/local/CyberCP/ApachController/backup.sh" + BackupUtil.normalExecutioner(command) + + message = "Database backups successfully generated on %s" % (time.strftime("%I-%M-%S-%a-%b-%Y")) + BackupUtil.SendEmail(message) + + @staticmethod + def MoveAllBackups(): + + for virtualHost in os.listdir("/home"): + completePath = "/home/%s/backup/" % (virtualHost) + command = "mv %s %s" % (completePath + '*.tar.gz', '/home/backup/') + subprocess.call(command, shell=True) + + + + +def main(): + + parser = argparse.ArgumentParser(description='CyberPanel Backup tool.') + parser.add_argument('function', help='Specific a function to call!') + args = parser.parse_args() + + if args.function == "home": + BackupUtil.SyncHome() + elif args.function == "db": + BackupUtil.BackupDBS() + elif args.function == "sync": + BackupUtil.MoveAllBackups() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/ApachController/__init__.py b/ApachController/__init__.py new file mode 100755 index 000000000..e69de29bb diff --git a/ApachController/backup.sh b/ApachController/backup.sh new file mode 100644 index 000000000..adb321633 --- /dev/null +++ b/ApachController/backup.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +USER="root" +PASSWORD="1d1bb076c3bd9ae9ef545e3eafb1a35c68d3c5f4a6c03862" +#OUTPUT="/Users/rabino/DBs" +cd /mnt/HC_Volume_2760413 + +#rm "$OUTPUTDIR/*gz" > /dev/null 2>&1 + +databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` +mkdir `date +%Y%m%d` + +for db in $databases; do + if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then + echo "Dumping database: $db" + mysqldump -u $USER -p$PASSWORD --databases $db > `date +%Y%m%d`/`date +%Y%m%d`.$db.sql + # gzip $OUTPUT/`date +%Y%m%d`.$db.sql + fi +done \ No newline at end of file diff --git a/ApachController/phpApache.xml b/ApachController/phpApache.xml new file mode 100755 index 000000000..cec7cb74a --- /dev/null +++ b/ApachController/phpApache.xml @@ -0,0 +1,459 @@ + + + + php%s-php-zstd + : Zstd Extension for PHP + 1 + + + + php%s-php-zephir-parser + Zephir parser extension + 0 + + + + php%s-php-xmlrpc + A module for PHP applications which use the XML-RPC + 0 + + + + php%s-php-xml + A module for PHP applications which use XML + 1 + + + + php%s-php-xcache + Fast, stable PHP opcode cacher + 0 + + + + php%s-php-twig + The flexible, fast, and secure template engine for PHP + 1 + + + + php%s-php-tidy + Standard PHP module provides tidy library support + 1 + + + + php%s-php-tarantool + PHP driver for Tarantool/Box + 1 + + + + php%s-php-suhosin + Suhosin is an advanced protection system for PHP + 1 + + + + php%s-php-soap + A module for PHP applications that use the SOAP protocol + 1 + + + + php%s-php-snmp + A module for PHP applications that query SNMP-managed devices + 1 + + + + php%s-php-snappy + Snappy Extension for PHP + 1 + + + + php%s-php-smbclient + PHP wrapper for libsmbclient + 1 + + + + php%s-php-recode + A module for PHP applications for using the recode library + 0 + + + + php%s-php-pspell + A module for PHP applications for using pspell interfaces + 1 + + + + php%s-php-process + Modules for PHP script using system process interfaces + 1 + + + + php%s-php-pimple + A simple dependency injection container for PHP Extensions + 1 + + + + php%s-php-phurple + PHP bindings for libpurple + 0 + + + + php%s-php-phpiredis + Client extension for Redis + 0 + + + + php%s-php-phalcon3 + Phalcon Framework + 0 + + + + php%s-php-pgsql + A PostgreSQL database module for PHP + 1 + + + + php%s-php-pecl-zmq + ZeroMQ messaging + 0 + + + + php%s-php-pecl-zip + Une extension de gestion des ZIP + 0 + + + + php%s-php-pecl-yp + YP/NIS functions + 0 + + + + php%s-php-pecl-yaz + Z39.50/SRU client + 0 + + + + php%s-php-pecl-yar + Light, concurrent RPC framework + 0 + + + + php%s-php-pecl-yaml + PHP Bindings for yaml + 0 + + + + php%s-php-pecl-yaf + Extension to work with the Memcached caching daemon. + 0 + + + + php%s-php-pecl-yac + Yet Another Framework + 0 + + + + php%s-php-pecl-yac + Lockless user data cache + 0 + + + + php%s-php-pecl-xxtea + XXTEA encryption algorithm extension for PHP + 0 + + + + php%s-php-pecl-xslcache + XSL extension that caches the parsed XSL style sheet + 0 + + + + php%s-php-pecl-xrange + Numeric iterator primitives + 0 + + + + php%s-php-pecl-xmp + Bindings for the libxmp library + 0 + + + + php%s-php-pecl-xmldiff + XML diff and merge. + 0 + + + + php%s-php-pecl-xhprof + PHP extension for XHProf, a Hierarchical Profiler + 0 + + + + php%s-php-pecl-xdiff + File differences/patches. + 0 + + + + php%s-php-pecl-xdebug + PECL package for debugging PHP scripts + 0 + + + + php%s-php-pecl-xattr + Extended attributes + 0 + + + + php%s-php-pecl-wxwidgets + Cross-platform widget toolkit + 0 + + + + php%s-php-pecl-weakref + Implementation of weak references + 0 + + + + php%s-php-pecl-vld + Dump the internal representation of PHP scripts + 0 + + + + php%s-php-pecl-varnish + Varnish Cache bindings + 0 + + + + php%s-php-pear.noarch + PHP Extension and Application Repository framework + 1 + + + + php%s-php-pdo + A database access abstraction module for PHP applications + 1 + + + + php%s-php-opcache + The Zend OPcache + 0 + + + + php%s-php-odbc + A module for PHP applications that use ODBC databases + 1 + + + + php%s-php-oci8 + A module for PHP applications that use OCI8 databases + 1 + + + + php%s-php-mysqlnd + A module for PHP applications that use MySQL Database + 1 + + + + php%s-php-mssql + MSSQL database module for PHP + 1 + + + + php%s-php-mcrypt + Standard PHP module provides mcrypt library support + 1 + + + + php%s-php-mbstring + A module for PHP applications which need multi-byte String handle + 1 + + + + php%s-php-maxminddb + MaxMind DB Reader extension + 1 + + + + php%s-php-magickwand + PHP API for ImageMagick + 0 + + + + php%s-php-lz4 + LZ4 Extension for PHP + 0 + + + + php%s-php-libvirt-doc + Document of php-libvirt + 0 + + + + php%s-php-libvirt + PHP language binding for Libvirt + 0 + + + + php%s-php-ldap + A module for PHP applications that use LDAP + 0 + + + + php%s-php-ioncube-loader + Loader for ionCube Encoded Files with ionCube + 0 + + + + php%s-php-intl + Internationalization extension for PHP applications + 1 + + + + php%s-php-interbase + A module for PHP applications that use Interbase/Firebird databases + 0 + + + + php%s-php-imap + A module for PHP applications that use IMAPs + 1 + + + + php%s-php-horde-horde-lz4 + Horde LZ4 Compression Extension + 0 + + + + php%s-php-gmp + A module for PHP applications for using the GNU MP library + 0 + + + + php%s-php-geos + PHP module for GEOS + 0 + + + + php%s-php-gd + A module for PHP applications for using the gd graphics library + 0 + + + + php%s-php-enchant + Enchant spelling extension for PHP applications + 0 + + + + php%s-php-embedded + PHP library for embedding in applications + 0 + + + + php%s-php-devel + Files needed for building PHP extensions + 0 + + + + php%s-php-dbg + The interactive PHP debugger + 0 + + + + php%s-php-dba + A database abstraction layer module for PHP applications + 0 + + + + php%s-php-common + Common files for PHP + 1 + + + + php%s-php-cli + Command-line interface for PHP + 0 + + + + php%s-php-channel-horde.noarch + Adds pear.horde.org channel to PEAR + 0 + + + + php%s-php-brotli + Brotli Extension for PHP + 0 + + + + php%s-php-bcmath + A module for PHP applications for using the bcmath library + 1 + + + \ No newline at end of file