mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 12:00:02 -04:00
Updated Alloy (v2.3)
This commit is contained in:
parent
c15aef5eb2
commit
b83e2fece4
5 changed files with 391 additions and 276 deletions
19
app.js
19
app.js
|
@ -6,6 +6,7 @@ const express = require('express'),
|
||||||
querystring = require('querystring'),
|
querystring = require('querystring'),
|
||||||
session = require('express-session'),
|
session = require('express-session'),
|
||||||
sanitizer = require('sanitizer'),
|
sanitizer = require('sanitizer'),
|
||||||
|
websocket = require('./ws-proxy.js'),
|
||||||
fetch = require('node-fetch');
|
fetch = require('node-fetch');
|
||||||
|
|
||||||
const config = JSON.parse(fs.readFileSync('./config.json', { encoding: 'utf8' }));
|
const config = JSON.parse(fs.readFileSync('./config.json', { encoding: 'utf8' }));
|
||||||
|
@ -23,22 +24,16 @@ 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://'; } else { server = http.createServer(app);
|
||||||
server_protocol = 'https://';
|
server_protocol = 'http://'; };
|
||||||
} else {
|
|
||||||
server = http.createServer(app);
|
|
||||||
server_protocol = 'http://';
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// WebSocket Proxying
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
var login = require('./auth');
|
|
||||||
|
|
||||||
|
|
||||||
btoa = (str) => {
|
btoa = (str) => {
|
||||||
str = new Buffer.from(str).toString('base64');
|
str = new Buffer.from(str).toString('base64');
|
||||||
return str;
|
return str;
|
||||||
|
@ -62,6 +57,8 @@ rewrite_url = (dataURL, option) => {
|
||||||
if (websitePath == '/') { return `${websiteURL}`; } else return `${websiteURL}${websitePath}`;
|
if (websitePath == '/') { return `${websiteURL}`; } else return `${websiteURL}${websitePath}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var login = require('./auth');
|
||||||
|
|
||||||
app.use(session({
|
app.use(session({
|
||||||
secret: 'alloy',
|
secret: 'alloy',
|
||||||
saveUninitialized: true,
|
saveUninitialized: true,
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
[
|
[
|
||||||
"example.com"
|
"add-your-website-url.blocked"
|
||||||
]
|
]
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "alloy-proxy",
|
"name": "alloy-proxy",
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"description": "A web proxy capable of proxying websites!",
|
"description": "A web proxy capable of proxying websites!",
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"sanitizer": "^0.1.3",
|
"sanitizer": "^0.1.3",
|
||||||
"session": "^0.1.0",
|
"session": "^0.1.0",
|
||||||
"cookies": "0.4"
|
"cookies": "0.4",
|
||||||
|
"ws": "^7.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -71,6 +71,36 @@ let setattribute_rewrite = window.Element.prototype.setAttribute; window.Element
|
||||||
return setattribute_rewrite.apply(this, arguments)
|
return setattribute_rewrite.apply(this, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rewriting all incoming websocket request.
|
||||||
|
|
||||||
|
WebSocket = new Proxy(WebSocket, {
|
||||||
|
|
||||||
|
construct(target, args_array) {
|
||||||
|
|
||||||
|
var protocol;
|
||||||
|
|
||||||
|
if (location.protocol == 'https:') { protocol = 'wss://' } else { protocol = 'ws://' }
|
||||||
|
|
||||||
|
args_array[0] = protocol + location.origin.split('/').splice(2).join('/') + prefix + 'ws/' + btoa(args_array[0]);
|
||||||
|
|
||||||
|
return new target(args_array);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Rewriting incoming pushstate.
|
||||||
|
|
||||||
|
history.pushState = new Proxy(history.pushState, {
|
||||||
|
|
||||||
|
apply: (target, thisArg, args_array) => {
|
||||||
|
|
||||||
|
args_array[2] = rewrite_url(args_array[2])
|
||||||
|
|
||||||
|
return target.apply(thisArg, args_array)
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
var previousState = window.history.state;
|
var previousState = window.history.state;
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
if (!window.location.pathname.startsWith(`${prefix}${btoa(url.origin)}/`)) {
|
if (!window.location.pathname.startsWith(`${prefix}${btoa(url.origin)}/`)) {
|
||||||
|
|
87
ws-proxy.js
Normal file
87
ws-proxy.js
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
const WebSocket = require('ws'),
|
||||||
|
fs = require('fs');
|
||||||
|
|
||||||
|
const config = JSON.parse(fs.readFileSync('./config.json', {encoding:'utf8'}));
|
||||||
|
|
||||||
|
if (!config.prefix.startsWith('/')) {
|
||||||
|
|
||||||
|
config.prefix = `/${config.prefix}`;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.prefix.endsWith('/')) {
|
||||||
|
|
||||||
|
config.prefix = `${config.prefix}/`;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
btoa = (str) => {
|
||||||
|
|
||||||
|
str = new Buffer.from(str).toString('base64');
|
||||||
|
|
||||||
|
return str;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
atob = (str) => {
|
||||||
|
|
||||||
|
str = new Buffer.from(str, 'base64').toString('utf-8');
|
||||||
|
|
||||||
|
return str;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = (server) => {
|
||||||
|
|
||||||
|
const wss = new WebSocket.Server({ server: server });
|
||||||
|
|
||||||
|
wss.on('connection', (cli, req) => {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const svr = new WebSocket(atob(req.url.toString().replace(`${config.prefix}ws/`, '')));
|
||||||
|
|
||||||
|
svr.on('message', (data) => {
|
||||||
|
|
||||||
|
try { cli.send(data) } catch(err){}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
svr.on('open', () => {
|
||||||
|
|
||||||
|
cli.on('message', (data) => {
|
||||||
|
|
||||||
|
svr.send(data)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
cli.on('close', (code) => {
|
||||||
|
|
||||||
|
try { svr.close(code); } catch(err) { svr.close(1006) };
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
svr.on('close', (code) => {
|
||||||
|
|
||||||
|
try { cli.close(code); } catch(err) { cli.close(1006) };
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
cli.on('error', (err) => {
|
||||||
|
|
||||||
|
try { svr.close(1001); } catch(err) { svr.close(1006) };
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
svr.on('error', (err) => {
|
||||||
|
|
||||||
|
try { cli.close(1001); } catch(err) { cli.close(1006) };
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch(err) { cli.close(1001); }
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue