Format
This commit is contained in:
parent
0e6ee114e5
commit
460aa64634
3 changed files with 257 additions and 239 deletions
48
masqr.js
48
masqr.js
|
|
@ -1,29 +1,35 @@
|
|||
import fp from 'fastify-plugin'
|
||||
import fs from 'fs';
|
||||
import fp from "fastify-plugin";
|
||||
import fs from "fs";
|
||||
const failureFile = fs.readFileSync("Checkfailed.html", "utf8");
|
||||
const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license=";
|
||||
const whiteListedDomain = ["nebulaproxy.io"];
|
||||
async function licenseCheck(req, pass) {
|
||||
try {
|
||||
const resp = await fetch(`${LICENSE_SERVER_URL}${pass}&host=${req.headers.host}`);
|
||||
const resp = await fetch(
|
||||
`${LICENSE_SERVER_URL}${pass}&host=${req.headers.host}`
|
||||
);
|
||||
const data = await resp.json();
|
||||
if (data.status === "License valid") {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
} catch { return false; }
|
||||
}
|
||||
const plugin = (fastify, opts, done) => {
|
||||
fastify.addHook('onRequest', function (req, reply, next) {
|
||||
if (req.cookies.authcheck === 'true' || whiteListedDomain.includes(req.headers.host)) {
|
||||
fastify.addHook("onRequest", function (req, reply, next) {
|
||||
if (
|
||||
req.cookies.authcheck === "true" ||
|
||||
whiteListedDomain.includes(req.headers.host)
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
const authHeader = req.headers.authorization;
|
||||
if (req.cookies.refreshcheck != "true") {
|
||||
reply
|
||||
.setCookie('refreshcheck', 'true', { maxAge: 1000 })
|
||||
.setCookie("refreshcheck", "true", { maxAge: 1000 })
|
||||
.type("text/html")
|
||||
.send(failureFile);
|
||||
return;
|
||||
|
|
@ -31,21 +37,29 @@ const plugin = (fastify, opts, done) => {
|
|||
if (!authHeader) {
|
||||
reply
|
||||
.code(401)
|
||||
.header('WWW-Authenticate', 'Basic')
|
||||
.header("WWW-Authenticate", "Basic")
|
||||
.type("text/html")
|
||||
.send(failureFile);
|
||||
return;
|
||||
}
|
||||
const auth = Buffer.from(authHeader.split(" ")[1], "base64").toString().split(":");
|
||||
const auth = Buffer.from(authHeader.split(" ")[1], "base64")
|
||||
.toString()
|
||||
.split(":");
|
||||
const user = auth[0];
|
||||
const pass = auth[1];
|
||||
licenseCheck(req, pass).then((data) => {
|
||||
if (!data) {
|
||||
reply.status(401).header('WWW-Authenticate', 'Basic').type("text/html").send(failureFile);
|
||||
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>')
|
||||
} else {
|
||||
reply
|
||||
.setCookie("authcheck", "true")
|
||||
.type("text/html")
|
||||
.send("<script>window.location.href = window.location.href</script>");
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
|
@ -54,8 +68,8 @@ const plugin = (fastify, opts, done) => {
|
|||
};
|
||||
|
||||
const masqr = fp(plugin, {
|
||||
fastify: '4.x',
|
||||
name: 'masqr'
|
||||
fastify: "4.x",
|
||||
name: "masqr"
|
||||
});
|
||||
|
||||
export default masqr;
|
||||
|
|
|
|||
10
server.ts
10
server.ts
|
|
@ -14,7 +14,7 @@ const __dirname = path.dirname(__filename);
|
|||
const bare = createBareServer("/bare/");
|
||||
const rh = createRammerhead();
|
||||
import chalk from "chalk";
|
||||
import masqr from './masqr.js';
|
||||
import masqr from "./masqr.js";
|
||||
|
||||
const rammerheadScopes = [
|
||||
"/rammerhead.js",
|
||||
|
|
@ -102,8 +102,12 @@ app.setNotFoundHandler((req, res) => {
|
|||
res.sendFile("index.html"); // SPA catch-all
|
||||
});
|
||||
|
||||
console.log(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")}`));
|
||||
console.log(
|
||||
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({
|
||||
port: 8080,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue