def __init__(self, addr, delegate=None, keyfile=None, certfile=None, ca_certs=None, base_name=None): # ca_certs arg here must be a file of concatenated certs if ca_certs is None: raise Exception('Missing CA Certs') elif not os.path.isfile(os.path.expanduser(ca_certs)): raise Exception( 'CA Certs must be an existing file of accepted root certs: %s' % ca_certs) # FIXME: set logRequests=true if --debug self._server = SecureXMLRPCServer(addr, keyfile=keyfile, certfile=certfile, ca_certs=ca_certs) if delegate is None: delegate = PrintingAggregateManager() self._server.register_instance(AggregateManager(delegate)) # Set the server on the delegate so it can access the # client certificate. delegate._server = self._server if not base_name is None: global RESOURCE_NAMESPACE RESOURCE_NAMESPACE = base_name
def _make_server(self, addr, keyfile=None, certfile=None, ca_certs=None): """Creates the XML RPC server.""" # ca_certs is a file of concatenated certs return SecureXMLRPCServer(addr, keyfile=keyfile, certfile=certfile, ca_certs=ca_certs)
def _make_server(self, addr, keyfile=None, certfile=None, ca_certs=None): """Creates the XML RPC server.""" # ca_certs is a file of concatenated certs # make 2nd arg logRequests=True if --debug debug = False if self.config.has_key('debug'): debug = self.config['debug'] return SecureXMLRPCServer(addr, logRequests=debug, keyfile=keyfile, certfile=certfile, ca_certs=ca_certs)
class AggregateManagerServer(object): """An XMLRPC Aggregate Manager Server. Delegates calls to given delegate, or the default printing AM.""" def __init__(self, addr, delegate=None, keyfile=None, certfile=None, ca_certs=None, base_name=None): # ca_certs arg here must be a file of concatenated certs if ca_certs is None: raise Exception('Missing CA Certs') elif not os.path.isfile(os.path.expanduser(ca_certs)): raise Exception('CA Certs must be an existing file of accepted root certs: %s' % ca_certs) # FIXME: set logRequests=true if --debug self._server = SecureXMLRPCServer(addr, keyfile=keyfile, certfile=certfile, ca_certs=ca_certs) if delegate is None: delegate = PrintingAggregateManager() self._server.register_instance(AggregateManager(delegate)) # Set the server on the delegate so it can access the # client certificate. delegate._server = self._server if not base_name is None: global RESOURCE_NAMESPACE RESOURCE_NAMESPACE = base_name def serve_forever(self): self._server.serve_forever() def register_instance(self, instance): # Pass the AM instance to the generic XMLRPC server, # which lets it know what XMLRPC methods to expose self._server.register_instance(instance)
class AggregateManagerServer(object): """An XMLRPC Aggregate Manager Server. Delegates calls to given delegate, or the default printing AM.""" def __init__(self, addr, delegate=None, keyfile=None, certfile=None, ca_certs=None, base_name=None): # ca_certs arg here must be a file of concatenated certs if ca_certs is None: raise Exception('Missing CA Certs') elif not os.path.isfile(os.path.expanduser(ca_certs)): raise Exception('CA Certs must be an existing file of accepted root certs: %s' % ca_certs) self._server = SecureXMLRPCServer(addr, keyfile=keyfile, certfile=certfile, ca_certs=ca_certs) if delegate is None: delegate = PrintingAggregateManager() self._server.register_instance(AggregateManager(delegate)) # Set the server on the delegate so it can access the # client certificate. delegate._server = self._server if not base_name is None: global RESOURCE_NAMESPACE RESOURCE_NAMESPACE = base_name def serve_forever(self): self._server.serve_forever() def register_instance(self, instance): # Pass the AM instance to the generic XMLRPC server, # which lets it know what XMLRPC methods to expose self._server.register_instance(instance)
def __init__(self): """Bind to port 443, load certs for ssl. Register XMLRPC functions. """ self.server = SecureXMLRPCServer(('localhost', 443), 'certs/mycert.pem') print("listening on port 443") self.DirServ = DirectoryService() self.server.register_function(self.DirServ.cd, 'cd') self.server.register_function(self.DirServ.close_session, 'close') self.server.register_function(self.DirServ.delete, 'delete') self.server.register_function(self.DirServ.fetch, 'fetch') self.server.register_function(self.DirServ.lock, 'lock') self.server.register_function(self.DirServ.ls, 'ls') self.server.register_function(self.DirServ.make_dir, 'make_dir') self.server.register_function(self.DirServ.save, 'save') self.server.register_function(self.DirServ.setup, 'setup')
def __init__(self): """Bind to port 443, load certs for ssl. Register XMLRPC functions. """ self.server = SecureXMLRPCServer( ("localhost", 443), "certs/mycert.pem", requestHandler=self.VerifyingRequestHandler ) print("listening on port 443") self.DirServ = DirectoryService() self.server.register_function(self.DirServ.cd, "cd") self.server.register_function(self.DirServ.close_session, "close") self.server.register_function(self.DirServ.delete, "delete") self.server.register_function(self.DirServ.fetch, "fetch") self.server.register_function(self.DirServ.lock, "lock") self.server.register_function(self.DirServ.ls, "ls") self.server.register_function(self.DirServ.make_dir, "make_dir") self.server.register_function(self.DirServ.save, "save") self.server.register_function(self.DirServ.setup, "setup")
def __init__(self, addr, delegate=None, keyfile=None, certfile=None, ca_certs=None, base_name=None): # ca_certs arg here must be a file of concatenated certs if ca_certs is None: raise Exception('Missing CA Certs') elif not os.path.isfile(os.path.expanduser(ca_certs)): raise Exception('CA Certs must be an existing file of accepted root certs: %s' % ca_certs) # FIXME: set logRequests=true if --debug self._server = SecureXMLRPCServer(addr, keyfile=keyfile, certfile=certfile, ca_certs=ca_certs) if delegate is None: delegate = PrintingAggregateManager() self._server.register_instance(AggregateManager(delegate)) # Set the server on the delegate so it can access the # client certificate. delegate._server = self._server if not base_name is None: global RESOURCE_NAMESPACE RESOURCE_NAMESPACE = base_name
def main(argv): global STOP_LAUNCHER global APP_CONFIG_FILE global XMLRPC_PORT global SECURE_XMLRPC_PORT global SAGE_SERVER global DO_REPORT global REPORT_NAME # parse the command line params (options, args) = get_commandline_options() doRedirect(not options.verbose) if options.config != "": APP_CONFIG_FILE = options.config XMLRPC_PORT = options.port SECURE_XMLRPC_PORT = XMLRPC_PORT+1 SAGE_SERVER = options.server DO_REPORT = not options.report REPORT_NAME = options.name # set the default timeout so that we don't wait forever socket.setdefaulttimeout(0.1) # 200ms... because both servers need to be running # create the main object for handling requests appLauncher = AppLauncher() # start the insecure server and listen for sage ui connections server = MySimpleXMLRPCServer(("", XMLRPC_PORT), logRequests=False) server.register_function(appLauncher.startDefaultApp) server.register_function(appLauncher.startApp) server.register_function(appLauncher.stopApp) server.register_function(appLauncher.getAppList) server.register_function(appLauncher.getAppConfigInfo) server.register_function(appLauncher.killLauncher) server.register_function(appLauncher.test) server.register_function(appLauncher.appStatus) server.register_introspection_functions() print "Started insecure XML_RPC server on port " + str(XMLRPC_PORT) # create a new key and certificate upon startup use_ssl = generateSSLCertificate() # now start the SSL version of the server if use_ssl: secureServer = SecureXMLRPCServer(("", SECURE_XMLRPC_PORT), logRequests=False) secureServer.register_function(appLauncher.startDefaultApp) secureServer.register_function(appLauncher.startApp) secureServer.register_function(appLauncher.stopApp) secureServer.register_function(appLauncher.getAppList) secureServer.register_function(appLauncher.getAppConfigInfo) secureServer.register_function(appLauncher.killLauncher) secureServer.register_function(appLauncher.test) secureServer.register_function(appLauncher.appStatus) secureServer.register_introspection_functions() print "Started secure SSL XML_RPC server on port " + str(SECURE_XMLRPC_PORT) # now loop forever and serve the requests oldT = time.time() while not STOP_LAUNCHER: try: # report every 6 seconds that we are still alive if (time.time() - oldT) > 6: appLauncher.reportLauncher() oldT = time.time() # accept and process any xmlrpc requests # this times out every few seconds as defined by the setdefaulttimeout above server.handle_request() if use_ssl: secureServer.handle_request() except KeyboardInterrupt: break except: WriteLog( "\n=======> XML_RPC SERVER ERROR: ") WriteLog( "".join(tb.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])) ) continue appLauncher.requests.stopSubmitThread() server.server_close() if use_ssl: secureServer.server_close() sys.exit(0)
class Server: def __init__(self): """Bind to port 443, load certs for ssl. Register XMLRPC functions. """ self.server = SecureXMLRPCServer( ("localhost", 443), "certs/mycert.pem", requestHandler=self.VerifyingRequestHandler ) print("listening on port 443") self.DirServ = DirectoryService() self.server.register_function(self.DirServ.cd, "cd") self.server.register_function(self.DirServ.close_session, "close") self.server.register_function(self.DirServ.delete, "delete") self.server.register_function(self.DirServ.fetch, "fetch") self.server.register_function(self.DirServ.lock, "lock") self.server.register_function(self.DirServ.ls, "ls") self.server.register_function(self.DirServ.make_dir, "make_dir") self.server.register_function(self.DirServ.save, "save") self.server.register_function(self.DirServ.setup, "setup") def run(self): """Await client requests forever. """ self.server.serve_forever() class VerifyingRequestHandler(SimpleXMLRPCRequestHandler): def parse_request(myself): if SimpleXMLRPCRequestHandler.parse_request(myself): if authenticate(myself.headers): return True else: myself.send_error(401, "Authentication failed") return False