##// END OF EJS Templates
system-info: expose env variables
super-admin -
r4743:9f402145 default
parent child Browse files
Show More
@@ -1,200 +1,234 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2020 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
24
23 import os
25 24
26 25 import rhodecode
27 26 from rhodecode.apps._base import BaseAppView
28 27 from rhodecode.apps._base.navigation import navigation_list
29 28 from rhodecode.lib import helpers as h
30 29 from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator)
31 30 from rhodecode.lib.utils2 import str2bool
32 31 from rhodecode.lib import system_info
33 32 from rhodecode.model.update import UpdateModel
34 33
35 34 log = logging.getLogger(__name__)
36 35
37 36
38 37 class AdminSystemInfoSettingsView(BaseAppView):
39 38 def load_default_context(self):
40 39 c = self._get_local_tmpl_context()
41 40 return c
42 41
42 def get_env_data(self):
43 black_list = [
44 'NIX_LDFLAGS',
45 'NIX_CFLAGS_COMPILE',
46 'propagatedBuildInputs',
47 'propagatedNativeBuildInputs',
48 'postInstall',
49 'buildInputs',
50 'buildPhase',
51 'preShellHook',
52 'preShellHook',
53 'preCheck',
54 'preBuild',
55 'postShellHook',
56 'postFixup',
57 'postCheck',
58 'nativeBuildInputs',
59 'installPhase',
60 'installCheckPhase',
61 'checkPhase',
62 'configurePhase',
63 'shellHook'
64 ]
65 secret_list = [
66 'RHODECODE_USER_PASS'
67 ]
68
69 for k, v in sorted(os.environ.items()):
70 if k in black_list:
71 continue
72 if k in secret_list:
73 v = '*****'
74 yield k, v
75
43 76 @LoginRequired()
44 77 @HasPermissionAllDecorator('hg.admin')
45 78 def settings_system_info(self):
46 79 _ = self.request.translate
47 80 c = self.load_default_context()
48 81
49 82 c.active = 'system'
50 83 c.navlist = navigation_list(self.request)
51 84
52 85 # TODO(marcink), figure out how to allow only selected users to do this
53 86 c.allowed_to_snapshot = self._rhodecode_user.admin
54 87
55 88 snapshot = str2bool(self.request.params.get('snapshot'))
56 89
57 90 c.rhodecode_update_url = UpdateModel().get_update_url()
91 c.env_data = self.get_env_data()
58 92 server_info = system_info.get_system_info(self.request.environ)
59 93
60 94 for key, val in server_info.items():
61 95 setattr(c, key, val)
62 96
63 97 def val(name, subkey='human_value'):
64 98 return server_info[name][subkey]
65 99
66 100 def state(name):
67 101 return server_info[name]['state']
68 102
69 103 def val2(name):
70 104 val = server_info[name]['human_value']
71 105 state = server_info[name]['state']
72 106 return val, state
73 107
74 108 update_info_msg = _('Note: please make sure this server can '
75 109 'access `${url}` for the update link to work',
76 110 mapping=dict(url=c.rhodecode_update_url))
77 111 version = UpdateModel().get_stored_version()
78 112 is_outdated = UpdateModel().is_outdated(
79 113 rhodecode.__version__, version)
80 114 update_state = {
81 115 'type': 'warning',
82 116 'message': 'New version available: {}'.format(version)
83 117 } \
84 118 if is_outdated else {}
85 119 c.data_items = [
86 120 # update info
87 121 (_('Update info'), h.literal(
88 122 '<span class="link" id="check_for_update" >%s.</span>' % (
89 123 _('Check for updates')) +
90 124 '<br/> <span >%s.</span>' % (update_info_msg)
91 125 ), ''),
92 126
93 127 # RhodeCode specific
94 128 (_('RhodeCode Version'), val('rhodecode_app')['text'], state('rhodecode_app')),
95 129 (_('Latest version'), version, update_state),
96 130 (_('RhodeCode Base URL'), val('rhodecode_config')['config'].get('app.base_url'), state('rhodecode_config')),
97 131 (_('RhodeCode Server IP'), val('server')['server_ip'], state('server')),
98 132 (_('RhodeCode Server ID'), val('server')['server_id'], state('server')),
99 133 (_('RhodeCode Configuration'), val('rhodecode_config')['path'], state('rhodecode_config')),
100 134 (_('RhodeCode Certificate'), val('rhodecode_config')['cert_path'], state('rhodecode_config')),
101 135 (_('Workers'), val('rhodecode_config')['config']['server:main'].get('workers', '?'), state('rhodecode_config')),
102 136 (_('Worker Type'), val('rhodecode_config')['config']['server:main'].get('worker_class', 'sync'), state('rhodecode_config')),
103 137 ('', '', ''), # spacer
104 138
105 139 # Database
106 140 (_('Database'), val('database')['url'], state('database')),
107 141 (_('Database version'), val('database')['version'], state('database')),
108 142 ('', '', ''), # spacer
109 143
110 144 # Platform/Python
111 145 (_('Platform'), val('platform')['name'], state('platform')),
112 146 (_('Platform UUID'), val('platform')['uuid'], state('platform')),
113 147 (_('Lang'), val('locale'), state('locale')),
114 148 (_('Python version'), val('python')['version'], state('python')),
115 149 (_('Python path'), val('python')['executable'], state('python')),
116 150 ('', '', ''), # spacer
117 151
118 152 # Systems stats
119 153 (_('CPU'), val('cpu')['text'], state('cpu')),
120 154 (_('Load'), val('load')['text'], state('load')),
121 155 (_('Memory'), val('memory')['text'], state('memory')),
122 156 (_('Uptime'), val('uptime')['text'], state('uptime')),
123 157 ('', '', ''), # spacer
124 158
125 159 # ulimit
126 160 (_('Ulimit'), val('ulimit')['text'], state('ulimit')),
127 161
128 162 # Repo storage
129 163 (_('Storage location'), val('storage')['path'], state('storage')),
130 164 (_('Storage info'), val('storage')['text'], state('storage')),
131 165 (_('Storage inodes'), val('storage_inodes')['text'], state('storage_inodes')),
132 166
133 167 (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')),
134 168 (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')),
135 169
136 170 (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')),
137 171 (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')),
138 172
139 173 (_('Temp storage location'), val('storage_temp')['path'], state('storage_temp')),
140 174 (_('Temp storage info'), val('storage_temp')['text'], state('storage_temp')),
141 175
142 176 (_('Search info'), val('search')['text'], state('search')),
143 177 (_('Search location'), val('search')['location'], state('search')),
144 178 ('', '', ''), # spacer
145 179
146 180 # VCS specific
147 181 (_('VCS Backends'), val('vcs_backends'), state('vcs_backends')),
148 182 (_('VCS Server'), val('vcs_server')['text'], state('vcs_server')),
149 183 (_('GIT'), val('git'), state('git')),
150 184 (_('HG'), val('hg'), state('hg')),
151 185 (_('SVN'), val('svn'), state('svn')),
152 186
153 187 ]
154 188
155 189 c.vcsserver_data_items = [
156 190 (k, v) for k,v in (val('vcs_server_config') or {}).items()
157 191 ]
158 192
159 193 if snapshot:
160 194 if c.allowed_to_snapshot:
161 195 c.data_items.pop(0) # remove server info
162 196 self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako'
163 197 else:
164 198 h.flash('You are not allowed to do this', category='warning')
165 199 return self._get_template_context(c)
166 200
167 201 @LoginRequired()
168 202 @HasPermissionAllDecorator('hg.admin')
169 203 def settings_system_info_check_update(self):
170 204 _ = self.request.translate
171 205 c = self.load_default_context()
172 206
173 207 update_url = UpdateModel().get_update_url()
174 208
175 209 _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">{}</div>'.format(s)
176 210 try:
177 211 data = UpdateModel().get_update_data(update_url)
178 212 except urllib2.URLError as e:
179 213 log.exception("Exception contacting upgrade server")
180 214 self.request.override_renderer = 'string'
181 215 return _err('Failed to contact upgrade server: %r' % e)
182 216 except ValueError as e:
183 217 log.exception("Bad data sent from update server")
184 218 self.request.override_renderer = 'string'
185 219 return _err('Bad data sent from update server')
186 220
187 221 latest = data['versions'][0]
188 222
189 223 c.update_url = update_url
190 224 c.latest_data = latest
191 225 c.latest_ver = latest['version']
192 226 c.cur_ver = rhodecode.__version__
193 227 c.should_upgrade = False
194 228
195 229 is_oudated = UpdateModel().is_outdated(c.cur_ver, c.latest_ver)
196 230 if is_oudated:
197 231 c.should_upgrade = True
198 232 c.important_notices = latest['general']
199 233 UpdateModel().store_version(latest['version'])
200 234 return self._get_template_context(c)
@@ -1,70 +1,89 b''
1 1
2 2 <div id="update_notice" style="display: none; margin: 0px 0px 30px 0px">
3 3 <div>${_('Checking for updates...')}</div>
4 4 </div>
5 5
6 6
7 7 <div class="panel panel-default">
8 8 <div class="panel-heading">
9 9 <h3 class="panel-title">${_('System Info')}</h3>
10 10 % if c.allowed_to_snapshot:
11 11 <a href="${h.route_path('admin_settings_system', _query={'snapshot':1})}" class="panel-edit">${_('create summary snapshot')}</a>
12 12 % endif
13 13 </div>
14 14 <div class="panel-body">
15 15 <dl class="dl-horizontal settings dt-400">
16 16 % for dt, dd, warn in c.data_items:
17 17 <dt>${dt}${':' if dt else '---'}</dt>
18 18 <dd>${dd}${'' if dt else '---'}
19 19 % if warn and warn['message']:
20 20 <div class="alert-${warn['type']}">
21 21 <strong>${warn['message']}</strong>
22 22 </div>
23 23 % endif
24 24 </dd>
25 25 % endfor
26 26 </dl>
27 27 </div>
28 28 </div>
29 29
30 30 <div class="panel panel-default">
31 31 <div class="panel-heading">
32 32 <h3 class="panel-title">${_('VCS Server')}</h3>
33 33 </div>
34 34 <div class="panel-body">
35 35 <dl class="dl-horizontal settings dt-400">
36 36 % for dt, dd in c.vcsserver_data_items:
37 37 <dt>${dt}${':' if dt else '---'}</dt>
38 38 <dd>${dd}${'' if dt else '---'}</dd>
39 39 % endfor
40 40 </dl>
41 41 </div>
42 42 </div>
43 43
44 44 <div class="panel panel-default">
45 45 <div class="panel-heading">
46 46 <h3 class="panel-title">${_('Python Packages')}</h3>
47 47 </div>
48 48 <div class="panel-body">
49 49 <table>
50 50 <th></th>
51 51 <th></th>
52 52 <th></th>
53 53 % for name, package_data in c.py_modules['human_value']:
54 54 <tr>
55 55 <td>${name.lower()}</td>
56 56 <td>${package_data['version']}</td>
57 57 <td>(${package_data['location']})</td>
58 58 </tr>
59 59 % endfor
60 60 </table>
61 61
62 62 </div>
63 63 </div>
64 64
65 <div class="panel panel-default">
66 <div class="panel-heading">
67 <h3 class="panel-title">${_('Env Variables')}</h3>
68 </div>
69 <div class="panel-body">
70 <table>
71 <th></th>
72 <th></th>
73 % for env_key, env_val in c.env_data:
74 <tr>
75 <td style="vertical-align: top">${env_key}</td>
76 <td>${env_val}</td>
77 </tr>
78 % endfor
79 </table>
80
81 </div>
82 </div>
83
65 84 <script>
66 85 $('#check_for_update').click(function(e){
67 86 $('#update_notice').show();
68 87 $('#update_notice').load("${h.route_path('admin_settings_system_update')}");
69 88 })
70 89 </script>
General Comments 0
You need to be logged in to leave comments. Login now