|
@@ -1,4 +1,7 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+## @package lodel.plugins.filesystem_session.main Main entry point of the plugin
|
|
4
|
+
|
2
|
5
|
import binascii
|
3
|
6
|
import datetime
|
4
|
7
|
import os
|
|
@@ -30,18 +33,24 @@ def generate_token():
|
30
|
33
|
|
31
|
34
|
## @brief checks the validity of a given session token
|
32
|
35
|
# @param token str
|
33
|
|
-# @raise ClientAuthenticationFailure for invalid or not found session token
|
|
36
|
+# @throw ClientAuthenticationFailure for invalid or not found session token
|
34
|
37
|
def check_token(token):
|
35
|
38
|
if len(token) != SESSION_TOKENSIZE:
|
36
|
39
|
raise ClientAuthenticationFailure("Invalid token string")
|
37
|
40
|
if token not in __sessions.keys():
|
38
|
41
|
raise ClientAuthenticationFailure("No session found for this token")
|
39
|
42
|
|
|
43
|
+
|
40
|
44
|
## @brief returns a session file path for a specific token
|
|
45
|
+# @param token str
|
|
46
|
+# @return str
|
41
|
47
|
def generate_file_path(token):
|
42
|
48
|
return os.path.abspath(os.path.join(Settings.sessions.directory, Settings.sessions.file_template) % token)
|
43
|
49
|
|
44
|
50
|
|
|
51
|
+##
|
|
52
|
+# @param filepath str
|
|
53
|
+# @return str|None : returns the token or None if no token was found
|
45
|
54
|
def get_token_from_filepath(filepath):
|
46
|
55
|
token_regex = re.compile(os.path.abspath(os.path.join(Settings.sessions.directory, Settings.sessions.file_template % '(?P<token>.*)')))
|
47
|
56
|
token_search_result = token_regex.match(filepath)
|
|
@@ -53,7 +62,7 @@ def get_token_from_filepath(filepath):
|
53
|
62
|
## @brief returns the session's last modification timestamp
|
54
|
63
|
# @param token str
|
55
|
64
|
# @return float
|
56
|
|
-# @raise ValueError if the given token doesn't match with an existing session
|
|
65
|
+# @throw ValueError if the given token doesn't match with an existing session
|
57
|
66
|
def get_session_last_modified(token):
|
58
|
67
|
if token in __sessions[token]:
|
59
|
68
|
return os.stat(__sessions[token]).st_mtime
|
|
@@ -138,17 +147,25 @@ def gc():
|
138
|
147
|
logger.debug("Expired session %s has been destroyed" % token)
|
139
|
148
|
|
140
|
149
|
|
|
150
|
+##
|
|
151
|
+# @param token str
|
|
152
|
+# @param key str
|
|
153
|
+# @param value
|
141
|
154
|
def set_session_value(token, key, value):
|
142
|
155
|
session = restore_session(token)
|
143
|
156
|
session[key] = value
|
144
|
157
|
save_session(token, session)
|
145
|
158
|
|
146
|
|
-
|
|
159
|
+##
|
|
160
|
+# @param token str
|
|
161
|
+# @param key str
|
147
|
162
|
def get_session_value(token, key):
|
148
|
163
|
session = restore_session(token)
|
149
|
164
|
return session[key]
|
150
|
165
|
|
151
|
|
-
|
|
166
|
+##
|
|
167
|
+# @param token str
|
|
168
|
+# @param key str
|
152
|
169
|
def del_session_value(token, key):
|
153
|
170
|
session = restore_session(token)
|
154
|
171
|
if key in session:
|