Fix masqr
This commit is contained in:
parent
0ad5812cd3
commit
8d0d1d1116
6 changed files with 32 additions and 20 deletions
|
|
@ -1,2 +1,2 @@
|
|||
MASQR_ENABLED=true
|
||||
MASQR_ENABLED=false
|
||||
PORT=3000
|
||||
7
index.js
7
index.js
|
|
@ -16,7 +16,7 @@ import cookies from "cookie-parser";
|
|||
|
||||
dotenv.config();
|
||||
|
||||
const whiteListedDomains = ["aluu.xyz", "localhost"];
|
||||
const whiteListedDomains = ["aluu.xyz"];
|
||||
const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license=";
|
||||
const MASQR_ENABLED = process.env.MASQR_ENABLED;
|
||||
|
||||
|
|
@ -31,7 +31,6 @@ const rh = rammerhead.createRammerhead({
|
|||
disableHttp2: false,
|
||||
});
|
||||
const app = express();
|
||||
app.use(astroSSR);
|
||||
|
||||
app.use(cookies());
|
||||
|
||||
|
|
@ -39,9 +38,11 @@ app.use(cookies());
|
|||
if (MASQR_ENABLED == "true") {
|
||||
log("Starting Masqr...");
|
||||
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...");
|
||||
app.use(router);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import path from "path";
|
||||
import fs from "fs";
|
||||
export async function masqrCheck(config, htmlFile) {
|
||||
try {
|
||||
const loadedHTMLFile = fs.readFileSync(htmlFile, "utf8");
|
||||
return async (req, res, next) => {
|
||||
|
||||
export async function masqrCheck(config) {
|
||||
return async (req, res, next) => {
|
||||
try {
|
||||
const loadedHtmlFile = fs.readFileSync(process.cwd() + "/" + config.htmlFile, "utf8");
|
||||
if (config.whitelist.includes(req.hostname)) {
|
||||
next();
|
||||
return;
|
||||
|
|
@ -12,7 +13,7 @@ export async function masqrCheck(config, htmlFile) {
|
|||
|
||||
if (!req.cookies) {
|
||||
// Send an error
|
||||
res.send("Request failed!");
|
||||
return res.send("Request failed!");
|
||||
}
|
||||
|
||||
if (req.cookies.authcheck) {
|
||||
|
|
@ -22,7 +23,7 @@ export async function masqrCheck(config, htmlFile) {
|
|||
if (!authheader) {
|
||||
res.setHeader("WWW-Authenticate", "Basic");
|
||||
res.status(401);
|
||||
MasqFail(req, res, loadedHTMLFile);
|
||||
MasqrFail(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
|
||||
|
|
@ -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
|
||||
return;
|
||||
} else {
|
||||
res.setHeader("WWW-Authenticate", "Basic");
|
||||
res.status(401);
|
||||
MasqrFail(req, res, loadedHtmlFile);
|
||||
return;
|
||||
}
|
||||
};
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -57,6 +66,7 @@ async function MasqFail(req, res, failureFile) {
|
|||
return;
|
||||
} catch (e) {
|
||||
res.setHeader("Content-Type", "text/html");
|
||||
res.status(401);
|
||||
res.send(failureFile);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ const t = i18n.useTranslations(lang);
|
|||
<nav class="top-header">
|
||||
<div id="title-background" class="title-background">
|
||||
<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 class="right">
|
||||
<a href={`/${lang}/marketplace/`} class="header-item">Marketplace</a>
|
||||
|
|
@ -70,7 +70,7 @@ const t = i18n.useTranslations(lang);
|
|||
.nav-img {
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
|
||||
.flex-item {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
|
|
|||
|
|
@ -146,8 +146,9 @@ const DESCRIPTION =
|
|||
linear-gradient(90deg, var(--c1) calc(100% / 6), var(--c2) 0 50%, var(--c1) 0 calc(500% / 6), var(--c2) 0);
|
||||
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));
|
||||
--c3: color-mix(in srgb, var(--accent-color-brighter), black var(--darken));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,5 +71,5 @@ import SchemaData from "@components/SchemaData.astro";
|
|||
}
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
<body style="background-color: black;"> </body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue