make real JSON (RFC4627) strings from opensecurityd
authorOliver Maurhart <oliver.maurhart@ait.ac.at>
Tue, 01 Apr 2014 16:11:36 +0200
changeset 10750cacad1967e
parent 106 c5101320b46c
child 108 dec3f05b57c5
make real JSON (RFC4627) strings from opensecurityd
OpenSecurity/bin/opensecurityd.pyw
OpenSecurity/bin/ui/configure_dialog.py
     1.1 --- a/OpenSecurity/bin/opensecurityd.pyw	Tue Apr 01 13:43:59 2014 +0200
     1.2 +++ b/OpenSecurity/bin/opensecurityd.pyw	Tue Apr 01 16:11:36 2014 +0200
     1.3 @@ -58,6 +58,7 @@
     1.4      '/browsing',                        'os_browsing',          # http://localhost:8080/browsing                                GET
     1.5      '/fetch_initial_image',             'os_fetch_image',       # http://localhost:8080/fetch_initial_image                     GET
     1.6      '/init',                            'os_init',              # http://localhost:8080/init                                    GET
     1.7 +    '/initial_image',                   'os_initial_image',     # http://localhost:8080/initial_image                           GET
     1.8      '/sdvms',                           'os_sdvms',             # http://localhost:8080/sdvms                                   GET, PUT
     1.9      '/sdvms/(.*)/application/(.*)',     'os_sdvm_application',  # http://localhost:8080/sdvms/[VMNAME]/application/[COMMAND]    GET
    1.10      '/sdvms/(.*)/ip',                   'os_sdvm_ip',           # http://localhost:8080/sdvms/[VMNAME]/ip                       GET
    1.11 @@ -164,6 +165,27 @@
    1.12          return page.format(trace_file_name)
    1.13  
    1.14  
    1.15 +class os_initial_image:
    1.16 +    """OpenSecurity '/initial_image' handler
    1.17 +    
    1.18 +    - GET: Return what we have as initial image.
    1.19 +    """
    1.20 +    
    1.21 +    def GET(self):
    1.22 +        log_call(web.ctx.environ)
    1.23 +        global gvm_mgr
    1.24 +        t = os.path.join(gvm_mgr.systemProperties['Default machine folder'], 'OsecVM.ova')
    1.25 +        res = ''
    1.26 +        if os.path.isfile(t):
    1.27 +            res = '{"initial_template": { '
    1.28 +            res += '"name": "OsecVM.ova", '
    1.29 +            res += '"path": "' + t.replace('\\', '\\\\') + '", '
    1.30 +            res += '"size": ' + str(os.path.getsize(t)) + ', ' 
    1.31 +            res += '"date": ' + str(os.path.getmtime(t)) + ''
    1.32 +            res += '}'
    1.33 +        return res
    1.34 +
    1.35 +
    1.36  class os_root:
    1.37      """OpenSecurity '/' handler
    1.38      
    1.39 @@ -173,11 +195,11 @@
    1.40      def GET(self):
    1.41          log_call(web.ctx.environ)
    1.42          global gvm_mgr
    1.43 -        res = "'os_server': { "
    1.44 -        res += "'version': '" + __version__ + "', "
    1.45 -        res += "'virtual box systemproperties': '" + str(gvm_mgr.systemProperties) + "', "
    1.46 -        res += "'current temporary folder': '" + tempfile.gettempdir() + "' "
    1.47 -        res += "}"
    1.48 +        res = '{"os_server": { '
    1.49 +        res += '"version": "' + __version__ + '", '
    1.50 +        res += '"virtual box systemproperties": ' + str(gvm_mgr.systemProperties).replace("'", '"') + ', '
    1.51 +        res += '"current temporary folder": "' + tempfile.gettempdir().replace('\\', '\\\\') + '" '
    1.52 +        res += '}}'
    1.53          return res
    1.54  
    1.55  
     2.1 --- a/OpenSecurity/bin/ui/configure_dialog.py	Tue Apr 01 13:43:59 2014 +0200
     2.2 +++ b/OpenSecurity/bin/ui/configure_dialog.py	Tue Apr 01 16:11:36 2014 +0200
     2.3 @@ -32,7 +32,9 @@
     2.4  # ------------------------------------------------------------
     2.5  # imports
     2.6  
     2.7 +import json
     2.8  import sys
     2.9 +import urllib2
    2.10  
    2.11  from PyQt4 import QtCore
    2.12  from PyQt4 import QtGui
    2.13 @@ -61,7 +63,6 @@
    2.14          self.ui.edtVersion.setText('<not evaluated yet>')
    2.15          self.ui.edtStatus.setEnabled(False);
    2.16          self.ui.edtVersion.setEnabled(False);
    2.17 -        self.ui.edtProgress.setEnabled(False);
    2.18  
    2.19          # local members
    2.20          self._about_dialog = AboutDialog()
    2.21 @@ -73,6 +74,9 @@
    2.22          self.ui.btnImport.clicked.connect(self.clicked_import)
    2.23          self.ui.btnRefresh.clicked.connect(self.clicked_refresh)
    2.24  
    2.25 +        # call first refresh immediately
    2.26 +        QtCore.QTimer.singleShot(0, self.clicked_refresh)
    2.27 +
    2.28  
    2.29      def clicked_about(self):
    2.30  
    2.31 @@ -95,7 +99,20 @@
    2.32      def clicked_refresh(self):
    2.33  
    2.34          """Refresh button has been clicked."""
    2.35 -        print('clicked_refresh()')
    2.36 +        self.ui.edtStatus.setText('<not evaluated yet>')
    2.37 +        self.ui.edtVersion.setText('<not evaluated yet>')
    2.38 +        self.ui.edtStatus.setEnabled(False);
    2.39 +        self.ui.edtVersion.setEnabled(False);
    2.40 +
    2.41 +        try:
    2.42 +            j = json.load(urllib2.urlopen('http://127.0.0.1:8080'))
    2.43 +            self.ui.edtStatus.setText('running')
    2.44 +            self.ui.edtStatus.setEnabled(True)
    2.45 +            self.ui.edtVersion.setText(j['os_server']['version'])
    2.46 +            self.ui.edtVersion.setEnabled(True)
    2.47 +            
    2.48 +        except:
    2.49 +            pass
    2.50  
    2.51  
    2.52  if __name__ == "__main__":