Skip to content

Commit

Permalink
Merge pull request #50 from M-Shport/360-phpfpm-plugin-conf
Browse files Browse the repository at this point in the history
Fix the availability check and improve results
  • Loading branch information
sibprogrammer authored Feb 6, 2024
2 parents 85d50f2 + a309c12 commit 327bc8a
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions 360-phpfpm-plugin-conf/360-phpfpm-plugin-conf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
### Copyright 1999-2022. Plesk International GmbH.
### Copyright 1999-2024. Plesk International GmbH.

###############################################################################
# This script helps to configure the PHP-FPM plugin for 360 Monitoring
# Requirements : Python 3.x
# Version : 1.2
# Version : 1.3
#########

from subprocess import Popen, call, PIPE
Expand All @@ -30,6 +30,7 @@
copyTemplate = 'cp -a /usr/local/psa/admin/conf/templates/default/domain/{0} /usr/local/psa/admin/conf/templates/custom/domain/{0}'
pleskLicenseCheck = 'plesk bin license -c'
getDomainList = 'plesk bin site -l'
checkIsResolved = 'plesk db -Nse "SELECT val FROM dom_param WHERE param = \'is_resolved\' AND dom_id = (SELECT id FROM domains WHERE name = \'{}\')"'
checkAvailability = 'curl -s -o /dev/null -w "%{{http_code}}" {}'


Expand Down Expand Up @@ -185,24 +186,34 @@ def fillTheLine(symbol, multiplier = 0):

# Check the availability of the domains and group them
for d in domainList:
statusCode = Popen(checkAvailability.format('https://' + d), stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
sCode = statusCode.stdout.readline()
if '30' in sCode:
statusCodeWww = Popen(checkAvailability.format('https://www.' + d), stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
sCodeWww = statusCodeWww.stdout.readline()
if '200' not in sCodeWww:
unavailableDomains.append(d)
elif '200' in sCode:
isResolved = Popen(checkIsResolved.format(d), stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
resolvedResult = isResolved.stdout.readline()
if 'true' not in resolvedResult:
unavailableDomains.append(d)
else:
nginxApachePhp = Popen(checkPHPServe.format(d), stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
serveBool = nginxApachePhp.stdout.readline()
if 'true' in serveBool:
nginxDomains.append(d)
elif 'false' in serveBool:
apacheDomains.append(d)
statusCode = Popen(checkAvailability.format('https://' + d), stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
sCode = statusCode.stdout.readline()
if '30' in sCode:
statusCodeWww = Popen(checkAvailability.format('https://www.' + d), stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
sCodeWww = statusCodeWww.stdout.readline()
if '200' in sCodeWww:
if 'true' in serveBool:
nginxDomains.append('www.' + d)
elif 'false' in serveBool:
apacheDomains.append('www.' + d)
else:
unavailableDomains.append(d)
elif '200' in sCode:
if 'true' in serveBool:
nginxDomains.append(d)
elif 'false' in serveBool:
apacheDomains.append(d)
else:
unavailableDomains.append(d)
else:
unavailableDomains.append(d)
else:
unavailableDomains.append(d)

if not nginxDomains and not apacheDomains:
prRed("There are no domains on this server")
Expand Down Expand Up @@ -297,8 +308,8 @@ def fillTheLine(symbol, multiplier = 0):
for d in (nginxDomains + apacheDomains):
isPHPAdditionalSettings = Popen(checkPHPAdditionalSettings.format(d), stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
if '0' in isPHPAdditionalSettings.stdout.readline():
printFunc(" Update PHP Settings for the domain " + d + "...")
callPhpUpdate = call(phpUpdate.format(d), stdout=PIPE, stderr=PIPE, shell=True)
printFunc(" Update PHP Settings for the domain " + d.replace('www.', '') + "...")
callPhpUpdate = call(phpUpdate.format(d.replace('www.', '')), stdout=PIPE, stderr=PIPE, shell=True)

printFunc()
prGreen("[+] The PHP Settings have been adjusted")
Expand Down Expand Up @@ -372,6 +383,20 @@ def fillTheLine(symbol, multiplier = 0):
printFunc()


# =========================================
# Show the results
# =========================================

prBlue(fillTheLine("="))
printFunc()
prBlue(fillTheLine("*", 57))
prBlue("The configuration was applied on:")
printFunc()
prGreen("Domains with Apache: {}".format(len(apacheDomains)))
prGreen("Domains with Nginx: {}".format(len(nginxDomains)))
prBlue(fillTheLine("*", 57))


# =========================================
# Show the list of the unavailable domains
# =========================================
Expand Down

0 comments on commit 327bc8a

Please sign in to comment.