Show More
@@ -1,48 +1,54 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 | ||
25 | from pyramid.view import view_config |
|
25 | from pyramid.view import view_config | |
26 |
|
26 | |||
27 | from rhodecode.apps._base import BaseAppView |
|
27 | from rhodecode.apps._base import BaseAppView | |
28 | from rhodecode.apps.admin.navigation import navigation_list |
|
28 | from rhodecode.apps.admin.navigation import navigation_list | |
29 | from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator) |
|
29 | from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator) | |
30 | from rhodecode.lib.utils import read_opensource_licenses |
|
30 | from rhodecode.lib.utils import read_opensource_licenses | |
31 |
|
31 | |||
32 | log = logging.getLogger(__name__) |
|
32 | log = logging.getLogger(__name__) | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | class OpenSourceLicensesAdminSettingsView(BaseAppView): |
|
35 | class OpenSourceLicensesAdminSettingsView(BaseAppView): | |
36 |
|
36 | |||
|
37 | def load_default_context(self): | |||
|
38 | c = self._get_local_tmpl_context() | |||
|
39 | self._register_global_c(c) | |||
|
40 | return c | |||
|
41 | ||||
37 | @LoginRequired() |
|
42 | @LoginRequired() | |
38 | @HasPermissionAllDecorator('hg.admin') |
|
43 | @HasPermissionAllDecorator('hg.admin') | |
39 | @view_config( |
|
44 | @view_config( | |
40 | route_name='admin_settings_open_source', request_method='GET', |
|
45 | route_name='admin_settings_open_source', request_method='GET', | |
41 | renderer='rhodecode:templates/admin/settings/settings.mako') |
|
46 | renderer='rhodecode:templates/admin/settings/settings.mako') | |
42 | def open_source_licenses(self): |
|
47 | def open_source_licenses(self): | |
|
48 | c = self.load_default_context() | |||
43 | c.active = 'open_source' |
|
49 | c.active = 'open_source' | |
44 | c.navlist = navigation_list(self.request) |
|
50 | c.navlist = navigation_list(self.request) | |
45 | c.opensource_licenses = collections.OrderedDict( |
|
51 | c.opensource_licenses = collections.OrderedDict( | |
46 | sorted(read_opensource_licenses().items(), key=lambda t: t[0])) |
|
52 | sorted(read_opensource_licenses().items(), key=lambda t: t[0])) | |
47 |
|
53 | |||
48 | return {} |
|
54 | return self._get_template_context(c) |
@@ -1,96 +1,102 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 logging |
|
21 | import logging | |
22 |
|
22 | |||
23 | from pylons import tmpl_context as c |
|
|||
24 | from pyramid.view import view_config |
|
23 | from pyramid.view import view_config | |
25 | from pyramid.httpexceptions import HTTPFound |
|
24 | from pyramid.httpexceptions import HTTPFound | |
26 |
|
25 | |||
27 | from rhodecode.apps._base import BaseAppView |
|
26 | from rhodecode.apps._base import BaseAppView | |
28 | from rhodecode.apps.admin.navigation import navigation_list |
|
27 | from rhodecode.apps.admin.navigation import navigation_list | |
29 | from rhodecode.lib.auth import ( |
|
28 | from rhodecode.lib.auth import ( | |
30 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) |
|
29 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) | |
31 | from rhodecode.lib.utils2 import safe_int |
|
30 | from rhodecode.lib.utils2 import safe_int | |
32 | from rhodecode.lib import system_info |
|
31 | from rhodecode.lib import system_info | |
33 | from rhodecode.lib import user_sessions |
|
32 | from rhodecode.lib import user_sessions | |
34 |
|
33 | |||
35 |
|
34 | |||
36 | log = logging.getLogger(__name__) |
|
35 | log = logging.getLogger(__name__) | |
37 |
|
36 | |||
38 |
|
37 | |||
39 | class AdminSessionSettingsView(BaseAppView): |
|
38 | class AdminSessionSettingsView(BaseAppView): | |
|
39 | def load_default_context(self): | |||
|
40 | c = self._get_local_tmpl_context() | |||
|
41 | ||||
|
42 | self._register_global_c(c) | |||
|
43 | return c | |||
40 |
|
44 | |||
41 | @LoginRequired() |
|
45 | @LoginRequired() | |
42 | @HasPermissionAllDecorator('hg.admin') |
|
46 | @HasPermissionAllDecorator('hg.admin') | |
43 | @view_config( |
|
47 | @view_config( | |
44 | route_name='admin_settings_sessions', request_method='GET', |
|
48 | route_name='admin_settings_sessions', request_method='GET', | |
45 | renderer='rhodecode:templates/admin/settings/settings.mako') |
|
49 | renderer='rhodecode:templates/admin/settings/settings.mako') | |
46 | def settings_sessions(self): |
|
50 | def settings_sessions(self): | |
|
51 | c = self.load_default_context() | |||
|
52 | ||||
47 | c.active = 'sessions' |
|
53 | c.active = 'sessions' | |
48 | c.navlist = navigation_list(self.request) |
|
54 | c.navlist = navigation_list(self.request) | |
49 |
|
55 | |||
50 | c.cleanup_older_days = 60 |
|
56 | c.cleanup_older_days = 60 | |
51 | older_than_seconds = 60 * 60 * 24 * c.cleanup_older_days |
|
57 | older_than_seconds = 60 * 60 * 24 * c.cleanup_older_days | |
52 |
|
58 | |||
53 | config = system_info.rhodecode_config().get_value()['value']['config'] |
|
59 | config = system_info.rhodecode_config().get_value()['value']['config'] | |
54 | c.session_model = user_sessions.get_session_handler( |
|
60 | c.session_model = user_sessions.get_session_handler( | |
55 | config.get('beaker.session.type', 'memory'))(config) |
|
61 | config.get('beaker.session.type', 'memory'))(config) | |
56 |
|
62 | |||
57 | c.session_conf = c.session_model.config |
|
63 | c.session_conf = c.session_model.config | |
58 | c.session_count = c.session_model.get_count() |
|
64 | c.session_count = c.session_model.get_count() | |
59 | c.session_expired_count = c.session_model.get_expired_count( |
|
65 | c.session_expired_count = c.session_model.get_expired_count( | |
60 | older_than_seconds) |
|
66 | older_than_seconds) | |
61 |
|
67 | |||
62 | return {} |
|
68 | return self._get_template_context(c) | |
63 |
|
69 | |||
64 | @LoginRequired() |
|
70 | @LoginRequired() | |
65 | @CSRFRequired() |
|
71 | @CSRFRequired() | |
66 | @HasPermissionAllDecorator('hg.admin') |
|
72 | @HasPermissionAllDecorator('hg.admin') | |
67 | @view_config( |
|
73 | @view_config( | |
68 | route_name='admin_settings_sessions_cleanup', request_method='POST') |
|
74 | route_name='admin_settings_sessions_cleanup', request_method='POST') | |
69 | def settings_sessions_cleanup(self): |
|
75 | def settings_sessions_cleanup(self): | |
70 | _ = self.request.translate |
|
76 | _ = self.request.translate | |
71 | expire_days = safe_int(self.request.params.get('expire_days')) |
|
77 | expire_days = safe_int(self.request.params.get('expire_days')) | |
72 |
|
78 | |||
73 | if expire_days is None: |
|
79 | if expire_days is None: | |
74 | expire_days = 60 |
|
80 | expire_days = 60 | |
75 |
|
81 | |||
76 | older_than_seconds = 60 * 60 * 24 * expire_days |
|
82 | older_than_seconds = 60 * 60 * 24 * expire_days | |
77 |
|
83 | |||
78 | config = system_info.rhodecode_config().get_value()['value']['config'] |
|
84 | config = system_info.rhodecode_config().get_value()['value']['config'] | |
79 | session_model = user_sessions.get_session_handler( |
|
85 | session_model = user_sessions.get_session_handler( | |
80 | config.get('beaker.session.type', 'memory'))(config) |
|
86 | config.get('beaker.session.type', 'memory'))(config) | |
81 |
|
87 | |||
82 | try: |
|
88 | try: | |
83 | session_model.clean_sessions( |
|
89 | session_model.clean_sessions( | |
84 | older_than_seconds=older_than_seconds) |
|
90 | older_than_seconds=older_than_seconds) | |
85 | self.request.session.flash( |
|
91 | self.request.session.flash( | |
86 | _('Cleaned up old sessions'), queue='success') |
|
92 | _('Cleaned up old sessions'), queue='success') | |
87 | except user_sessions.CleanupCommand as msg: |
|
93 | except user_sessions.CleanupCommand as msg: | |
88 | self.request.session.flash(msg.message, queue='warning') |
|
94 | self.request.session.flash(msg.message, queue='warning') | |
89 | except Exception as e: |
|
95 | except Exception as e: | |
90 | log.exception('Failed session cleanup') |
|
96 | log.exception('Failed session cleanup') | |
91 | self.request.session.flash( |
|
97 | self.request.session.flash( | |
92 | _('Failed to cleanup up old sessions'), queue='error') |
|
98 | _('Failed to cleanup up old sessions'), queue='error') | |
93 |
|
99 | |||
94 | redirect_to = self.request.resource_path( |
|
100 | redirect_to = self.request.resource_path( | |
95 | self.context, route_name='admin_settings_sessions') |
|
101 | self.context, route_name='admin_settings_sessions') | |
96 | return HTTPFound(redirect_to) |
|
102 | return HTTPFound(redirect_to) |
@@ -1,204 +1,209 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 logging |
|
21 | import logging | |
22 | import urllib2 |
|
22 | import urllib2 | |
23 | import packaging.version |
|
23 | import packaging.version | |
24 |
|
24 | |||
25 | from pylons import tmpl_context as c |
|
|||
26 | from pyramid.view import view_config |
|
25 | from pyramid.view import view_config | |
27 |
|
26 | |||
28 | import rhodecode |
|
27 | import rhodecode | |
29 | from rhodecode.apps._base import BaseAppView |
|
28 | from rhodecode.apps._base import BaseAppView | |
30 | from rhodecode.apps.admin.navigation import navigation_list |
|
29 | from rhodecode.apps.admin.navigation import navigation_list | |
31 | from rhodecode.lib import helpers as h |
|
30 | from rhodecode.lib import helpers as h | |
32 | from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator) |
|
31 | from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator) | |
33 | from rhodecode.lib.utils2 import str2bool |
|
32 | from rhodecode.lib.utils2 import str2bool | |
34 | from rhodecode.lib import system_info |
|
33 | from rhodecode.lib import system_info | |
35 | from rhodecode.lib.ext_json import json |
|
34 | from rhodecode.lib.ext_json import json | |
36 | from rhodecode.model.settings import SettingsModel |
|
35 | from rhodecode.model.settings import SettingsModel | |
37 |
|
36 | |||
38 | log = logging.getLogger(__name__) |
|
37 | log = logging.getLogger(__name__) | |
39 |
|
38 | |||
40 |
|
39 | |||
41 | class AdminSystemInfoSettingsView(BaseAppView): |
|
40 | class AdminSystemInfoSettingsView(BaseAppView): | |
|
41 | def load_default_context(self): | |||
|
42 | c = self._get_local_tmpl_context() | |||
|
43 | self._register_global_c(c) | |||
|
44 | return c | |||
42 |
|
45 | |||
43 | @staticmethod |
|
46 | @staticmethod | |
44 | def get_update_data(update_url): |
|
47 | def get_update_data(update_url): | |
45 | """Return the JSON update data.""" |
|
48 | """Return the JSON update data.""" | |
46 | ver = rhodecode.__version__ |
|
49 | ver = rhodecode.__version__ | |
47 | log.debug('Checking for upgrade on `%s` server', update_url) |
|
50 | log.debug('Checking for upgrade on `%s` server', update_url) | |
48 | opener = urllib2.build_opener() |
|
51 | opener = urllib2.build_opener() | |
49 | opener.addheaders = [('User-agent', 'RhodeCode-SCM/%s' % ver)] |
|
52 | opener.addheaders = [('User-agent', 'RhodeCode-SCM/%s' % ver)] | |
50 | response = opener.open(update_url) |
|
53 | response = opener.open(update_url) | |
51 | response_data = response.read() |
|
54 | response_data = response.read() | |
52 | data = json.loads(response_data) |
|
55 | data = json.loads(response_data) | |
53 |
|
56 | |||
54 | return data |
|
57 | return data | |
55 |
|
58 | |||
56 | def get_update_url(self): |
|
59 | def get_update_url(self): | |
57 | settings = SettingsModel().get_all_settings() |
|
60 | settings = SettingsModel().get_all_settings() | |
58 | return settings.get('rhodecode_update_url') |
|
61 | return settings.get('rhodecode_update_url') | |
59 |
|
62 | |||
60 | @LoginRequired() |
|
63 | @LoginRequired() | |
61 | @HasPermissionAllDecorator('hg.admin') |
|
64 | @HasPermissionAllDecorator('hg.admin') | |
62 | @view_config( |
|
65 | @view_config( | |
63 | route_name='admin_settings_system', request_method='GET', |
|
66 | route_name='admin_settings_system', request_method='GET', | |
64 | renderer='rhodecode:templates/admin/settings/settings.mako') |
|
67 | renderer='rhodecode:templates/admin/settings/settings.mako') | |
65 | def settings_system_info(self): |
|
68 | def settings_system_info(self): | |
66 | _ = self.request.translate |
|
69 | _ = self.request.translate | |
|
70 | c = self.load_default_context() | |||
67 |
|
71 | |||
68 | c.active = 'system' |
|
72 | c.active = 'system' | |
69 | c.navlist = navigation_list(self.request) |
|
73 | c.navlist = navigation_list(self.request) | |
70 |
|
74 | |||
71 | # TODO(marcink), figure out how to allow only selected users to do this |
|
75 | # TODO(marcink), figure out how to allow only selected users to do this | |
72 | c.allowed_to_snapshot = self._rhodecode_user.admin |
|
76 | c.allowed_to_snapshot = self._rhodecode_user.admin | |
73 |
|
77 | |||
74 | snapshot = str2bool(self.request.params.get('snapshot')) |
|
78 | snapshot = str2bool(self.request.params.get('snapshot')) | |
75 |
|
79 | |||
76 | c.rhodecode_update_url = self.get_update_url() |
|
80 | c.rhodecode_update_url = self.get_update_url() | |
77 | server_info = system_info.get_system_info(self.request.environ) |
|
81 | server_info = system_info.get_system_info(self.request.environ) | |
78 |
|
82 | |||
79 | for key, val in server_info.items(): |
|
83 | for key, val in server_info.items(): | |
80 | setattr(c, key, val) |
|
84 | setattr(c, key, val) | |
81 |
|
85 | |||
82 | def val(name, subkey='human_value'): |
|
86 | def val(name, subkey='human_value'): | |
83 | return server_info[name][subkey] |
|
87 | return server_info[name][subkey] | |
84 |
|
88 | |||
85 | def state(name): |
|
89 | def state(name): | |
86 | return server_info[name]['state'] |
|
90 | return server_info[name]['state'] | |
87 |
|
91 | |||
88 | def val2(name): |
|
92 | def val2(name): | |
89 | val = server_info[name]['human_value'] |
|
93 | val = server_info[name]['human_value'] | |
90 | state = server_info[name]['state'] |
|
94 | state = server_info[name]['state'] | |
91 | return val, state |
|
95 | return val, state | |
92 |
|
96 | |||
93 | update_info_msg = _('Note: please make sure this server can ' |
|
97 | update_info_msg = _('Note: please make sure this server can ' | |
94 | 'access `${url}` for the update link to work', |
|
98 | 'access `${url}` for the update link to work', | |
95 | mapping=dict(url=c.rhodecode_update_url)) |
|
99 | mapping=dict(url=c.rhodecode_update_url)) | |
96 | c.data_items = [ |
|
100 | c.data_items = [ | |
97 | # update info |
|
101 | # update info | |
98 | (_('Update info'), h.literal( |
|
102 | (_('Update info'), h.literal( | |
99 | '<span class="link" id="check_for_update" >%s.</span>' % ( |
|
103 | '<span class="link" id="check_for_update" >%s.</span>' % ( | |
100 | _('Check for updates')) + |
|
104 | _('Check for updates')) + | |
101 | '<br/> <span >%s.</span>' % (update_info_msg) |
|
105 | '<br/> <span >%s.</span>' % (update_info_msg) | |
102 | ), ''), |
|
106 | ), ''), | |
103 |
|
107 | |||
104 | # RhodeCode specific |
|
108 | # RhodeCode specific | |
105 | (_('RhodeCode Version'), val('rhodecode_app')['text'], state('rhodecode_app')), |
|
109 | (_('RhodeCode Version'), val('rhodecode_app')['text'], state('rhodecode_app')), | |
106 | (_('RhodeCode Server IP'), val('server')['server_ip'], state('server')), |
|
110 | (_('RhodeCode Server IP'), val('server')['server_ip'], state('server')), | |
107 | (_('RhodeCode Server ID'), val('server')['server_id'], state('server')), |
|
111 | (_('RhodeCode Server ID'), val('server')['server_id'], state('server')), | |
108 | (_('RhodeCode Configuration'), val('rhodecode_config')['path'], state('rhodecode_config')), |
|
112 | (_('RhodeCode Configuration'), val('rhodecode_config')['path'], state('rhodecode_config')), | |
109 | (_('RhodeCode Certificate'), val('rhodecode_config')['cert_path'], state('rhodecode_config')), |
|
113 | (_('RhodeCode Certificate'), val('rhodecode_config')['cert_path'], state('rhodecode_config')), | |
110 | (_('Workers'), val('rhodecode_config')['config']['server:main'].get('workers', '?'), state('rhodecode_config')), |
|
114 | (_('Workers'), val('rhodecode_config')['config']['server:main'].get('workers', '?'), state('rhodecode_config')), | |
111 | (_('Worker Type'), val('rhodecode_config')['config']['server:main'].get('worker_class', 'sync'), state('rhodecode_config')), |
|
115 | (_('Worker Type'), val('rhodecode_config')['config']['server:main'].get('worker_class', 'sync'), state('rhodecode_config')), | |
112 | ('', '', ''), # spacer |
|
116 | ('', '', ''), # spacer | |
113 |
|
117 | |||
114 | # Database |
|
118 | # Database | |
115 | (_('Database'), val('database')['url'], state('database')), |
|
119 | (_('Database'), val('database')['url'], state('database')), | |
116 | (_('Database version'), val('database')['version'], state('database')), |
|
120 | (_('Database version'), val('database')['version'], state('database')), | |
117 | ('', '', ''), # spacer |
|
121 | ('', '', ''), # spacer | |
118 |
|
122 | |||
119 | # Platform/Python |
|
123 | # Platform/Python | |
120 | (_('Platform'), val('platform')['name'], state('platform')), |
|
124 | (_('Platform'), val('platform')['name'], state('platform')), | |
121 | (_('Platform UUID'), val('platform')['uuid'], state('platform')), |
|
125 | (_('Platform UUID'), val('platform')['uuid'], state('platform')), | |
122 | (_('Python version'), val('python')['version'], state('python')), |
|
126 | (_('Python version'), val('python')['version'], state('python')), | |
123 | (_('Python path'), val('python')['executable'], state('python')), |
|
127 | (_('Python path'), val('python')['executable'], state('python')), | |
124 | ('', '', ''), # spacer |
|
128 | ('', '', ''), # spacer | |
125 |
|
129 | |||
126 | # Systems stats |
|
130 | # Systems stats | |
127 | (_('CPU'), val('cpu')['text'], state('cpu')), |
|
131 | (_('CPU'), val('cpu')['text'], state('cpu')), | |
128 | (_('Load'), val('load')['text'], state('load')), |
|
132 | (_('Load'), val('load')['text'], state('load')), | |
129 | (_('Memory'), val('memory')['text'], state('memory')), |
|
133 | (_('Memory'), val('memory')['text'], state('memory')), | |
130 | (_('Uptime'), val('uptime')['text'], state('uptime')), |
|
134 | (_('Uptime'), val('uptime')['text'], state('uptime')), | |
131 | ('', '', ''), # spacer |
|
135 | ('', '', ''), # spacer | |
132 |
|
136 | |||
133 | # Repo storage |
|
137 | # Repo storage | |
134 | (_('Storage location'), val('storage')['path'], state('storage')), |
|
138 | (_('Storage location'), val('storage')['path'], state('storage')), | |
135 | (_('Storage info'), val('storage')['text'], state('storage')), |
|
139 | (_('Storage info'), val('storage')['text'], state('storage')), | |
136 | (_('Storage inodes'), val('storage_inodes')['text'], state('storage_inodes')), |
|
140 | (_('Storage inodes'), val('storage_inodes')['text'], state('storage_inodes')), | |
137 |
|
141 | |||
138 | (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')), |
|
142 | (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')), | |
139 | (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')), |
|
143 | (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')), | |
140 |
|
144 | |||
141 | (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')), |
|
145 | (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')), | |
142 | (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')), |
|
146 | (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')), | |
143 |
|
147 | |||
144 | (_('Temp storage location'), val('storage_temp')['path'], state('storage_temp')), |
|
148 | (_('Temp storage location'), val('storage_temp')['path'], state('storage_temp')), | |
145 | (_('Temp storage info'), val('storage_temp')['text'], state('storage_temp')), |
|
149 | (_('Temp storage info'), val('storage_temp')['text'], state('storage_temp')), | |
146 |
|
150 | |||
147 | (_('Search info'), val('search')['text'], state('search')), |
|
151 | (_('Search info'), val('search')['text'], state('search')), | |
148 | (_('Search location'), val('search')['location'], state('search')), |
|
152 | (_('Search location'), val('search')['location'], state('search')), | |
149 | ('', '', ''), # spacer |
|
153 | ('', '', ''), # spacer | |
150 |
|
154 | |||
151 | # VCS specific |
|
155 | # VCS specific | |
152 | (_('VCS Backends'), val('vcs_backends'), state('vcs_backends')), |
|
156 | (_('VCS Backends'), val('vcs_backends'), state('vcs_backends')), | |
153 | (_('VCS Server'), val('vcs_server')['text'], state('vcs_server')), |
|
157 | (_('VCS Server'), val('vcs_server')['text'], state('vcs_server')), | |
154 | (_('GIT'), val('git'), state('git')), |
|
158 | (_('GIT'), val('git'), state('git')), | |
155 | (_('HG'), val('hg'), state('hg')), |
|
159 | (_('HG'), val('hg'), state('hg')), | |
156 | (_('SVN'), val('svn'), state('svn')), |
|
160 | (_('SVN'), val('svn'), state('svn')), | |
157 |
|
161 | |||
158 | ] |
|
162 | ] | |
159 |
|
163 | |||
160 | if snapshot: |
|
164 | if snapshot: | |
161 | if c.allowed_to_snapshot: |
|
165 | if c.allowed_to_snapshot: | |
162 | c.data_items.pop(0) # remove server info |
|
166 | c.data_items.pop(0) # remove server info | |
163 | self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako' |
|
167 | self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako' | |
164 | else: |
|
168 | else: | |
165 | self.request.session.flash( |
|
169 | self.request.session.flash( | |
166 | 'You are not allowed to do this', queue='warning') |
|
170 | 'You are not allowed to do this', queue='warning') | |
167 | return {} |
|
171 | return self._get_template_context(c) | |
168 |
|
172 | |||
169 | @LoginRequired() |
|
173 | @LoginRequired() | |
170 | @HasPermissionAllDecorator('hg.admin') |
|
174 | @HasPermissionAllDecorator('hg.admin') | |
171 | @view_config( |
|
175 | @view_config( | |
172 | route_name='admin_settings_system_update', request_method='GET', |
|
176 | route_name='admin_settings_system_update', request_method='GET', | |
173 | renderer='rhodecode:templates/admin/settings/settings_system_update.mako') |
|
177 | renderer='rhodecode:templates/admin/settings/settings_system_update.mako') | |
174 | def settings_system_info_check_update(self): |
|
178 | def settings_system_info_check_update(self): | |
175 | _ = self.request.translate |
|
179 | _ = self.request.translate | |
|
180 | c = self.load_default_context() | |||
176 |
|
181 | |||
177 | update_url = self.get_update_url() |
|
182 | update_url = self.get_update_url() | |
178 |
|
183 | |||
179 | _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">{}</div>'.format(s) |
|
184 | _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">{}</div>'.format(s) | |
180 | try: |
|
185 | try: | |
181 | data = self.get_update_data(update_url) |
|
186 | data = self.get_update_data(update_url) | |
182 | except urllib2.URLError as e: |
|
187 | except urllib2.URLError as e: | |
183 | log.exception("Exception contacting upgrade server") |
|
188 | log.exception("Exception contacting upgrade server") | |
184 | self.request.override_renderer = 'string' |
|
189 | self.request.override_renderer = 'string' | |
185 | return _err('Failed to contact upgrade server: %r' % e) |
|
190 | return _err('Failed to contact upgrade server: %r' % e) | |
186 | except ValueError as e: |
|
191 | except ValueError as e: | |
187 | log.exception("Bad data sent from update server") |
|
192 | log.exception("Bad data sent from update server") | |
188 | self.request.override_renderer = 'string' |
|
193 | self.request.override_renderer = 'string' | |
189 | return _err('Bad data sent from update server') |
|
194 | return _err('Bad data sent from update server') | |
190 |
|
195 | |||
191 | latest = data['versions'][0] |
|
196 | latest = data['versions'][0] | |
192 |
|
197 | |||
193 | c.update_url = update_url |
|
198 | c.update_url = update_url | |
194 | c.latest_data = latest |
|
199 | c.latest_data = latest | |
195 | c.latest_ver = latest['version'] |
|
200 | c.latest_ver = latest['version'] | |
196 | c.cur_ver = rhodecode.__version__ |
|
201 | c.cur_ver = rhodecode.__version__ | |
197 | c.should_upgrade = False |
|
202 | c.should_upgrade = False | |
198 |
|
203 | |||
199 | if (packaging.version.Version(c.latest_ver) > |
|
204 | if (packaging.version.Version(c.latest_ver) > | |
200 | packaging.version.Version(c.cur_ver)): |
|
205 | packaging.version.Version(c.cur_ver)): | |
201 | c.should_upgrade = True |
|
206 | c.should_upgrade = True | |
202 | c.important_notices = latest['general'] |
|
207 | c.important_notices = latest['general'] | |
203 |
|
208 | |||
204 | return {} |
|
209 | return self._get_template_context(c) |
@@ -1,178 +1,175 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-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 | """ |
|
21 | """ | |
22 | Channel Stream controller for rhodecode |
|
22 | Channel Stream controller for rhodecode | |
23 |
|
23 | |||
24 | :created_on: Oct 10, 2015 |
|
24 | :created_on: Oct 10, 2015 | |
25 | :author: marcinl |
|
25 | :author: marcinl | |
26 | :copyright: (c) 2013-2015 RhodeCode GmbH. |
|
26 | :copyright: (c) 2013-2015 RhodeCode GmbH. | |
27 | :license: Commercial License, see LICENSE for more details. |
|
27 | :license: Commercial License, see LICENSE for more details. | |
28 | """ |
|
28 | """ | |
29 |
|
29 | |||
30 | import logging |
|
30 | import logging | |
31 | import uuid |
|
31 | import uuid | |
32 |
|
32 | |||
33 | from pylons import tmpl_context as c |
|
|||
34 | from pyramid.settings import asbool |
|
|||
35 | from pyramid.view import view_config |
|
33 | from pyramid.view import view_config | |
36 | from webob.exc import HTTPBadRequest, HTTPForbidden, HTTPBadGateway |
|
34 | from webob.exc import HTTPBadRequest, HTTPForbidden, HTTPBadGateway | |
37 |
|
35 | |||
38 | from rhodecode.lib.channelstream import ( |
|
36 | from rhodecode.lib.channelstream import ( | |
39 | channelstream_request, |
|
37 | channelstream_request, | |
40 | ChannelstreamConnectionException, |
|
38 | ChannelstreamConnectionException, | |
41 | ChannelstreamPermissionException, |
|
39 | ChannelstreamPermissionException, | |
42 | check_channel_permissions, |
|
40 | check_channel_permissions, | |
43 | get_connection_validators, |
|
41 | get_connection_validators, | |
44 | get_user_data, |
|
42 | get_user_data, | |
45 | parse_channels_info, |
|
43 | parse_channels_info, | |
46 | update_history_from_logs, |
|
44 | update_history_from_logs, | |
47 | STATE_PUBLIC_KEYS) |
|
45 | STATE_PUBLIC_KEYS) | |
48 | from rhodecode.lib.auth import NotAnonymous |
|
46 | from rhodecode.lib.auth import NotAnonymous | |
49 | from rhodecode.lib.utils2 import str2bool |
|
|||
50 |
|
47 | |||
51 | log = logging.getLogger(__name__) |
|
48 | log = logging.getLogger(__name__) | |
52 |
|
49 | |||
53 |
|
50 | |||
54 | class ChannelstreamView(object): |
|
51 | class ChannelstreamView(object): | |
55 | def __init__(self, context, request): |
|
52 | def __init__(self, context, request): | |
56 | self.context = context |
|
53 | self.context = context | |
57 | self.request = request |
|
54 | self.request = request | |
58 |
|
55 | |||
59 | # Some of the decorators rely on this attribute to be present |
|
56 | # Some of the decorators rely on this attribute to be present | |
60 | # on the class of the decorated method. |
|
57 | # on the class of the decorated method. | |
61 | self._rhodecode_user = request.user |
|
58 | self._rhodecode_user = request.user | |
62 | registry = request.registry |
|
59 | registry = request.registry | |
63 | self.channelstream_config = registry.rhodecode_plugins['channelstream'] |
|
60 | self.channelstream_config = registry.rhodecode_plugins['channelstream'] | |
64 | if not self.channelstream_config.get('enabled'): |
|
61 | if not self.channelstream_config.get('enabled'): | |
65 | log.error('Channelstream plugin is disabled') |
|
62 | log.error('Channelstream plugin is disabled') | |
66 | raise HTTPBadRequest() |
|
63 | raise HTTPBadRequest() | |
67 |
|
64 | |||
68 | @NotAnonymous() |
|
65 | @NotAnonymous() | |
69 | @view_config(route_name='channelstream_connect', renderer='json') |
|
66 | @view_config(route_name='channelstream_connect', renderer='json') | |
70 | def connect(self): |
|
67 | def connect(self): | |
71 | """ handle authorization of users trying to connect """ |
|
68 | """ handle authorization of users trying to connect """ | |
72 | try: |
|
69 | try: | |
73 | json_body = self.request.json_body |
|
70 | json_body = self.request.json_body | |
74 | except Exception: |
|
71 | except Exception: | |
75 | log.exception('Failed to decode json from request') |
|
72 | log.exception('Failed to decode json from request') | |
76 | raise HTTPBadRequest() |
|
73 | raise HTTPBadRequest() | |
77 | try: |
|
74 | try: | |
78 | channels = check_channel_permissions( |
|
75 | channels = check_channel_permissions( | |
79 | json_body.get('channels'), |
|
76 | json_body.get('channels'), | |
80 | get_connection_validators(self.request.registry)) |
|
77 | get_connection_validators(self.request.registry)) | |
81 | except ChannelstreamPermissionException: |
|
78 | except ChannelstreamPermissionException: | |
82 | log.error('Incorrect permissions for requested channels') |
|
79 | log.error('Incorrect permissions for requested channels') | |
83 | raise HTTPForbidden() |
|
80 | raise HTTPForbidden() | |
84 |
|
81 | |||
85 |
user = |
|
82 | user = self._rhodecode_user | |
86 | if user.user_id: |
|
83 | if user.user_id: | |
87 | user_data = get_user_data(user.user_id) |
|
84 | user_data = get_user_data(user.user_id) | |
88 | else: |
|
85 | else: | |
89 | user_data = { |
|
86 | user_data = { | |
90 | 'id': None, |
|
87 | 'id': None, | |
91 | 'username': None, |
|
88 | 'username': None, | |
92 | 'first_name': None, |
|
89 | 'first_name': None, | |
93 | 'last_name': None, |
|
90 | 'last_name': None, | |
94 | 'icon_link': None, |
|
91 | 'icon_link': None, | |
95 | 'display_name': None, |
|
92 | 'display_name': None, | |
96 | 'display_link': None, |
|
93 | 'display_link': None, | |
97 | } |
|
94 | } | |
98 |
user_data['permissions'] = |
|
95 | user_data['permissions'] = self._rhodecode_user.permissions | |
99 | payload = { |
|
96 | payload = { | |
100 | 'username': user.username, |
|
97 | 'username': user.username, | |
101 | 'user_state': user_data, |
|
98 | 'user_state': user_data, | |
102 | 'conn_id': str(uuid.uuid4()), |
|
99 | 'conn_id': str(uuid.uuid4()), | |
103 | 'channels': channels, |
|
100 | 'channels': channels, | |
104 | 'channel_configs': {}, |
|
101 | 'channel_configs': {}, | |
105 | 'state_public_keys': STATE_PUBLIC_KEYS, |
|
102 | 'state_public_keys': STATE_PUBLIC_KEYS, | |
106 | 'info': { |
|
103 | 'info': { | |
107 | 'exclude_channels': ['broadcast'] |
|
104 | 'exclude_channels': ['broadcast'] | |
108 | } |
|
105 | } | |
109 | } |
|
106 | } | |
110 | filtered_channels = [channel for channel in channels |
|
107 | filtered_channels = [channel for channel in channels | |
111 | if channel != 'broadcast'] |
|
108 | if channel != 'broadcast'] | |
112 | for channel in filtered_channels: |
|
109 | for channel in filtered_channels: | |
113 | payload['channel_configs'][channel] = { |
|
110 | payload['channel_configs'][channel] = { | |
114 | 'notify_presence': True, |
|
111 | 'notify_presence': True, | |
115 | 'history_size': 100, |
|
112 | 'history_size': 100, | |
116 | 'store_history': True, |
|
113 | 'store_history': True, | |
117 | 'broadcast_presence_with_user_lists': True |
|
114 | 'broadcast_presence_with_user_lists': True | |
118 | } |
|
115 | } | |
119 | # connect user to server |
|
116 | # connect user to server | |
120 | try: |
|
117 | try: | |
121 | connect_result = channelstream_request(self.channelstream_config, |
|
118 | connect_result = channelstream_request(self.channelstream_config, | |
122 | payload, '/connect') |
|
119 | payload, '/connect') | |
123 | except ChannelstreamConnectionException: |
|
120 | except ChannelstreamConnectionException: | |
124 | log.exception('Channelstream service is down') |
|
121 | log.exception('Channelstream service is down') | |
125 | return HTTPBadGateway() |
|
122 | return HTTPBadGateway() | |
126 |
|
123 | |||
127 | connect_result['channels'] = channels |
|
124 | connect_result['channels'] = channels | |
128 | connect_result['channels_info'] = parse_channels_info( |
|
125 | connect_result['channels_info'] = parse_channels_info( | |
129 | connect_result['channels_info'], |
|
126 | connect_result['channels_info'], | |
130 | include_channel_info=filtered_channels) |
|
127 | include_channel_info=filtered_channels) | |
131 | update_history_from_logs(self.channelstream_config, |
|
128 | update_history_from_logs(self.channelstream_config, | |
132 | filtered_channels, connect_result) |
|
129 | filtered_channels, connect_result) | |
133 | return connect_result |
|
130 | return connect_result | |
134 |
|
131 | |||
135 | @NotAnonymous() |
|
132 | @NotAnonymous() | |
136 | @view_config(route_name='channelstream_subscribe', renderer='json') |
|
133 | @view_config(route_name='channelstream_subscribe', renderer='json') | |
137 | def subscribe(self): |
|
134 | def subscribe(self): | |
138 | """ can be used to subscribe specific connection to other channels """ |
|
135 | """ can be used to subscribe specific connection to other channels """ | |
139 | try: |
|
136 | try: | |
140 | json_body = self.request.json_body |
|
137 | json_body = self.request.json_body | |
141 | except Exception: |
|
138 | except Exception: | |
142 | log.exception('Failed to decode json from request') |
|
139 | log.exception('Failed to decode json from request') | |
143 | raise HTTPBadRequest() |
|
140 | raise HTTPBadRequest() | |
144 | try: |
|
141 | try: | |
145 | channels = check_channel_permissions( |
|
142 | channels = check_channel_permissions( | |
146 | json_body.get('channels'), |
|
143 | json_body.get('channels'), | |
147 | get_connection_validators(self.request.registry)) |
|
144 | get_connection_validators(self.request.registry)) | |
148 | except ChannelstreamPermissionException: |
|
145 | except ChannelstreamPermissionException: | |
149 | log.error('Incorrect permissions for requested channels') |
|
146 | log.error('Incorrect permissions for requested channels') | |
150 | raise HTTPForbidden() |
|
147 | raise HTTPForbidden() | |
151 | payload = {'conn_id': json_body.get('conn_id', ''), |
|
148 | payload = {'conn_id': json_body.get('conn_id', ''), | |
152 | 'channels': channels, |
|
149 | 'channels': channels, | |
153 | 'channel_configs': {}, |
|
150 | 'channel_configs': {}, | |
154 | 'info': { |
|
151 | 'info': { | |
155 | 'exclude_channels': ['broadcast']} |
|
152 | 'exclude_channels': ['broadcast']} | |
156 | } |
|
153 | } | |
157 | filtered_channels = [chan for chan in channels if chan != 'broadcast'] |
|
154 | filtered_channels = [chan for chan in channels if chan != 'broadcast'] | |
158 | for channel in filtered_channels: |
|
155 | for channel in filtered_channels: | |
159 | payload['channel_configs'][channel] = { |
|
156 | payload['channel_configs'][channel] = { | |
160 | 'notify_presence': True, |
|
157 | 'notify_presence': True, | |
161 | 'history_size': 100, |
|
158 | 'history_size': 100, | |
162 | 'store_history': True, |
|
159 | 'store_history': True, | |
163 | 'broadcast_presence_with_user_lists': True |
|
160 | 'broadcast_presence_with_user_lists': True | |
164 | } |
|
161 | } | |
165 | try: |
|
162 | try: | |
166 | connect_result = channelstream_request( |
|
163 | connect_result = channelstream_request( | |
167 | self.channelstream_config, payload, '/subscribe') |
|
164 | self.channelstream_config, payload, '/subscribe') | |
168 | except ChannelstreamConnectionException: |
|
165 | except ChannelstreamConnectionException: | |
169 | log.exception('Channelstream service is down') |
|
166 | log.exception('Channelstream service is down') | |
170 | return HTTPBadGateway() |
|
167 | return HTTPBadGateway() | |
171 | # include_channel_info will limit history only to new channel |
|
168 | # include_channel_info will limit history only to new channel | |
172 | # to not overwrite histories on other channels in client |
|
169 | # to not overwrite histories on other channels in client | |
173 | connect_result['channels_info'] = parse_channels_info( |
|
170 | connect_result['channels_info'] = parse_channels_info( | |
174 | connect_result['channels_info'], |
|
171 | connect_result['channels_info'], | |
175 | include_channel_info=filtered_channels) |
|
172 | include_channel_info=filtered_channels) | |
176 | update_history_from_logs(self.channelstream_config, |
|
173 | update_history_from_logs(self.channelstream_config, | |
177 | filtered_channels, connect_result) |
|
174 | filtered_channels, connect_result) | |
178 | return connect_result |
|
175 | return connect_result |
General Comments 0
You need to be logged in to leave comments.
Login now