1.1 --- a/OpenSecurity/bin/opensecurity_tray.pyw Wed Jun 25 21:49:25 2014 +0200
1.2 +++ b/OpenSecurity/bin/opensecurity_tray.pyw Wed Jun 25 22:26:34 2014 +0200
1.3 @@ -91,7 +91,14 @@
1.4
1.5 super(OpenSecurityTrayIcon, self).__init__(icon, parent)
1.6 self.setup_ui()
1.7 -
1.8 + self.activated.connect(self.activated_)
1.9 +
1.10 +
1.11 + def activated_(self, reason):
1.12 +
1.13 + """the system tray icon was activated"""
1.14 + self.refresh_format_menu()
1.15 +
1.16
1.17 def clicked_about(self):
1.18 """clicked about"""
1.19 @@ -170,7 +177,54 @@
1.20 elif sys.platform == 'win32' or sys.platform == 'cygwin':
1.21 mail_url = 'mailto:' + urllib.quote(address, '@') + '?' + urllib.quote('subject=' + subject)
1.22 subprocess.Popen(['cmd', '/C', 'start', mail_url])
1.23 -
1.24 +
1.25 +
1.26 + def format_drive(self):
1.27 +
1.28 + """format drive clicked (the sender should a QAction created with refresh_format_menu)"""
1.29 + try:
1.30 +
1.31 + # fiddle the IP of the VM controlling the VM
1.32 + s = self.sender()
1.33 + ip = str(s.text().split('\\\\')[1])
1.34 +
1.35 + # invoke the format drive dialog
1.36 + dlg_format_drive = os.path.join(sys.path[0], 'ui', 'format_drive_dialog.py')
1.37 + process_command = [sys.executable, dlg_format_drive, ip]
1.38 + process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
1.39 +
1.40 + stdout = process.communicate()[0]
1.41 +
1.42 + except:
1.43 + pass
1.44 +
1.45 +
1.46 + def refresh_format_menu(self):
1.47 +
1.48 + """create a new list of format 'drives'"""
1.49 + self._menu_format.clear()
1.50 + a = self._menu_format.addAction('<No Drive given>')
1.51 + a.setEnabled(False)
1.52 +
1.53 + try:
1.54 +
1.55 + # get machines
1.56 + machines = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms'))
1.57 + if len(machines) == 0:
1.58 + return
1.59 +
1.60 + self._icon_network = QtGui.QIcon()
1.61 + self._icon_network.addPixmap(QtGui.QPixmap(":/opensecurity/gfx/network-workgroup.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
1.62 +
1.63 + self._menu_format.clear()
1.64 + for m in machines:
1.65 + a = self._menu_format.addAction(m + '\\\\' + machines[m])
1.66 + a.setIcon(self._icon_network)
1.67 + a.triggered.connect(self.format_drive)
1.68 +
1.69 + except:
1.70 + pass
1.71 +
1.72
1.73 def setup_ui(self):
1.74 """create the user interface
1.75 @@ -202,6 +256,9 @@
1.76 menu.addAction(self.acConfigure)
1.77 menu.addSeparator()
1.78
1.79 + self._menu_format = menu.addMenu('Format')
1.80 + menu.addSeparator()
1.81 +
1.82 self.acMail = menu.addAction('Send feedback mail')
1.83 icon = QtGui.QIcon()
1.84 icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_mail_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
2.1 --- a/OpenSecurity/bin/ui/configure_dialog.py Wed Jun 25 21:49:25 2014 +0200
2.2 +++ b/OpenSecurity/bin/ui/configure_dialog.py Wed Jun 25 22:26:34 2014 +0200
2.3 @@ -219,33 +219,32 @@
2.4 self._icon_network = QtGui.QIcon()
2.5 self._icon_network.addPixmap(QtGui.QPixmap(":/opensecurity/gfx/network-workgroup.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
2.6
2.7 + try:
2.8
2.9 - #try:
2.10 + # get machines
2.11 + machines = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms'))
2.12 + for m in machines:
2.13 + i = QtGui.QTreeWidgetItem(self.ui.tvMachines)
2.14 + i.setIcon(0, self._icon_machine)
2.15 + i.setText(0, m)
2.16 + i.setIcon(1, self._icon_network)
2.17 + i.setText(1, machines[m])
2.18
2.19 - # get machines
2.20 - machines = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms'))
2.21 - for m in machines:
2.22 - i = QtGui.QTreeWidgetItem(self.ui.tvMachines)
2.23 - i.setIcon(0, self._icon_machine)
2.24 - i.setText(0, m)
2.25 - i.setIcon(1, self._icon_network)
2.26 - i.setText(1, machines[m])
2.27
2.28 + properties = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms/' + m))
2.29 + for p in properties:
2.30 + j = QtGui.QTreeWidgetItem(i)
2.31 + j.setIcon(0, self._icon_property)
2.32 + j.setText(0, p)
2.33 + j.setText(1, properties[p])
2.34
2.35 - properties = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms/' + m))
2.36 - for p in properties:
2.37 - j = QtGui.QTreeWidgetItem(i)
2.38 - j.setIcon(0, self._icon_property)
2.39 - j.setText(0, p)
2.40 - j.setText(1, properties[p])
2.41 + j.setIcon(0, self._icon_network)
2.42 + j.setText(0, 'ip')
2.43 + j.setText(1, machines[m])
2.44
2.45 - j.setIcon(0, self._icon_network)
2.46 - j.setText(0, 'ip')
2.47 - j.setText(1, machines[m])
2.48
2.49 -
2.50 - #except:
2.51 - # pass
2.52 + except:
2.53 + pass
2.54
2.55
2.56
3.1 --- a/OpenSecurity/bin/ui/format_drive_dialog.py Wed Jun 25 21:49:25 2014 +0200
3.2 +++ b/OpenSecurity/bin/ui/format_drive_dialog.py Wed Jun 25 22:26:34 2014 +0200
3.3 @@ -2,9 +2,9 @@
3.4 # -*- coding: utf-8 -*-
3.5
3.6 # ------------------------------------------------------------
3.7 -# keyfile_dialog.pyw
3.8 +# format_drive_dialog.pyw
3.9 #
3.10 -# the user should give us a keyfile
3.11 +# letting the user format a drive attached to a certain VM
3.12 #
3.13 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
3.14 #
3.15 @@ -38,7 +38,7 @@
3.16 from PyQt4 import QtCore
3.17 from PyQt4 import QtGui
3.18
3.19 -from ui_KeyfileDialog import Ui_KeyfileDialog
3.20 +from ui_FormatDriveDialog import Ui_FormatDriveDialog
3.21 from about_dialog import AboutDialog
3.22
3.23
3.24 @@ -46,16 +46,26 @@
3.25 # code
3.26
3.27
3.28 -class KeyfileDialog(QtGui.QDialog):
3.29 +class FormatDriveDialog(QtGui.QDialog):
3.30
3.31 """A dialog for letting the user pass on a password/keyfile combo"""
3.32
3.33 - def __init__(self, user_text = 'Please provide an approbitate password and keyfile to proceed:'):
3.34 + def __init__(self, ip):
3.35
3.36 QtGui.QDialog.__init__(self)
3.37
3.38 + user_text = """
3.39 +<b>Attention!</b><br/>
3.40 +You are going to wipe all data stored<br/>
3.41 +at device attached to IP <b>%s</b>.<br/>
3.42 +<br/>
3.43 +<b>This is irreversible.</b><br/>
3.44 +<br/>
3.45 +Please provide an approbitate password and keyfile to proceed:
3.46 +""" % ip
3.47 +
3.48 # setup the user interface
3.49 - self.ui = Ui_KeyfileDialog()
3.50 + self.ui = Ui_FormatDriveDialog()
3.51 self.ui.setupUi(self)
3.52
3.53 # local members
3.54 @@ -94,27 +104,34 @@
3.55
3.56 """Ok button has been clicked."""
3.57
3.58 + init_data = {}
3.59 +
3.60 + # pick the password
3.61 + init_data['password'] = self.ui.edtPassword.text()
3.62 +
3.63 # read the content of the keyfile
3.64 keyfile_content = ''
3.65 try:
3.66 - keyfile = open(self.ui.edtKeyfile.text(), 'r')
3.67 - keyfile_content = keyfile.read()
3.68 + if len(self.ui.edtKeyfile.text()) > 0:
3.69 + keyfile = open(self.ui.edtKeyfile.text(), 'r')
3.70 + keyfile_content = keyfile.read()
3.71 except Exception as e:
3.72 sys.stderr.write('failed to read keyfile content:\n' + str(e) + '\n')
3.73 QtGui.QMessageBox.critical(self, 'Failed to read keyfile', str(e))
3.74 return
3.75
3.76 # turn into Base64
3.77 - keyfile_content_base64 = base64.b64encode(keyfile_content)
3.78 + if len(keyfile_content) > 0:
3.79 + keyfile_content_base64 = base64.b64encode(keyfile_content)
3.80 + init_data['keyfile'] = keyfile_content_base64
3.81
3.82 - sys.stdout.write('{ ')
3.83 - sys.stdout.write('"password": "')
3.84 - sys.stdout.write(self.ui.edtPassword.text())
3.85 - sys.stdout.write('", ')
3.86 - sys.stdout.write('"keyfile": "')
3.87 - sys.stdout.write(keyfile_content_base64)
3.88 - sys.stdout.write('" ')
3.89 - sys.stdout.write('}\n')
3.90 + try:
3.91 + req = urllib2.Request('http://' + ip + ':58081/init', urllib.urlencode(init_data))
3.92 + res = urllib2.urlopen(req)
3.93 + except:
3.94 + print('EXCEPTION')
3.95 + pass
3.96 +
3.97 self.accept()
3.98
3.99
3.100 @@ -125,8 +142,17 @@
3.101
3.102
3.103 if __name__ == "__main__":
3.104 +
3.105 + print(sys.argv)
3.106 +
3.107 + ip = None
3.108 + try:
3.109 + ip = sys.argv[-1:][0]
3.110 + except:
3.111 + pass
3.112 +
3.113 a = QtGui.QApplication(sys.argv)
3.114 - d = KeyfileDialog()
3.115 + d = FormatDriveDialog(ip)
3.116 d.show()
3.117 sys.exit(a.exec_())
3.118