diff options
Diffstat (limited to 'pages/pair.inc')
-rw-r--r-- | pages/pair.inc | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/pages/pair.inc b/pages/pair.inc index 7f57420..fa301ad 100644 --- a/pages/pair.inc +++ b/pages/pair.inc @@ -21,9 +21,15 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; glob <p>Pairing allows a connected device that cannot normally use Cold Haze to gather data. This device will get full access to your account as if they were acting on your behalf, so make sure you trust the device and/or application you are using.</p> + <?php $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $_COOKIE['PEH2_SESSION_TOKEN'])), true); if (isset($data["profile"])): ?> <p>Equestria.dev may not have verified the application you use, always check for a signature. Enter the pairing code displayed on your device below:</p> <input autofocus type="text" placeholder="Pairing code" class="form-control" style="margin-bottom:15px;color:white;background:#111;border-color:#222;" id="code"> + <?php else: ?> + <div class="alert alert-danger"> + <b>Error:</b> You cannot use the pairing feature because your current session is using the old authentication system. Please log out and log in again to continue. + </div> + <?php endif; ?> </div> <div class="modal fade" id="confirm"> @@ -39,7 +45,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; glob <p>You are about to pair the following device with your Cold Haze account:</p> <blockquote style="display: grid; grid-template-columns: max-content 1fr; grid-gap: 10px;"> <div style="display: flex; align-items: center; justify-content: center;"> - <img src="/assets/logo/newlogo3.png" style="width: 32px; height: 32px;"> + <img src="/assets/logo/newlogo3.png" id="device-icon" style="width: 32px; height: 32px;"> </div> <div> <b>Name:</b> <span id="device-name">-</span><br> @@ -82,12 +88,30 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; glob <script> const modal = new bootstrap.Modal(document.getElementById("confirm")); + function getIconForName(name) { + if (name.startsWith("Luna Desktop ")) { + return "https://git.equestria.dev/equestria.dev/luna/raw/branch/mane/icons/logo.png"; + } + + if (name.startsWith("Cold Haze for Wear OS ")) { + return "https://static.equestria.horse/ch-wear.png"; + } + + return "/assets/logo/newlogo3.png"; + } + (async () => { const token = await (await fetch("/api/token")).text(); let ws = window.ws = new WebSocket("wss://ponies.equestria.horse/_PairingServices-WebSocket-EntryPoint/socket"); ws.onopen = (event) => { console.log(event); + + if (location.hash && location.hash.startsWith("#/")) { + document.getElementById("code").value = location.hash.substring(2); + document.getElementById("code").onkeydown(); + location.hash = ""; + } } ws.onclose = (event) => { @@ -109,8 +133,9 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; glob modal.hide(); document.getElementById("code").focus(); } else if (data.type === "device") { - document.getElementById("device-name").innerText = document.getElementById("paired-name-1").innerText = document.getElementById("paired-name-2").innerText = data.identity.name; + document.getElementById("device-name").innerText = document.getElementById("paired-name-1").innerText = document.getElementById("paired-name-2").innerText = window.currentName = data.identity.name; document.getElementById("device-address").innerText = data.identity.address; + document.getElementById("device-icon").src = getIconForName(data.identity.name ?? ""); document.getElementById("modal-button").classList.add("disabled"); modal.show(); @@ -134,6 +159,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; glob } window.currentCode = null; + window.currentName = ""; function pair(code) { const ua = new UAParser(navigator.userAgent).getResult(); @@ -162,7 +188,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; glob ws.send(JSON.stringify({ type: "confirm", code: window.currentCode, - token: (await (await fetch("/api/reauthenticate")).text()).trim() + token: (await (await fetch("/api/reauthenticate/?name=" + encodeURIComponent(btoa(window.currentName)))).text()).trim() })); } |