Fix masqr (thanks blumiere)

This commit is contained in:
rift 2024-02-08 22:08:21 -06:00
parent 521c2b8cdf
commit d36fc0fceb

View file

@ -85,51 +85,53 @@ app.register(cookieParser);
await app.register(import("@fastify/compress")); await app.register(import("@fastify/compress"));
// Uncomment if you wish to add masqr. // Uncomment if you wish to add masqr.
/* app.addHook("preHandler", async (req, reply) => { /*
if (req.cookies["authcheck"]) { app.addHook("preHandler", async (req, reply) => {
return; if (req.cookies["authcheck"]) {
} return reply;
}
const authheader = req.headers.authorization; const authheader = req.headers.authorization;
if (req.cookies["refreshcheck"] != "true") { if (req.cookies["refreshcheck"] != "true") {
reply reply
.setCookie("refreshcheck", "true", { maxAge: 10000 }) .setCookie("refreshcheck", "true", { maxAge: 10000 })
.type("text/html") .type("text/html")
.send(failureFile); .send(failureFile);
return; return reply;
} }
if (!authheader) { if (!authheader) {
reply reply
.code(401) .code(401)
.header("WWW-Authenticate", "Basic") .header("WWW-Authenticate", "Basic")
.type("text/html") .type("text/html")
.send(failureFile); .send(failureFile);
return; return reply;
} }
const auth = Buffer.from(authheader.split(" ")[1], "base64") const auth = Buffer.from(authheader.split(" ")[1], "base64")
.toString() .toString()
.split(":"); .split(":");
const user = auth[0]; const user = auth[0];
const pass = auth[1]; const pass = auth[1];
const licenseCheck = ( const licenseCheck = (
await ( await (
await fetch(`${LICENSE_SERVER_URL}${pass}&host=${req.headers.host}`) await fetch(`${LICENSE_SERVER_URL}${pass}&host=${req.headers.host}`)
).json() ).json()
)["status"]; )["status"];
console.log( console.log(
`${LICENSE_SERVER_URL}${pass}&host=${req.headers.host} returned ${licenseCheck}` `${LICENSE_SERVER_URL}${pass}&host=${req.headers.host} returned ${licenseCheck}`
); );
if (licenseCheck === "License valid") { if (licenseCheck === "License valid") {
reply.setCookie("authcheck", "true"); reply.setCookie("authcheck", "true");
return; return reply;
} }
reply.type("text/html").send(failureFile); reply.type("text/html").send(failureFile);
return reply;
}); */ }); */
app.register(fastifyStatic, { app.register(fastifyStatic, {