forked from QuiteAFancyEmerald/Holy-Unblocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.js
127 lines (106 loc) · 4.41 KB
/
backend.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
124
125
126
127
/* -----------------------------------------------
* Authors: QuiteAFancyEmerald, BinBashBanana (OlyB), YÖCTDÖNALD'S and the lime
* Additional help from Divide and SexyDuceDuce >:D test aaaa
* ----------------------------------------------- */
const fs = require('fs');
const path = require('path');
const http = require('http');
const https = require('https');
const express = require('express');
const corrosion = require('corrosion');
const config = require('./config.json');
const insert = require('./randomization.json');
const app = express();
const port = process.env.PORT || config.port;
const server = config.ssl ? https.createServer({ key: fs.readFileSync('./ssl/ssl.key'), cert: fs.readFileSync('./ssl/ssl.cert') }, app) : http.createServer(app);
btoa = (str) => {
return new Buffer.from(str).toString('base64');
}
atob = (str) => {
return new Buffer.from(str, 'base64').toString('utf-8');
}
const text404 = fs.readFileSync(path.normalize(__dirname + '/views/404.html'), 'utf8'),
pages = {
'index': 'index.html',
/* Main */
'in': 'info.html',
'faq': 'faq.html',
'j': 'hidden.html',
's': 'pages/frame.html',
'z': 'pages/surf.html',
'c': 'pages/nav/credits.html',
'x': 'pages/nav/bookmarklets.html',
'i': 'pages/nav/icons.html',
't': 'pages/nav/terms.html',
/* Games */
'g': 'pages/nav/gtools.html',
'h': 'pages/nav/games5.html',
'el': 'pages/nav/emulators.html',
'f': 'pages/nav/flash.html',
'm': 'pages/nav/emulibrary.html',
/* Proxies */
'q': 'pages/proxnav/corrosion.html',
'w': 'pages/proxnav/womginx.html',
'y': 'pages/proxnav/youtube.html',
'd': 'pages/proxnav/discordhub.html',
/* Ruffle and Webretro */
'fg': 'archive/gfiles/flash/index.html',
'eg': 'archive/gfiles/rarch/index.html'
};
const cookingInserts = insert.content;
const vegetables = insert.keywords;
const charRandom = insert.chars;
function randomListItem(lis) {
return lis[Math.floor(Math.random() * lis.length)];
}
function redditFix(str) {
return str.replace(/Ch­a­tbo­x/g, 'Re­dd­it');
}
function insertCharset(str) {
return str.replace(/­|​|<wbr>/g, function() { return randomListItem(charRandom); });
}
function insertCooking(str) {
return str.replace(/<!-- IMPORTANT-HUCOOKINGINSERT-DONOTDELETE -->/g, function() { return '<span style="display: none;" data-fact="' + randomListItem(vegetables) + '" data-type="' + randomListItem(vegetables) + '">' + randomListItem(cookingInserts) + '</span>'; });
}
function cacheBusting(str) {
return str.replace(/styles.min.css/g, 'styles-1636936688.min.css');
}
function cacheBusting2(str) {
return str.replace(/common.js/g, 'common-1628457888.js');
}
function cacheBusting3(str) {
return str.replace(/surf.js/g, 'surf-1628130462.js');
}
function insertAll(str) {
return insertCharset(insertCooking(redditFix(cacheBusting(cacheBusting2(cacheBusting3(str))))));
}
function tryReadFile(file) {
return fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : text404;
}
const fetch = (...args) =>
import ('node-fetch').then(({ default: fetch }) => fetch(...args));
let blacklist;
fetch("https://blocklistproject.github.io/Lists/alt-version/everything-nl.txt").then(response => response.text()).then(data => {
blacklist = data.split("\n") && config.blacklist;
});
const proxy = new corrosion({
title: config.title,
prefix: config.prefix || '/search/',
forceHttps: true,
codec: config.codec || 'xor',
ws: config.ws,
requestMiddleware: [
corrosion.middleware.blacklist(blacklist, 'Service not allowed due to bot protection! Make sure you are not trying to verify on a proxy.'),
],
});
proxy.bundleScripts();
/* Querystring Navigation */
app.get('/', async(req, res) => res.send(insertAll(tryReadFile(path.normalize(__dirname + '/views/' + (['/', '/?'].includes(req.url) ? pages.index : pages[Object.keys(req.query)[0]]))))));
/* Static Files Served */
app.use(express.static(path.normalize(__dirname + '/views')));
app.use((req, res) => {
if (req.url.startsWith(proxy.prefix)) return proxy.request(req, res);
res.status(404, res.send(insertAll(text404)))
});
server.listen(port);
console.log('Holy Unblocker is listening on port ' + port + '. This is simply a public for Holy Unblocker. Certain functions may not work properly.');