lots...
This commit is contained in:
parent
c8f00cdeaf
commit
abc547c642
5
.gitignore
vendored
5
.gitignore
vendored
@ -76,3 +76,8 @@ typings/
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# keys
|
||||
secrets.js
|
||||
secrets.json
|
||||
|
||||
*.sqlite
|
||||
|
8
.sequelizerc
Normal file
8
.sequelizerc
Normal file
@ -0,0 +1,8 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
'config': path.resolve(__dirname, 'models/sql/config/config.js'),
|
||||
'models-path': path.resolve(__dirname, 'models/sql'),
|
||||
'seeders-path': path.resolve(__dirname, 'models/sql/seeders'),
|
||||
'migrations-path': path.resolve(__dirname, 'models/sql/migrations')
|
||||
};
|
208
app.js
208
app.js
@ -1,122 +1,118 @@
|
||||
const zlib = require('zlib');
|
||||
const fs = require('fs');
|
||||
var https = require('https');
|
||||
'use strict';
|
||||
|
||||
const Module = require('module');
|
||||
const original_resolveFilename = Module._resolveFilename;
|
||||
|
||||
Module._resolveFilename = function(...args){
|
||||
args[0] = args[0].startsWith('>') ? args[0].replace('>', __dirname) : args[0];
|
||||
return original_resolveFilename(...args);
|
||||
};
|
||||
|
||||
const path = require('path');
|
||||
const ejs = require('ejs')
|
||||
const express = require('express');
|
||||
const proxy = require('http-proxy-middleware');
|
||||
|
||||
// Set up the express app.
|
||||
const app = express();
|
||||
|
||||
// List of front end node modules to be served
|
||||
const frontEndModules = [
|
||||
'jquery', 'jquery-ui', 'moment', 'mustache',
|
||||
// 'bootstrap', '@fortawesome',
|
||||
];
|
||||
|
||||
// Hold list of functions to run when the server is ready
|
||||
app.onListen = [function(){console.log('hello')}];
|
||||
|
||||
// Allow the express app to be exported into other files.
|
||||
module.exports = app;
|
||||
|
||||
// Build the conf object from the conf files.
|
||||
app.conf = require('./conf');
|
||||
|
||||
// Grab the projects PubSub
|
||||
app.contollers = require('./controller');
|
||||
|
||||
// Push pubsub over the socket and back.
|
||||
app.onListen.push(function(){
|
||||
app.io.use(middleware.authIO);
|
||||
|
||||
app.contollers.pubsub.subscribe(/./g, function(data, topic){
|
||||
app.io.emit('P2PSub', { topic, data });
|
||||
});
|
||||
|
||||
app.io.on('connection', (socket) => {
|
||||
// console.log('socket', socket)
|
||||
var user = socket.user;
|
||||
socket.on('P2PSub', (msg) => {
|
||||
app.contollers.pubsub.publish(msg.topic, {...msg.data, __from:socket.user});
|
||||
// socket.broadcast.emit('P2PSub', msg);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Hold onto the auth middleware
|
||||
const middleware = require('./middleware/auth');
|
||||
|
||||
// load the JSON parser middleware. Express will parse JSON into native objects
|
||||
// for any request that has JSON in its content type.
|
||||
app.use(express.json());
|
||||
app.set('json spaces', 2);
|
||||
|
||||
const port = process.env.NODE_PORT || '3000';
|
||||
// Set up the templating engine to build HTML for the front end.
|
||||
app.set('views', path.join(__dirname, 'views'));
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
const inject = fs.readFileSync('./inject.html', 'utf8');
|
||||
const mainjs = fs.readFileSync('./static/main.js', 'utf8');
|
||||
// Have express server static content( images, CSS, browser JS) from the public
|
||||
// local folder.
|
||||
app.use('/__static', express.static(path.join(__dirname, 'public')))
|
||||
|
||||
|
||||
const Transmission = require('transmission-promise')
|
||||
var tr_client = new Transmission({
|
||||
host:'tran.718it.biz',
|
||||
ssl: true,
|
||||
port: 443,
|
||||
username: 'william',
|
||||
password: 'palm7',
|
||||
})
|
||||
|
||||
app.post("/__api/torrent", async function(req, res, next){
|
||||
|
||||
if(req.body.password !== '4412'){
|
||||
return res.status(421);
|
||||
}
|
||||
|
||||
try{
|
||||
let cres = await tr_client.addUrl(Buffer.from(req.body.magnet, 'base64').toString('binary'));
|
||||
res.json(cres)
|
||||
|
||||
}catch(e){
|
||||
console.error('error', e)
|
||||
res.status(500).json({message: e})
|
||||
}
|
||||
// Server front end modules
|
||||
// https://stackoverflow.com/a/55700773/3140931
|
||||
frontEndModules.forEach(dep => {
|
||||
app.use(`/__static-modules/${dep}`, express.static(path.join(__dirname, `node_modules/${dep}`)))
|
||||
});
|
||||
|
||||
app.get("/__api/torrent/:id", async function(req, res, next){
|
||||
// API route
|
||||
app.use('/__api', require('./routes/api'));
|
||||
|
||||
try{
|
||||
let cres = await tr_client.get(Number(req.params.id), ["eta", "percentDone", "status", "rateDownload", "errorString", "hashString", 'name']);
|
||||
res.json({id:req.params.id, cres})
|
||||
// Routes for front end content.
|
||||
app.use('/', require('./routes/proxy'));
|
||||
|
||||
}catch(e){
|
||||
console.error('error', e)
|
||||
res.status(500).json({message: e})
|
||||
}
|
||||
// Catch 404 and forward to error handler. If none of the above routes are
|
||||
// used, this is what will be called.
|
||||
app.use(function(req, res, next) {
|
||||
var err = new Error('Not Found');
|
||||
err.message = 'Page not found'
|
||||
err.status = 404;
|
||||
next(err);
|
||||
});
|
||||
|
||||
// Error handler. This is where `next()` will go on error
|
||||
app.use(function(err, req, res, next) {
|
||||
console.error(err.status || 500, err.name, req.method, req.url);
|
||||
|
||||
// app.all("/*.js", function(req, res){res.send('')});
|
||||
// Parse key error for Sequilzw
|
||||
let keyErrors = {}
|
||||
if(['SequelizeValidationError'].includes(err.name) && err.errors){
|
||||
for(let item of err.errors){
|
||||
if(item.path){
|
||||
keyErrors[item.path] = item.message;
|
||||
}
|
||||
}
|
||||
err.status = 422;
|
||||
}
|
||||
|
||||
app.all('/static/main.js', function(req,res){
|
||||
res.write(mainjs);
|
||||
if(![404, 422].includes(err.status || res.status)){
|
||||
console.error(err.message);
|
||||
console.error(err.stack);
|
||||
console.error('=========================================');
|
||||
}
|
||||
res.status(err.status || 500);
|
||||
res.json({
|
||||
name: err.name || 'Unknown error',
|
||||
message: err.message,
|
||||
keyErrors,
|
||||
});
|
||||
});
|
||||
|
||||
app.all("/*", proxy({
|
||||
target: 'https://piratebay.party',
|
||||
agent: https.globalAgent,
|
||||
autoRewrite: true,
|
||||
secure: false,
|
||||
followRedirects: true,
|
||||
autoRewrite: true,
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
followRedirects: true,
|
||||
autoRewrite: true,
|
||||
changeOrigin: true,
|
||||
headers: {
|
||||
host: 'piratebay.party'
|
||||
},
|
||||
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
|
||||
|
||||
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://'))
|
||||
}
|
||||
|
||||
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('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(/piratebay\.party/ig, 'tpb.718it.biz');
|
||||
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}!`))
|
||||
|
98
bin/www
Normal file
98
bin/www
Normal file
@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var app = require('../app');
|
||||
var debug = require('debug')('proxy-api:server');
|
||||
var http = require('http');
|
||||
const conf = require('../conf');
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
*/
|
||||
|
||||
var port = normalizePort(process.env.NODE_PORT || conf.port || '3000');
|
||||
app.set('port', port);
|
||||
|
||||
/**
|
||||
* Create HTTP server.
|
||||
*/
|
||||
|
||||
var server = http.createServer(app);
|
||||
|
||||
var io = require('socket.io')(server);
|
||||
app.io = io;
|
||||
|
||||
/**
|
||||
* Listen on provided port, on all network interfaces.
|
||||
*/
|
||||
|
||||
server.listen(port);
|
||||
server.on('error', onError);
|
||||
server.on('listening', onListening);
|
||||
|
||||
/**
|
||||
* Normalize a port into a number, string, or false.
|
||||
*/
|
||||
|
||||
function normalizePort(val) {
|
||||
var port = parseInt(val, 10);
|
||||
|
||||
if (isNaN(port)) {
|
||||
// named pipe
|
||||
return val;
|
||||
}
|
||||
|
||||
if (port >= 0) {
|
||||
// port number
|
||||
return port;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "error" event.
|
||||
*/
|
||||
|
||||
function onError(error) {
|
||||
if (error.syscall !== 'listen') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
var bind = typeof port === 'string'
|
||||
? 'Pipe ' + port
|
||||
: 'Port ' + port;
|
||||
|
||||
// handle specific listen errors with friendly messages
|
||||
switch (error.code) {
|
||||
case 'EACCES':
|
||||
console.error(bind + ' requires elevated privileges');
|
||||
process.exit(1);
|
||||
break;
|
||||
case 'EADDRINUSE':
|
||||
console.error(bind + ' is already in use');
|
||||
process.exit(1);
|
||||
break;
|
||||
default:
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "listening" event.
|
||||
*/
|
||||
|
||||
function onListening() {
|
||||
var addr = server.address();
|
||||
var bind = typeof addr === 'string'
|
||||
? 'pipe ' + addr
|
||||
: 'port ' + addr.port;
|
||||
console.log('Listening on ' + bind);
|
||||
|
||||
for(let listener of app.onListen){
|
||||
listener()
|
||||
}
|
||||
}
|
25
conf/base.js
Normal file
25
conf/base.js
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
ldap: {
|
||||
url: 'ldap://10.1.0.55:389',
|
||||
bindDN: 'cn=ldapclient service,ou=people,dc=theta42,dc=com',
|
||||
bindPassword: '__IN SRECREST FILE__',
|
||||
userBase: 'ou=people,dc=theta42,dc=com',
|
||||
groupBase: 'ou=groups,dc=theta42,dc=com',
|
||||
userFilter: '(objectClass=posixAccount)',
|
||||
userNameAttribute: 'uid'
|
||||
},
|
||||
sql: {
|
||||
"storage": "database_test.sqlite",
|
||||
"dialect": "sqlite",
|
||||
logging: false,
|
||||
},
|
||||
transmission: {
|
||||
host:'10.2.254.40',
|
||||
ssl: false,
|
||||
port: 9091,
|
||||
username: 'william',
|
||||
password: '__IN SRECREST FILE__',
|
||||
}
|
||||
};
|
32
conf/index.js
Normal file
32
conf/index.js
Normal file
@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const extend = require('extend');
|
||||
|
||||
const environment = process.env.NODE_ENV || 'development';
|
||||
|
||||
function load(filePath, required){
|
||||
try {
|
||||
return require(filePath);
|
||||
} catch(error){
|
||||
if(error.name === 'SyntaxError'){
|
||||
console.error(`Loading ${filePath} file failed!\n`, error);
|
||||
process.exit(1);
|
||||
} else if (error.code === 'MODULE_NOT_FOUND'){
|
||||
console.warn(`No config file ${filePath} FOUND! This may cause issues...`);
|
||||
if (required){
|
||||
process.exit(1);
|
||||
}
|
||||
return {};
|
||||
}else{
|
||||
console.dir(`Unknown error in loading ${filePath} config file.\n`, error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = extend(
|
||||
true, // enable deep copy
|
||||
load('./base', true),
|
||||
load(`./${environment}`),
|
||||
load('./secrets'),
|
||||
{environment}
|
||||
);
|
56
controller/auth.js
Normal file
56
controller/auth.js
Normal file
@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
const {User, AuthToken} = require('>/models');
|
||||
|
||||
|
||||
class Auth{
|
||||
static errors = {
|
||||
login: function(){
|
||||
let error = new Error('LDAPLoginFailed');
|
||||
error.name = 'LDAPLoginFailed';
|
||||
error.message = `Invalid Credentials, login failed.`;
|
||||
error.status = 401;
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
static async login(data){
|
||||
try{
|
||||
let user = await User.login(data);
|
||||
let token = await AuthToken.create({username: user.username});
|
||||
|
||||
return {user, token}
|
||||
}catch(error){
|
||||
console.log('login error', error);
|
||||
throw this.errors.login();
|
||||
}
|
||||
}
|
||||
|
||||
static async checkToken(token){
|
||||
try{
|
||||
token = await AuthToken.get(token);
|
||||
if(token && token.check()) return token;
|
||||
|
||||
throw this.errors.login();
|
||||
}catch(error){
|
||||
throw this.errors.login();
|
||||
}
|
||||
}
|
||||
|
||||
static async logout(data){
|
||||
let token = await AuthToken.get(data);
|
||||
await token.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Auth.logOut = async function(data){
|
||||
try{
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {Auth};
|
||||
|
7
controller/index.js
Normal file
7
controller/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
auth: require('./auth'),
|
||||
pubsub: require('./pubsub'),
|
||||
torrent: require('./torrent'),
|
||||
}
|
6
controller/pubsub.js
Normal file
6
controller/pubsub.js
Normal file
@ -0,0 +1,6 @@
|
||||
const {PubSub} = require('p2psub');
|
||||
|
||||
ps = new PubSub();
|
||||
|
||||
|
||||
module.exports = ps;
|
15
controller/torrent.js
Normal file
15
controller/torrent.js
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const ps = require('./pubsub.js');
|
||||
const {Torrent} = require('>/models');
|
||||
|
||||
console.log('here!!!!!!!!!!!!!')
|
||||
|
||||
setInterval(async function(){
|
||||
ps.publish('torrent:server:status', await Torrent.trClient.sessionStats())
|
||||
}, 3000);
|
||||
|
||||
|
||||
// ps.subscribe(/./g, function(...args){
|
||||
// console.log('event', args);
|
||||
// });
|
154
inject.html
154
inject.html
@ -1,155 +1,7 @@
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script>
|
||||
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
|
||||
|
||||
<div id="dialog" title="Torrents">
|
||||
<h3>
|
||||
Torrents
|
||||
</h3>
|
||||
<ul>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script src="/__static-modules/jquery/dist/jquery.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function post(url, data, callback){
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callback(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var torrents = (function(){
|
||||
var torrents = {};
|
||||
|
||||
torrents.list = JSON.parse(window.localStorage.getItem('torrents') || '{}' ).list || [];
|
||||
|
||||
var in_list = function(data){
|
||||
return false;
|
||||
for(let torrent of torrents.list){
|
||||
if(torrent.hash === data.hash) return true;
|
||||
}
|
||||
};
|
||||
|
||||
torrents.add = function(data){
|
||||
if(in_list(data)) return false;
|
||||
torrents.list.push(data);
|
||||
torrents.updateStorage();
|
||||
};
|
||||
|
||||
torrents.updateStorage = function(){
|
||||
window.localStorage.setItem('torrents', JSON.stringify({list: torrents.list}))
|
||||
};
|
||||
|
||||
torrents.statusAll = function(callback){
|
||||
var list_count = torrents.list.length;
|
||||
var count = 0;
|
||||
|
||||
for(let torrent of torrents.list){
|
||||
if(torrent.percentDone === 1){
|
||||
count++;
|
||||
if(count === list_count){
|
||||
torrents.updateStorage();
|
||||
|
||||
(callback || function(){})(torrents.list)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$.getJSON('/__api/torrent/'+torrent.id, function(data){
|
||||
$.extend(true, torrent, data.cres.torrents[0])
|
||||
count++;
|
||||
if(count === list_count){
|
||||
torrents.updateStorage();
|
||||
|
||||
(callback || function(){})(torrents.list)
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
torrents.updateDialog = function(){
|
||||
var $ol = $($('#dialog').find('ul')[0]);
|
||||
|
||||
$ol.html('');
|
||||
|
||||
torrents.list.forEach(function(torrent){
|
||||
|
||||
let li = `<li>${torrent.name}`;
|
||||
|
||||
if(torrent.percentDone < 1){
|
||||
li += `
|
||||
<div id="progressbar-${torrent.hashString}"></div>
|
||||
ETA: ${moment().seconds(torrent.eta).fromNow()} Rate: ${Math.floor(torrent.rateDownload/1024/1024)}mb
|
||||
`
|
||||
}else{
|
||||
li += `<br /> Done! <a href="https://stuff.718it.biz/torrents/${torrent.name}" target="_blank"> HTTP Link</a>`
|
||||
}
|
||||
|
||||
li += `<hr /></li>`
|
||||
$ol.prepend(li)
|
||||
|
||||
$("#progressbar-"+torrent.hashString).progressbar({
|
||||
value: torrent.percentDone*100
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
$( document ).ready(function() {
|
||||
|
||||
torrents.statusAll();
|
||||
|
||||
torrents.timmer = setInterval(function(){
|
||||
console.log('auto update')
|
||||
torrents.statusAll(function(){
|
||||
torrents.updateDialog()
|
||||
$('body').prepend('<div id="tbp_proxy_header"></div>');
|
||||
$('#tbp_proxy_header').load('/__static/partial/header.html');
|
||||
});
|
||||
}, 2000)
|
||||
});
|
||||
|
||||
return torrents;
|
||||
})()
|
||||
|
||||
$( document ).ready(function() {
|
||||
|
||||
$($('input[name="q"]')[0]).before($('<img src="https://chocolatey.org/content/packageimages/transmission.2.92.svg" height=24 width=24/>').on('click', function(){
|
||||
torrents.statusAll(function(){
|
||||
console.log('stats all')
|
||||
$("#dialog").dialog();
|
||||
torrents.updateDialog()
|
||||
});
|
||||
|
||||
}))
|
||||
|
||||
$('a').each(function(idx, el){
|
||||
var $el = $(el);
|
||||
if($el.attr('href') && $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){
|
||||
torrents.add(data);
|
||||
// console.log(data);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
25
middleware/auth.js
Normal file
25
middleware/auth.js
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const { Auth } = require('>/controller/auth');
|
||||
|
||||
async function auth(req, res, next){
|
||||
try{
|
||||
req.token = await Auth.checkToken(req.header('auth-token'));
|
||||
req.user = await req.token.getUser();
|
||||
return next();
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function authIO(socket, next){
|
||||
try{
|
||||
let token = await Auth.checkToken(socket.handshake.auth.token || 0);
|
||||
socket.user = await token.getUser();
|
||||
next();
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {auth, authIO};
|
7
models/index.js
Normal file
7
models/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
User: require('./ldap/user').User,
|
||||
AuthToken: require('./sql').AuthToken,
|
||||
Torrent: require('./sql').Torrent
|
||||
};
|
99
models/ldap/group.js
Normal file
99
models/ldap/group.js
Normal file
@ -0,0 +1,99 @@
|
||||
'use strict';
|
||||
|
||||
const { Client, Attribute, Change } = require('ldapts');
|
||||
const conf = require('>/conf').ldap;
|
||||
|
||||
const client = new Client({
|
||||
url: conf.url,
|
||||
});
|
||||
|
||||
async function getGroups(client, member){
|
||||
try{
|
||||
|
||||
let memberFilter = member ? `(member=${member})`: ''
|
||||
|
||||
let groups = (await client.search(conf.groupBase, {
|
||||
scope: 'sub',
|
||||
filter: `(&(objectClass=groupOfNames)${memberFilter})`,
|
||||
attributes: ['*', 'createTimestamp', 'modifyTimestamp'],
|
||||
})).searchEntries;
|
||||
|
||||
return groups.map(function(group){
|
||||
if(!Array.isArray(group.member)) group.member = [group.member];
|
||||
return group
|
||||
});
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
var Group = {};
|
||||
|
||||
Group.list = async function(member){
|
||||
try{
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
let groups = await getGroups(client, member)
|
||||
|
||||
await client.unbind();
|
||||
|
||||
return groups.map(group => group.cn);
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Group.listDetail = async function(member){
|
||||
try{
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
let groups = await getGroups(client, member)
|
||||
|
||||
await client.unbind();
|
||||
|
||||
|
||||
return groups;
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Group.get = async function(data){
|
||||
try{
|
||||
|
||||
if(typeof data !== 'object'){
|
||||
let name = data;
|
||||
data = {};
|
||||
data.name = name;
|
||||
}
|
||||
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
let group = (await client.search(conf.groupBase, {
|
||||
scope: 'sub',
|
||||
filter: `(&(objectClass=groupOfNames)(cn=${data.name}))`,
|
||||
attributes: ['*', 'createTimestamp', 'modifyTimestamp'],
|
||||
})).searchEntries[0];
|
||||
|
||||
await client.unbind();
|
||||
|
||||
if(!Array.isArray(group.member)) group.member = [group.member];
|
||||
|
||||
if(group){
|
||||
let obj = Object.create(this);
|
||||
Object.assign(obj, group);
|
||||
|
||||
return obj;
|
||||
}else{
|
||||
let error = new Error('GroupNotFound');
|
||||
error.name = 'GroupNotFound';
|
||||
error.message = `LDAP:${data.cn} does not exists`;
|
||||
error.status = 404;
|
||||
throw error;
|
||||
}
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {Group};
|
6
models/ldap/index.js
Normal file
6
models/ldap/index.js
Normal file
@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
User: require('./user').User,
|
||||
Group: require('./group').Group,
|
||||
};
|
159
models/ldap/user.js
Normal file
159
models/ldap/user.js
Normal file
@ -0,0 +1,159 @@
|
||||
'use strict';
|
||||
|
||||
const {Client, Attribute} = require('ldapts');
|
||||
const LRUCache = require('lru-native2');
|
||||
const conf = require('>/conf').ldap;
|
||||
|
||||
var userLUR = new LRUCache({
|
||||
// The maximum age (in milliseconds) of an item.
|
||||
// The item will be removed if get() is called and the item is too old.
|
||||
// Default: 0, meaning items will never expire.
|
||||
maxAge: 60000,
|
||||
});
|
||||
|
||||
const client = new Client({
|
||||
url: conf.url,
|
||||
});
|
||||
|
||||
const user_parse = function(data){
|
||||
if(data[conf.userNameAttribute]){
|
||||
data.username = data[conf.userNameAttribute];
|
||||
data.userPassword = undefined;
|
||||
data.userBacking = "LDAP";
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var User = {}
|
||||
|
||||
User.backing = "LDAP";
|
||||
|
||||
User.list = async function(){
|
||||
try{
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
const res = await client.search(conf.userBase, {
|
||||
scope: 'sub',
|
||||
filter: conf.userFilter,
|
||||
attributes: ['*', 'createTimestamp', 'modifyTimestamp'],
|
||||
});
|
||||
|
||||
await client.unbind();
|
||||
|
||||
return res.searchEntries.map(function(user){return user.uid});
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
User.listDetail = async function(){
|
||||
try{
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
const res = await client.search(conf.userBase, {
|
||||
scope: 'sub',
|
||||
filter: conf.userFilter,
|
||||
attributes: ['*', 'createTimestamp', 'modifyTimestamp'],
|
||||
});
|
||||
|
||||
await client.unbind();
|
||||
|
||||
let users = [];
|
||||
|
||||
for(let user of res.searchEntries){
|
||||
let obj = Object.create(this);
|
||||
Object.assign(obj, user_parse(user));
|
||||
users.push(obj);
|
||||
}
|
||||
|
||||
return users;
|
||||
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
User.get = async function(data, key){
|
||||
try{
|
||||
if(typeof data !== 'object'){
|
||||
let uid = data;
|
||||
data = {};
|
||||
data.uid = uid;
|
||||
}
|
||||
|
||||
data.searchKey = data.searchKey || key || conf.userNameAttribute;
|
||||
data.searchValue = data.searchValue || data.uid;
|
||||
|
||||
let filter = `(&${conf.userFilter}(${data.searchKey}=${data.searchValue}))`;
|
||||
if(userLUR.get(filter)) return userLUR.get(filter)
|
||||
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
const res = await client.search(conf.userBase, {
|
||||
scope: 'sub',
|
||||
filter: filter,
|
||||
attributes: ['*', 'createTimestamp', 'modifyTimestamp'],
|
||||
});
|
||||
|
||||
await client.unbind();
|
||||
|
||||
if(res.searchEntries[0]){
|
||||
let obj = Object.create(this);
|
||||
Object.assign(obj, user_parse(res.searchEntries[0]));
|
||||
|
||||
userLUR.set(filter, obj);
|
||||
return obj;
|
||||
}else{
|
||||
let error = new Error('UserNotFound');
|
||||
error.name = 'UserNotFound';
|
||||
error.message = `LDAP:${data.searchValue} does not exists`;
|
||||
error.status = 404;
|
||||
throw error;
|
||||
}
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
User.exists = async function(data, key){
|
||||
// Return true or false if the requested entry exists ignoring error's.
|
||||
try{
|
||||
await this.get(data, key);
|
||||
|
||||
return true
|
||||
}catch(error){
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
User.login = async function(data){
|
||||
try{
|
||||
|
||||
let user = await this.get(data.uid || data[conf.userNameAttribute] || data.username);
|
||||
|
||||
await client.bind(user.dn, data.password);
|
||||
|
||||
await client.unbind();
|
||||
|
||||
return user;
|
||||
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = {User};
|
||||
|
||||
// (async function(){
|
||||
// try{
|
||||
// console.log(await User.list());
|
||||
|
||||
// console.log(await User.listDetail());
|
||||
|
||||
// console.log(await User.get('wmantly'))
|
||||
|
||||
// }catch(error){
|
||||
// console.error(error)
|
||||
// }
|
||||
// })()
|
49
models/sql/authtoken.js
Normal file
49
models/sql/authtoken.js
Normal file
@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (sequelize, DataTypes, Model) => {
|
||||
class AuthToken extends Model {
|
||||
/**
|
||||
* Helper method for defining associations.
|
||||
* This method is not a part of Sequelize lifecycle.
|
||||
* The `models/index` file will call this method automatically.
|
||||
*/
|
||||
static associate(models) {
|
||||
}
|
||||
|
||||
check(){
|
||||
// check expires_on date
|
||||
return this.is_valid;
|
||||
}
|
||||
}
|
||||
AuthToken.init({
|
||||
token:{
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
expires_on: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
validate:{
|
||||
isDate:true
|
||||
}
|
||||
},
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
ldapModel: 'User',
|
||||
allowNull: false,
|
||||
validate:{
|
||||
notNull: true,
|
||||
},
|
||||
},
|
||||
is_valid: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'AuthToken',
|
||||
});
|
||||
return AuthToken;
|
||||
};
|
3
models/sql/config/config.js
Normal file
3
models/sql/config/config.js
Normal file
@ -0,0 +1,3 @@
|
||||
const conf = require('../../../conf');
|
||||
|
||||
module.exports = conf.sql;
|
109
models/sql/index.js
Normal file
109
models/sql/index.js
Normal file
@ -0,0 +1,109 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { Sequelize, Utils } = require('sequelize');
|
||||
const process = require('process');
|
||||
const basename = path.basename(__filename);
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const config = require(__dirname + '/config/config.js');
|
||||
const db = {};
|
||||
|
||||
let sequelize;
|
||||
|
||||
// Connect sequelize models to LDAP models
|
||||
const ldapModels = require('../ldap');
|
||||
|
||||
function getFieldWithLdap(attributes){
|
||||
let out = [];
|
||||
|
||||
for (const [attribute, options] of Object.entries(attributes)) {
|
||||
if(options.ldapModel) out.push(attribute)
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
const sequilze_conf = {
|
||||
define: {
|
||||
hooks: {
|
||||
async afterValidate(instance) {
|
||||
let hasError = false;
|
||||
function itemError(key, validator, message){
|
||||
let error = new Sequelize.ValidationErrorItem(message);
|
||||
error.type = 'Validation error';
|
||||
error.path = key;
|
||||
error.origin = 'FUNCTION';
|
||||
error.instance = instance;
|
||||
error.validatorKey = 'validator';
|
||||
error.validatorName = 'validator';
|
||||
error.validatorArgs = [];
|
||||
error.original = [];
|
||||
|
||||
throw new Sequelize.ValidationError(null, [error]);
|
||||
}
|
||||
|
||||
for(let attribute of getFieldWithLdap(this.getAttributes())){
|
||||
let externalModel = ldapModels[this.getAttributes()[attribute].ldapModel];
|
||||
|
||||
if(!externalModel) itemError(attribute, 'modelExists', `LDAP model ${this.getAttributes()[attribute].ldapModel} not found.`);
|
||||
|
||||
if(!hasError && !(await externalModel.exists(instance[attribute])) ) itemError(attribute, 'foreignKey', `LDAP model has no object ${instance[attribute]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _Model extends Sequelize.Model{
|
||||
constructor(...args){
|
||||
super(...args)
|
||||
let hasLdap = getFieldWithLdap(this.constructor.getAttributes())
|
||||
for(let attribute of hasLdap){
|
||||
let externalModelName = this.constructor.getAttributes()[attribute].ldapModel;
|
||||
this[`get${externalModelName}`] = async function(){
|
||||
return await ldapModels[externalModelName].get(this[attribute]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Backward compatible with my LDAP and Redis models.
|
||||
// I will update the LDAP and Redis stuff to have method interfaces inline with sequilze
|
||||
static async get(token){
|
||||
return await this.findByPk(token);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (config.use_env_variable) {
|
||||
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
||||
} else {
|
||||
sequelize = new Sequelize(config.database, config.username, config.password, {...config, ...sequilze_conf});
|
||||
}
|
||||
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => {
|
||||
return (
|
||||
file.indexOf('.') !== 0 &&
|
||||
file !== basename &&
|
||||
file.slice(-3) === '.js' &&
|
||||
file.indexOf('.test.js') === -1
|
||||
);
|
||||
})
|
||||
.forEach(file => {
|
||||
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes, _Model);
|
||||
db[model.name] = model;
|
||||
});
|
||||
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
module.exports = db;
|
38
models/sql/migrations/20231230031017-create-auth-token.js
Normal file
38
models/sql/migrations/20231230031017-create-auth-token.js
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('AuthTokens', {
|
||||
token: {
|
||||
type: Sequelize.UUID,
|
||||
defaultValue: Sequelize.UUIDV4,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
is_valid: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: true,
|
||||
allowNull: false,
|
||||
},
|
||||
username: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
expires_on: {
|
||||
allowNull: true,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.dropTable('AuthTokens');
|
||||
}
|
||||
};
|
63
models/sql/migrations/20240101174644-create-torrent.js
Normal file
63
models/sql/migrations/20240101174644-create-torrent.js
Normal file
@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('Torrents', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
torrent_id: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
hashString: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
magnetLink: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.NUMBER
|
||||
},
|
||||
isPrivate: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
allowNull: false,
|
||||
},
|
||||
percentDone: {
|
||||
type: Sequelize.FLOAT
|
||||
},
|
||||
errorString: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
downloadDir: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
sizeWhenDone: {
|
||||
type: Sequelize.NUMBER,
|
||||
allowNull: true
|
||||
},
|
||||
added_by: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.dropTable('Torrents');
|
||||
}
|
||||
};
|
126
models/sql/torrent.js
Normal file
126
models/sql/torrent.js
Normal file
@ -0,0 +1,126 @@
|
||||
'use strict';
|
||||
|
||||
const Transmission = require('transmission-promise');
|
||||
const conf = require('>/conf');
|
||||
|
||||
const tr_client = new Transmission(conf.transmission)
|
||||
|
||||
const statusMap = [
|
||||
'STOPPED',
|
||||
'CHECK_WAIT',
|
||||
'CHECK',
|
||||
'DOWNLOAD_WAIT',
|
||||
'DOWNLOAD',
|
||||
'SEED_WAIT',
|
||||
'SEED',
|
||||
'ISOLATED',
|
||||
];
|
||||
|
||||
module.exports = (sequelize, DataTypes, Model) => {
|
||||
class Torrent extends Model {
|
||||
/**
|
||||
* Helper method for defining associations.
|
||||
* This method is not a part of Sequelize lifecycle.
|
||||
* The `models/index` file will call this method automatically.
|
||||
*/
|
||||
static associate(models) {
|
||||
// define association here
|
||||
}
|
||||
|
||||
static trClient = tr_client;
|
||||
|
||||
static async create(data, ...args){
|
||||
try{
|
||||
|
||||
// let instance = this.build(data);
|
||||
// console.log('instance', instance)
|
||||
await this.build(data).validate();
|
||||
// console.log('validate', val);
|
||||
|
||||
let res = await tr_client.addUrl(data.magnetLink);
|
||||
|
||||
return await super.create({
|
||||
magnetLink: data.magnetLink,
|
||||
torrent_id: res.id,
|
||||
hashString: res.hashString,
|
||||
name: res.name,
|
||||
added_by: data.added_by,
|
||||
status: 0,
|
||||
percentDone: 0,
|
||||
}, args);
|
||||
}catch (error){
|
||||
// console.log('Torrent create error', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getTorrentData(noUpdate){
|
||||
try{
|
||||
let res = ( await tr_client.get(Number(this.torrent_id), [
|
||||
"eta", "percentDone", "status", "rateDownload",
|
||||
"errorString", "hashString", 'name',
|
||||
'downloadDir',
|
||||
'files', //array of files
|
||||
'filesStats', // array of files with status
|
||||
'isFinished',
|
||||
'isStalled',
|
||||
'peers',
|
||||
'peersConnected', // array of peers,
|
||||
'sizeWhenDone',
|
||||
]) ).torrents[0];
|
||||
|
||||
await this.update(res);
|
||||
if(noUpdate) await this.save();
|
||||
return {...res, ...this.dataValues};
|
||||
}catch(error){
|
||||
console.error(`Torrent ${this.id} getTorrentData error`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Torrent.init({
|
||||
torrent_id: DataTypes.STRING,
|
||||
magnetLink: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate:{
|
||||
notNull: true,
|
||||
notEmpty: true,
|
||||
},
|
||||
},
|
||||
isPrivate: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
hashString: DataTypes.STRING,
|
||||
name: DataTypes.STRING,
|
||||
added_by: {
|
||||
type: DataTypes.STRING,
|
||||
ldapModel: 'User',
|
||||
allowNull: false,
|
||||
validate:{
|
||||
notNull: true,
|
||||
notEmpty: true,
|
||||
},
|
||||
},
|
||||
status: DataTypes.NUMBER,
|
||||
percentDone: DataTypes.FLOAT,
|
||||
downloadDir: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
errorString: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
sizeWhenDone: {
|
||||
type: DataTypes.NUMBER,
|
||||
allowNull: true,
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'Torrent',
|
||||
logging: false,
|
||||
});
|
||||
return Torrent;
|
||||
};
|
4972
package-lock.json
generated
4972
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@ -4,13 +4,32 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"migrate": "npx sequelize-cli db:migrate",
|
||||
"start": "node ./bin/www",
|
||||
"start-dev": "npx nodemon ./bin/www"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.17.1",
|
||||
"ejs": "^3.1.9",
|
||||
"express": "^4.18.2",
|
||||
"extend": "^3.0.2",
|
||||
"http-proxy-middleware": "^0.20.0",
|
||||
"transmission-promise": "^1.1.4"
|
||||
"jquery": "^3.7.1",
|
||||
"jquery-ui": "^1.13.2",
|
||||
"ldapts": "^7.0.7",
|
||||
"lru-native2": "^1.2.6",
|
||||
"moment": "^2.30.1",
|
||||
"mustache": "^4.2.0",
|
||||
"p2psub": "^0.1.9",
|
||||
"sequelize": "^6.35.2",
|
||||
"sequelize-cli": "^6.6.2",
|
||||
"socket.io": "^4.7.2",
|
||||
"sqlite3": "^5.1.7-rc.0",
|
||||
"transmission-promise": "^1.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.0.2"
|
||||
}
|
||||
}
|
||||
|
445
public/img/Transmission_Icon.svg
Normal file
445
public/img/Transmission_Icon.svg
Normal file
@ -0,0 +1,445 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="48px"
|
||||
height="48px"
|
||||
id="svg5186"
|
||||
sodipodi:version="0.32"
|
||||
inkscape:version="0.45+devel"
|
||||
sodipodi:docname="transmission.svg"
|
||||
inkscape:output_extension="org.inkscape.output.svg.inkscape"
|
||||
inkscape:export-filename="/home/andreas/project/application icons/48x48/transmission.png"
|
||||
inkscape:export-xdpi="90"
|
||||
inkscape:export-ydpi="90">
|
||||
<defs
|
||||
id="defs5188">
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient9795">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop9797" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop9799" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient9783">
|
||||
<stop
|
||||
style="stop-color:#000000;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop9785" />
|
||||
<stop
|
||||
style="stop-color:#000000;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop9787" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient9775">
|
||||
<stop
|
||||
style="stop-color:#f9f9f9;stop-opacity:1"
|
||||
offset="0"
|
||||
id="stop9777" />
|
||||
<stop
|
||||
style="stop-color:#eeeeec;stop-opacity:0.62037037"
|
||||
offset="1"
|
||||
id="stop9779" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient5948">
|
||||
<stop
|
||||
style="stop-color:#787b76;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop5950" />
|
||||
<stop
|
||||
id="stop5956"
|
||||
offset="0.87125719"
|
||||
style="stop-color:#babcb9;stop-opacity:1" />
|
||||
<stop
|
||||
style="stop-color:#787b76;stop-opacity:1"
|
||||
offset="1"
|
||||
id="stop5952" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient5908">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop5910" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop5912" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient5898">
|
||||
<stop
|
||||
style="stop-color:#cc0000;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop5900" />
|
||||
<stop
|
||||
id="stop5906"
|
||||
offset="0.36509839"
|
||||
style="stop-color:#ef0000;stop-opacity:1" />
|
||||
<stop
|
||||
style="stop-color:#aa0000;stop-opacity:1"
|
||||
offset="1"
|
||||
id="stop5902" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient5871">
|
||||
<stop
|
||||
style="stop-color:#f0f2ef;stop-opacity:1"
|
||||
offset="0"
|
||||
id="stop5873" />
|
||||
<stop
|
||||
style="stop-color:#cdd1c8;stop-opacity:1"
|
||||
offset="1"
|
||||
id="stop5875" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient5843">
|
||||
<stop
|
||||
style="stop-color:#888a85;stop-opacity:1"
|
||||
offset="0"
|
||||
id="stop5845" />
|
||||
<stop
|
||||
style="stop-color:#2e3436;stop-opacity:1"
|
||||
offset="1"
|
||||
id="stop5847" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient5835">
|
||||
<stop
|
||||
style="stop-color:#555753;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop5837" />
|
||||
<stop
|
||||
style="stop-color:#2e3436;stop-opacity:1"
|
||||
offset="1"
|
||||
id="stop5839" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient5823">
|
||||
<stop
|
||||
style="stop-color:#2e3436;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop5825" />
|
||||
<stop
|
||||
style="stop-color:#2e3436;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop5827" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient5234">
|
||||
<stop
|
||||
style="stop-color:#babdb6;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop5236" />
|
||||
<stop
|
||||
id="stop5242"
|
||||
offset="0.13299191"
|
||||
style="stop-color:#eeeeec;stop-opacity:1" />
|
||||
<stop
|
||||
style="stop-color:#babdb6;stop-opacity:1"
|
||||
offset="1"
|
||||
id="stop5238" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient5234"
|
||||
id="linearGradient5240"
|
||||
x1="23.738585"
|
||||
y1="4.156569"
|
||||
x2="23.738585"
|
||||
y2="19.46567"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient5823"
|
||||
id="linearGradient5829"
|
||||
x1="23.732271"
|
||||
y1="30.057167"
|
||||
x2="23.688078"
|
||||
y2="22.632544"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient5835"
|
||||
id="linearGradient5841"
|
||||
x1="23.9375"
|
||||
y1="30.616879"
|
||||
x2="23.9375"
|
||||
y2="36.357994"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient5843"
|
||||
id="linearGradient5849"
|
||||
x1="20.771132"
|
||||
y1="32.248005"
|
||||
x2="20.563131"
|
||||
y2="23.939499"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient5898"
|
||||
id="linearGradient5904"
|
||||
x1="14.8125"
|
||||
y1="5.6244211"
|
||||
x2="14.8125"
|
||||
y2="9"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient5908"
|
||||
id="linearGradient5914"
|
||||
x1="24.040522"
|
||||
y1="5.0690055"
|
||||
x2="24.040522"
|
||||
y2="10.0086"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient5871"
|
||||
id="linearGradient5928"
|
||||
x1="13.625"
|
||||
y1="33.125"
|
||||
x2="14.125"
|
||||
y2="24"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient5948"
|
||||
id="linearGradient5954"
|
||||
x1="10.1875"
|
||||
y1="20.25"
|
||||
x2="10.1875"
|
||||
y2="42.5"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter9771"
|
||||
x="-0.02976581"
|
||||
width="1.0595316"
|
||||
y="-0.13995509"
|
||||
height="1.2799102">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="0.5196773"
|
||||
id="feGaussianBlur9773" />
|
||||
</filter>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient9775"
|
||||
id="linearGradient9781"
|
||||
x1="24.71875"
|
||||
y1="35.958694"
|
||||
x2="23.936657"
|
||||
y2="17.070877"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient9783"
|
||||
id="linearGradient9789"
|
||||
x1="18.3125"
|
||||
y1="20.743757"
|
||||
x2="18.3125"
|
||||
y2="21.814325"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient9795"
|
||||
id="linearGradient9801"
|
||||
x1="30.4375"
|
||||
y1="31.82852"
|
||||
x2="29.742416"
|
||||
y2="27.45352"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="5.6568542"
|
||||
inkscape:cx="30.372474"
|
||||
inkscape:cy="21.423534"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="true"
|
||||
inkscape:grid-bbox="true"
|
||||
inkscape:document-units="px"
|
||||
inkscape:window-width="1091"
|
||||
inkscape:window-height="777"
|
||||
inkscape:window-x="557"
|
||||
inkscape:window-y="164">
|
||||
<inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid5195" />
|
||||
</sodipodi:namedview>
|
||||
<metadata
|
||||
id="metadata5191">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
id="layer1"
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer">
|
||||
<rect
|
||||
style="opacity:0.28240741;fill:#2e3436;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;filter:url(#filter9771)"
|
||||
id="rect9761"
|
||||
width="41.901279"
|
||||
height="8.9116125"
|
||||
x="3"
|
||||
y="39"
|
||||
rx="2.2980971"
|
||||
ry="2.2980971" />
|
||||
<path
|
||||
style="fill:url(#linearGradient5954);fill-rule:evenodd;stroke:#555753;stroke-width:1.00000011999999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
|
||||
d="M 10,16.59375 C 8.8196081,16.548814 7.6402135,17.571722 7.53125,18.8125 C 6.643292,26.100083 5.3269606,33.403527 4.65625,40.6875 L 4.65625,43.75 C 4.6900093,45.329492 5.7271791,46.392039 6.875,46.59375 L 41.5,46.59375 C 42.479024,46.569246 43.565009,45.89005 43.53125,44.59375 L 43.53125,40.65625 L 40.40625,19.4375 C 40.152431,18.135677 39.039534,16.752716 37.5,16.59375 L 10,16.59375 z"
|
||||
id="path5232"
|
||||
sodipodi:nodetypes="ccccccccccc" />
|
||||
<path
|
||||
style="fill:url(#linearGradient5928);fill-opacity:1;fill-rule:evenodd;stroke:#555753;stroke-width:0.99999994000000003px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 10.601853,39.624614 C 9.47224,39.502143 8.6733861,38.760954 8.7014295,37.401046 L 10.601853,21.407733 C 10.893931,20.339398 11.586949,19.485349 12.680909,19.488442 L 34.605501,19.488442 C 35.691818,19.455762 36.778134,20.208796 37.062569,21.104687 L 39.478435,37.237611 C 39.535481,38.706714 38.931012,39.557098 37.913093,39.523599 L 10.601853,39.624614 z"
|
||||
id="path5230"
|
||||
sodipodi:nodetypes="ccccccccc" />
|
||||
<path
|
||||
style="fill:url(#linearGradient5841);fill-rule:evenodd;stroke:url(#linearGradient5849);stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
|
||||
d="M 20.46875,20.4375 L 18.40625,32.46875 L 15.4375,32.46875 L 23.46875,37.625 L 32.4375,32.46875 L 29.46875,32.46875 L 27.59375,20.4375 L 20.46875,20.4375 z"
|
||||
id="path5197"
|
||||
sodipodi:nodetypes="cccccccc" />
|
||||
<rect
|
||||
style="opacity:1;fill:url(#linearGradient5904);fill-opacity:1;stroke:#930000;stroke-width:1.00000011999999994;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="rect5224"
|
||||
width="31.113209"
|
||||
height="6.0609155"
|
||||
x="8.4847708"
|
||||
y="4.5135489"
|
||||
rx="5.0159144"
|
||||
ry="1.9854566" />
|
||||
<rect
|
||||
style="opacity:0.58333333;fill:none;fill-opacity:1;stroke:url(#linearGradient5914);stroke-width:1.00000011999999994;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="rect5896"
|
||||
width="29.080278"
|
||||
height="3.9395947"
|
||||
x="9.5003824"
|
||||
y="5.5690055"
|
||||
rx="1.8339339"
|
||||
ry="1.2783499" />
|
||||
<path
|
||||
style="opacity:0.24537036000000001;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient9781);stroke-width:1.00000011999999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 10.592965,17.57221 C 9.474152,17.53019 8.3562869,18.486727 8.2530054,19.647002 L 5.4687498,39.722803 C 5.4796612,39.847886 5.4997885,39.979699 5.5279893,40.102694 L 5.5279893,42.966491 C 5.559989,44.443503 6.5430497,45.407885 7.6309909,45.596509 L 40.479283,45.596509 C 41.407232,45.573597 42.406944,44.967688 42.374947,43.755497 L 42.374947,40.073472 C 42.382229,40.044972 42.398547,40.013922 42.404566,39.985805 L 42.374947,39.781247 L 42.374947,39.576691 L 42.345327,39.576691 L 39.442592,20.202228 C 39.202015,18.98487 38.147175,17.72086 36.687956,17.57221 L 10.592965,17.57221 z"
|
||||
id="path5881" />
|
||||
<path
|
||||
style="fill:url(#linearGradient9789);fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1;opacity:0.20833333000000001"
|
||||
d="M 10.210155,29.955767 L 12.048004,22 L 36.07815,22.05802 L 37.857941,31.044156 L 36.681164,21.969631 C 36.460193,20.967897 35.929863,20 34.957591,20.025088 L 13.037281,19.980893 C 11.606886,19.936699 11.32554,20.864777 11,21.969631 L 10.210155,29.955767 z"
|
||||
id="path5926"
|
||||
sodipodi:nodetypes="ccccccccc" />
|
||||
<rect
|
||||
style="opacity:1;fill:url(#linearGradient5240);fill-opacity:1;stroke:#888a85;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="rect5226"
|
||||
width="7.0964494"
|
||||
height="25.970053"
|
||||
x="20.48369"
|
||||
y="3.6044116"
|
||||
rx="1.0763195"
|
||||
ry="1.0763192" />
|
||||
<rect
|
||||
style="opacity:1;fill:url(#linearGradient5829);fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="rect5244"
|
||||
width="8.1317272"
|
||||
height="8.0433397"
|
||||
x="19.975765"
|
||||
y="22.013826"
|
||||
rx="1.0763195"
|
||||
ry="1.0763192" />
|
||||
<path
|
||||
style="opacity:0.43518521;fill:none;fill-rule:evenodd;stroke:#ffffff;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 11.423372,41.486321 L 39.533811,41.486321"
|
||||
id="path5879"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<rect
|
||||
style="opacity:0.22685185;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="rect5892"
|
||||
width="5.151906"
|
||||
height="23.93712"
|
||||
x="21.428234"
|
||||
y="4.6321397"
|
||||
rx="1.0763195"
|
||||
ry="1.0763192" />
|
||||
<g
|
||||
id="g5972"
|
||||
style="opacity:0.62037037">
|
||||
<path
|
||||
sodipodi:nodetypes="cc"
|
||||
id="path5831"
|
||||
d="M 20.4375,30.5 L 27.5,30.5"
|
||||
style="fill:none;fill-rule:evenodd;stroke:#888a85;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1;opacity:1" />
|
||||
<path
|
||||
sodipodi:nodetypes="cc"
|
||||
id="path5833"
|
||||
d="M 19.960998,32.5 L 27.976504,32.5"
|
||||
style="fill:none;fill-rule:evenodd;stroke:#888a85;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1;opacity:0.68055556" />
|
||||
<path
|
||||
sodipodi:nodetypes="cc"
|
||||
id="path5958"
|
||||
d="M 20.273498,31.5 L 27.726504,31.5"
|
||||
style="fill:none;fill-rule:evenodd;stroke:#5d5d5c;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1;opacity:1" />
|
||||
<path
|
||||
sodipodi:nodetypes="cc"
|
||||
id="path5960"
|
||||
d="M 19.869986,33.488738 L 28.141277,33.488738"
|
||||
style="fill:none;fill-rule:evenodd;stroke:#5d5d5c;stroke-width:0.99999994000000003px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1;opacity:0.68055556" />
|
||||
</g>
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#ffffff;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 14.381412,31.513733 L 17.519198,31.513733"
|
||||
id="path9791"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#ffffff;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 30.443912,31.451233 L 33.581698,31.451233"
|
||||
id="path9803"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
sodipodi:type="arc"
|
||||
style="opacity:0.33500001;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="path5119"
|
||||
sodipodi:cx="9.8553009"
|
||||
sodipodi:cy="42.188465"
|
||||
sodipodi:rx="1.1932427"
|
||||
sodipodi:ry="1.0827572"
|
||||
d="M 11.048544,42.188465 A 1.1932427,1.0827572 0 1 1 8.6620582,42.188465 A 1.1932427,1.0827572 0 1 1 11.048544,42.188465 z"
|
||||
transform="matrix(0.4216252,0,0,0.4766032,5.3634688,21.39228)" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 16 KiB |
412
public/js/app.js
Normal file
412
public/js/app.js
Normal file
@ -0,0 +1,412 @@
|
||||
var app = {};
|
||||
|
||||
app.pubsub = (function(){
|
||||
app.topics = {};
|
||||
|
||||
app.subscribe = function(topic, listener) {
|
||||
if(topic instanceof RegExp){
|
||||
listener.match = topic;
|
||||
topic = "__REGEX__";
|
||||
}
|
||||
|
||||
// create the topic if not yet created
|
||||
if(!app.topics[topic]) app.topics[topic] = [];
|
||||
|
||||
// add the listener
|
||||
app.topics[topic].push(listener);
|
||||
}
|
||||
|
||||
app.matchTopics = function(topic){
|
||||
topic = topic || '';
|
||||
var matches = [... app.topics[topic] ? app.topics[topic] : []];
|
||||
|
||||
if(!app.topics['__REGEX__']) return matches;
|
||||
|
||||
for(var listener of app.topics['__REGEX__']){
|
||||
if(topic.match(listener.match)) matches.push(listener);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
app.publish = function(topic, data) {
|
||||
|
||||
// send the event to all listeners
|
||||
app.matchTopics(topic).forEach(function(listener) {
|
||||
setTimeout(function(data, topic){
|
||||
listener(data || {}, topic);
|
||||
}, 0, data, topic);
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
})(app);
|
||||
|
||||
app.socket = (function(app){
|
||||
// $.getScript('/socket.io/socket.io.js')
|
||||
// <script type="text/javascript" src="/socket.io/socket.io.js"></script>
|
||||
|
||||
var socket;
|
||||
$(document).ready(function(){
|
||||
socket = io({
|
||||
auth: {
|
||||
token: app.auth.getToken()
|
||||
}
|
||||
});
|
||||
// socket.emit('chat message', $('#m').val());
|
||||
socket.on('P2PSub', function(msg){
|
||||
msg.data.__noSocket = true;
|
||||
app.publish(msg.topic, msg.data);
|
||||
});
|
||||
|
||||
app.subscribe(/./g, function(data, topic){
|
||||
// console.log('local_pubs', data, topic)
|
||||
if(data.__noSocket) return;
|
||||
// console.log('local_pubs 2', data, topic)
|
||||
|
||||
socket.emit('P2PSub', { topic, data })
|
||||
});
|
||||
})
|
||||
|
||||
return socket;
|
||||
|
||||
})(app);
|
||||
|
||||
app.api = (function(app){
|
||||
var baseURL = '/__api/'
|
||||
|
||||
function post(url, data, callback){
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: baseURL+url,
|
||||
headers:{
|
||||
'auth-token': app.auth.getToken()
|
||||
},
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callback(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function put(url, data, callback){
|
||||
$.ajax({
|
||||
type: 'PUT',
|
||||
url: baseURL+url,
|
||||
headers:{
|
||||
'auth-token': app.auth.getToken()
|
||||
},
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callback(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function remove(url, callback, callback2){
|
||||
if(!$.isFunction(callback)) callback = callback2;
|
||||
$.ajax({
|
||||
type: 'delete',
|
||||
url: baseURL+url,
|
||||
headers:{
|
||||
'auth-token': app.auth.getToken()
|
||||
},
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callback(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function get(url, callback){
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: baseURL+url,
|
||||
headers:{
|
||||
'auth-token': app.auth.getToken()
|
||||
},
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callback(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {post: post, get: get, put: put, delete: remove}
|
||||
})(app)
|
||||
|
||||
app.auth = (function(app) {
|
||||
var user = {}
|
||||
function setToken(token){
|
||||
localStorage.setItem('APIToken', token);
|
||||
}
|
||||
|
||||
function getToken(){
|
||||
return localStorage.getItem('APIToken');
|
||||
}
|
||||
|
||||
function isLoggedIn(callback){
|
||||
if(getToken()){
|
||||
return app.api.get('user/me', function(error, data){
|
||||
if(error === 'Unauthorized') logOut();
|
||||
if(!error) app.auth.user = data;
|
||||
return callback(error, data);
|
||||
});
|
||||
}else{
|
||||
callback(null, false);
|
||||
}
|
||||
}
|
||||
|
||||
function logIn(args, callback){
|
||||
app.api.post('auth/login', args, function(error, data){
|
||||
if(data.login){
|
||||
setToken(data.token);
|
||||
}
|
||||
callback(error, !!data.token);
|
||||
});
|
||||
}
|
||||
|
||||
function logOut(callback){
|
||||
callback = callback || app.util.emptyFuction;
|
||||
localStorage.removeItem('APIToken');
|
||||
callback();
|
||||
}
|
||||
|
||||
function makeUserFromInvite(args, callback){
|
||||
app.api.post('auth/invite/'+ args.token, args, function(error, data){
|
||||
if(data.login){
|
||||
callback(null, data);
|
||||
setToken(data.token);
|
||||
}
|
||||
callback(error, !!data.token);
|
||||
});
|
||||
}
|
||||
|
||||
function forceLogin(){
|
||||
$.holdReady( true );
|
||||
app.auth.isLoggedIn(function(error, isLoggedIn){
|
||||
if(error || !isLoggedIn){
|
||||
app.auth.logOut(function(){})
|
||||
location.replace(`/login${location.href.replace(location.origin, '')}`);
|
||||
}else{
|
||||
$.holdReady( false );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function logInRedirect(){
|
||||
window.location.href = location.href.replace(location.origin+'/login', '') || '/'
|
||||
}
|
||||
|
||||
|
||||
$( document ).ready( function(){
|
||||
isLoggedIn(function(error, isLoggedIn){
|
||||
if(!error && isLoggedIn){
|
||||
$('.tbp_proxy_is_authed').show();
|
||||
$('.tbp_proxy_not_authed').hide();
|
||||
}else{
|
||||
$('.tbp_proxy_is_authed').hide();
|
||||
$('.tbp_proxy_not_authed').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
getToken: getToken,
|
||||
setToken: setToken,
|
||||
isLoggedIn: isLoggedIn,
|
||||
logIn: logIn,
|
||||
logOut: logOut,
|
||||
makeUserFromInvite: makeUserFromInvite,
|
||||
forceLogin,
|
||||
logInRedirect,
|
||||
}
|
||||
|
||||
})(app);
|
||||
|
||||
app.util = (function(app){
|
||||
|
||||
function getUrlParameter(name) {
|
||||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
||||
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
||||
var results = regex.exec(location.search);
|
||||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||
};
|
||||
|
||||
function actionMessage(message, $target, type, callback){
|
||||
message = message || '';
|
||||
$target = $target.closest('div.card').find('.actionMessage');
|
||||
type = type || 'info';
|
||||
callback = callback || function(){};
|
||||
|
||||
if($target.html() === message) return;
|
||||
|
||||
if($target.html()){
|
||||
$target.slideUp('fast', function(){
|
||||
$target.html('')
|
||||
$target.removeClass (function (index, className) {
|
||||
return (className.match (/(^|\s)ui-\S+/g) || []).join(' ');
|
||||
});
|
||||
if(message) return actionMessage(message, $target, type, callback);
|
||||
$target.hide()
|
||||
})
|
||||
}else{
|
||||
if(type) $target.addClass('ui-' + type);
|
||||
$target.html(message).slideDown('fast');
|
||||
}
|
||||
setTimeout(callback,10)
|
||||
}
|
||||
|
||||
$.fn.serializeObject = function() {
|
||||
var
|
||||
arr = $(this).serializeArray(),
|
||||
obj = {};
|
||||
|
||||
for(var i = 0; i < arr.length; i++) {
|
||||
if(obj[arr[i].name] === undefined) {
|
||||
obj[arr[i].name] = arr[i].value;
|
||||
} else {
|
||||
if(!(obj[arr[i].name] instanceof Array)) {
|
||||
obj[arr[i].name] = [obj[arr[i].name]];
|
||||
}
|
||||
obj[arr[i].name].push(arr[i].value);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
return {
|
||||
getUrlParameter: getUrlParameter,
|
||||
actionMessage: actionMessage,
|
||||
emptyFuction: function(){},
|
||||
|
||||
}
|
||||
})(app);
|
||||
|
||||
|
||||
app.user = (function(app){
|
||||
function list(callback){
|
||||
app.api.get('user/?detail=true', function(error, data){
|
||||
callback(error, data);
|
||||
})
|
||||
}
|
||||
|
||||
function add(args, callback){
|
||||
app.api.post('user/', args, function(error, data){
|
||||
callback(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function remove(args, callback){
|
||||
if(!confirm('Delete '+ args.uid+ 'user?')) return false;
|
||||
app.api.delete('user/'+ args.uid, function(error, data){
|
||||
callback(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function changePassword(args, callback){
|
||||
app.api.put('users/'+ arg.uid || '', args, function(error, data){
|
||||
callback(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function createInvite(callback){
|
||||
app.api.post('user/invite', {}, function(error, data, status){
|
||||
callback(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function consumeInvite(args){
|
||||
app.api.post('/auth/invite/'+args.token, args, function(error, data){
|
||||
if(data.token){
|
||||
app.auth.setToken(data.token)
|
||||
return callback(null, true)
|
||||
}
|
||||
callback(error)
|
||||
});
|
||||
}
|
||||
|
||||
return {list, remove, createInvite};
|
||||
|
||||
})(app);
|
||||
|
||||
app.group = (function(app){
|
||||
function list(callback){
|
||||
app.api.get('group?detail=true', function(error, data){
|
||||
callback(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function remove(args, callback){
|
||||
app.api.delete('group/'+args.cn, function(error, data){
|
||||
callback(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
return {list, remove}
|
||||
})(app);
|
||||
|
||||
$( document ).ready( function () {
|
||||
|
||||
$( 'div.row' ).fadeIn( 'slow' ); //show the page
|
||||
|
||||
//panel button's
|
||||
$( '.fa-arrows-v' ).click( function () {
|
||||
$( this ).closest( '.card' ).find( '.card-body' ).slideToggle( 'fast' );
|
||||
});
|
||||
|
||||
$('.actionMessage').on('click', 'button.action-close', function(event){
|
||||
app.util.actionMessage(null, $(this));
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
//ajax form submit
|
||||
function formAJAX( btn, del ) {
|
||||
event.preventDefault(); // avoid to execute the actual submit of the form.
|
||||
var $form = $(btn).closest( '[action]' ); // gets the 'form' parent
|
||||
var formData = $form.find( '[name]' ).serializeObject(); // builds query formDataing
|
||||
var method = $form.attr('method') || 'post';
|
||||
|
||||
// if( !$form.validate()) {
|
||||
// app.util.actionMessage('Please fix the form errors.', $form, 'danger')
|
||||
// return false;
|
||||
// }
|
||||
|
||||
app.util.actionMessage(
|
||||
'<div class="spinner-border" role="status"><span class="sr-only">Loading...</span></div>',
|
||||
$form,
|
||||
'state-highlight'
|
||||
);
|
||||
|
||||
app.api[method]($form.attr('action'), formData, function(error, data){
|
||||
app.util.actionMessage(data.message, $form, error ? 'state-error' : 'priority-primary'); //re-populate table
|
||||
if(!error){
|
||||
$form.trigger("reset");
|
||||
eval($form.attr('evalAJAX')); //gets JS to run after completion
|
||||
}
|
||||
});
|
||||
|
||||
}
|
283
public/lib/js/jq-repeat.js
Normal file
283
public/lib/js/jq-repeat.js
Normal file
@ -0,0 +1,283 @@
|
||||
(function($, Mustache){
|
||||
'use strict';
|
||||
if (!$.scope) {
|
||||
$.scope = {};
|
||||
}
|
||||
|
||||
var make = function( element ){
|
||||
|
||||
//construct array
|
||||
function makeArray( input ){
|
||||
|
||||
var result = [];
|
||||
|
||||
Object.defineProperty( result, "__repeatId", {
|
||||
value: repeatId,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
} );
|
||||
|
||||
Object.defineProperty( result, "__rq_template", {
|
||||
value: '',
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
} );
|
||||
|
||||
result.splice = function(inputValue, ...args){
|
||||
//splice does all the heavy lifting by interacting with the DOM elements.
|
||||
|
||||
var toProto = [...args]
|
||||
|
||||
var index;
|
||||
//if a string is submitted as the index, try to match it to index number
|
||||
if( typeof arguments[0] === 'string' ){
|
||||
index = this.indexOf( arguments[0] );//set where to start
|
||||
if ( index === -1 ) {
|
||||
return [];
|
||||
}
|
||||
}else{
|
||||
index = arguments[0]; //set where to start
|
||||
}
|
||||
|
||||
toProto.unshift(index)
|
||||
|
||||
|
||||
var howMany = arguments[1]; //sets the amount of fields to remove
|
||||
var args = Array.prototype.slice.call( arguments ); // coverts arguments into array
|
||||
var toAdd = args.slice(2); // only keeps fields to add to array
|
||||
|
||||
// if the starting point is higher then the total index count, start at the end
|
||||
if( index > this.length ) {
|
||||
index = this.length;
|
||||
}
|
||||
// if the starting point is negative, start form the end of the array, minus the start point
|
||||
if( index < 0 ) {
|
||||
index = this.length - Math.abs( index );
|
||||
}
|
||||
|
||||
// if there are things to add, figure out the how many new indexes we need
|
||||
if( !howMany && howMany !== 0 ) {
|
||||
howMany = this.length - index;
|
||||
}
|
||||
//not sure why i put this here... but it does matter!
|
||||
if( howMany > this.length - index ) {
|
||||
howMany = this.length - index;
|
||||
}
|
||||
|
||||
//figure out how many positions we need to shift the current elements
|
||||
var shift = toAdd.length - howMany;
|
||||
|
||||
// figure out how big the new array will be
|
||||
// var newLength = this.length + shift;
|
||||
|
||||
//removes fields from array based on howMany needs to be removed
|
||||
for( var i = index; i < +index+howMany; i++ ) {
|
||||
this.__take.apply( this[index].__jq_$el );
|
||||
// this.__take.apply( $( '.jq-repeat-'+ this.__repeatId +'[jq-repeat-index="'+ ( i + index ) +'"]' ) );
|
||||
}
|
||||
|
||||
//re-factor element index's
|
||||
for(var i = 0; i < this.length; i++){
|
||||
if( i >= index){
|
||||
|
||||
this[i].__jq_$el.attr( 'jq-repeat-index', i+shift );
|
||||
}
|
||||
}
|
||||
|
||||
//if there are fields to add to the array, add them
|
||||
if( toAdd.length > 0 ){
|
||||
|
||||
//$.each( toAdd, function( key, value ){
|
||||
for(var I = 0; I < toAdd.length; I++){
|
||||
|
||||
//figure out new elements index
|
||||
var key = I + index;
|
||||
// apply values to template
|
||||
var render = Mustache.render( this.__rq_template, toAdd[I] );
|
||||
|
||||
//set call name and index keys to DOM element
|
||||
var $render = $( render ).addClass( 'jq-repeat-'+ this.__repeatId ).attr( 'jq-repeat-index', key );
|
||||
|
||||
|
||||
//if add new elements in proper stop, or after the place holder.
|
||||
if( key === 0 ){
|
||||
$( '.jq-repeat-'+ this.__repeatId +'[jq-repeat-index="holder"]' ).after( $render );
|
||||
}else{
|
||||
$( '.jq-repeat-'+ this.__repeatId +'[jq-repeat-index="' + ( key -1 ) + '"]' ).after( $render );
|
||||
}
|
||||
|
||||
Object.defineProperty( toAdd[I], "__jq_$el", {
|
||||
value: $render,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
} );
|
||||
|
||||
//animate element
|
||||
this.__put.apply($render, [toAdd[I]]);
|
||||
}
|
||||
}
|
||||
|
||||
//set and return new array
|
||||
return Array.prototype.splice.apply(this, toProto);
|
||||
};
|
||||
result.push = function(){
|
||||
//add one or more objects to the array
|
||||
|
||||
//set the index value, if none is set make it zero
|
||||
var index = this.length || 0;
|
||||
|
||||
//loop each passed object and pass it to slice
|
||||
for (var i = 0 ; i < arguments.length; ++i) {
|
||||
this.splice( ( index + i ), 0, arguments[i] );
|
||||
}
|
||||
|
||||
//return new array length
|
||||
return this.length;
|
||||
};
|
||||
|
||||
result.unshift = function(item){
|
||||
return this.splice(0, 0, item);
|
||||
};
|
||||
|
||||
result.pop = function(){
|
||||
//remove and return array element
|
||||
|
||||
return this.splice( -1, 1 )[0];
|
||||
};
|
||||
result.reverse = function() {
|
||||
var temp = this.splice( 0 );
|
||||
Array.prototype.reverse.apply( temp );
|
||||
|
||||
for( var i = 0; i < temp.length; i++ ){
|
||||
this.push( temp[i] );
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
result.shift = function() {
|
||||
return this.splice( 0, 1 )[0];
|
||||
};
|
||||
result.loop = function(){
|
||||
var temp = this[0];
|
||||
this.splice( 0,1 );
|
||||
this.push( temp );
|
||||
|
||||
return temp;
|
||||
};
|
||||
result.loopUp = function(){
|
||||
var temp = this[this.length-1];
|
||||
this.splice( -1, 1 );
|
||||
this.splice( 0, 0, temp );
|
||||
return temp;
|
||||
};
|
||||
result.indexOf = function( key, value ){
|
||||
if( !value ){
|
||||
value = arguments[0];
|
||||
key = this.__index;
|
||||
}
|
||||
for ( var index = 0; index < this.length; ++index ) {
|
||||
if( this[index][key] === value ){
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
result.update = function( key, value, update ){
|
||||
//set variables using sting for index
|
||||
|
||||
// If update is called with no index/key, assume its the 0
|
||||
if(typeof key === 'object'){
|
||||
if(this[0]){
|
||||
return this.update(0, key);
|
||||
}
|
||||
return this.splice(0, 1, key);
|
||||
}
|
||||
|
||||
if( !update ){
|
||||
update = arguments[1];
|
||||
value = arguments[0];
|
||||
key = this.__index;
|
||||
}
|
||||
|
||||
var index = this.indexOf( key, value );
|
||||
|
||||
if(index === -1) {
|
||||
return [];
|
||||
}
|
||||
var object = $.extend( true, {}, this[index], update );
|
||||
return this.splice( index, 1, object )[0];
|
||||
};
|
||||
result.__put = function(){
|
||||
this.show();
|
||||
};
|
||||
result.__take = function(){
|
||||
this.remove();
|
||||
};
|
||||
|
||||
if(!input) {
|
||||
return result;
|
||||
}
|
||||
$.each( input, function( key, value ){
|
||||
var type = typeof value;
|
||||
if( type === 'object' ){
|
||||
result.push( value );
|
||||
}else if( type === 'string' ){
|
||||
Object.defineProperty( result, "__index", {
|
||||
value: value,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
} );
|
||||
} else if ( type === 'function'){
|
||||
Object.defineProperty( result, value.name, {
|
||||
value: value,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
var $this = $( element );
|
||||
var repeatId = $this.attr( 'jq-repeat' );
|
||||
var tempId = repeatId + 'Template';
|
||||
var templateId = $( '#' + tempId ).html();
|
||||
|
||||
$this.removeAttr( 'jq-repeat' );
|
||||
var template = element.outerHTML
|
||||
|
||||
$this.replaceWith( '<script type="x-tmpl-mustache" id="' + tempId + '" class="jq-repeat-' + repeatId + ' " jq-repeat-index="holder"><\/script>' );
|
||||
|
||||
Mustache.parse(templateId); // optional, speeds up future uses
|
||||
|
||||
|
||||
$.scope[repeatId] = makeArray($.scope[repeatId]);
|
||||
$.scope[repeatId].__rq_template = template
|
||||
};
|
||||
|
||||
$( document ).ready( function(){
|
||||
$( '[jq-repeat]' ).each(function(key, value){
|
||||
make(value);
|
||||
});
|
||||
|
||||
$(document).on('DOMNodeInserted', function(e) {
|
||||
if ( $(e.target).is('[jq-repeat]') ){
|
||||
make( e.target );
|
||||
}else{
|
||||
var t = $(e.target).find('[jq-repeat]');
|
||||
t.each(function(key, value){
|
||||
make(value);
|
||||
});
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
})(jQuery, Mustache);
|
395
public/partial/header.html
Normal file
395
public/partial/header.html
Normal file
@ -0,0 +1,395 @@
|
||||
<link rel="stylesheet" href="/__static-modules/jquery-ui/dist/themes/smoothness/jquery-ui.css">
|
||||
|
||||
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
|
||||
<script src='/__static-modules/mustache/mustache.min.js'></script>
|
||||
<script src="/__static/lib/js/jq-repeat.js"></script>
|
||||
<script src="/__static-modules/moment/min/moment-with-locales.min.js"></script>
|
||||
<script src="/__static-modules/jquery-ui/dist/jquery-ui.min.js"></script>
|
||||
<script src="/__static/js/app.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.ui-dialog .ui-dialog-title{
|
||||
width: unset;
|
||||
}
|
||||
|
||||
#tbp_proxy_header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
z-index: 95;
|
||||
background: lightblue;
|
||||
height: 3em;
|
||||
text-align: initial;
|
||||
padding-top: .5em;
|
||||
padding-right: 1em;
|
||||
}
|
||||
|
||||
#tbp_proxy_header_right{
|
||||
margin-right: 2em;
|
||||
float: right;
|
||||
|
||||
display: flex;
|
||||
align-items:center;
|
||||
}
|
||||
|
||||
#tbp_proxy_torrent_dialog_opener{
|
||||
border-radius: 25px;
|
||||
background: lightseagreen;
|
||||
display: flex;
|
||||
align-items:center;
|
||||
|
||||
padding: 1em;
|
||||
padding-top: .3em;
|
||||
padding-bottom: .3em;
|
||||
|
||||
margin-right: .5em;
|
||||
}
|
||||
|
||||
#header {
|
||||
padding-top: 3.5em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!--
|
||||
Dialog boxes to be displayed
|
||||
-->
|
||||
|
||||
<div id="tbp_proxy_login_dialog" title="SSO Login">
|
||||
<div class="shadow-lg card">
|
||||
<div class="card-header shadow actionMessage" style="display:none"></div>
|
||||
<div class="card-body">
|
||||
<form action="auth/login" onsubmit="formAJAX(this)" evalAJAX="
|
||||
app.auth.setToken(data.token);
|
||||
app.auth.logInRedirect();
|
||||
">
|
||||
<input type="hidden" name="redirect" value="<%= redirect %>">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label">User name</label>
|
||||
<div class="input-group mb-3 shadow">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" ><i class="fa-solid fa-user-tie"></i></span>
|
||||
</div>
|
||||
<input type="text" name="uid" class="form-control" placeholder="jsmith" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label">Password</label>
|
||||
<div class="input-group mb-3 shadow">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" ><i class="fa-solid fa-key"></i></span>
|
||||
</div>
|
||||
<input type="password" name="password" class="form-control" placeholder="hunter123!"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-outline-dark"><i class="fa-solid fa-right-to-bracket"></i> Log in</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--
|
||||
Torrent List Dialog
|
||||
-->
|
||||
|
||||
<style type="text/css">
|
||||
#tbp_proxy_torrent_dialog{
|
||||
padding: 0;
|
||||
}
|
||||
#tbp_proxy_torrent_dialog progress{
|
||||
width: 100%;
|
||||
height: 2em;
|
||||
}
|
||||
#tbp_proxy_torrent_dialog ul{
|
||||
max-height: 400px;
|
||||
overflow-y: scroll;
|
||||
list-style-type: none;
|
||||
padding-left: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div id="tbp_proxy_torrent_dialog" title="Torrents">
|
||||
<ul>
|
||||
<li jq-repeat="tbp_proxy_torrent_dialog_torrents">{{name}}
|
||||
<br />
|
||||
{{^isFinished}}
|
||||
<progress id="file" max="100" value="{{percentDone}}">{{percentDone}}%</progress>
|
||||
<br />
|
||||
Status: <b>{{statusText}}</b> ETA: <b>{{eta}}</b> Rate: <b>{{rateDownload}}</b>
|
||||
{{/isFinished}}
|
||||
{{#isFinished}}
|
||||
<br /> Done! <a href="https://stuff.718it.biz/torrents/{{name}}" target="_blank"> HTTP Link</a>
|
||||
{{/isFinished}}
|
||||
<hr />
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<!--
|
||||
Torrent Add Dialog
|
||||
-->
|
||||
<style type="text/css">
|
||||
#tbp_proxy_torrent_add_dialog_container{
|
||||
width: 32em;
|
||||
}
|
||||
|
||||
#tbp_proxy_torrent_add_dialog input[type="text"]{
|
||||
width: 90%;
|
||||
}
|
||||
#tbp_proxy_torrent_add_dialog label,legend{
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div id="tbp_proxy_torrent_add_dialog" title="Add torrent">
|
||||
<div id="tbp_proxy_torrent_add_dialog_container" class='card'>
|
||||
<div class="card-header shadow actionMessage" style="display:none"></div>
|
||||
<div jq-repeat="torrentAdd">
|
||||
<form action="torrent" method="post" onsubmit="formAJAX(this)" evalAJAX="
|
||||
app.publish('torrent:add', {...data, __noSocket: true});
|
||||
$('#tbp_proxy_torrent_add_dialog').dialog('close');
|
||||
openDialog($('#tbp_proxy_torrent_dialog'))
|
||||
">
|
||||
<p>
|
||||
<label for="_name">Name:</label>
|
||||
<br />
|
||||
<input type="text" name="_name" value="{{{name}}}" readonly/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="magnetLink">Magnet Link:</label>
|
||||
<br />
|
||||
<input type="text" name="magnetLink" value="{{{magnetLink}}}" readonly/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<legend>Public Download:</legend>
|
||||
|
||||
<label for="radio-1" title="The download will appare in the communal download folder">Public</label>
|
||||
<input type="radio" name="isPrivate" id="radio-1" value="true" checked readonly/>
|
||||
|
||||
<label for="radio-2" title="Only you(and the admins) will be able to see this download">Private</label>
|
||||
<input type="radio" name="isPrivate" id="radio-2" value="false" readonly/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<legend>Start on add:</legend>
|
||||
|
||||
<label for="isStart-1" title="The download will appare in the communal download folder">Yes</label>
|
||||
<input type="radio" name="isStart" id="isStart-1" value="true" checked readonly/>
|
||||
|
||||
<label for="isStart-2" title="Only you(and the admins) will be able to see this download">No</label>
|
||||
<input type="radio" name="isStart" id="isStart-2" value="false" readonly/>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<button type="submit">Start Download</button>
|
||||
<button onclick="$('#tbp_proxy_torrent_add_dialog').dialog('close')">Cancel</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--
|
||||
The bar injected at the top of the page
|
||||
-->
|
||||
|
||||
<div id="tbp_proxy_header_right">
|
||||
<span id="tbp_proxy_torrent_dialog_opener" class="tbp_proxy_is_authed">
|
||||
<img src="/__static/img/Transmission_Icon.svg" height="22" width="22" style="margin-right: .3em;" />
|
||||
<span><b>106</b></span>
|
||||
</span>
|
||||
<button id="tbp_proxy_login_dialog_opener" class="tbp_proxy_not_authed ui-button ui-corner-all ui-widget">Login</button>
|
||||
<button class="tbp_proxy_is_authed ui-button ui-corner-all ui-widget"
|
||||
onclick="app.auth.logOut(e => window.location.href='/')">Logout</button>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$( document ).ready(function() {
|
||||
var commonDialogOptions = {
|
||||
position: { my: "left top", at: "left bottom", of: '#tbp_proxy_header_right' },
|
||||
autoOpen: false,
|
||||
resizable: false,
|
||||
closeOnEscape: true,
|
||||
draggable: false,
|
||||
width: 'auto',
|
||||
};
|
||||
|
||||
/* Login Button and dialog*/
|
||||
$( "#tbp_proxy_login_dialog" ).dialog(commonDialogOptions);
|
||||
|
||||
$( "#tbp_proxy_login_dialog_opener" ).on( "click", function() {
|
||||
// https://stackoverflow.com/a/6500385
|
||||
$( "#tbp_proxy_login_dialog" ).parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog( "open" );
|
||||
});
|
||||
|
||||
|
||||
/* Torrent list button and dialog */
|
||||
$( "#tbp_proxy_torrent_dialog" ).dialog(commonDialogOptions);
|
||||
|
||||
$( "#tbp_proxy_torrent_dialog_opener" ).on( "click", function() {
|
||||
$( "#tbp_proxy_torrent_dialog" ).parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog( "open" );
|
||||
});
|
||||
|
||||
|
||||
/* Torrent add button and dialog */
|
||||
$( "#tbp_proxy_torrent_add_dialog" ).dialog({
|
||||
modal: true,
|
||||
height: 300,
|
||||
...commonDialogOptions
|
||||
});
|
||||
|
||||
$("body").on('click', 'img.718link', function(el){
|
||||
// magnetLink
|
||||
$.scope.torrentAdd.update({
|
||||
magnetLink: $(this).data('link'),
|
||||
name: (new URLSearchParams($(this).data('link'))).get('dn')
|
||||
});
|
||||
$('#tbp_proxy_torrent_add_dialog').parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog('open');
|
||||
});
|
||||
|
||||
$('a').each(function(idx, el){
|
||||
var $el = $(el);
|
||||
if($el.attr('href') && $el.attr('href').match("magnet:?")){
|
||||
$el.before('<img class="tbp_proxy_is_authed 718link" src="/__static/img/Transmission_Icon.svg" height=24 width=24 data-link="'+$el.attr('href')+'"/>')
|
||||
}
|
||||
});
|
||||
|
||||
/* Enable tooltips*/
|
||||
$( '#tbp_proxy_header' ).tooltip({
|
||||
track: true
|
||||
});
|
||||
|
||||
app.subscribe('torrent:add', function(data, topic){
|
||||
console.log('sub', topic, data)
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(data))
|
||||
});
|
||||
|
||||
listTorrents();
|
||||
setInterval(refreshTorrents, 2000)
|
||||
});
|
||||
|
||||
function openDialog($el){
|
||||
$el.parent().css({
|
||||
position:"fixed", 'margin-right': "2em", 'margin-top': '3em'
|
||||
}).end().dialog('open');
|
||||
}
|
||||
|
||||
function listTorrents(){
|
||||
app.torrent.list(function(err, data){
|
||||
for(let torrent of data.results){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(torrent))
|
||||
app.torrent.get(function(error, torrent){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.update('id', torrent.result.id, app.torrent.parseTorrnetItem(torrent.result))
|
||||
} , torrent.id, true)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function refreshTorrents(){
|
||||
for(let torrent of $.scope.tbp_proxy_torrent_dialog_torrents){
|
||||
if(!torrent.isFinished){
|
||||
app.torrent.get(function(error, torrent){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.update('id', torrent.result.id, app.torrent.parseTorrnetItem(torrent.result))
|
||||
} , torrent.id, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.torrent = (function(app){
|
||||
let myTorrents = [];
|
||||
|
||||
statusMap = [
|
||||
'Inactive',
|
||||
'CHECK_WAIT',
|
||||
'Verifying',
|
||||
'DOWNLOAD_WAIT',
|
||||
'Downloading',
|
||||
'SEED_WAIT',
|
||||
'Seeding',
|
||||
'ISOLATED',
|
||||
'Unknown',
|
||||
];
|
||||
|
||||
function list(callback, username) {
|
||||
app.api.get('torrent', callback);
|
||||
}
|
||||
|
||||
function get(callback, id, forceUpdate){
|
||||
app.api.get(`torrent/${id}?${forceUpdate ? 'latest': '' }`, callback);
|
||||
}
|
||||
|
||||
function parseTorrnetItem(torrent){
|
||||
return {
|
||||
...torrent,
|
||||
"eta": torrent.eta > 0 ? moment().seconds(torrent.eta).fromNow() : 'Unknown',
|
||||
"rateDownload": `${Math.floor(torrent.rateDownload/1024/1024)}mb/s`,
|
||||
"sizeWhenDone": `${Math.floor(torrent.sizeWhenDone/1024/1024)}mb/s`,
|
||||
"percentDone": torrent.percentDone*100,
|
||||
"statusText": statusMap[torrent.status || 8],
|
||||
// "createdAtString": moment(torrent.createdAt).fromNow().
|
||||
// "downloadDir": "/media/torrents",
|
||||
// "errorString": "",
|
||||
// "files": [],
|
||||
// "hashString": "4794a0915cada6c491eb5c910e1f4a0da727cac8",
|
||||
// "isFinished": false,
|
||||
// "isStalled": false,
|
||||
// "name": "reacher.s02e06.1080p.web.h264-successfulcrab[EZTVx.to].mkv",
|
||||
// "peers": [],
|
||||
// "peersConnected": 50,
|
||||
// "status": 4,
|
||||
// "id": 1,
|
||||
// "torrent_id": "454",
|
||||
// "magnetLink": "magnet:?xt=urn:btih:4794A0915CADA6C491EB5C910E1F4A0DA727CAC8&dn=Reacher+S02E06+1080p+WEB+H264-SuccessfulCrab&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2F47.ip-51-68-199.eu%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2920%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.cyberia.is%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.dler.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Ftracker.pirateparty.gr%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce",
|
||||
// "isPrivate": false,
|
||||
// "added_by": "wmantly",
|
||||
// "createdAt": "2024-01-05T21:18:30.607Z",
|
||||
// "updatedAt": "2024-01-05T21:32:54.493Z"
|
||||
}
|
||||
}
|
||||
|
||||
return {list, get, parseTorrnetItem};
|
||||
})(app);
|
||||
|
||||
</script>
|
||||
|
||||
<!-- {
|
||||
"result": {
|
||||
"downloadDir": "/media/torrents",
|
||||
"errorString": "",
|
||||
"eta": -2,
|
||||
"files": [],
|
||||
"hashString": "a7ff69e500f0b62c3dec1061b9998610385dc7b6",
|
||||
"isFinished": false,
|
||||
"isStalled": true,
|
||||
"name": "Aftershock.2012.LIMITED.720p.BluRay.x264-GECKOS+[PublicHD]",
|
||||
"peers": [],
|
||||
"peersConnected": 0,
|
||||
"percentDone": 0,
|
||||
"rateDownload": 0,
|
||||
"sizeWhenDone": 0,
|
||||
"status": 4,
|
||||
"dataValues": {
|
||||
"id": 1,
|
||||
"torrent_id": "451",
|
||||
"magnetLink": "magnet:?xt=urn:btih:DF0146FBD120793246BE3D29ADD11BC7D460BFBB&dn=Magnum+P+I+2018+S05E19+720p+HDTV+x264-SYNCOPY&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2F47.ip-51-68-199.eu%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2920%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.cyberia.is%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.dler.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Ftracker.pirateparty.gr%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce",
|
||||
"hashString": "a7ff69e500f0b62c3dec1061b9998610385dc7b6",
|
||||
"name": "Aftershock.2012.LIMITED.720p.BluRay.x264-GECKOS+[PublicHD]",
|
||||
"added_by": "wmantly",
|
||||
"status": 4,
|
||||
"percentDone": 0,
|
||||
"downloadDir": "/media/torrents",
|
||||
"errorString": "",
|
||||
"sizeWhenDone": 0,
|
||||
"createdAt": "2024-01-04T17:40:58.187Z",
|
||||
"updatedAt": "2024-01-05T19:30:37.676Z"
|
||||
},
|
||||
} -->
|
11
routes/api.js
Normal file
11
routes/api.js
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const router = require('express').Router();
|
||||
const middleware = require('>/middleware/auth');
|
||||
|
||||
router.use('/auth', require('./auth'));
|
||||
router.use('/token/auth', require('./authtoken'));
|
||||
router.use('/torrent', middleware.auth, require('./transmission'));
|
||||
router.use('/user', middleware.auth, require('./user'));
|
||||
|
||||
module.exports = router;
|
31
routes/auth.js
Normal file
31
routes/auth.js
Normal file
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const router = require('express').Router();
|
||||
const { Auth } = require('>/controller/auth');
|
||||
|
||||
router.post('/login', async function(req, res, next){
|
||||
try{
|
||||
let auth = await Auth.login(req.body);
|
||||
return res.json({
|
||||
login: true,
|
||||
token: auth.token.token,
|
||||
message:`${req.body.username} logged in!`,
|
||||
});
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.all('/logout', async function(req, res, next){
|
||||
try{
|
||||
if(req.user){
|
||||
await req.user.logout();
|
||||
}
|
||||
|
||||
res.json({message: 'Bye'})
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
67
routes/authtoken.js
Normal file
67
routes/authtoken.js
Normal file
@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
|
||||
const router = require('express').Router();
|
||||
const {AuthToken} = require('>/models');
|
||||
|
||||
|
||||
router.get('/', async function(req, res, next){
|
||||
try{
|
||||
return res.json(await AuthToken.findAll());
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function(req, res, next){
|
||||
try{
|
||||
return res.json(await AuthToken.create(req.body));
|
||||
}catch(error){
|
||||
console.error(error)
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/user/:username', async function(req, res, next){
|
||||
try{
|
||||
return res.json(await AuthToken.findAll({where:{
|
||||
username: req.params.username
|
||||
}}));
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/:token', async function(req, res, next){
|
||||
try{
|
||||
let token = await AuthToken.findByPk(req.params.token)
|
||||
token.dataValues.user = await token.getUser()
|
||||
|
||||
return res.json(token);
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/:token', async function(req, res, next){
|
||||
try{
|
||||
let token = await AuthToken.findByPk(req.params.token);
|
||||
await token.update(req.body);
|
||||
return res.json(token);
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/:token', async function(req, res, next){
|
||||
try{
|
||||
let token = await AuthToken.findByPk(req.params.token);
|
||||
await token.destroy();
|
||||
|
||||
return res.json({'deleted': true});
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
95
routes/proxy.js
Normal file
95
routes/proxy.js
Normal file
@ -0,0 +1,95 @@
|
||||
'use static';
|
||||
|
||||
const router = require('express').Router();
|
||||
const zlib = require('zlib');
|
||||
const fs = require('fs');
|
||||
const https = require('https');
|
||||
const http = require("http");
|
||||
const proxy = require('http-proxy-middleware');
|
||||
|
||||
const inject = fs.readFileSync('./inject.html', 'utf8');
|
||||
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);
|
||||
});
|
||||
|
||||
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'
|
||||
}
|
||||
|
||||
function generateRegexForDomain(domain) {
|
||||
// Escape special characters in the domain name
|
||||
const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
|
||||
// Construct a regular expression pattern to match the domain with optional http(s):// prefix
|
||||
const regexPattern = new RegExp(`(?:https?:\\/\\/)?${escapedDomain}`, 'ig');
|
||||
|
||||
return regexPattern;
|
||||
}
|
||||
|
||||
router.all("/*", proxy({
|
||||
target: proxyTarget.target,
|
||||
agent: proxyTarget.target.startsWith('https') ? https.globalAgent : http.globalAgent,
|
||||
secure: false,
|
||||
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){
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
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)
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
}));
|
||||
|
||||
module.exports = router;
|
42
routes/transmission.js
Normal file
42
routes/transmission.js
Normal file
@ -0,0 +1,42 @@
|
||||
'use static';
|
||||
|
||||
const router = require('express').Router();
|
||||
const {Torrent} = require('>/models');
|
||||
|
||||
router.get('/', async function(req, res, next){
|
||||
try{
|
||||
res.json({results: await Torrent.findAll({where:{added_by: req.user.username}})});
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/", async function(req, res, next){
|
||||
try{
|
||||
res.json(await Torrent.create({...req.body, added_by: req.user.username}))
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/server', async function(req, res, next){
|
||||
try{
|
||||
res.json(await Torrent.trClient.sessionStats())
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/:id", async function(req, res, next){
|
||||
try{
|
||||
let torrent = await Torrent.findByPk(req.params.id);
|
||||
if('latest' in req.query){
|
||||
torrent = await torrent.getTorrentData();
|
||||
}
|
||||
res.json({result: torrent});
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
35
routes/user.js
Normal file
35
routes/user.js
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const router = require('express').Router();
|
||||
const {User} = require('>/models');
|
||||
|
||||
router.get('/', async function(req, res, next){
|
||||
try{
|
||||
return res.json({
|
||||
results: await User[req.query.detail ? "listDetail" : "list"]()
|
||||
});
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/me', async function(req, res, next){
|
||||
try{
|
||||
|
||||
return res.json(await User.get({uid: req.user.uid}));
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/:uid', async function(req, res, next){
|
||||
try{
|
||||
return res.json({
|
||||
results: await User.get(req.params.uid),
|
||||
});
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
x
Reference in New Issue
Block a user