mb@63
|
1 |
#!/bin/env python
|
mb@63
|
2 |
# -*- coding: utf-8 -*-
|
mb@63
|
3 |
|
mb@63
|
4 |
# ------------------------------------------------------------
|
mb@63
|
5 |
# opensecurityd
|
mb@63
|
6 |
#
|
mb@63
|
7 |
# the opensecurityd as RESTful server
|
mb@63
|
8 |
#
|
mb@63
|
9 |
# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
|
mb@63
|
10 |
#
|
mb@63
|
11 |
# Copyright (C) 2013 AIT Austrian Institute of Technology
|
mb@63
|
12 |
# AIT Austrian Institute of Technology GmbH
|
mb@63
|
13 |
# Donau-City-Strasse 1 | 1220 Vienna | Austria
|
mb@63
|
14 |
# http://www.ait.ac.at
|
mb@63
|
15 |
#
|
mb@63
|
16 |
# This program is free software; you can redistribute it and/or
|
mb@63
|
17 |
# modify it under the terms of the GNU General Public License
|
mb@63
|
18 |
# as published by the Free Software Foundation version 2.
|
mb@63
|
19 |
#
|
mb@63
|
20 |
# This program is distributed in the hope that it will be useful,
|
mb@63
|
21 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
mb@63
|
22 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
mb@63
|
23 |
# GNU General Public License for more details.
|
mb@63
|
24 |
#
|
mb@63
|
25 |
# You should have received a copy of the GNU General Public License
|
mb@63
|
26 |
# along with this program; if not, write to the Free Software
|
mb@63
|
27 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
mb@63
|
28 |
# Boston, MA 02110-1301, USA.
|
mb@63
|
29 |
# ------------------------------------------------------------
|
mb@63
|
30 |
|
mb@63
|
31 |
|
mb@63
|
32 |
# ------------------------------------------------------------
|
mb@63
|
33 |
# imports
|
mb@63
|
34 |
|
oliver@130
|
35 |
import json
|
mb@63
|
36 |
import os
|
mb@63
|
37 |
import os.path
|
mb@63
|
38 |
import subprocess
|
mb@63
|
39 |
import sys
|
oliver@91
|
40 |
import tempfile
|
mb@63
|
41 |
import web
|
mb@63
|
42 |
|
oliver@87
|
43 |
import vmmanager
|
mb@63
|
44 |
|
mb@63
|
45 |
# local
|
oliver@144
|
46 |
import __init__ as opensecurity
|
oliver@91
|
47 |
from cygwin import Cygwin
|
oliver@147
|
48 |
from environment import Environment
|
oliver@74
|
49 |
from opensecurity_util import logger
|
mb@63
|
50 |
|
mb@63
|
51 |
|
mb@63
|
52 |
# ------------------------------------------------------------
|
mb@63
|
53 |
# const
|
mb@63
|
54 |
|
mb@63
|
55 |
"""All the URLs we know mapping to class handler"""
|
mb@63
|
56 |
opensecurity_urls = (
|
mb@63
|
57 |
'/browsing', 'os_browsing', # http://localhost:8080/browsing GET
|
oliver@91
|
58 |
'/fetch_initial_image', 'os_fetch_image', # http://localhost:8080/fetch_initial_image GET
|
oliver@91
|
59 |
'/init', 'os_init', # http://localhost:8080/init GET
|
oliver@107
|
60 |
'/initial_image', 'os_initial_image', # http://localhost:8080/initial_image GET
|
mb@63
|
61 |
'/sdvms', 'os_sdvms', # http://localhost:8080/sdvms GET, PUT
|
mb@63
|
62 |
'/sdvms/(.*)/application/(.*)', 'os_sdvm_application', # http://localhost:8080/sdvms/[VMNAME]/application/[COMMAND] GET
|
mb@63
|
63 |
'/sdvms/(.*)/ip', 'os_sdvm_ip', # http://localhost:8080/sdvms/[VMNAME]/ip GET
|
mb@63
|
64 |
'/sdvms/(.*)/start', 'os_sdvm_start', # http://localhost:8080/sdvms/[VMNAME]/start GET
|
mb@63
|
65 |
'/sdvms/(.*)/stop', 'os_sdvm_stop', # http://localhost:8080/sdvms/[VMNAME]/stop GET
|
mb@63
|
66 |
'/sdvms/(.*)', 'os_sdvm', # http://localhost:8080/sdvms/[VMNAME] GET, DELETE
|
oliver@93
|
67 |
'/setup', 'os_setup', # http://localhost:8080/setup GET
|
mb@63
|
68 |
'/vms', 'os_vms', # http://localhost:8080/vms GET
|
mb@63
|
69 |
'/vms/(.*)', 'os_vm', # http://localhost:8080/vms/[VMNAME] GET
|
oliver@87
|
70 |
'/update_template', 'os_update_template', # http://localhost:8080/update_template GET
|
oliver@87
|
71 |
'/terminate', 'os_terminate', # http://localhost:8080/terminate GET
|
oliver@87
|
72 |
'/', 'os_root' # http://localhost:8080/ GET
|
mb@63
|
73 |
)
|
mb@63
|
74 |
|
oliver@87
|
75 |
|
mb@66
|
76 |
# ------------------------------------------------------------
|
mb@63
|
77 |
# vars
|
mb@63
|
78 |
|
mb@63
|
79 |
# Global VMManager instance
|
oliver@86
|
80 |
gvm_mgr = None
|
oliver@86
|
81 |
|
oliver@138
|
82 |
# server instance
|
oliver@138
|
83 |
server = None
|
oliver@138
|
84 |
|
oliver@138
|
85 |
|
mb@63
|
86 |
# ------------------------------------------------------------
|
mb@63
|
87 |
# code
|
mb@63
|
88 |
|
mb@63
|
89 |
|
mb@63
|
90 |
class os_browsing:
|
mb@63
|
91 |
"""OpenSecurity '/browsing' handler
|
mb@63
|
92 |
|
mb@63
|
93 |
- GET: Start and prepare a new SecurityVM for Internet Browsing. Return the name of the VM.
|
mb@63
|
94 |
"""
|
mb@63
|
95 |
|
mb@63
|
96 |
def GET(self):
|
oliver@74
|
97 |
log_call(web.ctx.environ)
|
oliver@87
|
98 |
global gvm_mgr
|
mb@63
|
99 |
try:
|
mb@90
|
100 |
result = gvm_mgr.handleBrowsingRequest()
|
mb@90
|
101 |
return result
|
mb@63
|
102 |
except:
|
mb@63
|
103 |
raise web.internalerror()
|
mb@63
|
104 |
|
oliver@87
|
105 |
|
oliver@91
|
106 |
class os_fetch_image:
|
oliver@91
|
107 |
"""OpenSecurity '/fetch_initial_image' handler
|
oliver@91
|
108 |
|
oliver@91
|
109 |
- GET: fetch the initial image from the X-Net Servers
|
oliver@91
|
110 |
The initial image is stored in the
|
oliver@91
|
111 |
Virtual Box default machine path.
|
oliver@91
|
112 |
The result to this call is a temprary file
|
oliver@91
|
113 |
which shows the progress (or error state)
|
oliver@91
|
114 |
of this call.
|
oliver@91
|
115 |
"""
|
oliver@91
|
116 |
|
oliver@91
|
117 |
def GET(self):
|
oliver@91
|
118 |
|
oliver@91
|
119 |
log_call(web.ctx.environ)
|
oliver@91
|
120 |
global gvm_mgr
|
oliver@91
|
121 |
|
oliver@147
|
122 |
trace_file_name = os.path.join(Environment('OpenSecurity').log_path, 'OpenSecurity_fetch_image.log')
|
oliver@91
|
123 |
trace_file = open(trace_file_name, 'w+')
|
oliver@91
|
124 |
|
oliver@91
|
125 |
machine_folder = Cygwin.cygPath(gvm_mgr.getMachineFolder())
|
oliver@164
|
126 |
download_initial_image_script = Cygwin.cygPath(os.path.abspath(os.path.join(os.path.split(__file__)[0], 'download_initial_image.sh')))
|
oliver@164
|
127 |
Cygwin.bashExecute(download_initial_image_script + ' \'' + machine_folder + '\'', wait_return = False, stdout = trace_file, stderr = trace_file)
|
oliver@91
|
128 |
|
oliver@116
|
129 |
res = '{ "fetch_log": "' + trace_file_name.replace('\\', '\\\\') + '" }'
|
oliver@115
|
130 |
return res
|
oliver@91
|
131 |
|
oliver@147
|
132 |
|
oliver@91
|
133 |
class os_init:
|
oliver@91
|
134 |
"""OpenSecurity '/init' handler
|
oliver@91
|
135 |
|
oliver@91
|
136 |
- GET: Do initial import of OsecVM.ova
|
oliver@91
|
137 |
"""
|
oliver@91
|
138 |
|
oliver@91
|
139 |
def GET(self):
|
oliver@91
|
140 |
log_call(web.ctx.environ)
|
oliver@91
|
141 |
global gvm_mgr
|
oliver@91
|
142 |
|
oliver@147
|
143 |
trace_file_name = os.path.join(Environment('OpenSecurity').log_path, 'OpenSecurity_initial_import.log')
|
oliver@91
|
144 |
trace_file = open(trace_file_name, 'w+')
|
oliver@91
|
145 |
|
oliver@91
|
146 |
vm_image = Cygwin.cygPath(gvm_mgr.getMachineFolder()) + '/OsecVM.ova'
|
oliver@164
|
147 |
initial_import_script = Cygwin.cygPath(os.path.abspath(os.path.join(os.path.split(__file__)[0], 'initial_vm.sh')))
|
oliver@164
|
148 |
Cygwin.bashExecute(initial_import_script + ' \'' + vm_image + '\'', wait_return = False, stdout = trace_file, stderr = trace_file)
|
oliver@91
|
149 |
|
oliver@116
|
150 |
res = '{ "init_log": "' + trace_file_name.replace('\\', '\\\\') + '" }'
|
oliver@115
|
151 |
return res
|
oliver@91
|
152 |
|
oliver@91
|
153 |
|
oliver@107
|
154 |
class os_initial_image:
|
oliver@107
|
155 |
"""OpenSecurity '/initial_image' handler
|
oliver@107
|
156 |
|
oliver@107
|
157 |
- GET: Return what we have as initial image.
|
oliver@107
|
158 |
"""
|
oliver@107
|
159 |
|
oliver@107
|
160 |
def GET(self):
|
oliver@107
|
161 |
log_call(web.ctx.environ)
|
oliver@107
|
162 |
global gvm_mgr
|
oliver@107
|
163 |
t = os.path.join(gvm_mgr.systemProperties['Default machine folder'], 'OsecVM.ova')
|
oliver@107
|
164 |
res = ''
|
oliver@107
|
165 |
if os.path.isfile(t):
|
oliver@107
|
166 |
res = '{"initial_template": { '
|
oliver@107
|
167 |
res += '"name": "OsecVM.ova", '
|
oliver@107
|
168 |
res += '"path": "' + t.replace('\\', '\\\\') + '", '
|
oliver@107
|
169 |
res += '"size": ' + str(os.path.getsize(t)) + ', '
|
oliver@107
|
170 |
res += '"date": ' + str(os.path.getmtime(t)) + ''
|
oliver@112
|
171 |
res += '}}'
|
oliver@107
|
172 |
return res
|
oliver@107
|
173 |
|
oliver@107
|
174 |
|
oliver@87
|
175 |
class os_root:
|
oliver@87
|
176 |
"""OpenSecurity '/' handler
|
oliver@87
|
177 |
|
oliver@87
|
178 |
- GET: give information about current installation.
|
oliver@87
|
179 |
"""
|
oliver@87
|
180 |
|
oliver@87
|
181 |
def GET(self):
|
oliver@87
|
182 |
log_call(web.ctx.environ)
|
oliver@87
|
183 |
global gvm_mgr
|
oliver@130
|
184 |
|
oliver@130
|
185 |
# create a json string and pretty print it
|
oliver@107
|
186 |
res = '{"os_server": { '
|
oliver@144
|
187 |
res += '"version": "' + opensecurity.__version__ + '" '
|
oliver@130
|
188 |
res += ', "virtual box systemproperties": ' + str(gvm_mgr.systemProperties).replace("'", '"')
|
oliver@130
|
189 |
res += ', "current temporary folder": "' + tempfile.gettempdir().replace('\\', '\\\\') + '"'
|
oliver@147
|
190 |
res += ', "current log folder": "' + Environment('OpenSecurity').log_path.replace('\\', '\\\\') + '"'
|
oliver@130
|
191 |
|
oliver@130
|
192 |
try:
|
oliver@130
|
193 |
res += ', "whoami": "' + Cygwin.bashExecute('whoami')[1].strip() + '"'
|
oliver@130
|
194 |
except:
|
oliver@130
|
195 |
res += ', "whoami": "FAILED"'
|
oliver@130
|
196 |
|
oliver@130
|
197 |
try:
|
oliver@130
|
198 |
res += ', "mount": ' + str(Cygwin.bashExecute('mount')[1].split('\n')[:-1]).replace("'", '"')
|
oliver@130
|
199 |
except:
|
oliver@130
|
200 |
res += ', "mount": "FAILED"'
|
oliver@130
|
201 |
|
oliver@130
|
202 |
try:
|
oliver@130
|
203 |
res += ', "cygpath --windows ~": "' + Cygwin.bashExecute('cygpath --windows ~')[1].strip().replace('\\', '\\\\') + '"'
|
oliver@130
|
204 |
except:
|
oliver@130
|
205 |
res += ', "cygpath --windows ~": "FAILED"'
|
oliver@130
|
206 |
|
oliver@131
|
207 |
|
oliver@131
|
208 |
res += ', "status message": "' + gvm_mgr.status_message.replace('"', "'") + '"'
|
oliver@131
|
209 |
|
oliver@107
|
210 |
res += '}}'
|
oliver@130
|
211 |
|
oliver@130
|
212 |
# loading it into json and print it again ensures
|
oliver@130
|
213 |
# we really do have a valid RFC conform json string
|
oliver@130
|
214 |
# created (as long as the python json module is RFC conform)
|
oliver@130
|
215 |
return json.dumps(json.loads(res), indent = 4)
|
oliver@87
|
216 |
|
oliver@87
|
217 |
|
mb@63
|
218 |
class os_sdvm:
|
mb@63
|
219 |
"""OpenSecurity '/sdvms/[VM]' handler
|
mb@63
|
220 |
|
mb@63
|
221 |
- GET: Information about a specific SecurityVM
|
mb@63
|
222 |
- DELETE: Remove a specific
|
mb@63
|
223 |
"""
|
mb@63
|
224 |
|
mb@63
|
225 |
def GET(self, name):
|
oliver@74
|
226 |
log_call(web.ctx.environ)
|
oliver@87
|
227 |
global gvm_mgr
|
oliver@87
|
228 |
return gvm_mgr.getVMInfo(name)
|
mb@63
|
229 |
|
mb@63
|
230 |
def DELETE(self, name):
|
oliver@74
|
231 |
log_call(web.ctx.environ)
|
oliver@87
|
232 |
global gvm_mgr
|
oliver@87
|
233 |
return gvm_mgr.removeVM(name)
|
mb@63
|
234 |
|
mb@63
|
235 |
|
mb@63
|
236 |
class os_sdvm_application:
|
mb@63
|
237 |
"""OpenSecurity '/sdvms/[VM]/application/[CMD]' handler
|
mb@63
|
238 |
|
mb@63
|
239 |
- GET: start application with given command in the VM.
|
mb@63
|
240 |
"""
|
mb@63
|
241 |
|
mb@63
|
242 |
def GET(self, name, command):
|
oliver@74
|
243 |
log_call(web.ctx.environ)
|
oliver@87
|
244 |
global gvm_mgr
|
mb@63
|
245 |
command = '/' + command
|
oliver@87
|
246 |
result = Cygwin.sshExecuteX11(command, gvm_mgr.getHostOnlyIP(name), 'osecuser', Cygwin.cygPath(gvm_mgr.getMachineFolder()) + '/' + name + '/dvm_key' )
|
oliver@91
|
247 |
self.poweroffVM(name)
|
oliver@91
|
248 |
return gvm_mgr.removeVM(name)
|
mb@63
|
249 |
|
mb@63
|
250 |
|
mb@63
|
251 |
class os_sdvm_ip:
|
mb@63
|
252 |
"""OpenSecurity '/sdvms/[VM]/ip' handler
|
mb@63
|
253 |
|
mb@63
|
254 |
- GET: give IP of SecurityVM.
|
mb@63
|
255 |
"""
|
mb@63
|
256 |
|
mb@63
|
257 |
def GET(self, name):
|
oliver@74
|
258 |
log_call(web.ctx.environ)
|
oliver@87
|
259 |
global gvm_mgr
|
oliver@87
|
260 |
return gvm_mgr.getHostOnlyIP(name)
|
mb@63
|
261 |
|
mb@63
|
262 |
|
mb@63
|
263 |
class os_sdvm_start:
|
mb@63
|
264 |
"""OpenSecurity '/sdvms/[VM]/start' handler
|
mb@63
|
265 |
|
mb@63
|
266 |
- GET: Start specific SecuirtyVM.
|
mb@63
|
267 |
"""
|
mb@63
|
268 |
|
mb@63
|
269 |
def GET(self, name):
|
oliver@74
|
270 |
log_call(web.ctx.environ)
|
oliver@87
|
271 |
global gvm_mgr
|
oliver@87
|
272 |
return gvm_mgr.startVM(name)
|
mb@63
|
273 |
|
mb@63
|
274 |
|
mb@63
|
275 |
class os_sdvm_stop:
|
mb@63
|
276 |
"""OpenSecurity '/sdvms/[VM]/stop' handler
|
mb@63
|
277 |
|
mb@63
|
278 |
- GET: stop specific Secuirty VM.
|
mb@63
|
279 |
"""
|
mb@63
|
280 |
|
mb@63
|
281 |
def GET(self, name):
|
oliver@74
|
282 |
log_call(web.ctx.environ)
|
oliver@87
|
283 |
global gvm_mgr
|
oliver@87
|
284 |
return gvm_mgr.stopVM(name)
|
mb@63
|
285 |
|
mb@63
|
286 |
|
mb@63
|
287 |
class os_sdvms:
|
mb@63
|
288 |
"""OpenSecurity '/sdvms' handler
|
mb@63
|
289 |
|
mb@63
|
290 |
- GET: list all available secuirty VMs.
|
mb@63
|
291 |
- POST: create new security vm.
|
mb@63
|
292 |
"""
|
mb@63
|
293 |
|
mb@63
|
294 |
def GET(self):
|
mb@63
|
295 |
"""get the list of SDVMs"""
|
oliver@74
|
296 |
log_call(web.ctx.environ)
|
oliver@87
|
297 |
global gvm_mgr
|
oliver@87
|
298 |
return gvm_mgr.listSDVM()
|
mb@63
|
299 |
|
mb@63
|
300 |
def POST(self):
|
mb@63
|
301 |
"""create a new SDVM"""
|
oliver@74
|
302 |
log_call(web.ctx.environ)
|
oliver@87
|
303 |
global gvm_mgr
|
oliver@74
|
304 |
|
mb@63
|
305 |
# get a new vm-name
|
oliver@87
|
306 |
name = gvm_mgr.generateSDVMName()
|
mb@63
|
307 |
try:
|
oliver@87
|
308 |
gvm_mgr.createVM(name)
|
mb@63
|
309 |
except:
|
mb@63
|
310 |
raise web.internalerror()
|
mb@63
|
311 |
|
mb@63
|
312 |
return name
|
mb@63
|
313 |
|
oliver@87
|
314 |
|
oliver@93
|
315 |
class os_setup:
|
oliver@93
|
316 |
"""OpenSecurity '/setup' handler
|
oliver@93
|
317 |
|
oliver@93
|
318 |
- GET: Give user some info how to setup the OpenSecurity envvironment
|
oliver@93
|
319 |
"""
|
oliver@93
|
320 |
|
oliver@93
|
321 |
def GET(self):
|
oliver@93
|
322 |
|
oliver@93
|
323 |
log_call(web.ctx.environ)
|
oliver@93
|
324 |
|
oliver@93
|
325 |
page = """
|
oliver@93
|
326 |
<html>
|
oliver@93
|
327 |
<body>
|
oliver@93
|
328 |
<h1>Setup OpenSecurity</h1>
|
oliver@93
|
329 |
In order to setup OpenSecurity an inital VM image has to be downloaded and imported:<br/>
|
oliver@93
|
330 |
<ul>
|
oliver@93
|
331 |
<li>Download initial VM image: <a href="/fetch_initial_image">fetch_initial_image</a>
|
oliver@93
|
332 |
<li>Import initial VM: <a href="/init">init</a>
|
oliver@93
|
333 |
</ul>
|
oliver@93
|
334 |
</body>
|
oliver@93
|
335 |
</html>
|
oliver@93
|
336 |
"""
|
oliver@93
|
337 |
return page
|
oliver@93
|
338 |
|
oliver@93
|
339 |
|
oliver@87
|
340 |
class os_terminate:
|
oliver@87
|
341 |
"""OpenSecurity '/terminate' handler
|
oliver@87
|
342 |
|
oliver@87
|
343 |
- GET: terminate the opensecurityd.
|
oliver@87
|
344 |
|
oliver@87
|
345 |
TODO: need to find a better way doing this, and not via the
|
oliver@87
|
346 |
REST api. Maybe hack web.py server code?
|
oliver@87
|
347 |
"""
|
oliver@87
|
348 |
|
oliver@87
|
349 |
def GET(self):
|
oliver@87
|
350 |
log_call(web.ctx.environ)
|
oliver@139
|
351 |
global gvm_mgr
|
oliver@139
|
352 |
gvm_mgr.cleanup()
|
oliver@138
|
353 |
global server
|
oliver@138
|
354 |
server.stop()
|
oliver@87
|
355 |
return None
|
oliver@87
|
356 |
|
oliver@87
|
357 |
|
oliver@87
|
358 |
class os_update_template:
|
oliver@87
|
359 |
"""OpenSecurity '/update_template' handler
|
oliver@87
|
360 |
|
oliver@87
|
361 |
- GET: update template vm
|
oliver@87
|
362 |
"""
|
oliver@87
|
363 |
|
oliver@87
|
364 |
def GET(self):
|
oliver@87
|
365 |
#return gvm_mgr.guestExecute('SecurityDVM', 'sudo apt-get -y update')
|
oliver@87
|
366 |
global gvm_mgr
|
oliver@87
|
367 |
log_call(web.ctx.environ)
|
oliver@87
|
368 |
return gvm_mgr.updateTemplate()
|
oliver@87
|
369 |
|
oliver@87
|
370 |
|
mb@63
|
371 |
class os_vm:
|
mb@63
|
372 |
"""OpenSecurity '/vms/[VM]' handler
|
mb@63
|
373 |
|
mb@63
|
374 |
- GET: list information of arbitrary VM.
|
mb@63
|
375 |
"""
|
mb@63
|
376 |
|
mb@63
|
377 |
def GET(self, name):
|
oliver@74
|
378 |
log_call(web.ctx.environ)
|
oliver@87
|
379 |
global gvm_mgr
|
oliver@87
|
380 |
return gvm_mgr.getVMInfo(name)
|
mb@63
|
381 |
|
mb@63
|
382 |
|
mb@63
|
383 |
class os_vms:
|
mb@63
|
384 |
"""OpenSecurity '/vms' handler
|
mb@63
|
385 |
|
mb@63
|
386 |
- GET: list all (also non Security) VMs.
|
mb@63
|
387 |
"""
|
mb@63
|
388 |
|
mb@63
|
389 |
def GET(self):
|
oliver@74
|
390 |
log_call(web.ctx.environ)
|
oliver@87
|
391 |
global gvm_mgr
|
oliver@112
|
392 |
return str(gvm_mgr.listVM()).replace("'",'"')
|
mb@63
|
393 |
|
mb@63
|
394 |
|
oliver@74
|
395 |
def log_call(web_environ):
|
oliver@74
|
396 |
"""log the incoming call to the REST api"""
|
oliver@74
|
397 |
try:
|
oliver@74
|
398 |
call = 'REST ' + web_environ['REQUEST_METHOD'] + ' ' + web_environ['REQUEST_URI'] + ' from ' + web_environ['REMOTE_ADDR'] + ':' + web_environ['REMOTE_PORT']
|
oliver@74
|
399 |
logger.debug(call)
|
oliver@74
|
400 |
except:
|
oliver@74
|
401 |
pass
|
oliver@74
|
402 |
|
oliver@86
|
403 |
|
oliver@86
|
404 |
def main():
|
oliver@86
|
405 |
"""main startup for the opensecuirityd"""
|
oliver@87
|
406 |
|
oliver@139
|
407 |
global gvm_mgr
|
oliver@139
|
408 |
global server
|
oliver@139
|
409 |
|
oliver@87
|
410 |
logger.debug('Starting OpenSecurity REST server')
|
oliver@87
|
411 |
|
oliver@87
|
412 |
# ensure a VMManger is yet loaded
|
oliver@87
|
413 |
gvm_mgr = vmmanager.VMManager.getInstance()
|
oliver@87
|
414 |
|
oliver@98
|
415 |
# tweak sys.argv to control wep.py server start behavior
|
oliver@98
|
416 |
sys.argv = [__file__, "8080"]
|
oliver@87
|
417 |
server = web.application(opensecurity_urls, globals(), autoreload = False)
|
mb@63
|
418 |
server.run()
|
oliver@87
|
419 |
|
oliver@87
|
420 |
logger.debug('Stopped OpenSecurity REST server')
|
oliver@86
|
421 |
|
oliver@86
|
422 |
|
oliver@88
|
423 |
def stop():
|
oliver@88
|
424 |
"""stop the opensecuirityd"""
|
oliver@88
|
425 |
|
oliver@88
|
426 |
# calling sys.exit() raises a SystemExit exception
|
oliver@88
|
427 |
# of the WSGI Server to let it wind down
|
oliver@89
|
428 |
# gracefully
|
oliver@88
|
429 |
sys.exit(0)
|
oliver@88
|
430 |
|
oliver@88
|
431 |
|
oliver@88
|
432 |
|
oliver@86
|
433 |
# start
|
oliver@86
|
434 |
if __name__ == "__main__":
|
oliver@86
|
435 |
main()
|
oliver@86
|
436 |
|