diff -r 362039519454 -r 7dd551ac2fa0 runtime/Stunnel.py --- a/runtime/Stunnel.py Thu Mar 07 21:57:18 2019 +0100 +++ b/runtime/Stunnel.py Mon Mar 11 01:03:32 2019 +0100 @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os from binascii import b2a_hqx try: @@ -5,14 +6,15 @@ except ImportError: from subprocess import call -restart_stunnel_cmdline = ["/etc/init.d/S50stunnel","restart"] +restart_stunnel_cmdline = ["/etc/init.d/S50stunnel", "restart"] _PSKpath = None + def PSKgen(ID, PSKpath): # b2a_hqx output len is 4/3 input len - secret = os.urandom(192) # int(256/1.3333) + secret = os.urandom(192) # int(256/1.3333) secretstring = b2a_hqx(secret) PSKstring = ID+":"+secretstring @@ -20,6 +22,7 @@ f.write(PSKstring) call(restart_stunnel_cmdline) + def ensurePSK(ID, PSKpath): global _PSKpath _PSKpath = PSKpath @@ -28,14 +31,14 @@ # create if needed PSKgen(ID, PSKpath) -def getPSKID(): - if _PSKpath is not None : + +def getPSKID(errorlog): + if _PSKpath is not None: if not os.path.exists(_PSKpath): - confnodesroot.logger.write_error( + errorlog( 'Error: Pre-Shared-Key Secret in %s is missing!\n' % _PSKpath) return None - ID,_sep,PSK = open(_PSKpath).read().partition(':') + ID, _sep, PSK = open(_PSKpath).read().partition(':') PSK = PSK.rstrip('\n\r') - return (ID,PSK) + return (ID, PSK) return None -