Exemple #1
0
    def request(self, host, handler, request_body, verbose=0):
        # issue XML-RPC request
        h = self.make_connection(host)
        if verbose:
            h.set_debuglevel(1)

        self.send_request(h, handler, request_body)
        self.send_host(h, host)
        self.send_user_agent(h)

        self.send_content(h, request_body)

        r = h.getresponse()
        errcode = r.status
        errmsg = r.reason
        headers = r.msg

        # Creati g cookie jar
        cresponse = CookieResponse(headers)
        crequest = CookieRequest('https://' + host + '/')
        if '<methodName>base.ldapAuth</methodName>' in request_body:
            cj = LWPCookieJar()
            cj.extract_cookies(cresponse, crequest)
            if len(cj):
                cj.save(COOKIES_FILE, ignore_discard=True, ignore_expires=True)
                os.chmod(COOKIES_FILE, stat.S_IRUSR | stat.S_IWUSR)

        if errcode != 200:
            raise xmlrpclib.ProtocolError(host + handler, errcode, errmsg,
                                          headers)

        self.verbose = verbose

        return self.parse_response(r)
Exemple #2
0
    def parse_response(self, response):
        """ Override parse_response to store cookie info on
        response """
        # dummy response class for extracting cookies
        class CookieResponse:
            def __init__(self, headers):
                self.headers = headers
            def info(self):
                return self.headers

        if hasattr(response, 'getheader'):
            cj = LWPCookieJar()
            cresponse = CookieResponse(response.msg)
            cj.extract_cookies(cresponse, self.crequest)
            if len(cj) > 0 and self.cookie_file != None:
                cj.save(self.cookie_file)
                os.chmod(self.cookie_file, stat.S_IRUSR | stat.S_IWUSR)

        return xmlrpclib.Transport.parse_response(self, response)
Exemple #3
0
    def parse_response(self, response):
        """ Override parse_response to store cookie info on
        response """

        # dummy response class for extracting cookies
        class CookieResponse:
            def __init__(self, headers):
                self.headers = headers

            def info(self):
                return self.headers

        if hasattr(response, 'getheader'):
            cj = LWPCookieJar()
            cresponse = CookieResponse(response.msg)
            cj.extract_cookies(cresponse, self.crequest)
            if len(cj) > 0 and self.cookie_file != None:
                cj.save(self.cookie_file)
                os.chmod(self.cookie_file, stat.S_IRUSR | stat.S_IWUSR)

        return xmlrpclib.Transport.parse_response(self, response)
Exemple #4
0
    def request(self, host, handler, request_body, verbose=0):
        # issue XML-RPC request
        h = self.make_connection(host)
        if verbose:
            h.set_debuglevel(1)

        self.send_request(h, handler, request_body)
        self.send_host(h, host)
        self.send_user_agent(h)

        self.send_content(h, request_body)

        errcode, errmsg, headers = h.getreply()
        # Creating cookie jar
        cresponse = CookieResponse(headers)
        crequest = CookieRequest('https://' + host + '/')
        if '<methodName>base.ldapAuth</methodName>' in request_body:
            cj = LWPCookieJar()
            cj.extract_cookies(cresponse, crequest)
            if len(cj):
                cj.save(COOKIES_FILE, ignore_discard=True, ignore_expires=True)
                os.chmod(COOKIES_FILE, stat.S_IRUSR | stat.S_IWUSR)

        if errcode != 200:
            raise xmlrpclib.ProtocolError(
                host + handler,
                errcode, errmsg,
                headers
                )

        self.verbose = verbose

        try:
            sock = h._conn.sock
        except AttributeError:
            sock = None

        return self._parse_response(h.getfile(), sock)