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