XWin - needs dbus
authormb
Wed, 02 Apr 2014 10:41:00 +0100
changeset 110490a78181935
parent 97 f274426bdbb4
child 111 a2c7f29d3683
XWin - needs dbus
Fixed: Not terminating ssh session (due to debus-launcher not closing channels)
OpenSecurity/bin/cygwin.py
OpenSecurity/bin/opensecurity_tray.pyw
OpenSecurity/bin/os-admind.bat
OpenSecurity/bin/vmmanager.pyw
     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 +    
     2.1 --- a/OpenSecurity/bin/opensecurity_tray.pyw	Tue Mar 18 18:00:12 2014 +0100
     2.2 +++ b/OpenSecurity/bin/opensecurity_tray.pyw	Wed Apr 02 10:41:00 2014 +0100
     2.3 @@ -44,7 +44,9 @@
     2.4  # local
     2.5  from about import About
     2.6  from environment import Environment
     2.7 -
     2.8 +from cygwin import Cygwin
     2.9 +import threading
    2.10 +import time
    2.11  # ------------------------------------------------------------
    2.12  # code
    2.13  
    2.14 @@ -102,6 +104,7 @@
    2.15          try:
    2.16          
    2.17              # get a proper browsing VM
    2.18 +            Cygwin.start_X11()
    2.19              browsing_vm = urllib2.urlopen('http://127.0.0.1:8080/browsing').readline()
    2.20              #dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
    2.21              #process_command = [sys.executable, dlg_launch_image, browsing_vm, '/usr/bin/iceweasel']
    2.22 @@ -154,10 +157,8 @@
    2.23          cAcLaunch.triggered.connect(self.clicked_launch_application)
    2.24          cAcAbout.triggered.connect(self.clicked_about)
    2.25          cAcExit.triggered.connect(self.clicked_exit)
    2.26 -        
    2.27 -        
    2.28 +                           
    2.29  def main():
    2.30 -    
    2.31      app = QtGui.QApplication(sys.argv)
    2.32  
    2.33      # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
     3.1 --- a/OpenSecurity/bin/os-admind.bat	Tue Mar 18 18:00:12 2014 +0100
     3.2 +++ b/OpenSecurity/bin/os-admind.bat	Wed Apr 02 10:41:00 2014 +0100
     3.3 @@ -1,4 +1,4 @@
     3.4  @echo off
     3.5  cd %0%\..
     3.6 -C:\Python27\pythonw opensecurityd.pyw 8080
     3.7 +C:\Python27\python opensecurityd.pyw 8080
     3.8  
     4.1 --- a/OpenSecurity/bin/vmmanager.pyw	Tue Mar 18 18:00:12 2014 +0100
     4.2 +++ b/OpenSecurity/bin/vmmanager.pyw	Wed Apr 02 10:41:00 2014 +0100
     4.3 @@ -518,9 +518,12 @@
     4.4          raise OpenSecurityException('Command failed:' + ''.join(result[2]))
     4.5      return result
     4.6  
     4.7 +
     4.8 +            
     4.9  # handles browsing request                    
    4.10  class BrowsingHandler(threading.Thread):   
    4.11      vmm = None
    4.12 +    #Cygwin.start_X11()
    4.13      def __init__(self, vmmanager):
    4.14          threading.Thread.__init__(self)
    4.15          self.vmm = vmmanager
    4.16 @@ -528,7 +531,6 @@
    4.17      def run(self):
    4.18          drive = None
    4.19          try:
    4.20 -            Cygwin.start_X11()
    4.21              new_sdvm = self.vmm.generateSDVMName()
    4.22              self.vmm.createVM(new_sdvm)
    4.23              self.vmm.storageAttach(new_sdvm)
    4.24 @@ -536,12 +538,17 @@
    4.25              self.vmm.attachCertificateISO(new_sdvm)
    4.26              self.vmm.startVM(new_sdvm)
    4.27              new_ip = self.vmm.waitStartup(new_sdvm)
    4.28 -            drive = self.vmm.genNetworkDrive()
    4.29 -            if new_ip != None:
    4.30 -                self.vmm.mapNetworkDrive(drive, '\\\\' + new_ip + '\\Download', None, None)
    4.31 +            #drive = self.vmm.genNetworkDrive()
    4.32 +            #if new_ip != None:
    4.33 +            #    self.vmm.mapNetworkDrive(drive, '\\\\' + new_ip + '\\Download', None, None)
    4.34              #browser = '/usr/bin/iceweasel'
    4.35              #browser = '/usr/bin/midori'
    4.36 -            browser = '/usr/bin/chromium'
    4.37 +            #browser = '/usr/bin/chromium '
    4.38 +            browser = '\\\"/usr/bin/chromium; pidof dbus-launch | xargs kill\\\"'
    4.39 +            Cygwin.start_X11()
    4.40 +           
    4.41 +            #if Cygwin.is_X11_running()==True:
    4.42 +            #result = checkResult(Cygwin.bashExecute('DISPLAY=:0 xhost '+new_ip))
    4.43              result = checkResult(Cygwin.sshExecuteX11(browser, new_ip, 'osecuser', Cygwin.cygPath(self.vmm.getMachineFolder()) + '/' + new_sdvm + '/dvm_key'))
    4.44          except:
    4.45              logger.error("BrowsingHandler failed. Cleaning up")