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