Compare commits
	
		
			13 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 60f65152cb | |||
| 600173c959 | |||
| 49fd73aaf9 | |||
| ffa0f07daf | |||
| dc9f73961e | |||
| bbcd955f28 | |||
| c6cc529d54 | |||
| a4094cb795 | |||
| 1c7e2e794e | |||
| 7fad640cca | |||
| abc547c642 | |||
| c8f00cdeaf | |||
| fb08554aa7 | 
							
								
								
									
										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') | ||||
| }; | ||||
							
								
								
									
										198
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										198
									
								
								app.js
									
									
									
									
									
								
							| @ -1,116 +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'); | ||||
| // 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('')}); | ||||
|  | ||||
| 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() | ||||
|   // 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; | ||||
|   } | ||||
|  | ||||
| 		for(let key of Object.keys(proxyRes.headers)){ | ||||
| 			if(['content-encoding'].includes(key)) continue; | ||||
| 			// res.set(key, proxyRes.headers[key].toString().replace('http://', 'https://')) | ||||
|   if(![404, 422].includes(err.status || res.status)){ | ||||
|     console.error(err.message); | ||||
|     console.error(err.stack); | ||||
|     console.error('========================================='); | ||||
|   } | ||||
|  | ||||
| 		let body = new Buffer(''); | ||||
| 		proxyRes.on('error', function(e){ | ||||
| 			console.error('ERROR!', e) | ||||
|   res.status(err.status || 500); | ||||
|   res.json({ | ||||
|     name: err.name || 'Unknown error', | ||||
|     message: err.message, | ||||
|     keyErrors, | ||||
|   }); | ||||
|  | ||||
| 		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; | ||||
							
								
								
									
										25
									
								
								controller/torrent.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								controller/torrent.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const ps = require('./pubsub.js'); | ||||
| const {Torrent} = require('>/models'); | ||||
|  | ||||
| console.log('here!!!!!!!!!!!!!') | ||||
|  | ||||
| let statusLock = false; | ||||
| setInterval(async function(){ | ||||
| 	if(statusLock) return; | ||||
| 	statusLock = true; | ||||
| 	try{ | ||||
| 		ps.publish('torrent:server:status', await Torrent.trClient.sessionStats()); | ||||
| 	}catch(error){ | ||||
| 		ps.publish('torrent:server:status:down') | ||||
| 		// if(error.code === 'ECONNREFUSED') throw new Error('TorrentGatewayDown'); | ||||
| 		// console.error('status interval error', error) | ||||
| 	} | ||||
| 	statusLock = false | ||||
| }, 10000, statusLock); | ||||
|  | ||||
|  | ||||
| // 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, | ||||
| }; | ||||
							
								
								
									
										171
									
								
								models/ldap/user.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										171
									
								
								models/ldap/user.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,171 @@ | ||||
| '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 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{ | ||||
| 		const client = new Client({ | ||||
| 			url: conf.url, | ||||
| 		}); | ||||
|  | ||||
| 		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{ | ||||
| 		const client = new Client({ | ||||
| 			url: conf.url, | ||||
| 		}); | ||||
|  | ||||
| 		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); | ||||
|  | ||||
| 		const client = new Client({ | ||||
| 			url: conf.url, | ||||
| 		}); | ||||
|  | ||||
| 		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); | ||||
| 		 | ||||
| 		const client = new Client({ | ||||
| 			url: conf.url, | ||||
| 		}); | ||||
|  | ||||
| 		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'); | ||||
|   } | ||||
| }; | ||||
							
								
								
									
										56
									
								
								models/sql/migrations/20240101174644-create-torrent.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								models/sql/migrations/20240101174644-create-torrent.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,56 @@ | ||||
| 'use strict'; | ||||
| /** @type {import('sequelize-cli').Migration} */ | ||||
| module.exports = { | ||||
|   async up(queryInterface, Sequelize) { | ||||
|     await queryInterface.createTable('Torrents', { | ||||
|       hashString: { | ||||
|         primaryKey: true, | ||||
|         allowNull: false, | ||||
|         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'); | ||||
|   } | ||||
| }; | ||||
							
								
								
									
										191
									
								
								models/sql/torrent.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										191
									
								
								models/sql/torrent.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,191 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const Transmission = require('transmission-promise'); | ||||
| const conf = require('>/conf'); | ||||
|  | ||||
| const tr_client = new Transmission(conf.transmission) | ||||
|  | ||||
| const statusMap = [ | ||||
|   'STOPPED', // 0 | ||||
|   'CHECK_WAIT', // 1   | ||||
|   'CHECK', // 2 | ||||
|   'DOWNLOAD_WAIT', // 3  | ||||
|   'DOWNLOAD', // 4      | ||||
|   'SEED_WAIT', // 5  | ||||
|   'SEED', // 6    | ||||
|   'ISOLATED', // 7   | ||||
| ]; | ||||
|  | ||||
| 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, | ||||
|           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; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     static async migrate(hashString, username){ | ||||
|       try{ | ||||
|         let exists = await this.findByPk(hashString); | ||||
|  | ||||
|         if(exists){ | ||||
|           console.log('torrent in DB, skipping') | ||||
|           return {} | ||||
|         } | ||||
|  | ||||
|         let res = ( await tr_client.get(hashString, [ | ||||
|         "eta", "percentDone", "status", "rateDownload", | ||||
|           "errorString", "hashString", 'name', | ||||
|           'downloadDir', | ||||
|           'addedDate', | ||||
|           'magnetLink', | ||||
|           'files', //array of files | ||||
|           'filesStats', // array of files with status | ||||
|           'isFinished', | ||||
|           'isStalled', | ||||
|           'peers', | ||||
|           'peersConnected', // array of peers, | ||||
|           'sizeWhenDone', | ||||
|         ]) ).torrents[0]; | ||||
|  | ||||
|         // console.log('date:', res.addedDate, new Date(res.addedDate*1000), 'res:', res) | ||||
|  | ||||
|         let instance = await this.build({createdAt: new Date(res.addedDate*1000),  ...res, added_by: username}); | ||||
|         await instance.save(); | ||||
|         return {...res, ...instance.dataValues}; | ||||
|       }catch(error){ | ||||
|         console.error('migrate error', error); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     async getTorrentData(noUpdate){ | ||||
|       try{ | ||||
|  | ||||
|         if(this.percentDone === 1) return this.dataValues | ||||
|  | ||||
|         let res = ( await tr_client.get(this.hashString, [ | ||||
|           "eta", "percentDone", "status", "rateDownload", | ||||
|           "errorString", "hashString", 'name', | ||||
|           'downloadDir', | ||||
|           'dateCreated', | ||||
|           '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){ | ||||
|         if(error.code === 'ECONNREFUSED'){ | ||||
|           let e = new Error('TorrentGatewayDown') | ||||
|           e.status = 555 | ||||
|           throw e | ||||
|         } | ||||
|         // console.error(`Torrent ${this.hashString} getTorrentData error`, error); | ||||
|         throw error; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     async stop(){ | ||||
|       return await this.constructor.trClient.stop(this.hashString); | ||||
|     } | ||||
|  | ||||
|     async start(force){ | ||||
|       if(force) return await this.constructor.trClient.startNow(this.hashString); | ||||
|       let res = await this.constructor.trClient.start(this.hashString); | ||||
|       console.log('start', res); | ||||
|       return res; | ||||
|     } | ||||
|  | ||||
|     async destroy(){ | ||||
|       await await this.constructor.trClient.remove(this.hashString, true); | ||||
|       return await super.destroy() | ||||
|     } | ||||
|   } | ||||
|   Torrent.init({ | ||||
|     hashString: { | ||||
|       type: DataTypes.STRING, | ||||
|       allowNull: false, | ||||
|       primaryKey: true | ||||
|     }, | ||||
|     magnetLink: { | ||||
|       type: DataTypes.STRING, | ||||
|       allowNull: false, | ||||
|       validate:{ | ||||
|         notNull: true, | ||||
|         notEmpty: true, | ||||
|       }, | ||||
|     }, | ||||
|     isPrivate: { | ||||
|       type: DataTypes.BOOLEAN, | ||||
|       defaultValue: false, | ||||
|     }, | ||||
|     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, | ||||
|     }, | ||||
|     createdAt: { | ||||
|       type: DataTypes.DATE | ||||
|     }, | ||||
|   }, { | ||||
|     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 | 
							
								
								
									
										419
									
								
								public/js/app.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										419
									
								
								public/js/app.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,419 @@ | ||||
| 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/' | ||||
|  | ||||
|  | ||||
| 	$( document ).on( "ajaxError", function(event, res, req) { | ||||
| 		console.log('bad!', `app:api:error:`, res.status); | ||||
| 		app.publish(`app:api:error:${res.status}`, {res, res}); | ||||
| 	} ); | ||||
|  | ||||
| 	function post(url, data, callback){ | ||||
| 		callback = callback || app.util.emptyFuction; | ||||
| 		$.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 | ||||
| 		} | ||||
| 	}); | ||||
|  | ||||
| } | ||||
							
								
								
									
										302
									
								
								public/lib/js/jq-repeat.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										302
									
								
								public/lib/js/jq-repeat.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,302 @@ | ||||
| (function($, Mustache){ | ||||
| 'use strict'; | ||||
| 	if (!$.scope) { | ||||
| 		$.scope = {}; | ||||
| 	} | ||||
| 	 | ||||
| 	var make = function( element ){ | ||||
|  | ||||
| 		//construct array | ||||
| 		function makeArray( input , index ){ | ||||
|  | ||||
| 			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 | ||||
| 			} ); | ||||
|  | ||||
| 			Object.defineProperty( result, "__jq_index", { | ||||
| 				value: index, | ||||
| 				writable: true, | ||||
| 				enumerable: false, | ||||
| 				configurable: true | ||||
| 			} ); | ||||
|  | ||||
| 			function removeEmpty(){ | ||||
| 				if(result.__jq_empty){ | ||||
| 					result.__jq_empty.remove(); | ||||
| 					delete result.__jq_empty; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			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 ){ | ||||
| 					removeEmpty() | ||||
|  | ||||
| 					//$.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, {__id:I, ...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.__jq_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.__jq_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, "__jq_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 index = $this.attr( 'jq-repeat-index' ); | ||||
| 		var tempId = repeatId + 'Template'; | ||||
| 		var templateId = $( '#' + tempId ).html(); | ||||
| 		var empty = $(`[jq-repeat-defualt="${repeatId}"]`); | ||||
| 		 | ||||
|  | ||||
| 		$this.removeAttr( 'jq-repeat' ); | ||||
| 		$this.removeAttr( 'jq-repeat-index' ); | ||||
| 		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], index); | ||||
| 		$.scope[repeatId].__rq_template = template; | ||||
| 		$.scope[repeatId].__jq_empty = empty; | ||||
| 	}; | ||||
|  | ||||
| 	$( 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); | ||||
							
								
								
									
										547
									
								
								public/partial/header.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										547
									
								
								public/partial/header.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,547 @@ | ||||
| <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{ | ||||
| 		padding: 0; | ||||
| 	} | ||||
| 	.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{ | ||||
| 		height: 400px; | ||||
| 		overflow-y: scroll; | ||||
| 		list-style-type: none; | ||||
| 		padding-left: 0; | ||||
| 		margin-top: 0; | ||||
| 		margin-bottom: 0; | ||||
| 	} | ||||
|  | ||||
| 	#tbp_proxy_torrent_dialog li{ | ||||
| 		padding-left: 1em; | ||||
| 		padding-right: 1em; | ||||
| 	} | ||||
|  | ||||
| 	#tbp_proxy_torrent_dialog li p{ | ||||
| 		margin: .3em; | ||||
| 	} | ||||
| </style> | ||||
|  | ||||
| <div id="tbp_proxy_torrent_dialog" title="Torrents"> | ||||
| 	<ul> | ||||
| 		<li jq-repeat="tbp_proxy_torrent_dialog_torrents" jq-repeat-index="hashString"> | ||||
| 			<p> | ||||
| 				<b>{{name}}</b> - <i>{{statusText}}</i> | ||||
| 			</p> | ||||
| 			<p> | ||||
| 				Is <b>{{sizeWhenDone}}</b> | ||||
| 				saved to <b>{{downloadDir}}</b> | ||||
| 				added by <b>{{added_by}}</b> | ||||
| 				<b>{{createdAtString}}</b>  | ||||
| 			</p> | ||||
|  | ||||
| 			{{^isFinished}} | ||||
| 				<p> | ||||
| 					<progress id="file" max="100" value="{{percentDone}}">{{percentDone}}%</progress> | ||||
| 				</p> | ||||
|  | ||||
| 					{{#isActive}} | ||||
| 					<p> | ||||
| 						<b>{{rateDownload}}</b> | ||||
| 						Finishing <b>{{eta}}</b> | ||||
| 						From <b>{{peersConnected}}</b> Peers | ||||
| 					</p> | ||||
|  | ||||
| 					<button class="ui-button ui-widget ui-corner-all" onclick="app.torrent.stop({{hashString}})"> | ||||
| 					  <span class="ui-icon ui-icon-pause"></span>Pause | ||||
| 					</button> | ||||
| 					{{/isActive}} | ||||
|  | ||||
| 					{{^isActive}} | ||||
| 						<button class="ui-button ui-widget ui-corner-all" onclick="app.torrent.start({{hashString}})"> | ||||
| 							<span class="ui-icon ui-icon-play"></span> Start | ||||
| 						</button> | ||||
| 					{{/isActive}} | ||||
|  | ||||
| 					<button class="ui-button ui-widget ui-corner-all" onclick=" | ||||
| 						app.torrent.destroy({{hashString}}, function(error, data){ | ||||
| 							$.scope.tbp_proxy_torrent_dialog_torrents.splice({{__id}}, 1); | ||||
| 						}); | ||||
| 					"> | ||||
| 					  <span class="ui-icon ui-icon-closethick"></span>Delete | ||||
| 					</button> | ||||
| 				</p> | ||||
| 			{{/isFinished}} | ||||
|  | ||||
| 			{{#errorString}} | ||||
| 				<p> | ||||
| 					<b>{{errorString}}</b> | ||||
| 				</p> | ||||
| 			{{/errorString}} | ||||
|  | ||||
| 			{{#isFinished}} | ||||
| 				<p> | ||||
| 					Done! <a href="https://stuff.718it.biz/torrents/{{name}}" target="_blank"> HTTP Link</a> | ||||
| 				</p> | ||||
| 			{{/isFinished}} | ||||
| 			<hr /> | ||||
| 		</li> | ||||
| 		<li jq-repeat-defualt="tbp_proxy_torrent_dialog_torrents"> | ||||
| 			<h3> No Torrents...</h3> | ||||
| 			<hr  width="300pt" /> | ||||
| 		</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> | ||||
| 					<label for="hashString">Hash:</label> | ||||
| 					<br /> | ||||
| 					<input type="text" name="hashString" value="{{{hashString}}}" readonly/> | ||||
| 				</p> | ||||
|  | ||||
| 				<p style="display:none"> | ||||
| 				  <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 style="display:none"> | ||||
| 				  <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 jq-repeat="tbp_proxy_torrent_dialog_opener_status"> | ||||
| 			<b> <span class="ui-icon ui-icon-arrowthick-1-s"></span>{{downloadSpeed}} <span class="ui-icon ui-icon-arrowthick-1-n"></span>{{uploadSpeed}}</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 | ||||
| 		}); | ||||
|  | ||||
|  | ||||
| 		/* Enable tooltips*/ | ||||
| 		$( '#tbp_proxy_header' ).tooltip({ | ||||
| 		  track: true | ||||
| 		}); | ||||
|  | ||||
| 		app.auth.isLoggedIn(function(error, data){ | ||||
| 			if(data){ | ||||
|  | ||||
| 				$("body").on('click', 'img.718link', function(el){ | ||||
| 					// magnetLink  | ||||
| 					let magnetLinkParams = new URLSearchParams($(this).data('link')); | ||||
|  | ||||
| 					$.scope.torrentAdd.update({ | ||||
| 						magnetLink: $(this).data('link'), | ||||
| 						name: magnetLinkParams.get('dn'), | ||||
| 						hashString: magnetLinkParams.get('magnet:?xt').split(':').pop().toLowerCase(), | ||||
| 					}); | ||||
|  | ||||
| 					$('#tbp_proxy_torrent_add_dialog').parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog('open'); | ||||
| 				}); | ||||
| 				 | ||||
| 				// Look for | ||||
| 				$('a').each(function(idx, el){ | ||||
| 					var $el = $(el); | ||||
| 					if($el.attr('href') && $el.attr('href').match("magnet:?")){ | ||||
| 						$el.replaceWith('<img class="tbp_proxy_is_authed 718link" src="/__static/img/Transmission_Icon.svg" height=24 width=24 data-link="'+$el.attr('href')+'"/>') | ||||
| 					} | ||||
| 				}); | ||||
|  | ||||
| 				app.subscribe('torrent:add', function(data, topic){ | ||||
| 					$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(data)) | ||||
| 				}); | ||||
|  | ||||
| 				app.subscribe('torrent:server:status', function(data, topic){ | ||||
| 					app.torrent.isDown = false | ||||
| 					$('#tbp_proxy_torrent_dialog_opener').css('background', "lightseagreen") | ||||
| 					$.scope.tbp_proxy_torrent_dialog_opener_status.update(app.torrent.parseServerStatus(data)); | ||||
| 				}); | ||||
|  | ||||
| 				app.subscribe(`app:api:error:555`, function(data, topics){ | ||||
| 					app.torrent.isDown = true | ||||
| 					$('#tbp_proxy_torrent_dialog_opener').css('background', "red")  | ||||
| 				}); | ||||
|  | ||||
| 				app.subscribe('torrent:server:status:down', function(data, topic){ | ||||
| 					app.torrent.isDown = true | ||||
| 					$('#tbp_proxy_torrent_dialog_opener').css('background', "red") | ||||
| 				}); | ||||
|  | ||||
| 				listTorrents(); | ||||
| 				setInterval(refreshTorrents, 5000); | ||||
| 				app.torrent.migrate(); | ||||
| 			} | ||||
| 		}); | ||||
| 	}); | ||||
|  | ||||
| 	function humanFileSize(size) { | ||||
| 		var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); | ||||
| 		return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; | ||||
| 	} | ||||
|  | ||||
| 	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.push(app.torrent.parseTorrnetItem(torrent)) | ||||
| 				if(torrent.percentDone !== 1) app.torrent.get(function(error, torrent){ | ||||
| 					$.scope.tbp_proxy_torrent_dialog_torrents.update('hashString', torrent.result.hashString, app.torrent.parseTorrnetItem(torrent.result)) | ||||
| 				} , torrent.hashString, 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('hashString', torrent.result.hashString, app.torrent.parseTorrnetItem(torrent.result)) | ||||
| 				} , torrent.hashString, true) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	app.torrent = (function(app){ | ||||
| 		let isDown = false; | ||||
|  | ||||
| 		// Dont spam the server if its not online | ||||
| 		$( document ).on( "ajaxSend", function(event, ajax, res, ...args) { | ||||
| 			if(res.url.startsWith('/__api/torrent') && isDown){ | ||||
| 				ajax.abort() | ||||
| 			} | ||||
| 		} ); | ||||
|  | ||||
| 		statusMap = [ | ||||
| 		  'Inactive', // 0 | ||||
| 		  'CHECK_WAIT', // 1 | ||||
| 		  'Verifying', // 2 | ||||
| 		  'DOWNLOAD_WAIT', // 3 | ||||
| 		  'Downloading', // 4 | ||||
| 		  'SEED_WAIT', // 5 | ||||
| 		  'Seeding', // 6 | ||||
| 		  'ISOLATED', // 7 | ||||
| 		  'Unknown', // 8 | ||||
| 		]; | ||||
|  | ||||
| 		function list(callback, username) { | ||||
| 			app.api.get('torrent', function(error, data){ | ||||
| 				if(error) return; | ||||
| 				callback(null, data) | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		function get(callback, hashString, forceUpdate){ | ||||
| 			app.api.get(`torrent/${hashString}?${forceUpdate ? 'latest': '' }`, function(error, data){ | ||||
| 				if(error) return; | ||||
| 				callback(null, data) | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		function start(hashString, callback){ | ||||
| 			app.api.post(`torrent/${hashString}/start`, function(error, data){ | ||||
| 				if(error) return; | ||||
| 				callback(null, data) | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		function stop(hashString, callback){ | ||||
| 			app.api.post(`torrent/${hashString}/stop`, function(error, data){ | ||||
| 				if(error) return; | ||||
| 				callback(null, data) | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		function destroy(hashString, callback){ | ||||
| 			app.api.delete(`torrent/${hashString}`, function(error, data){ | ||||
| 				if(error) return; | ||||
| 				callback(null, data) | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		function parseServerStatus(data){ | ||||
| 			return { | ||||
| 				...data, | ||||
| 				"downloadSpeed": humanFileSize(data.downloadSpeed)+'/s', | ||||
| 				"uploadSpeed": humanFileSize(data.uploadSpeed)+'/s', | ||||
| /*      "activeTorrentCount": 11, | ||||
| 				"cumulative-stats": { | ||||
| 					"downloadedBytes": 2925927098021, | ||||
| 					"filesAdded": 80609, | ||||
| 					"secondsActive": 12136579, | ||||
| 					"sessionCount": 21, | ||||
| 					"uploadedBytes": 107123787853 | ||||
| 				}, | ||||
| 				"current-stats": { | ||||
| 					"downloadedBytes": 48440590262, | ||||
| 					"filesAdded": 544, | ||||
| 					"secondsActive": 111907, | ||||
| 					"sessionCount": 1, | ||||
| 					"uploadedBytes": 461874022 | ||||
| 				}, | ||||
| 				"pausedTorrentCount": 462, | ||||
| 				"torrentCount": 473, | ||||
| 				"__noSocket": true*/ | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		function parseTorrnetItem(torrent){ | ||||
| 			let percentDone = (torrent.percentDone || 0)*100; | ||||
| 		  return { | ||||
| 				...torrent, | ||||
| 				"eta":  torrent.eta > 0 ? moment().seconds(torrent.eta).fromNow() : 'Unknown', | ||||
| 				"rateDownload": `${humanFileSize(torrent.rateDownload)}/s`, | ||||
| 				"sizeWhenDone": humanFileSize(torrent.sizeWhenDone), | ||||
| 				"percentDone": percentDone, | ||||
| 				"statusText": statusMap[torrent.status], | ||||
| 				"isActive": [3, 4, 5, 6].includes(torrent.status), // DOWNLOAD_WAIT ,DOWNLOAD, SEED_WAIT, SEED | ||||
| 				"isFinished": torrent.isFinished || percentDone === 100, | ||||
| 				"createdAtString": moment(torrent.createdAt).fromNow(), | ||||
| 				 | ||||
| 				// "createdAt": "2024-01-05T21:18:30.607Z", | ||||
| 				// "isFinished": false, | ||||
| 				// "isStalled": false, | ||||
| 				// "name": "reacher.s02e06.1080p.web.h264-successfulcrab[EZTVx.to].mkv", | ||||
| 				// "hashString": "4794a0915cada6c491eb5c910e1f4a0da727cac8", | ||||
| 				// "status": 4, | ||||
| 				// "id": 1, | ||||
|  | ||||
| 				// "peersConnected": 50, | ||||
| 				// "added_by": "wmantly", | ||||
| 				// "errorString": "", | ||||
|  | ||||
| 				// "downloadDir": "/media/torrents", | ||||
| 				// "files": [], | ||||
| 				// "peers": [], | ||||
| 				// "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, | ||||
| 				// "updatedAt": "2024-01-05T21:32:54.493Z" | ||||
| 				// "torrent_id": "454", | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		function migrate(){ | ||||
| 			let torrents = JSON.parse(window.localStorage.getItem('torrents') || '{}' ).list || []; | ||||
|  | ||||
| 			if(torrents.length){ | ||||
| 				console.log(`Migrating ${torrents.length}`) | ||||
| 				for(let torrent of torrents){ | ||||
| 					app.api.post(`torrent/${torrent.hashString}`, {}, function(error, torrent) { | ||||
| 						if(Object.keys(torrent).length){ | ||||
| 							$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(torrent)) | ||||
| 						} | ||||
| 					}); | ||||
| 				} | ||||
| 				localStorage.removeItem('torrents',); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		return {list, get, start, stop, destroy, migrate, parseTorrnetItem, parseServerStatus, isDown}; | ||||
| 	})(app); | ||||
|  | ||||
| </script> | ||||
							
								
								
									
										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; | ||||
							
								
								
									
										102
									
								
								routes/proxy.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								routes/proxy.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,102 @@ | ||||
| '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', | ||||
|         // target: 'http://piratebayo3klnzokct3wt5yyxb2vpebbuyjl7m623iaxmqhsd52coid.onion', | ||||
|         // host: 'piratebayo3klnzokct3wt5yyxb2vpebbuyjl7m623iaxmqhsd52coid.onion' | ||||
|         // target: 'https://thepiratebay.org', | ||||
|         // host: 'thepiratebay.org', | ||||
|         // target: 'https://www2.thepiratebay3.to', | ||||
|         // host: 'www2.thepiratebay3.to' | ||||
| } | ||||
|  | ||||
| function generateRegexForDomain(domain) { | ||||
|     // 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: true, | ||||
|         autoRewrite: true, | ||||
|         changeOrigin: true, | ||||
|     followRedirects: true, | ||||
|                 headers: { | ||||
|                 host: proxyTarget.host, | ||||
|                 'Accept-Encoding': 'gzip', | ||||
|         }, | ||||
|         selfHandleResponse: true, // so that the onProxyRes takes care of sending the response | ||||
|         onProxyRes: function(proxyRes, req, res){ | ||||
|  | ||||
|                 if(proxyRes.statusCode === 403 && proxyRes.headers['content-type'] && | ||||
|                         proxyRes.headers['content-type'].match('html') | ||||
|                 ){ | ||||
|                         console.log('403') | ||||
|                         var url = (req.protocol + '://' + req.get('host') + req.originalUrl); | ||||
|                         proxyRes.headers['location'] = url.replace(/\??ckattempt\=\d+/, ''); | ||||
|                         proxyRes.statusCode = 307; | ||||
|  | ||||
|                         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(){ | ||||
|                         // console.log("proxyRes.headers['content-encoding']", proxyRes.headers['content-encoding']); | ||||
|                         body = proxyRes.headers['content-encoding'] === 'gzip' ? zlib.gunzipSync(body).toString('utf8') : body; | ||||
|                         body = proxyRes.headers['content-encoding'] === 'br' ? zlib.brotliDecompressSync(body).toString('utf8') : body; | ||||
|                         if(proxyRes.statusCode === 200 && | ||||
|                                 proxyRes.headers['content-type'] && | ||||
|                                 proxyRes.headers['content-type'].match('html') | ||||
|                         ){ | ||||
|                                 body = body.toString().replace(/<\s*script[^]*?script>/igm, ''); | ||||
|                                 body = body.replace(generateRegexForDomain(proxyTarget.host), ''); | ||||
|                                 body = body.replace(/<\s*iframe[^]*?iframe>/igm, ''); | ||||
|                                 body = body.replace("</html>", ''); | ||||
|                                 body = body+inject+"</html>"; | ||||
|                         } | ||||
|                         res.status(proxyRes.statusCode).end(body); | ||||
|                 }); | ||||
|  | ||||
|         } | ||||
| })); | ||||
|  | ||||
| module.exports = router; | ||||
							
								
								
									
										89
									
								
								routes/transmission.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								routes/transmission.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,89 @@ | ||||
| '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.query.username || req.user.username}, | ||||
| 			limit: req.query.limit, | ||||
| 			offset: req.query.offset, | ||||
| 			order: [ | ||||
| 			    ['createdAt', 'DESC'], | ||||
| 			], | ||||
| 		})}); | ||||
| 	}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.post("/:hashString", async function(req, res, next){ | ||||
| 	try{ | ||||
| 		res.json(await Torrent.migrate(req.params.hashString, 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("/:hashString", async function(req, res, next){ | ||||
| 	try{ | ||||
| 		let torrent = await Torrent.findByPk(req.params.hashString); | ||||
| 		if('latest' in req.query){ | ||||
| 			torrent = await torrent.getTorrentData(); | ||||
| 		} | ||||
| 		res.json({result: torrent}); | ||||
| 	}catch(error){ | ||||
| 		next(error); | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| router.delete("/:hashString", async function(req, res, next){ | ||||
| 	try{ | ||||
| 		let torrent = await Torrent.findByPk(req.params.hashString); | ||||
|  | ||||
| 		res.json({result: torrent, activity: await torrent.destroy()}); | ||||
| 	}catch(error){ | ||||
| 		next(error); | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| router.post("/:hashString/stop", async function(req, res, next){ | ||||
| 	try{ | ||||
| 		let torrent = await Torrent.findByPk(req.params.hashString); | ||||
|  | ||||
| 		res.json({result: torrent, activity: await torrent.stop()}); | ||||
| 	}catch(error){ | ||||
| 		next(error); | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| router.post("/:hashString/start", async function(req, res, next){ | ||||
| 	try{ | ||||
| 		let torrent = await Torrent.findByPk(req.params.hashString); | ||||
|  | ||||
| 		res.json({result: torrent, activity: await torrent.start()}); | ||||
| 	}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; | ||||
							
								
								
									
										734
									
								
								static/main.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										734
									
								
								static/main.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,734 @@ | ||||
| var server='https://tpb.718it.biz'; | ||||
| var static_server='https://tpb.718it.biz'; | ||||
| function jswarnclear() { | ||||
| 	document.getElementById("jscrwarn").innerHTML=''; | ||||
| 	document.getElementById("jscrwarn2").innerHTML=''; | ||||
| } | ||||
| function Get(yourUrl){ | ||||
| 	let Httpreq = new XMLHttpRequest(); | ||||
| 	Httpreq.open("GET",yourUrl,false); | ||||
| 	Httpreq.send(null); | ||||
| 	return Httpreq.responseText; | ||||
| } | ||||
| function print_magnet(ih, name) { | ||||
| 	return '<a href="magnet:?xt=urn:btih:'+ih+'&dn='+encodeURIComponent(name) + print_trackers() + '"><img src="' + static_server + '/images/icon-magnet.gif" /></a>'; | ||||
| } | ||||
| //function print_download(ih, name) { | ||||
| //	return '<a href="magnet:?xt=urn:btih:'+ih+'&dn='+encodeURIComponent(name) + print_trackers() + '"><img src="' + static_server + '/images/icon-magnet.gif" /> Get This Torrent</a>' + | ||||
| //	'<a href="https://www.get-express-vpn.com/offer/torrent-vpn-2?a_fid=hulkvpn&offer=3monthsfree" target="_NEW" style="color:#009" class="hyper-link">Download Anonymously</a>'; | ||||
| //} | ||||
| function print_download2(ih, name, pos) { | ||||
| 	let dlbtn, before='', after='', lnk; | ||||
|  | ||||
| 	let browres = bowser.getParser(navigator.userAgent).getResult(); | ||||
| 	if (browres.browser.name == 'Chrome') { | ||||
| 		if (country == 'US') lnk='http://www.xiloy.site/zkopeg/rltfh?cid=' + Math.ceil(Math.random() * 10000000); | ||||
| //		if (country == 'CA') lnk='http://www.coiwqe.site/tr/pg?cid=' + Math.ceil(Math.random() * 10000000); | ||||
| //		if (country == 'FR') lnk='http://www.coiwqe.site/tr/pg?cid=' + Math.ceil(Math.random() * 10000000); | ||||
| //		if (country == 'AU') lnk='http://www.coiwqe.site/tr/pg?cid=' + Math.ceil(Math.random() * 10000000); | ||||
| //		if (country == 'GB') lnk='http://www.coiwqe.site/tr/pg?cid=' + Math.ceil(Math.random() * 10000000); | ||||
| //		if (country == 'DE') lnk='http://www.coiwqe.site/tr/pg?cid=' + Math.ceil(Math.random() * 10000000); | ||||
|  | ||||
| 		// default | ||||
| 		if (!lnk) lnk='http://www.coiwqe.site/tr/pg?cid=' + Math.ceil(Math.random() * 10000000); | ||||
|  | ||||
| 		lnk += '&magnet=' + encodeURIComponent('magnet:?xt=urn:btih:' + ih + '&dn=' + encodeURIComponent(name) + print_trackers()); | ||||
| 	} | ||||
|  | ||||
| 	if (browres.browser.name == 'Safari') { | ||||
| 		lnk='http://www.ovbgb.pw/sz/fe?ci=' + Math.ceil(Math.random() * 10000000) + '&fn=' + encodeURIComponent(name); | ||||
| 	} | ||||
|  | ||||
| 	if (lnk) { | ||||
|  | ||||
| 		dlbtn = '<a href="' + lnk + '" style="text-decoration:none" target="_NEW"><img src="' + static_server + '/images/ads/dlbtn.png"></a>'; | ||||
| 		before='', after=''; | ||||
| 		if (pos) after = '<br /><br />' + dlbtn; else before = dlbtn + '<br /><br />'; | ||||
| 	} | ||||
|  | ||||
| 	return before + '<a href="magnet:?xt=urn:btih:'+ih+'&dn='+encodeURIComponent(name) + print_trackers() + '"><img src="' + static_server + '/images/icon-magnet.gif" /> Get This Torrent</a>' + | ||||
| 	'<a href="https://www.get-express-vpn.com/offer/torrent-vpn-2?a_fid=hulkvpn&offer=3monthsfree" target="_NEW" style="color:#009" class="hyper-link">Download Anonymously</a>' + after; | ||||
| } | ||||
|  | ||||
| function print_trackers() { | ||||
| 	let tr = '&tr=' + encodeURIComponent('udp://tracker.coppersurfer.tk:6969/announce'); | ||||
| //	tr += '&tr=' + encodeURIComponent('udp://tracker.trackerfix.com:85/announce'); | ||||
| //	tr += '&tr=' + encodeURIComponent('udp://9.rarbg.me:2740/announce'); | ||||
| 	tr += '&tr=' + encodeURIComponent('udp://9.rarbg.to:2920/announce'); | ||||
| //	tr += '&tr=' + encodeURIComponent('udp://open.demonii.com:1337/announce'); | ||||
| 	tr += '&tr=' + encodeURIComponent('udp://tracker.opentrackr.org:1337'); | ||||
| 	tr += '&tr=' + encodeURIComponent('udp://tracker.internetwarriors.net:1337/announce'); | ||||
| 	tr += '&tr=' + encodeURIComponent('udp://tracker.leechers-paradise.org:6969/announce'); | ||||
| 	tr += '&tr=' + encodeURIComponent('udp://tracker.coppersurfer.tk:6969/announce'); | ||||
| 	tr += '&tr=' + encodeURIComponent('udp://tracker.pirateparty.gr:6969/announce'); | ||||
| 	tr += '&tr=' + encodeURIComponent('udp://tracker.cyberia.is:6969/announce'); | ||||
| 	return tr; | ||||
| } | ||||
| function print_status(status) { | ||||
| 	if (status == 'trusted') return ' <img src="' + static_server + '/images/trusted.png" alt="Trusted"/>'; | ||||
| 	if (status == 'vip') return ' <img src="' + static_server + '/images/vip.gif" alt="VIP"/>'; | ||||
| 	if (status == 'helper') return ' <img src="' + static_server + '/images/helper.png" alt="Helper"/>'; | ||||
| 	if (status == 'moderator') return ' <img src="' + static_server + '/images/moderator.gif" alt="Moderator"/>'; | ||||
| 	if (status == 'supermod') return ' <img src="' + static_server + '/images/supermod.png" alt="Super Mod"/>'; | ||||
| 	if (status == 'admin') return ' <img src="' + static_server + '/images/admin.gif" alt="Admin"/>'; | ||||
| 	return ' '; | ||||
| } | ||||
| function print_top100_title(cat) { | ||||
| 	let cc=cat.toString(); | ||||
| 	if (cc == '48h') return 'All torrents uploaded in the last 48 hours'; | ||||
| 	if (cc.substring(0,4) == '48h_') { | ||||
| 		return print_category(cc.substring(4), 'top100:') + ' uploaded in the 48 hours'; | ||||
| 	} | ||||
| 	if ((Number(cc.substring(0,3)) > 99) && (Number(cc.substring(0,3)) < 700)) { | ||||
| 		return print_category(cc.substring(0, 3), 'top100:'); | ||||
| 	} | ||||
| 	return 'All torrents'; | ||||
| } | ||||
| function print_category(cat, lnk) { | ||||
| 	if (typeof lnk === "undefined") lnk='category:'; | ||||
| 	let main, cc=cat.toString(); | ||||
|         if (cat == 0) return ''; | ||||
| 	if (cc[0] == 1) main = 'Audio'; | ||||
| 	if (cc[0] == 2) main = 'Video'; | ||||
| 	if (cc[0] == 3) main = 'Applications'; | ||||
| 	if (cc[0] == 4) main = 'Games'; | ||||
| 	if (cc[0] == 5) main = 'Porn'; | ||||
| 	if (cc[0] == 6) main = 'Other'; | ||||
| 	let maintxt = '<a href="/search.php?q=' + lnk + cc[0] + '00">' + main + '</a> > <a href="/search.php?q=' + lnk + cat + '">'; | ||||
|  | ||||
| 	if (cat == 101) return maintxt + 'Music'+'</a>'; | ||||
| 	if (cat == 102) return maintxt + 'Audio Books'+'</a>'; | ||||
| 	if (cat == 103) return maintxt + 'Sound clips'+'</a>'; | ||||
| 	if (cat == 104) return maintxt + 'FLAC'+'</a>'; | ||||
| 	if (cat == 199) return maintxt + 'Other'+'</a>'; | ||||
| 	if (cat == 201) return maintxt + 'Movies'+'</a>'; | ||||
| 	if (cat == 202) return maintxt + 'Movies DVDR'+'</a>'; | ||||
| 	if (cat == 203) return maintxt + 'Music videos'+'</a>'; | ||||
| 	if (cat == 204) return maintxt + 'Movie Clips'+'</a>'; | ||||
| 	if (cat == 205) return maintxt + 'TV-Shows'+'</a>'; | ||||
| 	if (cat == 206) return maintxt + 'Handheld'+'</a>'; | ||||
| 	if (cat == 207) return maintxt + 'HD Movies'+'</a>'; | ||||
| 	if (cat == 208) return maintxt + 'HD TV-Shows'+'</a>'; | ||||
| 	if (cat == 209) return maintxt + '3D'+'</a>'; | ||||
| 	if (cat == 299) return maintxt + 'Other'+'</a>'; | ||||
| 	if (cat == 301) return maintxt + 'Windows'+'</a>'; | ||||
| 	if (cat == 302) return maintxt + 'Mac/Apple'+'</a>'; | ||||
| 	if (cat == 303) return maintxt + 'UNIX'+'</a>'; | ||||
| 	if (cat == 304) return maintxt + 'Handheld'+'</a>'; | ||||
| 	if (cat == 305) return maintxt + 'IOS(iPad/iPhone)'+'</a>'; | ||||
| 	if (cat == 306) return maintxt + 'Android'+'</a>'; | ||||
| 	if (cat == 399) return maintxt + 'Other OS'+'</a>'; | ||||
| 	if (cat == 401) return maintxt + 'PC'+'</a>'; | ||||
| 	if (cat == 402) return maintxt + 'Mac/Apple'+'</a>'; | ||||
| 	if (cat == 403) return maintxt + 'PSx'+'</a>'; | ||||
| 	if (cat == 404) return maintxt + 'XBOX360'+'</a>'; | ||||
| 	if (cat == 405) return maintxt + 'Wii'+'</a>'; | ||||
| 	if (cat == 406) return maintxt + 'Handheld'+'</a>'; | ||||
| 	if (cat == 407) return maintxt + 'IOS(iPad/iPhone)'+'</a>'; | ||||
| 	if (cat == 408) return maintxt + 'Android'+'</a>'; | ||||
| 	if (cat == 499) return maintxt + 'Other OS'+'</a>'; | ||||
| 	if (cat == 501) return maintxt + 'Movies'+'</a>'; | ||||
| 	if (cat == 502) return maintxt + 'Movies DVDR'+'</a>'; | ||||
| 	if (cat == 503) return maintxt + 'Pictures'+'</a>'; | ||||
| 	if (cat == 504) return maintxt + 'Games'+'</a>'; | ||||
| 	if (cat == 505) return maintxt + 'HD-Movies'+'</a>'; | ||||
| 	if (cat == 506) return maintxt + 'Movie Clips'+'</a>'; | ||||
| 	if (cat == 599) return maintxt + 'Other'+'</a>'; | ||||
| 	if (cat == 601) return maintxt + 'E-books'+'</a>'; | ||||
| 	if (cat == 602) return maintxt + 'Comics'+'</a>'; | ||||
| 	if (cat == 603) return maintxt + 'Pictures'+'</a>'; | ||||
| 	if (cat == 604) return maintxt + 'Covers'+'</a>'; | ||||
| 	if (cat == 605) return maintxt + 'Physibles'+'</a>'; | ||||
| 	if (cat == 699) return maintxt + 'Other'+'</a>'; | ||||
| 	return main; | ||||
| } | ||||
| function print_size(size, f) { | ||||
| 	let e=''; | ||||
| 	if (f) { | ||||
| 		e=' (' + size + ' Bytes)'; | ||||
| 	} | ||||
| 	if (size >= 1125899906842624) return round_to_precision(size/1125899906842624, 0.01) + ' PiB' + e; | ||||
| 	if (size >= 1099511627776) return round_to_precision(size/1099511627776, 0.01) + ' TiB' + e; | ||||
| 	if (size >= 1073741824) return round_to_precision(size/1073741824, 0.01) + ' GiB' + e; | ||||
| 	if (size >= 1048576) return round_to_precision(size/1048576, 0.01) + ' MiB' + e; | ||||
| 	if (size >= 1024) return round_to_precision(size/1024, 0.01) + ' KiB' + e; | ||||
| 	return size+' B'; | ||||
| } | ||||
| function round_to_precision(x, precision) { | ||||
| 	let y = +x + (precision === undefined ? 0.5 : precision/2); | ||||
| 	// Fix 1.4000000000000001 like results from rounding. | ||||
| 	let sz = y - (y % (precision === undefined ? 1 : +precision)) + ''; | ||||
| 	if (sz.indexOf('.') == -1) return sz; | ||||
| 	else return sz.substring(0, sz.indexOf('.')+3); | ||||
| } | ||||
| function print_date(date) { | ||||
| 	let dateObj = new Date(date * 1000); | ||||
| 	let month = dateObj.getUTCMonth() + 1; | ||||
| 	let day = dateObj.getUTCDate(); | ||||
| 	let year = dateObj.getUTCFullYear(); | ||||
| 	let m = dateObj.getUTCMonth() + 1; | ||||
| 	let mm; | ||||
| 	if (m < 10) mm = '0'+m | ||||
| 		else mm=m; | ||||
| 	let d = dateObj.getUTCDate(); | ||||
| 	let dd; | ||||
| 	if (d < 10) dd = '0'+d | ||||
| 		else dd=d; | ||||
| 	return dateObj.getUTCFullYear()+'-'+mm+'-'+dd; | ||||
| } | ||||
| function getParameterByName(name, url) { | ||||
| 	if (!url) url = window.location.href; | ||||
| 	name = name.replace(/[\[\]]/g, '\\$&'); | ||||
| 	let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), | ||||
| 	results = regex.exec(url); | ||||
| 	if (!results) return null; | ||||
| 	if (!results[2]) return ''; | ||||
| 	return decodeURIComponent(results[2].replace(/\+/g, ' ')); | ||||
| } | ||||
| function print_username(user) { | ||||
| 	if (user == "Anonymous") return "Anonymous"; | ||||
| 	let u; | ||||
| 	u = encodeURIComponent(user); | ||||
| 	return '<a href="/search.php?q=user:'+u+'">'+user+'</a>'; | ||||
| } | ||||
| function make_details() { | ||||
| 	let json_obj = JSON.parse(Get(server + '/t.php?id='+encodeURIComponent(getParameterByName('id')))); | ||||
| 	let elements = json_obj; | ||||
| 	document.getElementById("tlt").innerHTML=elements['name']; | ||||
| 	document.getElementById("name").innerHTML=elements['name']; | ||||
| 	document.getElementById("cat").innerHTML=print_category(elements['category']); | ||||
| 	document.getElementById("size").innerHTML=print_size(elements['size'], 1); | ||||
| 	document.getElementById("user").innerHTML= print_username(elements['username']) + ' ' + print_status(elements['status']); | ||||
| 	document.getElementById("ih").innerHTML=elements['info_hash']; | ||||
| 	document.getElementById("s").innerHTML=elements['seeders']; | ||||
| 	document.getElementById("l").innerHTML=elements['leechers']; | ||||
| document.getElementById("d").innerHTML=print_download2(elements['info_hash'], elements['name'], 0); | ||||
| 	document.getElementById("d2").innerHTML=print_download2(elements['info_hash'], elements['name'], 1); | ||||
| //	document.getElementById("d").innerHTML=print_download(elements['info_hash'], elements['name']); | ||||
| //	document.getElementById("d2").innerHTML=print_download(elements['info_hash'], elements['name']); | ||||
| 	document.getElementById("uld").innerHTML=print_date(elements['added']); | ||||
| 	document.getElementById("descr").innerHTML=elements['descr']; | ||||
| 	document.getElementById("nfiles").innerHTML=elements['num_files']; | ||||
| } | ||||
| function make_filelist() { | ||||
| 	let json_obj = JSON.parse(Get(server + '/f.php?id='+encodeURIComponent(getParameterByName('id')))); | ||||
| 	let elements = json_obj; | ||||
| 	let i=0; | ||||
|         for (element in elements) { | ||||
|                 if (i == 1) { | ||||
|                         document.write('\n<li class="alt">'); | ||||
|                         i=0; | ||||
|                 } else { | ||||
|                         document.write('\n<li>'); | ||||
| 			i=1; | ||||
|                 } | ||||
|  | ||||
| 		document.write('<span class="file-name">' + elements[element]['name'][0] + '</span><span class="file-size">' + print_size(elements[element]['size'][0], 0) + '</span></li>\n'); | ||||
|  | ||||
| 	} | ||||
| } | ||||
| function make_search() { | ||||
| 	let cats='', lnk='category:', json_obj, i=0, cpage; | ||||
| 	let qu = getParameterByName('q'); | ||||
|  | ||||
| 	if (getParameterByName('cat')) cats = cats + getParameterByName('cat'); | ||||
|  | ||||
| 	if (getParameterByName('audio')) cats=cats+',100'; | ||||
| 	if (getParameterByName('video')) cats=cats+',200'; | ||||
| 	if (getParameterByName('apps'))  cats=cats+',300'; | ||||
| 	if (getParameterByName('games')) cats=cats+',400'; | ||||
| 	if (getParameterByName('porn'))  cats=cats+',500'; | ||||
| 	if (getParameterByName('other')) cats=cats+',600'; | ||||
| 	if (cats[0] == ',') cats = cats.substring(1); | ||||
|  | ||||
| 	if (qu.substring(0,13) == 'top100:recent') { | ||||
| 		document.getElementById("tlt").innerHTML='Recent torrents'; | ||||
| 		if (qu.substring(0,13) == 'top100:recent') { | ||||
| 			json_obj = JSON.parse(Get(server + '/precompiled/data_top100_recent.json' )); | ||||
| 		} | ||||
| 		if (qu.substring(0,14) == 'top100:recent:') { | ||||
| 			cpage = Number(get_q_part(qu, 2)); | ||||
| 			if (cpage == 0) { | ||||
| 				json_obj = JSON.parse(Get(server + '/precompiled/data_top100_recent.json' )); | ||||
| 			} else { | ||||
| 				json_obj = JSON.parse(Get(server + '/precompiled/data_top100_recent_' + cpage + '.json' )); | ||||
| 			} | ||||
| 		} | ||||
| 	} else if (qu.substring(0,7) == 'top100:') { | ||||
| 		json_obj = JSON.parse(Get(server + '/precompiled/data_top100_' + qu.substring(7) + '.json' )); | ||||
| 		document.getElementById("tlt").innerHTML='Top 100: ' + print_top100_title(qu.substring(7)); | ||||
| 		lnk='top100:'; | ||||
| 	} else if (qu.substring(0,9) == 'category:') { | ||||
| 		json_obj = JSON.parse(Get(server + '/q.php?q=' + encodeURIComponent(qu))); | ||||
| 		document.getElementById("tlt").innerHTML='Browse ' + print_category(qu.substring(9)); | ||||
| 	} else if (qu.substring(0,5) == 'user:') { | ||||
| 		json_obj = JSON.parse(Get(server + '/q.php?q=' + encodeURIComponent(qu))); | ||||
| 		document.getElementById("tlt").innerHTML='User: ' + htmlEntities(qu.substring(5)); | ||||
| 	} else { | ||||
| 		json_obj = JSON.parse(Get(server + '/q.php?q=' + encodeURIComponent(qu) + '&cat=' + cats )); | ||||
| 		document.getElementById("tlt").innerHTML='Results for: ' + htmlEntities(qu); | ||||
| 	} | ||||
|  | ||||
| 	let elements = json_obj; | ||||
| 	for (element in elements) { | ||||
| 		if (i == 1) { | ||||
| 			document.write('\n<li class="list-entry alt" id="st">\n'); | ||||
| 			i=0; | ||||
| 		} else { | ||||
| 			document.write('\n<li class="list-entry" id="st">\n'); | ||||
| 			i=1; | ||||
| 		} | ||||
| 		document.write('<span class="list-item item-type">' + print_category(elements[element]['category'], lnk) + '</span>'); | ||||
| 		document.write('<span class="list-item item-name item-title"><a href="/description.php?id='+elements[element]['id']+'">' + elements[element]['name']+'</a></span>'); | ||||
| 		document.write('<span class="list-item item-uploaded">' + print_date(elements[element]['added']) + '</span>'); | ||||
| 		document.write('<span class="item-icons">' + print_magnet(elements[element]['info_hash'], elements[element]['name']) + print_status(elements[element]['status']) + '</span>'); | ||||
| 		document.write('<span class="list-item item-size">' + print_size(elements[element]['size'], 0) + '<input type="hidden" name="size" value="' + elements[element]['size'] + '"/></span>'); | ||||
| 		document.write('<span class="list-item item-seed">' + elements[element]['seeders'] + '</span>'); | ||||
| 		document.write('<span class="list-item item-leech">' + elements[element]['leechers'] + ' </span>'); | ||||
| 		document.write('<span class="list-item item-user">' + print_username(elements[element]['username']) + '</span>\n</li>\n'); | ||||
| 	} | ||||
|         document.write('</ol>\n'); | ||||
|  | ||||
| 	// Page selector | ||||
| 	if (qu.substring(0,5) == 'user:') { | ||||
| 		document.write('<center>\n'); | ||||
| 		if (get_q_part(qu, 1)) print_pageselector( get_q_part(qu, 1), Number(get_q_part(qu, 2)), '/search.php?q=user:' + htmlEntities(get_q_part(qu, 1)) ); | ||||
| 		document.write('</center>\n'); | ||||
| 	} | ||||
| 	if (qu.substring(0,13) == 'top100:recent') { | ||||
| 		document.write('<center>\n'); | ||||
| 		print_pageselector( 'recent', Number(get_q_part(qu, 2)), '/search.php?q=top100:recent' ); | ||||
| 		document.write('</center>\n'); | ||||
| 	} | ||||
|  | ||||
| 	document.write('</section>\n'); | ||||
|  | ||||
| } | ||||
| function get_q_part(stra, part) { | ||||
|         // 0 = type | ||||
|         // 1 = query | ||||
|         // 2 = page | ||||
|         if (part == 2) { | ||||
|                 if (stra.split(':').length == 2) return 0; | ||||
|                 let pg=stra.split(':')[stra.split(':').length-1]; | ||||
|                 if (isNaN(pg)) return 0; | ||||
|                 if (pg == '') return 0; | ||||
|                 return Number(pg); | ||||
|         } | ||||
|         return stra.split(':')[part]; | ||||
| } | ||||
| function setAll() { | ||||
|         document.forms['q'].elements['audio'].checked = false; | ||||
|         document.forms['q'].elements['video'].checked = false; | ||||
|         document.forms['q'].elements['apps'].checked  = false; | ||||
|         document.forms['q'].elements['games'].checked = false; | ||||
|         document.forms['q'].elements['porn'].checked  = false; | ||||
|         document.forms['q'].elements['other'].checked = false; | ||||
| } | ||||
| function rmAll() { | ||||
| 	document.forms['q'].elements['all'].checked = false; | ||||
| } | ||||
| // Default sort order | ||||
| var sort_o = new Array(10); | ||||
| sort_o[1]=1; | ||||
| sort_o[2]=1; | ||||
| sort_o[3]=0; | ||||
| sort_o[5]=0; | ||||
| sort_o[6]=0; | ||||
| sort_o[7]=0; | ||||
| sort_o[8]=1; | ||||
| function sortlist(sr) { | ||||
| 	if (sort_o[sr] == 1) { | ||||
| 		tinysort.defaults.order = 'asc'; | ||||
| 		sort_o[sr]=0; | ||||
| 	} else { | ||||
| 		tinysort.defaults.order = 'desc'; | ||||
| 		sort_o[sr]=1; | ||||
| 	} | ||||
| 	if (sr == 5) { | ||||
| 		tinysort('li#st',{selector:'input',attr:'value'}); | ||||
| 		return; | ||||
| 	} | ||||
| 	tinysort('li#st','span:nth-child(' + sr + ')'); | ||||
| } | ||||
| function htmlEntities(str) { | ||||
| 	return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); | ||||
| } | ||||
| function print_footer() { | ||||
| 	document.write('<footer class="row flow-root flow-column align-center">\n', | ||||
| '<nav>\n', | ||||
| '<div>\n', | ||||
| '<a href="/session/" title="Login/Upload">Login/Upload</a> |\n', | ||||
| '<a href="/session/" title="Register">Register</a>\n', | ||||
| '</div>\n', | ||||
| '<div>\n', | ||||
| '<a href="https://tpb.718it.biz" title="tor address">TOR</a> |\n', | ||||
| '<a href="https://pirates-forum.org/" title="discussion forum" target="_blank">Forum</a> |\n', | ||||
| '<a href="https://www.azirevpn.net/landing" target="_NEW"><b>VPN</b></a> |\n', | ||||
| '<a href="https://tmp.ninja" target="_NEW"><b>FileHosting</b></a>\n', | ||||
| '</div>\n', | ||||
| '</nav>\n', | ||||
| '<p style="overflow-wrap: break-word;">\n', | ||||
| '<a href="https://bitcoin.org" target="_NEW">BTC</a>: <b>3EoJMDs79b3ztkYvj2E1D98eHnZyCSQKso</b>\n', | ||||
| '<br /><a href="https://bitcoin.org" target="_NEW">BTC (Bech32)</a>: <b>bc1q9x30z7rz52c97jwc2j79w76y7l3ny54nlvd4ew</b>\n', | ||||
| '<br /><a href="https://litecoin.org" target="_NEW">LTC</a>: <b>LS78aoGtfuGCZ777x3Hmr6tcoW3WaYynx9</b>\n', | ||||
| '<br /><a href="https://getmonero.org" target="_NEW">XMR</a>: <b>46E5ekYrZd5UCcmNuYEX24FRjWVMgZ1ob79cRViyfvLFZjfyMhPDvbuCe54FqLQvVCgRKP4UUMMW5fy3ZhVQhD1JLLufBtu</b>\n', | ||||
| '</p>\n', | ||||
| '</footer>\n'); | ||||
| } | ||||
| function print_header1() { | ||||
| 	document.write('<section class="col-left" id="logo"><a href="/index.html"><img src="' + static_server + '/images/tpbsmall_notext.jpg" alt="The Pirate Bay"></a></section>\n', | ||||
| '<section class="col-center">\n', | ||||
| '<nav>\n', | ||||
| '<a href="/index.html" title="Search Torrents"><strong>Search Torrents</strong></a> |\n', | ||||
| '<a href="/browse.php" title="Browse Torrents">Browse Torrents</a> |\n', | ||||
| '<a href="/search.php?q=top100:recent" title="Recent Torrent">Recent Torrents</a> |\n', | ||||
| '<a href="/top.php" title="Top 100">Top 100</a>\n', | ||||
| '</nav>\n', | ||||
| '<form action="/search.php">\n'); | ||||
| } | ||||
| function print_header2() { | ||||
| 	document.write('<input value="Pirate Search" type="submit">\n', | ||||
| '<select name="cat" id="cat">\n', | ||||
| '<option value="0">All</option>\n', | ||||
| '<optgroup label="Audio">\n', | ||||
| '<option value="101">Music</option>\n', | ||||
| '<option value="102">Audio books</option>\n', | ||||
| '<option value="103">Sound clips</option>\n', | ||||
| '<option value="104">FLAC</option>\n', | ||||
| '<option value="199">Other</option>\n', | ||||
| '</optgroup>\n', | ||||
| '<optgroup label="Video">\n', | ||||
| '<option value="201">Movies</option>\n', | ||||
| '<option value="202">Movies DVDR</option>\n', | ||||
| '<option value="203">Music videos</option>\n', | ||||
| '<option value="204">Movie clips</option>\n', | ||||
| '<option value="205">TV shows</option>\n', | ||||
| '<option value="206">Handheld</option>\n', | ||||
| '<option value="207">HD - Movies</option>\n', | ||||
| '<option value="208">HD - TV shows</option>\n', | ||||
| '<option value="209">3D</option>\n', | ||||
| '<option value="299">Other</option>\n', | ||||
| '</optgroup>\n', | ||||
| '<optgroup label="Applications">\n', | ||||
| '<option value="301">Windows</option>\n', | ||||
| '<option value="302">Mac</option>\n', | ||||
| '<option value="303">UNIX</option>\n', | ||||
| '<option value="304">Handheld</option>\n', | ||||
| '<option value="305">IOS (iPad/iPhone)</option>\n', | ||||
| '<option value="306">Android</option>\n', | ||||
| '<option value="399">Other OS</option>\n', | ||||
| '</optgroup>\n', | ||||
| '<optgroup label="Games">\n', | ||||
| '<option value="401">PC</option>\n', | ||||
| '<option value="402">Mac</option>\n', | ||||
| '<option value="403">PSx</option>\n', | ||||
| '<option value="404">XBOX360</option>\n', | ||||
| '<option value="405">Wii</option>\n', | ||||
| '<option value="406">Handheld</option>\n', | ||||
| '<option value="407">IOS (iPad/iPhone)</option>\n', | ||||
| '<option value="408">Android</option>\n', | ||||
| '<option value="499">Other</option>\n', | ||||
| '</optgroup>\n', | ||||
| '<optgroup label="Porn">\n', | ||||
| '<option value="501">Movies</option>\n', | ||||
| '<option value="502">Movies DVDR</option>\n', | ||||
| '<option value="503">Pictures</option>\n', | ||||
| '<option value="504">Games</option>\n', | ||||
| '<option value="505">HD - Movies</option>\n', | ||||
| '<option value="506">Movie clips</option>\n', | ||||
| '<option value="599">Other</option>\n', | ||||
| '</optgroup>\n', | ||||
| '<optgroup label="Other">\n', | ||||
| '<option value="601">E-books</option>\n', | ||||
| '<option value="602">Comics</option>\n', | ||||
| '<option value="603">Pictures</option>\n', | ||||
| '<option value="604">Covers</option>\n', | ||||
| '<option value="605">Physibles</option>\n', | ||||
| '<option value="699">Other</option>\n', | ||||
| '</optgroup>\n', | ||||
| '</select>\n', | ||||
| '</form>\n', | ||||
| '</section>\n'); | ||||
| } | ||||
| function mark_selected() { | ||||
| 	let scate = document.getElementById('cat'); | ||||
| 	if (scate) { | ||||
|         	let ct = getParameterByName('cat'); | ||||
| 	        if ((Number(ct) > 99) && (Number(ct) < 700)) { | ||||
|         	        scate.value = ct; | ||||
| 	        } else { | ||||
|         	        scate.value = 0; | ||||
| 	        } | ||||
| 	} | ||||
| } | ||||
| function print_search() { | ||||
|         document.write('<section class="col-center">\n', | ||||
| '<input type="text" id="flist" onkeyup="filter_list()" placeholder="Filter names.." size=40>', | ||||
| '<ol id="torrents" class="view-single">\n', | ||||
| '<li class="list-header">\n', | ||||
| '<span class="list-item list-header item-type"><label onclick="sortlist(1);" title="Order by Category">Category</label></span>\n', | ||||
| '<span class="list-item list-header item-name"><label onclick="sortlist(2);"  title="Order by Name">Name</label></span>\n', | ||||
| '<span class="list-item list-header item-uploaded"><label onclick="sortlist(3);" title="Order by Date Uploaded">Uploaded</label></span>\n', | ||||
| '<span class="list-item list-header item-icons"> </span>\n', | ||||
| '<span class="list-item list-header item-size"><label onclick="sortlist(5);" title="Order by Size">Size</label></span>\n', | ||||
| '<span class="list-item list-header item-seed"><label onclick="sortlist(6);" title="Order by Seeders">SE</label></span>\n', | ||||
| '<span class="list-item list-header item-leech"><label onclick="sortlist(7);" title="Order by Leechers">LE</label></span>\n', | ||||
| '<span class="list-item list-header item-user"><label onclick="sortlist(8);" title="Order by ULed by">ULed by</label></span>\n', | ||||
| '</li>\n'); | ||||
|         if (typeof make_search !== "undefined" ) make_search(); | ||||
| } | ||||
| function print_browse() { | ||||
|         document.write('<section class="col-center">\n', | ||||
| '<dl class="row">\n', | ||||
| '<div class="category_list">\n', | ||||
| '<div>\n', | ||||
| '<dt><a href="/search.php?q=category:100" title="Audio">Audio</a></dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=category:101" title="Music">Music</a>\n', | ||||
| '<a href="/search.php?q=category:102" title="Audio books">Audio books</a>\n', | ||||
| '<a href="/search.php?q=category:103" title="Sound clips">Sound clips</a>\n', | ||||
| '<a href="/search.php?q=category:103" title="FLAC">FLAC</a>\n', | ||||
| '<a href="/search.php?q=category:199" title="Other">Other</a>\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '<div>\n', | ||||
| '<dt><a href="/search.php?q=category:200" title="Video">Video</a></dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=category:201" title="Movies">Movies</a>\n', | ||||
| '<a href="/search.php?q=category:202" title="Movies DVDR">Movies DVDR</a>\n', | ||||
| '<a href="/search.php?q=category:203" title="Music videos">Music videos</a>\n', | ||||
| '<a href="/search.php?q=category:204" title="Movie clips">Movie clips</a>\n', | ||||
| '<a href="/search.php?q=category:205" title="TV shows">TV shows</a>\n', | ||||
| '<a href="/search.php?q=category:206" title="Handheld">Handheld</a>\n', | ||||
| '<a href="/search.php?q=category:207" title="HD - Movies">HD - Movies</a>\n', | ||||
| '<a href="/search.php?q=category:208" title="HD - TV shows">HD - TV shows</a>\n', | ||||
| '<a href="/search.php?q=category:209" title="3D">3D</a>\n', | ||||
| '<a href="/search.php?q=category:299" title="Other">Other</a>\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '<div>\n', | ||||
| '<dt><a href="/search.php?q=category:300" title="Applications">Applications</a></dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=category:301" title="Windows">Windows</a>\n', | ||||
| '<a href="/search.php?q=category:302" title="Mac">Mac</a>\n', | ||||
| '<a href="/search.php?q=category:303" title="UNIX">UNIX</a>\n', | ||||
| '<a href="/search.php?q=category:304" title="Handheld">Handheld</a>\n', | ||||
| '<a href="/search.php?q=category:305" title="IOS (iPad/iPhone)">IOS (iPad/iPhone)</a>\n', | ||||
| '<a href="/search.php?q=category:306" title="Android">Android</a>\n', | ||||
| '<a href="/search.php?q=category:399" title="Other OS">Other OS</a>\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '</div>\n', | ||||
| '<div class="category_list">\n', | ||||
| '<div>\n', | ||||
| '<dt><a href="/search.php?q=category:400" title="Games">Games</a></dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=category:401" title="PC">PC</a>\n', | ||||
| '<a href="/search.php?q=category:402" title="Mac">Mac</a>\n', | ||||
| '<a href="/search.php?q=category:403" title="PSx">PSx</a>\n', | ||||
| '<a href="/search.php?q=category:404" title="XBOX360">XBOX360</a>\n', | ||||
| '<a href="/search.php?q=category:405" title="Wii">Wii</a>\n', | ||||
| '<a href="/search.php?q=category:406" title="Handheld">Handheld</a>\n', | ||||
| '<a href="/search.php?q=category:407" title="IOS (iPad/iPhone)">IOS (iPad/iPhone)</a>\n', | ||||
| '<a href="/search.php?q=category:408" title="Android">Android</a>\n', | ||||
| '<a href="/search.php?q=category:499" title="Other">Other</a>\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '<div>\n', | ||||
| '<dt><a href="/search.php?q=category:500" title="Porn">Porn</a></dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=category:501" title="Movies">Movies</a>,\n', | ||||
| '<a href="/search.php?q=category:502" title="Movies DVDR">Movies DVDR</a>\n', | ||||
| '<a href="/search.php?q=category:503" title="Pictures">Pictures</a>\n', | ||||
| '<a href="/search.php?q=category:504" title="Games">Games</a>\n', | ||||
| '<a href="/search.php?q=category:505" title="HD - Movies">HD - Movies</a>\n', | ||||
| '<a href="/search.php?q=category:506" title="Movie clips">Movie clips</a>\n', | ||||
| '<a href="/search.php?q=category:599" title="Other">Other</a>\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '<div>\n', | ||||
| '<dt><a href="/search.php?q=category:600" title="Other">Other</a></dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=category:601" title="E-books">E-books</a>\n', | ||||
| '<a href="/search.php?q=category:602" title="Comics">Comics</a>\n', | ||||
| '<a href="/search.php?q=category:603" title="Pictures">Pictures</a>\n', | ||||
| '<a href="/search.php?q=category:604" title="Covers">Covers</a>\n', | ||||
| '<span><a href="/search.php?q=category:605" title="Physibles">Physibles</a><a href=""><b>(?!)</b></a></span>\n', | ||||
| '<a href="/search.php?q=category:699" title="Other">Other</a>\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '</div>\n', | ||||
| '</dl>\n', | ||||
| '</section>\n'); | ||||
| } | ||||
| function print_top() { | ||||
|         document.write('<section class="col-center">\n', | ||||
| '<dl class="row">\n', | ||||
| '<div class="category_list">\n', | ||||
| '<b><a href="/search.php?q=top100:all">Total Top100</a></b> (<a href="/search.php?q=top100:48h">48h</a>)\n', | ||||
| '</div>\n', | ||||
| '</dl>\n', | ||||
| '<dl class="row">\n', | ||||
| '<div class="category_list">\n', | ||||
| '<div>\n', | ||||
| '<dt><b><a href="/search.php?q=top100:100" title="Audio">Audio</a></b> (<a href="/search.php?q=top100:48h_100">48h</a>)</dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=top100:101" title="Music">Music</a> (<a href="/search.php?q=top100:48h_101">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:102" title="Audio books">Audio books</a> (<a href="/search.php?q=top100:48h_102">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:103" title="Sound clips">Sound clips</a> (<a href="/search.php?q=top100:48h_103">48h</a>)<br />\n', | ||||
| '<a href="/search.php?q=top100:103" title="FLAC">FLAC</a> (<a href="/search.php?q=top100:48h_104">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:199" title="Other">Other</a> (<a href="/search.php?q=top100:48h_199">48h</a>)\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '<div>\n', | ||||
| '<dt><b><a href="/search.php?q=top100:200" title="Video">Video</a></b> (<a href="/search.php?q=top100:48h_200">48h</a>)</dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=top100:201" title="Movies">Movies</a> (<a href="/search.php?q=top100:48h_201">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:202" title="Movies DVDR">Movies DVDR</a> (<a href="/search.php?q=top100:48h_202">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:203" title="Music videos">Music videos</a> (<a href="/search.php?q=top100:48h_203">48h</a>)<br />\n', | ||||
| '<a href="/search.php?q=top100:204" title="Movie clips">Movie clips</a> (<a href="/search.php?q=top100:48h_204">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:205" title="TV shows">TV shows</a> (<a href="/search.php?q=top100:48h_205">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:206" title="Handheld">Handheld</a> (<a href="/search.php?q=top100:48h_206">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:207" title="HD - Movies">HD - Movies</a> (<a href="/search.php?q=top100:48h_207">48h</a>)<br />\n', | ||||
| '<a href="/search.php?q=top100:208" title="HD - TV shows">HD - TV shows</a> (<a href="/search.php?q=top100:48h_208">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:209" title="3D">3D</a> (<a href="/search.php?q=top100:48h_209">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:299" title="Other">Other</a> (<a href="/search.php?q=top100:48h_299">48h</a>)\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '<div>\n', | ||||
| '<dt><b><a href="/search.php?q=top100:300" title="Applications">Applications</a></b> (<a href="/search.php?q=top100:48h_400">48h</a>)</dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=top100:301" title="Windows">Windows</a> (<a href="/search.php?q=top100:48h_301">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:302" title="Mac">Mac</a> (<a href="/search.php?q=top100:48h_302">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:303" title="UNIX">UNIX</a> (<a href="/search.php?q=top100:48h_303">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:304" title="Handheld">Handheld</a> (<a href="/search.php?q=top100:48h_304">48h</a>)<br />\n', | ||||
| '<a href="/search.php?q=top100:305" title="IOS (iPad/iPhone)">IOS (iPad/iPhone)</a> (<a href="/search.php?q=top100:48h_305">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:306" title="Android">Android</a> (<a href="/search.php?q=top100:48h_306">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:399" title="Other OS">Other OS</a> (<a href="/search.php?q=top100:48h_399">48h</a>)\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '</div>\n', | ||||
| '<div class="category_list">\n', | ||||
| '<div>\n', | ||||
| '<dt><b><a href="/search.php?q=top100:400" title="Games">Games</a></b> (<a href="/search.php?q=top100:48h_400">48h</a>)</dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=top100:401" title="PC">PC</a> (<a href="/search.php?q=top100:48h_401">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:402" title="Mac">Mac</a> (<a href="/search.php?q=top100:48h_402">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:403" title="PSx">PSx</a> (<a href="/search.php?q=top100:48h_403">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:404" title="XBOX360">XBOX360</a> (<a href="/search.php?q=top100:48h_404">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:405" title="Wii">Wii</a> (<a href="/search.php?q=top100:48h_405">48h</a>)<br />\n', | ||||
| '<a href="/search.php?q=top100:406" title="Handheld">Handheld</a> (<a href="/search.php?q=top100:48h_406">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:407" title="IOS (iPad/iPhone)">IOS (iPad/iPhone)</a> (<a href="/search.php?q=top100:48h_407">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:408" title="Android">Android</a> (<a href="/search.php?q=top100:48h_408">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:499" title="Other">Other</a> (<a href="/search.php?q=top100:48h_499">48h</a>)\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '<div>\n', | ||||
| '<dt><b><a href="/search.php?q=top100:500" title="Porn">Porn</a></b> (<a href="/search.php?q=top100:48h_500">48h</a>)</dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=top100:501" title="Movies">Movies</a> (<a href="/search.php?q=top100:48h_501">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:502" title="Movies DVDR">Movies DVDR</a> (<a href="/search.php?q=top100:48h_502">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:503" title="Pictures">Pictures</a> (<a href="/search.php?q=top100:48h_503">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:504" title="Games">Games</a> (<a href="/search.php?q=top100:48h_504">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:505" title="HD - Movies">HD - Movies</a> (<a href="/search.php?q=top100:48h_505">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:506" title="Movie clips">Movie clips</a> (<a href="/search.php?q=top100:48h_506">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:599" title="Other">Other</a> (<a href="/search.php?q=top100:48h_599">48h</a>)\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '<div>\n', | ||||
| '<dt><b><a href="/search.php?q=top100:600" title="Other">Other</a></b> (<a href="/search.php?q=top100:48h_600">48h</a>)</dt>\n', | ||||
| '<dd>\n', | ||||
| '<a href="/search.php?q=top100:601" title="E-books">E-books</a> (<a href="/search.php?q=top100:48h_601">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:602" title="Comics">Comics</a> (<a href="/search.php?q=top100:48h_602">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:603" title="Pictures">Pictures</a> (<a href="/search.php?q=top100:48h_603">48h</a>)<br />\n', | ||||
| '<a href="/search.php?q=top100:604" title="Covers">Covers</a> (<a href="/search.php?q=top100:48h_604">48h</a>)\n', | ||||
| '<span><a href="/search.php?q=top100:605" title="Physibles">Physibles</a></a></span> (<a href="/search.php?q=top100:48h_605">48h</a>)\n', | ||||
| '<a href="/search.php?q=top100:699" title="Other">Other</a> (<a href="/search.php?q=top100:48h_699">48h</a>)\n', | ||||
| '</dd>\n', | ||||
| '</div>\n', | ||||
| '</div>\n', | ||||
| '</dl>\n', | ||||
| '</section>\n'); | ||||
| } | ||||
| function do_pop_porn() {} | ||||
| function do_pop() {} | ||||
| function thepop(adConfig) {} | ||||
| function print_selector_number(i, curpage, linkto) { | ||||
|         let before, after; | ||||
|         if (i == curpage) { | ||||
|                 before = '<b>'; | ||||
|                 after = '</b>'; | ||||
|         } else { | ||||
|                 before = '<a href="' + linkto + ':' + i + '">'; | ||||
|                 after = '</a>'; | ||||
|         } | ||||
|         document.write(before, i+1, after, ' \n'); | ||||
| } | ||||
| function print_pageselector(username, curpage, linkto) { | ||||
|         let json_obj = JSON.parse(Get(server + '/q.php?q=pcnt:' + username )); | ||||
|         let elements = json_obj; | ||||
|         let pages = Number(elements)-1; | ||||
|         let before, after, o, i, strt, stp; | ||||
|  | ||||
|         if (pages < 2) return ''; | ||||
|  | ||||
|         if (pages < 30) { | ||||
|                 for (i=0; i < pages; i++) { | ||||
|                         print_selector_number(i, curpage, linkto); | ||||
|                 } | ||||
|         } else { | ||||
|                 if (curpage-10 > 5) { | ||||
|                         strt=curpage-10; | ||||
|                         if (strt > pages-25) strt=pages-25; | ||||
|  | ||||
|                         print_selector_number(0, curpage, linkto); | ||||
|                         print_selector_number(1, curpage, linkto); | ||||
|                         print_selector_number(2, curpage, linkto); | ||||
|                         document.write('... '); | ||||
|                 } else { | ||||
|                         strt=0; | ||||
|                 } | ||||
|                 if (pages-curpage-10 > 5) { | ||||
|                         stp=curpage+11; | ||||
|                         if (stp < 27) stp=26; | ||||
|                         if (stp > pages) stp=pages; | ||||
|                 } else { | ||||
|                         if (strt == 0) { | ||||
|                                 stp=16; | ||||
|                         } else { | ||||
|                                 stp=pages; | ||||
|                         } | ||||
|                 } | ||||
|                 for (i=strt; i < stp; i++) { | ||||
|                         print_selector_number(i, curpage, linkto); | ||||
|  | ||||
|                 } | ||||
|                 if (pages-curpage-10 > 5) { | ||||
|                         document.write('... '); | ||||
|                         print_selector_number(pages-2, curpage, linkto); | ||||
|                         print_selector_number(pages-1, curpage, linkto); | ||||
|                         print_selector_number(pages, curpage, linkto); | ||||
|                 } | ||||
|  | ||||
|         } | ||||
|         document.write('<br />\n'); | ||||
| } | ||||
| function filter_list() { | ||||
|   let input, filter, ul, li, a, i, txtValue; | ||||
|   input = document.getElementById('flist'); | ||||
|   filter = input.value.toUpperCase(); | ||||
|   li = document.getElementsByClassName('list-entry'); | ||||
|  | ||||
|   for (i = 0; i < li.length; i++) { | ||||
|     a = li[i].getElementsByTagName('span')[1]; | ||||
|     txtValue = a.textContent || a.innerText; | ||||
|     if (txtValue.toUpperCase().indexOf(filter) > -1) { | ||||
|       li[i].style.display = ''; | ||||
|     } else { | ||||
|       li[i].style.display = 'none'; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| function do_interstitial_porn() {} | ||||
| function do_interstitial() {} | ||||
		Reference in New Issue
	
	Block a user
	