This commit is contained in:
MotorTruck1221 2024-03-23 01:48:06 -06:00
parent 0e6ee114e5
commit 460aa64634
No known key found for this signature in database
GPG key ID: 06901A625432AC21
3 changed files with 257 additions and 239 deletions

110
masqr.js
View file

@ -1,61 +1,75 @@
import fp from 'fastify-plugin' import fp from "fastify-plugin";
import fs from 'fs'; import fs from "fs";
const failureFile = fs.readFileSync("Checkfailed.html", "utf8"); const failureFile = fs.readFileSync("Checkfailed.html", "utf8");
const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license="; const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license=";
const whiteListedDomain = ["nebulaproxy.io"]; const whiteListedDomain = ["nebulaproxy.io"];
async function licenseCheck(req, pass) { async function licenseCheck(req, pass) {
try { try {
const resp = await fetch(`${LICENSE_SERVER_URL}${pass}&host=${req.headers.host}`); const resp = await fetch(
const data = await resp.json(); `${LICENSE_SERVER_URL}${pass}&host=${req.headers.host}`
if (data.status === "License valid") { );
return true; const data = await resp.json();
} if (data.status === "License valid") {
else { return true;
return false; } else {
} return false;
} catch { return false; } }
} catch {
return false;
}
} }
const plugin = (fastify, opts, done) => { const plugin = (fastify, opts, done) => {
fastify.addHook('onRequest', function (req, reply, next) { fastify.addHook("onRequest", function (req, reply, next) {
if (req.cookies.authcheck === 'true' || whiteListedDomain.includes(req.headers.host)) { if (
return next(); req.cookies.authcheck === "true" ||
} whiteListedDomain.includes(req.headers.host)
const authHeader = req.headers.authorization; ) {
if (req.cookies.refreshcheck != "true") { return next();
reply }
.setCookie('refreshcheck', 'true', { maxAge: 1000 }) const authHeader = req.headers.authorization;
.type("text/html") if (req.cookies.refreshcheck != "true") {
.send(failureFile); reply
return; .setCookie("refreshcheck", "true", { maxAge: 1000 })
} .type("text/html")
if (!authHeader) { .send(failureFile);
reply return;
.code(401) }
.header('WWW-Authenticate', 'Basic') if (!authHeader) {
.type("text/html") reply
.send(failureFile); .code(401)
return; .header("WWW-Authenticate", "Basic")
} .type("text/html")
const auth = Buffer.from(authHeader.split(" ")[1], "base64").toString().split(":"); .send(failureFile);
const user = auth[0]; return;
const pass = auth[1]; }
licenseCheck(req, pass).then((data) => { const auth = Buffer.from(authHeader.split(" ")[1], "base64")
if (!data) { .toString()
reply.status(401).header('WWW-Authenticate', 'Basic').type("text/html").send(failureFile); .split(":");
return; const user = auth[0];
} const pass = auth[1];
else { licenseCheck(req, pass).then((data) => {
reply.setCookie('authcheck', 'true').type("text/html").send('<script>window.location.href = window.location.href</script>') if (!data) {
return; reply
} .status(401)
}); .header("WWW-Authenticate", "Basic")
.type("text/html")
.send(failureFile);
return;
} else {
reply
.setCookie("authcheck", "true")
.type("text/html")
.send("<script>window.location.href = window.location.href</script>");
return;
}
}); });
done(); });
done();
}; };
const masqr = fp(plugin, { const masqr = fp(plugin, {
fastify: '4.x', fastify: "4.x",
name: 'masqr' name: "masqr"
}); });
export default masqr; export default masqr;

View file

@ -14,7 +14,7 @@ const __dirname = path.dirname(__filename);
const bare = createBareServer("/bare/"); const bare = createBareServer("/bare/");
const rh = createRammerhead(); const rh = createRammerhead();
import chalk from "chalk"; import chalk from "chalk";
import masqr from './masqr.js'; import masqr from "./masqr.js";
const rammerheadScopes = [ const rammerheadScopes = [
"/rammerhead.js", "/rammerhead.js",
@ -102,8 +102,12 @@ app.setNotFoundHandler((req, res) => {
res.sendFile("index.html"); // SPA catch-all res.sendFile("index.html"); // SPA catch-all
}); });
console.log(chalk.green(`Server listening on ${chalk.bold("http://localhost:8080")}`)); console.log(
console.log(chalk.magenta(`Server also listening on ${chalk.bold("http://0.0.0.0:8080")}`)); chalk.green(`Server listening on ${chalk.bold("http://localhost:8080")}`)
);
console.log(
chalk.magenta(`Server also listening on ${chalk.bold("http://0.0.0.0:8080")}`)
);
app.listen({ app.listen({
port: 8080, port: 8080,