From 6a3b0626441484cd94ce0adb267514d36c6ac59e Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Thu, 25 Jul 2024 23:57:53 -0500 Subject: [PATCH] Add Dracula theme and overhaul IDBManager.ts, misc fixes and changes --- index.js | 2 +- middleware/masqr.js | 95 +++++++++---------- pnpm-lock.yaml | 8 +- public/marketplace/dracula-theme/dracula.svg | 56 +++++++++++ public/marketplace/dracula-theme/theme.css | 9 ++ src/components/ProxyRegistrar.astro | 5 +- .../SettingsContent/CustomizationTab.astro | 56 +---------- src/components/SettingsContent/ProxyTab.astro | 2 +- src/components/ThemeLoader.astro | 13 ++- src/components/UI/Dropdown.astro | 3 +- src/components/UI/Header.astro | 2 +- src/components/UI/Link.astro | 2 +- src/components/ts/IDBManager.ts | 75 +++++++++++++-- src/components/ts/WispServerTiming.ts | 13 ++- src/components/ts/marketplace.ts | 21 +--- src/json/marketplace.json | 9 ++ src/layouts/Layout.astro | 1 + src/pages/[lang]/settings.astro | 37 ++++---- src/types.d.ts | 10 +- 19 files changed, 249 insertions(+), 170 deletions(-) create mode 100644 public/marketplace/dracula-theme/dracula.svg create mode 100644 public/marketplace/dracula-theme/theme.css diff --git a/index.js b/index.js index eb01720..f2aa198 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ import { handler as ssrHandler } from "./dist/server/entry.mjs"; dotenv.config(); -const whiteListedDomains = ["aluu.xyz"]; +const whiteListedDomains = ["aluu.xyz", "localhost:3000"]; const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license="; const WISP_ENABLED = process.env.USE_WISP; const MASQR_ENABLED = process.env.MASQR_ENABLED; diff --git a/middleware/masqr.js b/middleware/masqr.js index 11c8def..864e1ce 100644 --- a/middleware/masqr.js +++ b/middleware/masqr.js @@ -1,54 +1,53 @@ import path from "path"; import fs from "fs"; export async function masqrCheck(config, htmlFile) { - 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; - } - }; + 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 @@