1.1 --- a/OpenSecurity/bin/cygwin.py Tue Mar 18 18:00:12 2014 +0100
1.2 +++ b/OpenSecurity/bin/cygwin.py Wed Apr 02 10:41:00 2014 +0100
1.3 @@ -42,7 +42,8 @@
1.4 # local
1.5 from environment import Environment
1.6 from opensecurity_util import logger, setupLogger, OpenSecurityException
1.7 -
1.8 +import time
1.9 +#import wmi
1.10 # ------------------------------------------------------------
1.11 # code
1.12
1.13 @@ -69,6 +70,25 @@
1.14
1.15 return theClass
1.16
1.17 +class XRunner(threading.Thread):
1.18 + #running = True
1.19 + def __init__(self):
1.20 + threading.Thread.__init__(self)
1.21 +
1.22 + def stop(self):
1.23 + self.running = False
1.24 +
1.25 + def run(self):
1.26 + #while self.running:
1.27 + logger.info('X starting')
1.28 + if not Cygwin.is_X11_running():
1.29 + #os.system('"'+Cygwin.cygwin_x11+'" :0 -multiwindow -resize')
1.30 + sts = call('"'+Cygwin.cygwin_x11+'" :0 -multiwindow -resize', shell=True)
1.31 + else:
1.32 + logger.info('X already started')
1.33 +
1.34 +
1.35 +
1.36 @once
1.37 class Cygwin(object):
1.38 cygwin_root = ''
1.39 @@ -197,29 +217,33 @@
1.40 # executes command over ssh on guest vm with X forwarding
1.41 @staticmethod
1.42 def sshExecuteX11(command, address, user_name, certificate, wait_return=True):
1.43 - return Cygwin.bashExecute('DISPLAY=:0.0 /usr/bin/ssh -v -Y -i \\\"' + certificate +'\\\" ' + user_name + '@' + address + ' ' + command + '')
1.44 + #return call('"'+ Cygwin.cygwin_bash +'" -l -c "' + 'DISPLAY=:0.0 ssh -Y -i \\\"' + certificate +'\\\" ' + user_name + '@' + address + ' ' + command + '"', shell=True)
1.45 + return Cygwin.bashExecute('DISPLAY=:0.0 ssh -Y -i \\\"' + certificate +'\\\" ' + user_name + '@' + address + ' ' + command + '')
1.46
1.47 @staticmethod
1.48 def is_X11_running():
1.49 """check if we can connect to a X11 running instance"""
1.50 - p = Cygwin.bashExecute('DISPLAY=:0 xset -q') #/usr/bin/
1.51 + p = Cygwin.bashExecute('xset -display :0.0 q', wait_return = True, window = False)
1.52 return p[0] == 0
1.53
1.54 -
1.55 @staticmethod
1.56 def start_X11():
1.57 """start X11 in the background (if not already running) on DISPLAY=:0"""
1.58 - # do not start if already running
1.59 - if Cygwin.is_X11_running():
1.60 - return
1.61 - # launch X11 (forget output and return immediately)
1.62 - return Cygwin.execute(Cygwin.cygwin_x11, ':0 -multiwindow', wait_return = False, window = False)
1.63 + runner = XRunner()
1.64 + runner.start()
1.65 + return (0, None, None)
1.66 +
1.67 + # launch X11
1.68 + #return Cygwin.execute(Cygwin.cygwin_x11, ':0 -multiwindow', wait_return = True, window = False)
1.69 + #return Cygwin.bashExecute('XWin :0 -multiwindow', wait_return = True, window = False)
1.70 + #return Cygwin.bashExecute('DISPLAY=:0.0 xhost +', wait_return = True, window = False)
1.71 + #return os.system('"'+Cygwin.cygwin_x11+'" :0 -multiwindow -resize')
1.72
1.73 @staticmethod
1.74 def cygPath(path):
1.75 cmd = 'cygpath -u \'' + path + '\''
1.76 return Cygwin.bashExecute(cmd)[1].rstrip('\n')
1.77 -
1.78 +
1.79 # start
1.80 if __name__ == "__main__":
1.81 logger = setupLogger('Cygwin')
1.82 @@ -228,8 +252,31 @@
1.83 logger.info(c.bin())
1.84 logger.info(c.bash())
1.85 logger.info(c.ssh())
1.86 + logger.info(c.x11())
1.87
1.88 - print(c.bashExecute('echo $PATH')[1])
1.89 - print(c.cygPath('C:'))
1.90 - print('C:\\Program Files\\OpenSecurity: ' + c.cygPath('C:\\Program Files\\OpenSecurity'))
1.91 - c.start_X11()
1.92 + runner = XRunner()
1.93 + runner.start()
1.94 +
1.95 + Cygwin.start_X11()
1.96 +
1.97 +
1.98 +
1.99 + #time.sleep(500)
1.100 +
1.101 + #Cygwin.start_X11()
1.102 + #print (Cygwin.is_X11_running())
1.103 + #print (Cygwin.is_X11_running())
1.104 + #new_sdvm = 'SecurityDVM0'
1.105 + #new_ip = Cygwin.vboxExecute('guestproperty get ' + new_sdvm + ' /VirtualBox/GuestInfo/Net/0/V4/IP')[1]
1.106 + #new_ip = new_ip[new_ip.index(':')+1:].strip()
1.107 + #new_ip = '+'
1.108 + #result = Cygwin.bashExecute('DISPLAY=:0.0 xhost '+new_ip)
1.109 + #browser = '/usr/bin/midori '
1.110 + #print(Cygwin.sshExecuteX11(browser, new_ip, 'osecuser', '/cygdrive/c/Users/BarthaM/VirtualBox VMs' + '/' + new_sdvm + '/dvm_key'))
1.111 +
1.112 + #print(Cygwin.bashExecute('echo $PATH')[1])
1.113 + #print(Cygwin.cygPath('C:'))
1.114 + #print('C:\\Program Files\\OpenSecurity: ' + c.cygPath('C:\\Program Files\\OpenSecurity'))
1.115 +
1.116 + sys.exit(0)
1.117 +