OpenSecurity/bin/opensecurity_client_restful_server.py
changeset 142 709cbb3b16de
parent 136 ac117cd7bab1
child 144 dd472ede7a9f
     1.1 --- a/OpenSecurity/bin/opensecurity_client_restful_server.py	Wed Apr 30 12:06:22 2014 +0200
     1.2 +++ b/OpenSecurity/bin/opensecurity_client_restful_server.py	Fri May 09 14:09:02 2014 +0200
     1.3 @@ -32,9 +32,11 @@
     1.4  # ------------------------------------------------------------
     1.5  # imports
     1.6  
     1.7 +import getpass
     1.8  import json
     1.9  import os
    1.10  import os.path
    1.11 +import platform
    1.12  import socket
    1.13  import subprocess
    1.14  import sys
    1.15 @@ -59,6 +61,7 @@
    1.16  opensecurity_urls = (
    1.17      '/credentials',             'os_credentials',
    1.18      '/keyfile',                 'os_keyfile',
    1.19 +    '/log',                     'os_log',
    1.20      '/notification',            'os_notification',
    1.21      '/password',                'os_password',
    1.22      '/',                        'os_root'
    1.23 @@ -143,6 +146,42 @@
    1.24          return 'user queried for password and keyfile'
    1.25  
    1.26  
    1.27 +class os_log:
    1.28 +
    1.29 +    """OpenSecurity '/log' handler.
    1.30 +    
    1.31 +    This is called on GET or POST on the log function /log
    1.32 +    """
    1.33 +    
    1.34 +    def GET(self):
    1.35 +        
    1.36 +        # pick the arguments
    1.37 +        self.POST()
    1.38 +
    1.39 +
    1.40 +    def POST(self):
    1.41 +        
    1.42 +        # pick the arguments
    1.43 +        args = web.input()
    1.44 +        args['user'] = getpass.getuser()
    1.45 +        args['system'] = platform.node() + " " + platform.system() + " " + platform.release()
    1.46 +
    1.47 +        # bounce log data
    1.48 +        url_addr = 'http://GIMME-SERVER-TO-LOG-TO/log'
    1.49 +
    1.50 +        # by provided a 'data' we turn this into a POST statement
    1.51 +        d = urllib.urlencode(args)
    1.52 +        req = urllib2.Request(url_addr, d)
    1.53 +        try:
    1.54 +            res = urllib2.urlopen(req)
    1.55 +        except:
    1.56 +            print('failed to contact: ' + url_addr)
    1.57 +            print('log data: ' + d)
    1.58 +            return "Failed"
    1.59 +         
    1.60 +        return "Ok"
    1.61 +
    1.62 +
    1.63  class os_notification:
    1.64  
    1.65      """OpenSecurity '/notification' handler.
    1.66 @@ -299,8 +338,9 @@
    1.67          # TODO: it would be WAY easier and secure if we just 
    1.68          #       add the result json to a HTTP-POST here.
    1.69          url_addr = 'http://' + self._remote_ip + ':58080' + self._resource
    1.70 -        url = url_addr + '?' + urllib.urlencode(j)
    1.71 -        req = urllib2.Request(url)
    1.72 +
    1.73 +        # by provided a 'data' we turn this into a POST statement
    1.74 +        req = urllib2.Request(url_addr, urllib.urlencode(j))
    1.75          try:
    1.76              res = urllib2.urlopen(req)
    1.77          except: