Fix masqr

This commit is contained in:
wearrrrr 2024-10-03 21:03:04 -05:00
parent 0ad5812cd3
commit 8d0d1d1116
6 changed files with 32 additions and 20 deletions

View file

@ -1,2 +1,2 @@
MASQR_ENABLED=true MASQR_ENABLED=false
PORT=3000 PORT=3000

View file

@ -16,7 +16,7 @@ import cookies from "cookie-parser";
dotenv.config(); dotenv.config();
const whiteListedDomains = ["aluu.xyz", "localhost"]; const whiteListedDomains = ["aluu.xyz"];
const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license="; const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license=";
const MASQR_ENABLED = process.env.MASQR_ENABLED; const MASQR_ENABLED = process.env.MASQR_ENABLED;
@ -31,7 +31,6 @@ const rh = rammerhead.createRammerhead({
disableHttp2: false, disableHttp2: false,
}); });
const app = express(); const app = express();
app.use(astroSSR);
app.use(cookies()); app.use(cookies());
@ -39,9 +38,11 @@ app.use(cookies());
if (MASQR_ENABLED == "true") { if (MASQR_ENABLED == "true") {
log("Starting Masqr..."); log("Starting Masqr...");
const masqrCheck = (await import("./middleware/Masqr/index.js")).masqrCheck; const masqrCheck = (await import("./middleware/Masqr/index.js")).masqrCheck;
app.use(await masqrCheck({ whitelist: whiteListedDomains, licenseServer: LICENSE_SERVER_URL }, "Checkfailed.html")); app.use(await masqrCheck({ whitelist: whiteListedDomains, licenseServer: LICENSE_SERVER_URL, htmlFile: "Checkfailed.html" }));
} }
app.use(astroSSR);
log("Starting Marketplace Provider..."); log("Starting Marketplace Provider...");
app.use(router); app.use(router);

View file

@ -1,9 +1,10 @@
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
export async function masqrCheck(config, htmlFile) {
try { export async function masqrCheck(config) {
const loadedHTMLFile = fs.readFileSync(htmlFile, "utf8"); return async (req, res, next) => {
return async (req, res, next) => { try {
const loadedHtmlFile = fs.readFileSync(process.cwd() + "/" + config.htmlFile, "utf8");
if (config.whitelist.includes(req.hostname)) { if (config.whitelist.includes(req.hostname)) {
next(); next();
return; return;
@ -12,7 +13,7 @@ export async function masqrCheck(config, htmlFile) {
if (!req.cookies) { if (!req.cookies) {
// Send an error // Send an error
res.send("Request failed!"); return res.send("Request failed!");
} }
if (req.cookies.authcheck) { if (req.cookies.authcheck) {
@ -22,7 +23,7 @@ export async function masqrCheck(config, htmlFile) {
if (!authheader) { if (!authheader) {
res.setHeader("WWW-Authenticate", "Basic"); res.setHeader("WWW-Authenticate", "Basic");
res.status(401); res.status(401);
MasqFail(req, res, loadedHTMLFile); MasqrFail(req, res, loadedHtmlFile);
return; 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 // If we are at this point, then the request should be a valid masqr request, and we are going to check the license server
@ -36,13 +37,21 @@ export async function masqrCheck(config, htmlFile) {
}); });
res.send(`<script>window.location.href = window.location.href</script>`); // fun hack to make the browser refresh and remove the auth params from the URL res.send(`<script>window.location.href = window.location.href</script>`); // fun hack to make the browser refresh and remove the auth params from the URL
return; return;
} else {
res.setHeader("WWW-Authenticate", "Basic");
res.status(401);
MasqrFail(req, res, loadedHtmlFile);
return;
} }
}; } catch (err) {
} catch (err) { console.error(err);
return; res.status(500);
} res.send("Internal server error");
return;
}
};
} }
async function MasqFail(req, res, failureFile) { async function MasqrFail(req, res, failureFile) {
if (!req.headers.host) { if (!req.headers.host) {
return; return;
} }
@ -57,6 +66,7 @@ async function MasqFail(req, res, failureFile) {
return; return;
} catch (e) { } catch (e) {
res.setHeader("Content-Type", "text/html"); res.setHeader("Content-Type", "text/html");
res.status(401);
res.send(failureFile); res.send(failureFile);
return; return;
} }

View file

@ -7,7 +7,7 @@ const t = i18n.useTranslations(lang);
<nav class="top-header"> <nav class="top-header">
<div id="title-background" class="title-background"> <div id="title-background" class="title-background">
<div class="left"> <div class="left">
<a href={`/${lang}/`} class="header-item flex-item"><img class="nav-img" src="/favicon.svg"/><span>{t("nav.brand")}</span></a> <a href={`/${lang}/`} class="header-item flex-item"><img class="nav-img" src="/favicon.svg" /><span>{t("nav.brand")}</span></a>
</div> </div>
<div class="right"> <div class="right">
<a href={`/${lang}/marketplace/`} class="header-item">Marketplace</a> <a href={`/${lang}/marketplace/`} class="header-item">Marketplace</a>

View file

@ -147,7 +147,8 @@ const DESCRIPTION =
background-size: calc(1.732 * var(--s)) var(--s); background-size: calc(1.732 * var(--s)) var(--s);
} }
html[data-theme="macchiato"], html[data-theme="mocha"] { html[data-theme="macchiato"],
html[data-theme="mocha"] {
--c2: color-mix(in srgb, var(--dropdown-background-color), black var(--darken)); --c2: color-mix(in srgb, var(--dropdown-background-color), black var(--darken));
--c3: color-mix(in srgb, var(--accent-color-brighter), black var(--darken)); --c3: color-mix(in srgb, var(--accent-color-brighter), black var(--darken));
} }

View file

@ -71,5 +71,5 @@ import SchemaData from "@components/SchemaData.astro";
} }
</script> </script>
</head> </head>
<body></body> <body style="background-color: black;"> </body>
</html> </html>