diff --git a/jlog/views.py b/jlog/views.py index 82a4891e7..472f2c3b7 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -104,6 +104,7 @@ def log_record(request): return HttpResponse('无日志记录!') +@require_role('user') def get_role_name(request): asset_id = request.GET.get('id', 9999) asset = get_object(Asset, id=asset_id) @@ -113,9 +114,10 @@ def get_role_name(request): return HttpResponse('error') -@require_role() +@require_role('user') def web_terminal(request): asset_id = request.GET.get('id') - web_terminal_uri = 'ws://%s/terminal?id=%s&role=dev' % (WEB_SOCKET_HOST, asset_id) + role_name = request.GET.get('role') + web_terminal_uri = 'ws://%s/terminal?id=%s&role=%s' % (WEB_SOCKET_HOST, asset_id, role_name) return render_to_response('jlog/web_terminal.html', locals()) diff --git a/jumpserver/api.py b/jumpserver/api.py index cbf7eebc8..7e2a0d0ef 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -59,7 +59,7 @@ def get_asset_info(asset): else: info['port'] = asset.port info['username'] = asset.username - info['password'] = asset.password + info['password'] = CRYPTOR.decrypt(asset.password) return info diff --git a/run_websocket.py b/run_websocket.py index 6963c1701..02b132f2d 100644 --- a/run_websocket.py +++ b/run_websocket.py @@ -257,12 +257,16 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): login_role = role break if not login_role: - logger.warning('Websocket: Not that Role %s for Host: %s User: %s ' % (role_name, asset.name, + logger.warning('Websocket: Not that Role %s for Host: %s User: %s ' % (role_name, asset.hostname, self.user.username)) self.close() return - logger.debug('Websocket: request web terminal Host: %s User: %s Role: %s' % ()) - # Todo: 判断 + else: + logger.warning('Websocket: No that Host: %s User: %s ' % (asset_id, self.user.username)) + self.close() + return + logger.debug('Websocket: request web terminal Host: %s User: %s Role: %s' % (asset.hostname, self.user.username, + login_role.name)) self.term = WebTty(self.user, self.asset, login_role) self.term.get_connection() self.term.channel = self.term.ssh.invoke_shell(term='xterm')