Esempio n. 1
0
    def __init__(self, req, sid=None):
        self._remember_me = False
        self._req, self._sid, self._secret = req, sid, None
        self._lock = CFG_WEBSESSION_ENABLE_LOCKING
        self._new = 1
        self._locked = 0
        self._invalid = 0
        self._dirty = False
        self._http_ip = None
        self._https_ip = None
        self.__need_https = False

        dict.__init__(self)

        if not self._sid:
            # check to see if cookie exists
            cookie = get_cookie(req, CFG_WEBSESSION_COOKIE_NAME)
            if cookie:
                self._sid = cookie.value
            else:
                stub_cookie = get_cookie(req,
                                         CFG_WEBSESSION_COOKIE_NAME + 'stub')
                self.__need_https = stub_cookie and stub_cookie.value == 'HTTPS'

        if self._sid:
            if not _check_sid(self._sid):
                if sid:
                    # Supplied explicitly by user of the class,
                    # raise an exception and make the user code
                    # deal with it.
                    raise ValueError("Invalid Session ID: sid=%s" % sid)
                else:
                    # Derived from the cookie sent by browser,
                    # wipe it out so it gets replaced with a
                    # correct value.
                    self._sid = None

        if self._sid:
            # attempt to load ourselves
            self.lock()
            if self.load():
                self._new = 0

        if self._new:
            # make a new session
            if self._sid:
                self.unlock()  # unlock old sid
            self._sid = _new_sid(self._req)
            self.lock()  # lock new sid
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                self._https_ip = remote_ip
            else:
                self._http_ip = remote_ip

        # need cleanup?
        if random.randint(1, CFG_WEBSESSION_CLEANUP_CHANCE) == 1:
            self.cleanup()
Esempio n. 2
0
    def __init__(self, req, sid=None):
        self._remember_me = False
        self._req, self._sid, self._secret = req, sid, None
        self._lock = CFG_WEBSESSION_ENABLE_LOCKING
        self._new = 1
        self._created = 0
        self._accessed = 0
        self._timeout = 0
        self._locked = 0
        self._invalid = 0
        self._http_ip = None
        self._https_ip = None

        dict.__init__(self)

        if not self._sid:
            # check to see if cookie exists
            cookie = get_cookie(req, CFG_WEBSESSION_COOKIE_NAME)
            if cookie:
                self._sid = cookie.value

        if self._sid:
            if not _check_sid(self._sid):
                if sid:
                    # Supplied explicitly by user of the class,
                    # raise an exception and make the user code
                    # deal with it.
                    raise ValueError("Invalid Session ID: sid=%s" % sid)
                else:
                    # Derived from the cookie sent by browser,
                    # wipe it out so it gets replaced with a
                    # correct value.
                    self._sid = None

        if self._sid:
            # attempt to load ourselves
            self.lock()
            if self.load():
                self._new = 0

        if self._new:
            # make a new session
            if self._sid:
                self.unlock() # unlock old sid
            self._sid = _new_sid(self._req)
            self.lock()                 # lock new sid
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                self._https_ip = remote_ip
            else:
                self._http_ip = remote_ip
            add_cookie(self._req, self.make_cookie())
            self._created = time.time()
            self._timeout = CFG_WEBSESSION_EXPIRY_LIMIT_DEFAULT * \
                CFG_WEBSESSION_ONE_DAY

        self._accessed = time.time()

        # need cleanup?
        if random.randint(1, CFG_WEBSESSION_CLEANUP_CHANCE) == 1:
            self.cleanup()
Esempio n. 3
0
    def __init__(self, req, sid=None):
        self._remember_me = False
        self._req, self._sid, self._secret = req, sid, None
        self._new = 1
        self._created = 0
        self._accessed = 0
        self._timeout = 0
        self._invalid = 0
        self._dirty = False
        self._http_ip = None
        self._https_ip = None
        self.__need_https = False
        self._cleanup_function = None

        dict.__init__(self)

        if not self._sid:
            # check to see if cookie exists
            cookie = get_cookie(req, CFG_WEBSESSION_COOKIE_NAME)
            if cookie:
                self._sid = cookie.value
            else:
                stub_cookie = get_cookie(req, CFG_WEBSESSION_COOKIE_NAME + "stub")
                self.__need_https = stub_cookie and stub_cookie.value == "HTTPS"

        if self._sid:
            if not _check_sid(self._sid):
                if sid:
                    # Supplied explicitly by user of the class,
                    # raise an exception and make the user code
                    # deal with it.
                    raise ValueError("Invalid Session ID: sid=%s" % sid)
                else:
                    # Derived from the cookie sent by browser,
                    # wipe it out so it gets replaced with a
                    # correct value.
                    self._sid = None

        if self._sid:
            # attempt to load ourselves
            if self.load():
                self._new = 0

        if self._new:
            # make a new session
            self._sid = _new_sid(self._req)
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                self._https_ip = remote_ip
            else:
                self._http_ip = remote_ip
            self._created = time.time()
            self._timeout = CFG_WEBSESSION_EXPIRY_LIMIT_DEFAULT * CFG_WEBSESSION_ONE_DAY

        self._accessed = time.time()

        # need cleanup?
        if random.randint(1, CFG_WEBSESSION_CLEANUP_CHANCE) == 1:
            self.cleanup()

        if self._new and (not self.__need_https or self._req.is_https()):
            ## We want to issue cookies only in case this is a new session
            ## and there is not already a session cookie that is available
            ## only over HTTPS
            for cookie in self.make_cookies():
                self._req.set_cookie(cookie)
Esempio n. 4
0
    def __init__(self, req, sid=None):
        self._remember_me = False
        self._req, self._sid, self._secret = req, sid, None
        self._new = 1
        self._created = 0
        self._accessed = 0
        self._timeout = 0
        self._invalid = 0
        self._dirty = False
        self._http_ip = None
        self._https_ip = None
        self.__need_https = False
        self._cleanup_function = None

        dict.__init__(self)

        if not self._sid:
            # check to see if cookie exists
            cookie = get_cookie(req, CFG_WEBSESSION_COOKIE_NAME)
            if cookie:
                self._sid = cookie.value
            else:
                stub_cookie = get_cookie(req,
                                         CFG_WEBSESSION_COOKIE_NAME + 'stub')
                self.__need_https = stub_cookie and stub_cookie.value == 'HTTPS'

        if self._sid:
            if not _check_sid(self._sid):
                if sid:
                    # Supplied explicitly by user of the class,
                    # raise an exception and make the user code
                    # deal with it.
                    raise ValueError("Invalid Session ID: sid=%s" % sid)
                else:
                    # Derived from the cookie sent by browser,
                    # wipe it out so it gets replaced with a
                    # correct value.
                    self._sid = None

        if self._sid:
            # attempt to load ourselves
            if self.load():
                self._new = 0

        if self._new:
            # make a new session
            self._sid = _new_sid(self._req)
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                self._https_ip = remote_ip
            else:
                self._http_ip = remote_ip
            self._created = time.time()
            self._timeout = CFG_WEBSESSION_EXPIRY_LIMIT_DEFAULT * \
                CFG_WEBSESSION_ONE_DAY

        self._accessed = time.time()

        # need cleanup?
        if random.randint(1, CFG_WEBSESSION_CLEANUP_CHANCE) == 1:
            self.cleanup()

        if self._new and (not self.__need_https or self._req.is_https()):
            ## We want to issue cookies only in case this is a new session
            ## and there is not already a session cookie that is available
            ## only over HTTPS
            for cookie in self.make_cookies():
                self._req.set_cookie(cookie)