merge
authormb
Tue, 18 Feb 2014 14:40:49 +0100
changeset 679cbc46fcc100
parent 66 d768c98d1e48
parent 65 7877250bcf6f
child 69 e08ddfc32901
merge
     1.1 --- a/OpenSecurity/bin/cygwin.py	Tue Feb 18 14:38:24 2014 +0100
     1.2 +++ b/OpenSecurity/bin/cygwin.py	Tue Feb 18 14:40:49 2014 +0100
     1.3 @@ -59,6 +59,7 @@
     1.4      theClass.cygwin_bin = os.path.join(theClass.cygwin_root, 'bin') + os.path.sep
     1.5      theClass.cygwin_bash = os.path.join(theClass.cygwin_bin, 'bash.exe')
     1.6      theClass.cygwin_ssh = os.path.join(theClass.cygwin_bin, 'ssh.exe')
     1.7 +    theClass.cygwin_x11 = os.path.join(theClass.cygwin_bin, 'XWin.exe')
     1.8      theClass.win_cmd = os.environ.get("COMSPEC", "cmd.exe") 
     1.9      
    1.10      """get the path to the VirtualBox installation on this system"""
    1.11 @@ -77,6 +78,7 @@
    1.12      cygwin_bin = ''
    1.13      cygwin_bash = ''
    1.14      cygwin_ssh = ''
    1.15 +    cygwin_x11 = ''
    1.16      vbox_root = ''
    1.17      vbox_man = ''
    1.18      win_cmd = ''
    1.19 @@ -102,6 +104,10 @@
    1.20      @staticmethod    
    1.21      def ssh():
    1.22          return Cygwin.cygwin_ssh
    1.23 +
    1.24 +    @staticmethod    
    1.25 +    def x11():
    1.26 +        return Cygwin.cygwin_x11
    1.27      
    1.28      @staticmethod
    1.29      def vboxman():
    1.30 @@ -143,7 +149,7 @@
    1.31      
    1.32      @staticmethod
    1.33      def bashExecute(command, wait_return=True, window = False, bash_opts=''):
    1.34 -        command = bash_opts + ' --login -c ' + command
    1.35 +        command = bash_opts + ' -l -c '  + command
    1.36          return Cygwin.execute(Cygwin.cygwin_bash, command, wait_return, window)
    1.37      
    1.38      @staticmethod
    1.39 @@ -181,7 +187,7 @@
    1.40          if Cygwin.is_X11_running():
    1.41              return           
    1.42          # launch X11 (forget output and return immediately)
    1.43 -        return Cygwin.bashExecute('"/usr/bin/X :0 -multiwindow"', bash_opts=' -i ', wait_return = False)
    1.44 +        return Cygwin.execute(Cygwin.cygwin_x11, ':0 -multiwindow', wait_return = False, window = False)
    1.45      
    1.46      @staticmethod    
    1.47      def cygPath(path):
     2.1 --- a/OpenSecurity/install/initial_vm.bat	Tue Feb 18 14:38:24 2014 +0100
     2.2 +++ b/OpenSecurity/install/initial_vm.bat	Tue Feb 18 14:40:49 2014 +0100
     2.3 @@ -1,58 +1,107 @@
     2.4 -@echo off
     2.5 -
     2.6 -rem ensure environment is ready
     2.7 -
     2.8 -rem This gets up VirtualBox VBoxSVC.exe COM Server right
     2.9 -rem and thus helps us not to run in any timing problems
    2.10 -rem due to a lazy VBox COM Server ... o.O
    2.11 -VBoxManage list vms > %TEMP%\VMS.txt
    2.12 -del %TEMP%\VMS.txt
    2.13 -
    2.14 -rem Now, VBox should feel good within the Windows OS space
    2.15 -rem switch into the User's VBox setup folders
    2.16 -C:
    2.17 -cd "C:\Users\%USERNAME%
    2.18 -mkdir "VirtualBox VMs"
    2.19 -cd "VirtualBox VMs"
    2.20 -
    2.21 -rem get recent initial VM and create disk image
    2.22 -echo "download initial OpenSecurity VM"
    2.23 -rem wget http://service.x-net.at/opensecurity/OsecVM_initialized.ova
    2.24 -
    2.25 -rem I've already downloaded ... this is for convenience --> delete this line
    2.26 -rem This is just for testing. Enbale the real "wget http://service...." line above
    2.27 -rem to get the real VM image from X-Net
    2.28 -copy C:\Users\dyle\Documents\OpenSecurity\setup\OsecVM_initialized.ova .
    2.29 -
    2.30 -rem import the VM
    2.31 -VBoxManage.exe import OsecVM_initialized.ova --vsys 0 --vmname SecurityDVM --unit 12 --disk SecurityDVM\SecurityDVM.vmdk
    2.32 -
    2.33 -rem launch the SecurityVM the first time to let the user do initial updates
    2.34 -VBoxManage.exe startvm SecurityDVM
    2.35 -
    2.36 -echo # Start VirtualBox and update the machine	
    2.37 -echo #                                         
    2.38 -echo # login with                              
    2.39 -echo #   user: root                            
    2.40 -echo #   pass: osecvm                          
    2.41 -echo #                                         
    2.42 -echo # issue these commands as root            
    2.43 -echo #                                         
    2.44 -echo #       # apt-get update                  
    2.45 -echo #       # apt-get upgrade                 
    2.46 -echo #       # apt-get dist-upgrade            
    2.47 -echo #                                         
    2.48 -echo # then shutdown the machine with          
    2.49 -echo #                                         
    2.50 -echo #       # shutdown -h now                 
    2.51 -echo #                                         
    2.52 -echo # press a key when done to proceed        
    2.53 -pause
    2.54 -
    2.55 -rem Turn the VM disk image immutable and attach it
    2.56 -echo sealing disk image ...
    2.57 -VBoxManage.exe storageattach SecurityDVM --storagectl SATA --port 0 --medium none
    2.58 -VBoxManage.exe modifyhd SecurityDVM\SecurityDVM.vmdk --type immutable
    2.59 -VBoxManage.exe storageattach SecurityDVM --storagectl SATA --port 0 --device 0 --type hdd --mtype normal --medium SecurityDVM\SecurityDVM.vmdk
    2.60 -echo done. OpenSecurity is ready to serve
    2.61 -
    2.62 +@echo off
    2.63 +
    2.64 +cd "%0%\.."
    2.65 +SET WGET="%0%\..\..\cygwin64\bin\wget.exe"
    2.66 +SET BASH="%0%\..\..\cygwin64\bin\bash.exe"
    2.67 +SET OS_ADMIN_PORT=8080
    2.68 +
    2.69 +rem ------------------------------------------------------------
    2.70 +rem install initial OpenSecuity VM image
    2.71 +rem ------------------------------------------------------------
    2.72 +
    2.73 +SET OVA_TEMPLATE_URL="http://service.x-net.at/opensecurity/OsecVM_latest.ova"
    2.74 +
    2.75 +
    2.76 +:ENSURE_VBOX_READY
    2.77 +rem ensure environment is ready
    2.78 +rem This gets up VirtualBox VBoxSVC.exe COM Server right
    2.79 +rem and thus helps us not to run in any timing problems
    2.80 +rem due to a lazy VBox COM Server ... o.O
    2.81 +rem
    2.82 +rem 1. locate the VBoxManage.exe
    2.83 +rem 2. check version (ability to call)
    2.84 +rem 3. enumerate vms (ensure VBoxSVC.exe feels good)
    2.85 +
    2.86 +CSCRIPT //NoLogo vbox_lookup.vbs >%TEMP%\vbox_lookup
    2.87 +SET /P VBM_DIR=<%TEMP%\vbox_lookup
    2.88 +SET VBM="%VBM_DIR%VBoxManage.exe"
    2.89 +IF NOT EXIST %VBM% GOTO VBM_MISSING
    2.90 +%VBM% -version >%TEMP%\vbox_version
    2.91 +IF NOT ERRORLEVEL 0 GOTO VBM_ERROR
    2.92 +%VBM% list vms > %TEMP%\VMS.txt
    2.93 +del %TEMP%\VMS.txt
    2.94 +
    2.95 +
    2.96 +:PREPARE_VBOX_FOLDER
    2.97 +rem Now, VBox should feel good within the Windows OS space
    2.98 +rem switch into the User's VBox setup folders 
    2.99 +rem
   2.100 +rem 1. create Virtual box folder (if not already existing)
   2.101 +rem 2. download OVA template
   2.102 +rem 3. import OVS template in VBox
   2.103 +
   2.104 +SET VBP=%HOMEDRIVE%%HOMEPATH%\VirtualBox VMs
   2.105 +IF NOT EXIST "%VBP%" MKDIR "%VBP%"
   2.106 +
   2.107 +
   2.108 +:DOWNLOAD_TEMPLATE_VM
   2.109 +rem Download the OSec.ova template from the X-Net servers
   2.110 +
   2.111 +IF EXIST OsecVM.ova GOTO COPY_TEMPLATE_VM
   2.112 +echo "download initial OpenSecurity VM"
   2.113 +"%WGET%" %OVA_TEMPLATE_URL%
   2.114 +IF NOT ERRORLEVEL 0 GOTO OVA_DOWNLOAD_ERROR
   2.115 +RENAME OsecVM_latest.ova OsecVM.ova
   2.116 +
   2.117 +:COPY_TEMPLATE_VM
   2.118 +echo "copying template VM into Virtual Box's realm"
   2.119 +%HOMEDRIVE%
   2.120 +cd "%VBP%"
   2.121 +COPY "%0%\..\OSecVM.ova" .
   2.122 +
   2.123 +
   2.124 +:IMPORT_TEMPLATE_VM
   2.125 +%VBM% import OsecVM.ova --vsys 0 --vmname SecurityDVM --unit 12 --disk SecurityDVM\SecurityDVM.vmdk
   2.126 +IF NOT ERRORLEVEL 0 GOTO VBM_IMPORT_ERROR
   2.127 +echo "turn template into immutable image"
   2.128 +%VBM% storageattach SecurityDVM --storagectl SATA --port 0 --medium none
   2.129 +%VBM% storageattach SecurityDVM --storagectl SATA --port 0 --device 0 --type hdd --mtype writethrough --medium SecurityDVM\SecurityDVM.vmdk
   2.130 +%VBM% storageattach SecurityDVM --storagectl SATA --port 0 --medium none
   2.131 +%VBM% storageattach SecurityDVM --storagectl SATA --port 0 --device 0 --type hdd --mtype immutable --medium SecurityDVM\SecurityDVM.vmdk
   2.132 +echo "OpenSecurity VM Image ready."
   2.133 +
   2.134 +:UPDATE_TEMPLATE
   2.135 +rem we have imported the Template
   2.136 +rem now, we need to update the template before first use
   2.137 +
   2.138 +cd "%0%\..\.."
   2.139 +SET PATH=%CD%\python27;%PATH%
   2.140 +START python27\pythonw bin\opensecurityd.pyw
   2.141 +echo Waiting for OpenSecurity Amdin Daemon to start
   2.142 +%BASH% -c -l "for i in $(seq 0 4); do echo -n '.'; sleep 1; done; echo"
   2.143 +rem trigger update
   2.144 +%WGET% http://localhost:%OS_ADMIN_PORT%/update_template
   2.145 +GOTO END
   2.146 +
   2.147 +
   2.148 +:OVA_DOWNLOAD_ERROR
   2.149 +echo "Failed to download OVA initial image."
   2.150 +GOTO END
   2.151 +
   2.152 +
   2.153 +:VBM_ERROR
   2.154 +echo "Error calling VBoxManage.exe"
   2.155 +GOTO END
   2.156 +
   2.157 +
   2.158 +:VBM_MISSING
   2.159 +echo "Could not locate VBoxManage.exe --> Is VirtualBox installed?"
   2.160 +GOTO END
   2.161 +
   2.162 +
   2.163 +:VBM_IMPORT_ERROR
   2.164 +echo "Failed to import OVA template into VBox."
   2.165 +GOTO END
   2.166 +
   2.167 +
   2.168 +:END