Beispiel #1
0
 def headerParserHandler(self, req):
     log_setreq(req)
     # init configuration options with proper component
     options = req.get_options()
     # if we are initializing out of a <Location> handler don't
     # freak out
     if not options.has_key("RHNComponentType"):
         # clearly nothing to do
         return apache.OK
     initCFG(options["RHNComponentType"])
     initLOG(CFG.LOG_FILE, CFG.DEBUG)
     if req.method == 'GET':
         # This is the ping method
         return apache.OK
     self.servers = rhnImport.load("upload_server/handlers",
         interface_signature='upload_class')
     if not options.has_key('SERVER'):
         log_error("SERVER not set in the apache config files!")
         return apache.HTTP_INTERNAL_SERVER_ERROR
     server_name = options['SERVER']
     if not self.servers.has_key(server_name):
         log_error("Unable to load server %s from available servers %s" %
             (server_name, self.servers))
         return apache.HTTP_INTERNAL_SERVER_ERROR
     server_class = self.servers[server_name]
     self.server = server_class(req)
     return self._wrapper(req, "headerParserHandler")
    def headerParserHandler(self, req):
        """
        after a request has been received, first thing we do is to create the
        input object
        """
        # pylint: disable=R0911

        log_setreq(req)
        log_debug(3)
        self.start_time = time.time()
        # Decline if this is a subrequest:
        if req.main:
            return apache.DECLINED
        log_debug(4, req.method, req.path_info, req.headers_in)

        # Clear the global flags.
        rhnFlags.reset()
        # Init the transport options.
        rhnFlags.set('outputTransportOptions', UserDictCase())
        # Init the session token dictionary.
        rhnFlags.set("AUTH_SESSION_TOKEN", UserDictCase())

        ret = self._init_request_processor(req)
        if ret != apache.OK:
            return ret

        ret = self._set_client_info(req)
        if ret != apache.OK:
            return ret

        # Check the protocol version
        if req.proto_num < 1001:
            # HTTP protocols prior to 1.1 close the connection
            rhnFlags.get('outputTransportOptions')["Connection"] = "close"

        ret = self._set_proxy_info(req)
        if ret != apache.OK:
            return ret

        # Need to run _set_other first, since _set_lang needs RoodDir set
        ret = self._set_other(req)
        if ret != apache.OK:
            return ret

        ret = self._set_lang(req)
        if ret != apache.OK:
            return ret

        return apache.OK
Beispiel #3
0
    def headerParserHandler(self, req):
        """
        after a request has been received, first thing we do is to create the
        input object
        """
        # pylint: disable=R0911

        log_setreq(req)
        log_debug(3)
        self.start_time = time.time()
        # Decline if this is a subrequest:
        if req.main:
            return apache.DECLINED
        log_debug(4, req.method, req.path_info, req.headers_in)

        # Clear the global flags.
        rhnFlags.reset()
        # Init the transport options.
        rhnFlags.set('outputTransportOptions', UserDictCase())
        # Init the session token dictionary.
        rhnFlags.set("AUTH_SESSION_TOKEN", UserDictCase())

        ret = self._init_request_processor(req)
        if ret != apache.OK:
            return ret

        ret = self._set_client_info(req)
        if ret != apache.OK:
            return ret

        # Check the protocol version
        if req.proto_num < 1001:
            # HTTP protocols prior to 1.1 close the connection
            rhnFlags.get('outputTransportOptions')["Connection"] = "close"

        ret = self._set_proxy_info(req)
        if ret != apache.OK:
            return ret

        # Need to run _set_other first, since _set_lang needs RoodDir set
        ret = self._set_other(req)
        if ret != apache.OK:
            return ret

        ret = self._set_lang(req)
        if ret != apache.OK:
            return ret

        return apache.OK
    def headerParserHandler(self, req):

        log_setreq(req)
        # We need to init CFG and Logging
        options = req.get_options()
        # if we are initializing out of a <Location> handler don't
        # freak out
        if "RHNComponentType" not in options:
            # clearly nothing to do
            return apache.OK
        initCFG(options["RHNComponentType"])
        initLOG(CFG.LOG_FILE, CFG.DEBUG)
        """ parse the request, init database and figure out what can we call """
        log_debug(2, req.the_request)
        # call method from inherited class
        ret = apacheSession.headerParserHandler(self, req)
        if ret != apache.OK:
            return ret
        # make sure we have DB connection
        if not CFG.SEND_MESSAGE_TO_ALL:
            try:
                rhnSQL.initDB()
            except rhnSQL.SQLConnectError:
                rhnTB.Traceback(mail=1, req=req, severity="schema")
                return apache.HTTP_INTERNAL_SERVER_ERROR
        else:
            # If in outage mode, close the DB connections
            rhnSQL.closeDB()

        # Store client capabilities
        client_cap_header = 'X-RHN-Client-Capability'
        if client_cap_header in req.headers_in:
            client_caps = req.headers_in[client_cap_header]
            client_caps = [
                _f for _f in list(
                    map(string.strip, string.split(client_caps, ","))) if _f
            ]
            rhnCapability.set_client_capabilities(client_caps)

        # Enabling the input header flags associated with the redirects/newer clients
        redirect_support_flags = [
            'X-RHN-Redirect', 'X-RHN-Transport-Capability'
        ]
        for flag in redirect_support_flags:
            if flag in req.headers_in:
                rhnFlags.set(flag, str(req.headers_in[flag]))

        return apache.OK
Beispiel #5
0
    def headerParserHandler(self, req):

        log_setreq(req)
        # We need to init CFG and Logging
        options = req.get_options()
        # if we are initializing out of a <Location> handler don't
        # freak out
        if not options.has_key("RHNComponentType"):
            # clearly nothing to do
            return apache.OK
        initCFG(options["RHNComponentType"])
        initLOG(CFG.LOG_FILE, CFG.DEBUG)

        """ parse the request, init database and figure out what can we call """
        log_debug(2, req.the_request)
        # call method from inherited class
        ret = apacheSession.headerParserHandler(self, req)
        if ret != apache.OK:
            return ret
        # make sure we have DB connection
        if not CFG.SEND_MESSAGE_TO_ALL:
            try:
                rhnSQL.initDB()
            except rhnSQL.SQLConnectError:
                rhnTB.Traceback(mail=1, req=req, severity="schema")
                return apache.HTTP_INTERNAL_SERVER_ERROR
        else:
            # If in outage mode, close the DB connections
            rhnSQL.closeDB()

        # Store client capabilities
        client_cap_header = 'X-RHN-Client-Capability'
        if req.headers_in.has_key(client_cap_header):
            client_caps = req.headers_in[client_cap_header]
            client_caps = filter(None,
                                 map(string.strip, string.split(client_caps, ","))
                                 )
            rhnCapability.set_client_capabilities(client_caps)

        # Enabling the input header flags associated with the redirects/newer clients
        redirect_support_flags = ['X-RHN-Redirect', 'X-RHN-Transport-Capability']
        for flag in redirect_support_flags:
            if req.headers_in.has_key(flag):
                rhnFlags.set(flag, str(req.headers_in[flag]))

        return apache.OK
    def headerParserHandler(self, req):
        # pylint: disable=W0201
        log_setreq(req)
        self.start_time = time.time()
        # init configuration options with proper component
        options = req.get_options()
        # if we are initializing out of a <Location> handler don't
        # freak out
        if "RHNComponentType" not in options:
            # clearly nothing to do
            return apache.OK
        initCFG(options["RHNComponentType"])
        initLOG(CFG.LOG_FILE, CFG.DEBUG)
        # short-circuit everything if sending a system-wide message.
        if CFG.SEND_MESSAGE_TO_ALL:
            # Drop the database connection
            # pylint: disable=W0702
            try:
                rhnSQL.closeDB()
            except:
                pass

            # Fetch global message being sent to clients if applicable.
            msg = open(CFG.MESSAGE_TO_ALL).read()
            log_debug(3, "Sending message to all clients: %s" % msg)
            return self._send_xmlrpc(
                req,
                rhnFault(-1,
                         _("IMPORTANT MESSAGE FOLLOWS:\n%s") % msg,
                         explain=0))

        rhnSQL.initDB()
        self.server = options['SERVER']

        self.server_classes = rhnImport.load("satellite_exporter/handlers")

        if self.server not in self.server_classes:
            # XXX do something interesting here
            log_error("Missing server", self.server)
            return apache.HTTP_NOT_FOUND

        return self._wrapper(req, self._headerParserHandler)
Beispiel #7
0
    def __call__(self, req):
        # NOTE: all imports done here due to required initialization of
        #       of the configuration module before all others.
        #       Initialization is dependent on RHNComponentType in the
        #       req object.

        if self.__init:
            from apacheHandler import getComponentType
            # We cannot trust the config files to tell us if we are in the
            # broker or in the redirect because we try to always pass
            # upstream all requests
            componentType = getComponentType(req)
            initCFG(componentType)
            initLOG(CFG.LOG_FILE, CFG.DEBUG)
            log_debug(1, 'New request, component %s' % (componentType, ))

        # Instantiate the handlers
        if HandlerWrap.svrHandlers is None:
            HandlerWrap.svrHandlers = self.get_handler_factory(req)()

        if self.__init:
            # Set the component type
            HandlerWrap.svrHandlers.set_component(componentType)

        try:
            log_setreq(req)
            if hasattr(HandlerWrap.svrHandlers, self.__name):
                f = getattr(HandlerWrap.svrHandlers, self.__name)
                ret = f(req)
            else:
                raise Exception("Class has no attribute %s" % self.__name)
        # pylint: disable=W0702
        except:
            Traceback(self.__name,
                      req,
                      extra="Unhandled exception type",
                      severity="unhandled")
            return apache.HTTP_INTERNAL_SERVER_ERROR
        else:
            return ret
Beispiel #8
0
    def headerParserHandler(self, req):
        # pylint: disable=W0201
        log_setreq(req)
        self.start_time = time.time()
        # init configuration options with proper component
        options = req.get_options()
        # if we are initializing out of a <Location> handler don't
        # freak out
        if "RHNComponentType" not in options:
            # clearly nothing to do
            return apache.OK
        initCFG(options["RHNComponentType"])
        initLOG(CFG.LOG_FILE, CFG.DEBUG)
        # short-circuit everything if sending a system-wide message.
        if CFG.SEND_MESSAGE_TO_ALL:
            # Drop the database connection
            # pylint: disable=W0702
            try:
                rhnSQL.closeDB()
            except:
                pass

            # Fetch global message being sent to clients if applicable.
            msg = open(CFG.MESSAGE_TO_ALL).read()
            log_debug(3, "Sending message to all clients: %s" % msg)
            return self._send_xmlrpc(req, rhnFault(-1,
                                                   _("IMPORTANT MESSAGE FOLLOWS:\n%s") % msg, explain=0))

        rhnSQL.initDB()
        self.server = options['SERVER']

        self.server_classes = rhnImport.load("satellite_exporter/handlers")

        if self.server not in self.server_classes:
            # XXX do something interesting here
            log_error("Missing server", self.server)
            return apache.HTTP_NOT_FOUND

        return self._wrapper(req, self._headerParserHandler)
Beispiel #9
0
    def __call__(self, req):
        # NOTE: all imports done here due to required initialization of
        #       of the configuration module before all others.
        #       Initialization is dependent on RHNComponentType in the
        #       req object.

        if self.__init:
            from apacheHandler import getComponentType
            # We cannot trust the config files to tell us if we are in the
            # broker or in the redirect because we try to always pass
            # upstream all requests
            componentType = getComponentType(req)
            initCFG(componentType)
            initLOG(CFG.LOG_FILE, CFG.DEBUG)
            log_debug(1, 'New request, component %s' % (componentType, ))

        # Instantiate the handlers
        if HandlerWrap.svrHandlers is None:
            HandlerWrap.svrHandlers = self.get_handler_factory(req)()

        if self.__init:
            # Set the component type
            HandlerWrap.svrHandlers.set_component(componentType)

        try:
            log_setreq(req)
            if hasattr(HandlerWrap.svrHandlers, self.__name):
                f = getattr(HandlerWrap.svrHandlers, self.__name)
                ret = f(req)
            else:
                raise Exception("Class has no attribute %s" % self.__name)
        # pylint: disable=W0702
        except:
            Traceback(self.__name, req, extra="Unhandled exception type",
                      severity="unhandled")
            return apache.HTTP_INTERNAL_SERVER_ERROR
        else:
            return ret