XML-RPC

César González cesar en eureka-sistemas.com
Vie Mar 26 01:06:31 CET 2004


Pues parece que la lista no permite adjuntos. Ahi va :


#/usr/bin/env python
# -*- coding: ISO-8859-15 -*-

from twisted.web import xmlrpc, server
from twisted.python import log, reflect
from twisted.internet import ssl, reactor
from OpenSSL import SSL
import sys
import xmlrpclib
import base64
import string

class SSLServerFactory:

    def getContext(self):
        ctx = SSL.Context(SSL.SSLv23_METHOD)
        ctx.use_certificate_file('cacert.pem')
        ctx.use_privatekey_file('cakey.pem')
        return ctx

class netDispacher(xmlrpc.XMLRPC):

    def addObject(self, name, obj):
        self.putSubHandler(name, obj)

    def xmlrpc_ping(self):
        return "pong"

    def render(self, request):
        headers = request.getAllHeaders()
        args, functionPath = xmlrpclib.loads(request.content.read())
        if headers.has_key("authorization"):
            real_auth = '%s:%s' % ("admin", "admin")
            auth = headers["authorization"]
            auth = auth.replace("Basic ","")
            decoded_auth = base64.decodestring(auth)
            if decoded_auth == real_auth:
                user=string.split(real_auth, ":")
                log.err("XML-RPCServer: Usuario - %s - ha ejecutado %s" % 
(user[0], functionPath))
                return xmlrpc.XMLRPC.render(self, request)
        log.err("XML-RPCServer: Usuario no Autorizado - %s queria ejecutar %s" 
% (decoded_auth, functionPath))
        request.setResponseCode(401)
        self._cbRender(
                xmlrpc.Fault(401, "Usuario no Autorizado == Donde vas sin 
frenos"),
                request
            )

if __name__ == "__main__":
        log.startLogging(sys.stdout)
        i_netDispatcher=netDispacher()
        reactor.listenSSL(8668, server.Site(i_netDispatcher), 
SSLServerFactory())
        #Si no quieres ssl usa listenTCP en lugar de listenSSL :
        #reactor.listenTCP(7080, server.Site(i_netDispatcher))
        reactor.run()




------------ próxima parte ------------
_______________________________________________
Python-es mailing list
Python-es en aditel.org
http://listas.aditel.org/listinfo/python-es


Más información sobre la lista de distribución Python-es