# HG changeset patch # User Oliver Maurhart # Date 1403727994 -7200 # Node ID ae931a692b54b30c0aeb7a1dcba5d3dab117ddcf # Parent be839e4a1370940e64a2fe8d54fd638e1699dc8f format drive working diff -r be839e4a1370 -r ae931a692b54 OpenSecurity/bin/opensecurity_tray.pyw --- a/OpenSecurity/bin/opensecurity_tray.pyw Wed Jun 25 21:49:25 2014 +0200 +++ b/OpenSecurity/bin/opensecurity_tray.pyw Wed Jun 25 22:26:34 2014 +0200 @@ -91,7 +91,14 @@ super(OpenSecurityTrayIcon, self).__init__(icon, parent) self.setup_ui() - + self.activated.connect(self.activated_) + + + def activated_(self, reason): + + """the system tray icon was activated""" + self.refresh_format_menu() + def clicked_about(self): """clicked about""" @@ -170,7 +177,54 @@ elif sys.platform == 'win32' or sys.platform == 'cygwin': mail_url = 'mailto:' + urllib.quote(address, '@') + '?' + urllib.quote('subject=' + subject) subprocess.Popen(['cmd', '/C', 'start', mail_url]) - + + + def format_drive(self): + + """format drive clicked (the sender should a QAction created with refresh_format_menu)""" + try: + + # fiddle the IP of the VM controlling the VM + s = self.sender() + ip = str(s.text().split('\\\\')[1]) + + # invoke the format drive dialog + dlg_format_drive = os.path.join(sys.path[0], 'ui', 'format_drive_dialog.py') + process_command = [sys.executable, dlg_format_drive, ip] + process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE) + + stdout = process.communicate()[0] + + except: + pass + + + def refresh_format_menu(self): + + """create a new list of format 'drives'""" + self._menu_format.clear() + a = self._menu_format.addAction('') + a.setEnabled(False) + + try: + + # get machines + machines = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms')) + if len(machines) == 0: + return + + self._icon_network = QtGui.QIcon() + self._icon_network.addPixmap(QtGui.QPixmap(":/opensecurity/gfx/network-workgroup.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + + self._menu_format.clear() + for m in machines: + a = self._menu_format.addAction(m + '\\\\' + machines[m]) + a.setIcon(self._icon_network) + a.triggered.connect(self.format_drive) + + except: + pass + def setup_ui(self): """create the user interface @@ -202,6 +256,9 @@ menu.addAction(self.acConfigure) menu.addSeparator() + self._menu_format = menu.addMenu('Format') + menu.addSeparator() + self.acMail = menu.addAction('Send feedback mail') icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_mail_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off) diff -r be839e4a1370 -r ae931a692b54 OpenSecurity/bin/ui/configure_dialog.py --- a/OpenSecurity/bin/ui/configure_dialog.py Wed Jun 25 21:49:25 2014 +0200 +++ b/OpenSecurity/bin/ui/configure_dialog.py Wed Jun 25 22:26:34 2014 +0200 @@ -219,33 +219,32 @@ self._icon_network = QtGui.QIcon() self._icon_network.addPixmap(QtGui.QPixmap(":/opensecurity/gfx/network-workgroup.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + try: - #try: + # get machines + machines = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms')) + for m in machines: + i = QtGui.QTreeWidgetItem(self.ui.tvMachines) + i.setIcon(0, self._icon_machine) + i.setText(0, m) + i.setIcon(1, self._icon_network) + i.setText(1, machines[m]) - # get machines - machines = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms')) - for m in machines: - i = QtGui.QTreeWidgetItem(self.ui.tvMachines) - i.setIcon(0, self._icon_machine) - i.setText(0, m) - i.setIcon(1, self._icon_network) - i.setText(1, machines[m]) + properties = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms/' + m)) + for p in properties: + j = QtGui.QTreeWidgetItem(i) + j.setIcon(0, self._icon_property) + j.setText(0, p) + j.setText(1, properties[p]) - properties = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms/' + m)) - for p in properties: - j = QtGui.QTreeWidgetItem(i) - j.setIcon(0, self._icon_property) - j.setText(0, p) - j.setText(1, properties[p]) + j.setIcon(0, self._icon_network) + j.setText(0, 'ip') + j.setText(1, machines[m]) - j.setIcon(0, self._icon_network) - j.setText(0, 'ip') - j.setText(1, machines[m]) - - #except: - # pass + except: + pass diff -r be839e4a1370 -r ae931a692b54 OpenSecurity/bin/ui/format_drive_dialog.py --- a/OpenSecurity/bin/ui/format_drive_dialog.py Wed Jun 25 21:49:25 2014 +0200 +++ b/OpenSecurity/bin/ui/format_drive_dialog.py Wed Jun 25 22:26:34 2014 +0200 @@ -2,9 +2,9 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------ -# keyfile_dialog.pyw +# format_drive_dialog.pyw # -# the user should give us a keyfile +# letting the user format a drive attached to a certain VM # # Autor: Oliver Maurhart, # @@ -38,7 +38,7 @@ from PyQt4 import QtCore from PyQt4 import QtGui -from ui_KeyfileDialog import Ui_KeyfileDialog +from ui_FormatDriveDialog import Ui_FormatDriveDialog from about_dialog import AboutDialog @@ -46,16 +46,26 @@ # code -class KeyfileDialog(QtGui.QDialog): +class FormatDriveDialog(QtGui.QDialog): """A dialog for letting the user pass on a password/keyfile combo""" - def __init__(self, user_text = 'Please provide an approbitate password and keyfile to proceed:'): + def __init__(self, ip): QtGui.QDialog.__init__(self) + user_text = """ +Attention!
+You are going to wipe all data stored
+at device attached to IP %s.
+
+This is irreversible.
+
+Please provide an approbitate password and keyfile to proceed: +""" % ip + # setup the user interface - self.ui = Ui_KeyfileDialog() + self.ui = Ui_FormatDriveDialog() self.ui.setupUi(self) # local members @@ -94,27 +104,34 @@ """Ok button has been clicked.""" + init_data = {} + + # pick the password + init_data['password'] = self.ui.edtPassword.text() + # read the content of the keyfile keyfile_content = '' try: - keyfile = open(self.ui.edtKeyfile.text(), 'r') - keyfile_content = keyfile.read() + if len(self.ui.edtKeyfile.text()) > 0: + keyfile = open(self.ui.edtKeyfile.text(), 'r') + keyfile_content = keyfile.read() except Exception as e: sys.stderr.write('failed to read keyfile content:\n' + str(e) + '\n') QtGui.QMessageBox.critical(self, 'Failed to read keyfile', str(e)) return # turn into Base64 - keyfile_content_base64 = base64.b64encode(keyfile_content) + if len(keyfile_content) > 0: + keyfile_content_base64 = base64.b64encode(keyfile_content) + init_data['keyfile'] = keyfile_content_base64 - sys.stdout.write('{ ') - sys.stdout.write('"password": "') - sys.stdout.write(self.ui.edtPassword.text()) - sys.stdout.write('", ') - sys.stdout.write('"keyfile": "') - sys.stdout.write(keyfile_content_base64) - sys.stdout.write('" ') - sys.stdout.write('}\n') + try: + req = urllib2.Request('http://' + ip + ':58081/init', urllib.urlencode(init_data)) + res = urllib2.urlopen(req) + except: + print('EXCEPTION') + pass + self.accept() @@ -125,8 +142,17 @@ if __name__ == "__main__": + + print(sys.argv) + + ip = None + try: + ip = sys.argv[-1:][0] + except: + pass + a = QtGui.QApplication(sys.argv) - d = KeyfileDialog() + d = FormatDriveDialog(ip) d.show() sys.exit(a.exec_())