forked from ShadowDevLabs/ShadowV3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
123 lines (108 loc) · 4.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import express from "express";
import basicAuth from "express-basic-auth"
import wisp from "wisp-server-node";
import * as cheerio from "cheerio";
import { createServer } from "http";
import { fileURLToPath } from "url";
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
import { join } from "path";
import { users, port, brokenSites } from "./config.js";
import https from "https";
const version = process.env.npm_package_version;
const publicPath = fileURLToPath(new URL("./public/", import.meta.url));
const app = express();
const server = createServer();
if (Object.keys(users).length > 0) app.use(basicAuth({ users, challenge: true }));
app.use(express.static(publicPath, { maxAge: 604800000 })); //1 week
app.use('/books/files', (req, res) => https.request(`https://phantom.lol${req.originalUrl}`, { method: req.method, headers: req.headers }, proxyRes => proxyRes.pipe(res)).end());
app.use("/epoxy/", express.static(epoxyPath));
app.use("/libcurl/", express.static(libcurlPath));
app.use("/baremux/", express.static(baremuxPath));
app.use("/uv/", express.static(uvPath));
app.use("/privacy", express.static(publicPath + "/privacy.html"));
app.get("/api/version", (req, res) => {
if (req.query.v && req.query.v != version) {
res.status(400).send(version);
return;
}
res.status(200).send(version);
});
app.get("/api/broken-site", async (req, res) => {
res.status(200).send(await brokenSites());
})
app.get("/api/search-suggestions", async (req, res) => {
let response;
let results = [];
const query = req.query.query;
switch (req.headers.engine ?? "google") {
case "duckduckgo":
response = await fetch(
`http://api.duckduckgo.com/ac?q=${query}&format=json`
).then((i) => i.json());
results = response.map(result => result.phrase);
break;
case "google":
response = await fetch(
`http://suggestqueries.google.com/complete/search?client=firefox&q=${query}`
).then((i) => i.json());
results = response[1];
break;
case "yandex":
response = await fetch(
`https://suggest.yandex.com/suggest?part=${query}`
).then((i) => i.json());
results = response[1].map(suggestion => suggestion);
break;
default:
res.status(400).send('How?');
return;
}
res.send(results);
});
app.get("/api/user-agents", async (req, res) => {
let text = await fetch("https://useragents.me/");
text = await text.text();
const $ = cheerio.load(text);
res.send(
$("#most-common-desktop-useragents-json-csv > div:eq(0) > textarea").val(),
);
});
app.use((req, res) => {
res.status(404);
res.sendFile(join(publicPath, "404.html"));
});
server.on("request", (req, res) => {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
app(req, res);
});
server.on("upgrade", (req, socket, head) => {
if (req.url.endsWith("/wisp/"))
wisp.routeRequest(req, socket, head);
else socket.end();
});
server.on("listening", () => {
const address = server.address();
console.log(
"\n\n\n\x1b[35m\x1b[2m\x1b[1m%s\x1b[0m\n",
`Shadow ${version} has started!\nSprinting on port ${address.port}`,
);
setTimeout(function () {
console.log("\n");
}, 750);
setTimeout(function () {
console.log("\n");
}, 1000);
setTimeout(function () {
console.log(`
┌────────────┬─────────────┬────────────┐
│ Wisp │ Site │ API's │
├────────────┼─────────────┼────────────┤
│ \x1b[32mrunning \x1b[0m │ \x1b[32mrunning \x1b[0m │ \x1b[32mrunning \x1b[0m│
└────────────┴─────────────┴────────────┘
`);
}, 1500);
});
server.listen(process.argv[2] || port);