Show More
@@ -0,0 +1,200 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | ||
|
3 | # Copyright (C) 2016-2017 RhodeCode GmbH | |
|
4 | # | |
|
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 | |
|
7 | # (only), as published by the Free Software Foundation. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
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/>. | |
|
16 | # | |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
|
20 | ||
|
21 | import logging | |
|
22 | import urllib2 | |
|
23 | import packaging.version | |
|
24 | ||
|
25 | from pylons import tmpl_context as c | |
|
26 | from pyramid.view import view_config | |
|
27 | ||
|
28 | import rhodecode | |
|
29 | from rhodecode.lib import helpers as h | |
|
30 | from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator) | |
|
31 | from rhodecode.lib.utils2 import str2bool | |
|
32 | from rhodecode.lib import system_info | |
|
33 | from rhodecode.lib.ext_json import json | |
|
34 | ||
|
35 | from rhodecode.admin.views.base import AdminSettingsView | |
|
36 | from rhodecode.admin.navigation import navigation_list | |
|
37 | from rhodecode.model.settings import SettingsModel | |
|
38 | ||
|
39 | log = logging.getLogger(__name__) | |
|
40 | ||
|
41 | ||
|
42 | class AdminSystemInfoSettingsView(AdminSettingsView): | |
|
43 | ||
|
44 | @staticmethod | |
|
45 | def get_update_data(update_url): | |
|
46 | """Return the JSON update data.""" | |
|
47 | ver = rhodecode.__version__ | |
|
48 | log.debug('Checking for upgrade on `%s` server', update_url) | |
|
49 | opener = urllib2.build_opener() | |
|
50 | opener.addheaders = [('User-agent', 'RhodeCode-SCM/%s' % ver)] | |
|
51 | response = opener.open(update_url) | |
|
52 | response_data = response.read() | |
|
53 | data = json.loads(response_data) | |
|
54 | ||
|
55 | return data | |
|
56 | ||
|
57 | def get_update_url(self): | |
|
58 | settings = SettingsModel().get_all_settings() | |
|
59 | return settings.get('rhodecode_update_url') | |
|
60 | ||
|
61 | @LoginRequired() | |
|
62 | @HasPermissionAllDecorator('hg.admin') | |
|
63 | @view_config( | |
|
64 | route_name='admin_settings_system', request_method='GET', | |
|
65 | renderer='rhodecode:templates/admin/settings/settings.mako') | |
|
66 | def settings_sessions(self): | |
|
67 | _ = self.request.translate | |
|
68 | ||
|
69 | c.active = 'system' | |
|
70 | c.navlist = navigation_list(self.request) | |
|
71 | ||
|
72 | # TODO(marcink), figure out how to allow only selected users to do this | |
|
73 | c.allowed_to_snapshot = self._rhodecode_user.admin | |
|
74 | ||
|
75 | snapshot = str2bool(self.request.params.get('snapshot')) | |
|
76 | ||
|
77 | c.rhodecode_update_url = self.get_update_url() | |
|
78 | server_info = system_info.get_system_info(self.request.environ) | |
|
79 | ||
|
80 | for key, val in server_info.items(): | |
|
81 | setattr(c, key, val) | |
|
82 | ||
|
83 | def val(name, subkey='human_value'): | |
|
84 | return server_info[name][subkey] | |
|
85 | ||
|
86 | def state(name): | |
|
87 | return server_info[name]['state'] | |
|
88 | ||
|
89 | def val2(name): | |
|
90 | val = server_info[name]['human_value'] | |
|
91 | state = server_info[name]['state'] | |
|
92 | return val, state | |
|
93 | ||
|
94 | update_info_msg = _('Note: please make sure this server can ' | |
|
95 | 'access `${url}` for the update link to work', | |
|
96 | mapping=dict(url=c.rhodecode_update_url)) | |
|
97 | c.data_items = [ | |
|
98 | # update info | |
|
99 | (_('Update info'), h.literal( | |
|
100 | '<span class="link" id="check_for_update" >%s.</span>' % ( | |
|
101 | _('Check for updates')) + | |
|
102 | '<br/> <span >%s.</span>' % (update_info_msg) | |
|
103 | ), ''), | |
|
104 | ||
|
105 | # RhodeCode specific | |
|
106 | (_('RhodeCode Version'), val('rhodecode_app')['text'], state('rhodecode_app')), | |
|
107 | (_('RhodeCode Server IP'), val('server')['server_ip'], state('server')), | |
|
108 | (_('RhodeCode Server ID'), val('server')['server_id'], state('server')), | |
|
109 | (_('RhodeCode Configuration'), val('rhodecode_config')['path'], state('rhodecode_config')), | |
|
110 | ('', '', ''), # spacer | |
|
111 | ||
|
112 | # Database | |
|
113 | (_('Database'), val('database')['url'], state('database')), | |
|
114 | (_('Database version'), val('database')['version'], state('database')), | |
|
115 | ('', '', ''), # spacer | |
|
116 | ||
|
117 | # Platform/Python | |
|
118 | (_('Platform'), val('platform')['name'], state('platform')), | |
|
119 | (_('Platform UUID'), val('platform')['uuid'], state('platform')), | |
|
120 | (_('Python version'), val('python')['version'], state('python')), | |
|
121 | (_('Python path'), val('python')['executable'], state('python')), | |
|
122 | ('', '', ''), # spacer | |
|
123 | ||
|
124 | # Systems stats | |
|
125 | (_('CPU'), val('cpu'), state('cpu')), | |
|
126 | (_('Load'), val('load')['text'], state('load')), | |
|
127 | (_('Memory'), val('memory')['text'], state('memory')), | |
|
128 | (_('Uptime'), val('uptime')['text'], state('uptime')), | |
|
129 | ('', '', ''), # spacer | |
|
130 | ||
|
131 | # Repo storage | |
|
132 | (_('Storage location'), val('storage')['path'], state('storage')), | |
|
133 | (_('Storage info'), val('storage')['text'], state('storage')), | |
|
134 | (_('Storage inodes'), val('storage_inodes')['text'], state('storage_inodes')), | |
|
135 | ||
|
136 | (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')), | |
|
137 | (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')), | |
|
138 | ||
|
139 | (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')), | |
|
140 | (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')), | |
|
141 | ||
|
142 | (_('Temp storage location'), val('storage_temp')['path'], state('storage_temp')), | |
|
143 | (_('Temp storage info'), val('storage_temp')['text'], state('storage_temp')), | |
|
144 | ||
|
145 | (_('Search info'), val('search')['text'], state('search')), | |
|
146 | (_('Search location'), val('search')['location'], state('search')), | |
|
147 | ('', '', ''), # spacer | |
|
148 | ||
|
149 | # VCS specific | |
|
150 | (_('VCS Backends'), val('vcs_backends'), state('vcs_backends')), | |
|
151 | (_('VCS Server'), val('vcs_server')['text'], state('vcs_server')), | |
|
152 | (_('GIT'), val('git'), state('git')), | |
|
153 | (_('HG'), val('hg'), state('hg')), | |
|
154 | (_('SVN'), val('svn'), state('svn')), | |
|
155 | ||
|
156 | ] | |
|
157 | ||
|
158 | if snapshot: | |
|
159 | if c.allowed_to_snapshot: | |
|
160 | c.data_items.pop(0) # remove server info | |
|
161 | self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako' | |
|
162 | else: | |
|
163 | self.request.session.flash( | |
|
164 | 'You are not allowed to do this', queue='warning') | |
|
165 | return {} | |
|
166 | ||
|
167 | @LoginRequired() | |
|
168 | @HasPermissionAllDecorator('hg.admin') | |
|
169 | @view_config( | |
|
170 | route_name='admin_settings_system_update', request_method='GET', | |
|
171 | renderer='rhodecode:templates/admin/settings/settings_system_update.mako') | |
|
172 | def settings_sessions_cleanup(self): | |
|
173 | _ = self.request.translate | |
|
174 | ||
|
175 | update_url = self.get_update_url() | |
|
176 | ||
|
177 | _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">{}</div>'.format(s) | |
|
178 | try: | |
|
179 | data = self.get_update_data(update_url) | |
|
180 | except urllib2.URLError as e: | |
|
181 | log.exception("Exception contacting upgrade server") | |
|
182 | return _err('Failed to contact upgrade server: %r' % e) | |
|
183 | except ValueError as e: | |
|
184 | log.exception("Bad data sent from update server") | |
|
185 | return _err('Bad data sent from update server') | |
|
186 | ||
|
187 | latest = data['versions'][0] | |
|
188 | ||
|
189 | c.update_url = update_url | |
|
190 | c.latest_data = latest | |
|
191 | c.latest_ver = latest['version'] | |
|
192 | c.cur_ver = rhodecode.__version__ | |
|
193 | c.should_upgrade = False | |
|
194 | ||
|
195 | if (packaging.version.Version(c.latest_ver) > | |
|
196 | packaging.version.Version(c.cur_ver)): | |
|
197 | c.should_upgrade = True | |
|
198 | c.important_notices = latest['general'] | |
|
199 | ||
|
200 | return {} |
@@ -40,6 +40,13 b' def includeme(config):' | |||
|
40 | 40 | pattern=ADMIN_PREFIX + '/settings/vcs/svn_generate_cfg') |
|
41 | 41 | |
|
42 | 42 | config.add_route( |
|
43 | name='admin_settings_system', | |
|
44 | pattern=ADMIN_PREFIX + '/settings/system') | |
|
45 | config.add_route( | |
|
46 | name='admin_settings_system_update', | |
|
47 | pattern=ADMIN_PREFIX + '/settings/system/updates') | |
|
48 | ||
|
49 | config.add_route( | |
|
43 | 50 | name='admin_settings_sessions', |
|
44 | 51 | pattern=ADMIN_PREFIX + '/settings/sessions') |
|
45 | 52 | config.add_route( |
@@ -503,12 +503,6 b' def make_map(config):' | |||
|
503 | 503 | m.connect('admin_settings_search', '/settings/search', |
|
504 | 504 | action='settings_search', conditions={'method': ['GET']}) |
|
505 | 505 | |
|
506 | m.connect('admin_settings_system', '/settings/system', | |
|
507 | action='settings_system', conditions={'method': ['GET']}) | |
|
508 | ||
|
509 | m.connect('admin_settings_system_update', '/settings/system/updates', | |
|
510 | action='settings_system_update', conditions={'method': ['GET']}) | |
|
511 | ||
|
512 | 506 | m.connect('admin_settings_supervisor', '/settings/supervisor', |
|
513 | 507 | action='settings_supervisor', conditions={'method': ['GET']}) |
|
514 | 508 | m.connect('admin_settings_supervisor_log', '/settings/supervisor/{procid}/log', |
@@ -25,15 +25,13 b' settings controller for rhodecode admin' | |||
|
25 | 25 | |
|
26 | 26 | import collections |
|
27 | 27 | import logging |
|
28 | import urllib2 | |
|
29 | 28 | |
|
30 | 29 | import datetime |
|
31 | 30 | import formencode |
|
32 | 31 | from formencode import htmlfill |
|
33 | import packaging.version | |
|
34 | 32 | from pylons import request, tmpl_context as c, url, config |
|
35 | 33 | from pylons.controllers.util import redirect |
|
36 |
from pylons.i18n.translation import _ |
|
|
34 | from pylons.i18n.translation import _ | |
|
37 | 35 | from pyramid.threadlocal import get_current_registry |
|
38 | 36 | from webob.exc import HTTPBadRequest |
|
39 | 37 | |
@@ -48,7 +46,6 b' from rhodecode.lib.utils import repo2db_' | |||
|
48 | 46 | from rhodecode.lib.utils2 import ( |
|
49 | 47 | str2bool, safe_unicode, AttributeDict, safe_int) |
|
50 | 48 | from rhodecode.lib.compat import OrderedDict |
|
51 | from rhodecode.lib.ext_json import json | |
|
52 | 49 | from rhodecode.lib.utils import jsonify |
|
53 | 50 | |
|
54 | 51 | from rhodecode.model.db import RhodeCodeUi, Repository |
@@ -544,153 +541,6 b' class SettingsController(BaseController)' | |||
|
544 | 541 | return render('admin/settings/settings.mako') |
|
545 | 542 | |
|
546 | 543 | @HasPermissionAllDecorator('hg.admin') |
|
547 | def settings_system(self): | |
|
548 | """GET /admin/settings/system: All items in the collection""" | |
|
549 | # url('admin_settings_system') | |
|
550 | snapshot = str2bool(request.GET.get('snapshot')) | |
|
551 | defaults = self._form_defaults() | |
|
552 | ||
|
553 | c.active = 'system' | |
|
554 | c.rhodecode_update_url = defaults.get('rhodecode_update_url') | |
|
555 | server_info = ScmModel().get_server_info(request.environ) | |
|
556 | ||
|
557 | for key, val in server_info.iteritems(): | |
|
558 | setattr(c, key, val) | |
|
559 | ||
|
560 | def val(name, subkey='human_value'): | |
|
561 | return server_info[name][subkey] | |
|
562 | ||
|
563 | def state(name): | |
|
564 | return server_info[name]['state'] | |
|
565 | ||
|
566 | def val2(name): | |
|
567 | val = server_info[name]['human_value'] | |
|
568 | state = server_info[name]['state'] | |
|
569 | return val, state | |
|
570 | ||
|
571 | c.data_items = [ | |
|
572 | # update info | |
|
573 | (_('Update info'), h.literal( | |
|
574 | '<span class="link" id="check_for_update" >%s.</span>' % ( | |
|
575 | _('Check for updates')) + | |
|
576 | '<br/> <span >%s.</span>' % (_('Note: please make sure this server can access `%s` for the update link to work') % c.rhodecode_update_url) | |
|
577 | ), ''), | |
|
578 | ||
|
579 | # RhodeCode specific | |
|
580 | (_('RhodeCode Version'), val('rhodecode_app')['text'], state('rhodecode_app')), | |
|
581 | (_('RhodeCode Server IP'), val('server')['server_ip'], state('server')), | |
|
582 | (_('RhodeCode Server ID'), val('server')['server_id'], state('server')), | |
|
583 | (_('RhodeCode Configuration'), val('rhodecode_config')['path'], state('rhodecode_config')), | |
|
584 | ('', '', ''), # spacer | |
|
585 | ||
|
586 | # Database | |
|
587 | (_('Database'), val('database')['url'], state('database')), | |
|
588 | (_('Database version'), val('database')['version'], state('database')), | |
|
589 | ('', '', ''), # spacer | |
|
590 | ||
|
591 | # Platform/Python | |
|
592 | (_('Platform'), val('platform')['name'], state('platform')), | |
|
593 | (_('Platform UUID'), val('platform')['uuid'], state('platform')), | |
|
594 | (_('Python version'), val('python')['version'], state('python')), | |
|
595 | (_('Python path'), val('python')['executable'], state('python')), | |
|
596 | ('', '', ''), # spacer | |
|
597 | ||
|
598 | # Systems stats | |
|
599 | (_('CPU'), val('cpu'), state('cpu')), | |
|
600 | (_('Load'), val('load')['text'], state('load')), | |
|
601 | (_('Memory'), val('memory')['text'], state('memory')), | |
|
602 | (_('Uptime'), val('uptime')['text'], state('uptime')), | |
|
603 | ('', '', ''), # spacer | |
|
604 | ||
|
605 | # Repo storage | |
|
606 | (_('Storage location'), val('storage')['path'], state('storage')), | |
|
607 | (_('Storage info'), val('storage')['text'], state('storage')), | |
|
608 | (_('Storage inodes'), val('storage_inodes')['text'], state('storage_inodes')), | |
|
609 | ||
|
610 | (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')), | |
|
611 | (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')), | |
|
612 | ||
|
613 | (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')), | |
|
614 | (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')), | |
|
615 | ||
|
616 | (_('Temp storage location'), val('storage_temp')['path'], state('storage_temp')), | |
|
617 | (_('Temp storage info'), val('storage_temp')['text'], state('storage_temp')), | |
|
618 | ||
|
619 | (_('Search info'), val('search')['text'], state('search')), | |
|
620 | (_('Search location'), val('search')['location'], state('search')), | |
|
621 | ('', '', ''), # spacer | |
|
622 | ||
|
623 | # VCS specific | |
|
624 | (_('VCS Backends'), val('vcs_backends'), state('vcs_backends')), | |
|
625 | (_('VCS Server'), val('vcs_server')['text'], state('vcs_server')), | |
|
626 | (_('GIT'), val('git'), state('git')), | |
|
627 | (_('HG'), val('hg'), state('hg')), | |
|
628 | (_('SVN'), val('svn'), state('svn')), | |
|
629 | ||
|
630 | ] | |
|
631 | ||
|
632 | # TODO: marcink, figure out how to allow only selected users to do this | |
|
633 | c.allowed_to_snapshot = c.rhodecode_user.admin | |
|
634 | ||
|
635 | if snapshot: | |
|
636 | if c.allowed_to_snapshot: | |
|
637 | c.data_items.pop(0) # remove server info | |
|
638 | return render('admin/settings/settings_system_snapshot.mako') | |
|
639 | else: | |
|
640 | h.flash('You are not allowed to do this', category='warning') | |
|
641 | ||
|
642 | return htmlfill.render( | |
|
643 | render('admin/settings/settings.mako'), | |
|
644 | defaults=defaults, | |
|
645 | encoding="UTF-8", | |
|
646 | force_defaults=False) | |
|
647 | ||
|
648 | @staticmethod | |
|
649 | def get_update_data(update_url): | |
|
650 | """Return the JSON update data.""" | |
|
651 | ver = rhodecode.__version__ | |
|
652 | log.debug('Checking for upgrade on `%s` server', update_url) | |
|
653 | opener = urllib2.build_opener() | |
|
654 | opener.addheaders = [('User-agent', 'RhodeCode-SCM/%s' % ver)] | |
|
655 | response = opener.open(update_url) | |
|
656 | response_data = response.read() | |
|
657 | data = json.loads(response_data) | |
|
658 | ||
|
659 | return data | |
|
660 | ||
|
661 | @HasPermissionAllDecorator('hg.admin') | |
|
662 | def settings_system_update(self): | |
|
663 | """GET /admin/settings/system/updates: All items in the collection""" | |
|
664 | # url('admin_settings_system_update') | |
|
665 | defaults = self._form_defaults() | |
|
666 | update_url = defaults.get('rhodecode_update_url', '') | |
|
667 | ||
|
668 | _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">%s</div>' % (s) | |
|
669 | try: | |
|
670 | data = self.get_update_data(update_url) | |
|
671 | except urllib2.URLError as e: | |
|
672 | log.exception("Exception contacting upgrade server") | |
|
673 | return _err('Failed to contact upgrade server: %r' % e) | |
|
674 | except ValueError as e: | |
|
675 | log.exception("Bad data sent from update server") | |
|
676 | return _err('Bad data sent from update server') | |
|
677 | ||
|
678 | latest = data['versions'][0] | |
|
679 | ||
|
680 | c.update_url = update_url | |
|
681 | c.latest_data = latest | |
|
682 | c.latest_ver = latest['version'] | |
|
683 | c.cur_ver = rhodecode.__version__ | |
|
684 | c.should_upgrade = False | |
|
685 | ||
|
686 | if (packaging.version.Version(c.latest_ver) > | |
|
687 | packaging.version.Version(c.cur_ver)): | |
|
688 | c.should_upgrade = True | |
|
689 | c.important_notices = latest['general'] | |
|
690 | ||
|
691 | return render('admin/settings/settings_system_update.mako') | |
|
692 | ||
|
693 | @HasPermissionAllDecorator('hg.admin') | |
|
694 | 544 | def settings_supervisor(self): |
|
695 | 545 | c.rhodecode_ini = rhodecode.CONFIG |
|
696 | 546 | c.active = 'supervisor' |
@@ -8,7 +8,7 b'' | |||
|
8 | 8 | <div class="panel-heading"> |
|
9 | 9 | <h3 class="panel-title">${_('System Info')}</h3> |
|
10 | 10 | % if c.allowed_to_snapshot: |
|
11 |
<a href="${ |
|
|
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"> |
@@ -52,6 +52,6 b'' | |||
|
52 | 52 | <script> |
|
53 | 53 | $('#check_for_update').click(function(e){ |
|
54 | 54 | $('#update_notice').show(); |
|
55 |
$('#update_notice').load("${h. |
|
|
55 | $('#update_notice').load("${h.route_path('admin_settings_system_update',version=c.rhodecode_version, platform=c.platform)}"); | |
|
56 | 56 | }) |
|
57 | 57 | </script> |
General Comments 0
You need to be logged in to leave comments.
Login now