mirror of
https://github.com/NebulaServices/Nebula.git
synced 2025-05-16 21:10:02 -04:00
Add masqr!
This commit is contained in:
parent
fd8424242e
commit
e9a88bc1cd
4 changed files with 73 additions and 58 deletions
61
masqr.js
Normal file
61
masqr.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
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 data = await resp.json();
|
||||
if (data.status === "License valid") {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
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)) {
|
||||
return next();
|
||||
}
|
||||
const authHeader = req.headers.authorization;
|
||||
if (req.cookies.refreshcheck != "true") {
|
||||
reply
|
||||
.setCookie('refreshcheck', 'true', { maxAge: 1000 })
|
||||
.type("text/html")
|
||||
.send(failureFile);
|
||||
return;
|
||||
}
|
||||
if (!authHeader) {
|
||||
reply
|
||||
.code(401)
|
||||
.header('WWW-Authenticate', 'Basic')
|
||||
.type("text/html")
|
||||
.send(failureFile);
|
||||
return;
|
||||
}
|
||||
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);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
reply.setCookie('authcheck', 'true').type("text/html").send('<script>window.location.href = window.location.href</script>')
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
done();
|
||||
};
|
||||
|
||||
const masqr = fp(plugin, {
|
||||
fastify: '4.x',
|
||||
name: 'masqr'
|
||||
});
|
||||
|
||||
export default masqr;
|
|
@ -31,6 +31,7 @@
|
|||
"crypto-js": "^4.2.0",
|
||||
"express": "^4.19.1",
|
||||
"fastify": "^4.26.2",
|
||||
"fastify-plugin": "^4.5.1",
|
||||
"framer-motion": "^10.18.0",
|
||||
"i18next": "^23.10.1",
|
||||
"i18next-browser-languagedetector": "^7.2.0",
|
||||
|
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
|
@ -65,6 +65,9 @@ dependencies:
|
|||
fastify:
|
||||
specifier: ^4.26.2
|
||||
version: 4.26.2
|
||||
fastify-plugin:
|
||||
specifier: ^4.5.1
|
||||
version: 4.5.1
|
||||
framer-motion:
|
||||
specifier: ^10.18.0
|
||||
version: 10.18.0(react-dom@18.2.0)(react@18.2.0)
|
||||
|
|
66
server.ts
66
server.ts
|
@ -5,21 +5,16 @@ import path from "path";
|
|||
import fs from "fs";
|
||||
import cookieParser from "@fastify/cookie";
|
||||
import { createServer } from "http";
|
||||
|
||||
import { createBareServer } from "@tomphttp/bare-server-node";
|
||||
import createRammerhead from "rammerhead/src/server/index.js";
|
||||
import wisp from "wisp-server-node";
|
||||
import { Socket } from "net";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const bare = createBareServer("/bare/");
|
||||
const rh = createRammerhead();
|
||||
|
||||
const failureFile = fs.readFileSync("Checkfailed.html", "utf8");
|
||||
|
||||
const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license=";
|
||||
import chalk from "chalk";
|
||||
import masqr from './masqr.js';
|
||||
|
||||
const rammerheadScopes = [
|
||||
"/rammerhead.js",
|
||||
|
@ -83,56 +78,7 @@ const app = fastify({ logger: false, serverFactory });
|
|||
|
||||
app.register(cookieParser);
|
||||
await app.register(import("@fastify/compress"));
|
||||
|
||||
// Uncomment if you wish to add masqr.
|
||||
/*
|
||||
app.addHook("preHandler", async (req, reply) => {
|
||||
if (req.cookies["authcheck"]) {
|
||||
return reply;
|
||||
}
|
||||
|
||||
const authheader = req.headers.authorization;
|
||||
|
||||
if (req.cookies["refreshcheck"] != "true") {
|
||||
reply
|
||||
.setCookie("refreshcheck", "true", { maxAge: 10000 })
|
||||
.type("text/html")
|
||||
.send(failureFile);
|
||||
return reply;
|
||||
}
|
||||
|
||||
if (!authheader) {
|
||||
reply
|
||||
.code(401)
|
||||
.header("WWW-Authenticate", "Basic")
|
||||
.type("text/html")
|
||||
.send(failureFile);
|
||||
return reply;
|
||||
}
|
||||
|
||||
const auth = Buffer.from(authheader.split(" ")[1], "base64")
|
||||
.toString()
|
||||
.split(":");
|
||||
const user = auth[0];
|
||||
const pass = auth[1];
|
||||
|
||||
const licenseCheck = (
|
||||
await (
|
||||
await fetch(`${LICENSE_SERVER_URL}${pass}&host=${req.headers.host}`)
|
||||
).json()
|
||||
)["status"];
|
||||
console.log(
|
||||
`${LICENSE_SERVER_URL}${pass}&host=${req.headers.host} returned ${licenseCheck}`
|
||||
);
|
||||
|
||||
if (licenseCheck === "License valid") {
|
||||
reply.setCookie("authcheck", "true");
|
||||
return reply;
|
||||
}
|
||||
|
||||
reply.type("text/html").send(failureFile);
|
||||
return reply;
|
||||
}); */
|
||||
app.register(masqr);
|
||||
|
||||
app.register(fastifyStatic, {
|
||||
root: path.join(__dirname, "dist"),
|
||||
|
@ -155,6 +101,10 @@ 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")}`));
|
||||
|
||||
app.listen({
|
||||
port: 8080
|
||||
port: 8080,
|
||||
host: "0.0.0.0"
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue