##// END OF EJS Templates
system-info: ensure safe read of base_url in case it's not set.
marcink -
r3292:8bad3b77 default
parent child Browse files
Show More
@@ -1,202 +1,202 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2018 RhodeCode GmbH
3 # Copyright (C) 2016-2018 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
23
24 from pyramid.view import view_config
24 from pyramid.view import view_config
25
25
26 import rhodecode
26 import rhodecode
27 from rhodecode.apps._base import BaseAppView
27 from rhodecode.apps._base import BaseAppView
28 from rhodecode.apps._base.navigation import navigation_list
28 from rhodecode.apps._base.navigation import navigation_list
29 from rhodecode.lib import helpers as h
29 from rhodecode.lib import helpers as h
30 from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator)
30 from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator)
31 from rhodecode.lib.utils2 import str2bool
31 from rhodecode.lib.utils2 import str2bool
32 from rhodecode.lib import system_info
32 from rhodecode.lib import system_info
33 from rhodecode.model.update import UpdateModel
33 from rhodecode.model.update import UpdateModel
34
34
35 log = logging.getLogger(__name__)
35 log = logging.getLogger(__name__)
36
36
37
37
38 class AdminSystemInfoSettingsView(BaseAppView):
38 class AdminSystemInfoSettingsView(BaseAppView):
39 def load_default_context(self):
39 def load_default_context(self):
40 c = self._get_local_tmpl_context()
40 c = self._get_local_tmpl_context()
41 return c
41 return c
42
42
43 @LoginRequired()
43 @LoginRequired()
44 @HasPermissionAllDecorator('hg.admin')
44 @HasPermissionAllDecorator('hg.admin')
45 @view_config(
45 @view_config(
46 route_name='admin_settings_system', request_method='GET',
46 route_name='admin_settings_system', request_method='GET',
47 renderer='rhodecode:templates/admin/settings/settings.mako')
47 renderer='rhodecode:templates/admin/settings/settings.mako')
48 def settings_system_info(self):
48 def settings_system_info(self):
49 _ = self.request.translate
49 _ = self.request.translate
50 c = self.load_default_context()
50 c = self.load_default_context()
51
51
52 c.active = 'system'
52 c.active = 'system'
53 c.navlist = navigation_list(self.request)
53 c.navlist = navigation_list(self.request)
54
54
55 # TODO(marcink), figure out how to allow only selected users to do this
55 # TODO(marcink), figure out how to allow only selected users to do this
56 c.allowed_to_snapshot = self._rhodecode_user.admin
56 c.allowed_to_snapshot = self._rhodecode_user.admin
57
57
58 snapshot = str2bool(self.request.params.get('snapshot'))
58 snapshot = str2bool(self.request.params.get('snapshot'))
59
59
60 c.rhodecode_update_url = UpdateModel().get_update_url()
60 c.rhodecode_update_url = UpdateModel().get_update_url()
61 server_info = system_info.get_system_info(self.request.environ)
61 server_info = system_info.get_system_info(self.request.environ)
62
62
63 for key, val in server_info.items():
63 for key, val in server_info.items():
64 setattr(c, key, val)
64 setattr(c, key, val)
65
65
66 def val(name, subkey='human_value'):
66 def val(name, subkey='human_value'):
67 return server_info[name][subkey]
67 return server_info[name][subkey]
68
68
69 def state(name):
69 def state(name):
70 return server_info[name]['state']
70 return server_info[name]['state']
71
71
72 def val2(name):
72 def val2(name):
73 val = server_info[name]['human_value']
73 val = server_info[name]['human_value']
74 state = server_info[name]['state']
74 state = server_info[name]['state']
75 return val, state
75 return val, state
76
76
77 update_info_msg = _('Note: please make sure this server can '
77 update_info_msg = _('Note: please make sure this server can '
78 'access `${url}` for the update link to work',
78 'access `${url}` for the update link to work',
79 mapping=dict(url=c.rhodecode_update_url))
79 mapping=dict(url=c.rhodecode_update_url))
80 version = UpdateModel().get_stored_version()
80 version = UpdateModel().get_stored_version()
81 is_outdated = UpdateModel().is_outdated(
81 is_outdated = UpdateModel().is_outdated(
82 rhodecode.__version__, version)
82 rhodecode.__version__, version)
83 update_state = {
83 update_state = {
84 'type': 'warning',
84 'type': 'warning',
85 'message': 'New version available: {}'.format(version)
85 'message': 'New version available: {}'.format(version)
86 } \
86 } \
87 if is_outdated else {}
87 if is_outdated else {}
88 c.data_items = [
88 c.data_items = [
89 # update info
89 # update info
90 (_('Update info'), h.literal(
90 (_('Update info'), h.literal(
91 '<span class="link" id="check_for_update" >%s.</span>' % (
91 '<span class="link" id="check_for_update" >%s.</span>' % (
92 _('Check for updates')) +
92 _('Check for updates')) +
93 '<br/> <span >%s.</span>' % (update_info_msg)
93 '<br/> <span >%s.</span>' % (update_info_msg)
94 ), ''),
94 ), ''),
95
95
96 # RhodeCode specific
96 # RhodeCode specific
97 (_('RhodeCode Version'), val('rhodecode_app')['text'], state('rhodecode_app')),
97 (_('RhodeCode Version'), val('rhodecode_app')['text'], state('rhodecode_app')),
98 (_('Latest version'), version, update_state),
98 (_('Latest version'), version, update_state),
99 (_('RhodeCode Base URL'), val('rhodecode_config')['config']['app.base_url'], state('rhodecode_config')),
99 (_('RhodeCode Base URL'), val('rhodecode_config')['config'].get('app.base_url'), state('rhodecode_config')),
100 (_('RhodeCode Server IP'), val('server')['server_ip'], state('server')),
100 (_('RhodeCode Server IP'), val('server')['server_ip'], state('server')),
101 (_('RhodeCode Server ID'), val('server')['server_id'], state('server')),
101 (_('RhodeCode Server ID'), val('server')['server_id'], state('server')),
102 (_('RhodeCode Configuration'), val('rhodecode_config')['path'], state('rhodecode_config')),
102 (_('RhodeCode Configuration'), val('rhodecode_config')['path'], state('rhodecode_config')),
103 (_('RhodeCode Certificate'), val('rhodecode_config')['cert_path'], state('rhodecode_config')),
103 (_('RhodeCode Certificate'), val('rhodecode_config')['cert_path'], state('rhodecode_config')),
104 (_('Workers'), val('rhodecode_config')['config']['server:main'].get('workers', '?'), state('rhodecode_config')),
104 (_('Workers'), val('rhodecode_config')['config']['server:main'].get('workers', '?'), state('rhodecode_config')),
105 (_('Worker Type'), val('rhodecode_config')['config']['server:main'].get('worker_class', 'sync'), state('rhodecode_config')),
105 (_('Worker Type'), val('rhodecode_config')['config']['server:main'].get('worker_class', 'sync'), state('rhodecode_config')),
106 ('', '', ''), # spacer
106 ('', '', ''), # spacer
107
107
108 # Database
108 # Database
109 (_('Database'), val('database')['url'], state('database')),
109 (_('Database'), val('database')['url'], state('database')),
110 (_('Database version'), val('database')['version'], state('database')),
110 (_('Database version'), val('database')['version'], state('database')),
111 ('', '', ''), # spacer
111 ('', '', ''), # spacer
112
112
113 # Platform/Python
113 # Platform/Python
114 (_('Platform'), val('platform')['name'], state('platform')),
114 (_('Platform'), val('platform')['name'], state('platform')),
115 (_('Platform UUID'), val('platform')['uuid'], state('platform')),
115 (_('Platform UUID'), val('platform')['uuid'], state('platform')),
116 (_('Lang'), val('locale'), state('locale')),
116 (_('Lang'), val('locale'), state('locale')),
117 (_('Python version'), val('python')['version'], state('python')),
117 (_('Python version'), val('python')['version'], state('python')),
118 (_('Python path'), val('python')['executable'], state('python')),
118 (_('Python path'), val('python')['executable'], state('python')),
119 ('', '', ''), # spacer
119 ('', '', ''), # spacer
120
120
121 # Systems stats
121 # Systems stats
122 (_('CPU'), val('cpu')['text'], state('cpu')),
122 (_('CPU'), val('cpu')['text'], state('cpu')),
123 (_('Load'), val('load')['text'], state('load')),
123 (_('Load'), val('load')['text'], state('load')),
124 (_('Memory'), val('memory')['text'], state('memory')),
124 (_('Memory'), val('memory')['text'], state('memory')),
125 (_('Uptime'), val('uptime')['text'], state('uptime')),
125 (_('Uptime'), val('uptime')['text'], state('uptime')),
126 ('', '', ''), # spacer
126 ('', '', ''), # spacer
127
127
128 # ulimit
128 # ulimit
129 (_('Ulimit'), val('ulimit')['text'], state('ulimit')),
129 (_('Ulimit'), val('ulimit')['text'], state('ulimit')),
130
130
131 # Repo storage
131 # Repo storage
132 (_('Storage location'), val('storage')['path'], state('storage')),
132 (_('Storage location'), val('storage')['path'], state('storage')),
133 (_('Storage info'), val('storage')['text'], state('storage')),
133 (_('Storage info'), val('storage')['text'], state('storage')),
134 (_('Storage inodes'), val('storage_inodes')['text'], state('storage_inodes')),
134 (_('Storage inodes'), val('storage_inodes')['text'], state('storage_inodes')),
135
135
136 (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')),
136 (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')),
137 (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')),
137 (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')),
138
138
139 (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')),
139 (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')),
140 (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')),
140 (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')),
141
141
142 (_('Temp storage location'), val('storage_temp')['path'], state('storage_temp')),
142 (_('Temp storage location'), val('storage_temp')['path'], state('storage_temp')),
143 (_('Temp storage info'), val('storage_temp')['text'], state('storage_temp')),
143 (_('Temp storage info'), val('storage_temp')['text'], state('storage_temp')),
144
144
145 (_('Search info'), val('search')['text'], state('search')),
145 (_('Search info'), val('search')['text'], state('search')),
146 (_('Search location'), val('search')['location'], state('search')),
146 (_('Search location'), val('search')['location'], state('search')),
147 ('', '', ''), # spacer
147 ('', '', ''), # spacer
148
148
149 # VCS specific
149 # VCS specific
150 (_('VCS Backends'), val('vcs_backends'), state('vcs_backends')),
150 (_('VCS Backends'), val('vcs_backends'), state('vcs_backends')),
151 (_('VCS Server'), val('vcs_server')['text'], state('vcs_server')),
151 (_('VCS Server'), val('vcs_server')['text'], state('vcs_server')),
152 (_('GIT'), val('git'), state('git')),
152 (_('GIT'), val('git'), state('git')),
153 (_('HG'), val('hg'), state('hg')),
153 (_('HG'), val('hg'), state('hg')),
154 (_('SVN'), val('svn'), state('svn')),
154 (_('SVN'), val('svn'), state('svn')),
155
155
156 ]
156 ]
157
157
158 if snapshot:
158 if snapshot:
159 if c.allowed_to_snapshot:
159 if c.allowed_to_snapshot:
160 c.data_items.pop(0) # remove server info
160 c.data_items.pop(0) # remove server info
161 self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako'
161 self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako'
162 else:
162 else:
163 h.flash('You are not allowed to do this', category='warning')
163 h.flash('You are not allowed to do this', category='warning')
164 return self._get_template_context(c)
164 return self._get_template_context(c)
165
165
166 @LoginRequired()
166 @LoginRequired()
167 @HasPermissionAllDecorator('hg.admin')
167 @HasPermissionAllDecorator('hg.admin')
168 @view_config(
168 @view_config(
169 route_name='admin_settings_system_update', request_method='GET',
169 route_name='admin_settings_system_update', request_method='GET',
170 renderer='rhodecode:templates/admin/settings/settings_system_update.mako')
170 renderer='rhodecode:templates/admin/settings/settings_system_update.mako')
171 def settings_system_info_check_update(self):
171 def settings_system_info_check_update(self):
172 _ = self.request.translate
172 _ = self.request.translate
173 c = self.load_default_context()
173 c = self.load_default_context()
174
174
175 update_url = UpdateModel().get_update_url()
175 update_url = UpdateModel().get_update_url()
176
176
177 _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">{}</div>'.format(s)
177 _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">{}</div>'.format(s)
178 try:
178 try:
179 data = UpdateModel().get_update_data(update_url)
179 data = UpdateModel().get_update_data(update_url)
180 except urllib2.URLError as e:
180 except urllib2.URLError as e:
181 log.exception("Exception contacting upgrade server")
181 log.exception("Exception contacting upgrade server")
182 self.request.override_renderer = 'string'
182 self.request.override_renderer = 'string'
183 return _err('Failed to contact upgrade server: %r' % e)
183 return _err('Failed to contact upgrade server: %r' % e)
184 except ValueError as e:
184 except ValueError as e:
185 log.exception("Bad data sent from update server")
185 log.exception("Bad data sent from update server")
186 self.request.override_renderer = 'string'
186 self.request.override_renderer = 'string'
187 return _err('Bad data sent from update server')
187 return _err('Bad data sent from update server')
188
188
189 latest = data['versions'][0]
189 latest = data['versions'][0]
190
190
191 c.update_url = update_url
191 c.update_url = update_url
192 c.latest_data = latest
192 c.latest_data = latest
193 c.latest_ver = latest['version']
193 c.latest_ver = latest['version']
194 c.cur_ver = rhodecode.__version__
194 c.cur_ver = rhodecode.__version__
195 c.should_upgrade = False
195 c.should_upgrade = False
196
196
197 is_oudated = UpdateModel().is_outdated(c.cur_ver, c.latest_ver)
197 is_oudated = UpdateModel().is_outdated(c.cur_ver, c.latest_ver)
198 if is_oudated:
198 if is_oudated:
199 c.should_upgrade = True
199 c.should_upgrade = True
200 c.important_notices = latest['general']
200 c.important_notices = latest['general']
201 UpdateModel().store_version(latest['version'])
201 UpdateModel().store_version(latest['version'])
202 return self._get_template_context(c)
202 return self._get_template_context(c)
General Comments 0
You need to be logged in to leave comments. Login now