Checking in helpers for the server
This commit is contained in:
parent
d5841d2c80
commit
473a0d54c0
1 changed files with 42 additions and 0 deletions
42
servertools/helpers.py
Normal file
42
servertools/helpers.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
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)
|
Loading…
Reference in a new issue