1.1 --- a/OpenSecurity/bin/opensecurityd.py Tue Dec 10 12:16:11 2013 +0100
1.2 +++ b/OpenSecurity/bin/opensecurityd.py Tue Dec 10 14:04:11 2013 +0100
1.3 @@ -47,21 +47,22 @@
1.4 # ------------------------------------------------------------
1.5 # const
1.6
1.7 -__version__ = "0.1"
1.8 +__version__ = "0.2"
1.9
1.10
1.11 """All the URLs we know mapping to class handler"""
1.12 opensecurity_urls = (
1.13 - '/device_change', 'os_device_change', # http://localhost:8080/device_change GET
1.14 - '/sdvm_started', 'os_sdvm_started', # http://localhost:8080/sdvm_started GET
1.15 - '/sdvms', 'os_sdvms', # http://localhost:8080/sdvms GET, PUT
1.16 - '/sdvms/(.*)/ip', 'os_sdvm_ip', # http://localhost:8080/sdvms/[VMNAME]/ip GET
1.17 - '/sdvms/(.*)/start', 'os_sdvm_start', # http://localhost:8080/sdvms/[VMNAME]/start GET
1.18 - '/sdvms/(.*)/stop', 'os_sdvm_stop', # http://localhost:8080/sdvms/[VMNAME]/stop GET
1.19 - '/sdvms/(.*)', 'os_sdvm', # http://localhost:8080/sdvms/[VMNAME] GET, DELETE
1.20 - '/vms', 'os_vms', # http://localhost:8080/vms GET
1.21 - '/vms/(.*)', 'os_vm', # http://localhost:8080/vms/[VMNAME] GET
1.22 - '/', 'os_root' # http://localhost:8080/ GET
1.23 + '/device_change', 'os_device_change', # http://localhost:8080/device_change GET
1.24 + '/browsing', 'os_browsing', # http://localhost:8080/browsing GET
1.25 + '/sdvms', 'os_sdvms', # http://localhost:8080/sdvms GET, PUT
1.26 + '/sdvms/(.*)/application/(.*)', 'os_sdvm_application', # http://localhost:8080/sdvms/[VMNAME]/application/[COMMAND] GET
1.27 + '/sdvms/(.*)/ip', 'os_sdvm_ip', # http://localhost:8080/sdvms/[VMNAME]/ip GET
1.28 + '/sdvms/(.*)/start', 'os_sdvm_start', # http://localhost:8080/sdvms/[VMNAME]/start GET
1.29 + '/sdvms/(.*)/stop', 'os_sdvm_stop', # http://localhost:8080/sdvms/[VMNAME]/stop GET
1.30 + '/sdvms/(.*)', 'os_sdvm', # http://localhost:8080/sdvms/[VMNAME] GET, DELETE
1.31 + '/vms', 'os_vms', # http://localhost:8080/vms GET
1.32 + '/vms/(.*)', 'os_vm', # http://localhost:8080/vms/[VMNAME] GET
1.33 + '/', 'os_root' # http://localhost:8080/ GET
1.34 )
1.35
1.36
1.37 @@ -83,15 +84,28 @@
1.38 gvm_mgr.handleDeviceChange()
1.39 return "os_device_change"
1.40
1.41 -class os_sdvm_started:
1.42 - """OpenSecurity '/sdvm_started' handler"""
1.43 +
1.44 +class os_browsing:
1.45 + """OpenSecurity '/browsing' handler
1.46 +
1.47 + - GET: Start and prepare a new SecurityVM for Internet Browsing. Return the name of the VM.
1.48 + """
1.49
1.50 def GET(self):
1.51 - # self.request get address
1.52 - return "os_sdvm_started"
1.53 + try:
1.54 + browsingVM = gvm_mgr.handleBrowsingRequest()
1.55 + gvm_mgr.startVM(browsingVM)
1.56 + return browsingVM
1.57 + except:
1.58 + raise web.internalerror()
1.59
1.60 +
1.61 class os_sdvm:
1.62 - """OpenSecurity '/sdvms/[VM]' handler"""
1.63 + """OpenSecurity '/sdvms/[VM]' handler
1.64 +
1.65 + - GET: Information about a specific SecurityVM
1.66 + - DELETE: Remove a specific
1.67 + """
1.68
1.69 def GET(self, name):
1.70 return gvm_mgr.getVMInfo(name)
1.71 @@ -100,35 +114,60 @@
1.72 return gvm_mgr.removeVM(name)
1.73
1.74
1.75 +class os_sdvm_application:
1.76 + """OpenSecurity '/sdvms/[VM]/application/[CMD]' handler
1.77 +
1.78 + - GET: start application with given command in the VM.
1.79 + """
1.80 +
1.81 + def GET(self, name, command):
1.82 + command = '/' + command
1.83 + print('---> request to launch application in VM -- ' + name + ':' + command + ' <---')
1.84 + return gvm_mgr.sshGuestX11Execute(name, command)
1.85 +
1.86 +
1.87 class os_sdvm_ip:
1.88 - """OpenSecurity '/sdvms/[VM]/ip' handler"""
1.89 + """OpenSecurity '/sdvms/[VM]/ip' handler
1.90 +
1.91 + - GET: give IP of SecurityVM.
1.92 + """
1.93
1.94 def GET(self, name):
1.95 return gvm_mgr.getHostOnlyIP(name)
1.96
1.97
1.98 class os_sdvm_start:
1.99 - """OpenSecurity '/sdvms/[VM]/start' handler"""
1.100 + """OpenSecurity '/sdvms/[VM]/start' handler
1.101 +
1.102 + - GET: Start specific SecuirtyVM.
1.103 + """
1.104
1.105 def GET(self, name):
1.106 return gvm_mgr.startVM(name)
1.107
1.108
1.109 class os_sdvm_stop:
1.110 - """OpenSecurity '/sdvms/[VM]/stop' handler"""
1.111 + """OpenSecurity '/sdvms/[VM]/stop' handler
1.112 +
1.113 + - GET: stop specific Secuirty VM.
1.114 + """
1.115
1.116 def GET(self, name):
1.117 return gvm_mgr.stopVM(name)
1.118
1.119
1.120 class os_sdvms:
1.121 - """OpenSecurity '/sdvms' handler"""
1.122 + """OpenSecurity '/sdvms' handler
1.123 +
1.124 + - GET: list all available secuirty VMs.
1.125 + - POST: create new security vm.
1.126 + """
1.127
1.128 def GET(self):
1.129 """get the list of SDVMs"""
1.130 return gvm_mgr.listSDVM()
1.131
1.132 - def PUT(self):
1.133 + def POST(self):
1.134 """create a new SDVM"""
1.135
1.136 # get a new vm-name
1.137 @@ -141,21 +180,30 @@
1.138 return name
1.139
1.140 class os_vm:
1.141 - """OpenSecurity '/vms/[VM]' handler"""
1.142 + """OpenSecurity '/vms/[VM]' handler
1.143 +
1.144 + - GET: list information of arbitrary VM.
1.145 + """
1.146
1.147 def GET(self, name):
1.148 return gvm_mgr.getVMInfo(name)
1.149
1.150
1.151 class os_vms:
1.152 - """OpenSecurity '/vms' handler"""
1.153 + """OpenSecurity '/vms' handler
1.154 +
1.155 + - GET: list all (also non Security) VMs.
1.156 + """
1.157
1.158 def GET(self):
1.159 return gvm_mgr.listVM()
1.160
1.161
1.162 class os_root:
1.163 - """OpenSecurity '/' handler"""
1.164 + """OpenSecurity '/' handler
1.165 +
1.166 + - GET: give information about current installation.
1.167 + """
1.168
1.169 def GET(self):
1.170 res = "'os_server': { "