From 84b31a596d4987bd8027a83238197fab34b56c30 Mon Sep 17 00:00:00 2001 From: Haozhe Xie Date: Thu, 14 Nov 2024 13:06:48 +0800 Subject: [PATCH 1/6] fix: change to relative path for URLs. --- web/index.html | 6 +++--- web/js/script.js | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/web/index.html b/web/index.html index 0f10e136..6e66037b 100644 --- a/web/index.html +++ b/web/index.html @@ -5,8 +5,8 @@ [1] - - + + [2] @@ -28,7 +28,7 @@

[3]

[5] - + diff --git a/web/js/script.js b/web/js/script.js index 8855a79a..81bd3580 100644 --- a/web/js/script.js +++ b/web/js/script.js @@ -21,7 +21,7 @@ var webSocketFactory = { function getInfo() { - var url = "/msg.html"; + var url = "msg.html"; try { if (window.XMLHttpRequest) { @@ -69,7 +69,11 @@ function processInfo() { if (notFound) { setInfo("Connecting to VNC", true); - var webSocket = webSocketFactory.connect("ws://" + window.location.host + "/websockify"); + var protocol = window.location.protocol === "https:" ? "wss:" : "ws:", + wsHref = window.location.href.replace(window.location.protocol, protocol), + wsUrl = wsHref + "websockify", + webSocket = webSocketFactory.connect(wsUrl); + return true; } From f61999a08283277a467d033a9c908d15ee9312f7 Mon Sep 17 00:00:00 2001 From: Haozhe Xie Date: Thu, 14 Nov 2024 15:03:54 +0800 Subject: [PATCH 2/6] fix: change the default URL for websockify in noVNC. --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index e79fd022..560cd2bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,7 @@ RUN set -eu && \ tar -xf /tmp/novnc.tar.gz -C /tmp/ && \ cd "/tmp/noVNC-${VERSION_VNC}" && \ mv app core vendor package.json *.html /usr/share/novnc && \ + sed -i "s|UI\.initSetting('path', 'websockify')|UI.initSetting('path', window.location.pathname.replace(/[^/]*$/, '').substring(1) + 'websockify')|" /usr/share/novnc/app/ui.js && \ unlink /etc/nginx/sites-enabled/default && \ sed -i 's/^worker_processes.*/worker_processes 1;/' /etc/nginx/nginx.conf && \ echo "$VERSION_ARG" > /run/version && \ From 6a27e0f7edace5de0223147d9d7bcd0dd4a08ee6 Mon Sep 17 00:00:00 2001 From: Haozhe Xie Date: Thu, 14 Nov 2024 18:32:24 +0800 Subject: [PATCH 3/6] fix: prevent the NGINX redirect to /. --- web/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/nginx.conf b/web/nginx.conf index be644131..f91babc5 100644 --- a/web/nginx.conf +++ b/web/nginx.conf @@ -40,7 +40,7 @@ server { index vnc.html; if ($request_uri = "/") { - return 301 /?resize=scale&reconnect=true&autoconnect=true; + return 301 ?resize=scale&reconnect=true&autoconnect=true; } } From f2b009cd7050bf3f6bf0f056282dd0dbd581c5f8 Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 15 Nov 2024 02:59:51 +0100 Subject: [PATCH 4/6] fix: Strip filename from path --- web/js/script.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/web/js/script.js b/web/js/script.js index 81bd3580..7881b4df 100644 --- a/web/js/script.js +++ b/web/js/script.js @@ -69,11 +69,27 @@ function processInfo() { if (notFound) { setInfo("Connecting to VNC", true); - var protocol = window.location.protocol === "https:" ? "wss:" : "ws:", - wsHref = window.location.href.replace(window.location.protocol, protocol), - wsUrl = wsHref + "websockify", - webSocket = webSocketFactory.connect(wsUrl); + var path = window.location.href; + var protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; + + // Is this a file-like path, e.g. http.../foo.bar? + const regex = /^(.*)\/([^.]+(\.([^\/?#]+))+)(\?[^#]*)?(#.*)?$/; + const match = path.match(regex); + + // Only if it is, do we cut that part off: + if (match !== null) { + const { [1]:dirname, [2]:file, [4]:ext } = match; + path = dirname; + } + + if (!path.endsWith('/')) { + path = path + '/' + } + + path = path.replace(window.location.protocol, protocol); + var webSocket = webSocketFactory.connect(path + "websockify"); + return true; } From 7481286f740465034df8927c3838e95893f3741b Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 15 Nov 2024 03:11:05 +0100 Subject: [PATCH 5/6] Update script.js --- web/js/script.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/web/js/script.js b/web/js/script.js index 7881b4df..bc932bae 100644 --- a/web/js/script.js +++ b/web/js/script.js @@ -70,7 +70,7 @@ function processInfo() { if (notFound) { setInfo("Connecting to VNC", true); - var path = window.location.href; + var path = window.location.href.split("#")[0].split("?")[0]; var protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; // Is this a file-like path, e.g. http.../foo.bar? @@ -82,13 +82,9 @@ function processInfo() { const { [1]:dirname, [2]:file, [4]:ext } = match; path = dirname; } - - if (!path.endsWith('/')) { - path = path + '/' - } path = path.replace(window.location.protocol, protocol); - var webSocket = webSocketFactory.connect(path + "websockify"); + var webSocket = webSocketFactory.connect(path.replace(/\/$/, '') + "/websockify"); return true; } From 7fff91ea6d5d0568ba2fb99131f4069c77cf8c33 Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 15 Nov 2024 03:46:18 +0100 Subject: [PATCH 6/6] Update script.js --- web/js/script.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/web/js/script.js b/web/js/script.js index bc932bae..bfa42301 100644 --- a/web/js/script.js +++ b/web/js/script.js @@ -70,21 +70,10 @@ function processInfo() { if (notFound) { setInfo("Connecting to VNC", true); - var path = window.location.href.split("#")[0].split("?")[0]; var protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; - - // Is this a file-like path, e.g. http.../foo.bar? - const regex = /^(.*)\/([^.]+(\.([^\/?#]+))+)(\?[^#]*)?(#.*)?$/; - const match = path.match(regex); - - // Only if it is, do we cut that part off: - if (match !== null) { - const { [1]:dirname, [2]:file, [4]:ext } = match; - path = dirname; - } - - path = path.replace(window.location.protocol, protocol); - var webSocket = webSocketFactory.connect(path.replace(/\/$/, '') + "/websockify"); + var path = window.location.pathname.replace(/[^/]*$/, '').replace(/\/$/, ''); + var wsUrl = protocol + "//" + window.location.host + path + "/websockify"; + var webSocket = webSocketFactory.connect(wsUrl); return true; }