Add masqrbation abilities

This commit is contained in:
rift 2024-01-22 21:19:31 -06:00
parent ad3d231d16
commit 1c54765c77
4 changed files with 108 additions and 0 deletions

35
Checkfailed.html Normal file
View file

@ -0,0 +1,35 @@
<!doctype html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html {
color-scheme: light dark;
}
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>
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
<a href="/"><b>Refresh this page</b></a>
</p>
<p>
For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br />
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.
</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

View file

@ -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",

15
pnpm-lock.yaml generated
View file

@ -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'}

View file

@ -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: "/",