1.1 --- a/OpenSecurity/bin/launch.pyw Tue Dec 10 17:24:12 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__":