From 8fc5553b52dd6d8fdb032ac4305bf3c3fcb52c2b Mon Sep 17 00:00:00 2001 From: rift <117926989+Riftriot@users.noreply.github.com> Date: Mon, 12 Feb 2024 16:48:20 -0600 Subject: [PATCH] fix autofill --- server.ts | 136 +++++++++++++++++++++++++-------------------- src/pages/Home.tsx | 4 +- 2 files changed, 77 insertions(+), 63 deletions(-) diff --git a/server.ts b/server.ts index 8e58a99..1c8a1e9 100644 --- a/server.ts +++ b/server.ts @@ -1,9 +1,9 @@ -import { createBareServer } from '@nebula-services/bare-server-node'; +import { createBareServer } from "@nebula-services/bare-server-node"; import chalk from "chalk"; -import express from 'express'; -import { createServer } from 'node:http'; +import express from "express"; +import { createServer } from "node:http"; import { fileURLToPath } from "url"; -import createRammerhead from 'rammerhead/src/server/index.js'; +import createRammerhead from "rammerhead/src/server/index.js"; import path from "path"; import fs from "fs"; import cookieParser from "cookie-parser"; @@ -17,49 +17,51 @@ const whiteListedDomains = ["nebulaproxy.io"]; // Add any public domains you hav const failureFile = fs.readFileSync("Checkfailed.html", "utf8"); const rh = createRammerhead(); 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', + "/rammerhead.js", + "/hammerhead.js", + "/transport-worker.js", + "/task.js", + "/iframe-task.js", + "/worker-hammerhead.js", + "/messaging", + "/sessionexists", + "/deletesession", + "/newsession", + "/editsession", + "/needpassword", + "/syncLocalStorage", + "/api/shuffleDict" ]; const rammerheadSession = /^\/[a-z0-9]{32}/; -console.log(`${chalk.magentaBright('Starting Nebula...')}\n`); +console.log(`${chalk.magentaBright("Starting Nebula...")}\n`); const app = express(); -app.use(cookieParser()) +app.use(cookieParser()); // Congratulations! Masqr failed to validate, this is either your first visit or you're a FRAUD async function MasqFail(req, res) { - if (!req.headers.host) { - // no bitch still using HTTP/1.0 go away - return; - } - const unsafeSuffix = req.headers.host + ".html" - let safeSuffix = path.normalize(unsafeSuffix).replace(/^(\.\.(\/|\\|$))+/, ''); - let safeJoin = path.join(process.cwd()+"/Masqrd", safeSuffix); - try { - await fs.promises.access(safeJoin) // man do I wish this was an if-then instead of a "exception on fail" - const failureFileLocal = await fs.promises.readFile(safeJoin, "utf8"); - res.setHeader("Content-Type", "text/html"); - res.send(failureFileLocal); - return; - } catch(e) { - res.setHeader("Content-Type", "text/html"); - res.send(failureFile); - return; - } + if (!req.headers.host) { + // no bitch still using HTTP/1.0 go away + return; + } + const unsafeSuffix = req.headers.host + ".html"; + let safeSuffix = path + .normalize(unsafeSuffix) + .replace(/^(\.\.(\/|\\|$))+/, ""); + let safeJoin = path.join(process.cwd() + "/Masqrd", safeSuffix); + try { + await fs.promises.access(safeJoin); // man do I wish this was an if-then instead of a "exception on fail" + const failureFileLocal = await fs.promises.readFile(safeJoin, "utf8"); + res.setHeader("Content-Type", "text/html"); + res.send(failureFileLocal); + return; + } catch (e) { + res.setHeader("Content-Type", "text/html"); + res.send(failureFile); + return; + } } // Woooooo masqr yayyyy (said no one) @@ -116,26 +118,36 @@ async function MasqFail(req, res) { app.use(express.static("dist")); -app.get('*', (req, res) => { - res.sendFile(path.join(__dirname, 'dist', 'index.html')); +app.get("/search=:query", async (req, res) => { + const { query } = req.params; + + const response = await fetch( + `http://api.duckduckgo.com/ac?q=${query}&format=json` + ).then((apiRes) => apiRes.json()); + + res.send(response); +}); + +app.get("*", (req, res) => { + res.sendFile(path.join(__dirname, "dist", "index.html")); }); const server = createServer(); -const bare = createBareServer('/bare/'); +const bare = createBareServer("/bare/"); -server.on('request', (req, res) => { - if (bare.shouldRoute(req)) { - bare.routeRequest(req, res); - } else if (shouldRouteRh(req)) { - routeRhRequest(req, res); - } else { - app(req, res); - } +server.on("request", (req, res) => { + if (bare.shouldRoute(req)) { + bare.routeRequest(req, res); + } else if (shouldRouteRh(req)) { + routeRhRequest(req, res); + } else { + app(req, res); + } }); -server.on('upgrade', (req, socket, head) => { - if (bare.shouldRoute(req)) { +server.on("upgrade", (req, socket, head) => { + if (bare.shouldRoute(req)) { bare.routeUpgrade(req, socket, head); } else if (shouldRouteRh(req)) { routeRhUpgrade(req, socket, head); @@ -145,23 +157,27 @@ server.on('upgrade', (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) - ); + 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); + rh.emit("request", req, res); } function routeRhUpgrade(req, socket, head) { - rh.emit('upgrade', req, socket, 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`); -}); \ No newline at end of file + console.log( + `${ + chalk.magentaBright("You can now use Nebula on port ") + chalk.bold(port) + }\n` + ); +}); diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 26e6d84..70b2d0b 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -5,7 +5,6 @@ import { HeaderRoute } from "../components/HeaderRoute"; import { set } from "../util/IDB"; import { uninstallServiceWorkers } from "../util/SWHelper"; import prod from "./config.json"; // Set prod to true if you wish to load balance - import { enc } from "../aes"; import CloakedHead from "../util/CloakedHead"; import { useEffect } from "preact/hooks"; @@ -15,7 +14,6 @@ export function Home() { const [showSuggestions, setShowSuggestions] = useState(false); const [inputValue, setInputValue] = useState(""); const [suggestions, setSuggestions] = useState([]); - useEffect(() => { const handleLoad = () => { const firstLoad = localStorage.getItem("firstLoad") || "true"; @@ -157,7 +155,7 @@ export function Home() { } >