more details on GUI parts
authorom
Wed, 11 Dec 2013 14:42:55 +0100
changeset 42e10a08095ccc
parent 40 b44a603b0b95
child 43 7c2e34bcdf3d
more details on GUI parts
OpenSecurity/bin/launch.pyw
OpenSecurity/bin/opensecurity_tray.pyw
OpenSecurity/bin/vmmanager.py
OpenSecurity/test/create-security-vm.bat
     1.1 --- a/OpenSecurity/bin/launch.pyw	Wed Dec 11 12:07:16 2013 +0100
     1.2 +++ b/OpenSecurity/bin/launch.pyw	Wed Dec 11 14:42:55 2013 +0100
     1.3 @@ -36,7 +36,6 @@
     1.4  import os
     1.5  import subprocess
     1.6  import sys
     1.7 -import urllib
     1.8  import urllib2
     1.9  
    1.10  from PyQt4 import QtCore
    1.11 @@ -68,7 +67,8 @@
    1.12          size = self.geometry()
    1.13          self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
    1.14          
    1.15 -        self._vms = [ { 'name': 'SecurityDVM0', 'ip': '192.168.56.101' } ]
    1.16 +        # TODO: THIS HERE IS HARD CODED
    1.17 +        self._vms = [ { 'name': 'SecurityDVM0' } ]
    1.18          self._apps = [ { 'name': 'Browser', 'command': '/usr/bin/iceweasel' } ]
    1.19          
    1.20          # add the VMs we know
    1.21 @@ -186,11 +186,7 @@
    1.22          
    1.23      def vm_get(self):
    1.24          """The vm of choice."""
    1.25 -        v = str(self._cbVM.currentText())
    1.26 -        for vm in self._vms:
    1.27 -            if v == vm['name']:
    1.28 -                return vm['ip']
    1.29 -        return v
    1.30 +        return str(self._cbVM.currentText())
    1.31          
    1.32      vm = property(vm_get)
    1.33          
    1.34 @@ -227,43 +223,33 @@
    1.35      
    1.36      # parse command line
    1.37      parser = argparse.ArgumentParser(description = 'OpenSecurity Launcher: run application in VM')
    1.38 -    parser.add_argument('ip', metavar='IP', help='IP of Virtual Machine', nargs='?', type=str, default='')
    1.39 +    parser.add_argument('vm', metavar='VM', help='Name of Virtual Machine', nargs='?', type=str, default='')
    1.40      parser.add_argument('command', metavar='COMMAND', help='Full path of command and arguments to start inside VM', nargs='?', type=str, default='')
    1.41      args = parser.parse_args()
    1.42      
    1.43 -    # we must have at least all or none set
    1.44 -    set_ip = args.ip != ''
    1.45 -    set_command = args.command != ''
    1.46 -    set_ALL = set_ip and set_command
    1.47 -    set_NONE = (not set_ip) and (not set_command)
    1.48 -    if (not set_ALL) and (not set_NONE):
    1.49 -        sys.stderr.write("Please specify ip and command or none.\n")
    1.50 -        sys.stderr.write("Type '--help' for help.\n")
    1.51 -        sys.exit(1)
    1.52 +    # we must have all set
    1.53 +    if args.vm == "" or args.command == '':
    1.54 +        print('VM and/or COMMAND missing - invoking user dialog')
    1.55 +        args.vm, args.command = ask_user()
    1.56          
    1.57 -    # check if we need to ask the user
    1.58 -    if set_NONE:
    1.59 -        args.ip, args.command = ask_user()
    1.60 -        
    1.61 -    # still no IP? --> no chance, over and out!
    1.62 -    if args.ip == '':
    1.63 +    # still no VM? --> no chance, over and out!
    1.64 +    if args.vm == '':
    1.65          sys.exit(0)
    1.66          
    1.67      # ensure we have our X11 running
    1.68      Cygwin.start_X11()
    1.69      
    1.70      # call the OpenSecurity Admin to launch our progie =)
    1.71 -    url_vm = urllib.quote(args.ip)
    1.72 -    url_command = urllib.quote(args.command)
    1.73 -    QtGui.QMessageBox.information(None, 'OpenSecurity Launche', 'About to launch <br/><b>' + url_command + '</b><br/>at VM <br/><b>' + url_vm + '</b>')
    1.74 +    # TODO: hard coded PORT
    1.75 +    url = 'http://127.0.0.1:8080/sdvms/' + args.vm + '/application' + args.command
    1.76 +    print('Calling ' + url)
    1.77 +    try:
    1.78 +        result = urllib2.urlopen(url, None, 5)
    1.79 +    except urllib2.HTTPError as e:
    1.80 +        # Error, Fail, ... :(
    1.81 +        msg = 'Error received from OpenSecurity Subsystem\nError code: ' + str(e.code) + '\nReason: ' + e.reason
    1.82 +        QtGui.QMessageBox.critical(None, 'OpenSecurity Error', msg)
    1.83      
    1.84 -    # user_at_guest = args.user + '@' + args.ip
    1.85 -    # ssh = 'DISPLAY=:0 /usr/bin/ssh -Y ' + user_at_guest + ' ' + args.command
    1.86 -    # print(ssh)
    1.87 -    
    1.88 -    # # off we go!
    1.89 -    # Cygwin()(['/bin/bash', '--login', '-i', '-c', ssh], None, None, None)
    1.90 -
    1.91      
    1.92  # start
    1.93  if __name__ == "__main__":
     2.1 --- a/OpenSecurity/bin/opensecurity_tray.pyw	Wed Dec 11 12:07:16 2013 +0100
     2.2 +++ b/OpenSecurity/bin/opensecurity_tray.pyw	Wed Dec 11 14:42:55 2013 +0100
     2.3 @@ -36,6 +36,7 @@
     2.4  import os
     2.5  import subprocess
     2.6  import sys
     2.7 +import urllib2
     2.8  
     2.9  from PyQt4 import QtCore
    2.10  from PyQt4 import QtGui
    2.11 @@ -49,6 +50,30 @@
    2.12  # code
    2.13  
    2.14  
    2.15 +class OpenSecurityWait(QtGui.QDialog):
    2.16 +
    2.17 +    """OpenSecurity: please wait ..."""
    2.18 +    
    2.19 +    def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
    2.20 +        super(OpenSecurityWait, self).__init__(parent, flags)
    2.21 +        self.setWindowTitle('OpenSecurity')
    2.22 +        self.setup_ui()
    2.23 +        
    2.24 +        
    2.25 +    def setup_ui(self):
    2.26 +        """Create the widgets."""
    2.27 +        
    2.28 +        lyMain = QtGui.QVBoxLayout(self)
    2.29 +        lyMain.setContentsMargins(8, 8, 8, 8)
    2.30 +        
    2.31 +        # content area: left pixmap, right text
    2.32 +        lbTitle = QtGui.QLabel('Creating secure subsystem. Please stand by ...')
    2.33 +        lyMain.addWidget(lbTitle)
    2.34 +        
    2.35 +        self.setMinimumSize(400, 50)
    2.36 +        self.resize(lyMain.minimumSize())
    2.37 +
    2.38 +
    2.39  class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
    2.40      
    2.41      """This is the OpenSecuirty Tray Icon"""
    2.42 @@ -67,11 +92,31 @@
    2.43  
    2.44      def clicked_browser(self):
    2.45          """wish for safe internet browsing"""
    2.46 -        dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
    2.47 -        process_command = [sys.executable, dlg_launch_image, '192.168.56.101', '/usr/bin/iceweasel']
    2.48 -        print(process_command)
    2.49 -        process = subprocess.Popen(process_command, shell = False)
    2.50 -        process.communicate()
    2.51 +        
    2.52 +        # TODO: HARDCODED ADDRESS OF OPENSECURITYD
    2.53 +        
    2.54 +        # tell the user to wait
    2.55 +        dlg = OpenSecurityWait()
    2.56 +        dlg.show()
    2.57 +        QtGui.QApplication.instance().processEvents()
    2.58 +        
    2.59 +        try:
    2.60 +        
    2.61 +            # get a proper browsing VM
    2.62 +            browsing_vm = urllib2.urlopen('http://127.0.0.1:8080/browsing').readline()
    2.63 +            dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
    2.64 +            process_command = [sys.executable, dlg_launch_image, browsing_vm, '/usr/bin/iceweasel']
    2.65 +            print(process_command)
    2.66 +            process = subprocess.Popen(process_command, shell = False)
    2.67 +            process.communicate()
    2.68 +            
    2.69 +        except:
    2.70 +            dlg.hide()
    2.71 +            QtGui.QApplication.instance().processEvents()
    2.72 +            QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
    2.73 +            
    2.74 +        dlg.hide()
    2.75 +        QtGui.QApplication.instance().processEvents()
    2.76              
    2.77              
    2.78      def clicked_exit(self):
     3.1 --- a/OpenSecurity/bin/vmmanager.py	Wed Dec 11 12:07:16 2013 +0100
     3.2 +++ b/OpenSecurity/bin/vmmanager.py	Wed Dec 11 14:42:55 2013 +0100
     3.3 @@ -16,7 +16,7 @@
     3.4  import string
     3.5  
     3.6  
     3.7 -DEBUG = False
     3.8 +DEBUG = True
     3.9  
    3.10  class USBFilter:
    3.11      vendorid = ""
     4.1 --- a/OpenSecurity/test/create-security-vm.bat	Wed Dec 11 12:07:16 2013 +0100
     4.2 +++ b/OpenSecurity/test/create-security-vm.bat	Wed Dec 11 14:42:55 2013 +0100
     4.3 @@ -1,2 +1,2 @@
     4.4  @echo off
     4.5 -..\cygwin\bin\curl -X POST http://127.0.0.1:8080/sdvms
     4.6 \ No newline at end of file
     4.7 +..\cygwin\bin\curl -X POST http://127.0.0.1:8080/sdvms