[PATCH][Wok 0/2] Kimchi is logging out due to session timeout even when user is typing or using the webpage

Ramon Medeiros (2): Move constant from auth.py to template.py Issue #133: Kimchi is logging out due to session timeout even when user is typing or using the webpage src/wok/auth.py | 9 ++++----- src/wok/template.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) -- 2.5.5

As auth importing template, this was causing an error. To avoid it, put REFRESH constant at template, and as auth is importing it, use by reference. Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- src/wok/auth.py | 9 ++++----- src/wok/template.py | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wok/auth.py b/src/wok/auth.py index 0355e86..421f8f3 100644 --- a/src/wok/auth.py +++ b/src/wok/auth.py @@ -40,7 +40,6 @@ from wok.utils import get_all_tabs, run_command USER_NAME = 'username' USER_GROUPS = 'groups' USER_ROLES = 'roles' -REFRESH = 'robot-refresh' tabs = get_all_tabs() @@ -263,13 +262,13 @@ def check_auth_session(): debug("Session authenticated for user %s" % session) wokRobot = cherrypy.request.headers.get('Wok-Robot') if wokRobot == "wok-robot": - if (time.time() - cherrypy.session[REFRESH] > + if (time.time() - cherrypy.session[template.REFRESH] > int(config.get('server', 'session_timeout')) * 60): cherrypy.session[USER_NAME] = None cherrypy.lib.sessions.expire() raise cherrypy.HTTPError(401, "sessionTimeout") else: - cherrypy.session[REFRESH] = time.time() + cherrypy.session[template.REFRESH] = time.time() return True debug("Session not found") @@ -316,7 +315,7 @@ def login(username, password, **kwargs): cherrypy.session[USER_NAME] = username cherrypy.session[USER_GROUPS] = user.get_groups() cherrypy.session[USER_ROLES] = user.get_roles() - cherrypy.session[REFRESH] = time.time() + cherrypy.session[template.REFRESH] = time.time() cherrypy.session.release_lock() return user.get_user() @@ -324,7 +323,7 @@ def login(username, password, **kwargs): def logout(): cherrypy.session.acquire_lock() cherrypy.session[USER_NAME] = None - cherrypy.session[REFRESH] = 0 + cherrypy.session[template.REFRESH] = 0 cherrypy.session.release_lock() cherrypy.lib.sessions.close() diff --git a/src/wok/template.py b/src/wok/template.py index 2162c8a..68243d9 100644 --- a/src/wok/template.py +++ b/src/wok/template.py @@ -28,6 +28,7 @@ from glob import iglob from wok.config import paths +REFRESH = 'robot-refresh' def get_lang(): cookie = cherrypy.request.cookie -- 2.5.5

Adds a header "Session-Expires-On" returning the remaining time to expire the session. Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- src/wok/template.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/wok/template.py b/src/wok/template.py index 68243d9..43a34db 100644 --- a/src/wok/template.py +++ b/src/wok/template.py @@ -22,14 +22,18 @@ import cherrypy import errno import json +import time from Cheetah.Template import Template from glob import iglob +from wok import config as config from wok.config import paths +EXPIRES_ON = 'Session-Expires-On' REFRESH = 'robot-refresh' + def get_lang(): cookie = cherrypy.request.cookie if "wokLang" in cookie.keys(): @@ -110,6 +114,17 @@ def render_cheetah_file(resource, data): def render(resource, data): + # get timeout and last refresh + s_timeout = float(config.config.get("server", "session_timeout")) + cherrypy.session.acquire_lock() + last_req = cherrypy.session.get(REFRESH) + cherrypy.session.release_lock() + + # last_request is present: calculate remaining time + if last_req is not None: + session_expires = (float(last_req) + (s_timeout * 60)) - time.time() + cherrypy.response.headers[EXPIRES_ON] = session_expires + if can_accept('application/json'): cherrypy.response.headers['Content-Type'] = \ 'application/json;charset=utf-8' -- 2.5.5

On Jul 20 02:24PM, Ramon Medeiros wrote:
Adds a header "Session-Expires-On" returning the remaining time to expire the session.
Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- src/wok/template.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/src/wok/template.py b/src/wok/template.py index 68243d9..43a34db 100644 --- a/src/wok/template.py +++ b/src/wok/template.py @@ -22,14 +22,18 @@ import cherrypy import errno import json +import time from Cheetah.Template import Template from glob import iglob
+from wok import config as config from wok.config import paths
+EXPIRES_ON = 'Session-Expires-On' REFRESH = 'robot-refresh'
+ def get_lang(): cookie = cherrypy.request.cookie if "wokLang" in cookie.keys(): @@ -110,6 +114,17 @@ def render_cheetah_file(resource, data):
def render(resource, data): + # get timeout and last refresh + s_timeout = float(config.config.get("server", "session_timeout")) + cherrypy.session.acquire_lock() + last_req = cherrypy.session.get(REFRESH) + cherrypy.session.release_lock() + + # last_request is present: calculate remaining time + if last_req is not None: + session_expires = (float(last_req) + (s_timeout * 60)) - time.time() + cherrypy.response.headers[EXPIRES_ON] = session_expires
As commented by Aline on RFC, was requested on https://github.com/kimchi-project/wok/issues/133#issuecomment-232752799 the time the session will expires since last request, so I guess the correct formula is: session_expires = (float(last_req) + (s_timeout * 60)) Doesn't?
+ if can_accept('application/json'): cherrypy.response.headers['Content-Type'] = \ 'application/json;charset=utf-8' -- 2.5.5
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
-- Paulo Ricardo Paz Vital Linux Technology Center, IBM Systems http://www.ibm.com/linux/ltc/

On 07/20/2016 03:06 PM, Paulo Ricardo Paz Vital wrote:
Adds a header "Session-Expires-On" returning the remaining time to expire the session.
Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- src/wok/template.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/src/wok/template.py b/src/wok/template.py index 68243d9..43a34db 100644 --- a/src/wok/template.py +++ b/src/wok/template.py @@ -22,14 +22,18 @@ import cherrypy import errno import json +import time from Cheetah.Template import Template from glob import iglob
+from wok import config as config from wok.config import paths
+EXPIRES_ON = 'Session-Expires-On' REFRESH = 'robot-refresh'
+ def get_lang(): cookie = cherrypy.request.cookie if "wokLang" in cookie.keys(): @@ -110,6 +114,17 @@ def render_cheetah_file(resource, data):
def render(resource, data): + # get timeout and last refresh + s_timeout = float(config.config.get("server", "session_timeout")) + cherrypy.session.acquire_lock() + last_req = cherrypy.session.get(REFRESH) + cherrypy.session.release_lock() + + # last_request is present: calculate remaining time + if last_req is not None: + session_expires = (float(last_req) + (s_timeout * 60)) - time.time() + cherrypy.response.headers[EXPIRES_ON] = session_expires As commented by Aline on RFC, was requested on https://github.com/kimchi-project/wok/issues/133#issuecomment-232752799
On Jul 20 02:24PM, Ramon Medeiros wrote: the time the session will expires since last request, so I guess the correct formula is:
session_expires = (float(last_req) + (s_timeout * 60))
Doesn't? just check with Peter Pennings,
he says that is easier to deal just with the remaining time. He is also copied here
+ if can_accept('application/json'): cherrypy.response.headers['Content-Type'] = \ 'application/json;charset=utf-8' -- 2.5.5
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
-- Ramon Nunes Medeiros Kimchi Developer Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com

On Jul 20 04:38PM, Ramon Medeiros wrote:
On 07/20/2016 03:06 PM, Paulo Ricardo Paz Vital wrote:
Adds a header "Session-Expires-On" returning the remaining time to expire the session.
Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- src/wok/template.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/src/wok/template.py b/src/wok/template.py index 68243d9..43a34db 100644 --- a/src/wok/template.py +++ b/src/wok/template.py @@ -22,14 +22,18 @@ import cherrypy import errno import json +import time from Cheetah.Template import Template from glob import iglob
+from wok import config as config from wok.config import paths
+EXPIRES_ON = 'Session-Expires-On' REFRESH = 'robot-refresh'
+ def get_lang(): cookie = cherrypy.request.cookie if "wokLang" in cookie.keys(): @@ -110,6 +114,17 @@ def render_cheetah_file(resource, data):
def render(resource, data): + # get timeout and last refresh + s_timeout = float(config.config.get("server", "session_timeout")) + cherrypy.session.acquire_lock() + last_req = cherrypy.session.get(REFRESH) + cherrypy.session.release_lock() + + # last_request is present: calculate remaining time + if last_req is not None: + session_expires = (float(last_req) + (s_timeout * 60)) - time.time() + cherrypy.response.headers[EXPIRES_ON] = session_expires As commented by Aline on RFC, was requested on https://github.com/kimchi-project/wok/issues/133#issuecomment-232752799
On Jul 20 02:24PM, Ramon Medeiros wrote: the time the session will expires since last request, so I guess the correct formula is:
session_expires = (float(last_req) + (s_timeout * 60))
Doesn't? just check with Peter Pennings,
he says that is easier to deal just with the remaining time.
OK! So, I guess it's reviewed-by :-)
He is also copied here
+ if can_accept('application/json'): cherrypy.response.headers['Content-Type'] = \ 'application/json;charset=utf-8' -- 2.5.5
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
--
Ramon Nunes Medeiros Kimchi Developer Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
-- Paulo Ricardo Paz Vital Linux Technology Center, IBM Systems http://www.ibm.com/linux/ltc/

Applied. Thanks. Regards, Aline Manera
participants (3)
-
Aline Manera
-
Paulo Ricardo Paz Vital
-
Ramon Medeiros