mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 08:16:11 +01:00
apache manager
This commit is contained in:
@@ -29,6 +29,8 @@ class ApacheVhost:
|
||||
php72Path = '/etc/opt/remi/php72/php-fpm.d/'
|
||||
php73Path = '/etc/opt/remi/php73/php-fpm.d/'
|
||||
|
||||
serviceName = 'httpd'
|
||||
|
||||
else:
|
||||
serverRootPath = '/etc/apache2'
|
||||
configBasePath = '/etc/apache2/sites-enabled/'
|
||||
@@ -46,6 +48,8 @@ class ApacheVhost:
|
||||
php81Path = '/etc/php/8.1/fpm/pool.d/'
|
||||
php82Path = '/etc/php/8.2/fpm/pool.d/'
|
||||
|
||||
serviceName = 'apache2'
|
||||
|
||||
|
||||
|
||||
lswsMainConf = "/usr/local/lsws/conf/httpd_config.conf"
|
||||
@@ -139,8 +143,10 @@ class ApacheVhost:
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
sockPath = '/var/run/php-fpm/'
|
||||
group = 'nobody'
|
||||
else:
|
||||
sockPath = '/var/run/php/'
|
||||
group = 'nogroup'
|
||||
|
||||
## Non-SSL Conf
|
||||
|
||||
@@ -191,12 +197,13 @@ class ApacheVhost:
|
||||
currentConf = currentConf.replace('{Sock}', virtualHostName)
|
||||
currentConf = currentConf.replace('{externalApp}', externalApp)
|
||||
currentConf = currentConf.replace('{sockPath}', sockPath)
|
||||
currentConf = currentConf.replace('{group}', group)
|
||||
|
||||
confFile.write(currentConf)
|
||||
|
||||
ApacheVhost.GenerateSelfSignedSSL(virtualHostName)
|
||||
|
||||
command = "systemctl restart httpd"
|
||||
command = f"systemctl restart {ApacheVhost.serviceName}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
return [1, 'None']
|
||||
@@ -262,8 +269,10 @@ class ApacheVhost:
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
sockPath = '/var/run/php-fpm/'
|
||||
group = 'nobody'
|
||||
else:
|
||||
sockPath = '/var/run/php/'
|
||||
group = 'nogroup'
|
||||
|
||||
finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf'
|
||||
confFile = open(finalConfPath, "w+")
|
||||
@@ -312,12 +321,13 @@ class ApacheVhost:
|
||||
currentConf = currentConf.replace('{Sock}', virtualHostName)
|
||||
currentConf = currentConf.replace('{externalApp}', externalApp)
|
||||
currentConf = currentConf.replace('{sockPath}', sockPath)
|
||||
currentConf = currentConf.replace('{group}', group)
|
||||
|
||||
confFile.write(currentConf)
|
||||
|
||||
ApacheVhost.GenerateSelfSignedSSL(virtualHostName)
|
||||
|
||||
command = "systemctl restart httpd"
|
||||
command = f"systemctl restart {ApacheVhost.serviceName}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
return [1, 'None']
|
||||
@@ -326,6 +336,7 @@ class ApacheVhost:
|
||||
|
||||
@staticmethod
|
||||
def setupApacheVhostChild(administratorEmail, externalApp, virtualHostUser, phpVersion, virtualHostName, path):
|
||||
|
||||
result = ApacheVhost.perHostVirtualConfChild(administratorEmail, externalApp, virtualHostUser, phpVersion,
|
||||
virtualHostName, path)
|
||||
if result[0] == 0:
|
||||
@@ -347,7 +358,7 @@ class ApacheVhost:
|
||||
|
||||
ApacheVhost.deletePHPPath(virtualHostName)
|
||||
|
||||
command = "systemctl restart httpd"
|
||||
command = f"systemctl restart {ApacheVhost.serviceName}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
except BaseException as msg:
|
||||
@@ -375,59 +386,154 @@ class ApacheVhost:
|
||||
phpPath = ApacheVhost.DecidePHPPath('54', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
command = "systemctl restart php%s-php-fpm" % ('54')
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php54-php-fpm'
|
||||
else:
|
||||
phpService = f"php5.4-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('55', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
|
||||
os.remove(phpPath)
|
||||
command = "systemctl restart php%s-php-fpm" % ('55')
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php55-php-fpm'
|
||||
else:
|
||||
phpService = f"php5.5-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('56', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
command = "systemctl restart php%s-php-fpm" % ('56')
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php56-php-fpm'
|
||||
else:
|
||||
phpService = f"php5.6-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('70', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
command = "systemctl restart php%s-php-fpm" % ('70')
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php70-php-fpm'
|
||||
else:
|
||||
phpService = f"php7.0-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('71', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
command = "systemctl restart php%s-php-fpm" % ('71')
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php71-php-fpm'
|
||||
else:
|
||||
phpService = f"php7.1-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('72', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
command = "systemctl restart php%s-php-fpm" % ('72')
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php72-php-fpm'
|
||||
else:
|
||||
phpService = f"php7.2-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('73', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
command = "systemctl restart php%s-php-fpm" % ('73')
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php73-php-fpm'
|
||||
else:
|
||||
phpService = f"php7.3-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('74', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php74-php-fpm'
|
||||
else:
|
||||
phpService = f"php7.4-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('80', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php80-php-fpm'
|
||||
else:
|
||||
phpService = f"php8.0-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('81', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php81-php-fpm'
|
||||
else:
|
||||
phpService = f"php8.1-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
phpPath = ApacheVhost.DecidePHPPath('82', virtualHostName)
|
||||
if os.path.exists(phpPath):
|
||||
os.remove(phpPath)
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php82-php-fpm'
|
||||
else:
|
||||
phpService = f"php8.2-fpm"
|
||||
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
@staticmethod
|
||||
def changePHP(phpVersion, vhFile):
|
||||
try:
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
sockPath = '/var/run/php-fpm/'
|
||||
group = 'nobody'
|
||||
else:
|
||||
sockPath = '/var/run/php/'
|
||||
group = 'nogroup'
|
||||
|
||||
virtualHostName = vhFile.split('/')[6]
|
||||
|
||||
finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf'
|
||||
|
||||
if not os.path.exists(finalConfPath):
|
||||
logging.writeToFile(f'Config path: {finalConfPath}')
|
||||
return 0
|
||||
|
||||
ApacheVhost.deletePHPPath(virtualHostName)
|
||||
|
||||
website = Websites.objects.get(domain=virtualHostName)
|
||||
try:
|
||||
website = Websites.objects.get(domain=virtualHostName)
|
||||
externalApp = website.externalApp
|
||||
except:
|
||||
child = ChildDomains.objects.get(domain=virtualHostName)
|
||||
externalApp = child.master.externalApp
|
||||
|
||||
php = PHPManager.getPHPString(phpVersion)
|
||||
|
||||
@@ -435,16 +541,26 @@ class ApacheVhost:
|
||||
|
||||
confFile = open(finalConfPath, "w+")
|
||||
currentConf = vhostConfs.phpFpmPool
|
||||
currentConf = currentConf.replace('{www}', website.externalApp)
|
||||
currentConf = currentConf.replace('{www}', externalApp)
|
||||
currentConf = currentConf.replace('{Sock}', virtualHostName)
|
||||
currentConf = currentConf.replace('{externalApp}', website.externalApp)
|
||||
currentConf = currentConf.replace('{externalApp}', externalApp)
|
||||
currentConf = currentConf.replace('{sockPath}', sockPath)
|
||||
currentConf = currentConf.replace('{group}', group)
|
||||
|
||||
confFile.write(currentConf)
|
||||
|
||||
command = "systemctl stop php%s-php-fpm" % (php)
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
phpService = f'php{php}-php-fpm'
|
||||
else:
|
||||
phpService = f"{phpVersion.replace(' ', '').lower()}-fpm"
|
||||
|
||||
command = f"systemctl stop {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
command = "systemctl restart php%s-php-fpm" % (php)
|
||||
command = f"systemctl restart {phpService}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
command = f"systemctl restart {ApacheVhost.serviceName}"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user