fix autofill

This commit is contained in:
rift 2024-02-12 16:48:20 -06:00
parent 0813d6bfd9
commit 8fc5553b52
2 changed files with 77 additions and 63 deletions

View file

@ -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 chalk from "chalk";
import express from 'express'; import express from "express";
import { createServer } from 'node:http'; import { createServer } from "node:http";
import { fileURLToPath } from "url"; 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 path from "path";
import fs from "fs"; import fs from "fs";
import cookieParser from "cookie-parser"; import cookieParser from "cookie-parser";
@ -17,28 +17,28 @@ const whiteListedDomains = ["nebulaproxy.io"]; // Add any public domains you hav
const failureFile = fs.readFileSync("Checkfailed.html", "utf8"); const failureFile = fs.readFileSync("Checkfailed.html", "utf8");
const rh = createRammerhead(); const rh = createRammerhead();
const rammerheadScopes = [ const rammerheadScopes = [
'/rammerhead.js', "/rammerhead.js",
'/hammerhead.js', "/hammerhead.js",
'/transport-worker.js', "/transport-worker.js",
'/task.js', "/task.js",
'/iframe-task.js', "/iframe-task.js",
'/worker-hammerhead.js', "/worker-hammerhead.js",
'/messaging', "/messaging",
'/sessionexists', "/sessionexists",
'/deletesession', "/deletesession",
'/newsession', "/newsession",
'/editsession', "/editsession",
'/needpassword', "/needpassword",
'/syncLocalStorage', "/syncLocalStorage",
'/api/shuffleDict', "/api/shuffleDict"
]; ];
const rammerheadSession = /^\/[a-z0-9]{32}/; const rammerheadSession = /^\/[a-z0-9]{32}/;
console.log(`${chalk.magentaBright('Starting Nebula...')}\n`); console.log(`${chalk.magentaBright("Starting Nebula...")}\n`);
const app = express(); 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 // Congratulations! Masqr failed to validate, this is either your first visit or you're a FRAUD
async function MasqFail(req, res) { async function MasqFail(req, res) {
@ -46,11 +46,13 @@ async function MasqFail(req, res) {
// no bitch still using HTTP/1.0 go away // no bitch still using HTTP/1.0 go away
return; return;
} }
const unsafeSuffix = req.headers.host + ".html" const unsafeSuffix = req.headers.host + ".html";
let safeSuffix = path.normalize(unsafeSuffix).replace(/^(\.\.(\/|\\|$))+/, ''); let safeSuffix = path
.normalize(unsafeSuffix)
.replace(/^(\.\.(\/|\\|$))+/, "");
let safeJoin = path.join(process.cwd() + "/Masqrd", safeSuffix); let safeJoin = path.join(process.cwd() + "/Masqrd", safeSuffix);
try { try {
await fs.promises.access(safeJoin) // man do I wish this was an if-then instead of a "exception on fail" 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"); const failureFileLocal = await fs.promises.readFile(safeJoin, "utf8");
res.setHeader("Content-Type", "text/html"); res.setHeader("Content-Type", "text/html");
res.send(failureFileLocal); res.send(failureFileLocal);
@ -116,15 +118,25 @@ async function MasqFail(req, res) {
app.use(express.static("dist")); app.use(express.static("dist"));
app.get('*', (req, res) => { app.get("/search=:query", async (req, res) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html')); 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 server = createServer();
const bare = createBareServer('/bare/'); const bare = createBareServer("/bare/");
server.on('request', (req, res) => { server.on("request", (req, res) => {
if (bare.shouldRoute(req)) { if (bare.shouldRoute(req)) {
bare.routeRequest(req, res); bare.routeRequest(req, res);
} else if (shouldRouteRh(req)) { } else if (shouldRouteRh(req)) {
@ -134,7 +146,7 @@ server.on('request', (req, res) => {
} }
}); });
server.on('upgrade', (req, socket, head) => { server.on("upgrade", (req, socket, head) => {
if (bare.shouldRoute(req)) { if (bare.shouldRoute(req)) {
bare.routeUpgrade(req, socket, head); bare.routeUpgrade(req, socket, head);
} else if (shouldRouteRh(req)) { } else if (shouldRouteRh(req)) {
@ -145,7 +157,7 @@ server.on('upgrade', (req, socket, head) => {
}); });
function shouldRouteRh(req) { function shouldRouteRh(req) {
const url = new URL(req.url, 'http://0.0.0.0'); const url = new URL(req.url, "http://0.0.0.0");
return ( return (
rammerheadScopes.includes(url.pathname) || rammerheadScopes.includes(url.pathname) ||
rammerheadSession.test(url.pathname) rammerheadSession.test(url.pathname)
@ -153,15 +165,19 @@ function shouldRouteRh(req) {
} }
function routeRhRequest(req, res) { function routeRhRequest(req, res) {
rh.emit('request', req, res); rh.emit("request", req, res);
} }
function routeRhUpgrade(req, socket, head) { function routeRhUpgrade(req, socket, head) {
rh.emit('upgrade', req, socket, head); rh.emit("upgrade", req, socket, head);
} }
const port = parseInt(process.env.PORT || "8080"); const port = parseInt(process.env.PORT || "8080");
server.listen(port, () => { server.listen(port, () => {
console.log(`${chalk.magentaBright("You can now use Nebula on port ") + chalk.bold(port)}\n`); console.log(
`${
chalk.magentaBright("You can now use Nebula on port ") + chalk.bold(port)
}\n`
);
}); });

View file

@ -5,7 +5,6 @@ import { HeaderRoute } from "../components/HeaderRoute";
import { set } from "../util/IDB"; import { set } from "../util/IDB";
import { uninstallServiceWorkers } from "../util/SWHelper"; import { uninstallServiceWorkers } from "../util/SWHelper";
import prod from "./config.json"; // Set prod to true if you wish to load balance import prod from "./config.json"; // Set prod to true if you wish to load balance
import { enc } from "../aes"; import { enc } from "../aes";
import CloakedHead from "../util/CloakedHead"; import CloakedHead from "../util/CloakedHead";
import { useEffect } from "preact/hooks"; import { useEffect } from "preact/hooks";
@ -15,7 +14,6 @@ export function Home() {
const [showSuggestions, setShowSuggestions] = useState(false); const [showSuggestions, setShowSuggestions] = useState(false);
const [inputValue, setInputValue] = useState(""); const [inputValue, setInputValue] = useState("");
const [suggestions, setSuggestions] = useState([]); const [suggestions, setSuggestions] = useState([]);
useEffect(() => { useEffect(() => {
const handleLoad = () => { const handleLoad = () => {
const firstLoad = localStorage.getItem("firstLoad") || "true"; const firstLoad = localStorage.getItem("firstLoad") || "true";
@ -157,7 +155,7 @@ export function Home() {
} }
> >
<div <div
className={`font-roboto w-110 flex h-10 flex-none shrink-0 items-center text-input-text justify-center border border-input-border-color bg-input p-2 text-xl hover:bg-dropdown-option-hover-color ${ className={`font-roboto w-110 flex h-10 flex-none shrink-0 items-center justify-center border border-input-border-color bg-input p-2 text-xl text-input-text hover:bg-dropdown-option-hover-color ${
index === suggestions.length - 1 ? "rounded-b-2xl" : "" index === suggestions.length - 1 ? "rounded-b-2xl" : ""
}`} }`}
key={index} key={index}