1.1 --- a/OpenSecurity/bin/ui/format_drive_dialog.py Wed Jun 25 21:49:09 2014 +0200
1.2 +++ b/OpenSecurity/bin/ui/format_drive_dialog.py Wed Jun 25 22:26:34 2014 +0200
1.3 @@ -2,9 +2,9 @@
1.4 # -*- coding: utf-8 -*-
1.5
1.6 # ------------------------------------------------------------
1.7 -# keyfile_dialog.pyw
1.8 +# format_drive_dialog.pyw
1.9 #
1.10 -# the user should give us a keyfile
1.11 +# letting the user format a drive attached to a certain VM
1.12 #
1.13 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
1.14 #
1.15 @@ -38,7 +38,7 @@
1.16 from PyQt4 import QtCore
1.17 from PyQt4 import QtGui
1.18
1.19 -from ui_KeyfileDialog import Ui_KeyfileDialog
1.20 +from ui_FormatDriveDialog import Ui_FormatDriveDialog
1.21 from about_dialog import AboutDialog
1.22
1.23
1.24 @@ -46,16 +46,26 @@
1.25 # code
1.26
1.27
1.28 -class KeyfileDialog(QtGui.QDialog):
1.29 +class FormatDriveDialog(QtGui.QDialog):
1.30
1.31 """A dialog for letting the user pass on a password/keyfile combo"""
1.32
1.33 - def __init__(self, user_text = 'Please provide an approbitate password and keyfile to proceed:'):
1.34 + def __init__(self, ip):
1.35
1.36 QtGui.QDialog.__init__(self)
1.37
1.38 + user_text = """
1.39 +<b>Attention!</b><br/>
1.40 +You are going to wipe all data stored<br/>
1.41 +at device attached to IP <b>%s</b>.<br/>
1.42 +<br/>
1.43 +<b>This is irreversible.</b><br/>
1.44 +<br/>
1.45 +Please provide an approbitate password and keyfile to proceed:
1.46 +""" % ip
1.47 +
1.48 # setup the user interface
1.49 - self.ui = Ui_KeyfileDialog()
1.50 + self.ui = Ui_FormatDriveDialog()
1.51 self.ui.setupUi(self)
1.52
1.53 # local members
1.54 @@ -94,27 +104,34 @@
1.55
1.56 """Ok button has been clicked."""
1.57
1.58 + init_data = {}
1.59 +
1.60 + # pick the password
1.61 + init_data['password'] = self.ui.edtPassword.text()
1.62 +
1.63 # read the content of the keyfile
1.64 keyfile_content = ''
1.65 try:
1.66 - keyfile = open(self.ui.edtKeyfile.text(), 'r')
1.67 - keyfile_content = keyfile.read()
1.68 + if len(self.ui.edtKeyfile.text()) > 0:
1.69 + keyfile = open(self.ui.edtKeyfile.text(), 'r')
1.70 + keyfile_content = keyfile.read()
1.71 except Exception as e:
1.72 sys.stderr.write('failed to read keyfile content:\n' + str(e) + '\n')
1.73 QtGui.QMessageBox.critical(self, 'Failed to read keyfile', str(e))
1.74 return
1.75
1.76 # turn into Base64
1.77 - keyfile_content_base64 = base64.b64encode(keyfile_content)
1.78 + if len(keyfile_content) > 0:
1.79 + keyfile_content_base64 = base64.b64encode(keyfile_content)
1.80 + init_data['keyfile'] = keyfile_content_base64
1.81
1.82 - sys.stdout.write('{ ')
1.83 - sys.stdout.write('"password": "')
1.84 - sys.stdout.write(self.ui.edtPassword.text())
1.85 - sys.stdout.write('", ')
1.86 - sys.stdout.write('"keyfile": "')
1.87 - sys.stdout.write(keyfile_content_base64)
1.88 - sys.stdout.write('" ')
1.89 - sys.stdout.write('}\n')
1.90 + try:
1.91 + req = urllib2.Request('http://' + ip + ':58081/init', urllib.urlencode(init_data))
1.92 + res = urllib2.urlopen(req)
1.93 + except:
1.94 + print('EXCEPTION')
1.95 + pass
1.96 +
1.97 self.accept()
1.98
1.99
1.100 @@ -125,8 +142,17 @@
1.101
1.102
1.103 if __name__ == "__main__":
1.104 +
1.105 + print(sys.argv)
1.106 +
1.107 + ip = None
1.108 + try:
1.109 + ip = sys.argv[-1:][0]
1.110 + except:
1.111 + pass
1.112 +
1.113 a = QtGui.QApplication(sys.argv)
1.114 - d = KeyfileDialog()
1.115 + d = FormatDriveDialog(ip)
1.116 d.show()
1.117 sys.exit(a.exec_())
1.118