Skip to content

Commit

Permalink
Add the check for F2B and fix the article links
Browse files Browse the repository at this point in the history
  • Loading branch information
MShport committed Aug 17, 2023
1 parent 3cecda3 commit 38515e2
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions 360-restrictions-check/360-restrictions-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
###############################################################################
# This script helps to check whether there are any restriction to add a server to Plesk 360
# Requirements : Python 2.7 or 3.x
# Version : 1.0
# Version : 1.1
#########

import subprocess
Expand Down Expand Up @@ -96,7 +96,7 @@ def prBlue(textToPrint):
getPleskHostname = 'plesk db -Nse "select val from misc where param = \'FullHostName\'"'
resolveIPList = []
commandC = 'curl --silent -I {} | grep Server | cut -f 2 -d ":"'
cArticle = "https://support.plesk.com/hc/en-us/articles/4408702163218"
cArticle = "https://support.plesk.com/hc/en-us/articles/13303705971095"

prBlue("=========================================================")
prBlue("Checking whether the server is behind Cloudflare:")
Expand Down Expand Up @@ -137,7 +137,7 @@ def prBlue(textToPrint):
checkAllowRule = False
positionAllowDrop = True
errFCode = False
fArticle = "https://support.plesk.com/hc/en-us/articles/115001078014"
fArticle = "https://support.plesk.com/hc/en-us/articles/12377519983511"

prBlue("================================")
prBlue("Checking firewall rules:")
Expand All @@ -154,7 +154,7 @@ def prBlue(textToPrint):
prRed("Otherwise, please check the firewall rules on your own")
printFunc()
elif not outData:
prGreen("There are no firewall restrictions for accessing Plesk UI via port 8443")
prGreen("There are no active firewall restrictions for accessing Plesk UI via port 8443")
printFunc()
else:
for line in outData.splitlines():
Expand Down Expand Up @@ -188,7 +188,7 @@ def prBlue(textToPrint):
prGreen("Access is allowed for the IP address" + "\033[93m {}\033[00m".format(ip))
break
elif checkAllowRule and allowRulePosition[0] == '0':
prGreen("There are no firewall restrictions for accessing Plesk UI via port 8443")
prGreen("There are no active firewall restrictions for accessing Plesk UI via port 8443")
elif checkAllowRule:
for ip in ipAddresses:
for sublist in listRules:
Expand Down Expand Up @@ -226,7 +226,54 @@ def prBlue(textToPrint):
prRed(">>> Here is the article for help: " + fArticle)

printFunc()



# Check Fail2Ban
errF2BCode = False
f2bArticle = "https://support.plesk.com/hc/en-us/articles/12377009252247"

prBlue("=========================================")
prBlue("Checking Fail2Ban logs:")
prBlue("=========================================")
printFunc()

commandCheckF2BLogs = 'cat /var/log/fail2ban.log'
commandCheckF2BTrusted = 'grep "ignoreip" /etc/fail2ban/jail.local'
f2bEntries = []

checkF2BLogs = subprocess.Popen(commandCheckF2BLogs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
outLogsData, errLogsData = checkF2BLogs.communicate()
checkF2BTrusted = subprocess.Popen(commandCheckF2BTrusted, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
outTrustedData, errTrustedData = checkF2BTrusted.communicate()

if errLogsData and not "No such file or directory" in errLogsData:
printFunc("ERROR: " + errData)
prRed("Please fix the issue and re-run this script")
prRed("Otherwise, please check the Fail2Ban logs on your own")
printFunc()
elif "No such file or directory" in errLogsData:
prRed("The file /var/log/fail2ban.log does not exist")
prRed("Fail2Ban may be disabled but it is recommended to double-check that manually")
else:
for line in outLogsData.splitlines():
f2bEntries.append(line)

if [item for entry in ipAddresses for item in f2bEntries if entry in item]:
for ip in ipAddresses:
if ip in outTrustedData:
prGreen("The trusted list of Fail2Ban contains the IP address" + "\033[93m {}\033[00m".format(ip))
elif any(ip in i for i in f2bEntries):
errF2BCode = True
prRed("The Fail2Ban log has records about the IP address" + "\033[93m {}\033[00m".format(ip))
else:
prGreen("Fail2Ban did not ban any of the IP addresses")

if errF2BCode:
printFunc()
prRed(">>> Here is the article for help: " + f2bArticle)

printFunc()


# Check administrative restrictions
noAdmRes = False
Expand All @@ -236,7 +283,7 @@ def prBlue(textToPrint):
excludeAllowList = []
ipCount = 0
errACode = False
aArticle = "https://support.plesk.com/hc/en-us/articles/115001881814"
aArticle = "https://support.plesk.com/hc/en-us/articles/12377478650647"

prBlue("===============================================================")
prBlue("Checking restrictions for administrative access rules:")
Expand Down Expand Up @@ -308,7 +355,7 @@ def prBlue(textToPrint):

# Check API
errApiCode = False
apiArticle = "https://support.plesk.com/hc/en-us/articles/360001125374"
apiArticle = "https://support.plesk.com/hc/en-us/articles/12377275665559"

prBlue("=========================================")
prBlue("Checking [api] section in panel.ini:")
Expand Down

0 comments on commit 38515e2

Please sign in to comment.