From 69f9634a111a2d20fbcbfd85852a39d1820ae44a Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 26 Jan 2021 15:09:28 -0300 Subject: [PATCH] bootstrap less ugly gui --- README.md | 4 +- src/main/resources/web/auth.html | 61 -------------------- src/main/resources/web/auth.js | 68 ++++++++++++---------- src/main/resources/web/auth_ms.js | 2 +- src/main/resources/web/index.html | 93 ++++++++++++++++++++++++++++--- src/main/resources/web/style.css | 23 -------- 6 files changed, 127 insertions(+), 124 deletions(-) delete mode 100644 src/main/resources/web/auth.html delete mode 100644 src/main/resources/web/style.css diff --git a/README.md b/README.md index 008fdbe..edd68a3 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Usage for offline mode: Usage for online mode with two accounts (recommended): - Run the shadow jar or ./gradlew clean run - You should set up a CORS Proxy (something like https://github.com/Rob--W/cors-anywhere) on local machine. -- Go to https://localhost:25543/auth.html, configure the CORS Proxy URL (something like http://localhost:8080/, +- Go to https://localhost:25543/, configure the CORS Proxy URL (something like http://localhost:8080/, note the ending slash) and listen to the username A that you're using to connect to the proxy. - Add the account B you'll use in _u parameter to browser auth page. - Connect to mc.example.com._v1_8._u(account B).viaaas.localhost @@ -34,7 +34,7 @@ Usage for online mode with two accounts (recommended): Usage for online mode with one account: - Run the shadow jar or ./gradlew clean run - You should set up a CORS Proxy (something like https://github.com/Rob--W/cors-anywhere) on local machine. -- Go to https://localhost:25543/auth.html, configure the CORS Proxy URL (something like http://localhost:8080/, +- Go to https://localhost:25543/, configure the CORS Proxy URL (something like http://localhost:8080/, note the ending slash) and listen to the username. - Add the account to browser auth page. - Connect to mc.example.com._v1_8.viaaas.localhost diff --git a/src/main/resources/web/auth.html b/src/main/resources/web/auth.html deleted file mode 100644 index 8cb3a30..0000000 --- a/src/main/resources/web/auth.html +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - VIAaaS Authenticator - - - - - - - -
-

Browser Minecraft accounts:

-

- -
- -

-

-


- -
-
- -
- -
- -
- -

- -

-
-
-
-

DO NOT TYPE YOUR CREDENTIALS IF YOU DON'T TRUST THIS VIAAAS INSTANCE OR THE CORS PROXY!

-

Mojang API calls in browser are called through a CORS Proxy. See - https://github.com/Rob--W/cors-anywhere - for setting up one. Calling Mojang API from a remote IP address may block your account.

-

WebSocket connection status: ?

-
-

-

-
- - - diff --git a/src/main/resources/web/auth.js b/src/main/resources/web/auth.js index 8393acb..76ba976 100644 --- a/src/main/resources/web/auth.js +++ b/src/main/resources/web/auth.js @@ -6,20 +6,23 @@ if (urlParams.get("mcauth_success") == "false") { alert("Couldn't authenticate with Minecraft.ID: " + urlParams.get("mcauth_msg")); } -function askWsUrl() { - let url = localStorage.getItem("ws-url") || "wss://localhost:25543/ws"; - url = prompt("VIAaaS instance websocket", url) || url; +function defaultWs() { + return window.location.host == "viaversion.github.io" || !window.location.host ? "wss://localhost:25543/ws" : "wss://" + window.location.host + "/ws"; +} + +function getWsUrl() { + let url = localStorage.getItem("ws-url") || defaultWs(); localStorage.setItem("ws-url", url); return url; } -var wsUrl = window.location.host == "viaversion.github.io" ? askWsUrl() : "wss://" + window.location.host + "/ws"; +var wsUrl = getWsUrl(); var socket = null; var connectionStatus = document.getElementById("connection_status"); var listening = document.getElementById("listening"); var actions = document.getElementById("actions"); -var acounts = document.getElementById("accounts"); +var accounts = document.getElementById("accounts-list"); var listenVisible = false; isSuccess = status => status >= 200 && status < 300; @@ -214,33 +217,35 @@ function getTokens() { function renderActions() { actions.innerHTML = ""; - if (username != null && mcauth_code != null) { + if (listenVisible) { + if (username != null && mcauth_code != null) { + let p = document.createElement("p"); + let add = document.createElement("a"); + p.appendChild(add); + add.innerText = "Listen to " + username; + add.href = "#"; + add.onclick = () => { + socket.send(JSON.stringify({ + "action": "minecraft_id_login", + "username": username, + "code": mcauth_code})); + mcauth_code = null; + }; + actions.appendChild(p); + } let p = document.createElement("p"); - let add = document.createElement("a"); - p.appendChild(add); - add.innerText = "Listen to " + username; - add.href = "#"; - add.onclick = () => { - socket.send(JSON.stringify({ - "action": "minecraft_id_login", - "username": username, - "code": mcauth_code})); - mcauth_code = null; + let link = document.createElement("a"); + p.appendChild(link); + link.innerText = "Listen to username in VIAaaS instance"; + link.href = "#"; + link.onclick = () => { + let user = prompt("Username (Minecraft.ID is case-sensitive): ", ""); + if (!user) return; + let callbackUrl = new URL(location.origin + location.pathname + "#username=" + encodeURIComponent(user)); + location = "https://api.minecraft.id/gateway/start/" + encodeURIComponent(user) + "?callback=" + encodeURIComponent(callbackUrl); }; actions.appendChild(p); } - let p = document.createElement("p"); - let link = document.createElement("a"); - p.appendChild(link); - link.innerText = "Listen to username in VIAaaS instance"; - link.href = "#"; - link.onclick = () => { - let user = prompt("Username (Minecraft.ID is case-sensitive): ", ""); - if (!user) return; - let callbackUrl = new URL(location.origin + location.pathname + "#username=" + encodeURIComponent(user)); - location = "https://api.minecraft.id/gateway/start/" + encodeURIComponent(user) + "?callback=" + encodeURIComponent(callbackUrl); - }; - actions.appendChild(p); } function onSocketMsg(event) { @@ -321,8 +326,13 @@ function connect() { $(() => { - $("#cors-proxy").on("change", () => localStorage.setItem('cors-proxy', $("#cors-proxy").val())); + $("#cors-proxy").on("change", () => localStorage.setItem("cors-proxy", $("#cors-proxy").val())); $("#cors-proxy").val(getCorsProxy()); + $("#ws-url").on("change", () => { + localStorage.setItem("ws-url", $("#ws-url").val()); + location.reload(); + }); + $("#ws-url").val(getWsUrl()); $("#login_submit_mc").on("click", () => loginMc($("#email").val(), $("#password").val())); $("#login_submit_ms").on("click", loginMs); diff --git a/src/main/resources/web/auth_ms.js b/src/main/resources/web/auth_ms.js index 39c8e25..ab339f7 100644 --- a/src/main/resources/web/auth_ms.js +++ b/src/main/resources/web/auth_ms.js @@ -1,7 +1,7 @@ // https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-javascript-auth-code const redirectUrl = location.origin == "https://localhost:25543" ? -"https://localhost:25543/auth.html" : "https://viaversion.github.io/VIAaaS/src/main/resources/web/auth.html"; +"https://localhost:25543/" : "https://viaversion.github.io/VIAaaS/src/main/resources/web/"; const msalConfig = { auth: { diff --git a/src/main/resources/web/index.html b/src/main/resources/web/index.html index e67f7ad..4d930fb 100644 --- a/src/main/resources/web/index.html +++ b/src/main/resources/web/index.html @@ -5,18 +5,95 @@ - - - + + + - - + + + + VIAaaS - ViaVersion as a Service + + + + + + -

VIAaaS

-

Authenticator

-

Source code

+ +
+
+

DO NOT TYPE YOUR CREDENTIALS IF YOU DON'T TRUST THIS VIAAAS INSTANCE OR THE CORS PROXY!

+

Mojang API calls in browser are called through a CORS Proxy. See + https://github.com/Rob--W/cors-anywhere + for setting up one. Calling Mojang API from a remote IP address may block your account.

+

WebSocket connection status: ?

+
+

+

+
+ +
+
+ + +
+
+ + +
+
+ +
+

Browser Minecraft accounts:

+
+
+
+ +
+
+ + +
+
+ + +
+ +
+
+
+ diff --git a/src/main/resources/web/style.css b/src/main/resources/web/style.css deleted file mode 100644 index f58bb1c..0000000 --- a/src/main/resources/web/style.css +++ /dev/null @@ -1,23 +0,0 @@ -body { - word-break: break-word; - font-family: sans-serif; -} -@media (min-width: 700px) { - #browser_accounts { - float: right; - width: 300px; - } -} -#browser_accounts { - text-align: center; - display: inline-block; - border: 1px solid black; - padding: 10px; -} -#connection_status { - background: black; - color: white; -} -.account_head { - width: 16px; -}