From 1c54765c77bff19cb3878e56ee69ec07b887cc71 Mon Sep 17 00:00:00 2001 From: rift <117926989+Riftriot@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:19:31 -0600 Subject: [PATCH] Add masqrbation abilities --- Checkfailed.html | 35 +++++++++++++++++++++++++++++ package.json | 1 + pnpm-lock.yaml | 15 +++++++++++++ server.ts | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 Checkfailed.html diff --git a/Checkfailed.html b/Checkfailed.html new file mode 100644 index 0000000..84cf7b0 --- /dev/null +++ b/Checkfailed.html @@ -0,0 +1,35 @@ + + + + Welcome to nginx! + + + +

Welcome to nginx!

+

+ If you see this page, the nginx web server is successfully installed and + working. Further configuration is required. If you are expecting another + page, please check your network or + Refresh this page +

+ +

+ For online documentation and support please refer to + nginx.org.
+ Commercial support is available at + nginx.com. +

+ +

Thank you for using nginx.

+ + + diff --git a/package.json b/package.json index 60731d0..1a9f1f1 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "@fastify/compress": "^6.5.0", + "@fastify/cookie": "^9.3.1", "@fastify/static": "^6.12.0", "@nebula-services/bare-server-node": "2.0.1-patch.1", "@nebula-services/dynamic": "0.7.2-patch.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 753b11a..631145d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ dependencies: '@fastify/compress': specifier: ^6.5.0 version: 6.5.0 + '@fastify/cookie': + specifier: ^9.3.1 + version: 9.3.1 '@fastify/static': specifier: ^6.12.0 version: 6.12.0 @@ -1092,6 +1095,13 @@ packages: pumpify: 2.0.1 dev: false + /@fastify/cookie@9.3.1: + resolution: {integrity: sha512-h1NAEhB266+ZbZ0e9qUE6NnNR07i7DnNXWG9VbbZ8uC6O/hxHpl+Zoe5sw1yfdZ2U6XhToUGDnzQtWJdCaPwfg==} + dependencies: + cookie-signature: 1.2.1 + fastify-plugin: 4.5.1 + dev: false + /@fastify/deepmerge@1.3.0: resolution: {integrity: sha512-J8TOSBq3SoZbDhM9+R/u77hP93gz/rajSA+K2kGyijPpORPWUXHUpTaleoj+92As0S9uPRP7Oi8IqMf0u+ro6A==} dev: false @@ -2212,6 +2222,11 @@ packages: /convert-source-map@2.0.0: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} + /cookie-signature@1.2.1: + resolution: {integrity: sha512-78KWk9T26NhzXtuL26cIJ8/qNHANyJ/ZYrmEXFzUmhZdjpBv+DlWlOANRTGBt48YcyslsLrj0bMLFTmXvLRCOw==} + engines: {node: '>=6.6.0'} + dev: false + /cookie@0.5.0: resolution: {integrity: sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==} engines: {node: '>= 0.6'} diff --git a/server.ts b/server.ts index a63a552..39bc660 100644 --- a/server.ts +++ b/server.ts @@ -2,7 +2,9 @@ import fastify from "fastify"; import fastifyStatic from "@fastify/static"; import { fileURLToPath } from "url"; import path from "path"; +import fs from "fs"; import createRammerhead from "rammerhead/src/server/index.js"; +import cookieParser from "@fastify/cookie"; import { createBareServer } from "@nebula-services/bare-server-node"; import { createServer } from "http"; @@ -12,6 +14,10 @@ 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="; + const rammerheadScopes = [ "/rammerhead.js", "/hammerhead.js", @@ -70,6 +76,57 @@ const serverFactory = (handler, opts) => { const app = fastify({ logger: true, serverFactory }); +app.register(cookieParser); + + +// Uncomment if you wish to add masqr. +/* app.addHook("preHandler", async (req, reply) => { + if (req.cookies["authcheck"]) { + return; + } + + const authheader = req.headers.authorization; + + if (req.cookies["refreshcheck"] != "true") { + reply + .setCookie("refreshcheck", "true", { maxAge: 10000 }) + .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]; + + 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.type("text/html").send(failureFile); +}); */ + app.register(fastifyStatic, { root: path.join(__dirname, "dist"), prefix: "/",