working on installment and console-less
authordyle@opensecurity.d03.arc.local
Mon, 27 Jan 2014 15:12:33 +0000
changeset 521238895dc6b6
parent 51 9e8fffdb8f47
child 53 01839f13cef3
working on installment and console-less
OpenSecurity/bin/cygwin.py
OpenSecurity/bin/launch.pyw
OpenSecurity/bin/vmmanager.py
OpenSecurity/install/initial_vm.bat
     1.1 --- a/OpenSecurity/bin/cygwin.py	Thu Jan 23 17:03:27 2014 +0000
     1.2 +++ b/OpenSecurity/bin/cygwin.py	Mon Jan 27 15:12:33 2014 +0000
     1.3 @@ -67,19 +67,25 @@
     1.4          return path_valid[0]
     1.5  
     1.6  
     1.7 -    def execute(self, command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE):
     1.8 +    def execute(self, command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, dos_window = False):
     1.9          """execute a cygwin shell command
    1.10          
    1.11          command is list of arguments like ['/bin/ls', '-al', '-h']
    1.12          
    1.13          a Popen object is returned"""
    1.14 -        command_path = Cygwin.root() + os.sep.join(command[0].split('/'))
    1.15 +        command_path = os.sep.join([Cygwin.root()] + command[0].split('/')[1:])
    1.16          command = [command_path] + command[1:]
    1.17 -        
    1.18 +
    1.19 +        # with or without DOS window
    1.20 +        if not dos_window:
    1.21 +            run_command = os.sep.join([Cygwin.root()] + ['bin', 'run']) 
    1.22 +            command = [run_command] + command
    1.23 +
    1.24          try:
    1.25 +            print('cygwin: ' + ' '.join(command))
    1.26              return subprocess.Popen(command, shell = False, stdin = stdin, stdout = stdout, stderr = stderr)
    1.27          except:
    1.28 -            sys.stderr.writeln('Failed to execute cygwin command.\n\tcommand="' + command + '"')
    1.29 +            sys.stderr.write('Failed to execute cygwin command.\n\tcommand="' + ' '.join(command) + '"\n')
    1.30          
    1.31          
    1.32      @staticmethod
     2.1 --- a/OpenSecurity/bin/launch.pyw	Thu Jan 23 17:03:27 2014 +0000
     2.2 +++ b/OpenSecurity/bin/launch.pyw	Mon Jan 27 15:12:33 2014 +0000
     2.3 @@ -238,7 +238,10 @@
     2.4          
     2.5      # ensure we have our X11 running
     2.6      Cygwin.start_X11()
     2.7 -    
     2.8 +   
     2.9 +    sys.exit(0)
    2.10 +
    2.11 +
    2.12      # call the OpenSecurity Admin to launch our progie =)
    2.13      # TODO: hard coded PORT
    2.14      url = 'http://127.0.0.1:8080/sdvms/' + args.vm + '/application' + args.command
     3.1 --- a/OpenSecurity/bin/vmmanager.py	Thu Jan 23 17:03:27 2014 +0000
     3.2 +++ b/OpenSecurity/bin/vmmanager.py	Mon Jan 27 15:12:33 2014 +0000
     3.3 @@ -15,6 +15,9 @@
     3.4  import time
     3.5  import string
     3.6  
     3.7 +#import shutil
     3.8 +#import stat
     3.9 +
    3.10  
    3.11  DEBUG = True
    3.12  class VMManagerException(Exception):
    3.13 @@ -284,6 +287,57 @@
    3.14      #generates ISO containing authorized_keys for use with guest VM
    3.15      def genCertificateISO(self, vm_name):
    3.16          machineFolder = self.getDefaultMachineFolder()
    3.17 +
    3.18 +        ## create a SSH key pair in a machine subfolder
    3.19 +        #vm_folder = os.path.join(machineFolder, vm_name)
    3.20 +        #ssh_folder = os.path.join(vm_folder, '.ssh')
    3.21 +        #try:
    3.22 +        #    os.mkdir(ssh_folder)
    3.23 +        #except:
    3.24 +        #    pass
    3.25 +        #ssh_keyfile = os.path.join(ssh_folder, 'dvm_key')
    3.26 +        #
    3.27 +        # delete old key file (if existing)
    3.28 +        #try:
    3.29 +        #    os.remove(ssh_keyfile)
    3.30 +        #except:
    3.31 +        #    pass
    3.32 +        #
    3.33 +        ## create new key file    
    3.34 +        #try:
    3.35 +        #    p = Cygwin()(['/bin/ssh-keygen', '-q', '-t', 'rsa', '-N', '', '-C', vm_name, '-f', ssh_keyfile])
    3.36 +        #    p.wait()
    3.37 +        #except:
    3.38 +        #    sys.stderr.write('failed to create a new SSH key pair as: ' + ssh_keyfile + '\n')
    3.39 +        #    return
    3.40 +        #try:
    3.41 +        #    os.chmod(ssh_keyfile,  stat.S_IREAD)
    3.42 +        #except:
    3.43 +        #    pass
    3.44 +        #
    3.45 +        ## move out private key
    3.46 +        #try:
    3.47 +        #    os.rename(ssh_keyfile, os.path.join(vm_folder, 'dvm_key'))
    3.48 +        #except : 
    3.49 +        #    sys.stderr.write('failed to move private SSH key\n')
    3.50 +        #    return
    3.51 +        #
    3.52 +        ## rename public key to 'authorized_keys'
    3.53 +        #try:
    3.54 +        #    os.rename(ssh_keyfile + '.pub', os.path.join(ssh_folder, 'authorized_keys'))
    3.55 +        #except:
    3.56 +        #    sys.stderr.write('failed to rename public key to "authorized_keys"\n')
    3.57 +        #    return
    3.58 +        #
    3.59 +        ## generate ISO image  
    3.60 +        #iso_file = os.path.join(vm_folder, vm_name + '.iso')
    3.61 +        #try:
    3.62 +        #    p = Cygwin()(['/bin/genisoimage', '-J', '-R', '-o', iso_file, ssh_folder])
    3.63 +        #    p.wait()
    3.64 +        #except:
    3.65 +        #    sys.stderr.write('failed to create ISO image.\n')
    3.66 +        #    return
    3.67 +
    3.68          # create .ssh folder in vm_name
    3.69          cmd = self.cygwin_path+'bash.exe --login -c \"mkdir -p \\\"' + machineFolder + '\\' + vm_name + '\\.ssh\\\"\"'
    3.70          self.execute(cmd)
    3.71 @@ -468,4 +522,4 @@
    3.72      time.sleep(60)
    3.73      #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""
    3.74      #man.execute(cmd)
    3.75 -    
    3.76 \ No newline at end of file
    3.77 +    
     4.1 --- a/OpenSecurity/install/initial_vm.bat	Thu Jan 23 17:03:27 2014 +0000
     4.2 +++ b/OpenSecurity/install/initial_vm.bat	Mon Jan 27 15:12:33 2014 +0000
     4.3 @@ -1,37 +1,58 @@
     4.4  @echo off
     4.5  
     4.6  rem ensure environment is ready
     4.7 +
     4.8 +rem This gets up VirtualBox VBoxSVC.exe COM Server right
     4.9 +rem and thus helps us not to run in any timing problems
    4.10 +rem due to a lazy VBox COM Server ... o.O
    4.11 +VBoxManage list vms > %TEMP%\VMS.txt
    4.12 +del %TEMP%\VMS.txt
    4.13 +
    4.14 +rem Now, VBox should feel good within the Windows OS space
    4.15 +rem switch into the User's VBox setup folders
    4.16  C:
    4.17 -cd "C:\Documents and Settings\%USERNAME%\VirtualBox VMs"
    4.18 +cd "C:\Users\%USERNAME%
    4.19 +mkdir "VirtualBox VMs"
    4.20 +cd "VirtualBox VMs"
    4.21  
    4.22  rem get recent initial VM and create disk image
    4.23  echo "download initial OpenSecurity VM"
    4.24  rem wget http://service.x-net.at/opensecurity/OsecVM_initialized.ova
    4.25 -VBoxManage.exe import OsecVM_initialized.ova --vsys 0 --vmname SecurityDVM --unit 12 --disk SecurityDVM.vmdk
    4.26  
    4.27 -# launch the SecurityVM the first time to let the user do initial updates
    4.28 +rem I've already downloaded ... this is for convenience --> delete this line
    4.29 +rem This is just for testing. Enbale the real "wget http://service...." line above
    4.30 +rem to get the real VM image from X-Net
    4.31 +copy C:\Users\dyle\Documents\OpenSecurity\setup\OsecVM_initialized.ova .
    4.32 +
    4.33 +rem import the VM
    4.34 +VBoxManage.exe import OsecVM_initialized.ova --vsys 0 --vmname SecurityDVM --unit 12 --disk SecurityDVM\SecurityDVM.vmdk
    4.35 +
    4.36 +rem launch the SecurityVM the first time to let the user do initial updates
    4.37  VBoxManage.exe startvm SecurityDVM
    4.38  
    4.39 -echo "# Start VirtualBox and update the machine	"
    4.40 -echo "#                                         "
    4.41 -echo "# login with                              "
    4.42 -echo "#   user: root                            "
    4.43 -echo "#   pass: osecvm                          "
    4.44 -echo "#                                         "
    4.45 -echo "# issue these commands as root            "
    4.46 -echo "#                                         "
    4.47 -echo "#       # apt-get update                  "
    4.48 -echo "#       # apt-get upgrade                 "
    4.49 -echo "#       # apt-get dist-upgrade            "
    4.50 -echo "#                                         "
    4.51 -echo "# then shutdown the machine with          "
    4.52 -echo "#                                         "
    4.53 -echo "#       # shutdown -h now                 "
    4.54 -echo "#                                         "
    4.55 -echo "# press a key when done to proceed        "
    4.56 +echo # Start VirtualBox and update the machine	
    4.57 +echo #                                         
    4.58 +echo # login with                              
    4.59 +echo #   user: root                            
    4.60 +echo #   pass: osecvm                          
    4.61 +echo #                                         
    4.62 +echo # issue these commands as root            
    4.63 +echo #                                         
    4.64 +echo #       # apt-get update                  
    4.65 +echo #       # apt-get upgrade                 
    4.66 +echo #       # apt-get dist-upgrade            
    4.67 +echo #                                         
    4.68 +echo # then shutdown the machine with          
    4.69 +echo #                                         
    4.70 +echo #       # shutdown -h now                 
    4.71 +echo #                                         
    4.72 +echo # press a key when done to proceed        
    4.73  pause
    4.74  
    4.75  rem Turn the VM disk image immutable and attach it
    4.76 +echo sealing disk image ...
    4.77  VBoxManage.exe storageattach SecurityDVM --storagectl SATA --port 0 --medium none
    4.78 -VBoxManage.exe modifyhd SecurityDVM.vmdk settype immutable
    4.79 -VBoxManage.exe storageattach SecurityDVM --storagectl SATA --port 0 --device 0 --type hdd --mtype normal --medium SecurityDVM.vmdk
    4.80 +VBoxManage.exe modifyhd SecurityDVM\SecurityDVM.vmdk --type immutable
    4.81 +VBoxManage.exe storageattach SecurityDVM --storagectl SATA --port 0 --device 0 --type hdd --mtype normal --medium SecurityDVM\SecurityDVM.vmdk
    4.82 +echo done. OpenSecurity is ready to serve
    4.83 +