-
Notifications
You must be signed in to change notification settings - Fork 528
/
index.mjs
105 lines (91 loc) · 2.41 KB
/
index.mjs
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
/*
Copyright © Fog Network
Made by Nebelung
MIT license: https://opensource.org/licenses/MIT
*/
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const express = require("express")
const app = express()
const basicAuth = require("express-basic-auth");
const config = require("./config.json")
const port = process.env.PORT || config.port
const Corrosion = require("./lib/server")
import RhodiumProxy from 'Rhodium';
const auth = config.auth
const username = config.username
const password = config.password
const users = {}
users[username] = password
const fetch = require("node-fetch");
import Server from 'bare-server-node';
const bare = new Server('/bare/', '');
const proxy = new Corrosion({
prefix: "/corrosion/",
codec: "xor",
title: "Tsunami",
forceHttps: true,
requestMiddleware: [
Corrosion.middleware.blacklist([
"accounts.google.com",
], "Page is blocked"),
]
});
proxy.bundleScripts();
const Rhodium = new RhodiumProxy({
encode: "xor",
prefix: "/rhodium/",
server: app,
Corrosion: [true, proxy],
title: "Tsunami"
})
Rhodium.init();
if (config.chromebook == "true") {
app.use(function(req, res){
if (!req.get('User-Agent').includes("CrOS")) {
res.status(403)
}
});
}
if (auth == "true") {
app.use(basicAuth({
users,
challenge: true,
unauthorizedResponse: autherror
}));
}
function autherror(req) {
return req.auth
? ("Credentials " + req.auth.user + ":" + req.auth.password + " rejected")
: "Error"
}
app.use(express.static("./public", {
extensions: ["html"]
}));
app.get("/", function(req, res){
res.sendFile("index.html", {root: "./public"});
});
app.get("/suggestions", function(req, res){
async function getsuggestions() {
var term = req.query.q || "";
var response = await fetch("https://duckduckgo.com/ac/?q=" + term + "&type=list");
var result = await response.json();
var suggestions = result[1]
res.send(suggestions)
}
getsuggestions()
});
app.use(function (req, res) {
if (req.url.startsWith(proxy.prefix)) {
proxy.request(req,res);
} else if (req.url.startsWith(Rhodium.prefix)) {
return Rhodium.request(req, res)
} else if (req.url.startsWith("/bare/")) {
return bare.route_request(req, res)
} else {
res.status(404).sendFile("404.html", {root: "./public"});
}
})
app.listen(port, () => {
console.log(`Tsunami is running at localhost:${port}`)
})