Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/index.mjs
1033 views
1
/*
2
Copyright © Fog Network
3
Made by Nebelung
4
MIT license: https://opensource.org/licenses/MIT
5
*/
6
7
import { createRequire } from "module";
8
const require = createRequire(import.meta.url);
9
const express = require("express")
10
const app = express()
11
const basicAuth = require("express-basic-auth");
12
const config = require("./config.json")
13
const port = process.env.PORT || config.port
14
const Corrosion = require("./lib/server")
15
import RhodiumProxy from 'Rhodium';
16
const auth = config.auth
17
const username = config.username
18
const password = config.password
19
const users = {}
20
users[username] = password
21
const fetch = require("node-fetch");
22
import Server from 'bare-server-node';
23
24
const bare = new Server('/bare/', '');
25
26
const proxy = new Corrosion({
27
prefix: "/corrosion/",
28
codec: "xor",
29
title: "Tsunami",
30
forceHttps: true,
31
requestMiddleware: [
32
Corrosion.middleware.blacklist([
33
"accounts.google.com",
34
], "Page is blocked"),
35
]
36
});
37
38
proxy.bundleScripts();
39
40
const Rhodium = new RhodiumProxy({
41
encode: "xor",
42
prefix: "/rhodium/",
43
server: app,
44
Corrosion: [true, proxy],
45
title: "Tsunami"
46
})
47
48
Rhodium.init();
49
50
if (config.chromebook == "true") {
51
app.use(function(req, res){
52
if (!req.get('User-Agent').includes("CrOS")) {
53
res.status(403)
54
}
55
});
56
}
57
58
if (auth == "true") {
59
app.use(basicAuth({
60
users,
61
challenge: true,
62
unauthorizedResponse: autherror
63
}));
64
}
65
66
function autherror(req) {
67
return req.auth
68
? ("Credentials " + req.auth.user + ":" + req.auth.password + " rejected")
69
: "Error"
70
}
71
72
app.use(express.static("./public", {
73
extensions: ["html"]
74
}));
75
76
app.get("/", function(req, res){
77
res.sendFile("index.html", {root: "./public"});
78
});
79
80
app.get("/suggestions", function(req, res){
81
async function getsuggestions() {
82
var term = req.query.q || "";
83
var response = await fetch("https://duckduckgo.com/ac/?q=" + term + "&type=list");
84
var result = await response.json();
85
var suggestions = result[1]
86
res.send(suggestions)
87
}
88
getsuggestions()
89
});
90
91
app.use(function (req, res) {
92
if (req.url.startsWith(proxy.prefix)) {
93
proxy.request(req,res);
94
} else if (req.url.startsWith(Rhodium.prefix)) {
95
return Rhodium.request(req, res)
96
} else if (req.url.startsWith("/bare/")) {
97
return bare.route_request(req, res)
98
} else {
99
res.status(404).sendFile("404.html", {root: "./public"});
100
}
101
})
102
103
app.listen(port, () => {
104
console.log(`Tsunami is running at localhost:${port}`)
105
})
106