Finalize SSL command implementation

This commit is contained in:
Klaus-Uwe Mitterer 2016-07-20 18:17:06 +02:00
parent 3690c8ec95
commit 4ac190ef23
1 changed files with 18 additions and 8 deletions

View File

@ -30,7 +30,7 @@ def logger(message, prio=syslog.LOG_INFO, sink=logging):
def listIncluded(host, section):
for i in setuptools.getListSetting("SSL" if section == 0 else "Ports", "hosts"):
if i[0] == host:
if i[0].lower() == host.lower():
return True
return False
@ -57,11 +57,21 @@ class TCPHandler(socketserver.StreamRequestHandler):
elif command in ("ssl", "tls"):
try:
if listIncluded(str(content[1]), SSL):
expiry = ssltools.getRemoteExpiry(str(content[1]), int(content[2]))
try:
expiry = ssltools.getRemoteExpiry(str(content[1]), int(content[2]))
except:
expiry = ssltools.getRemoteExpiry(str(content[1]), 443)
if expiry > datetime.datetime.now():
return "OK: %s certificate is valid until %s." % (content[1], expiry)
elif expiry < datetime.datetime.now():
return "AL: %s certificate has expired! (%s) Please renew ASAP!" % (content[1], expiry)
dm = "%s certificate is valid until: %s" % (content[1], expiry)
try:
delta = int(content[3])
except:
delta = 0
if expiry < datetime.datetime.now() + datetime.timedelta(days=delta):
return "AL: %s" % dm
return "OK: %s" % dm
else:
return "AL: %s certificate has expired! Please renew ASAP! - %s" % (content[1], expiry)
else:
return "NM: %s is not being monitored!" % content[1]
except TypeError:
@ -76,10 +86,10 @@ class TCPHandler(socketserver.StreamRequestHandler):
return "UA: Not currently implemented."
else:
return "IM: Unknown command %s." % command
# except TypeError:
# return "IM: Invalid values passed to %s." % command
except TypeError:
return "IM: Invalid values passed to %s. Try HELP %s." % (command, command)
except IndexError:
return "IM: Invalid values passed to %s." % command
return "IM: Invalid values passed to %s. Try HELP %s." % (command, command)
def handle(self):
remote = self.client_address[0] + ":" + str(self.client_address[1])