basic project
This commit is contained in:
parent
a5165478b9
commit
249c9cb1f3
76
app.js
76
app.js
@ -1,13 +1,73 @@
|
||||
const zlib = require('zlib');
|
||||
const fs = require('fs');
|
||||
const express = require('express');
|
||||
var requestProxy = require("express-request-proxy");
|
||||
const proxy = require('http-proxy-middleware');
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
const port = process.env.NODE_PORT || '3000';
|
||||
|
||||
app.all(
|
||||
"/*",
|
||||
requestProxy({
|
||||
url: "https://piratebayztemzmv.onion/*",
|
||||
})
|
||||
);
|
||||
const inject = fs.readFileSync('./inject.html', 'utf8');
|
||||
|
||||
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
|
||||
const Transmission = require('transmission-promise')
|
||||
let tr_client = new Transmission({
|
||||
host:'192.168.1.176',
|
||||
// port: ,
|
||||
username: 'william',
|
||||
// password: 'palm7',
|
||||
// ssl: true
|
||||
})
|
||||
|
||||
tr_client.on('ready', console.log)
|
||||
|
||||
tr_client.on('error', console.log)
|
||||
|
||||
|
||||
app.post("/__api/torrent", function(req, res, next){
|
||||
|
||||
console.log('api', req.body)
|
||||
|
||||
tr_client.addUrl(Buffer.from(req.body.magnet, 'base64').toString('binary')).then(function(data){
|
||||
console.log(data)
|
||||
res.status('200')
|
||||
}).error(function(err){
|
||||
console.error(err)
|
||||
res.status('500').json({})
|
||||
});
|
||||
});
|
||||
|
||||
app.all("/*.js", function(req, res){res.send('')});
|
||||
|
||||
app.all("/*", proxy({
|
||||
target: 'http://piratebayztemzmv.onion',
|
||||
autoRewrite: true,
|
||||
selfHandleResponse: true, // so that the onProxyRes takes care of sending the response
|
||||
onProxyRes: function(proxyRes, req, res){
|
||||
|
||||
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('data', function(data){
|
||||
body = Buffer.concat([body, data]);
|
||||
});
|
||||
|
||||
proxyRes.on('end', function(){
|
||||
body = proxyRes.headers['content-encoding'] === 'gzip' ? zlib.gunzipSync(body).toString('utf8') : body;
|
||||
if(proxyRes.headers['content-type'] && proxyRes.headers['content-type'].match('html')){
|
||||
body = body.toString().replace(/<\s*script[^]*?script>/igm, '');
|
||||
body = body.replace(/<\s*iframe[^]*?iframe>/igm, '');
|
||||
body = body.replace("</html>", '');
|
||||
body = body+inject+"</html>";
|
||||
}
|
||||
res.status(proxyRes.statusCode).end(body);
|
||||
});
|
||||
|
||||
}
|
||||
}));
|
||||
|
||||
app.listen(port, () => console.log(`The Pirate Bay TOR proxy listening on ${port}!`))
|
||||
|
41
inject.html
Normal file
41
inject.html
Normal file
@ -0,0 +1,41 @@
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function post(url, data, callack){
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callack(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$( document ).ready(function() {
|
||||
|
||||
$('a').each(function(idx, el){
|
||||
if($(el).attr('href').match("magnet:?")){
|
||||
$(el).before('<img class="718link" src="https://chocolatey.org/content/packageimages/transmission.2.92.svg" height=24 width=24 data-link="'+$(el).attr('href')+'"/>')
|
||||
}
|
||||
})
|
||||
|
||||
$("body").on('click', 'img.718link', function(el){
|
||||
|
||||
post('/__api/torrent', {
|
||||
magnet: window.btoa($(this).data('link')),
|
||||
password: prompt('password?')
|
||||
}, function(err, data){
|
||||
console.log(arguments);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
919
package-lock.json
generated
919
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,10 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.17.1",
|
||||
"express-request-proxy": "^2.2.2"
|
||||
"express-request-proxy": "^2.2.2",
|
||||
"http-proxy-middleware": "^0.20.0",
|
||||
"node-transmission": "^1.1.0",
|
||||
"nodemon": "^2.0.2",
|
||||
"transmission-promise": "^1.1.4"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user