From 5c645207f86364d94a0b26e4beb43896f9c4b13b Mon Sep 17 00:00:00 2001 From: SeungYongShim Date: Sat, 2 Mar 2024 20:27:10 +0900 Subject: [PATCH] The most significant changes involve the modification of the `WebsockifyMiddleware.cs` and `ui.js` files to accept `vnc_host` and `vnc_port` as query parameters from the request, replacing the previously hardcoded `_hostname` and `_port`. Additionally, the `vnc.html` file has been updated to include input fields for `vnc_host` and `vnc_port`, enabling the user to specify these values in the UI. 1. The `WebsockifyMiddleware.cs` file has been updated to accept `vnc_host` and `vnc_port` as query parameters from the request. This replaces the previously hardcoded `_hostname` and `_port`. The `TcpClient` and `NetworkStream` objects are now wrapped in a `using` statement for better resource management. 2. The `ui.js` file has been modified so that the `UI` object initializes `vnc_host` and `vnc_port` settings from the URL. These settings are then retrieved and appended to the URL when creating a new `RFB` object. 3. The `vnc.html` file has been updated to include input fields for `vnc_host` and `vnc_port`. This allows the user to specify these values in the UI. --- src/VncApp/Middleware/WebsockifyMiddleware.cs | 9 ++++++--- src/VncApp/wwwroot/app/ui.js | 10 +++++++++- src/VncApp/wwwroot/vnc.html | 8 ++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/VncApp/Middleware/WebsockifyMiddleware.cs b/src/VncApp/Middleware/WebsockifyMiddleware.cs index 93e2153..194c3e1 100644 --- a/src/VncApp/Middleware/WebsockifyMiddleware.cs +++ b/src/VncApp/Middleware/WebsockifyMiddleware.cs @@ -41,11 +41,14 @@ public async Task InvokeAsync(HttpContext context) WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(); - TcpClient tcpClient = new TcpClient(); + var vncHost = context.Request.Query["vnc_host"][0]; + var vncPort = context.Request.Query["vnc_port"][0]; - tcpClient.Connect(_hostname, _port); + using TcpClient tcpClient = new TcpClient(); - NetworkStream networkStream = tcpClient.GetStream(); + tcpClient.Connect(vncHost, int.Parse(vncPort)); + + using NetworkStream networkStream = tcpClient.GetStream(); Task receiveTask = Task.Run(async () => { diff --git a/src/VncApp/wwwroot/app/ui.js b/src/VncApp/wwwroot/app/ui.js index c1f6776..21e7e24 100644 --- a/src/VncApp/wwwroot/app/ui.js +++ b/src/VncApp/wwwroot/app/ui.js @@ -169,7 +169,10 @@ const UI = { } } - /* Populate the controls if defaults are provided in the URL */ + /* Populate the controls if defaults are provided in the URL */ + UI.initSetting('vnc_host', window.location.hostname); + UI.initSetting('vnc_port', port); + UI.initSetting('host', window.location.hostname); UI.initSetting('port', port); UI.initSetting('encrypt', (window.location.protocol === "https:")); @@ -1010,6 +1013,10 @@ const UI = { const port = UI.getSetting('port'); const path = UI.getSetting('path'); + const vnc_host = UI.getSetting('vnc_host'); + const vnc_port = UI.getSetting('vnc_port'); + + if (typeof password === 'undefined') { password = WebUtil.getConfigVar('password'); UI.reconnectPassword = password; @@ -1040,6 +1047,7 @@ const UI = { url += ':' + port; } url += '/' + path; + url += '?' + 'vnc_host=' + vnc_host + '&vnc_port=' + vnc_port; UI.rfb = new RFB(document.getElementById('noVNC_container'), url, { shared: UI.getSetting('shared'), diff --git a/src/VncApp/wwwroot/vnc.html b/src/VncApp/wwwroot/vnc.html index 24a118d..e52232e 100644 --- a/src/VncApp/wwwroot/vnc.html +++ b/src/VncApp/wwwroot/vnc.html @@ -203,6 +203,14 @@

no
VNC

+
  • + + +
  • +
  • + + +