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