1.1 --- a/OpenSecurity/bin/opensecurity_client_restful_server.py Wed Jun 25 22:26:34 2014 +0200
1.2 +++ b/OpenSecurity/bin/opensecurity_client_restful_server.py Thu Jun 26 12:14:08 2014 +0200
1.3 @@ -132,10 +132,9 @@
1.4 # create the process which queries the user
1.5 dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw')
1.6 process_command = [sys.executable, dlg_image, 'credentials', args.text]
1.7 - process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
1.8
1.9 # run process result handling in seprate thread (not to block main one)
1.10 - bouncer = ProcessResultBouncer(process, remote_ip, '/credentials')
1.11 + bouncer = ProcessResultBouncer(process_command, remote_ip, '/credentials')
1.12 bouncer.start()
1.13
1.14 return 'user queried for credentials'
1.15 @@ -165,10 +164,9 @@
1.16 # create the process which queries the user
1.17 dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw')
1.18 process_command = [sys.executable, dlg_image, 'keyfile', args.text]
1.19 - process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
1.20
1.21 # run process result handling in seprate thread (not to block main one)
1.22 - bouncer = ProcessResultBouncer(process, remote_ip, '/keyfile')
1.23 + bouncer = ProcessResultBouncer(process_command, remote_ip, '/keyfile')
1.24 bouncer.start()
1.25
1.26 return 'user queried for password and keyfile'
1.27 @@ -266,7 +264,7 @@
1.28 raise web.badrequest('no text given')
1.29
1.30 # invoke the user dialog as a subprocess
1.31 - dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.py')
1.32 + dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw')
1.33 process_command = [sys.executable, dlg_image, 'notification-' + args.msgtype, args.text]
1.34 process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
1.35
1.36 @@ -297,10 +295,9 @@
1.37 # create the process which queries the user
1.38 dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw')
1.39 process_command = [sys.executable, dlg_image, 'password', args.text]
1.40 - process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
1.41
1.42 # run process result handling in seprate thread (not to block main one)
1.43 - bouncer = ProcessResultBouncer(process, remote_ip, '/password')
1.44 + bouncer = ProcessResultBouncer(process_command, remote_ip, '/password')
1.45 bouncer.start()
1.46
1.47 return 'user queried for password'
1.48 @@ -534,12 +531,12 @@
1.49
1.50 """A class to post the result of a given process - assuming it to be in JSON - to a REST Api."""
1.51
1.52 - def __init__(self, process, remote_ip, resource):
1.53 + def __init__(self, process_command, remote_ip, resource):
1.54
1.55 """ctor"""
1.56
1.57 threading.Thread.__init__(self)
1.58 - self._process = process
1.59 + self._process_command = process_command
1.60 self._remote_ip = remote_ip
1.61 self._resource = resource
1.62
1.63 @@ -554,27 +551,37 @@
1.64
1.65 """run the thread"""
1.66
1.67 - # invoke the user dialog as a subprocess
1.68 - result = self._process.communicate()[0]
1.69 - if self._process.returncode != 0:
1.70 - print 'user request has been aborted.'
1.71 - return
1.72 -
1.73 - # all ok, tell send request back appropriate destination
1.74 - try:
1.75 - j = json.loads(result)
1.76 - except:
1.77 - print 'error in password parsing'
1.78 - return
1.79 -
1.80 - # by provided a 'data' we turn this into a POST statement
1.81 - url_addr = 'http://' + self._remote_ip + ':58080' + self._resource
1.82 - req = urllib2.Request(url_addr, urllib.urlencode(j))
1.83 - try:
1.84 - res = urllib2.urlopen(req)
1.85 - except:
1.86 - print 'failed to contact: ' + url_addr
1.87 - return
1.88 + while True:
1.89 +
1.90 + # invoke the user dialog as a subprocess
1.91 + process = subprocess.Popen(self._process_command, shell = False, stdout = subprocess.PIPE)
1.92 + result = process.communicate()[0]
1.93 + if process.returncode != 0:
1.94 + print 'user request has been aborted.'
1.95 + return
1.96 +
1.97 + # all ok, tell send request back appropriate destination
1.98 + try:
1.99 + j = json.loads(result)
1.100 + except:
1.101 + print 'error in password parsing'
1.102 + return
1.103 +
1.104 + # by provided a 'data' we turn this into a POST statement
1.105 + url_addr = 'http://' + self._remote_ip + ':58080' + self._resource
1.106 + req = urllib2.Request(url_addr, urllib.urlencode(j))
1.107 + try:
1.108 + res = urllib2.urlopen(req)
1.109 + if res.getcode() == 200:
1.110 + return
1.111 +
1.112 + except urllib2.HTTPError as e:
1.113 +
1.114 + # invoke the user dialog as a subprocess
1.115 + dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw')
1.116 + dlg_process_command = [sys.executable, dlg_image, 'notification-critical', 'Error is<br/>Code: {0!s}<br/><b>{1}</b>'.format(e.code, e.reason)]
1.117 + dlg_process = subprocess.Popen(dlg_process_command, shell = False, stdout = subprocess.PIPE)
1.118 + dlg_process.communicate()[0]
1.119
1.120
1.121 class RESTServerThread(threading.Thread):
2.1 --- a/OpenSecurity/bin/ui/format_drive_dialog.py Wed Jun 25 22:26:34 2014 +0200
2.2 +++ b/OpenSecurity/bin/ui/format_drive_dialog.py Thu Jun 26 12:14:08 2014 +0200
2.3 @@ -108,6 +108,9 @@
2.4
2.5 # pick the password
2.6 init_data['password'] = self.ui.edtPassword.text()
2.7 + if len(init_data['password']) == 0:
2.8 + QtGui.QMessageBox.critical(self, 'Format error', 'Please specify a password.')
2.9 + return
2.10
2.11 # read the content of the keyfile
2.12 keyfile_content = ''