# HG changeset patch
# User om
# Date 1386769375 -3600
# Node ID e10a08095ccce191d48269a2315119c346b36f84
# Parent b44a603b0b95d928d52d3c551faca57e3d8a98a9
more details on GUI parts
diff -r b44a603b0b95 -r e10a08095ccc OpenSecurity/bin/launch.pyw
--- a/OpenSecurity/bin/launch.pyw Wed Dec 11 12:07:16 2013 +0100
+++ b/OpenSecurity/bin/launch.pyw Wed Dec 11 14:42:55 2013 +0100
@@ -36,7 +36,6 @@
import os
import subprocess
import sys
-import urllib
import urllib2
from PyQt4 import QtCore
@@ -68,7 +67,8 @@
size = self.geometry()
self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
- self._vms = [ { 'name': 'SecurityDVM0', 'ip': '192.168.56.101' } ]
+ # TODO: THIS HERE IS HARD CODED
+ self._vms = [ { 'name': 'SecurityDVM0' } ]
self._apps = [ { 'name': 'Browser', 'command': '/usr/bin/iceweasel' } ]
# add the VMs we know
@@ -186,11 +186,7 @@
def vm_get(self):
"""The vm of choice."""
- v = str(self._cbVM.currentText())
- for vm in self._vms:
- if v == vm['name']:
- return vm['ip']
- return v
+ return str(self._cbVM.currentText())
vm = property(vm_get)
@@ -227,43 +223,33 @@
# parse command line
parser = argparse.ArgumentParser(description = 'OpenSecurity Launcher: run application in VM')
- parser.add_argument('ip', metavar='IP', help='IP of Virtual Machine', nargs='?', type=str, default='')
+ parser.add_argument('vm', metavar='VM', help='Name of Virtual Machine', nargs='?', type=str, default='')
parser.add_argument('command', metavar='COMMAND', help='Full path of command and arguments to start inside VM', nargs='?', type=str, default='')
args = parser.parse_args()
- # we must have at least all or none set
- set_ip = args.ip != ''
- set_command = args.command != ''
- set_ALL = set_ip and set_command
- set_NONE = (not set_ip) and (not set_command)
- if (not set_ALL) and (not set_NONE):
- sys.stderr.write("Please specify ip and command or none.\n")
- sys.stderr.write("Type '--help' for help.\n")
- sys.exit(1)
+ # we must have all set
+ if args.vm == "" or args.command == '':
+ print('VM and/or COMMAND missing - invoking user dialog')
+ args.vm, args.command = ask_user()
- # check if we need to ask the user
- if set_NONE:
- args.ip, args.command = ask_user()
-
- # still no IP? --> no chance, over and out!
- if args.ip == '':
+ # still no VM? --> no chance, over and out!
+ if args.vm == '':
sys.exit(0)
# ensure we have our X11 running
Cygwin.start_X11()
# call the OpenSecurity Admin to launch our progie =)
- url_vm = urllib.quote(args.ip)
- url_command = urllib.quote(args.command)
- QtGui.QMessageBox.information(None, 'OpenSecurity Launche', 'About to launch
' + url_command + '
at VM
' + url_vm + '')
+ # TODO: hard coded PORT
+ url = 'http://127.0.0.1:8080/sdvms/' + args.vm + '/application' + args.command
+ print('Calling ' + url)
+ try:
+ result = urllib2.urlopen(url, None, 5)
+ except urllib2.HTTPError as e:
+ # Error, Fail, ... :(
+ msg = 'Error received from OpenSecurity Subsystem\nError code: ' + str(e.code) + '\nReason: ' + e.reason
+ QtGui.QMessageBox.critical(None, 'OpenSecurity Error', msg)
- # user_at_guest = args.user + '@' + args.ip
- # ssh = 'DISPLAY=:0 /usr/bin/ssh -Y ' + user_at_guest + ' ' + args.command
- # print(ssh)
-
- # # off we go!
- # Cygwin()(['/bin/bash', '--login', '-i', '-c', ssh], None, None, None)
-
# start
if __name__ == "__main__":
diff -r b44a603b0b95 -r e10a08095ccc OpenSecurity/bin/opensecurity_tray.pyw
--- a/OpenSecurity/bin/opensecurity_tray.pyw Wed Dec 11 12:07:16 2013 +0100
+++ b/OpenSecurity/bin/opensecurity_tray.pyw Wed Dec 11 14:42:55 2013 +0100
@@ -36,6 +36,7 @@
import os
import subprocess
import sys
+import urllib2
from PyQt4 import QtCore
from PyQt4 import QtGui
@@ -49,6 +50,30 @@
# code
+class OpenSecurityWait(QtGui.QDialog):
+
+ """OpenSecurity: please wait ..."""
+
+ def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
+ super(OpenSecurityWait, self).__init__(parent, flags)
+ self.setWindowTitle('OpenSecurity')
+ self.setup_ui()
+
+
+ def setup_ui(self):
+ """Create the widgets."""
+
+ lyMain = QtGui.QVBoxLayout(self)
+ lyMain.setContentsMargins(8, 8, 8, 8)
+
+ # content area: left pixmap, right text
+ lbTitle = QtGui.QLabel('Creating secure subsystem. Please stand by ...')
+ lyMain.addWidget(lbTitle)
+
+ self.setMinimumSize(400, 50)
+ self.resize(lyMain.minimumSize())
+
+
class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
"""This is the OpenSecuirty Tray Icon"""
@@ -67,11 +92,31 @@
def clicked_browser(self):
"""wish for safe internet browsing"""
- dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
- process_command = [sys.executable, dlg_launch_image, '192.168.56.101', '/usr/bin/iceweasel']
- print(process_command)
- process = subprocess.Popen(process_command, shell = False)
- process.communicate()
+
+ # TODO: HARDCODED ADDRESS OF OPENSECURITYD
+
+ # tell the user to wait
+ dlg = OpenSecurityWait()
+ dlg.show()
+ QtGui.QApplication.instance().processEvents()
+
+ try:
+
+ # get a proper browsing VM
+ browsing_vm = urllib2.urlopen('http://127.0.0.1:8080/browsing').readline()
+ dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
+ process_command = [sys.executable, dlg_launch_image, browsing_vm, '/usr/bin/iceweasel']
+ print(process_command)
+ process = subprocess.Popen(process_command, shell = False)
+ process.communicate()
+
+ except:
+ dlg.hide()
+ QtGui.QApplication.instance().processEvents()
+ QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
+
+ dlg.hide()
+ QtGui.QApplication.instance().processEvents()
def clicked_exit(self):
diff -r b44a603b0b95 -r e10a08095ccc OpenSecurity/bin/vmmanager.py
--- a/OpenSecurity/bin/vmmanager.py Wed Dec 11 12:07:16 2013 +0100
+++ b/OpenSecurity/bin/vmmanager.py Wed Dec 11 14:42:55 2013 +0100
@@ -16,7 +16,7 @@
import string
-DEBUG = False
+DEBUG = True
class USBFilter:
vendorid = ""
diff -r b44a603b0b95 -r e10a08095ccc OpenSecurity/test/create-security-vm.bat
--- a/OpenSecurity/test/create-security-vm.bat Wed Dec 11 12:07:16 2013 +0100
+++ b/OpenSecurity/test/create-security-vm.bat Wed Dec 11 14:42:55 2013 +0100
@@ -1,2 +1,2 @@
@echo off
-..\cygwin\bin\curl -X POST http://127.0.0.1:8080/sdvms
\ No newline at end of file
+..\cygwin\bin\curl -X POST http://127.0.0.1:8080/sdvms