Edited Query Paths

This commit is contained in:
TheEmeraldStarr 2020-11-01 12:53:20 -08:00
parent a35b6533b7
commit 825b7233f1

264
app.js
View file

@ -1,4 +1,6 @@
const express = require('express'), const { checkServerIdentity } = require('tls');
const express = require('express'),
app = express(), app = express(),
http = require('http'), http = require('http'),
https = require('https'), https = require('https'),
@ -10,48 +12,48 @@
fetch = require('node-fetch'), fetch = require('node-fetch'),
path = require("path"); path = require("path");
const config = JSON.parse(fs.readFileSync('./config.json', { const config = JSON.parse(fs.readFileSync('./config.json', {
encoding: 'utf8' encoding: 'utf8'
})); }));
if (!config.prefix.startsWith('/')) { if (!config.prefix.startsWith('/')) {
config.prefix = `/${config.prefix}`; config.prefix = `/${config.prefix}`;
} }
if (!config.prefix.endsWith('/')) { if (!config.prefix.endsWith('/')) {
config.prefix = `${config.prefix}/`; config.prefix = `${config.prefix}/`;
} }
let server; let server;
let server_protocol; let server_protocol;
const server_options = { const server_options = {
key: fs.readFileSync('./ssl/default.key'), key: fs.readFileSync('./ssl/default.key'),
cert: fs.readFileSync('./ssl/default.crt') cert: fs.readFileSync('./ssl/default.crt')
} }
if (config.ssl == true) { if (config.ssl == true) {
server = https.createServer(server_options, app); server = https.createServer(server_options, app);
server_protocol = 'https://'; server_protocol = 'https://';
} else { } else {
server = http.createServer(app); server = http.createServer(app);
server_protocol = 'http://'; server_protocol = 'http://';
}; };
// WebSocket Proxying // WebSocket Proxying
websocket(server); websocket(server);
console.log(`Alloy Proxy now running on ${server_protocol}0.0.0.0:${config.port}! Proxy prefix is "${config.prefix}"!`); console.log(`Alloy Proxy now running on ${server_protocol}0.0.0.0:${config.port}! Proxy prefix is "${config.prefix}"!`);
server.listen(process.env.PORT || config.port); server.listen(process.env.PORT || config.port);
btoa = (str) => { btoa = (str) => {
str = new Buffer.from(str).toString('base64'); str = new Buffer.from(str).toString('base64');
return str; return str;
}; };
atob = (str) => { atob = (str) => {
str = new Buffer.from(str, 'base64').toString('utf-8'); str = new Buffer.from(str, 'base64').toString('utf-8');
return str; return str;
}; };
rewrite_url = (dataURL, option) => { rewrite_url = (dataURL, option) => {
var websiteURL; var websiteURL;
var websitePath; var websitePath;
if (option == 'decode') { if (option == 'decode') {
@ -64,19 +66,19 @@
if (websitePath == '/') { if (websitePath == '/') {
return `${websiteURL}`; return `${websiteURL}`;
} else return `${websiteURL}${websitePath}`; } else return `${websiteURL}${websitePath}`;
}; };
app.use(session({ app.use(session({
secret: 'alloy', secret: 'alloy',
saveUninitialized: true, saveUninitialized: true,
resave: true, resave: true,
cookieName: '__alloy_cookie_auth=yes', cookieName: '__alloy_cookie_auth=yes',
duration: 30 * 60 * 1000, duration: 30 * 60 * 1000,
activeDuration: 5 * 60 * 1000 activeDuration: 5 * 60 * 1000
})); }));
// We made our own version of body-parser instead, due to issues. // We made our own version of body-parser instead, due to issues.
app.use((req, res, next) => { app.use((req, res, next) => {
if (req.method == 'POST') { if (req.method == 'POST') {
req.raw_body = ''; req.raw_body = '';
req.on('data', chunk => { req.on('data', chunk => {
@ -92,9 +94,9 @@
next(); next();
}); });
} else return next(); } else return next();
}); });
app.use(`${config.prefix}utils/`, async (req, res, next) => { app.use(`${config.prefix}utils/`, async(req, res, next) => {
if (req.url.startsWith('/assets/')) { if (req.url.startsWith('/assets/')) {
res.sendFile(__dirname + '/utils' + req.url); res.sendFile(__dirname + '/utils' + req.url);
} }
@ -109,18 +111,18 @@
} }
return res.redirect(307, config.prefix + rewrite_url(url)); return res.redirect(307, config.prefix + rewrite_url(url));
} }
}); });
/* /*
//Cookie Auth //Cookie Auth
app.use(checkAuth); app.use(checkAuth);
app.use(auth); app.use(auth);
function auth(req, res, next) { function auth(req, res, next) {
let user = new User({ let user = new User({
cookieName: '__alloy_cookie_auth=yes' cookieName: '__alloy_cookie_auth=yes'
}); });
@ -155,11 +157,11 @@
} }
}; };
// Check the auth of the routes => middleware functions // Check the auth of the routes => middleware functions
function checkAuth(req, res, next) { function checkAuth(req, res, next) {
console.log('checkAuth ' + req.url); console.log('checkAuth ' + req.url);
// don 't serve /secure to those not logged in => /secure if for those who are logged in // don 't serve /secure to those not logged in => /secure if for those who are logged in
// you should add to this list, for each and every secure url // you should add to this list, for each and every secure url
if (req.url.indexOf(`${config.prefix}session/`) === 0 && (!req.session || !req.session.authenticated)) { if (req.url.indexOf(`${config.prefix}session/`) === 0 && (!req.session || !req.session.authenticated)) {
res.render(fs.readFileSync('./utils/error/error.html', 'utf8').toString().replace('%ERROR%', `Error 401: The website '${sanitizer.sanitize(proxy.url.hostname)}' is not permitted!`), { res.render(fs.readFileSync('./utils/error/error.html', 'utf8').toString().replace('%ERROR%', `Error 401: The website '${sanitizer.sanitize(proxy.url.hostname)}' is not permitted!`), {
status: 403 status: 403
@ -169,7 +171,7 @@
xt(); xt();
} */ } */
app.post(`${config.prefix}session/`, async (req, res, next) => { app.post(`${config.prefix}session/`, async(req, res, next) => {
let url = querystring.parse(req.raw_body).url; let url = querystring.parse(req.raw_body).url;
if (url.startsWith('//')) { if (url.startsWith('//')) {
url = 'http:' + url; url = 'http:' + url;
@ -196,9 +198,9 @@
response.end('Coookie!!'); */ response.end('Coookie!!'); */
req.session.authenticated = true; req.session.authenticated = true;
}); });
app.use(config.prefix, async (req, res, next) => { app.use(config.prefix, async(req, res, next) => {
var proxy = {}; var proxy = {};
proxy.url = rewrite_url(req.url.slice(1), 'decode'); proxy.url = rewrite_url(req.url.slice(1), 'decode');
proxy.url = { proxy.url = {
@ -385,10 +387,10 @@
}; };
// We send the response from the server rewritten. // We send the response from the server rewritten.
res.send(proxy.sendResponse); res.send(proxy.sendResponse);
}); });
//Querystrings //Querystrings
app.get('/', async (req, res) => { app.get('/', async(req, res) => {
/* /*
@ -405,144 +407,132 @@
} }
*/ */
/* var hbsites = {};
&& hostname == hbsites
*/
if (req.url == '/') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/index.html', { case '/':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'index.html'), 'utf8'));
}));
} }
if (req.url == '/?z') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/z.html', { case '/?z':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'surf.html'), 'utf8'));
}));
} }
if (req.url == '/?a') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/a.html', { case '/?a':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'proxnav', 'alloy.html'), 'utf8'));
}));
} }
if (req.url == '/?dd') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/expr/d.html', { case '/?dd':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'redirects', 'discordprox.html'), 'utf8'));
}));
} }
if (req.url == '/?b') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/b.html', { case '/?b':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'proxnav', 'node.html'), 'utf8'));
}));
} }
if (req.url == '/?y') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/y.html', { case '/?y':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'proxnav', 'youtube.html'), 'utf8'));
}));
} }
if (req.url == '/?e') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/e.html', { case '/?e':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'proxnav', 'pydodge.html'), 'utf8'));
}));
} }
if (req.url == '/?d') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/d.html', { case '/?d':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'proxnav', 'discordhub.html'), 'utf8'));
}));
} }
if (req.url == '/?c') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/c.html', { case '/?c':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'nav', 'credits.html'), 'utf8'));
}));
} }
if (req.url == '/?f') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/f.html', { case '/?f':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'nav', 'flash.html'), 'utf8'));
}));
} }
if (req.url == '/?g') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/g.html', { case '/?g':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'nav', 'gtools.html'), 'utf8'));
}));
} }
if (req.url == '/?h') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/h.html', { case '/?h':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'nav', 'games5.html'), 'utf8'));
}));
} }
if (req.url == '/?i') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/i.html', { case '/?i':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'nav', 'icons.html'), 'utf8'));
}));
} }
if (req.url == '/?in') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/info.html', { case '/?in':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'info.html'), 'utf8'));
}));
} }
if (req.url == '/?k') { switch (req.url == '/?k') {
return res.send(fs.readFileSync(path.resolve() + '/public/k.html', { case '/?k':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'bppages', 'frames', 'krunker.html'), 'utf8'));
}));
} }
if (req.url == '/?m') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/m.html', { case '/?m':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'nav', 'gba.html'), 'utf8'));
}));
} }
if (req.url == '/?n') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/n.html', { case '/?n':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'redirects', 'chatbox.html'), 'utf8'));
}));
} }
if (req.url == '/?p') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/p.html', { case '/?p':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'proxnav', 'pmprox.html'), 'utf8'));
}));
} }
if (req.url == '/?t') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/t.html', { case '/?t':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'nav', 'terms.html'), 'utf8'));
}));
} }
if (req.url == '/?x') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/x.html', { case '/?x':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'nav', 'bookmarklets.html'), 'utf8'));
}));
} }
if (req.url == '/?yh') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/yh.html', { case '/?yh':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'redirects', 'ythub.html'), 'utf8'));
}));
} }
if (req.url == '/?ym') { switch (req.url) {
return res.send(fs.readFileSync(path.resolve() + '/public/ym.html', { case '/?ym':
encoding: 'utf8' return res.send(fs.readFileSync(path.join(__dirname, 'public', 'pages', 'redirects', 'ytmobile.html'), 'utf8'));
}));
} }
}); // Frames Page
app.use('/', express.static('public')); switch (req.url) {
case '/?j':
return res.send(fs.readFileSync(path.join(__dirname, 'public', 'hidden.html'), 'utf8'))
}
app.use(async (req, res, next) => { });
app.use('/', express.static('public'));
app.use(async(req, res, next) => {
if (req.headers['referer']) { if (req.headers['referer']) {
let referer = '/' + String(req.headers['referer']).split('/').splice(3).join('/'); let referer = '/' + String(req.headers['referer']).split('/').splice(3).join('/');
@ -563,4 +553,4 @@
res.redirect(307, config.prefix + btoa(req.session.url) + req.url) res.redirect(307, config.prefix + btoa(req.session.url) + req.url)
} else return next(); } else return next();
}); });