Securing SimpleXMLRPCServer?

John Abel john.abel at pa.press.net
Fri Jul 12 04:35:57 EDT 2002


If we ever meet in person, I will gladly buy you many beers.

Thank you for your time, and patience :)

Regards

John

On Thu, 2002-07-11 at 01:15, Brian Quinlan wrote:

    Here is some XML-RPC IP-based authentication code that works:
    
    import sys, os, gzip, smtplib, SimpleXMLRPCServer, string
    
    class
    AuthenticatingSimpleXMLRPCRequestHandler(SimpleXMLRPCServer.SimpleXMLRPC
    RequestHandler):
        class UnknownIP(Exception): pass
    
        def _dispatch( self, method, params ):
            ip, port = self.client_address
            if ip not in ["144.178.233.83","144.178.234.189", '127.0.0.1'] :
                raise self.UnknownIP, "Client IP Is Not Authorised"
            else:
     
    SimpleXMLRPCServer.SimpleXMLRPCRequestHandler._dispatch(self, method,
    params)
    
    
    def GetFiles(FileRequest):
        print FileRequest
        RetrFile = open(FileRequest,"r")
        FileContents = "Not Found"
        for FileLine in RetrFile:
            if FileContents == None:
                FileContents = FileLine
            else:
                FileContents = FileContents + FileLine
        
        return FileContents
    
    if __name__== "__main__":
    
        XMLRPCServer = SimpleXMLRPCServer.SimpleXMLRPCServer (
    ("127.0.0.1",8000), AuthenticatingSimpleXMLRPCRequestHandler )
        XMLRPCServer.register_function(GetFiles)
        XMLRPCServer.serve_forever()
    
    
    > Thanks again for your help and patience.
    
    If we ever meet in person, you owe me many beers :-)
    
    Cheers,
    Brian



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020712/9cafe08b/attachment.html>


More information about the Python-list mailing list