Commit 473a0d54 authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Checking in helpers for the server

parent d5841d2c
Pipeline #215 skipped
import ast, syslog, sys, setuptools, servertools, encodings.idna, os
logging = exec(setuptools.getSetting("Log", "sink")) or servertools.STDOUT
def logger(message, prio=syslog.LOG_INFO, sink=logging):
if sink in (servertools.STDOUT, servertools.STDDEB):
if prio not in (syslog.LOG_NOTICE, syslog.LOG_INFO, syslog.LOG_DEBUG):
print(message)
sys.stderr.write(message)
elif prio != syslog.LOG_DEBUG or sink == servertools.STDDEB:
print(message)
elif sink == servertools.SYSLOG:
syslog.openlog("KumiStatusServer", syslog.LOG_PID)
syslog.syslog(prio, message)
elif sink != servertools.SILENT:
try:
sys.stderr.write("Unknown logging level %s, assuming STDOUT from now on." % str(sink))
except:
pass
logging = servertools.STDOUT
logger(message, prio, logging)
def listIncluded(host, section):
if not setuptools.getListSetting("Server", "ignorelist"):
for i in setuptools.getListSetting("SSL" if section == servertools.SSL else "Ports", "hosts"):
if encodings.idna.ToASCII(i[0].lower()).decode("UTF-8") == encodings.idna.ToASCII(host.lower()).decode("UTF-8"):
return True
return False
return True
def normalizeHost(host):
return encodings.idna.ToASCII(str(host)).decode("UTF-8")
def shutdown(reboot = False, status = 0):
if reboot:
args = sys.argv[:]
args.insert(0, sys.executable)
try:
os.execv(sys.executable, args)
except:
logger("Restart failed. Shutting down.")
exit(status)
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