Commit c958d290 authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Add support for punycode, some bug fixing

parent 4ac190ef
Pipeline #169 skipped
import datetime, os, setuptools, socketserver, ssltools, sys, syslog, threading
import datetime, encodings, os, setuptools, socketserver, ssltools, sys, syslog, threading
SYSLOG = 0
STDOUT = 1
......@@ -8,7 +8,12 @@ SILENT = 9 # Quiet mode
SSL = 0
PORT = 1
exec("logging = %s or STDOUT" % setuptools.getSetting("Log", "sink"))
logging = STDOUT
try:
exec("logging = " + setuptools.getSetting("Log", "sink"))
except:
pass
def logger(message, prio=syslog.LOG_INFO, sink=logging):
if sink in (STDOUT, STDDEB):
......@@ -56,11 +61,13 @@ class TCPHandler(socketserver.StreamRequestHandler):
return "UA: Not currently implemented."
elif command in ("ssl", "tls"):
try:
if listIncluded(str(content[1]), SSL):
try:
expiry = ssltools.getRemoteExpiry(str(content[1]), int(content[2]))
except:
expiry = ssltools.getRemoteExpiry(str(content[1]), 443)
host = encodings.idna.ToASCII(str(content[1]))
try:
port = int(content[2])
except IndexError:
port = 443
if listIncluded(host, SSL):
expiry = ssltools.getRemoteExpiry(host, port)
if expiry > datetime.datetime.now():
dm = "%s certificate is valid until: %s" % (content[1], expiry)
try:
......@@ -71,13 +78,11 @@ class TCPHandler(socketserver.StreamRequestHandler):
return "AL: %s" % dm
return "OK: %s" % dm
else:
return "AL: %s certificate has expired! Please renew ASAP! - %s" % (content[1], expiry)
return "AL: %s certificate has expired on: %s" % (content[1], expiry)
else:
return "NM: %s is not being monitored!" % content[1]
except TypeError:
raise
except:
return "ER: Could not verify SSL certificate on %s:%i. Is the server down?" % (content[1], content[2])
return "ER: Could not verify SSL certificate on %s:%i. Is the server down?" % (content[1], int(content[2]))
elif command == "port":
return "UA: Not currently implemented."
elif command in ("req", "request"):
......@@ -86,9 +91,9 @@ class TCPHandler(socketserver.StreamRequestHandler):
return "UA: Not currently implemented."
else:
return "IM: Unknown command %s." % command
except TypeError:
except TypeError as e:
return "IM: Invalid values passed to %s. Try HELP %s." % (command, command)
except IndexError:
except IndexError as e:
return "IM: Invalid values passed to %s. Try HELP %s." % (command, command)
def handle(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment