Edouard@2321: import os Edouard@2321: from binascii import hexlify Edouard@2321: Edouard@2321: restart_stunnel_cmdline = ["/etc/init.d/S50stunnel","restart"] Edouard@2321: Edouard@2321: def pskgen(ID, pskpath): Edouard@2321: secretstring = hexlify(os.urandom(256)) Edouard@2321: pskstring = ID+":"+secretstring Edouard@2321: with open(pskpath, 'w') as f: Edouard@2321: f.write(pskstring) Edouard@2321: call(restart_stunnel_cmdline) Edouard@2321: Edouard@2321: def ensurepsk(ID, pskpath): Edouard@2321: # check if already there Edouard@2321: if not os.path.exists(pskpath): Edouard@2321: # create if needed Edouard@2321: pskgen(IS, pskpath) Edouard@2321: