Show More
@@ -1,101 +1,101 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import collections |
|
22 | 22 | import logging |
|
23 | 23 | |
|
24 | 24 | from pylons import tmpl_context as c |
|
25 | 25 | from pyramid.view import view_config |
|
26 | 26 | from pyramid.httpexceptions import HTTPFound |
|
27 | 27 | |
|
28 | 28 | from rhodecode.translation import _ |
|
29 | 29 | |
|
30 | 30 | from rhodecode.admin.views.base import AdminSettingsView |
|
31 | 31 | from rhodecode.lib.auth import ( |
|
32 | 32 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) |
|
33 | 33 | from rhodecode.lib.utils2 import safe_int |
|
34 | 34 | from rhodecode.lib import system_info |
|
35 | 35 | from rhodecode.lib import user_sessions |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | from rhodecode.admin.navigation import navigation_list |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | log = logging.getLogger(__name__) |
|
42 | 42 | |
|
43 | 43 | |
|
44 | 44 | class AdminSessionSettingsView(AdminSettingsView): |
|
45 | 45 | |
|
46 | 46 | @LoginRequired() |
|
47 | 47 | @HasPermissionAllDecorator('hg.admin') |
|
48 | 48 | @view_config( |
|
49 | 49 | route_name='admin_settings_sessions', request_method='GET', |
|
50 | 50 | renderer='rhodecode:templates/admin/settings/settings.mako') |
|
51 | 51 | def settings_sessions(self): |
|
52 | 52 | c.active = 'sessions' |
|
53 | 53 | c.navlist = navigation_list(self.request) |
|
54 | 54 | |
|
55 | 55 | c.cleanup_older_days = 60 |
|
56 |
older_than_seconds = |
|
|
56 | older_than_seconds = 60 * 60 * 24 * c.cleanup_older_days | |
|
57 | 57 | |
|
58 | 58 | config = system_info.rhodecode_config().get_value()['value']['config'] |
|
59 | 59 | c.session_model = user_sessions.get_session_handler( |
|
60 | 60 | config.get('beaker.session.type', 'memory'))(config) |
|
61 | 61 | |
|
62 | 62 | c.session_conf = c.session_model.config |
|
63 | 63 | c.session_count = c.session_model.get_count() |
|
64 | 64 | c.session_expired_count = c.session_model.get_expired_count( |
|
65 | 65 | older_than_seconds) |
|
66 | 66 | |
|
67 | 67 | return {} |
|
68 | 68 | |
|
69 | 69 | @LoginRequired() |
|
70 | 70 | @CSRFRequired() |
|
71 | 71 | @HasPermissionAllDecorator('hg.admin') |
|
72 | 72 | @view_config( |
|
73 | 73 | route_name='admin_settings_sessions_cleanup', request_method='POST') |
|
74 | 74 | def settings_sessions_cleanup(self): |
|
75 | 75 | |
|
76 | 76 | expire_days = safe_int(self.request.params.get('expire_days')) |
|
77 | 77 | |
|
78 | 78 | if expire_days is None: |
|
79 | 79 | expire_days = 60 |
|
80 | 80 | |
|
81 |
older_than_seconds = |
|
|
81 | older_than_seconds = 60 * 60 * 24 * expire_days | |
|
82 | 82 | |
|
83 | 83 | config = system_info.rhodecode_config().get_value()['value']['config'] |
|
84 | 84 | session_model = user_sessions.get_session_handler( |
|
85 | 85 | config.get('beaker.session.type', 'memory'))(config) |
|
86 | 86 | |
|
87 | 87 | try: |
|
88 | 88 | session_model.clean_sessions( |
|
89 | 89 | older_than_seconds=older_than_seconds) |
|
90 | 90 | self.request.session.flash( |
|
91 | 91 | _('Cleaned up old sessions'), queue='success') |
|
92 | 92 | except user_sessions.CleanupCommand as msg: |
|
93 | 93 | self.request.session.flash(msg.message, queue='warning') |
|
94 | 94 | except Exception as e: |
|
95 | 95 | log.exception('Failed session cleanup') |
|
96 | 96 | self.request.session.flash( |
|
97 | 97 | _('Failed to cleanup up old sessions'), queue='error') |
|
98 | 98 | |
|
99 | 99 | redirect_to = self.request.resource_path( |
|
100 | 100 | self.context, route_name='admin_settings_sessions') |
|
101 | 101 | return HTTPFound(redirect_to) |
General Comments 0
You need to be logged in to leave comments.
Login now