1.1 --- a/encryptionprovider-package Tue Nov 04 18:26:39 2014 +0100
1.2 +++ b/encryptionprovider-package Mon Nov 10 14:45:01 2014 +0100
1.3 @@ -7,7 +7,7 @@
1.4 Standards-Version: 3.9.2
1.5
1.6 Package: encryptionprovider
1.7 -Version: 0.0.26
1.8 +Version: 0.0.29
1.9 Maintainer: ft <ft@x-net.at>
1.10 # Pre-Depends: <comma-separated list of packages>
1.11 Depends: python,python-requests,python-urllib3,python-netifaces,python-netaddr,python-webpy
2.1 Binary file encryptionprovider_0.0.27_all.deb has changed
3.1 Binary file encryptionprovider_0.0.28_all.deb has changed
4.1 Binary file encryptionprovider_0.0.29_all.deb has changed
5.1 --- a/passwordreceiver.py Tue Nov 04 18:26:39 2014 +0100
5.2 +++ b/passwordreceiver.py Mon Nov 10 14:45:01 2014 +0100
5.3 @@ -41,14 +41,53 @@
5.4 import os
5.5 import sys
5.6 import base64
5.7 -#import logging
5.8 +import thread
5.9 +import urllib3
5.10 +import netaddr
5.11
5.12 opensecurity_urls = (
5.13 '/password', 'os_password',
5.14 '/init', 'os_init'
5.15 )
5.16
5.17 -#__LOG = logging.getLogger("passwordreceiver")
5.18 +STATUS_CODE_OK = 200
5.19 +
5.20 +
5.21 +def sendDataToRest (urlpath, data):
5.22 + netifaces.ifaddresses("eth0")[2][0]["addr"]
5.23 +
5.24 + # Get first address in network (0 = network ip -> 192.168.0.0)
5.25 + remote_ip = netaddr.IPNetwork("%s/%s" %(netifaces.ifaddresses("eth0")[2][0]["addr"], netifaces.ifaddresses("eth0")[2][0]["netmask"]))[1]
5.26 +
5.27 + url = ("http://%s:8090//%s" %(remote_ip, urlpath))
5.28 +
5.29 + try:
5.30 + response = httpPool.request_encode_body("POST", url, fields=data, retries=0)
5.31 + except Exception, e:
5.32 + return
5.33 +
5.34 + if response.status == STATUS_CODE_OK:
5.35 + return True
5.36 + else:
5.37 + return False
5.38 +
5.39 +
5.40 +def sendNotification (type, message):
5.41 + data = {"msgtype" : type, "text" : message}
5.42 +
5.43 + if (type == "information"):
5.44 + sendDataToRest ("message", data)
5.45 + else:
5.46 + sendDataToRest ("notification", data)
5.47 +
5.48 +def sendInitialisationFailedError():
5.49 + sendNotification("critical", "Initialisation of the stick failed.")
5.50 +
5.51 +
5.52 +
5.53 +
5.54 +
5.55 +
5.56
5.57 class os_password:
5.58
5.59 @@ -108,30 +147,25 @@
5.60 os.remove(keyfilepath)
5.61
5.62 def runPreInitScript(self, preinitscript, device):
5.63 - #__LOG.debug("Start preinit Script")
5.64
5.65 command = [preinitscript, device]
5.66 process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
5.67 retval = process.wait()
5.68 ( stdout, stderr ) = process.communicate()
5.69
5.70 - #__LOG.debug("preinit done result: %s" %(retval,))
5.71 -
5.72 if (retval != 0):
5.73 raise web.badrequest(stderr)
5.74
5.75 def runPostInitScript(self, postinitscript):
5.76 - #__LOG.debug("Start postinit Script")
5.77 -
5.78 command = [postinitscript]
5.79 process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
5.80 retval = process.wait()
5.81 ( stdout, stderr ) = process.communicate()
5.82
5.83 - #__LOG.debug("postinit done result: %s" %(retval,))
5.84 -
5.85 if (retval != 0):
5.86 - raise web.badrequest(stderr)
5.87 + return False
5.88 + else:
5.89 + return True
5.90
5.91 def GET(self, settings):
5.92 return self.POST(settings)
5.93 @@ -154,9 +188,12 @@
5.94 command = [settings["script"], settings["device"], settings["mountpoint"], args["password"], settings["keyfilepath"]]
5.95 else:
5.96 command = [settings["script"], settings["device"], settings["mountpoint"], args["password"]]
5.97 -
5.98 - #__LOG.debug("Start init script")
5.99
5.100 + thread.start_new_thread(self.initStick, (command,settings,args,))
5.101 +
5.102 + return "Success: Init started"
5.103 +
5.104 + def initStick(self, command, settings, args):
5.105 process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
5.106 retval = process.wait()
5.107 ( stdout, stderr ) = process.communicate()
5.108 @@ -164,15 +201,12 @@
5.109 if "keyfile" in args:
5.110 self.deleteKeyfile(settings["keyfilepath"])
5.111
5.112 - #__LOG.debug("init done result: %s" %(retval,))
5.113 -
5.114 if (retval != 0):
5.115 - raise web.badrequest(stderr)
5.116 + sendInitialisationFailedError();
5.117
5.118 # Do the postinit stuff
5.119 - self.runPostInitScript(settings["postinitscript"])
5.120 -
5.121 - return "Success: Stick is initialized and mounted"
5.122 + if (self.runPostInitScript(settings["postinitscript"]) != True):
5.123 + sendInitialisationFailedError();
5.124
5.125 class MyRestListener(web.application):
5.126 def __init__(self, mapping=(), fvars={}, autoreload=None, script=None, device=None, mountpoint=None, tries=None, keyfilepath=None, preinitscript=None, postinitscript=None):