Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
fa5b7a3249 | |||
60f65152cb | |||
d34b74e505 | |||
600173c959 | |||
49fd73aaf9 | |||
dc9f73961e | |||
a4094cb795 |
@ -11,10 +11,6 @@ var userLUR = new LRUCache({
|
||||
maxAge: 60000,
|
||||
});
|
||||
|
||||
const client = new Client({
|
||||
url: conf.url,
|
||||
});
|
||||
|
||||
const user_parse = function(data){
|
||||
if(data[conf.userNameAttribute]){
|
||||
data.username = data[conf.userNameAttribute];
|
||||
@ -31,6 +27,10 @@ User.backing = "LDAP";
|
||||
|
||||
User.list = async function(){
|
||||
try{
|
||||
const client = new Client({
|
||||
url: conf.url,
|
||||
});
|
||||
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
const res = await client.search(conf.userBase, {
|
||||
@ -49,6 +49,10 @@ User.list = async function(){
|
||||
|
||||
User.listDetail = async function(){
|
||||
try{
|
||||
const client = new Client({
|
||||
url: conf.url,
|
||||
});
|
||||
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
const res = await client.search(conf.userBase, {
|
||||
@ -86,7 +90,11 @@ User.get = async function(data, key){
|
||||
data.searchValue = data.searchValue || data.uid;
|
||||
|
||||
let filter = `(&${conf.userFilter}(${data.searchKey}=${data.searchValue}))`;
|
||||
if(userLUR.get(filter)) return userLUR.get(filter)
|
||||
if(userLUR.get(filter)) return userLUR.get(filter);
|
||||
|
||||
const client = new Client({
|
||||
url: conf.url,
|
||||
});
|
||||
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
const res = await client.search(conf.userBase, {
|
||||
@ -131,6 +139,10 @@ User.login = async function(data){
|
||||
|
||||
let user = await this.get(data.uid || data[conf.userNameAttribute] || data.username);
|
||||
|
||||
const client = new Client({
|
||||
url: conf.url,
|
||||
});
|
||||
|
||||
await client.bind(user.dn, data.password);
|
||||
|
||||
await client.unbind();
|
||||
|
115
routes/proxy.js
115
routes/proxy.js
@ -13,16 +13,21 @@ const mainjs = fs.readFileSync('./static/main.js', 'utf8');
|
||||
// app.all("/*.js", function(req, res){res.send('')});
|
||||
|
||||
router.all('/static/main.js', function(req,res){
|
||||
res.write(mainjs);
|
||||
res.write(mainjs);
|
||||
});
|
||||
|
||||
const proxyTarget = {
|
||||
// target: "https://wtfismyip.com",
|
||||
// host: "wtfismyip.com",
|
||||
target: 'https://piratebay.party',
|
||||
host: 'piratebay.party',
|
||||
// target: 'http://172.16.0.1',
|
||||
// host: 'piratebayo3klnzokct3wt5yyxb2vpebbuyjl7m623iaxmqhsd52coid.onion'
|
||||
// target: "https://wtfismyip.com",
|
||||
// host: "wtfismyip.com",
|
||||
target: 'https://piratebay.party',
|
||||
host: 'piratebay.party',
|
||||
// target: 'http://172.16.0.1',
|
||||
// target: 'http://piratebayo3klnzokct3wt5yyxb2vpebbuyjl7m623iaxmqhsd52coid.onion',
|
||||
// host: 'piratebayo3klnzokct3wt5yyxb2vpebbuyjl7m623iaxmqhsd52coid.onion'
|
||||
// target: 'https://thepiratebay.org',
|
||||
// host: 'thepiratebay.org',
|
||||
// target: 'https://www2.thepiratebay3.to',
|
||||
// host: 'www2.thepiratebay3.to'
|
||||
}
|
||||
|
||||
function generateRegexForDomain(domain) {
|
||||
@ -36,60 +41,62 @@ function generateRegexForDomain(domain) {
|
||||
}
|
||||
|
||||
router.all("/*", proxy({
|
||||
target: proxyTarget.target,
|
||||
agent: proxyTarget.target.startsWith('https') ? https.globalAgent : http.globalAgent,
|
||||
secure: false,
|
||||
autoRewrite: true,
|
||||
changeOrigin: true,
|
||||
target: proxyTarget.target,
|
||||
agent: proxyTarget.target.startsWith('https') ? https.globalAgent : http.globalAgent,
|
||||
secure: true,
|
||||
autoRewrite: true,
|
||||
changeOrigin: true,
|
||||
followRedirects: true,
|
||||
headers: {
|
||||
host: proxyTarget.host
|
||||
},
|
||||
selfHandleResponse: true, // so that the onProxyRes takes care of sending the response
|
||||
onProxyRes: function(proxyRes, req, res){
|
||||
headers: {
|
||||
host: proxyTarget.host,
|
||||
'Accept-Encoding': 'gzip',
|
||||
},
|
||||
selfHandleResponse: true, // so that the onProxyRes takes care of sending the response
|
||||
onProxyRes: function(proxyRes, req, res){
|
||||
|
||||
if(proxyRes.statusCode === 403 && proxyRes.headers['content-type'] &&
|
||||
proxyRes.headers['content-type'].match('html')
|
||||
){
|
||||
console.log('403')
|
||||
var url = (req.protocol + '://' + req.get('host') + req.originalUrl);
|
||||
proxyRes.headers['location'] = url.replace(/\??ckattempt\=\d+/, '');
|
||||
proxyRes.statusCode == 307
|
||||
if(proxyRes.statusCode === 403 && proxyRes.headers['content-type'] &&
|
||||
proxyRes.headers['content-type'].match('html')
|
||||
){
|
||||
console.log('403')
|
||||
var url = (req.protocol + '://' + req.get('host') + req.originalUrl);
|
||||
proxyRes.headers['location'] = url.replace(/\??ckattempt\=\d+/, '');
|
||||
proxyRes.statusCode = 307;
|
||||
|
||||
return res.end()
|
||||
}
|
||||
return res.end()
|
||||
}
|
||||
|
||||
for(let key of Object.keys(proxyRes.headers)){
|
||||
if(['content-encoding'].includes(key)) continue;
|
||||
// res.set(key, proxyRes.headers[key].toString().replace('http://', 'https://'))
|
||||
}
|
||||
for(let key of Object.keys(proxyRes.headers)){
|
||||
if(['content-encoding'].includes(key)) continue;
|
||||
// res.set(key, proxyRes.headers[key].toString().replace('http://', 'https://'))
|
||||
}
|
||||
|
||||
let body = new Buffer('');
|
||||
proxyRes.on('error', function(e){
|
||||
console.error('ERROR!', e)
|
||||
});
|
||||
let body = new Buffer('');
|
||||
proxyRes.on('error', function(e){
|
||||
console.error('ERROR!', e)
|
||||
});
|
||||
|
||||
proxyRes.on('data', function(data){
|
||||
body = Buffer.concat([body, data]);
|
||||
});
|
||||
proxyRes.on('data', function(data){
|
||||
body = Buffer.concat([body, data]);
|
||||
});
|
||||
|
||||
proxyRes.on('end', function(){
|
||||
body = proxyRes.headers['content-encoding'] === 'gzip' ? zlib.gunzipSync(body).toString('utf8') : body;
|
||||
body = proxyRes.headers['content-encoding'] === 'br' ? zlib.brotliDecompressSync(body).toString('utf8') : body;
|
||||
if(proxyRes.statusCode === 200 &&
|
||||
proxyRes.headers['content-type'] &&
|
||||
proxyRes.headers['content-type'].match('html')
|
||||
){
|
||||
body = body.toString().replace(/<\s*script[^]*?script>/igm, '');
|
||||
body = body.replace(generateRegexForDomain(proxyTarget.host), '');
|
||||
body = body.replace(/<\s*iframe[^]*?iframe>/igm, '');
|
||||
body = body.replace("</html>", '');
|
||||
body = body+inject+"</html>";
|
||||
}
|
||||
res.status(proxyRes.statusCode).end(body);
|
||||
});
|
||||
proxyRes.on('end', function(){
|
||||
// console.log("proxyRes.headers['content-encoding']", proxyRes.headers['content-encoding']);
|
||||
body = proxyRes.headers['content-encoding'] === 'gzip' ? zlib.gunzipSync(body).toString('utf8') : body;
|
||||
body = proxyRes.headers['content-encoding'] === 'br' ? zlib.brotliDecompressSync(body).toString('utf8') : body;
|
||||
if(proxyRes.statusCode === 200 &&
|
||||
proxyRes.headers['content-type'] &&
|
||||
proxyRes.headers['content-type'].match('html')
|
||||
){
|
||||
body = body.toString().replace(/<\s*script[^]*?script>/igm, '');
|
||||
body = body.replace(generateRegexForDomain(proxyTarget.host), '');
|
||||
body = body.replace(/<\s*iframe[^]*?iframe>/igm, '');
|
||||
body = body.replace("</html>", '');
|
||||
body = body+inject+"</html>";
|
||||
}
|
||||
res.status(proxyRes.statusCode).end(body);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router;
|
Loading…
x
Reference in New Issue
Block a user