From 35c167503db228be767c0b50e28108f4ba96a090 Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Thu, 25 Jul 2024 22:15:11 -0500 Subject: [PATCH 1/2] Add WispServerTiming.ts, begin work on a dropdown that shows wisp servers and their ping --- src/components/SettingsContent/ProxyTab.astro | 9 ++- src/components/ts/WispServerTiming.ts | 49 +++++++++++++ src/pages/[lang]/index.astro | 1 + src/pages/[lang]/settings.astro | 73 ++++++++++--------- src/types.d.ts | 10 +++ 5 files changed, 106 insertions(+), 36 deletions(-) create mode 100644 src/components/ts/WispServerTiming.ts diff --git a/src/components/SettingsContent/ProxyTab.astro b/src/components/SettingsContent/ProxyTab.astro index 6dda0b3..e4caf17 100644 --- a/src/components/SettingsContent/ProxyTab.astro +++ b/src/components/SettingsContent/ProxyTab.astro @@ -29,6 +29,11 @@ const transportsList = [ { name: "Libcurl", value: "/libcurl/index.mjs" }, { name: "Bare", value: "/baremod/index.mjs" }, ]; + +const wispURLList = [ + { name: "Alu (US)", value: "wss://aluu.xyz/wisp/" }, + { name: "Nebula (US)", value: "wss://nebulaproxy.io/wisp/" } +]; ---
@@ -45,8 +50,8 @@ const transportsList = [
- - + +
diff --git a/src/components/ts/WispServerTiming.ts b/src/components/ts/WispServerTiming.ts new file mode 100644 index 0000000..ca67bfc --- /dev/null +++ b/src/components/ts/WispServerTiming.ts @@ -0,0 +1,49 @@ +export async function testWispServers(servers: WispServer[]): Promise { + let wispData: WispData[] = []; + + for (const server of servers) { + let start = performance.now(); + + try { + await new Promise((resolve, reject) => { + let socket = new WebSocket(server.url); + + socket.onopen = () => { + let end = performance.now(); + console.log(`Connected to ${server.url} in ${end - start}ms`); + let data = { + server: server, + time: end - start + }; + wispData.push(data); + socket.close(); + resolve(null); + }; + + socket.onerror = (error) => { + reject(error); + }; + }); + } catch (error) { + console.error(`Failed to connect to ${server.url}`, error); + } + } + + if (wispData.length === servers.length) { + return wispData; + } else { + throw new Error('Failed to connect to all servers'); + } +} + + +window.wispData = await testWispServers([ + { + url: 'wss://aluu.xyz/wisp/' + }, + { + url: 'wss://nebulaproxy.io/wisp/' + }, +]) + +console.log(window.wispData); \ No newline at end of file diff --git a/src/pages/[lang]/index.astro b/src/pages/[lang]/index.astro index adfd071..c7d0fc4 100644 --- a/src/pages/[lang]/index.astro +++ b/src/pages/[lang]/index.astro @@ -60,6 +60,7 @@ export function getStaticPaths() {
+ `); // fun hack to make the browser refresh and remove the auth params from the URL - return; - } - }; + let loadedHTMLFile = fs.readFileSync(htmlFile, "utf8"); + return async (req, res, next) => { + if (req.headers.host && config.whitelist.includes(req.headers.host)) { + next(); + return; + } + const authheader = req.headers.authorization; + if (req.cookies["authcheck"]) { + next(); + return; + } + if (!authheader) { + res.setHeader("WWW-Authenticate", "Basic"); + res.status(401); + MasqFail(req, res, loadedHTMLFile); + return; + } + // If we are at this point, then the request should be a valid masqr request, and we are going to check the license server + const auth = Buffer.from(authheader.split(" ")[1], "base64").toString().split(":"); + const pass = auth[1]; + const licenseCheck = (await (await fetch(config.licenseServer + pass + "&host=" + req.headers.host)).json())["status"]; + if (licenseCheck === "License valid") { + // Authenticated, set cookie for a year + res.cookie("authcheck", "true", { + expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), + }); + res.send(``); // fun hack to make the browser refresh and remove the auth params from the URL + return; + } + }; } async function MasqFail(req, res, failureFile) { - if (!req.headers.host) { - return; - } - const unsafeSuffix = req.headers.host + ".html"; - let safeSuffix = path.normalize(unsafeSuffix).replace(/^(\.\.(\/|\\|$))+/, ""); - let safeJoin = path.join(process.cwd() + "/Masqrd", safeSuffix); - try { - await fs.promises.access(safeJoin); // man do I wish this was an if-then instead of a "exception on fail" - const failureFileLocal = await fs.promises.readFile(safeJoin, "utf8"); - res.setHeader("Content-Type", "text/html"); - res.send(failureFileLocal); - return; - } - catch (e) { - res.setHeader("Content-Type", "text/html"); - res.send(failureFile); - return; - } + if (!req.headers.host) { + return; + } + const unsafeSuffix = req.headers.host + ".html"; + let safeSuffix = path.normalize(unsafeSuffix).replace(/^(\.\.(\/|\\|$))+/, ""); + let safeJoin = path.join(process.cwd() + "/Masqrd", safeSuffix); + try { + await fs.promises.access(safeJoin); // man do I wish this was an if-then instead of a "exception on fail" + const failureFileLocal = await fs.promises.readFile(safeJoin, "utf8"); + res.setHeader("Content-Type", "text/html"); + res.send(failureFileLocal); + return; + } catch (e) { + res.setHeader("Content-Type", "text/html"); + res.send(failureFile); + return; + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e82a4b9..11219c4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1877,8 +1877,8 @@ packages: jsonfile@6.1.0: resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} - keyv-lru-files@git+https://git@github.com:holy-unblocker/keyv-lru-files.git#dceb102630357eda76317f9005905bbc5e6521e7: - resolution: {commit: dceb102630357eda76317f9005905bbc5e6521e7, repo: git@github.com:holy-unblocker/keyv-lru-files.git, type: git} + keyv-lru-files@https://codeload.github.com/holy-unblocker/keyv-lru-files/tar.gz/dceb102630357eda76317f9005905bbc5e6521e7: + resolution: {tarball: https://codeload.github.com/holy-unblocker/keyv-lru-files/tar.gz/dceb102630357eda76317f9005905bbc5e6521e7} version: 1.3.1 keyv@4.5.4: @@ -5158,7 +5158,7 @@ snapshots: optionalDependencies: graceful-fs: 4.2.11 - keyv-lru-files@git+https://git@github.com:holy-unblocker/keyv-lru-files.git#dceb102630357eda76317f9005905bbc5e6521e7: + keyv-lru-files@https://codeload.github.com/holy-unblocker/keyv-lru-files/tar.gz/dceb102630357eda76317f9005905bbc5e6521e7: dependencies: rimraf: 3.0.2 sqlite: 4.2.1 @@ -5942,7 +5942,7 @@ snapshots: dependencies: async-exit-hook: 2.0.1 cookie: 0.5.0 - keyv-lru-files: git+https://git@github.com:holy-unblocker/keyv-lru-files.git#dceb102630357eda76317f9005905bbc5e6521e7 + keyv-lru-files: https://codeload.github.com/holy-unblocker/keyv-lru-files/tar.gz/dceb102630357eda76317f9005905bbc5e6521e7 mime: 2.6.0 testcafe-hammerhead: 24.5.18 uglify-js: 3.17.4 diff --git a/public/marketplace/dracula-theme/dracula.svg b/public/marketplace/dracula-theme/dracula.svg new file mode 100644 index 0000000..9ca4588 --- /dev/null +++ b/public/marketplace/dracula-theme/dracula.svg @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/marketplace/dracula-theme/theme.css b/public/marketplace/dracula-theme/theme.css new file mode 100644 index 0000000..ed195d3 --- /dev/null +++ b/public/marketplace/dracula-theme/theme.css @@ -0,0 +1,9 @@ +[data-theme="dracula"] { + --background-color: #282a36; + --background-highlight: #44475a; + --accent-color: #4e5268; + --accent-color-brighter: #2d2f3c; + --text-color: #f8f8f2; + --text-color-accent: #dddddd; + --dropdown-background-color: #6272a4; +} \ No newline at end of file diff --git a/src/components/ProxyRegistrar.astro b/src/components/ProxyRegistrar.astro index feae13d..433237d 100644 --- a/src/components/ProxyRegistrar.astro +++ b/src/components/ProxyRegistrar.astro @@ -2,7 +2,7 @@ import { TransportMgr, initTransport } from "./ts/TransportManager"; import "notyf/notyf.min.css"; import { Notyf } from "notyf"; - import { loadIDB, GetStore } from "./ts/IDBManager"; + import { loadIDB, GetStore, ValidateStoreExists, CreateStore } from "./ts/IDBManager"; let form = document.querySelector("form"); let input = document.querySelector("input"); @@ -55,6 +55,9 @@ async function loadPageExtensions() { try { let iframe = document.getElementById("proxy-frame") as HTMLIFrameElement; + if (!ValidateStoreExists("InstalledExtensions")) { + CreateStore("InstalledExtensions", { keyPath: "slug" }); + } let db = loadIDB("AluDB", 1); db.onsuccess = () => { let store = GetStore("InstalledExtensions", "readonly"); diff --git a/src/components/SettingsContent/CustomizationTab.astro b/src/components/SettingsContent/CustomizationTab.astro index f1b187d..6a16c23 100644 --- a/src/components/SettingsContent/CustomizationTab.astro +++ b/src/components/SettingsContent/CustomizationTab.astro @@ -20,62 +20,10 @@ const languageList = [
- +
- +
- - diff --git a/src/components/SettingsContent/ProxyTab.astro b/src/components/SettingsContent/ProxyTab.astro index e4caf17..8bf4ad0 100644 --- a/src/components/SettingsContent/ProxyTab.astro +++ b/src/components/SettingsContent/ProxyTab.astro @@ -32,7 +32,7 @@ const transportsList = [ const wispURLList = [ { name: "Alu (US)", value: "wss://aluu.xyz/wisp/" }, - { name: "Nebula (US)", value: "wss://nebulaproxy.io/wisp/" } + { name: "Nebula (US)", value: "wss://nebulaproxy.io/wisp/" }, ]; --- diff --git a/src/components/ThemeLoader.astro b/src/components/ThemeLoader.astro index b147803..eaf97d1 100644 --- a/src/components/ThemeLoader.astro +++ b/src/components/ThemeLoader.astro @@ -1,4 +1,15 @@