1.1 --- a/OpenSecurity/bin/launch.py Fri Dec 06 12:24:24 2013 +0100
1.2 +++ b/OpenSecurity/bin/launch.py Tue Dec 10 14:04:11 2013 +0100
1.3 @@ -36,6 +36,8 @@
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 from PyQt4 import QtGui
1.12 @@ -44,7 +46,6 @@
1.13 from about import About
1.14 from cygwin import Cygwin
1.15 from environment import Environment
1.16 -import opensecurity_server
1.17
1.18
1.19 # ------------------------------------------------------------
1.20 @@ -61,17 +62,25 @@
1.21 self.setWindowTitle('OpenSecuirty Launch Application')
1.22 self.setup_ui()
1.23
1.24 - # known vms and applications
1.25 - self._apps, self_vms = [], []
1.26 -
1.27 # positionate ourself central
1.28 screen = QtGui.QDesktopWidget().screenGeometry()
1.29 self.resize(self.geometry().width() * 1.25, self.geometry().height())
1.30 size = self.geometry()
1.31 self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
1.32
1.33 - # refresh vm and command input
1.34 - self.refresh()
1.35 + self._vms = [ { 'name': 'SecurityDVM0', 'ip': '192.168.56.101' } ]
1.36 + self._apps = [ { 'name': 'Browser', 'command': '/usr/bin/iceweasel' } ]
1.37 +
1.38 + # add the VMs we know
1.39 + self._cbVM.clear()
1.40 + for vm in self._vms:
1.41 + self._cbVM.addItem(vm['name'])
1.42 +
1.43 + # add the commands we know
1.44 + self._cbApplication.clear()
1.45 + for app in self._apps:
1.46 + self._cbApplication.addItem(app['name'])
1.47 +
1.48
1.49
1.50 def app_get(self):
1.51 @@ -101,23 +110,6 @@
1.52 self.accept()
1.53
1.54
1.55 - def refresh(self):
1.56 - """load the known vms and commands and adjust input fields"""
1.57 -
1.58 - self._apps = opensecurity_server.query_apps()
1.59 - self._vms = opensecurity_server.query_vms()
1.60 -
1.61 - # add the VMs we know
1.62 - self._cbApplication.clear()
1.63 - for app in self._apps:
1.64 - self._cbApplication.addItem(app['name'])
1.65 -
1.66 - # add the commands we know
1.67 - self._cbVM.clear()
1.68 - for vm in self._vms:
1.69 - self._cbVM.addItem(vm['name'])
1.70 -
1.71 -
1.72 def setup_ui(self):
1.73 """Create the widgets."""
1.74
1.75 @@ -192,17 +184,6 @@
1.76 btnAbout.clicked.connect(self.clicked_about)
1.77
1.78
1.79 - def user_get(self):
1.80 - """The user of the vm of choice."""
1.81 - v = str(self._cbVM.currentText())
1.82 - for vm in self._vms:
1.83 - if v == vm['name']:
1.84 - return vm['user']
1.85 - return v
1.86 -
1.87 - user = property(user_get)
1.88 -
1.89 -
1.90 def vm_get(self):
1.91 """The vm of choice."""
1.92 v = str(self._cbVM.currentText())
1.93 @@ -235,9 +216,9 @@
1.94 app.exec_()
1.95
1.96 if dlg.result() == QtGui.QDialog.Accepted:
1.97 - return dlg.user, dlg.vm, dlg.app
1.98 + return dlg.vm, dlg.app
1.99
1.100 - return '', '', ''
1.101 + return '', ''
1.102
1.103
1.104 def main():
1.105 @@ -245,40 +226,43 @@
1.106
1.107 # parse command line
1.108 parser = argparse.ArgumentParser(description = 'OpenSecurity Launcher: run application in VM')
1.109 - parser.add_argument('user', metavar='USER', help='USER on Virtual Machine', nargs='?', type=str, default='')
1.110 parser.add_argument('ip', metavar='IP', help='IP of Virtual Machine', nargs='?', type=str, default='')
1.111 parser.add_argument('command', metavar='COMMAND', help='Full path of command and arguments to start inside VM', nargs='?', type=str, default='')
1.112 args = parser.parse_args()
1.113
1.114 # we must have at least all or none set
1.115 - set_user = args.user != ''
1.116 set_ip = args.ip != ''
1.117 set_command = args.command != ''
1.118 - set_ALL = set_user and set_ip and set_command
1.119 - set_NONE = (not set_user) and (not set_ip) and (not set_command)
1.120 + set_ALL = set_ip and set_command
1.121 + set_NONE = (not set_ip) and (not set_command)
1.122 if (not set_ALL) and (not set_NONE):
1.123 - sys.stderr.write("Please specify user, ip and command or none.\n")
1.124 + sys.stderr.write("Please specify ip and command or none.\n")
1.125 sys.stderr.write("Type '--help' for help.\n")
1.126 sys.exit(1)
1.127
1.128 # check if we need to ask the user
1.129 if set_NONE:
1.130 - args.user, args.ip, args.command = ask_user()
1.131 + args.ip, args.command = ask_user()
1.132
1.133 # still no IP? --> no chance, over and out!
1.134 if args.ip == '':
1.135 sys.exit(0)
1.136
1.137 # ensure we have our X11 running
1.138 - Cygwin.start_X11()
1.139 + #Cygwin.start_X11()
1.140
1.141 - # the SSH command
1.142 - user_at_guest = args.user + '@' + args.ip
1.143 - ssh = 'DISPLAY=:0 /usr/bin/ssh -Y ' + user_at_guest + ' ' + args.command
1.144 - print(ssh)
1.145 + # call the OpenSecurity Admin to launch our progie =)
1.146 + url_vm = urllib.quote(args.ip)
1.147 + url_command = urllib.quote(args.command)
1.148 + print(url_vm)
1.149 + print(url_command)
1.150
1.151 - # off we go!
1.152 - Cygwin()(['/bin/bash', '--login', '-i', '-c', ssh], None, None, None)
1.153 + # user_at_guest = args.user + '@' + args.ip
1.154 + # ssh = 'DISPLAY=:0 /usr/bin/ssh -Y ' + user_at_guest + ' ' + args.command
1.155 + # print(ssh)
1.156 +
1.157 + # # off we go!
1.158 + # Cygwin()(['/bin/bash', '--login', '-i', '-c', ssh], None, None, None)
1.159
1.160
1.161 # start