mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	Trying to improve cpu on server..
This commit is contained in:
		| @@ -3,6 +3,12 @@ var gulp    = require('gulp'), | |||||||
| 	uglify  = require('gulp-uglifyjs'), | 	uglify  = require('gulp-uglifyjs'), | ||||||
| 	concat  = require('gulp-concat'); | 	concat  = require('gulp-concat'); | ||||||
|  |  | ||||||
|  | gulp.task('server', function() { | ||||||
|  |     gulp.src(['server/handlers/db.js', 'server/handlers/server.js', 'server/handlers/io.js', 'server/handlers/frontpage.js', 'server/handlers/functions.js', 'server/handlers/chat.js', 'server/handlers/list_change.js', 'server/handlers/list_settings.js', 'server/handlers/list.js', 'server/handlers/suggestions.js']) | ||||||
|  |         .pipe(concat('index.js')) | ||||||
|  |         .pipe(gulp.dest('server/')); | ||||||
|  | }); | ||||||
|  |  | ||||||
| gulp.task('js', function () { | gulp.task('js', function () { | ||||||
|     gulp.src(['server/public/assets/js/*.js', '!server/public/assets/js/embed*', '!server/public/assets/js/remotecontroller.js', '!server/public/assets/js/callback.js']) |     gulp.src(['server/public/assets/js/*.js', '!server/public/assets/js/embed*', '!server/public/assets/js/remotecontroller.js', '!server/public/assets/js/callback.js']) | ||||||
|         .pipe(uglify({ |         .pipe(uglify({ | ||||||
| @@ -60,6 +66,7 @@ gulp.task('remotecontroller', function () { | |||||||
| }); | }); | ||||||
|  |  | ||||||
| gulp.task('default', function(){ | gulp.task('default', function(){ | ||||||
|  |     gulp.watch(['server/handlers/*.js', 'router/*.js'], ['server']); | ||||||
|     gulp.watch('server/public/assets/js/*.js', ['js']); |     gulp.watch('server/public/assets/js/*.js', ['js']); | ||||||
|     gulp.watch('server/public/assets/js/*.js', ['embed']); |     gulp.watch('server/public/assets/js/*.js', ['embed']); | ||||||
|     gulp.watch(['server/public/assets/js/callback.js', 'server/public/assets/js/helpers.js'], ['callback']); |     gulp.watch(['server/public/assets/js/callback.js', 'server/public/assets/js/helpers.js'], ['callback']); | ||||||
|   | |||||||
							
								
								
									
										24
									
								
								npm-debug.log
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								npm-debug.log
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | |||||||
|  | 0 info it worked if it ends with ok | ||||||
|  | 1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ] | ||||||
|  | 2 info using npm@3.10.10 | ||||||
|  | 3 info using node@v6.10.3 | ||||||
|  | 4 verbose stack Error: missing script: start | ||||||
|  | 4 verbose stack     at run (/usr/local/lib/node_modules/npm/lib/run-script.js:151:19) | ||||||
|  | 4 verbose stack     at /usr/local/lib/node_modules/npm/lib/run-script.js:61:5 | ||||||
|  | 4 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5 | ||||||
|  | 4 verbose stack     at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45) | ||||||
|  | 4 verbose stack     at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3) | ||||||
|  | 4 verbose stack     at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5) | ||||||
|  | 4 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:311:12 | ||||||
|  | 4 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 | ||||||
|  | 4 verbose stack     at tryToString (fs.js:456:3) | ||||||
|  | 4 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:443:12) | ||||||
|  | 5 verbose cwd /Users/kasperrt/zoff | ||||||
|  | 6 error Darwin 16.6.0 | ||||||
|  | 7 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" | ||||||
|  | 8 error node v6.10.3 | ||||||
|  | 9 error npm  v3.10.10 | ||||||
|  | 10 error missing script: start | ||||||
|  | 11 error If you need help, you may report this error at: | ||||||
|  | 11 error     <https://github.com/npm/npm/issues> | ||||||
|  | 12 verbose exit [ 1, true ] | ||||||
| @@ -6,9 +6,9 @@ var chat = function(msg, guid, offline, socket) { | |||||||
|   } |   } | ||||||
|   var coll = msg.channel; |   var coll = msg.channel; | ||||||
|   db.collection(coll).find({views:{$exists:true}}, function(err, docs){ |   db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
|     if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socket.zoff_id, msg.pass)))) { |     if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socket.zoff_id, msg.pass)))) { | ||||||
|       var data = msg.data; |       var data = msg.data; | ||||||
|       Functions.check_inlist(coll, guid, socket, offline); |       check_inlist(coll, guid, socket, offline); | ||||||
|       if(data !== "" && data !== undefined && data !== null && |       if(data !== "" && data !== undefined && data !== null && | ||||||
|       data.length < 151 && data.replace(/\s/g, '').length){ |       data.length < 151 && data.replace(/\s/g, '').length){ | ||||||
|         db.collection("user_names").find({"guid": guid}, function(err, docs) { |         db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||||
| @@ -33,7 +33,7 @@ var all_chat = function(msg, guid, offline, socket) { | |||||||
|   var coll = msg.channel; |   var coll = msg.channel; | ||||||
|   var data = msg.data; |   var data = msg.data; | ||||||
|  |  | ||||||
|   Functions.check_inlist(coll, guid, socket, offline); |   check_inlist(coll, guid, socket, offline); | ||||||
|   if(data !== "" && data !== undefined && data !== null && |   if(data !== "" && data !== undefined && data !== null && | ||||||
|   data.length < 151 && data.replace(/\s/g, '').length){ |   data.length < 151 && data.replace(/\s/g, '').length){ | ||||||
|     db.collection("user_names").find({"guid": guid}, function(err, docs) { |     db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||||
| @@ -92,7 +92,7 @@ var removename = function(guid, coll) { | |||||||
| } | } | ||||||
|  |  | ||||||
| var generate_name = function(guid, announce_payload) { | var generate_name = function(guid, announce_payload) { | ||||||
|   var tmp_name = Functions.rndName(guid, 8); |   var tmp_name = rndName(guid, 8); | ||||||
|   db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: tmp_name}}, {upsert: true}, function(err, updated) { |   db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: tmp_name}}, {upsert: true}, function(err, updated) { | ||||||
|     if(updated.nModified == 1 || (updated.hasOwnProperty("upserted") && n == 1)) { |     if(updated.nModified == 1 || (updated.hasOwnProperty("upserted") && n == 1)) { | ||||||
|       db.collection("user_names").update({"guid": guid}, {$set: {name: tmp_name}}, {upsert: true}, function(err, update){ |       db.collection("user_names").update({"guid": guid}, {$set: {name: tmp_name}}, {upsert: true}, function(err, update){ | ||||||
| @@ -121,9 +121,3 @@ var get_name = function(guid, announce_payload) { | |||||||
|     } |     } | ||||||
|   }) |   }) | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports.namechange = namechange; |  | ||||||
| module.exports.get_name = get_name; |  | ||||||
| module.exports.removename = removename; |  | ||||||
| module.exports.chat = chat; |  | ||||||
| module.exports.all_chat = all_chat; |  | ||||||
|   | |||||||
| @@ -9,5 +9,3 @@ db.on('connected', function(err) { | |||||||
| db.on('error',function(err) { | db.on('error',function(err) { | ||||||
| 	console.log("\n" + new Date().toString() + "\n Database error: ", err); | 	console.log("\n" + new Date().toString() + "\n Database error: ", err); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| module.exports = db; |  | ||||||
|   | |||||||
| @@ -3,13 +3,13 @@ function frontpage_lists(msg, socket) { | |||||||
|     socket.emit("update_required"); |     socket.emit("update_required"); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| console.log("gotten second ", Functions.get_time()); | console.log("gotten second ", get_time()); | ||||||
|   db.collection("frontpage_lists").find({frontpage:true}, function(err, docs){ |   db.collection("frontpage_lists").find({frontpage:true}, function(err, docs){ | ||||||
|     console.log("gotten third ", Functions.get_time()); |     console.log("gotten third ", get_time()); | ||||||
|         db.collection("connected_users").find({"_id": "total_users"}, function(err, tot){ |         db.collection("connected_users").find({"_id": "total_users"}, function(err, tot){ | ||||||
|         console.log("sending frontpage ", Functions.get_time()); |         console.log("sending frontpage ", get_time()); | ||||||
|         socket.compress(true).emit("playlists", {channels: docs, viewers: tot[0].total_users}); |         socket.compress(true).emit("playlists", {channels: docs, viewers: tot[0].total_users}); | ||||||
|         console.log("sent frontpage ", Functions.get_time()); |         console.log("sent frontpage ", get_time()); | ||||||
|          }); |          }); | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
| @@ -18,9 +18,6 @@ function update_frontpage(coll, id, title) { | |||||||
|         db.collection("frontpage_lists").update({_id: coll}, {$set: { |         db.collection("frontpage_lists").update({_id: coll}, {$set: { | ||||||
|                 id: id, |                 id: id, | ||||||
|                 title: title, |                 title: title, | ||||||
|                 accessed: Functions.get_time()} |                 accessed: get_time()} | ||||||
|         },{upsert: true}, function(err, returnDocs){}); |         },{upsert: true}, function(err, returnDocs){}); | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports.update_frontpage = update_frontpage; |  | ||||||
| module.exports.frontpage_lists = frontpage_lists; |  | ||||||
|   | |||||||
| @@ -1,147 +1,143 @@ | |||||||
| var Functions = { |  | ||||||
|   remove_unique_id: function(short_id) { |  | ||||||
|   	db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {}); |  | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   remove_name_from_db: function(guid, name) { |  | ||||||
|   	db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: name}}, function(err, updated) { |  | ||||||
|   		db.collection("user_names").remove({"guid": guid}, function(err, removed) {	}); |  | ||||||
|   	}); |  | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   remove_from_array: function(array, element){ |  | ||||||
|   	if(Functions.contains(array, element)){ |  | ||||||
|   		var index = array.indexOf(element); |  | ||||||
|   		if(index != -1) |  | ||||||
|   		array.splice(index, 1); |  | ||||||
|   	} |  | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   get_short_id: function(seed, minlen, socket) { |  | ||||||
| 		var len = minlen; |  | ||||||
| 		var id = Functions.rndName(seed, minlen, socket); |  | ||||||
|  |  | ||||||
| 		db.collection("unique_ids").update({"_id": "unique_ids"}, {$addToSet: {unique_ids: id}}, {upsert: true}, function(err, updated) { |  | ||||||
| 			if(updated.nModified == 1) { |  | ||||||
| 				short_id = id; |  | ||||||
| 				socket.join(short_id); |  | ||||||
| 				socket.emit("id", short_id); |  | ||||||
| 			} else { |  | ||||||
| 				Functions.get_short_id(Functions.rndName(String(len)+id, len + 0.1, socket)); |  | ||||||
| 			} |  | ||||||
| 		}); |  | ||||||
| 	}, |  | ||||||
|  |  | ||||||
|   uniqueID: function(seed, minlen){ |  | ||||||
|   	var len = minlen; |  | ||||||
|   	var id = Functions.rndName(seed, minlen); |  | ||||||
|  |  | ||||||
|   	db.collection("unique_ids").update({"_id": "unique_ids"}, {$addToSet: {unique_ids: id}}, function(err, updated) { |  | ||||||
|   		if(updated.nModified == 1) { |  | ||||||
|   			return id; |  | ||||||
|   		} else { |  | ||||||
|   			return Functions.uniqueID(Functions.rndName(String(len)+id, len + 0.1)); |  | ||||||
|   		} |  | ||||||
|   	}); |  | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   check_inlist: function(coll, guid, socket, offline) |  | ||||||
|   { |  | ||||||
|   	if(!offline && coll != undefined){ |  | ||||||
|   		db.collection("connected_users").update({"_id": coll}, {$addToSet:{users: guid}}, {upsert: true}, function(err, updated) { |  | ||||||
|   			if(updated.nModified > 0) { |  | ||||||
|   				db.collection("connected_users").find({"_id": coll}, function(err, new_doc) { |  | ||||||
|   					db.collection("frontpage_lists").update({"_id": coll}, {$set: {"viewers": new_doc[0].users.length}}, function(){ |  | ||||||
|                         if(new_doc[0].users == undefined || new_doc[0].users.length == undefined) { |  | ||||||
|                             io.to(coll).emit("viewers", 1); |  | ||||||
|                         } else { |  | ||||||
| 		                    io.to(coll).emit("viewers", new_doc[0].users.length); |  | ||||||
|                         } |  | ||||||
|   						db.collection("user_names").find({"guid": guid}, function(err, docs) { |  | ||||||
|   							if(docs.length == 1) { |  | ||||||
|   								socket.broadcast.to(coll).emit('chat', {from: docs[0].name, msg: " joined"}); |  | ||||||
|   							} |  | ||||||
|   						}); |  | ||||||
|  |  | ||||||
|   						db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs){}); |  | ||||||
|   					}); |  | ||||||
|   				}); |  | ||||||
|   			} |  | ||||||
|   		}); |  | ||||||
|  |  | ||||||
|   	} else { |  | ||||||
|   		db.collection("connected_users").update({"_id": coll}, {$addToSet: {users: guid}}, function(err, docs){}); |  | ||||||
|   		db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs) {}); |  | ||||||
|   	} |  | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   rndName: function(seed, len) { |  | ||||||
|   	var vowels = ['a', 'e', 'i', 'o', 'u']; |  | ||||||
|   	consts =  ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y']; |  | ||||||
|   	len = Math.floor(len); |  | ||||||
|   	word = ''; |  | ||||||
|   	is_vowel = false; |  | ||||||
|   	var arr; |  | ||||||
|   	for (var i = 0; i < len; i++) { |  | ||||||
|   		if (is_vowel) arr = vowels; |  | ||||||
|   		else arr = consts; |  | ||||||
|   		is_vowel = !is_vowel; |  | ||||||
|   		word += arr[(seed[i%seed.length].charCodeAt()+i) % (arr.length-1)]; |  | ||||||
|   	} |  | ||||||
|   	return word; |  | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   decrypt_string: function(socket_id, pw){ |  | ||||||
|   	try { |  | ||||||
|   		var input = pw.split("$"); |  | ||||||
|   		pw = input[0]; |  | ||||||
|   		var testKey = ((new Buffer(socket_id).toString('base64')) + (new Buffer(socket_id).toString('base64'))).substring(0,32); |  | ||||||
|   		var keyNew = (new Buffer(testKey)).toString('base64'); |  | ||||||
|   		var encrypted = CryptoJS.enc.Base64.parse(pw); |  | ||||||
|   		var key = CryptoJS.enc.Base64.parse(keyNew); |  | ||||||
|   		var iv = CryptoJS.enc.Base64.parse(input[1]); |  | ||||||
|   		var decrypted = CryptoJS.enc.Utf8.stringify( |  | ||||||
|   			CryptoJS.AES.decrypt({ |  | ||||||
|   				ciphertext: encrypted |  | ||||||
|   			}, |  | ||||||
|       	key, |  | ||||||
|        // edit: changed to Pkcs5 |  | ||||||
|       	{ |  | ||||||
|   				mode: CryptoJS.mode.CBC, |  | ||||||
|   				padding: CryptoJS.pad.Pkcs7, |  | ||||||
|   				iv: iv, |  | ||||||
|   			})); |  | ||||||
|   			return decrypted; |  | ||||||
|   	} catch(e) { |  | ||||||
|   		return ""; |  | ||||||
|   	} |  | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   get_time: function() |  | ||||||
|   { |  | ||||||
|   	var d = new Date(); |  | ||||||
|   	var time = Math.floor(d.getTime() / 1000); |  | ||||||
|   	return time; |  | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   contains: function(a, obj) { |  | ||||||
|   	try{ |  | ||||||
|   		var i = a.length; |  | ||||||
|   		while (i--) { |  | ||||||
|   			if (a[i] === obj) { |  | ||||||
|   				return true; |  | ||||||
|   			} |  | ||||||
|   		} |  | ||||||
|   		return false; |  | ||||||
|   	}catch(e){ |  | ||||||
|   		return false; |  | ||||||
|   	} |  | ||||||
|   }, |  | ||||||
|  |  | ||||||
|   hash_pass: function(adminpass) { |  | ||||||
|   	return crypto.createHash('sha256').update(adminpass).digest('base64'); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|  | function remove_unique_id(short_id) { | ||||||
|  | 	db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {}); | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = Functions; | function remove_name_from_db(guid, name) { | ||||||
|  | 	db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: name}}, function(err, updated) { | ||||||
|  | 		db.collection("user_names").remove({"guid": guid}, function(err, removed) {	}); | ||||||
|  | 	}); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function remove_from_array(array, element){ | ||||||
|  | 	if(contains(array, element)){ | ||||||
|  | 		var index = array.indexOf(element); | ||||||
|  | 		if(index != -1) | ||||||
|  | 		array.splice(index, 1); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function get_short_id(seed, minlen, socket) { | ||||||
|  | 	var len = minlen; | ||||||
|  | 	var id = rndName(seed, minlen, socket); | ||||||
|  |  | ||||||
|  | 	db.collection("unique_ids").update({"_id": "unique_ids"}, {$addToSet: {unique_ids: id}}, {upsert: true}, function(err, updated) { | ||||||
|  | 		if(updated.nModified == 1) { | ||||||
|  | 			short_id = id; | ||||||
|  | 			socket.join(short_id); | ||||||
|  | 			socket.emit("id", short_id); | ||||||
|  | 		} else { | ||||||
|  | 			get_short_id(rndName(String(len)+id, len + 0.1, socket)); | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function uniqueID(seed, minlen){ | ||||||
|  | 	var len = minlen; | ||||||
|  | 	var id = rndName(seed, minlen); | ||||||
|  |  | ||||||
|  | 	db.collection("unique_ids").update({"_id": "unique_ids"}, {$addToSet: {unique_ids: id}}, function(err, updated) { | ||||||
|  | 		if(updated.nModified == 1) { | ||||||
|  | 			return id; | ||||||
|  | 		} else { | ||||||
|  | 			return uniqueID(rndName(String(len)+id, len + 0.1)); | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function check_inlist(coll, guid, socket, offline) | ||||||
|  | { | ||||||
|  | 	if(!offline && coll != undefined){ | ||||||
|  | 		db.collection("connected_users").update({"_id": coll}, {$addToSet:{users: guid}}, {upsert: true}, function(err, updated) { | ||||||
|  | 			if(updated.nModified > 0) { | ||||||
|  | 				db.collection("connected_users").find({"_id": coll}, function(err, new_doc) { | ||||||
|  | 					db.collection("frontpage_lists").update({"_id": coll}, {$set: {"viewers": new_doc[0].users.length}}, function(){ | ||||||
|  |                       if(new_doc[0].users == undefined || new_doc[0].users.length == undefined) { | ||||||
|  |                           io.to(coll).emit("viewers", 1); | ||||||
|  |                       } else { | ||||||
|  | 	                    io.to(coll).emit("viewers", new_doc[0].users.length); | ||||||
|  |                       } | ||||||
|  | 						db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||||
|  | 							if(docs.length == 1) { | ||||||
|  | 								socket.broadcast.to(coll).emit('chat', {from: docs[0].name, msg: " joined"}); | ||||||
|  | 							} | ||||||
|  | 						}); | ||||||
|  |  | ||||||
|  | 						db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs){}); | ||||||
|  | 					}); | ||||||
|  | 				}); | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 	} else { | ||||||
|  | 		db.collection("connected_users").update({"_id": coll}, {$addToSet: {users: guid}}, function(err, docs){}); | ||||||
|  | 		db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs) {}); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function rndName(seed, len) { | ||||||
|  | 	var vowels = ['a', 'e', 'i', 'o', 'u']; | ||||||
|  | 	consts =  ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y']; | ||||||
|  | 	len = Math.floor(len); | ||||||
|  | 	word = ''; | ||||||
|  | 	is_vowel = false; | ||||||
|  | 	var arr; | ||||||
|  | 	for (var i = 0; i < len; i++) { | ||||||
|  | 		if (is_vowel) arr = vowels; | ||||||
|  | 		else arr = consts; | ||||||
|  | 		is_vowel = !is_vowel; | ||||||
|  | 		word += arr[(seed[i%seed.length].charCodeAt()+i) % (arr.length-1)]; | ||||||
|  | 	} | ||||||
|  | 	return word; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function decrypt_string(socket_id, pw){ | ||||||
|  | 	try { | ||||||
|  | 		var input = pw.split("$"); | ||||||
|  | 		pw = input[0]; | ||||||
|  | 		var testKey = ((new Buffer(socket_id).toString('base64')) + (new Buffer(socket_id).toString('base64'))).substring(0,32); | ||||||
|  | 		var keyNew = (new Buffer(testKey)).toString('base64'); | ||||||
|  | 		var encrypted = CryptoJS.enc.Base64.parse(pw); | ||||||
|  | 		var key = CryptoJS.enc.Base64.parse(keyNew); | ||||||
|  | 		var iv = CryptoJS.enc.Base64.parse(input[1]); | ||||||
|  | 		var decrypted = CryptoJS.enc.Utf8.stringify( | ||||||
|  | 			CryptoJS.AES.decrypt({ | ||||||
|  | 				ciphertext: encrypted | ||||||
|  | 			}, | ||||||
|  |     	key, | ||||||
|  |      // edit: changed to Pkcs5 | ||||||
|  |     	{ | ||||||
|  | 				mode: CryptoJS.mode.CBC, | ||||||
|  | 				padding: CryptoJS.pad.Pkcs7, | ||||||
|  | 				iv: iv, | ||||||
|  | 			})); | ||||||
|  | 			return decrypted; | ||||||
|  | 	} catch(e) { | ||||||
|  | 		return ""; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function get_time() | ||||||
|  | { | ||||||
|  | 	var d = new Date(); | ||||||
|  | 	var time = Math.floor(d.getTime() / 1000); | ||||||
|  | 	return time; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function contains(a, obj) { | ||||||
|  | 	try{ | ||||||
|  | 		var i = a.length; | ||||||
|  | 		while (i--) { | ||||||
|  | 			if (a[i] === obj) { | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		return false; | ||||||
|  | 	}catch(e){ | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function hash_pass(adminpass) { | ||||||
|  | 	return crypto.createHash('sha256').update(adminpass).digest('base64'); | ||||||
|  | } | ||||||
|   | |||||||
| @@ -1,388 +1,386 @@ | |||||||
| module.exports = function() { | io.on('connection', function(socket){ | ||||||
| 	io.on('connection', function(socket){ | 	socket.zoff_id = socket.id; | ||||||
| 		socket.zoff_id = socket.id; | 	socket.emit("get_list"); | ||||||
| 		socket.emit("get_list"); |  | ||||||
|  |  | ||||||
| 		var guid = Functions.hash_pass(socket.handshake.headers["user-agent"] + socket.handshake.address + socket.handshake.headers["accept-language"]); | 	var guid = hash_pass(socket.handshake.headers["user-agent"] + socket.handshake.address + socket.handshake.headers["accept-language"]); | ||||||
|  |  | ||||||
| 		socket.on('close', function() { | 	socket.on('close', function() { | ||||||
| 			console.log("closing socket"); | 		console.log("closing socket"); | ||||||
| 		}); | 	}); | ||||||
|  |  | ||||||
| 		socket.on('pinging', function() { | 	socket.on('pinging', function() { | ||||||
| 			socket.emit("ok"); | 		socket.emit("ok"); | ||||||
| 		}); | 	}); | ||||||
|  |  | ||||||
| 		var ping_timeout; | 	var ping_timeout; | ||||||
| 		var socketid = socket.zoff_id; | 	var socketid = socket.zoff_id; | ||||||
| 		var coll; | 	var coll; | ||||||
| 		var in_list = false; | 	var in_list = false; | ||||||
|         var name = ""; |     var name = ""; | ||||||
| 		var short_id; | 	var short_id; | ||||||
| 		Chat.get_name(guid, {announce: false}); | 	get_name(guid, {announce: false}); | ||||||
| 		Functions.get_short_id(socketid, 4, socket); | 	get_short_id(socketid, 4, socket); | ||||||
| 		var offline = false; | 	var offline = false; | ||||||
| 		var chromecast_object = false; | 	var chromecast_object = false; | ||||||
|  |  | ||||||
| 		socket.emit("guid", guid); | 	socket.emit("guid", guid); | ||||||
|  |  | ||||||
| 		socket.on('self_ping', function(msg) { | 	socket.on('self_ping', function(msg) { | ||||||
| 			var channel = msg.channel; | 		var channel = msg.channel; | ||||||
| 			if(offline) { | 		if(offline) { | ||||||
| 				db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){}); | 			db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){}); | ||||||
| 			} else { | 		} else { | ||||||
| 				db.collection("connected_users").update({"_id": channel}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){ | 			db.collection("connected_users").update({"_id": channel}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){ | ||||||
| 					db.collection("frontpage_lists").update({"_id": channel}, {$inc: {viewers: 1}}, {upsert: true}, function(){}); | 				db.collection("frontpage_lists").update({"_id": channel}, {$inc: {viewers: 1}}, {upsert: true}, function(){}); | ||||||
| 				}); | 			}); | ||||||
| 			} | 		} | ||||||
| 			/*if(name != "") { | 		/*if(name != "") { | ||||||
| 				db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, {upsert: true}, function(err, updated) { | 			db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, {upsert: true}, function(err, updated) { | ||||||
| 					if(updated.nModified == 1) { | 				if(updated.nModified == 1) { | ||||||
| 						db.collection("user_names").update({"guid": guid}, {$set: {name: name}}, {upsert:true}, function(err, update){}); | 					db.collection("user_names").update({"guid": guid}, {$set: {name: name}}, {upsert:true}, function(err, update){}); | ||||||
|  | 				} | ||||||
|  | 			}); | ||||||
|  | 		}*/ | ||||||
|  | 		db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, {upsert: true}, function(err, docs){}); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('chromecast', function(msg) { | ||||||
|  | 		try { | ||||||
|  | 			if(typeof(msg) == "object" && msg.hasOwnProperty("guid") && msg.hasOwnProperty("socket_id") && msg.hasOwnProperty("channel")) { | ||||||
|  | 				db.collection("connected_users").find({"_id": msg.channel}, function(err, connected_users_channel) { | ||||||
|  | 					if(connected_users_channel.length > 0 && connected_users_channel[0].users.indexOf(msg.guid) > -1) { | ||||||
|  | 						guid = msg.guid; | ||||||
|  | 						socketid = msg.socket_id; | ||||||
|  | 						socket.zoff_id = socketid; | ||||||
|  | 						coll = msg.channel; | ||||||
|  | 						in_list = true; | ||||||
|  | 						chromecast_object = true; | ||||||
|  | 						socket.join(coll); | ||||||
| 					} | 					} | ||||||
| 				}); | 				}); | ||||||
| 			}*/ |  | ||||||
| 			db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, {upsert: true}, function(err, docs){}); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('chromecast', function(msg) { |  | ||||||
| 			try { |  | ||||||
| 				if(typeof(msg) == "object" && msg.hasOwnProperty("guid") && msg.hasOwnProperty("socket_id") && msg.hasOwnProperty("channel")) { |  | ||||||
| 					db.collection("connected_users").find({"_id": msg.channel}, function(err, connected_users_channel) { |  | ||||||
| 						if(connected_users_channel.length > 0 && connected_users_channel[0].users.indexOf(msg.guid) > -1) { |  | ||||||
| 							guid = msg.guid; |  | ||||||
| 							socketid = msg.socket_id; |  | ||||||
| 							socket.zoff_id = socketid; |  | ||||||
| 							coll = msg.channel; |  | ||||||
| 							in_list = true; |  | ||||||
| 							chromecast_object = true; |  | ||||||
| 							socket.join(coll); |  | ||||||
| 						} |  | ||||||
| 					}); |  | ||||||
| 				} |  | ||||||
| 			} catch(e) { |  | ||||||
| 				return; |  | ||||||
| 			} | 			} | ||||||
| 		}); | 		} catch(e) { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  |  | ||||||
| 		socket.on("get_spread", function(){ | 	socket.on("get_spread", function(){ | ||||||
| 			db.collection("connected_users").find({"_id": "total_users"}, function(err, tot) { | 		db.collection("connected_users").find({"_id": "total_users"}, function(err, tot) { | ||||||
|                 db.collection("connected_users").find({"_id": "offline_users"}, function(err, off) { |             db.collection("connected_users").find({"_id": "offline_users"}, function(err, off) { | ||||||
| 					db.collection("connected_users").find({"_id": {$ne: "total_users"}, "_id": {$ne: "offline_users"}}, function(err, users_list) { | 				db.collection("connected_users").find({"_id": {$ne: "total_users"}, "_id": {$ne: "offline_users"}}, function(err, users_list) { | ||||||
| 	                    if(tot.length > 0 && off.length == 0) { |                     if(tot.length > 0 && off.length == 0) { | ||||||
| 	                        socket.emit("spread_listeners", {offline: 0, total: tot[0].total_users, online_users: users_list}); |                         socket.emit("spread_listeners", {offline: 0, total: tot[0].total_users, online_users: users_list}); | ||||||
| 	                    } else if(tot.length > 0 && off.length > 0){ |                     } else if(tot.length > 0 && off.length > 0){ | ||||||
| 							socket.emit("spread_listeners", {offline: off[0].users.length, total: tot[0].total_users, online_users: users_list}); | 						socket.emit("spread_listeners", {offline: off[0].users.length, total: tot[0].total_users, online_users: users_list}); | ||||||
| 						} | 					} | ||||||
| 					}); |  | ||||||
|                 }); |  | ||||||
| 			}); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('suggest_thumbnail', function(msg){ |  | ||||||
| 			Suggestions.thumbnail(msg, coll, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('suggest_description', function(msg){ |  | ||||||
| 			Suggestions.description(msg, coll, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on("offline", function(msg){ |  | ||||||
| 			if(!msg.hasOwnProperty('status') && !msg.hasOwnProperty('channel')) { |  | ||||||
| 				socket.emit("update_required"); |  | ||||||
| 				return; |  | ||||||
| 			} |  | ||||||
| 			var status = msg.status; |  | ||||||
| 			var channel = msg.channel; |  | ||||||
| 			if(status){ |  | ||||||
| 				in_list = false; |  | ||||||
| 				offline = true; |  | ||||||
| 				if(channel != "") coll = channel; |  | ||||||
| 				if(coll !== undefined) { |  | ||||||
| 					db.collection("connected_users").findAndModify({ |  | ||||||
| 						query: {"_id": coll}, |  | ||||||
| 						update: {$pull: {users: guid}}, |  | ||||||
| 						upsert: true, |  | ||||||
| 					}, function(err, updated) { |  | ||||||
| 						if(updated.nModified > 0) { |  | ||||||
| 							io.to(coll).emit("viewers", updated.users); |  | ||||||
| 							db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, docs){}); |  | ||||||
| 						} |  | ||||||
| 						Functions.remove_name_from_db(guid, name); |  | ||||||
| 					}); |  | ||||||
| 				} |  | ||||||
|  |  | ||||||
| 				Functions.remove_unique_id(short_id); |  | ||||||
|  |  | ||||||
| 				db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, function(err, docs) {}); |  | ||||||
| 				db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs) {}); |  | ||||||
| 			} else { |  | ||||||
| 				offline = false; |  | ||||||
| 				db.collection("connected_users").update({"_id": "offline_users"}, {$pull: {users: guid}}, function(err, docs) { |  | ||||||
| 					Functions.check_inlist(coll, guid, socket, offline); |  | ||||||
| 				}); | 				}); | ||||||
| 			} |             }); | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		/*socket.on('namechange', function(msg) |  | ||||||
| 		{ |  | ||||||
|             if(coll == undefined) { |  | ||||||
|                 coll = msg.channel; |  | ||||||
|             } |  | ||||||
| 			Chat.namechange(msg.name, guid, coll, function(new_name) { |  | ||||||
| 				name = new_name; |  | ||||||
| 			}); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('removename', function() |  | ||||||
| 		{ |  | ||||||
| 			Chat.removename(guid, coll); |  | ||||||
| 			name = ""; |  | ||||||
| 		});*/ |  | ||||||
|  |  | ||||||
| 		socket.on('chat', function (msg) { |  | ||||||
| 			Chat.chat(msg, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on("all,chat", function(data) |  | ||||||
| 		{ |  | ||||||
| 			Chat.all_chat(data, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('frontpage_lists', function(msg) |  | ||||||
| 		{ |  | ||||||
|             console.log("First gotten", Functions.get_time()); |  | ||||||
| 			/*Frontpage.frontpage_lists(msg, socket);*/ |  | ||||||
| 			if(!msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) { |  | ||||||
| 			    socket.emit("update_required"); |  | ||||||
| 			  } |  | ||||||
|  |  | ||||||
| 			console.log("gotten second ", Functions.get_time()); |  | ||||||
| 			  db.collection("frontpage_lists").find({frontpage:true}, function(err, docs){ |  | ||||||
| 			    console.log("gotten third ", Functions.get_time()); |  | ||||||
| 			        db.collection("connected_users").find({"_id": "total_users"}, function(err, tot){ |  | ||||||
| 			        console.log("sending frontpage ", Functions.get_time()); |  | ||||||
| 			        socket.compress(true).emit("playlists", {channels: docs, viewers: tot[0].total_users}); |  | ||||||
| 			        console.log("sent frontpage ", Functions.get_time()); |  | ||||||
| 			         }); |  | ||||||
| 			  }); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('now_playing', function(list, fn) |  | ||||||
| 		{ |  | ||||||
| 			List.now_playing(list, fn, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('id', function(arr) |  | ||||||
| 		{ |  | ||||||
| 			if(typeof(arr) == 'object') |  | ||||||
| 			io.to(arr.id).emit(arr.id, {type: arr.type, value: arr.value}); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('list', function(msg) |  | ||||||
| 		{ |  | ||||||
| 			try { |  | ||||||
| 	      var list = msg.channel; |  | ||||||
| 	      if(list.length == 0) return; |  | ||||||
| 	      coll = emojiStrip(list).toLowerCase(); |  | ||||||
| 	      coll = coll.replace("_", ""); |  | ||||||
| 	      coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
| 	      coll = filter.clean(coll); |  | ||||||
| 	    } catch(e) { |  | ||||||
| 	      return; |  | ||||||
| 	    } |  | ||||||
| 			List.list(msg, guid, coll, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('end', function(obj) |  | ||||||
| 		{ |  | ||||||
| 			if(coll === undefined) { |  | ||||||
| 	      try { |  | ||||||
| 	        coll = obj.channel; |  | ||||||
| 	        if(coll.length == 0) return; |  | ||||||
| 	        coll = emojiStrip(coll).toLowerCase(); |  | ||||||
| 	        coll = coll.replace("_", ""); |  | ||||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
| 	        coll = filter.clean(coll); |  | ||||||
| 	      } catch(e) { |  | ||||||
| 	        return; |  | ||||||
| 	      } |  | ||||||
| 	    } |  | ||||||
| 			List.end(obj, coll, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('add', function(arr) |  | ||||||
| 		{ |  | ||||||
| 			if(coll !== undefined) { |  | ||||||
| 	      try { |  | ||||||
| 	        coll = arr.list; |  | ||||||
| 	        if(coll.length == 0) return; |  | ||||||
| 	        coll = emojiStrip(coll).toLowerCase(); |  | ||||||
| 	        coll = coll.replace("_", ""); |  | ||||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
| 	        coll = filter.clean(coll); |  | ||||||
| 	      } catch(e) { |  | ||||||
| 	        return; |  | ||||||
| 	      } |  | ||||||
| 	    } |  | ||||||
| 			ListChange.add(arr, coll, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('delete_all', function(msg) { |  | ||||||
| 			if(coll !== undefined) { |  | ||||||
| 				try { |  | ||||||
| 					coll = msg.channel; |  | ||||||
| 					if(coll.length == 0) return; |  | ||||||
| 					coll = emojiStrip(coll).toLowerCase(); |  | ||||||
| 					coll = coll.replace("_", ""); |  | ||||||
| 					coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
| 					coll = filter.clean(coll); |  | ||||||
| 				} catch(e) { |  | ||||||
| 					return; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			ListChange.delete_all(msg, coll, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('vote', function(msg) |  | ||||||
| 		{ |  | ||||||
| 			if(coll !== undefined) { |  | ||||||
| 	      try { |  | ||||||
| 	        coll = msg.channel; |  | ||||||
| 	        if(coll.length == 0) return; |  | ||||||
| 	        coll = emojiStrip(coll).toLowerCase(); |  | ||||||
| 	        coll = coll.replace("_", ""); |  | ||||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
| 	        coll = filter.clean(coll); |  | ||||||
| 	      } catch(e) { |  | ||||||
| 	        return; |  | ||||||
| 	      } |  | ||||||
| 	    } |  | ||||||
| 			ListChange.voteUndecided(msg, coll, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('password', function(inp) |  | ||||||
| 		{ |  | ||||||
| 			ListSettings.password(inp, coll, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('skip', function(list) |  | ||||||
| 		{ |  | ||||||
| 			if(coll !== undefined) { |  | ||||||
| 	      try { |  | ||||||
| 	        coll = list.channel; |  | ||||||
| 	        if(coll.length == 0) return; |  | ||||||
| 	        coll = emojiStrip(coll).toLowerCase(); |  | ||||||
| 	        coll = coll.replace("_", ""); |  | ||||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
| 	        coll = filter.clean(coll); |  | ||||||
| 	      } catch(e) { |  | ||||||
| 	        return; |  | ||||||
| 	      } |  | ||||||
| 	    } |  | ||||||
| 			List.skip(list, guid, coll, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('conf', function(params) |  | ||||||
| 		{ |  | ||||||
| 			ListSettings.conf(params, coll, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('shuffle', function(msg) |  | ||||||
| 		{ |  | ||||||
| 			if(coll !== undefined) { |  | ||||||
| 	      try { |  | ||||||
| 	        coll = msg.channel; |  | ||||||
| 	        if(coll.length == 0) return; |  | ||||||
| 	        coll = emojiStrip(coll).toLowerCase(); |  | ||||||
| 	        coll = coll.replace("_", ""); |  | ||||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
| 	        coll = filter.clean(coll); |  | ||||||
| 	      } catch(e) { |  | ||||||
| 	        return; |  | ||||||
| 	      } |  | ||||||
| 	    } |  | ||||||
| 			ListChange.shuffle(msg, coll, guid, offline, socket); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('change_channel', function(obj) |  | ||||||
| 		{ |  | ||||||
| 			if(coll === undefined && obj !== undefined && obj.channel !== undefined){ |  | ||||||
| 				try { |  | ||||||
| 					coll = obj.channel; |  | ||||||
| 					if(coll.length == 0) return; |  | ||||||
| 					coll = emojiStrip(coll).toLowerCase(); |  | ||||||
| 					coll = coll.replace("_", ""); |  | ||||||
| 					coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
| 					coll = filter.clean(coll); |  | ||||||
| 				} catch(e) { |  | ||||||
| 					return; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, true); |  | ||||||
| 			in_list = false; |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('disconnect', function() |  | ||||||
| 		{ |  | ||||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('disconnected', function() |  | ||||||
| 		{ |  | ||||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('reconnect_failed', function() |  | ||||||
| 		{ |  | ||||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('connect_timeout', function() |  | ||||||
| 		{ |  | ||||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('error', function() |  | ||||||
| 		{ |  | ||||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		socket.on('pos', function(obj) |  | ||||||
| 		{ |  | ||||||
|  |  | ||||||
| 			if(coll !== undefined) { |  | ||||||
| 				try { |  | ||||||
| 					coll = obj.channel; |  | ||||||
| 					if(coll.length == 0) return; |  | ||||||
| 					coll = emojiStrip(coll).toLowerCase(); |  | ||||||
| 					coll = coll.replace("_", ""); |  | ||||||
| 					coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
| 					coll = filter.clean(coll); |  | ||||||
| 				} catch(e) { |  | ||||||
| 					return; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			if(coll == "" || coll == undefined || coll == null) { |  | ||||||
| 				socket.emit("update_required"); |  | ||||||
| 				return; |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			db.collection(coll).find({views: {$exists: true}}, function(err, docs) { |  | ||||||
| 				if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, obj.pass)))) { |  | ||||||
| 					Functions.check_inlist(coll, guid, socket, offline); |  | ||||||
| 					List.send_play(coll, socket); |  | ||||||
| 				} else { |  | ||||||
| 					socket.emit("auth_required"); |  | ||||||
| 				} |  | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
|     //send_ping(); | 	socket.on('suggest_thumbnail', function(msg){ | ||||||
| } | 		thumbnail(msg, coll, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('suggest_description', function(msg){ | ||||||
|  | 		description(msg, coll, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on("offline", function(msg){ | ||||||
|  | 		if(!msg.hasOwnProperty('status') && !msg.hasOwnProperty('channel')) { | ||||||
|  | 			socket.emit("update_required"); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 		var status = msg.status; | ||||||
|  | 		var channel = msg.channel; | ||||||
|  | 		if(status){ | ||||||
|  | 			in_list = false; | ||||||
|  | 			offline = true; | ||||||
|  | 			if(channel != "") coll = channel; | ||||||
|  | 			if(coll !== undefined) { | ||||||
|  | 				db.collection("connected_users").findAndModify({ | ||||||
|  | 					query: {"_id": coll}, | ||||||
|  | 					update: {$pull: {users: guid}}, | ||||||
|  | 					upsert: true, | ||||||
|  | 				}, function(err, updated) { | ||||||
|  | 					if(updated.nModified > 0) { | ||||||
|  | 						io.to(coll).emit("viewers", updated.users); | ||||||
|  | 						db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, docs){}); | ||||||
|  | 					} | ||||||
|  | 					remove_name_from_db(guid, name); | ||||||
|  | 				}); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			remove_unique_id(short_id); | ||||||
|  |  | ||||||
|  | 			db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, function(err, docs) {}); | ||||||
|  | 			db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs) {}); | ||||||
|  | 		} else { | ||||||
|  | 			offline = false; | ||||||
|  | 			db.collection("connected_users").update({"_id": "offline_users"}, {$pull: {users: guid}}, function(err, docs) { | ||||||
|  | 				check_inlist(coll, guid, socket, offline); | ||||||
|  | 			}); | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	/*socket.on('namechange', function(msg) | ||||||
|  | 	{ | ||||||
|  |         if(coll == undefined) { | ||||||
|  |             coll = msg.channel; | ||||||
|  |         } | ||||||
|  | 		namechange(msg.name, guid, coll, function(new_name) { | ||||||
|  | 			name = new_name; | ||||||
|  | 		}); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('removename', function() | ||||||
|  | 	{ | ||||||
|  | 		removename(guid, coll); | ||||||
|  | 		name = ""; | ||||||
|  | 	});*/ | ||||||
|  |  | ||||||
|  | 	socket.on('chat', function (msg) { | ||||||
|  | 		chat(msg, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on("all,chat", function(data) | ||||||
|  | 	{ | ||||||
|  | 		all_chat(data, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('frontpage_lists', function(msg) | ||||||
|  | 	{ | ||||||
|  |         console.log("First gotten", get_time()); | ||||||
|  | 		/*Frontpage.frontpage_lists(msg, socket);*/ | ||||||
|  | 		if(!msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) { | ||||||
|  | 		    socket.emit("update_required"); | ||||||
|  | 		  } | ||||||
|  |  | ||||||
|  | 		console.log("gotten second ", get_time()); | ||||||
|  | 		  db.collection("frontpage_lists").find({frontpage:true}, function(err, docs){ | ||||||
|  | 		    console.log("gotten third ", get_time()); | ||||||
|  | 		        db.collection("connected_users").find({"_id": "total_users"}, function(err, tot){ | ||||||
|  | 		        console.log("sending frontpage ", get_time()); | ||||||
|  | 		        socket.compress(true).emit("playlists", {channels: docs, viewers: tot[0].total_users}); | ||||||
|  | 		        console.log("sent frontpage ", get_time()); | ||||||
|  | 		         }); | ||||||
|  | 		  }); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('now_playing', function(list, fn) | ||||||
|  | 	{ | ||||||
|  | 		now_playing(list, fn, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('id', function(arr) | ||||||
|  | 	{ | ||||||
|  | 		if(typeof(arr) == 'object') | ||||||
|  | 		io.to(arr.id).emit(arr.id, {type: arr.type, value: arr.value}); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('list', function(msg) | ||||||
|  | 	{ | ||||||
|  | 		try { | ||||||
|  |       var list = msg.channel; | ||||||
|  |       if(list.length == 0) return; | ||||||
|  |       coll = emojiStrip(list).toLowerCase(); | ||||||
|  |       coll = coll.replace("_", ""); | ||||||
|  |       coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  |       coll = filter.clean(coll); | ||||||
|  |     } catch(e) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  | 		list(msg, guid, coll, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('end', function(obj) | ||||||
|  | 	{ | ||||||
|  | 		if(coll === undefined) { | ||||||
|  |       try { | ||||||
|  |         coll = obj.channel; | ||||||
|  |         if(coll.length == 0) return; | ||||||
|  |         coll = emojiStrip(coll).toLowerCase(); | ||||||
|  |         coll = coll.replace("_", ""); | ||||||
|  |         coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  |         coll = filter.clean(coll); | ||||||
|  |       } catch(e) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 		end(obj, coll, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('add', function(arr) | ||||||
|  | 	{ | ||||||
|  | 		if(coll !== undefined) { | ||||||
|  |       try { | ||||||
|  |         coll = arr.list; | ||||||
|  |         if(coll.length == 0) return; | ||||||
|  |         coll = emojiStrip(coll).toLowerCase(); | ||||||
|  |         coll = coll.replace("_", ""); | ||||||
|  |         coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  |         coll = filter.clean(coll); | ||||||
|  |       } catch(e) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 		add(arr, coll, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('delete_all', function(msg) { | ||||||
|  | 		if(coll !== undefined) { | ||||||
|  | 			try { | ||||||
|  | 				coll = msg.channel; | ||||||
|  | 				if(coll.length == 0) return; | ||||||
|  | 				coll = emojiStrip(coll).toLowerCase(); | ||||||
|  | 				coll = coll.replace("_", ""); | ||||||
|  | 				coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  | 				coll = filter.clean(coll); | ||||||
|  | 			} catch(e) { | ||||||
|  | 				return; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		delete_all(msg, coll, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('vote', function(msg) | ||||||
|  | 	{ | ||||||
|  | 		if(coll !== undefined) { | ||||||
|  |       try { | ||||||
|  |         coll = msg.channel; | ||||||
|  |         if(coll.length == 0) return; | ||||||
|  |         coll = emojiStrip(coll).toLowerCase(); | ||||||
|  |         coll = coll.replace("_", ""); | ||||||
|  |         coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  |         coll = filter.clean(coll); | ||||||
|  |       } catch(e) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 		voteUndecided(msg, coll, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('password', function(inp) | ||||||
|  | 	{ | ||||||
|  | 		password(inp, coll, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('skip', function(list) | ||||||
|  | 	{ | ||||||
|  | 		if(coll !== undefined) { | ||||||
|  |       try { | ||||||
|  |         coll = list.channel; | ||||||
|  |         if(coll.length == 0) return; | ||||||
|  |         coll = emojiStrip(coll).toLowerCase(); | ||||||
|  |         coll = coll.replace("_", ""); | ||||||
|  |         coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  |         coll = filter.clean(coll); | ||||||
|  |       } catch(e) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 		skip(list, guid, coll, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('conf', function(params) | ||||||
|  | 	{ | ||||||
|  | 		conf(params, coll, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('shuffle', function(msg) | ||||||
|  | 	{ | ||||||
|  | 		if(coll !== undefined) { | ||||||
|  |       try { | ||||||
|  |         coll = msg.channel; | ||||||
|  |         if(coll.length == 0) return; | ||||||
|  |         coll = emojiStrip(coll).toLowerCase(); | ||||||
|  |         coll = coll.replace("_", ""); | ||||||
|  |         coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  |         coll = filter.clean(coll); | ||||||
|  |       } catch(e) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 		shuffle(msg, coll, guid, offline, socket); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('change_channel', function(obj) | ||||||
|  | 	{ | ||||||
|  | 		if(coll === undefined && obj !== undefined && obj.channel !== undefined){ | ||||||
|  | 			try { | ||||||
|  | 				coll = obj.channel; | ||||||
|  | 				if(coll.length == 0) return; | ||||||
|  | 				coll = emojiStrip(coll).toLowerCase(); | ||||||
|  | 				coll = coll.replace("_", ""); | ||||||
|  | 				coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  | 				coll = filter.clean(coll); | ||||||
|  | 			} catch(e) { | ||||||
|  | 				return; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		left_channel(coll, guid, short_id, in_list, socket, true); | ||||||
|  | 		in_list = false; | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('disconnect', function() | ||||||
|  | 	{ | ||||||
|  | 		left_channel(coll, guid, short_id, in_list, socket, false); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('disconnected', function() | ||||||
|  | 	{ | ||||||
|  | 		left_channel(coll, guid, short_id, in_list, socket, false); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('reconnect_failed', function() | ||||||
|  | 	{ | ||||||
|  | 		left_channel(coll, guid, short_id, in_list, socket, false); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('connect_timeout', function() | ||||||
|  | 	{ | ||||||
|  | 		left_channel(coll, guid, short_id, in_list, socket, false); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('error', function() | ||||||
|  | 	{ | ||||||
|  | 		left_channel(coll, guid, short_id, in_list, socket, false); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	socket.on('pos', function(obj) | ||||||
|  | 	{ | ||||||
|  |  | ||||||
|  | 		if(coll !== undefined) { | ||||||
|  | 			try { | ||||||
|  | 				coll = obj.channel; | ||||||
|  | 				if(coll.length == 0) return; | ||||||
|  | 				coll = emojiStrip(coll).toLowerCase(); | ||||||
|  | 				coll = coll.replace("_", ""); | ||||||
|  | 				coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  | 				coll = filter.clean(coll); | ||||||
|  | 			} catch(e) { | ||||||
|  | 				return; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		if(coll == "" || coll == undefined || coll == null) { | ||||||
|  | 			socket.emit("update_required"); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		db.collection(coll).find({views: {$exists: true}}, function(err, docs) { | ||||||
|  | 			if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, obj.pass)))) { | ||||||
|  | 				check_inlist(coll, guid, socket, offline); | ||||||
|  | 				send_play(coll, socket); | ||||||
|  | 			} else { | ||||||
|  | 				socket.emit("auth_required"); | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  | 	}); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | send_ping(); | ||||||
|  |  | ||||||
| function send_ping() { | function send_ping() { | ||||||
| 	db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true}, function(err, docs){ | 	db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true}, function(err, docs){ | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ var list = function(msg, guid, coll, offline, socket) { | |||||||
|       socket.emit("update_required"); |       socket.emit("update_required"); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     var pass = Functions.decrypt_string(socketid, msg.pass); |     var pass = decrypt_string(socketid, msg.pass); | ||||||
|     db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){ |     db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){ | ||||||
|       if(frontpage_lists.length == 1) |       if(frontpage_lists.length == 1) | ||||||
|       { |       { | ||||||
| @@ -39,7 +39,7 @@ var list = function(msg, guid, coll, offline, socket) { | |||||||
|             } |             } | ||||||
|             in_list = true; |             in_list = true; | ||||||
|             socket.join(coll); |             socket.join(coll); | ||||||
|             Functions.check_inlist(coll, guid, socket, offline); |             check_inlist(coll, guid, socket, offline); | ||||||
|  |  | ||||||
|             if(frontpage_lists.viewers != undefined){ |             if(frontpage_lists.viewers != undefined){ | ||||||
|               io.to(coll).emit("viewers", frontpage_lists.viewers); |               io.to(coll).emit("viewers", frontpage_lists.viewers); | ||||||
| @@ -55,9 +55,9 @@ var list = function(msg, guid, coll, offline, socket) { | |||||||
|         }); |         }); | ||||||
|       } else{ |       } else{ | ||||||
|         db.createCollection(coll, function(err, docs){ |         db.createCollection(coll, function(err, docs){ | ||||||
|           db.collection(coll).insert({"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": ""}, function(err, docs){ |           db.collection(coll).insert({"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":get_time(), "views": [], "vote": false, "desc": ""}, function(err, docs){ | ||||||
|             send_list(coll, socket, true, false, true); |             send_list(coll, socket, true, false, true); | ||||||
|             db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time()}); |             db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": get_time()}); | ||||||
|           }); |           }); | ||||||
|         }); |         }); | ||||||
|       } |       } | ||||||
| @@ -80,7 +80,7 @@ var skip = function(list, guid, coll, offline, socket) { | |||||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ |     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == decrypt_string(socketid, list.userpass)))) { |       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == decrypt_string(socketid, list.userpass)))) { | ||||||
|  |  | ||||||
|         Functions.check_inlist(coll, guid, socket, offline); |         check_inlist(coll, guid, socket, offline); | ||||||
|  |  | ||||||
|         adminpass = ""; |         adminpass = ""; | ||||||
|         video_id  = list.id; |         video_id  = list.id; | ||||||
| @@ -95,7 +95,7 @@ var skip = function(list, guid, coll, offline, socket) { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         if(adminpass !== undefined && adminpass !== null && adminpass !== "") |         if(adminpass !== undefined && adminpass !== null && adminpass !== "") | ||||||
|         hash = Functions.hash_pass(Functions.decrypt_string(socketid, adminpass)); |         hash = hash_pass(decrypt_string(socketid, adminpass)); | ||||||
|         else |         else | ||||||
|         hash = ""; |         hash = ""; | ||||||
|  |  | ||||||
| @@ -106,14 +106,14 @@ var skip = function(list, guid, coll, offline, socket) { | |||||||
|             if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error) |             if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error) | ||||||
|             { |             { | ||||||
|               db.collection("frontpage_lists").find({"_id": coll}, function(err, frontpage_viewers){ |               db.collection("frontpage_lists").find({"_id": coll}, function(err, frontpage_viewers){ | ||||||
|                 if((frontpage_viewers[0].viewers/2 <= docs[0].skips.length+1 && !Functions.contains(docs[0].skips, guid) && frontpage_viewers[0].viewers != 2) || |                 if((frontpage_viewers[0].viewers/2 <= docs[0].skips.length+1 && !contains(docs[0].skips, guid) && frontpage_viewers[0].viewers != 2) || | ||||||
|                 (frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) || |                 (frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !contains(docs[0].skips, guid)) || | ||||||
|                 (docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip)) |                 (docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip)) | ||||||
|                 { |                 { | ||||||
|                   change_song(coll, error, video_id); |                   change_song(coll, error, video_id); | ||||||
|                   socket.emit("toast", "skip"); |                   socket.emit("toast", "skip"); | ||||||
|                   io.to(coll).emit('chat', {from: name, msg: " skipped"}); |                   io.to(coll).emit('chat', {from: name, msg: " skipped"}); | ||||||
|                 }else if(!Functions.contains(docs[0].skips, guid)){ |                 }else if(!contains(docs[0].skips, guid)){ | ||||||
|                   db.collection(coll).update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){ |                   db.collection(coll).update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){ | ||||||
|                     if(frontpage_viewers[0].viewers == 2) |                     if(frontpage_viewers[0].viewers == 2) | ||||||
|                     to_skip = 1; |                     to_skip = 1; | ||||||
| @@ -172,11 +172,11 @@ function change_song(coll, error, id) { | |||||||
| 									if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | 									if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||||
| 									change_song_post(coll, next_song); | 									change_song_post(coll, next_song); | ||||||
| 									io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); | 									io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); | ||||||
| 									db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); | 									db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: get_time()}}, {upsert: true}, function(err, docs){}); | ||||||
| 								}); | 								}); | ||||||
| 							} else { | 							} else { | ||||||
| 								if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) { | 								if((docs[0].skipped_time != undefined && docs[0].skipped_time != get_time()) || docs[0].skipped_time == undefined) { | ||||||
| 									db.collection(coll).update({views: {$exists: true}}, {$set: {skipped_time: Functions.get_time()}}, function(err, updated){ | 									db.collection(coll).update({views: {$exists: true}}, {$set: {skipped_time: get_time()}}, function(err, updated){ | ||||||
| 										db.collection(coll).update({now_playing:true, id:id}, { | 										db.collection(coll).update({now_playing:true, id:id}, { | ||||||
| 											$set:{ | 											$set:{ | ||||||
| 												now_playing:false, | 												now_playing:false, | ||||||
| @@ -199,10 +199,10 @@ function change_song(coll, error, id) { | |||||||
| 							if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | 							if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||||
| 							change_song_post(coll, next_song); | 							change_song_post(coll, next_song); | ||||||
| 							io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); | 							io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); | ||||||
| 							db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); | 							db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: get_time()}}, {upsert: true}, function(err, docs){}); | ||||||
| 						}); | 						}); | ||||||
| 					} else { | 					} else { | ||||||
| 						if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) { | 						if((docs[0].skipped_time != undefined && docs[0].skipped_time != get_time()) || docs[0].skipped_time == undefined) { | ||||||
| 							db.collection(coll).update({now_playing:true, id:id}, { | 							db.collection(coll).update({now_playing:true, id:id}, { | ||||||
| 								$set:{ | 								$set:{ | ||||||
| 									now_playing:false, | 									now_playing:false, | ||||||
| @@ -256,17 +256,17 @@ function change_song_post(coll, next_song) | |||||||
| 					now_playing:true, | 					now_playing:true, | ||||||
| 					votes:0, | 					votes:0, | ||||||
| 					guids:[], | 					guids:[], | ||||||
| 					added:Functions.get_time() | 					added:get_time() | ||||||
| 				} | 				} | ||||||
| 			}, function(err, returnDocs){ | 			}, function(err, returnDocs){ | ||||||
| 				db.collection(coll).update({views:{$exists:true}},{ | 				db.collection(coll).update({views:{$exists:true}},{ | ||||||
| 					$set:{ | 					$set:{ | ||||||
| 						startTime:Functions.get_time(), | 						startTime:get_time(), | ||||||
| 						skips:[] | 						skips:[] | ||||||
| 					} | 					} | ||||||
| 				}, function(err, returnDocs){ | 				}, function(err, returnDocs){ | ||||||
| 					db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | 					db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | ||||||
| 						io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay}); | 						io.to(coll).emit("channel", {type: "song_change", time: get_time(), remove: conf[0].removeplay}); | ||||||
| 						send_play(coll); | 						send_play(coll); | ||||||
| 						Frontpage.update_frontpage(coll, docs[0].id, docs[0].title); | 						Frontpage.update_frontpage(coll, docs[0].id, docs[0].title); | ||||||
| 					}); | 					}); | ||||||
| @@ -309,12 +309,12 @@ function send_list(coll, socket, send, list_send, configs, shuffled) | |||||||
| 										now_playing:true, | 										now_playing:true, | ||||||
| 										votes:0, | 										votes:0, | ||||||
| 										guids:[], | 										guids:[], | ||||||
| 										added:Functions.get_time() | 										added:get_time() | ||||||
| 									} | 									} | ||||||
| 								}, function(err, returnDocs){ | 								}, function(err, returnDocs){ | ||||||
| 									db.collection(coll).update({views:{$exists:true}}, { | 									db.collection(coll).update({views:{$exists:true}}, { | ||||||
| 										$set:{ | 										$set:{ | ||||||
| 											startTime: Functions.get_time(), | 											startTime: get_time(), | ||||||
| 											skips:[] | 											skips:[] | ||||||
| 										} | 										} | ||||||
| 									}, function(err, returnDocs){ | 									}, function(err, returnDocs){ | ||||||
| @@ -382,20 +382,20 @@ var end = function(obj, coll, guid, offline, socket) { | |||||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ |     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, obj.pass)))) { |       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, obj.pass)))) { | ||||||
|  |  | ||||||
|         Functions.check_inlist(coll, guid, socket, offline); |         check_inlist(coll, guid, socket, offline); | ||||||
|         db.collection(coll).find({now_playing:true}, function(err, np){ |         db.collection(coll).find({now_playing:true}, function(err, np){ | ||||||
|           if(err !== null) console.log(err); |           if(err !== null) console.log(err); | ||||||
|           if(np !== null && np !== undefined && np.length == 1 && np[0].id == id){ |           if(np !== null && np !== undefined && np.length == 1 && np[0].id == id){ | ||||||
|             db.collection(coll).find({views:{$exists:true}}, function(err, docs){ |             db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
|               var startTime = docs[0].startTime; |               var startTime = docs[0].startTime; | ||||||
|               if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=Functions.get_time()+5) |               if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=get_time()+5) | ||||||
|               { |               { | ||||||
|                 db.collection(coll).remove({now_playing:true}, function(err, docs){ |                 db.collection(coll).remove({now_playing:true}, function(err, docs){ | ||||||
|                   change_song_post(coll); |                   change_song_post(coll); | ||||||
|                   db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:-1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){}); |                   db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:-1}, $set:{accessed: get_time()}}, {upsert:true}, function(err, docs){}); | ||||||
|                 }); |                 }); | ||||||
|               }else{ |               }else{ | ||||||
|                 if(startTime+parseInt(np[0].duration)<=Functions.get_time()+5) |                 if(startTime+parseInt(np[0].duration)<=get_time()+5) | ||||||
|                 { |                 { | ||||||
|                   change_song(coll, false, id); |                   change_song(coll, false, id); | ||||||
|                 } |                 } | ||||||
| @@ -418,14 +418,14 @@ function send_play(coll, socket) | |||||||
| 		db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | 		db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | ||||||
| 			if(err !== null) console.log(err); | 			if(err !== null) console.log(err); | ||||||
| 			try{ | 			try{ | ||||||
| 				if(Functions.get_time()-conf[0].startTime > np[0].duration){ | 				if(get_time()-conf[0].startTime > np[0].duration){ | ||||||
| 					change_song(coll, false, np[0].id); | 					change_song(coll, false, np[0].id); | ||||||
| 				}else if(conf !== null && conf !== undefined && conf.length !== 0) | 				}else if(conf !== null && conf !== undefined && conf.length !== 0) | ||||||
| 				{ | 				{ | ||||||
| 					if(conf[0].adminpass !== "") conf[0].adminpass = true; | 					if(conf[0].adminpass !== "") conf[0].adminpass = true; | ||||||
| 					if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true; | 					if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true; | ||||||
| 					else conf[0].userpass = false; | 					else conf[0].userpass = false; | ||||||
| 					toSend = {np: np, conf: conf, time: Functions.get_time()}; | 					toSend = {np: np, conf: conf, time: get_time()}; | ||||||
| 					if(socket === undefined) { | 					if(socket === undefined) { | ||||||
| 						io.to(coll).emit("np", toSend); | 						io.to(coll).emit("np", toSend); | ||||||
| 						getNextSong(coll) | 						getNextSong(coll) | ||||||
| @@ -488,21 +488,10 @@ function left_channel(coll, guid, short_id, in_list, socket, change) | |||||||
| 				db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, updated){}); | 				db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, updated){}); | ||||||
|  |  | ||||||
| 				if(!change) { | 				if(!change) { | ||||||
| 					Functions.remove_name_from_db(guid, name); | 					remove_name_from_db(guid, name); | ||||||
| 				} | 				} | ||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
| 	}); | 	}); | ||||||
| 	Functions.remove_unique_id(short_id); | 	remove_unique_id(short_id); | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports.left_channel = left_channel; |  | ||||||
| module.exports.end = end; |  | ||||||
| module.exports.getNextSong = getNextSong; |  | ||||||
| module.exports.change_song_post = change_song_post; |  | ||||||
| module.exports.change_song = change_song; |  | ||||||
| module.exports.skip = skip; |  | ||||||
| module.exports.send_list = send_list; |  | ||||||
| module.exports.send_play = send_play; |  | ||||||
| module.exports.list = list; |  | ||||||
| module.exports.now_playing = now_playing; |  | ||||||
|   | |||||||
| @@ -11,11 +11,11 @@ var add = function(arr, coll, guid, offline, socket) { | |||||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ |     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, arr.pass)))) { |       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, arr.pass)))) { | ||||||
|  |  | ||||||
|         Functions.check_inlist(coll, guid, socket, offline); |         check_inlist(coll, guid, socket, offline); | ||||||
|  |  | ||||||
|         var id = arr.id; |         var id = arr.id; | ||||||
|         var title = arr.title; |         var title = arr.title; | ||||||
|         var hash = Functions.hash_pass(Functions.decrypt_string(socketid, arr.adminpass)); |         var hash = hash_pass(decrypt_string(socketid, arr.adminpass)); | ||||||
|         var duration = parseInt(arr.duration); |         var duration = parseInt(arr.duration); | ||||||
|         var full_list = arr.playlist; |         var full_list = arr.playlist; | ||||||
|         var last = arr.num == arr.total - 1; |         var last = arr.num == arr.total - 1; | ||||||
| @@ -34,7 +34,7 @@ var add = function(arr, coll, guid, offline, socket) { | |||||||
|                 var votes; |                 var votes; | ||||||
|                 var added; |                 var added; | ||||||
|                 if(full_list) { |                 if(full_list) { | ||||||
|                   var time = Functions.get_time()-total; |                   var time = get_time()-total; | ||||||
|                   time = time.toString(); |                   time = time.toString(); | ||||||
|                   var total_len = total.toString().length; |                   var total_len = total.toString().length; | ||||||
|                   var now_len = num.toString().length; |                   var now_len = num.toString().length; | ||||||
| @@ -49,7 +49,7 @@ var add = function(arr, coll, guid, offline, socket) { | |||||||
|                   added = time; |                   added = time; | ||||||
|                   votes = 0; |                   votes = 0; | ||||||
|                 } else { |                 } else { | ||||||
|                   added = Functions.get_time(); |                   added = get_time(); | ||||||
|                   votes = 1; |                   votes = 1; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -81,15 +81,15 @@ var add = function(arr, coll, guid, offline, socket) { | |||||||
|                   db.collection(coll).update({id: id}, {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}, {upsert: true}, function(err, docs){ |                   db.collection(coll).update({id: id}, {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}, {upsert: true}, function(err, docs){ | ||||||
|                     if(np) |                     if(np) | ||||||
|                     { |                     { | ||||||
|                       List.send_list(coll, undefined, false, true, false); |                       send_list(coll, undefined, false, true, false); | ||||||
|                       db.collection(coll).update({views:{$exists:true}}, {$set:{startTime: Functions.get_time()}}); |                       db.collection(coll).update({views:{$exists:true}}, {$set:{startTime: get_time()}}); | ||||||
|                       List.send_play(coll, undefined); |                       send_play(coll, undefined); | ||||||
|                       Frontpage.update_frontpage(coll, id, title); |                       Frontpage.update_frontpage(coll, id, title); | ||||||
|                     } else { |                     } else { | ||||||
|                       io.to(coll).emit("channel", {type: "added", value: {"_id": "asd", "added":added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}}); |                       io.to(coll).emit("channel", {type: "added", value: {"_id": "asd", "added":added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}}); | ||||||
|                     } |                     } | ||||||
|                     db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){}); |                     db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: get_time()}}, {upsert:true}, function(err, docs){}); | ||||||
|                     List.getNextSong(coll); |                     getNextSong(coll); | ||||||
|                   }); |                   }); | ||||||
|                   if(!full_list) { |                   if(!full_list) { | ||||||
|                     socket.emit("toast", "addedsong"); |                     socket.emit("toast", "addedsong"); | ||||||
| @@ -110,7 +110,7 @@ var add = function(arr, coll, guid, offline, socket) { | |||||||
|             db.collection(coll).find({id: id}, function(err, docs) { |             db.collection(coll).find({id: id}, function(err, docs) { | ||||||
|               if(docs.length === 0) { |               if(docs.length === 0) { | ||||||
|                 db.collection(coll).update({id: id}, {$set:{ |                 db.collection(coll).update({id: id}, {$set:{ | ||||||
|                   "added":Functions.get_time(), |                   "added":get_time(), | ||||||
|                   "guids": [guid], |                   "guids": [guid], | ||||||
|                   "id":id, |                   "id":id, | ||||||
|                   "now_playing": false, |                   "now_playing": false, | ||||||
| @@ -157,14 +157,14 @@ var voteUndecided = function(msg, coll, guid, offline, socket) { | |||||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ |     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) { |       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) { | ||||||
|  |  | ||||||
|         Functions.check_inlist(coll, guid, socket, offline); |         check_inlist(coll, guid, socket, offline); | ||||||
|  |  | ||||||
|         if(msg.type == "del") |         if(msg.type == "del") | ||||||
|         del(msg, socket, socketid); |         del(msg, socket, socketid); | ||||||
|         else |         else | ||||||
|         { |         { | ||||||
|           var id = msg.id; |           var id = msg.id; | ||||||
|           var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); |           var hash = hash_pass(decrypt_string(socketid, msg.adminpass)); | ||||||
|           db.collection(coll).find({views:{$exists:true}}, function(err, docs){ |           db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
|             if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) || |             if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) || | ||||||
|             docs[0].vote === false)) |             docs[0].vote === false)) | ||||||
| @@ -193,17 +193,17 @@ var shuffle = function(msg, coll, guid, offline, socket) { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Functions.check_inlist(coll, guid, socket, offline); |     check_inlist(coll, guid, socket, offline); | ||||||
|     var hash; |     var hash; | ||||||
|     if(msg.adminpass === "") hash = msg.adminpass; |     if(msg.adminpass === "") hash = msg.adminpass; | ||||||
|     else hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); |     else hash = hash_pass(decrypt_string(socketid, msg.adminpass)); | ||||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ |     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { |       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) { | ||||||
|         if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash || docs[0].adminpass === "") || docs[0].shuffle === false)) |         if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash || docs[0].adminpass === "") || docs[0].shuffle === false)) | ||||||
|         { |         { | ||||||
|           db.collection(coll).find({now_playing:false}).forEach(function(err, docs){ |           db.collection(coll).find({now_playing:false}).forEach(function(err, docs){ | ||||||
|             if(!docs){ |             if(!docs){ | ||||||
|               List.send_list(coll, undefined, false, true, false, true); |               send_list(coll, undefined, false, true, false, true); | ||||||
|               socket.emit("toast", "shuffled"); |               socket.emit("toast", "shuffled"); | ||||||
|  |  | ||||||
|               return; |               return; | ||||||
| @@ -222,8 +222,8 @@ var shuffle = function(msg, coll, guid, offline, socket) { | |||||||
|     var complete = function(tot, curr){ |     var complete = function(tot, curr){ | ||||||
|       if(tot == curr) |       if(tot == curr) | ||||||
|       { |       { | ||||||
|         List.send_list(coll, undefined, false, true, false); |         send_list(coll, undefined, false, true, false); | ||||||
|         List.getNextSong(coll); |         getNextSong(coll); | ||||||
|       } |       } | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| @@ -238,7 +238,7 @@ function del(params, socket, socketid) { | |||||||
| 		coll = encodeURIComponent(coll).replace(/\W/g, ''); | 		coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
| 		coll = filter.clean(coll); | 		coll = filter.clean(coll); | ||||||
| 		db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | 		db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
| 			if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.decrypt_string(socketid, params.adminpass))) | 			if(docs !== null && docs.length !== 0 && docs[0].adminpass == hash_pass(decrypt_string(socketid, params.adminpass))) | ||||||
| 			{ | 			{ | ||||||
| 				db.collection(coll).find({id:params.id}, function(err, docs){ | 				db.collection(coll).find({id:params.id}, function(err, docs){ | ||||||
| 					dont_increment = true; | 					dont_increment = true; | ||||||
| @@ -249,7 +249,7 @@ function del(params, socket, socketid) { | |||||||
| 						db.collection(coll).remove({id:params.id}, function(err, docs){ | 						db.collection(coll).remove({id:params.id}, function(err, docs){ | ||||||
| 							socket.emit("toast", "deletesong"); | 							socket.emit("toast", "deletesong"); | ||||||
| 							io.to(coll).emit("channel", {type:"deleted", value: params.id}); | 							io.to(coll).emit("channel", {type:"deleted", value: params.id}); | ||||||
| 							if(dont_increment) db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); | 							if(dont_increment) db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: get_time()}}, {upsert: true}, function(err, docs){}); | ||||||
| 						}); | 						}); | ||||||
| 					} | 					} | ||||||
| 				}); | 				}); | ||||||
| @@ -262,16 +262,16 @@ function del(params, socket, socketid) { | |||||||
| var delete_all = function(msg, coll, guid, offline, socket) { | var delete_all = function(msg, coll, guid, offline, socket) { | ||||||
|   var socketid = socket.zoff_id; |   var socketid = socket.zoff_id; | ||||||
|   if(typeof(msg) == 'object' && msg.hasOwnProperty('channel') && msg.hasOwnProperty('adminpass') && msg.hasOwnProperty('pass')) { |   if(typeof(msg) == 'object' && msg.hasOwnProperty('channel') && msg.hasOwnProperty('adminpass') && msg.hasOwnProperty('pass')) { | ||||||
|     var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); |     var hash = hash_pass(decrypt_string(socketid, msg.adminpass)); | ||||||
|     var hash_userpass = Functions.decrypt_string(socketid, msg.pass); |     var hash_userpass = decrypt_string(socketid, msg.pass); | ||||||
|  |  | ||||||
|     db.collection(coll).find({views: {$exists: true}}, function(err, conf) { |     db.collection(coll).find({views: {$exists: true}}, function(err, conf) { | ||||||
|       if(conf.length == 1 && conf) { |       if(conf.length == 1 && conf) { | ||||||
|         conf = conf[0]; |         conf = conf[0]; | ||||||
|         if(conf.adminpass == hash && conf.adminpass != "" && (conf.userpass == "" || conf.userpass == undefined || (conf.userpass != "" && conf.userpass != undefined && conf.pass == hash_userpass))) { |         if(conf.adminpass == hash && conf.adminpass != "" && (conf.userpass == "" || conf.userpass == undefined || (conf.userpass != "" && conf.userpass != undefined && conf.pass == hash_userpass))) { | ||||||
|           db.collection(coll).remove({views: {$exists: false}}, {multi: true}, function(err, succ) { |           db.collection(coll).remove({views: {$exists: false}}, {multi: true}, function(err, succ) { | ||||||
|             List.send_list(coll, false, true, true, true); |             send_list(coll, false, true, true, true); | ||||||
|             db.collection("frontpage_lists").update({_id: coll}, {$set: {count: 0, accessed: Functions.get_time()}}, {upsert: true}, function(err, docs) {}); |             db.collection("frontpage_lists").update({_id: coll}, {$set: {count: 0, accessed: get_time()}}, {upsert: true}, function(err, docs) {}); | ||||||
|             socket.emit("toast", "deleted_songs"); |             socket.emit("toast", "deleted_songs"); | ||||||
|           }); |           }); | ||||||
|         } else { |         } else { | ||||||
| @@ -287,15 +287,15 @@ var delete_all = function(msg, coll, guid, offline, socket) { | |||||||
|  |  | ||||||
| function vote(coll, id, guid, socket, full_list, last) { | function vote(coll, id, guid, socket, full_list, last) { | ||||||
| 	db.collection(coll).find({id:id, now_playing: false}, function(err, docs){ | 	db.collection(coll).find({id:id, now_playing: false}, function(err, docs){ | ||||||
| 		if(docs !== null && docs.length > 0 && !Functions.contains(docs[0].guids, guid)) | 		if(docs !== null && docs.length > 0 && !contains(docs[0].guids, guid)) | ||||||
| 		{ | 		{ | ||||||
| 			db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, docs) | 			db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:get_time()}, $push :{guids: guid}}, function(err, docs) | ||||||
| 			{ | 			{ | ||||||
| 				if((full_list && last) || (!full_list)) | 				if((full_list && last) || (!full_list)) | ||||||
| 				socket.emit("toast", "voted"); | 				socket.emit("toast", "voted"); | ||||||
| 				io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()}); | 				io.to(coll).emit("channel", {type: "vote", value: id, time: get_time()}); | ||||||
|  |  | ||||||
| 				List.getNextSong(coll); | 				getNextSong(coll); | ||||||
| 			}); | 			}); | ||||||
| 		}else | 		}else | ||||||
| 		{ | 		{ | ||||||
| @@ -303,10 +303,3 @@ function vote(coll, id, guid, socket, full_list, last) { | |||||||
| 		} | 		} | ||||||
| 	}); | 	}); | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports.shuffle = shuffle; |  | ||||||
| module.exports.delete_all = delete_all; |  | ||||||
| module.exports.del = del; |  | ||||||
| module.exports.vote = vote; |  | ||||||
| module.exports.voteUndecided = voteUndecided; |  | ||||||
| module.exports.add = add; |  | ||||||
|   | |||||||
| @@ -20,22 +20,22 @@ var password = function(inp, coll, guid, offline, socket) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     uncrypted = pw; |     uncrypted = pw; | ||||||
|     pw = Functions.decrypt_string(socket.zoff_id, pw); |     pw = decrypt_string(socket.zoff_id, pw); | ||||||
|  |  | ||||||
|     Functions.check_inlist(coll, guid, socket, offline); |     check_inlist(coll, guid, socket, offline); | ||||||
|  |  | ||||||
|     if(inp.oldpass) |     if(inp.oldpass) | ||||||
|     { |     { | ||||||
|       opw = inp.oldpass; |       opw = inp.oldpass; | ||||||
|     } |     } | ||||||
|     opw = Functions.decrypt_string(socket.zoff_id, opw); |     opw = decrypt_string(socket.zoff_id, opw); | ||||||
|  |  | ||||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ |     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||||
|       if(docs !== null && docs.length !== 0) |       if(docs !== null && docs.length !== 0) | ||||||
|       { |       { | ||||||
|         if(docs[0].adminpass === "" || docs[0].adminpass == Functions.hash_pass(opw)) |         if(docs[0].adminpass === "" || docs[0].adminpass == hash_pass(opw)) | ||||||
|         { |         { | ||||||
|           db.collection(coll).update({views:{$exists:true}}, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){ |           db.collection(coll).update({views:{$exists:true}}, {$set:{adminpass:hash_pass(pw)}}, function(err, docs){ | ||||||
|             if(inp.oldpass) |             if(inp.oldpass) | ||||||
|             socket.emit("toast", "changedpass"); |             socket.emit("toast", "changedpass"); | ||||||
|             else |             else | ||||||
| @@ -82,7 +82,7 @@ var conf = function(params, coll, guid, offline, socket) { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Functions.check_inlist(coll, guid, socket, offline); |     check_inlist(coll, guid, socket, offline); | ||||||
|  |  | ||||||
|     var voting = params.voting; |     var voting = params.voting; | ||||||
|     var addsongs = params.addsongs; |     var addsongs = params.addsongs; | ||||||
| @@ -93,7 +93,7 @@ var conf = function(params, coll, guid, offline, socket) { | |||||||
|     var adminpass = params.adminpass; |     var adminpass = params.adminpass; | ||||||
|     var skipping = params.skipping; |     var skipping = params.skipping; | ||||||
|     var shuffling = params.shuffling; |     var shuffling = params.shuffling; | ||||||
|     var userpass = Functions.decrypt_string(socket.zoff_id, params.userpass); |     var userpass = decrypt_string(socket.zoff_id, params.userpass); | ||||||
|  |  | ||||||
|     if((!params.userpass_changed && frontpage) || (params.userpass_changed && userpass == "")) { |     if((!params.userpass_changed && frontpage) || (params.userpass_changed && userpass == "")) { | ||||||
|       userpass = ""; |       userpass = ""; | ||||||
| @@ -105,7 +105,7 @@ var conf = function(params, coll, guid, offline, socket) { | |||||||
|     if(params.description) description = params.description; |     if(params.description) description = params.description; | ||||||
|  |  | ||||||
|     if(adminpass !== "") { |     if(adminpass !== "") { | ||||||
|       hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, adminpass)); |       hash = hash_pass(decrypt_string(socket.zoff_id, adminpass)); | ||||||
|     } else { |     } else { | ||||||
|       hash = adminpass; |       hash = adminpass; | ||||||
|     } |     } | ||||||
| @@ -139,7 +139,7 @@ var conf = function(params, coll, guid, offline, socket) { | |||||||
|             socket.emit("toast", "savedsettings"); |             socket.emit("toast", "savedsettings"); | ||||||
|  |  | ||||||
|             db.collection("frontpage_lists").update({_id: coll}, {$set:{ |             db.collection("frontpage_lists").update({_id: coll}, {$set:{ | ||||||
|               frontpage:frontpage, accessed: Functions.get_time()} |               frontpage:frontpage, accessed: get_time()} | ||||||
|             }, |             }, | ||||||
|             {upsert:true}, function(err, docs){}); |             {upsert:true}, function(err, docs){}); | ||||||
|           }); |           }); | ||||||
| @@ -152,6 +152,3 @@ var conf = function(params, coll, guid, offline, socket) { | |||||||
|     socket.emit('update_required'); |     socket.emit('update_required'); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports.conf = conf; |  | ||||||
| module.exports.password = password; |  | ||||||
|   | |||||||
| @@ -71,29 +71,17 @@ app.use(bodyParser.urlencoded({     // to support URL-encoded bodies | |||||||
| app.use(cookieParser()); | app.use(cookieParser()); | ||||||
| 
 | 
 | ||||||
| /* Starting DB and socketio */ | /* Starting DB and socketio */ | ||||||
| io = require('socket.io')(server, { | var io = require('socket.io')(server, { | ||||||
| 	pingTimeout: 25000, | 	pingTimeout: 25000, | ||||||
| }); //, "origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*" + add)});
 | }); //, "origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*" + add)});
 | ||||||
| db = require('./handlers/db.js'); | var request = require('request'); | ||||||
| var socketIO = require('./handlers/io.js'); |  | ||||||
| socketIO(); |  | ||||||
| 
 | 
 | ||||||
| request = require('request'); | var crypto = require('crypto'); | ||||||
| 
 | var node_cryptojs = require('node-cryptojs-aes'); | ||||||
| /* Globally needed "libraries" and files */ | var CryptoJS = node_cryptojs.CryptoJS; | ||||||
| Functions = require('./handlers/functions.js'); | var emojiStrip = require('emoji-strip'); | ||||||
| ListChange = require('./handlers/list_change.js'); | var Filter = require('bad-words'); | ||||||
| Chat = require('./handlers/chat.js'); | var filter = new Filter({ placeHolder: 'x'}); | ||||||
| List = require('./handlers/list.js'); |  | ||||||
| Suggestions = require('./handlers/suggestions.js'); |  | ||||||
| ListSettings = require('./handlers/list_settings.js'); |  | ||||||
| Frontpage = require('./handlers/frontpage.js'); |  | ||||||
| crypto = require('crypto'); |  | ||||||
| node_cryptojs = require('node-cryptojs-aes'); |  | ||||||
| CryptoJS = node_cryptojs.CryptoJS; |  | ||||||
| emojiStrip = require('emoji-strip'); |  | ||||||
| Filter = require('bad-words'); |  | ||||||
| filter = new Filter({ placeHolder: 'x'}); |  | ||||||
| 
 | 
 | ||||||
| var router = require('./routing/router.js'); | var router = require('./routing/router.js'); | ||||||
| var port = 8080; | var port = 8080; | ||||||
| @@ -3,9 +3,9 @@ var thumbnail = function(msg, coll, guid, offline, socket) { | |||||||
|     msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, ""); |     msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, ""); | ||||||
|     if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail; |     if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail; | ||||||
|     var channel = msg.channel.toLowerCase(); |     var channel = msg.channel.toLowerCase(); | ||||||
|     var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass)); |     var hash = hash_pass(decrypt_string(socket.zoff_id, msg.adminpass)); | ||||||
|     db.collection(channel).find({views:{$exists:true}}, function(err, docs){ |     db.collection(channel).find({views:{$exists:true}}, function(err, docs){ | ||||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { |       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) { | ||||||
|         if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ |         if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ | ||||||
|           db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){ |           db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){ | ||||||
|             socket.emit("toast", "suggested_thumbnail"); |             socket.emit("toast", "suggested_thumbnail"); | ||||||
| @@ -23,9 +23,9 @@ var thumbnail = function(msg, coll, guid, offline, socket) { | |||||||
| var description = function(msg, coll, guid, offline, socket) { | var description = function(msg, coll, guid, offline, socket) { | ||||||
|   if(msg.description && msg.channel && msg.adminpass && msg.description.length < 100){ |   if(msg.description && msg.channel && msg.adminpass && msg.description.length < 100){ | ||||||
|     var channel = msg.channel.toLowerCase(); |     var channel = msg.channel.toLowerCase(); | ||||||
|     var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass)); |     var hash = hash_pass(decrypt_string(socket.zoff_id, msg.adminpass)); | ||||||
|     db.collection(channel).find({views:{$exists:true}}, function(err, docs){ |     db.collection(channel).find({views:{$exists:true}}, function(err, docs){ | ||||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { |       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) { | ||||||
|         if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ |         if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ | ||||||
|           db.collection("suggested_descriptions").update({channel: channel}, {$set:{description: msg.description}}, {upsert:true}, function(err, docs){ |           db.collection("suggested_descriptions").update({channel: channel}, {$set:{description: msg.description}}, {upsert:true}, function(err, docs){ | ||||||
|             socket.emit("toast", "suggested_description"); |             socket.emit("toast", "suggested_description"); | ||||||
| @@ -39,6 +39,3 @@ var description = function(msg, coll, guid, offline, socket) { | |||||||
|     socket.emit("toast", "description_denied"); |     socket.emit("toast", "description_denied"); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports.description = description; |  | ||||||
| module.exports.thumbnail = thumbnail; |  | ||||||
|   | |||||||
							
								
								
									
										1823
									
								
								server/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1823
									
								
								server/index.js
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -3,6 +3,9 @@ var router = express.Router(); | |||||||
| const path = require('path'); | const path = require('path'); | ||||||
| var nodemailer = require('nodemailer'); | var nodemailer = require('nodemailer'); | ||||||
| var mailconfig = require('../mailconfig.js'); | var mailconfig = require('../mailconfig.js'); | ||||||
|  | var mongo_db_cred = {config: 'mydb'}; | ||||||
|  | var mongojs = require('mongojs'); | ||||||
|  | var db = mongojs(mongo_db_cred.config); | ||||||
|  |  | ||||||
| router.use(function(req, res, next) { | router.use(function(req, res, next) { | ||||||
|     next(); // make sure we go to the next routes and don't stop here |     next(); // make sure we go to the next routes and don't stop here | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user