OpenSecurity/bin/opensecurityd.pyw
changeset 130 f770f1b2abf7
parent 126 21ce69d58251
child 131 8b4df474e577
     1.1 --- a/OpenSecurity/bin/opensecurityd.pyw	Thu Apr 03 10:52:56 2014 +0200
     1.2 +++ b/OpenSecurity/bin/opensecurityd.pyw	Thu Apr 24 12:19:30 2014 +0200
     1.3 @@ -32,6 +32,7 @@
     1.4  # ------------------------------------------------------------
     1.5  # imports
     1.6  
     1.7 +import json
     1.8  import os
     1.9  import os.path
    1.10  import subprocess
    1.11 @@ -50,7 +51,7 @@
    1.12  # ------------------------------------------------------------
    1.13  # const
    1.14  
    1.15 -__version__ = "0.2.4"
    1.16 +__version__ = "0.2.5"
    1.17  
    1.18  
    1.19  """All the URLs we know mapping to class handler"""
    1.20 @@ -178,12 +179,34 @@
    1.21      def GET(self):
    1.22          log_call(web.ctx.environ)
    1.23          global gvm_mgr
    1.24 +
    1.25 +        # create a json string and pretty print it
    1.26          res = '{"os_server": { '
    1.27 -        res += '"version": "' + __version__ + '", '
    1.28 -        res += '"virtual box systemproperties": ' + str(gvm_mgr.systemProperties).replace("'", '"') + ', '
    1.29 -        res += '"current temporary folder": "' + tempfile.gettempdir().replace('\\', '\\\\') + '" '
    1.30 +        res += '"version": "' + __version__ + '" '
    1.31 +        res += ', "virtual box systemproperties": ' + str(gvm_mgr.systemProperties).replace("'", '"') 
    1.32 +        res += ', "current temporary folder": "' + tempfile.gettempdir().replace('\\', '\\\\') + '"'
    1.33 +
    1.34 +        try:
    1.35 +            res += ', "whoami": "' + Cygwin.bashExecute('whoami')[1].strip() + '"'
    1.36 +        except:
    1.37 +            res += ', "whoami": "FAILED"'
    1.38 +
    1.39 +        try:
    1.40 +            res += ', "mount": ' + str(Cygwin.bashExecute('mount')[1].split('\n')[:-1]).replace("'", '"')
    1.41 +        except:
    1.42 +            res += ', "mount": "FAILED"'
    1.43 +
    1.44 +        try:
    1.45 +            res += ', "cygpath --windows ~": "' + Cygwin.bashExecute('cygpath --windows ~')[1].strip().replace('\\', '\\\\') + '"'
    1.46 +        except:
    1.47 +            res += ', "cygpath --windows ~": "FAILED"'
    1.48 +
    1.49          res += '}}'
    1.50 -        return res
    1.51 +
    1.52 +        # loading it into json and print it again ensures
    1.53 +        # we really do have a valid RFC conform json string
    1.54 +        # created (as long as the python json module is RFC conform)
    1.55 +        return json.dumps(json.loads(res), indent = 4)
    1.56  
    1.57  
    1.58  class os_sdvm: