diff --git a/jumpserver/views.py b/jumpserver/views.py index b95c314b4..7aa51dcac 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -344,7 +344,7 @@ def download(request): def exec_cmd(request): role = request.GET.get('role') check_assets = request.GET.get('check_assets', '') - web_terminal_uri = '%s/exec?role=%s' % (WEB_SOCKET_HOST, role) + web_terminal_uri = '/ws/exec?role=%s' % (role) return my_render('exec_cmd.html', locals(), request) @@ -356,7 +356,8 @@ def web_terminal(request): if asset: print asset hostname = asset.hostname - web_terminal_uri = '%s/ws/terminal?id=%s&role=%s' % (WEB_SOCKET_HOST, asset_id, role_name) + # web_terminal_uri = '%s/ws/terminal?id=%s&role=%s' % (WEB_SOCKET_HOST, asset_id, role_name) + web_terminal_uri = '/ws/terminal?id=%s&role=%s' % (asset_id, role_name) return render_to_response('jlog/web_terminal.html', locals()) diff --git a/run_websocket.py b/run_websocket.py index 0f758b947..7f0e21469 100755 --- a/run_websocket.py +++ b/run_websocket.py @@ -442,7 +442,7 @@ def main(): (r'/monitor', MonitorHandler), (r'/ws/terminal', WebTerminalHandler), (r'/kill', WebTerminalKillHandler), - (r'/exec', ExecHandler), + (r'/ws/exec', ExecHandler), (r"/static/(.*)", tornado.web.StaticFileHandler, dict(path=os.path.join(os.path.dirname(__file__), "static"))), ('.*', tornado.web.FallbackHandler, dict(fallback=container)), diff --git a/templates/exec_cmd.html b/templates/exec_cmd.html index d1eda2fcb..2316229e8 100644 --- a/templates/exec_cmd.html +++ b/templates/exec_cmd.html @@ -29,7 +29,7 @@ protocol = 'wss://'; } - var wsUri = protocol + "{{ web_terminal_uri }}"; //请求的websocket url + var wsUri = protocol + document.URL.match(RegExp('//(.*?)/'))[1] + "{{ web_terminal_uri }}"; //请求的websocket url var ws = new WebSocket(wsUri); function createSystemMessage(message) { diff --git a/templates/jlog/web_terminal.html b/templates/jlog/web_terminal.html index 420249a10..547002f19 100644 --- a/templates/jlog/web_terminal.html +++ b/templates/jlog/web_terminal.html @@ -48,7 +48,7 @@ protocol = 'wss://'; } - var endpoint = protocol + '{{ web_terminal_uri }}'; + var endpoint = protocol + document.URL.match(RegExp('//(.*?)/'))[1] + '{{ web_terminal_uri }}'; if (window.WebSocket) { this._connection = new WebSocket(endpoint);