Rename file

This commit is contained in:
MotorTruck1221 2024-03-23 00:37:59 -06:00
parent c5d60be069
commit 0ffd145633
No known key found for this signature in database
GPG key ID: 06901A625432AC21
2 changed files with 160 additions and 360 deletions

View file

@ -1,160 +0,0 @@
import fastify from "fastify";
import fastifyStatic from "@fastify/static";
import { fileURLToPath } from "url";
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=";
const rammerheadScopes = [
"/rammerhead.js",
"/hammerhead.js",
"/transport-worker.js",
"/task.js",
"/iframe-task.js",
"/worker-hammerhead.js",
"/messaging",
"/sessionexists",
"/deletesession",
"/newsession",
"/editsession",
"/needpassword",
"/syncLocalStorage",
"/api/shuffleDict",
"/mainport"
];
const rammerheadSession = /^\/[a-z0-9]{32}/;
function shouldRouteRh(req) {
const url = new URL(req.url, "http://0.0.0.0");
return (
rammerheadScopes.includes(url.pathname) ||
rammerheadSession.test(url.pathname)
);
}
function routeRhRequest(req, res) {
rh.emit("request", req, res);
}
function routeRhUpgrade(req, socket, head) {
rh.emit("upgrade", req, socket, head);
}
const serverFactory = (handler, opts) => {
return createServer()
.on("request", (req, res) => {
if (bare.shouldRoute(req)) {
bare.routeRequest(req, res);
} else if (shouldRouteRh(req)) {
routeRhRequest(req, res);
} else {
handler(req, res);
}
})
.on("upgrade", (req, socket, head) => {
if (bare.shouldRoute(req)) {
bare.routeUpgrade(req, socket, head);
} else if (shouldRouteRh(req)) {
routeRhUpgrade(req, socket, head);
} else {
wisp.routeRequest(req, socket as Socket, head);
}
});
};
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(fastifyStatic, {
root: path.join(__dirname, "dist"),
prefix: "/",
serve: true,
wildcard: false
});
app.get("/search=:query", async (req, res) => {
const { query } = req.params as { query: string }; // Define the type for req.params
const response = await fetch(
`http://api.duckduckgo.com/ac?q=${query}&format=json`
).then((apiRes) => apiRes.json());
res.send(response);
});
app.setNotFoundHandler((req, res) => {
res.sendFile("index.html"); // SPA catch-all
});
app.listen({
port: 8080
});

360
server.ts
View file

@ -1,200 +1,160 @@
import { createBareServer } from "@tomphttp/bare-server-node"; import fastify from "fastify";
import chalk from "chalk"; import fastifyStatic from "@fastify/static";
import express from "express"; import { fileURLToPath } from "url";
import { createServer } from "node:http"; import path from "path";
import { fileURLToPath } from "url"; import fs from "fs";
import compression from "compression"; import cookieParser from "@fastify/cookie";
import createRammerhead from "rammerhead/src/server/index.js"; import { createServer } from "http";
import path from "path";
import fs from "fs"; import { createBareServer } from "@tomphttp/bare-server-node";
import cookieParser from "cookie-parser"; import createRammerhead from "rammerhead/src/server/index.js";
import wisp from "wisp-server-node"; import wisp from "wisp-server-node";
import { Request, Response } from "express"; import { Socket } from "net";
//@ts-ignore
import { Socket, Head } from "ws"; const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); const bare = createBareServer("/bare/");
const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license="; const rh = createRammerhead();
const whiteListedDomains = ["nebulaproxy.io"]; // Add any public domains you have here
const failureFile = fs.readFileSync("Checkfailed.html", "utf8"); const failureFile = fs.readFileSync("Checkfailed.html", "utf8");
const rh = createRammerhead();
const rammerheadScopes = [ const LICENSE_SERVER_URL = "https://license.mercurywork.shop/validate?license=";
"/rammerhead.js",
"/hammerhead.js", const rammerheadScopes = [
"/transport-worker.js", "/rammerhead.js",
"/task.js", "/hammerhead.js",
"/iframe-task.js", "/transport-worker.js",
"/worker-hammerhead.js", "/task.js",
"/messaging", "/iframe-task.js",
"/sessionexists", "/worker-hammerhead.js",
"/deletesession", "/messaging",
"/newsession", "/sessionexists",
"/editsession", "/deletesession",
"/needpassword", "/newsession",
"/syncLocalStorage", "/editsession",
"/api/shuffleDict" "/needpassword",
]; "/syncLocalStorage",
const rammerheadSession = /^\/[a-z0-9]{32}/; "/api/shuffleDict",
"/mainport"
console.log(`${chalk.magentaBright("Starting Nebula...")}\n`); ];
const app = express(); const rammerheadSession = /^\/[a-z0-9]{32}/;
app.use(
compression({ function shouldRouteRh(req) {
threshold: 0, const url = new URL(req.url, "http://0.0.0.0");
filter: () => true return (
}) rammerheadScopes.includes(url.pathname) ||
); rammerheadSession.test(url.pathname)
app.use(cookieParser()); );
}
// Congratulations! Masqr failed to validate, this is either your first visit or you're a FRAUD
async function MasqFail(req: Request, res: Response) { function routeRhRequest(req, res) {
if (!req.headers.host) { rh.emit("request", req, res);
// no bitch still using HTTP/1.0 go away }
return;
} function routeRhUpgrade(req, socket, head) {
const unsafeSuffix = req.headers.host + ".html"; rh.emit("upgrade", req, socket, head);
let safeSuffix = path }
.normalize(unsafeSuffix)
.replace(/^(\.\.(\/|\\|$))+/, ""); const serverFactory = (handler, opts) => {
let safeJoin = path.join(process.cwd() + "/Masqrd", safeSuffix); return createServer()
try { .on("request", (req, res) => {
await fs.promises.access(safeJoin); // man do I wish this was an if-then instead of a "exception on fail" if (bare.shouldRoute(req)) {
const failureFileLocal = await fs.promises.readFile(safeJoin, "utf8"); bare.routeRequest(req, res);
res.setHeader("Content-Type", "text/html"); } else if (shouldRouteRh(req)) {
res.send(failureFileLocal); routeRhRequest(req, res);
return; } else {
} catch (e) { handler(req, res);
res.setHeader("Content-Type", "text/html"); }
res.send(failureFile); })
return; .on("upgrade", (req, socket, head) => {
} if (bare.shouldRoute(req)) {
} bare.routeUpgrade(req, socket, head);
} else if (shouldRouteRh(req)) {
// Woooooo masqr yayyyy (said no one) routeRhUpgrade(req, socket, head);
// uncomment for masqr } else if (req.url.endsWith("/wisp/")) {
/* app.use(async (req, res, next) => { wisp.routeRequest(req, socket as Socket, head);
if (req.headers.host && whiteListedDomains.includes(req.headers.host)) { }
next(); });
return; };
}
if (req.url.includes("/bare/")) { // replace this with your bare endpoint const app = fastify({ logger: false, serverFactory });
next();
return; app.register(cookieParser);
// Bypass for UV and other bares await app.register(import("@fastify/compress"));
}
// Uncomment if you wish to add masqr.
const authheader = req.headers.authorization; /*
app.addHook("preHandler", async (req, reply) => {
if (req.cookies["authcheck"]) { if (req.cookies["authcheck"]) {
next(); return reply;
return; }
}
const authheader = req.headers.authorization;
if (req.cookies['refreshcheck'] != "true") { if (req.cookies["refreshcheck"] != "true") {
res.cookie("refreshcheck", "true", {maxAge: 10000}) // 10s refresh check reply
MasqFail(req, res) .setCookie("refreshcheck", "true", { maxAge: 10000 })
return; .type("text/html")
} .send(failureFile);
return reply;
if (!authheader) { }
res.setHeader('WWW-Authenticate', 'Basic'); // Yeah so we need to do this to get the auth params, kinda annoying and just showing a login prompt gives it away so its behind a 10s refresh check if (!authheader) {
res.status(401); reply
MasqFail(req, res) .code(401)
return; .header("WWW-Authenticate", "Basic")
} .type("text/html")
.send(failureFile);
const auth = Buffer.from(authheader.split(' ')[1], return reply;
'base64').toString().split(':'); }
const user = auth[0];
const pass = auth[1]; const auth = Buffer.from(authheader.split(" ")[1], "base64")
.toString()
const licenseCheck = ((await (await fetch(LICENSE_SERVER_URL + pass + "&host=" + req.headers.host)).json()))["status"] .split(":");
console.log(LICENSE_SERVER_URL + pass + "&host=" + req.headers.host +" returned " +licenseCheck) const user = auth[0];
if (licenseCheck == "License valid") { const pass = auth[1];
res.cookie("authcheck", "true", {expires: new Date((Date.now()) + (365*24*60*60 * 1000))}) // authorize session, for like a year, by then the link will be expired lol
res.send(`<script> window.location.href = window.location.href </script>`) // fun hack to make the browser refresh and remove the auth params from the URL const licenseCheck = (
return; await (
} await fetch(`${LICENSE_SERVER_URL}${pass}&host=${req.headers.host}`)
).json()
MasqFail(req, res) )["status"];
return; console.log(
}) */ `${LICENSE_SERVER_URL}${pass}&host=${req.headers.host} returned ${licenseCheck}`
);
app.use(
express.static("dist", { if (licenseCheck === "License valid") {
//force .cjs files to be served as text/javascript (libcurl) reply.setCookie("authcheck", "true");
setHeaders: (res, path) => { return reply;
if (path.endsWith(".cjs")) { }
res.setHeader("Content-Type", "text/javascript");
} reply.type("text/html").send(failureFile);
} return reply;
}) }); */
);
app.register(fastifyStatic, {
app.get("/search=:query", async (req: Request, res: Response) => { root: path.join(__dirname, "dist"),
const { query } = req.params; prefix: "/",
serve: true,
const response = await fetch( wildcard: false
`http://api.duckduckgo.com/ac?q=${query}&format=json` });
).then((apiRes) => apiRes.json());
app.get("/search=:query", async (req, res) => {
res.send(response); const { query } = req.params as { query: string }; // Define the type for req.params
});
const response = await fetch(
app.get("*", (req, res) => { `http://api.duckduckgo.com/ac?q=${query}&format=json`
res.sendFile(path.join(__dirname, "dist", "index.html")); ).then((apiRes) => apiRes.json());
});
res.send(response);
const server = createServer(); });
const bare = createBareServer("/bare/"); app.setNotFoundHandler((req, res) => {
res.sendFile("index.html"); // SPA catch-all
server.on("request", (req: Request, res: Response) => { });
if (bare.shouldRoute(req)) {
bare.routeRequest(req, res); app.listen({
} else if (shouldRouteRh(req)) { port: 8080
routeRhRequest(req, res); });
} else {
app(req, res);
}
});
server.on("upgrade", (req: Request, socket: Socket, head: Head) => {
if (bare.shouldRoute(req)) {
bare.routeUpgrade(req, socket, head);
} else if (shouldRouteRh(req)) {
routeRhUpgrade(req, socket, head);
} else if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
}
});
function shouldRouteRh(req) {
const url = new URL(req.url, "http://0.0.0.0");
return (
rammerheadScopes.includes(url.pathname) ||
rammerheadSession.test(url.pathname)
);
}
function routeRhRequest(req: Request, res: Response) {
rh.emit("request", req, res);
}
function routeRhUpgrade(req: Request, socket: Socket, head: Head) {
rh.emit("upgrade", req, socket, head);
}
const port = parseInt(process.env.PORT || "8080");
server.listen(port, () => {
console.log(
`${
chalk.magentaBright("You can now use Nebula on port ") + chalk.bold(port)
}\n`
);
});