mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 12:00:02 -04:00
Updated Alloy Proxy
This commit is contained in:
parent
003b5da951
commit
2bc4785d47
6 changed files with 25 additions and 54 deletions
53
src/charinsert.js
Normal file
53
src/charinsert.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* -----------------------------------------------
|
||||
/* Author : Divide
|
||||
/* MIT license: http://opensource.org/licenses/MIT
|
||||
/* ----------------------------------------------- */
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
mime = require('mime-types'),
|
||||
char_insert = (str, hash) => {
|
||||
var output = '';
|
||||
|
||||
str.split(' ').forEach((word, word_index) => (word.split('').forEach((chr, chr_index) => output += (!chr_index || chr_index == word.length) ? '<span style="white-space: nowrap">&#' + chr.charCodeAt() + '</span>' : '<span style="white-space: nowrap">​<span style="display:none;font-size:0px;">​' + hash + '</span>&#' + chr.charCodeAt() + '​</span>'), output += word_index != str.split(' ').length - 1 ? ' ' : ''));
|
||||
|
||||
return output
|
||||
},
|
||||
hash = s => { for (var i = 0, h = 9; i < s.length;) h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9); return h ^ h >>> 9 },
|
||||
express_ip = req => {
|
||||
var ip = null,
|
||||
methods = [req.headers['cf-connecting-ip'], req.headers['x-real-ip'], req.headers['x-forwarded-for']];
|
||||
|
||||
methods.filter(method => method).forEach(method => {
|
||||
if (ip) return;
|
||||
|
||||
ip = method;
|
||||
|
||||
if (ip.includes(',')) {
|
||||
ip = ip.split(',')[ip.split(',').length - 1].replace(' ', '');
|
||||
if (ip.length > 15) ip = ip.split(',')[0].replace(' ', '');
|
||||
}
|
||||
});
|
||||
|
||||
return ip || '127.0.0.1';
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
static: public_path => (req, res, next) => {
|
||||
var pub_file = path.join(public_path, req.url);
|
||||
|
||||
if (fs.existsSync(pub_file)) {
|
||||
if (fs.statSync(pub_file).isDirectory()) pub_file = path.join(pub_file, 'index.html');
|
||||
if (!fs.existsSync(pub_file)) return next();
|
||||
|
||||
var mime_type = mime.lookup(pub_file),
|
||||
data = fs.readFileSync(pub_file),
|
||||
ext = path.extname(pub_file);
|
||||
|
||||
if (ext == '.html') data = data.toString('utf8').replace(/char_?insert{([\s\S]*?)}/gi, (match, str) => char_insert(str, hash(express_ip(req))));
|
||||
|
||||
res.contentType(mime_type).send(data);
|
||||
} else next();
|
||||
},
|
||||
parse: string => char_insert(string, '-1231'),
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue