OpenSecurity/bin/opensecurityd.pyw
changeset 91 a26757850ea9
parent 90 bfd41c38d156
child 93 8fe521017397
     1.1 --- a/OpenSecurity/bin/opensecurityd.pyw	Fri Mar 07 14:32:12 2014 +0100
     1.2 +++ b/OpenSecurity/bin/opensecurityd.pyw	Mon Mar 10 13:01:08 2014 +0100
     1.3 @@ -36,12 +36,13 @@
     1.4  import os.path
     1.5  import subprocess
     1.6  import sys
     1.7 +import tempfile
     1.8  import web
     1.9 -from cygwin import Cygwin
    1.10  
    1.11  import vmmanager
    1.12  
    1.13  # local
    1.14 +from cygwin import Cygwin
    1.15  from environment import Environment
    1.16  from opensecurity_util import logger
    1.17  
    1.18 @@ -55,6 +56,8 @@
    1.19  """All the URLs we know mapping to class handler"""
    1.20  opensecurity_urls = (
    1.21      '/browsing',                        'os_browsing',          # http://localhost:8080/browsing                                GET
    1.22 +    '/fetch_initial_image',             'os_fetch_image',       # http://localhost:8080/fetch_initial_image                     GET
    1.23 +    '/init',                            'os_init',              # http://localhost:8080/init                                    GET
    1.24      '/sdvms',                           'os_sdvms',             # http://localhost:8080/sdvms                                   GET, PUT
    1.25      '/sdvms/(.*)/application/(.*)',     'os_sdvm_application',  # http://localhost:8080/sdvms/[VMNAME]/application/[COMMAND]    GET
    1.26      '/sdvms/(.*)/ip',                   'os_sdvm_ip',           # http://localhost:8080/sdvms/[VMNAME]/ip                       GET
    1.27 @@ -96,6 +99,52 @@
    1.28              raise web.internalerror()
    1.29  
    1.30         
    1.31 +class os_fetch_image:
    1.32 +    """OpenSecurity '/fetch_initial_image' handler
    1.33 +    
    1.34 +    - GET: fetch the initial image from the X-Net Servers
    1.35 +            The initial image is stored in the
    1.36 +            Virtual Box default machine path.
    1.37 +            The result to this call is a temprary file
    1.38 +            which shows the progress (or error state)
    1.39 +            of this call.
    1.40 +    """
    1.41 +    
    1.42 +    def GET(self):
    1.43 +        
    1.44 +        log_call(web.ctx.environ)
    1.45 +        global gvm_mgr
    1.46 +
    1.47 +        trace_file_name = os.path.join(tempfile.gettempdir(), 'OpenSecurity_fetch_image.log')
    1.48 +        trace_file = open(trace_file_name, 'w+')
    1.49 +
    1.50 +        machine_folder = Cygwin.cygPath(gvm_mgr.getMachineFolder()) 
    1.51 +        download_initial_image_script = '/OpenSecurity/bin/download_initial_image.sh \'' + machine_folder + '\''
    1.52 +        Cygwin.bashExecute(download_initial_image_script, wait_return = False, stdout = trace_file, stderr = trace_file) 
    1.53 +
    1.54 +        return trace_file_name
    1.55 +
    1.56 +
    1.57 +class os_init:
    1.58 +    """OpenSecurity '/init' handler
    1.59 +    
    1.60 +    - GET: Do initial import of OsecVM.ova
    1.61 +    """
    1.62 +    
    1.63 +    def GET(self):
    1.64 +        log_call(web.ctx.environ)
    1.65 +        global gvm_mgr
    1.66 +
    1.67 +        trace_file_name = os.path.join(tempfile.gettempdir(), 'OpenSecurity_initial_import.log')
    1.68 +        trace_file = open(trace_file_name, 'w+')
    1.69 +
    1.70 +        vm_image = Cygwin.cygPath(gvm_mgr.getMachineFolder()) + '/OsecVM.ova'
    1.71 +        initial_import_script = '/OpenSecurity/bin/initial_vm.sh \'' + vm_image + '\''
    1.72 +        Cygwin.bashExecute(initial_import_script, wait_return = False, stdout = trace_file, stderr = trace_file) 
    1.73 +
    1.74 +        return trace_file_name
    1.75 +
    1.76 +
    1.77  class os_root:
    1.78      """OpenSecurity '/' handler
    1.79      
    1.80 @@ -107,7 +156,8 @@
    1.81          global gvm_mgr
    1.82          res = "'os_server': { "
    1.83          res += "'version': '" + __version__ + "', "
    1.84 -        res += "'machine_folder': '" + gvm_mgr.machineFolder + "' "
    1.85 +        res += "'virtual box systemproperties': '" + str(gvm_mgr.systemProperties) + "', "
    1.86 +        res += "'current temporary folder': '" + tempfile.gettempdir() + "' "
    1.87          res += "}"
    1.88          return res
    1.89  
    1.90 @@ -141,7 +191,8 @@
    1.91          global gvm_mgr
    1.92          command = '/' + command
    1.93          result = Cygwin.sshExecuteX11(command, gvm_mgr.getHostOnlyIP(name), 'osecuser', Cygwin.cygPath(gvm_mgr.getMachineFolder()) + '/' + name + '/dvm_key'  )
    1.94 -        return result
    1.95 +        self.poweroffVM(name)
    1.96 +        return gvm_mgr.removeVM(name)
    1.97      
    1.98  
    1.99  class os_sdvm_ip:
   1.100 @@ -229,6 +280,7 @@
   1.101      def GET(self):
   1.102          log_call(web.ctx.environ)
   1.103          global gvm_mgr
   1.104 +        gvm_mgr.stop()
   1.105          gvm_mgr.cleanup()
   1.106          sys.exit(0)
   1.107          return None