apache as backend

This commit is contained in:
usman@cyberpersons.com
2023-05-15 12:19:42 +05:00
parent 5a7eb5133d
commit 4b01e23e07
5 changed files with 263 additions and 124 deletions

View File

@@ -4,6 +4,7 @@ import subprocess
import shlex
import plogical.CyberCPLogFileWriter as logging
from ApachController.ApacheVhosts import ApacheVhost
from plogical.processUtilities import ProcessUtilities
class ApacheController:
@@ -102,22 +103,25 @@ LoadModule mpm_event_module modules/mod_mpm_event.so
def InstallApache():
try:
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
command = "yum install -y httpd httpd-tools mod_ssl php-fpm"
if ApacheController.executioner(command) == 0:
else:
command = "apt update -y && sudo apt upgrade -y && apt install apache2 -y"
if ProcessUtilities.executioner(command, None, True) == 0:
return "Failed to install Apache and PHP-FPM."
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
command = "yum -y install centos-release-scl yum-utils"
if ApacheController.executioner(command) == 0:
if ProcessUtilities.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:
if ProcessUtilities.executioner(command) == 0:
return "Failed to --enable rhel-server-rhscl-7-rpms"
## Minor Configuration changes.
sslPath = "/etc/httpd/conf.d/ssl.conf"
sslPath = "/etc/apache2/conf.d/ssl.conf"
if os.path.exists(sslPath):
os.remove(sslPath)
@@ -144,15 +148,51 @@ LoadModule mpm_event_module modules/mod_mpm_event.so
# MPM Module Configurations
writeToFile = open(ApacheController.mpmConfigsPath , 'w')
writeToFile = open(ApacheController.mpmConfigsPath, 'w')
writeToFile.write(ApacheController.mpmConfigs)
writeToFile.close()
else:
sslPath = "/etc/httpd/conf.d/ssl.conf"
confPath = ApacheVhost.serverRootPath + "/apache2.conf"
portsPath = '/etc/apache2/ports.conf'
WriteToFile = open(portsPath, 'w')
WriteToFile.write('Listen 8081\nListen 8082\n')
WriteToFile.close()
command = f"sed -i 's/User ${{APACHE_RUN_USER}}/User nobody/g' {confPath}"
if ProcessUtilities.executioner(command, None, True) == 0:
return "Apache run user change failed"
command = f"sed -i 's/Group ${{APACHE_RUN_GROUP}}/Group nogroup/g' {confPath}"
if ProcessUtilities.executioner(command, None, True) == 0:
return "Apache run group change failed"
command = 'apt-get install apache2-suexec-pristine -y'
if ProcessUtilities.executioner(command, None, True) == 0:
return "Apache run apache2-suexec-pristine"
command = 'a2enmod suexec proxy ssl proxy_fcgi proxy'
if ProcessUtilities.executioner(command, None, True) == 0:
return "Apache run suexec proxy ssl"
###
command = "systemctl start httpd.service"
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
serviceName = 'httpd'
else:
serviceName = 'apache2'
command = f"systemctl start {serviceName}.service"
ApacheController.executioner(command)
command = "systemctl enable httpd.service"
command = f"systemctl enable {serviceName}.service"
ApacheController.executioner(command)
return 1
@@ -164,6 +204,8 @@ LoadModule mpm_event_module modules/mod_mpm_event.so
def phpVersions():
# Version 5.4
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
command = 'yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm'
ApacheController.executioner(command)
@@ -241,6 +283,21 @@ LoadModule mpm_event_module modules/mod_mpm_event.so
if ApacheController.executioner(command) == 0:
return "Failed to install php73-fpm"
else:
command = 'apt install python-software-properties -y'
if ProcessUtilities.executioner(command, None, True) == 0:
return "Failed to install python-software-properties"
command = 'add-apt-repository ppa:ondrej/php -y'
if ProcessUtilities.executioner(command, None, True) == 0:
return "Failed to ppa:ondrej/php"
command = "sudo apt-get install -y php-fpm php7.4-fpm php8.0-fpm php7.4-mysql php7.4-curl php7.4-gd php7.4-mbstring php7.4-xml php7.4-zip php8.0-mysql php8.0-curl php8.0-gd php8.0-mbstring php8.0-xml php8.0-zip"
if ProcessUtilities.executioner(command, None, True) == 0:
return "Failed to install Apache and PHP-FPM."
try:
wwwConfPath = ApacheVhost.php54Path + "/www.conf"

View File

@@ -16,9 +16,11 @@ import re
class ApacheVhost:
apacheInstallStatusPath = '/home/cyberpanel/apacheInstallStatus'
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
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/'
@@ -26,8 +28,33 @@ class ApacheVhost:
php71Path = '/etc/opt/remi/php71/php-fpm.d/'
php72Path = '/etc/opt/remi/php72/php-fpm.d/'
php73Path = '/etc/opt/remi/php73/php-fpm.d/'
else:
serverRootPath = '/etc/apache2'
configBasePath = '/etc/apache2/sites-enabled/'
php54Path = '/etc/php/5.4/fpm/pool.d/'
php55Path = '/etc/php/5.5/fpm/pool.d/'
php56Path = '/etc/php/5.6/fpm/pool.d/'
php70Path = '/etc/php/7.0/fpm/pool.d/'
php71Path = '/etc/php/7.1/fpm/pool.d/'
php72Path = '/etc/php/7.2/fpm/pool.d/'
php73Path = '/etc/php/7.3/fpm/pool.d/'
php74Path = '/etc/php/7.4/fpm/pool.d/'
php80Path = '/etc/php/8.0/fpm/pool.d/'
php81Path = '/etc/php/8.1/fpm/pool.d/'
php82Path = '/etc/php/8.2/fpm/pool.d/'
lswsMainConf = "/usr/local/lsws/conf/httpd_config.conf"
count = 0
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
sslBasePath = "/etc/httpd/conf.d/ssl/"
else:
sslBasePath = "/etc/apache2/conf-enabled/"
@staticmethod
def DecidePHPPath(php, virtualHostName):
@@ -45,6 +72,14 @@ class ApacheVhost:
finalConfPath = ApacheVhost.php72Path + virtualHostName
elif php == '73':
finalConfPath = ApacheVhost.php73Path + virtualHostName
elif php == '74':
finalConfPath = ApacheVhost.php74Path + virtualHostName
elif php == '80':
finalConfPath = ApacheVhost.php80Path + virtualHostName
elif php == '81':
finalConfPath = ApacheVhost.php81Path + virtualHostName
elif php == '82':
finalConfPath = ApacheVhost.php82Path + virtualHostName
return finalConfPath + '.conf'
@@ -74,6 +109,18 @@ class ApacheVhost:
if os.path.exists(ApacheVhost.php73Path + virtualHostName):
return ApacheVhost.php73Path + virtualHostName
if os.path.exists(ApacheVhost.php74Path + virtualHostName):
return ApacheVhost.php74Path + virtualHostName
if os.path.exists(ApacheVhost.php80Path + virtualHostName):
return ApacheVhost.php80Path + virtualHostName
if os.path.exists(ApacheVhost.php81Path + virtualHostName):
return ApacheVhost.php81Path + virtualHostName
if os.path.exists(ApacheVhost.php82Path + virtualHostName):
return ApacheVhost.php82Path + virtualHostName
@staticmethod
def GenerateSelfSignedSSL(virtualHostName):
if os.path.exists(ApacheVhost.sslBasePath):
@@ -90,6 +137,11 @@ class ApacheVhost:
def perHostVirtualConf(administratorEmail,externalApp, virtualHostUser, phpVersion, virtualHostName):
try:
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
sockPath = '/var/run/php-fpm/'
else:
sockPath = '/var/run/php/'
## Non-SSL Conf
finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf'
@@ -104,6 +156,7 @@ class ApacheVhost:
currentConf = currentConf.replace('{php}', php)
currentConf = currentConf.replace('{adminEmails}', administratorEmail)
currentConf = currentConf.replace('{externalApp}', virtualHostUser)
currentConf = currentConf.replace('{sockPath}', sockPath)
confFile.write(currentConf)
confFile.close()
@@ -122,6 +175,8 @@ class ApacheVhost:
currentConf = currentConf.replace('{php}', php)
currentConf = currentConf.replace('{adminEmails}', administratorEmail)
currentConf = currentConf.replace('{externalApp}', virtualHostUser)
currentConf = currentConf.replace('{SSLBase}', ApacheVhost.sslBasePath)
currentConf = currentConf.replace('{sockPath}', sockPath)
confFile.write(currentConf)
confFile.close()
@@ -135,6 +190,7 @@ class ApacheVhost:
currentConf = currentConf.replace('{www}', virtualHostUser)
currentConf = currentConf.replace('{Sock}', virtualHostName)
currentConf = currentConf.replace('{externalApp}', externalApp)
currentConf = currentConf.replace('{sockPath}', sockPath)
confFile.write(currentConf)
@@ -204,6 +260,11 @@ class ApacheVhost:
## Non - SSL Conf
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
sockPath = '/var/run/php-fpm/'
else:
sockPath = '/var/run/php/'
finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf'
confFile = open(finalConfPath, "w+")
@@ -216,6 +277,7 @@ class ApacheVhost:
currentConf = currentConf.replace('{adminEmails}', administratorEmail)
currentConf = currentConf.replace('{externalApp}', virtualHostUser)
currentConf = currentConf.replace('{path}', path)
currentConf = currentConf.replace('{sockPath}', sockPath)
confFile.write(currentConf)
confFile.close()
@@ -234,6 +296,8 @@ class ApacheVhost:
currentConf = currentConf.replace('{adminEmails}', administratorEmail)
currentConf = currentConf.replace('{externalApp}', virtualHostUser)
currentConf = currentConf.replace('{path}', path)
currentConf = currentConf.replace('{sockPath}', sockPath)
currentConf = currentConf.replace('{SSLBase}', ApacheVhost.sslBasePath)
confFile.write(currentConf)
confFile.close()
@@ -247,6 +311,7 @@ class ApacheVhost:
currentConf = currentConf.replace('{www}', "".join(re.findall("[a-zA-Z]+", virtualHostName))[:7])
currentConf = currentConf.replace('{Sock}', virtualHostName)
currentConf = currentConf.replace('{externalApp}', externalApp)
currentConf = currentConf.replace('{sockPath}', sockPath)
confFile.write(currentConf)

View File

@@ -221,7 +221,7 @@ context /.well-known/acme-challenge {
ServerAdmin {administratorEmail}
SuexecUserGroup {externalApp} {externalApp}
DocumentRoot /home/{virtualHostName}/public_html/
<Proxy "unix:/var/run/php-fpm/{virtualHostName}.sock|fcgi://php-fpm-{externalApp}">
<Proxy "unix:{sockPath}{virtualHostName}.sock|fcgi://php-fpm-{externalApp}">
ProxySet disablereuse=off
</proxy>
<FilesMatch \.php$>
@@ -246,7 +246,7 @@ context /.well-known/acme-challenge {
ServerAdmin {administratorEmail}
SuexecUserGroup {externalApp} {externalApp}
DocumentRoot /home/{virtualHostName}/public_html/
<Proxy "unix:/var/run/php-fpm/{virtualHostName}.sock|fcgi://php-fpm-{externalApp}">
<Proxy "unix:{sockPath}{virtualHostName}.sock|fcgi://php-fpm-{externalApp}">
ProxySet disablereuse=off
</proxy>
<FilesMatch \.php$>
@@ -264,8 +264,8 @@ context /.well-known/acme-challenge {
SSLEngine on
SSLVerifyClient none
SSLCertificateFile /etc/httpd/conf.d/ssl/{virtualHostName}.fullchain.pem
SSLCertificateKeyFile /etc/httpd/conf.d/ssl/{virtualHostName}.privkey.pem
SSLCertificateFile {SSLBase}{virtualHostName}.fullchain.pem
SSLCertificateKeyFile {SSLBase}{virtualHostName}.privkey.pem
</VirtualHost>
"""
@@ -276,7 +276,7 @@ context /.well-known/acme-challenge {
ServerAdmin {administratorEmail}
SuexecUserGroup {externalApp} {externalApp}
DocumentRoot {path}
<Proxy "unix:/var/run/php-fpm/{virtualHostName}.sock|fcgi://php-fpm-{externalApp}">
<Proxy "unix:{sockPath}{virtualHostName}.sock|fcgi://php-fpm-{externalApp}">
ProxySet disablereuse=off
</proxy>
<FilesMatch \.php$>
@@ -301,7 +301,7 @@ context /.well-known/acme-challenge {
ServerAdmin {administratorEmail}
SuexecUserGroup {externalApp} {externalApp}
DocumentRoot {path}
<Proxy "unix:/var/run/php-fpm/{virtualHostName}.sock|fcgi://php-fpm-{externalApp}">
<Proxy "unix:{sockPath}{virtualHostName}.sock|fcgi://php-fpm-{externalApp}">
ProxySet disablereuse=off
</proxy>
<FilesMatch \.php$>
@@ -318,8 +318,8 @@ context /.well-known/acme-challenge {
</Directory>
SSLEngine on
SSLVerifyClient none
SSLCertificateFile /etc/httpd/conf.d/ssl/{virtualHostName}.fullchain.pem
SSLCertificateKeyFile /etc/httpd/conf.d/ssl/{virtualHostName}.privkey.pem
SSLCertificateFile {SSLBase}{virtualHostName}.fullchain.pem
SSLCertificateKeyFile {SSLBase}{virtualHostName}.privkey.pem
</VirtualHost>
"""
@@ -383,7 +383,7 @@ REWRITERULE ^(.*)$ HTTP://proxyApacheBackendSSL/$1 [P,L]
"""
phpFpmPool = """[{www}]
listen = /var/run/php-fpm/{Sock}.sock
listen = {sockPath}{Sock}.sock
listen.owner = nobody
listen.group = nobody
listen.mode = 0660
@@ -396,7 +396,7 @@ pm.min_spare_servers = 1
pm.max_spare_servers = 1
"""
phpFpmPoolReplace = """[{www}]
listen = /var/run/php-fpm/{Sock}.sock
listen = {sockPath}{Sock}.sock
listen.owner = nobody
listen.group = nobody
listen.mode = 0660

View File

@@ -2405,7 +2405,7 @@ app.controller('createWebsite', function ($scope, $http, $timeout, $window) {
$scope.currentStatus = "Starting creation..";
var ssl, dkimCheck, openBasedir, mailDomain;
var ssl, dkimCheck, openBasedir, mailDomain, apacheBackend;
if ($scope.sslCheck === true) {
ssl = 1;
@@ -2413,6 +2413,12 @@ app.controller('createWebsite', function ($scope, $http, $timeout, $window) {
ssl = 0
}
if ($scope.apacheBackend === true) {
apacheBackend = 1;
} else {
apacheBackend = 0
}
if ($scope.dkimCheck === true) {
dkimCheck = 1;
} else {
@@ -2461,9 +2467,11 @@ app.controller('createWebsite', function ($scope, $http, $timeout, $window) {
websiteOwner: websiteOwner,
dkimCheck: dkimCheck,
openBasedir: openBasedir,
mailDomain: mailDomain
mailDomain: mailDomain,
apacheBackend: apacheBackend
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')

View File

@@ -254,6 +254,15 @@
</div>
</div>
<label class="col-sm-3 control-label"></label>
<div class="col-sm-9">
<div class="checkbox">
<label>
<input ng-model="apacheBackend" type="checkbox" value="">
Apache as Backend
</label>
</div>
</div>
<label class="col-sm-3 control-label"></label>
<div class="col-sm-9">
<div class="checkbox">
<label>