1.1 --- a/OpenSecurity/bin/cygwin.py Tue May 20 11:21:48 2014 +0200
1.2 +++ b/OpenSecurity/bin/cygwin.py Tue May 20 15:26:03 2014 +0200
1.3 @@ -37,7 +37,7 @@
1.4 import subprocess
1.5 import sys
1.6 import _winreg
1.7 -from subprocess import Popen, PIPE, call, STARTUPINFO, _subprocess
1.8 +from subprocess import Popen, PIPE, STARTUPINFO, _subprocess
1.9 import threading
1.10
1.11 # local
1.12 @@ -74,24 +74,6 @@
1.13 theClass.user_home = os.environ['APPDATA']#os.path.expandvars("%APPDATA%")
1.14 return theClass
1.15
1.16 -class XRunner(threading.Thread):
1.17 - #running = True
1.18 - def __init__(self):
1.19 - threading.Thread.__init__(self)
1.20 -
1.21 - def stop(self):
1.22 - self.running = False
1.23 -
1.24 - def run(self):
1.25 - #while self.running:
1.26 - logger.info('X starting')
1.27 - if not Cygwin.is_X11_running():
1.28 - #os.system('"'+Cygwin.cygwin_x11+'" :0 -multiwindow -resize')
1.29 - sts = call('"'+Cygwin.cygwin_x11+'" :0 -multiwindow -resize', shell=True)
1.30 - else:
1.31 - logger.info('X already started')
1.32 -
1.33 -
1.34
1.35 @once
1.36 class Cygwin(object):
1.37 @@ -231,27 +213,23 @@
1.38 # executes command over ssh on guest vm with X forwarding
1.39 @staticmethod
1.40 def sshExecuteX11(command, address, user_name, certificate, wait_return=True):
1.41 - #return call('"'+ Cygwin.cygwin_bash +'" -l -c "' + 'DISPLAY=:0.0 ssh -Y -i \\\"' + certificate +'\\\" ' + user_name + '@' + address + ' ' + command + '"', shell=True)
1.42 return Cygwin.bashExecute('DISPLAY=:0.0 ssh -Y -o StrictHostKeyChecking=no -i \\\"' + certificate +'\\\" ' + user_name + '@' + address + ' ' + command + '')
1.43
1.44 @staticmethod
1.45 def is_X11_running():
1.46 """check if we can connect to a X11 running instance"""
1.47 - p = Cygwin.bashExecute('xset -display :0.0 q', wait_return = True, window = False)
1.48 + p = Cygwin.bashExecute('xset -display :0 q', wait_return = True, window = False)
1.49 return p[0] == 0
1.50
1.51 @staticmethod
1.52 def start_X11():
1.53 - """start X11 in the background (if not already running) on DISPLAY=:0"""
1.54 - runner = XRunner()
1.55 - runner.start()
1.56 + """start X11 in the background (if not already running) on DISPLAY=:0
1.57 +
1.58 + If there is already a X11 running then exit silently, calling this
1.59 + method as often as needed.
1.60 + """
1.61 + Popen('"' + Cygwin.cygwin_x11 + '" :0 -multiwindow -resize -silent-dup-error')
1.62 return (0, None, None)
1.63 -
1.64 - # launch X11
1.65 - #return Cygwin.execute(Cygwin.cygwin_x11, ':0 -multiwindow', wait_return = True, window = False)
1.66 - #return Cygwin.bashExecute('XWin :0 -multiwindow', wait_return = True, window = False)
1.67 - #return Cygwin.bashExecute('DISPLAY=:0.0 xhost +', wait_return = True, window = False)
1.68 - #return os.system('"'+Cygwin.cygwin_x11+'" :0 -multiwindow -resize')
1.69
1.70 @staticmethod
1.71 def cygPath(path):
2.1 --- a/OpenSecurity/bin/opensecurity_tray.pyw Tue May 20 11:21:48 2014 +0200
2.2 +++ b/OpenSecurity/bin/opensecurity_tray.pyw Tue May 20 15:26:03 2014 +0200
2.3 @@ -32,6 +32,7 @@
2.4 # imports
2.5
2.6 import argparse
2.7 +import json
2.8 import os
2.9 import subprocess
2.10 import sys
2.11 @@ -117,8 +118,10 @@
2.12
2.13 # TODO: HARDCODED ADDRESS OF OPENSECURITYD
2.14 browsing_vm = urllib2.urlopen('http://127.0.0.1:8080/browsing').readline()
2.15 + print('Called http://127.0.0.1:8080/browsing got: ' + str(browsing_vm))
2.16
2.17 except:
2.18 +
2.19 d.hide()
2.20 QtGui.QApplication.instance().processEvents()
2.21 QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
2.22 @@ -143,8 +146,24 @@
2.23 """clicked the launch an application"""
2.24 dlg_launch_image = os.path.join(sys.path[0], 'ui', 'launch_dialog.py')
2.25 process_command = [sys.executable, dlg_launch_image]
2.26 - print(process_command)
2.27 - process = subprocess.Popen(process_command, shell = False)
2.28 + process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
2.29 + try:
2.30 + stdout = process.communicate()[0]
2.31 + j = json.loads(stdout)
2.32 + except:
2.33 + return
2.34 +
2.35 + try:
2.36 +
2.37 + # get a proper browsing VM
2.38 + Cygwin.start_X11()
2.39 +
2.40 + # TODO: HARDCODED ADDRESS OF OPENSECURITYD
2.41 + url = 'http://127.0.0.1:8080/sdvms/' + j['vm'] + '/application' + j['application']
2.42 + result = urllib2.urlopen(url).readline()
2.43 +
2.44 + except:
2.45 + pass
2.46
2.47
2.48 def clicked_mail(self):
3.1 --- a/OpenSecurity/bin/opensecurityd.pyw Tue May 20 11:21:48 2014 +0200
3.2 +++ b/OpenSecurity/bin/opensecurityd.pyw Tue May 20 15:26:03 2014 +0200
3.3 @@ -244,8 +244,7 @@
3.4 global gvm_mgr
3.5 command = '/' + command
3.6 result = Cygwin.sshExecuteX11(command, gvm_mgr.getHostOnlyIP(name), 'osecuser', Cygwin.cygPath(gvm_mgr.getMachineFolder()) + '/' + name + '/dvm_key' )
3.7 - self.poweroffVM(name)
3.8 - return gvm_mgr.removeVM(name)
3.9 + return 'Command ' + str(command) + ' started on VM "' + name + '" with IP ' + gvm_mgr.getHostOnlyIP(name)
3.10
3.11
3.12 class os_sdvm_ip:
4.1 --- a/OpenSecurity/bin/ui/launch_dialog.py Tue May 20 11:21:48 2014 +0200
4.2 +++ b/OpenSecurity/bin/ui/launch_dialog.py Tue May 20 15:26:03 2014 +0200
4.3 @@ -85,12 +85,12 @@
4.4
4.5 """Ok button has been clicked."""
4.6 sys.stdout.write('{ ')
4.7 - sys.stdout.write('\'application\': \'')
4.8 + sys.stdout.write('"application": "')
4.9 sys.stdout.write(self.app)
4.10 - sys.stdout.write('\', ')
4.11 - sys.stdout.write('\'vm\': \'')
4.12 + sys.stdout.write('", ')
4.13 + sys.stdout.write('"vm": "')
4.14 sys.stdout.write(self.vm)
4.15 - sys.stdout.write('\' ')
4.16 + sys.stdout.write('" ')
4.17 sys.stdout.write('}\n')
4.18 self.accept()
4.19
4.20 @@ -111,7 +111,7 @@
4.21
4.22 if __name__ == "__main__":
4.23 a = QtGui.QApplication(sys.argv)
4.24 - d = LaunchDialog(['SDVM0', 'SDVM1'], ['/usr/bin/chromium', '/usr/bin/thunderbird'])
4.25 + d = LaunchDialog(['SecurityDVM0', 'SecurityDVM1'], ['/usr/bin/xterm', '/usr/bin/chromium', '/usr/bin/thunderbird'])
4.26 d.show()
4.27 sys.exit(a.exec_())
4.28