示例#1
0
    def load(self):
        """
        Load the session from the database.
        @return: 1 in case of success, 0 otherwise.
        @rtype: integer
        """
        session_dict = None
        invalid = False
        res = run_sql(
            "SELECT session_object FROM session "
            "WHERE session_key=%s", (self._sid, ))
        if res:
            session_dict = cPickle.loads(blob_to_string(res[0][0]))
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                if session_dict['_https_ip'] is not None:
                    if ':' in remote_ip:
                        ## IPV6 address, we don't skip bits
                        if session_dict['_https_ip'] != remote_ip:
                            invalid = True
                    else:
                        if _mkip(session_dict['_https_ip']) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS != \
                            _mkip(remote_ip) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS:
                            invalid = True
                else:
                    session_dict['_https_ip'] = remote_ip
            else:
                if session_dict['_http_ip'] is not None:
                    if ':' in remote_ip:
                        ## IPV6 address, we don't skip bits
                        if session_dict['_http_ip'] != remote_ip:
                            invalid = True
                    else:
                        if _mkip(session_dict['_http_ip']) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS != \
                            _mkip(remote_ip) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS:
                            invalid = True
                else:
                    session_dict['_http_ip'] = remote_ip

        if session_dict is None:
            return 0

        if invalid:
            return 0

        if (time.time() - session_dict["_accessed"]) > \
                session_dict["_timeout"]:
            return 0

        self._created = session_dict["_created"]
        self._accessed = session_dict["_accessed"]
        self._timeout = session_dict["_timeout"]
        self._remember_me = session_dict["_remember_me"]
        self.update(session_dict["_data"])
        return 1
示例#2
0
文件: session.py 项目: fjorba/invenio
    def load(self):
        """
        Load the session from the database.
        @return: 1 in case of success, 0 otherwise.
        @rtype: integer
        """
        session_dict = None
        invalid = False
        res = run_sql("SELECT session_object FROM session "
                        "WHERE session_key=%s", (self._sid, ))
        if res:
            session_dict = cPickle.loads(blob_to_string(res[0][0]))
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                if session_dict['_https_ip'] is not None:
                    if ':' in remote_ip:
                        ## IPV6 address, we don't skip bits
                        if session_dict['_https_ip'] != remote_ip:
                            invalid = True
                    else:
                        if _mkip(session_dict['_https_ip']) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS != \
                            _mkip(remote_ip) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS:
                            invalid = True
                else:
                    session_dict['_https_ip'] = remote_ip
            else:
                if session_dict['_http_ip'] is not None:
                    if ':' in remote_ip:
                        ## IPV6 address, we don't skip bits
                        if session_dict['_http_ip'] != remote_ip:
                            invalid = True
                    else:
                        if _mkip(session_dict['_http_ip']) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS != \
                            _mkip(remote_ip) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS:
                            invalid = True
                else:
                    session_dict['_http_ip'] = remote_ip

        if session_dict is None:
            return 0

        if invalid:
            return 0

        if (time.time() - session_dict["_accessed"]) > \
                session_dict["_timeout"]:
            return 0

        self._created  = session_dict["_created"]
        self._accessed = session_dict["_accessed"]
        self._timeout  = session_dict["_timeout"]
        self._remember_me = session_dict["_remember_me"]
        self.update(session_dict["_data"])
        return 1
示例#3
0
    def load(self):
        """
        Load the session from the database.
        @return: 1 in case of success, 0 otherwise.
        @rtype: integer
        """
        session_dict = None
        invalid = False
        res = self.load_from_storage(self._sid)
        if res:
            session_dict = cPickle.loads(blob_to_string(res))
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                if session_dict["_https_ip"] is not None:
                    if ":" in remote_ip:
                        ## IPV6 address, we don't skip bits
                        if session_dict["_https_ip"] != remote_ip:
                            invalid = True
                    else:
                        if (
                            _mkip(session_dict["_https_ip"]) >> CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS
                            != _mkip(remote_ip) >> CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS
                        ):
                            invalid = True
                else:
                    session_dict["_https_ip"] = remote_ip
            else:
                if session_dict["_http_ip"] is not None:
                    if ":" in remote_ip:
                        ## IPV6 address, we don't skip bits
                        if session_dict["_http_ip"] != remote_ip:
                            invalid = True
                    else:
                        if (
                            _mkip(session_dict["_http_ip"]) >> CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS
                            != _mkip(remote_ip) >> CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS
                        ):
                            invalid = True
                else:
                    session_dict["_http_ip"] = remote_ip

        if session_dict is None:
            return 0

        if invalid:
            return 0

        if (time.time() - session_dict["_accessed"]) > session_dict["_timeout"]:
            return 0

        self._created = session_dict["_created"]
        self._accessed = session_dict["_accessed"]
        self._timeout = session_dict["_timeout"]
        self._remember_me = session_dict["_remember_me"]
        self.update(session_dict["_data"])
        return 1
示例#4
0
    def load(self):
        """
        Load the session from the database.
        @return: 1 in case of success, 0 otherwise.
        @rtype: integer
        """
        session_dict = None
        invalid = False
        res = run_sql(
            "SELECT session_object FROM session "
            "WHERE session_key=%s AND session_expiry>=UTC_TIMESTAMP()",
            (self._sid, ))
        if res:
            session_dict = cPickle.loads(
                zlib.decompress(blob_to_string(res[0][0])))
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                if session_dict['_https_ip'] is not None:
                    if ':' in remote_ip:
                        ## IPV6 address, we don't skip bits
                        if session_dict['_https_ip'] != remote_ip:
                            invalid = True
                    else:
                        if _mkip(session_dict['_https_ip']) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS != \
                            _mkip(remote_ip) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS:
                            invalid = True
                else:
                    session_dict['_https_ip'] = remote_ip
            else:
                if session_dict['_http_ip'] is not None:
                    if ':' in remote_ip:
                        ## IPV6 address, we don't skip bits
                        if session_dict['_http_ip'] != remote_ip:
                            invalid = True
                    else:
                        if _mkip(session_dict['_http_ip']) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS != \
                            _mkip(remote_ip) >> \
                                CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS:
                            invalid = True
                else:
                    session_dict['_http_ip'] = remote_ip

        if session_dict is None:
            return 0

        if invalid:
            return 0

        self.update(session_dict)
        self._remember_me = session_dict.get("_permanent", False)
        return 1
示例#5
0
    def load(self):
        """
        Load the session from the database.
        @return: 1 in case of success, 0 otherwise.
        @rtype: integer
        """
        session_dict = None
        invalid = False
        res = run_sql(
            "SELECT session_object FROM session "
            "WHERE session_key=%s", (self._sid, ))
        if res:
            session_dict = cPickle.loads(blob_to_string(res[0][0]))
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                if session_dict['_https_ip'] is not None and \
                        session_dict['_https_ip'] != remote_ip:
                    invalid = True
                else:
                    session_dict['_https_ip'] = remote_ip
            else:
                if session_dict['_http_ip'] is not None and \
                        session_dict['_http_ip'] != remote_ip:
                    invalid = True
                else:
                    session_dict['_http_ip'] = remote_ip

        if session_dict is None:
            return 0

        if invalid:
            return 0

        if (time.time() - session_dict["_accessed"]) > \
                session_dict["_timeout"]:
            return 0

        self._created = session_dict["_created"]
        self._accessed = session_dict["_accessed"]
        self._timeout = session_dict["_timeout"]
        self._remember_me = session_dict["_remember_me"]
        self.update(session_dict["_data"])
        return 1
示例#6
0
    def load(self):
        """
        Load the session from the database.
        @return: 1 in case of success, 0 otherwise.
        @rtype: integer
        """
        session_dict = None
        invalid = False
        res = run_sql("SELECT session_object FROM session "
                        "WHERE session_key=%s", (self._sid, ))
        if res:
            session_dict = cPickle.loads(blob_to_string(res[0][0]))
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                if session_dict['_https_ip'] is not None and \
                        session_dict['_https_ip'] != remote_ip:
                    invalid = True
                else:
                    session_dict['_https_ip'] = remote_ip
            else:
                if session_dict['_http_ip'] is not None and \
                        session_dict['_http_ip'] != remote_ip:
                    invalid = True
                else:
                    session_dict['_http_ip'] = remote_ip

        if session_dict is None:
            return 0

        if invalid:
            return 0

        if (time.time() - session_dict["_accessed"]) > \
                session_dict["_timeout"]:
            return 0

        self._created  = session_dict["_created"]
        self._accessed = session_dict["_accessed"]
        self._timeout  = session_dict["_timeout"]
        self._remember_me = session_dict["_remember_me"]
        self.update(session_dict["_data"])
        return 1
def deserialize(firerole_def_ser):
    """ Deserialize and decompress a definition."""
    if firerole_def_ser:
        return cPickle.loads(decompress(blob_to_string(firerole_def_ser)))
    else:
        return CFG_ACC_EMPTY_ROLE_DEFINITION_OBJ
def deserialize(firerole_def_ser):
    """ Deserialize and decompress a definition."""
    if firerole_def_ser:
        return cPickle.loads(decompress(blob_to_string(firerole_def_ser)))
    else:
        return CFG_ACC_EMPTY_ROLE_DEFINITION_OBJ