# HG changeset patch # User Oliver Maurhart # Date 1403777648 -7200 # Node ID 973b5888eec63999618bbee20d0424a3a6726bdf # Parent ae931a692b54b30c0aeb7a1dcba5d3dab117ddcf password request loop done diff -r ae931a692b54 -r 973b5888eec6 OpenSecurity/bin/opensecurity_client_restful_server.py --- a/OpenSecurity/bin/opensecurity_client_restful_server.py Wed Jun 25 22:26:34 2014 +0200 +++ b/OpenSecurity/bin/opensecurity_client_restful_server.py Thu Jun 26 12:14:08 2014 +0200 @@ -132,10 +132,9 @@ # create the process which queries the user dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw') process_command = [sys.executable, dlg_image, 'credentials', args.text] - process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE) # run process result handling in seprate thread (not to block main one) - bouncer = ProcessResultBouncer(process, remote_ip, '/credentials') + bouncer = ProcessResultBouncer(process_command, remote_ip, '/credentials') bouncer.start() return 'user queried for credentials' @@ -165,10 +164,9 @@ # create the process which queries the user dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw') process_command = [sys.executable, dlg_image, 'keyfile', args.text] - process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE) # run process result handling in seprate thread (not to block main one) - bouncer = ProcessResultBouncer(process, remote_ip, '/keyfile') + bouncer = ProcessResultBouncer(process_command, remote_ip, '/keyfile') bouncer.start() return 'user queried for password and keyfile' @@ -266,7 +264,7 @@ raise web.badrequest('no text given') # invoke the user dialog as a subprocess - dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.py') + dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw') process_command = [sys.executable, dlg_image, 'notification-' + args.msgtype, args.text] process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE) @@ -297,10 +295,9 @@ # create the process which queries the user dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw') process_command = [sys.executable, dlg_image, 'password', args.text] - process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE) # run process result handling in seprate thread (not to block main one) - bouncer = ProcessResultBouncer(process, remote_ip, '/password') + bouncer = ProcessResultBouncer(process_command, remote_ip, '/password') bouncer.start() return 'user queried for password' @@ -534,12 +531,12 @@ """A class to post the result of a given process - assuming it to be in JSON - to a REST Api.""" - def __init__(self, process, remote_ip, resource): + def __init__(self, process_command, remote_ip, resource): """ctor""" threading.Thread.__init__(self) - self._process = process + self._process_command = process_command self._remote_ip = remote_ip self._resource = resource @@ -554,27 +551,37 @@ """run the thread""" - # invoke the user dialog as a subprocess - result = self._process.communicate()[0] - if self._process.returncode != 0: - print 'user request has been aborted.' - return - - # all ok, tell send request back appropriate destination - try: - j = json.loads(result) - except: - print 'error in password parsing' - return - - # by provided a 'data' we turn this into a POST statement - url_addr = 'http://' + self._remote_ip + ':58080' + self._resource - req = urllib2.Request(url_addr, urllib.urlencode(j)) - try: - res = urllib2.urlopen(req) - except: - print 'failed to contact: ' + url_addr - return + while True: + + # invoke the user dialog as a subprocess + process = subprocess.Popen(self._process_command, shell = False, stdout = subprocess.PIPE) + result = process.communicate()[0] + if process.returncode != 0: + print 'user request has been aborted.' + return + + # all ok, tell send request back appropriate destination + try: + j = json.loads(result) + except: + print 'error in password parsing' + return + + # by provided a 'data' we turn this into a POST statement + url_addr = 'http://' + self._remote_ip + ':58080' + self._resource + req = urllib2.Request(url_addr, urllib.urlencode(j)) + try: + res = urllib2.urlopen(req) + if res.getcode() == 200: + return + + except urllib2.HTTPError as e: + + # invoke the user dialog as a subprocess + dlg_image = os.path.join(sys.path[0], 'opensecurity_dialog.pyw') + dlg_process_command = [sys.executable, dlg_image, 'notification-critical', 'Error is
Code: {0!s}
{1}'.format(e.code, e.reason)] + dlg_process = subprocess.Popen(dlg_process_command, shell = False, stdout = subprocess.PIPE) + dlg_process.communicate()[0] class RESTServerThread(threading.Thread): diff -r ae931a692b54 -r 973b5888eec6 OpenSecurity/bin/ui/format_drive_dialog.py --- a/OpenSecurity/bin/ui/format_drive_dialog.py Wed Jun 25 22:26:34 2014 +0200 +++ b/OpenSecurity/bin/ui/format_drive_dialog.py Thu Jun 26 12:14:08 2014 +0200 @@ -108,6 +108,9 @@ # pick the password init_data['password'] = self.ui.edtPassword.text() + if len(init_data['password']) == 0: + QtGui.QMessageBox.critical(self, 'Format error', 'Please specify a password.') + return # read the content of the keyfile keyfile_content = ''