mirror of
https://github.com/KevinMidboe/zoff.git
synced 2026-05-14 17:46:18 +00:00
Started work for having session-logins instead of sending passwords back and forth
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
function get_history(channel, all, socket, pass) {
|
||||
function get_history(channel, all, socket) {
|
||||
var query = {};
|
||||
if(all) {
|
||||
query = {
|
||||
@@ -10,13 +10,17 @@ function get_history(channel, all, socket, pass) {
|
||||
channel: channel,
|
||||
};
|
||||
}
|
||||
var pass = "";
|
||||
if(!query.all) {
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(err, conf) {
|
||||
if(conf.length > 0) {
|
||||
if(conf[0].userpass == "" || conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socket.zoff_id, pass)).digest('base64')) {
|
||||
getAndSendLogs(channel, all, socket, pass, query);
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), channel, function(userpass) {
|
||||
pass = userpass;
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(err, conf) {
|
||||
if(conf.length > 0) {
|
||||
if(conf[0].userpass == "" || conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socket.zoff_id, pass)).digest('base64')) {
|
||||
getAndSendLogs(channel, all, socket, pass, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
getAndSendLogs(channel, all, socket, pass, query);
|
||||
@@ -40,9 +44,7 @@ function getAndSendLogs(channel, all, socket, pass, query) {
|
||||
|
||||
function chat(msg, guid, offline, socket) {
|
||||
if(typeof(msg) !== 'object' || !msg.hasOwnProperty('data') ||
|
||||
!msg.hasOwnProperty('channel') || !msg.hasOwnProperty('pass') ||
|
||||
typeof(msg.data) != "string" || typeof(msg.channel) != "string" ||
|
||||
typeof(msg.pass) != "string") {
|
||||
!msg.hasOwnProperty('channel') || typeof(msg.data) != "string" || typeof(msg.channel) != "string") {
|
||||
var result = {
|
||||
data: {
|
||||
expected: "string",
|
||||
@@ -61,30 +63,33 @@ function chat(msg, guid, offline, socket) {
|
||||
return;
|
||||
}
|
||||
var coll = msg.channel.toLowerCase();
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socket.zoff_id, msg.pass)).digest("base64")))) {
|
||||
var data = msg.data;
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
if(data !== "" && data !== undefined && data !== null &&
|
||||
data.length < 151 && data.replace(/\s/g, '').length){
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 1) {
|
||||
db.collection("registered_users").find({"_id": docs[0].name}, function(err, n) {
|
||||
var icon = false;
|
||||
if(n.length > 0 && n[0].icon) {
|
||||
icon = n[0].icon;
|
||||
}
|
||||
db.collection("chat_logs").insert({ "createdAt": new Date(), all: false, channel: coll, from: docs[0].name, msg: ": " + data, icon: icon });
|
||||
io.to(coll).emit('chat', {from: docs[0].name, msg: ": " + data, icon: icon});
|
||||
});
|
||||
} else if(docs.length == 0){
|
||||
get_name(guid, {announce: false, channel: coll, message: data, all: false});
|
||||
}
|
||||
});
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) {
|
||||
msg.pass = userpass;
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socket.zoff_id, msg.pass)).digest("base64")))) {
|
||||
var data = msg.data;
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
if(data !== "" && data !== undefined && data !== null &&
|
||||
data.length < 151 && data.replace(/\s/g, '').length){
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 1) {
|
||||
db.collection("registered_users").find({"_id": docs[0].name}, function(err, n) {
|
||||
var icon = false;
|
||||
if(n.length > 0 && n[0].icon) {
|
||||
icon = n[0].icon;
|
||||
}
|
||||
db.collection("chat_logs").insert({ "createdAt": new Date(), all: false, channel: coll, from: docs[0].name, msg: ": " + data, icon: icon });
|
||||
io.to(coll).emit('chat', {from: docs[0].name, msg: ": " + data, icon: icon});
|
||||
});
|
||||
} else if(docs.length == 0){
|
||||
get_name(guid, {announce: false, channel: coll, message: data, all: false});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
socket.emit('auth_required');
|
||||
}
|
||||
} else {
|
||||
socket.emit('auth_required');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -135,72 +140,85 @@ function namechange(data, guid, socket, tried) {
|
||||
var pw = "";
|
||||
var new_password;
|
||||
var first = false;
|
||||
if(data.hasOwnProperty("first")) {
|
||||
first = data.first;
|
||||
}
|
||||
if(data.hasOwnProperty("password")) {
|
||||
pw = data.password;
|
||||
new_password = false;
|
||||
} else if(data.hasOwnProperty("new_password") && data.hasOwnProperty("old_password")) {
|
||||
pw = data.old_password;
|
||||
new_password = Functions.decrypt_string(socket.zoff_id, data.new_password);
|
||||
}
|
||||
var password = Functions.decrypt_string(socket.zoff_id, pw);
|
||||
var name = data.name;
|
||||
db.collection("registered_users").find({"_id": name.toLowerCase()}, function(err, docs) {
|
||||
var accepted_password = false;
|
||||
var icon = false;
|
||||
if(docs.length == 0) {
|
||||
if(new_password) {
|
||||
return;
|
||||
}
|
||||
accepted_password = true;
|
||||
db.collection("registered_users").update({"_id": name.toLowerCase()}, {$set: {password: Functions.hash_pass(password)}}, {upsert: true}, function() {});
|
||||
} else if(docs[0].password == Functions.hash_pass(password)) {
|
||||
if(docs[0].icon) {
|
||||
icon = docs[0].icon;
|
||||
}
|
||||
accepted_password = true;
|
||||
if(new_password) {
|
||||
db.collection("registered_users").update({"_id": name.toLowerCase(), password: Functions.hash_pass(password)}, {$set: {password: Functions.hash_pass(new_password)}}, function() {});
|
||||
}
|
||||
Functions.getSessionChatPass(Functions.getSession(socket), function(name, pass) {
|
||||
var name = data.name;
|
||||
if(data.hasOwnProperty("first")) {
|
||||
first = data.first;
|
||||
}
|
||||
if(accepted_password) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, names) {
|
||||
if(names.length > 0) {
|
||||
var old_name = names[0].name;
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function() {});
|
||||
db.collection("user_names").update({"guid": guid}, {$set: {name: name, icon: icon}}, function(err, docs) {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, function(err, docs) {
|
||||
socket.emit('name', {type: "name", accepted: true});
|
||||
if(old_name != name && !first) {
|
||||
io.to(data.channel).emit('chat', {from: old_name, msg: " changed name to " + name});
|
||||
io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: data.channel});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if(tried < 3 || tried == undefined) {
|
||||
if(tried == undefined) {
|
||||
tried = 1;
|
||||
}
|
||||
namechange(data, guid, socket, tried + 1);
|
||||
}
|
||||
if(data.hasOwnProperty("password")) {
|
||||
pw = data.password;
|
||||
new_password = false;
|
||||
} else if(data.hasOwnProperty("new_password") && data.hasOwnProperty("old_password")) {
|
||||
pw = data.old_password;
|
||||
new_password = Functions.decrypt_string(socket.zoff_id, data.new_password);
|
||||
}
|
||||
if(data.hasOwnProperty("first") && data.first) {
|
||||
pw = pass;
|
||||
name = name;
|
||||
new_password = false;
|
||||
}
|
||||
var password = Functions.decrypt_string(socket.zoff_id, pw);
|
||||
db.collection("registered_users").find({"_id": name.toLowerCase()}, function(err, docs) {
|
||||
var accepted_password = false;
|
||||
var icon = false;
|
||||
if(docs.length == 0) {
|
||||
if(new_password) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
socket.emit('name', {type: "name", accepted: false});
|
||||
}
|
||||
accepted_password = true;
|
||||
Functions.setSessionChatPass(Functions.getSession(socket), name.toLowerCase(), data.password, function() {
|
||||
db.collection("registered_users").update({"_id": name.toLowerCase()}, {$set: {password: Functions.hash_pass(password)}}, {upsert: true}, function() {});
|
||||
});
|
||||
} else if(docs[0].password == Functions.hash_pass(password)) {
|
||||
if(docs[0].icon) {
|
||||
icon = docs[0].icon;
|
||||
}
|
||||
accepted_password = true;
|
||||
if(new_password) {
|
||||
Functions.setSessionChatPass(Functions.getSession(socket), name.toLowerCase(), data.new_password, function() {
|
||||
db.collection("registered_users").update({"_id": name.toLowerCase(), password: Functions.hash_pass(password)}, {$set: {password: Functions.hash_pass(new_password)}}, function() {});
|
||||
});
|
||||
}
|
||||
}
|
||||
if(accepted_password) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, names) {
|
||||
if(names.length > 0) {
|
||||
var old_name = names[0].name;
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function() {});
|
||||
db.collection("user_names").update({"guid": guid}, {$set: {name: name, icon: icon}}, function(err, docs) {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, function(err, docs) {
|
||||
//socket.emit('name', {type: "name", accepted: true});
|
||||
if(old_name != name && !first) {
|
||||
io.to(data.channel).emit('chat', {from: old_name, msg: " changed name to " + name});
|
||||
io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: data.channel});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if(tried < 3 || tried == undefined) {
|
||||
if(tried == undefined) {
|
||||
tried = 1;
|
||||
}
|
||||
namechange(data, guid, socket, tried + 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
socket.emit('name', {type: "name", accepted: false});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function removename(guid, coll) {
|
||||
function removename(guid, coll, socket) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 1) {
|
||||
var old_name = docs[0].name;
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function(err, updated) {
|
||||
db.collection("user_names").remove({"guid": guid}, function(err, removed) {
|
||||
get_name(guid, {announce: true, old_name: old_name, channel: coll});
|
||||
Functions.removeSessionChatPass(Functions.getSession(socket), function() {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function(err, updated) {
|
||||
db.collection("user_names").remove({"guid": guid}, function(err, removed) {
|
||||
get_name(guid, {announce: true, old_name: old_name, channel: coll});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -234,7 +252,7 @@ function generate_name(guid, announce_payload, second) {
|
||||
})
|
||||
}
|
||||
|
||||
function get_name(guid, announce_payload) {
|
||||
function get_name(guid, announce_payload, first) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 0) {
|
||||
Chat.generate_name(guid, announce_payload);
|
||||
|
||||
@@ -8,6 +8,7 @@ try {
|
||||
}
|
||||
var mongojs = require('mongojs');
|
||||
var db = mongojs('mongodb://' + mongo_config.host + '/' + mongo_config.config);
|
||||
var connected_db = mongojs('mongodb://' + mongo_config.host + '/user_credentials');
|
||||
var ObjectId = mongojs.ObjectId;
|
||||
|
||||
db.collection("chat_logs").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 600 });
|
||||
@@ -15,7 +16,7 @@ db.collection("timeout_api").createIndex({ "createdAt": 1 }, { expireAfterSecond
|
||||
db.collection("api_links").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 86400 });
|
||||
db.on('connected', function(err) {
|
||||
console.log("connected");
|
||||
})
|
||||
});
|
||||
|
||||
db.on('error',function(err) {
|
||||
console.log("\n" + new Date().toString() + "\n Database error: ", err);
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
var path = require('path');
|
||||
try {
|
||||
var mongo_config = require(path.join(path.join(__dirname, '../config/'), 'mongo_config.js'));
|
||||
} catch(e) {
|
||||
console.log("Error - missing file");
|
||||
console.log("Seems you forgot to create the file mongo_config.js in /server/config/. Have a look at mongo_config.example.js.");
|
||||
process.exit();
|
||||
}
|
||||
var mongojs = require('mongojs');
|
||||
var connected_db = mongojs('mongodb://' + mongo_config.host + '/user_credentials');
|
||||
|
||||
function remove_unique_id(short_id) {
|
||||
db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {});
|
||||
@@ -9,6 +19,17 @@ function remove_name_from_db(guid, name) {
|
||||
});
|
||||
}
|
||||
|
||||
function getSession(socket) {
|
||||
try {
|
||||
var cookieParser = require("cookie-parser");
|
||||
var cookie = require("cookie");
|
||||
var parsedCookies = cookie.parse(socket.handshake.headers.cookie);
|
||||
return parsedCookies["_uI"];
|
||||
} catch(e) {
|
||||
return "empty";
|
||||
}
|
||||
}
|
||||
|
||||
function remove_from_array(array, element){
|
||||
if(Functions.contains(array, element)){
|
||||
var index = array.indexOf(element);
|
||||
@@ -139,6 +160,119 @@ function hash_pass(adminpass, hex) {
|
||||
return crypto.createHash('sha256').update(adminpass).digest('base64');
|
||||
}
|
||||
|
||||
function setSessionAdminPass(id, adminpass, list, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
connected_db.collection(id).update({_id: list}, {$set: {adminpass: adminpass}}, {upsert: true}, function(e, d){
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
} catch(e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function setSessionChatPass(id, name, pass, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
connected_db.collection(id).update({_id: "_chat_"}, {$set: {password: pass, name: name}}, {upsert: true}, function(e) {
|
||||
callback();
|
||||
return;
|
||||
})
|
||||
} catch(e) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function getSessionChatPass(id, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
callback("", "", false);
|
||||
return;
|
||||
}
|
||||
|
||||
connected_db.collection(id).find({_id: "_chat_"}, function(e, d) {
|
||||
if(d.length > 0) {
|
||||
var name = "";
|
||||
var pass = "";
|
||||
if(d[0].name != undefined) name = d[0].name;
|
||||
if(d[0].password != undefined) pass = d[0].password;
|
||||
callback(name, password);
|
||||
return;
|
||||
} else {
|
||||
callback("", "", false);
|
||||
return;
|
||||
}
|
||||
})
|
||||
} catch(e) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function setSessionUserPass(id, userpass, list, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
connected_db.collection(id).update({_id: list}, {$set: {userpass: userpass}}, {upsert: true}, function(e, d){
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
} catch(e) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function getSessionAdminUser(id, list, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
callback("", "", false);
|
||||
return;
|
||||
}
|
||||
connected_db.collection(id).find({_id: list}, function(e, d) {
|
||||
var userpass = "";
|
||||
var adminpass = "";
|
||||
if(d.length > 0) {
|
||||
if(d[0].userpass != undefined) userpass = d[0].userpass;
|
||||
if(d[0].adminpass != undefined) adminpass = d[0].adminpass;
|
||||
}
|
||||
callback(userpass, adminpass, true);
|
||||
})
|
||||
} catch(e) {
|
||||
callback("", "", false);
|
||||
}
|
||||
}
|
||||
|
||||
function removeSessionChatPass(id, callback) {
|
||||
if(id == "empty") {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
connected_db.collection(id).remove({_id: "_chat_"}, function() {
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.getSessionChatPass = getSessionChatPass;
|
||||
module.exports.setSessionChatPass = setSessionChatPass;
|
||||
module.exports.removeSessionChatPass = removeSessionChatPass;
|
||||
module.exports.setSessionAdminPass = setSessionAdminPass;
|
||||
module.exports.setSessionUserPass = setSessionUserPass;
|
||||
module.exports.getSessionAdminUser = getSessionAdminUser;
|
||||
module.exports.getSession = getSession;
|
||||
module.exports.generate_channel_name = generate_channel_name;
|
||||
module.exports.remove_unique_id = remove_unique_id;
|
||||
module.exports.remove_name_from_db = remove_name_from_db;
|
||||
|
||||
@@ -44,6 +44,10 @@ module.exports = function() {
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("logout", function() {
|
||||
Functions.setSessionAdminPass(Functions.getSession(socket), "", coll, function() {})
|
||||
});
|
||||
|
||||
socket.on('chromecast', function(msg) {
|
||||
try {
|
||||
if(typeof(msg) == "object" && msg.hasOwnProperty("guid") &&
|
||||
@@ -51,6 +55,14 @@ module.exports = function() {
|
||||
typeof(msg.channel) == "string" && typeof(msg.socket_id) == "string") {
|
||||
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) {
|
||||
var q = socket.handshake.headers.cookie.split(" ");
|
||||
for(var i = 0; i < q.length; i++) {
|
||||
if(q[i].substring(0,4) == "_uI=") {
|
||||
q[i] = "_uI=rpmFLmS2QvgRavsU6uTNYLAOWjXj5UUi0a4P24eqbao%3D; ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
socket.handshake.headers.cookie = q.join(" ");
|
||||
guid = msg.guid;
|
||||
socketid = msg.socket_id;
|
||||
socket.zoff_id = socketid;
|
||||
@@ -66,6 +78,10 @@ module.exports = function() {
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("get_id", function() {
|
||||
socket.emit("id_chromecast", Functions.getSession(socket));
|
||||
});
|
||||
|
||||
socket.on("error_video", function(msg) {
|
||||
try {
|
||||
var _list = msg.channel;
|
||||
@@ -117,7 +133,7 @@ module.exports = function() {
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
Chat.removename(guid, msg.channel);
|
||||
Chat.removename(guid, msg.channel, socket);
|
||||
});
|
||||
|
||||
socket.on("offline", function(msg){
|
||||
@@ -179,9 +195,7 @@ module.exports = function() {
|
||||
|
||||
socket.on('get_history', function(msg) {
|
||||
if(!msg.hasOwnProperty("channel") || !msg.hasOwnProperty("all") ||
|
||||
!msg.hasOwnProperty("pass") || typeof(msg.pass) != "string" ||
|
||||
typeof(msg.channel) != "string" || typeof(msg.all) != "boolean") {
|
||||
console.log("here");
|
||||
var result = {
|
||||
all: {
|
||||
expected: "boolean",
|
||||
@@ -199,7 +213,7 @@ module.exports = function() {
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
Chat.get_history(msg.channel, msg.all, socket, msg.pass);
|
||||
Chat.get_history(msg.channel, msg.all, socket);
|
||||
});
|
||||
|
||||
socket.on('chat', function (msg) {
|
||||
@@ -399,8 +413,7 @@ module.exports = function() {
|
||||
|
||||
socket.on('pos', function(obj)
|
||||
{
|
||||
if(!obj.hasOwnProperty("channel") || typeof(obj.channel) != "string" ||
|
||||
(obj.hasOwnProperty("pass") && typeof(obj.pass) != "string"))
|
||||
if(!obj.hasOwnProperty("channel") || typeof(obj.channel) != "string")
|
||||
if(coll !== undefined) {
|
||||
try {
|
||||
coll = obj.channel.toLowerCase();
|
||||
@@ -414,8 +427,7 @@ module.exports = function() {
|
||||
}
|
||||
}
|
||||
|
||||
if(!obj.hasOwnProperty("channel") || typeof(obj.channel) != "string" ||
|
||||
!obj.hasOwnProperty("pass") || typeof(obj.pass) != "string") {
|
||||
if(!obj.hasOwnProperty("channel") || typeof(obj.channel) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -431,18 +443,24 @@ module.exports = function() {
|
||||
}
|
||||
|
||||
db.collection(coll + "_settings").find(function(err, docs) {
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, obj.pass)).digest("base64")))) {
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
List.send_play(coll, socket);
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
obj.pass = userpass;
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, obj.pass)).digest("base64")))) {
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
List.send_play(coll, socket);
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
//send_ping();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
function send_ping() {
|
||||
db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true}, function(err, docs){
|
||||
|
||||
@@ -22,63 +22,72 @@ function list(msg, guid, coll, offline, socket) {
|
||||
|
||||
if(typeof(msg) === 'object' && msg !== undefined && msg !== null)
|
||||
{
|
||||
if(!msg.hasOwnProperty('version') || !msg.hasOwnProperty("channel") || !msg.hasOwnProperty("pass") ||
|
||||
msg.version != VERSION || msg.version == undefined ||
|
||||
typeof(msg.channel) != "string" || typeof(msg.pass) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined,
|
||||
},
|
||||
version: {
|
||||
expected: VERSION,
|
||||
got: msg.version,
|
||||
},
|
||||
pass: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined,
|
||||
},
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
coll = msg.channel.toLowerCase();
|
||||
var pass = crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64");
|
||||
db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){
|
||||
if(frontpage_lists.length == 1)
|
||||
{
|
||||
db.collection(coll + "_settings").find(function(err, docs) {
|
||||
if(docs.length == 0 || (docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || docs[0].userpass == pass))) {
|
||||
if(docs.length > 0 && docs[0].hasOwnProperty('userpass') && docs[0].userpass != "" && docs[0].userpass == pass) {
|
||||
socket.emit("auth_accepted", {value: true});
|
||||
}
|
||||
in_list = true;
|
||||
socket.join(coll);
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
if(frontpage_lists.viewers != undefined){
|
||||
io.to(coll).emit("viewers", frontpage_lists.viewers);
|
||||
} else {
|
||||
io.to(coll).emit("viewers", 1);
|
||||
}
|
||||
|
||||
List.send_list(coll, socket, true, false, true);
|
||||
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
db.createCollection(coll, function(err, docs){
|
||||
var configs = {"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": "", userpass: "", id: "config"};
|
||||
db.collection(coll + "_settings").insert(configs, function(err, docs){
|
||||
socket.join(coll);
|
||||
List.send_list(coll, socket, true, false, true);
|
||||
db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1});
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
});
|
||||
});
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
|
||||
if(gotten && userpass != "" && !msg.hasOwnProperty("pass")) {
|
||||
msg.pass = userpass;
|
||||
}
|
||||
if(!msg.hasOwnProperty('version') || !msg.hasOwnProperty("channel") ||
|
||||
msg.version != VERSION || msg.version == undefined ||
|
||||
typeof(msg.channel) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined,
|
||||
},
|
||||
version: {
|
||||
expected: VERSION,
|
||||
got: msg.version,
|
||||
},
|
||||
pass: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined,
|
||||
},
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
coll = msg.channel.toLowerCase();
|
||||
var pass = crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64");
|
||||
db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){
|
||||
if(frontpage_lists.length == 1)
|
||||
{
|
||||
db.collection(coll + "_settings").find(function(err, docs) {
|
||||
if(docs.length == 0 || (docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || docs[0].userpass == pass))) {
|
||||
if(docs.length > 0 && docs[0].hasOwnProperty('userpass') && docs[0].userpass != "" && docs[0].userpass == pass) {
|
||||
Functions.setSessionUserPass(Functions.getSession(socket), msg.pass, coll, function(){})
|
||||
socket.emit("auth_accepted", {value: true});
|
||||
}
|
||||
if(docs.length > 0 && docs[0].hasOwnProperty("adminpass") && docs[0].adminpass != "" && docs[0].adminpass == Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, adminpass), true))) {
|
||||
socket.emit("pw", true);
|
||||
}
|
||||
in_list = true;
|
||||
socket.join(coll);
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
if(frontpage_lists.viewers != undefined){
|
||||
io.to(coll).emit("viewers", frontpage_lists.viewers);
|
||||
} else {
|
||||
io.to(coll).emit("viewers", 1);
|
||||
}
|
||||
|
||||
List.send_list(coll, socket, true, false, true);
|
||||
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
db.createCollection(coll, function(err, docs){
|
||||
var configs = {"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": "", userpass: "", id: "config"};
|
||||
db.collection(coll + "_settings").insert(configs, function(err, docs){
|
||||
socket.join(coll);
|
||||
List.send_list(coll, socket, true, false, true);
|
||||
db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1});
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
@@ -109,10 +118,8 @@ function skip(list, guid, coll, offline, socket) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!list.hasOwnProperty("pass") || !list.hasOwnProperty("userpass") ||
|
||||
!list.hasOwnProperty("id") || !list.hasOwnProperty("channel") ||
|
||||
typeof(list.pass) != "string" || typeof(list.id) != "string" ||
|
||||
typeof(list.channel) != "string" || typeof(list.userpass) != "string") {
|
||||
if(!list.hasOwnProperty("id") || !list.hasOwnProperty("channel") ||
|
||||
typeof(list.id) != "string" || typeof(list.channel) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -134,72 +141,77 @@ function skip(list, guid, coll, offline, socket) {
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, list.userpass)).digest("base64")))) {
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
list.pass = adminpass;
|
||||
list.userpass = userpass;
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, list.userpass)).digest("base64")))) {
|
||||
|
||||
adminpass = "";
|
||||
video_id = list.id;
|
||||
err = list.error;
|
||||
var error = false;
|
||||
var video_id;
|
||||
if(err != "5" && err != "100" && err != "101" && err != "150")
|
||||
{
|
||||
adminpass = list.pass;
|
||||
}else if(err == "5" || err == "100" || err == "101" || err == "150"){
|
||||
error = true;
|
||||
}
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
if(adminpass !== undefined && adminpass !== null && adminpass !== "")
|
||||
hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, adminpass),true));
|
||||
else
|
||||
hash = "";
|
||||
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
|
||||
if(docs !== null && docs.length !== 0)
|
||||
adminpass = "";
|
||||
video_id = list.id;
|
||||
err = list.error;
|
||||
var error = false;
|
||||
var video_id;
|
||||
if(err != "5" && err != "100" && err != "101" && err != "150")
|
||||
{
|
||||
if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error)
|
||||
{
|
||||
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) ||
|
||||
(frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) ||
|
||||
(docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip))
|
||||
{
|
||||
List.change_song(coll, error, video_id);
|
||||
socket.emit("toast", "skip");
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 1) {
|
||||
db.collection("registered_users").find({"_id": docs[0].name}, function(err, n) {
|
||||
var icon = false;
|
||||
if(n.length > 0 && n[0].icon) {
|
||||
icon = n[0].icon;
|
||||
}
|
||||
io.to(coll).emit('chat', {from: docs[0].name, icon: icon, msg: " skipped"});
|
||||
});
|
||||
}
|
||||
});
|
||||
}else if(!Functions.contains(docs[0].skips, guid)){
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$push:{skips:guid}}, function(err, d){
|
||||
if(frontpage_viewers[0].viewers == 2)
|
||||
to_skip = 1;
|
||||
else
|
||||
to_skip = (Math.ceil(frontpage_viewers[0].viewers/2) - docs[0].skips.length-1);
|
||||
socket.emit("toast", to_skip + " more are needed to skip!");
|
||||
socket.to(coll).emit('chat', {from: name, msg: " voted to skip"});
|
||||
});
|
||||
}else{
|
||||
socket.emit("toast", "alreadyskip");
|
||||
}
|
||||
});
|
||||
}else
|
||||
socket.emit("toast", "noskip");
|
||||
adminpass = list.pass;
|
||||
}else if(err == "5" || err == "100" || err == "101" || err == "150"){
|
||||
error = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
|
||||
if(adminpass !== undefined && adminpass !== null && adminpass !== "")
|
||||
hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, adminpass),true));
|
||||
else
|
||||
hash = "";
|
||||
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
|
||||
if(docs !== null && docs.length !== 0)
|
||||
{
|
||||
if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error)
|
||||
{
|
||||
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) ||
|
||||
(frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) ||
|
||||
(docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip))
|
||||
{
|
||||
List.change_song(coll, error, video_id);
|
||||
socket.emit("toast", "skip");
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 1) {
|
||||
db.collection("registered_users").find({"_id": docs[0].name}, function(err, n) {
|
||||
var icon = false;
|
||||
if(n.length > 0 && n[0].icon) {
|
||||
icon = n[0].icon;
|
||||
}
|
||||
io.to(coll).emit('chat', {from: docs[0].name, icon: icon, msg: " skipped"});
|
||||
});
|
||||
}
|
||||
});
|
||||
}else if(!Functions.contains(docs[0].skips, guid)){
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$push:{skips:guid}}, function(err, d){
|
||||
if(frontpage_viewers[0].viewers == 2)
|
||||
to_skip = 1;
|
||||
else
|
||||
to_skip = (Math.ceil(frontpage_viewers[0].viewers/2) - docs[0].skips.length-1);
|
||||
socket.emit("toast", to_skip + " more are needed to skip!");
|
||||
socket.to(coll).emit('chat', {from: name, msg: " voted to skip"});
|
||||
});
|
||||
}else{
|
||||
socket.emit("toast", "alreadyskip");
|
||||
}
|
||||
});
|
||||
}else
|
||||
socket.emit("toast", "noskip");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
@@ -480,9 +492,8 @@ function end(obj, coll, guid, offline, socket) {
|
||||
|
||||
if(id !== undefined && id !== null && id !== "") {
|
||||
|
||||
if(!obj.hasOwnProperty("id") || !obj.hasOwnProperty("channel") || !obj.hasOwnProperty("pass") ||
|
||||
typeof(obj.id) != "string" || typeof(obj.channel) != "string" ||
|
||||
typeof(obj.pass) != "string") {
|
||||
if(!obj.hasOwnProperty("id") || !obj.hasOwnProperty("channel") ||
|
||||
typeof(obj.id) != "string" || typeof(obj.channel) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -500,34 +511,37 @@ function end(obj, coll, guid, offline, socket) {
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) {
|
||||
obj.pass = userpass;
|
||||
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, obj.pass)).digest("base64")))) {
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, obj.pass)).digest("base64")))) {
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
db.collection(coll).find({now_playing:true}, function(err, np){
|
||||
if(err !== null) console.log(err);
|
||||
if(np !== null && np !== undefined && np.length == 1 && np[0].id == id){
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
var startTime = docs[0].startTime;
|
||||
if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=Functions.get_time()+5)
|
||||
{
|
||||
db.collection(coll).remove({now_playing:true}, function(err, docs){
|
||||
List.change_song_post(coll);
|
||||
db.collection("frontpage_lists").update({_id:coll, count: {$gt: 0}}, {$inc:{count:-1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
|
||||
});
|
||||
}else{
|
||||
if(startTime+parseInt(np[0].duration)<=Functions.get_time()+5)
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
db.collection(coll).find({now_playing:true}, function(err, np){
|
||||
if(err !== null) console.log(err);
|
||||
if(np !== null && np !== undefined && np.length == 1 && np[0].id == id){
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
var startTime = docs[0].startTime;
|
||||
if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=Functions.get_time()+5)
|
||||
{
|
||||
List.change_song(coll, false, id);
|
||||
db.collection(coll).remove({now_playing:true}, function(err, docs){
|
||||
List.change_song_post(coll);
|
||||
db.collection("frontpage_lists").update({_id:coll, count: {$gt: 0}}, {$inc:{count:-1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
|
||||
});
|
||||
}else{
|
||||
if(startTime+parseInt(np[0].duration)<=Functions.get_time()+5)
|
||||
{
|
||||
List.change_song(coll, false, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
|
||||
@@ -43,8 +43,7 @@ function add_function(arr, coll, guid, offline, socket) {
|
||||
typeof(arr.end) != "number" || typeof(arr.title) != "string" ||
|
||||
typeof(arr.list) != "string" || typeof(arr.duration) != "number" ||
|
||||
typeof(arr.playlist) != "boolean" || typeof(arr.num) != "number" ||
|
||||
typeof(arr.total) != "number" || typeof(arr.pass) != "string" ||
|
||||
typeof(arr.adminpass) != "string") {
|
||||
typeof(arr.total) != "number") {
|
||||
var result = {
|
||||
start: {
|
||||
expected: "number or string that can be cast to int",
|
||||
@@ -90,143 +89,146 @@ function add_function(arr, coll, guid, offline, socket) {
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
arr.adminpass = adminpass;
|
||||
arr.userpass = userpass;
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, arr.pass)).digest("base64")))) {
|
||||
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, arr.pass)).digest("base64")))) {
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
var id = arr.id;
|
||||
var title = arr.title;
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, arr.adminpass), true));
|
||||
var duration = parseInt(arr.duration);
|
||||
var full_list = arr.playlist;
|
||||
var last = arr.num == arr.total - 1;
|
||||
var num = arr.num;
|
||||
var total = arr.total;
|
||||
/*db.collection(coll + "_settings").find(function(err, docs)
|
||||
{*/
|
||||
conf = docs;
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].addsongs === false))
|
||||
{
|
||||
db.collection(coll).find({id:id, type:{$ne:"suggested"}}, function(err, docs){
|
||||
if(docs !== null && docs.length === 0)
|
||||
{
|
||||
var guids = full_list === true ? [] : [guid];
|
||||
var votes;
|
||||
var added;
|
||||
if(full_list) {
|
||||
var time = Functions.get_time()-total;
|
||||
time = time.toString();
|
||||
var total_len = total.toString().length;
|
||||
var now_len = num.toString().length;
|
||||
var to_add = num.toString();
|
||||
while(now_len < total_len) {
|
||||
to_add = "0" + to_add;
|
||||
now_len = to_add.length;
|
||||
var id = arr.id;
|
||||
var title = arr.title;
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, arr.adminpass), true));
|
||||
var duration = parseInt(arr.duration);
|
||||
var full_list = arr.playlist;
|
||||
var last = arr.num == arr.total - 1;
|
||||
var num = arr.num;
|
||||
var total = arr.total;
|
||||
/*db.collection(coll + "_settings").find(function(err, docs)
|
||||
{*/
|
||||
conf = docs;
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].addsongs === false))
|
||||
{
|
||||
db.collection(coll).find({id:id, type:{$ne:"suggested"}}, function(err, docs){
|
||||
if(docs !== null && docs.length === 0)
|
||||
{
|
||||
var guids = full_list === true ? [] : [guid];
|
||||
var votes;
|
||||
var added;
|
||||
if(full_list) {
|
||||
var time = Functions.get_time()-total;
|
||||
time = time.toString();
|
||||
var total_len = total.toString().length;
|
||||
var now_len = num.toString().length;
|
||||
var to_add = num.toString();
|
||||
while(now_len < total_len) {
|
||||
to_add = "0" + to_add;
|
||||
now_len = to_add.length;
|
||||
}
|
||||
time = time.substring(0, time.length - total_len);
|
||||
time = time + to_add;
|
||||
time = parseInt(time);
|
||||
added = time;
|
||||
votes = 0;
|
||||
} else {
|
||||
added = Functions.get_time();
|
||||
votes = 1;
|
||||
}
|
||||
time = time.substring(0, time.length - total_len);
|
||||
time = time + to_add;
|
||||
time = parseInt(time);
|
||||
added = time;
|
||||
votes = 0;
|
||||
} else {
|
||||
added = Functions.get_time();
|
||||
votes = 1;
|
||||
}
|
||||
|
||||
db.collection(coll).find({now_playing:true}, function(err, docs){
|
||||
if((docs !== null && docs.length === 0)){
|
||||
np = true;
|
||||
if(full_list && num === 0){
|
||||
db.collection(coll).find({now_playing:true}, function(err, docs){
|
||||
if((docs !== null && docs.length === 0)){
|
||||
np = true;
|
||||
time = time.toString();
|
||||
total += 1;
|
||||
var total_len = total.toString().length;
|
||||
var now_len = total.toString().length;
|
||||
var to_add = total.toString();
|
||||
while(now_len < total_len) {
|
||||
to_add = "0" + to_add;
|
||||
now_len = to_add.length;
|
||||
if(full_list && num === 0){
|
||||
np = true;
|
||||
time = time.toString();
|
||||
total += 1;
|
||||
var total_len = total.toString().length;
|
||||
var now_len = total.toString().length;
|
||||
var to_add = total.toString();
|
||||
while(now_len < total_len) {
|
||||
to_add = "0" + to_add;
|
||||
now_len = to_add.length;
|
||||
}
|
||||
time = time.substring(0, time.length - total_len);
|
||||
time = parseInt(time).toString() + to_add;
|
||||
time = parseInt(time);
|
||||
added = time;
|
||||
votes = 0;
|
||||
} else if(full_list) {
|
||||
np = false;
|
||||
}
|
||||
time = time.substring(0, time.length - total_len);
|
||||
time = parseInt(time).toString() + to_add;
|
||||
time = parseInt(time);
|
||||
added = time;
|
||||
votes = 0;
|
||||
} else if(full_list) {
|
||||
} else {
|
||||
np = false;
|
||||
}
|
||||
} else {
|
||||
np = false;
|
||||
}
|
||||
var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end), "type": "video"};
|
||||
db.collection(coll).update({id: id}, new_song, {upsert: true}, function(err, docs){
|
||||
new_song._id = "asd";
|
||||
if(np) {
|
||||
List.send_list(coll, undefined, false, true, false);
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$set:{startTime: Functions.get_time()}});
|
||||
List.send_play(coll, undefined);
|
||||
Frontpage.update_frontpage(coll, id, title);
|
||||
if(!full_list) Search.get_correct_info(new_song, coll, false);
|
||||
} else {
|
||||
io.to(coll).emit("channel", {type: "added", value: new_song});
|
||||
if(!full_list) Search.get_correct_info(new_song, coll, true);
|
||||
var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end), "type": "video"};
|
||||
db.collection(coll).update({id: id}, new_song, {upsert: true}, function(err, docs){
|
||||
new_song._id = "asd";
|
||||
if(np) {
|
||||
List.send_list(coll, undefined, false, true, false);
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$set:{startTime: Functions.get_time()}});
|
||||
List.send_play(coll, undefined);
|
||||
Frontpage.update_frontpage(coll, id, title);
|
||||
if(!full_list) Search.get_correct_info(new_song, coll, false);
|
||||
} else {
|
||||
io.to(coll).emit("channel", {type: "added", value: new_song});
|
||||
if(!full_list) Search.get_correct_info(new_song, coll, true);
|
||||
}
|
||||
db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
|
||||
List.getNextSong(coll);
|
||||
});
|
||||
if(!full_list) {
|
||||
socket.emit("toast", "addedsong");
|
||||
} else if(full_list && last) {
|
||||
socket.emit("toast", "addedplaylist");
|
||||
}
|
||||
db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
|
||||
List.getNextSong(coll);
|
||||
});
|
||||
if(!full_list) {
|
||||
socket.emit("toast", "addedsong");
|
||||
} else if(full_list && last) {
|
||||
} else if(!full_list) {
|
||||
ListChange.vote(coll, id, guid, socket, full_list, last);
|
||||
if(full_list && last) {
|
||||
socket.emit("toast", "addedplaylist");
|
||||
}
|
||||
});
|
||||
} else if(!full_list) {
|
||||
ListChange.vote(coll, id, guid, socket, full_list, last);
|
||||
if(full_list && last) {
|
||||
} else if(full_list && last) {
|
||||
socket.emit("toast", "addedplaylist");
|
||||
}
|
||||
} else if(full_list && last) {
|
||||
socket.emit("toast", "addedplaylist");
|
||||
});
|
||||
} else if(!full_list) {
|
||||
db.collection(coll).find({id: id}, function(err, docs) {
|
||||
if(docs.length === 0) {
|
||||
db.collection(coll).update({id: id}, {$set:{
|
||||
"added":Functions.get_time(),
|
||||
"guids": [guid],
|
||||
"id":id,
|
||||
"now_playing": false,
|
||||
"title":title,
|
||||
"votes":1,
|
||||
"duration":duration,
|
||||
"start": start,
|
||||
"end": end,
|
||||
"type":"suggested"}
|
||||
},
|
||||
{upsert:true}, function(err, docs){
|
||||
socket.emit("toast", "suggested");
|
||||
io.to(coll).emit("suggested", {id: id, title: title, duration: duration});
|
||||
});
|
||||
} else if(docs[0].now_playing === true){
|
||||
socket.emit("toast", "alreadyplay");
|
||||
} else{
|
||||
if(conf[0].vote === false) ListChange.vote(coll, id, guid, socket, full_list, last);
|
||||
else socket.emit("toast", "listhaspass");
|
||||
}
|
||||
});
|
||||
} else if (full_list){
|
||||
if(arr.num == 0) {
|
||||
socket.emit("toast", "listhaspass");
|
||||
}
|
||||
});
|
||||
} else if(!full_list) {
|
||||
db.collection(coll).find({id: id}, function(err, docs) {
|
||||
if(docs.length === 0) {
|
||||
db.collection(coll).update({id: id}, {$set:{
|
||||
"added":Functions.get_time(),
|
||||
"guids": [guid],
|
||||
"id":id,
|
||||
"now_playing": false,
|
||||
"title":title,
|
||||
"votes":1,
|
||||
"duration":duration,
|
||||
"start": start,
|
||||
"end": end,
|
||||
"type":"suggested"}
|
||||
},
|
||||
{upsert:true}, function(err, docs){
|
||||
socket.emit("toast", "suggested");
|
||||
io.to(coll).emit("suggested", {id: id, title: title, duration: duration});
|
||||
});
|
||||
} else if(docs[0].now_playing === true){
|
||||
socket.emit("toast", "alreadyplay");
|
||||
} else{
|
||||
if(conf[0].vote === false) ListChange.vote(coll, id, guid, socket, full_list, last);
|
||||
else socket.emit("toast", "listhaspass");
|
||||
}
|
||||
});
|
||||
} else if (full_list){
|
||||
if(arr.num == 0) {
|
||||
socket.emit("toast", "listhaspass");
|
||||
}
|
||||
}
|
||||
//});
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
//});
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
@@ -248,10 +250,8 @@ function voteUndecided(msg, coll, guid, offline, socket) {
|
||||
if(typeof(msg) === 'object' && msg !== undefined && msg !== null){
|
||||
|
||||
if(!msg.hasOwnProperty("channel") || !msg.hasOwnProperty("id") ||
|
||||
!msg.hasOwnProperty("type") || !msg.hasOwnProperty("adminpass") ||
|
||||
!msg.hasOwnProperty("pass") || typeof(msg.pass) != "string" ||
|
||||
typeof(msg.channel) != "string" || typeof(msg.id) != "string" ||
|
||||
typeof(msg.type) != "string" || typeof(msg.adminpass) != "string") {
|
||||
!msg.hasOwnProperty("type") || typeof(msg.channel) != "string" ||
|
||||
typeof(msg.id) != "string" || typeof(msg.type) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -278,27 +278,31 @@ function voteUndecided(msg, coll, guid, offline, socket) {
|
||||
return;
|
||||
}
|
||||
coll = msg.channel.toLowerCase();;
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
msg.adminpass = adminpass;
|
||||
msg.pass = userpass;
|
||||
|
||||
db.collection(coll + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64")))) {
|
||||
db.collection(coll + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64")))) {
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
if(msg.type == "del") {
|
||||
ListChange.del(msg, socket, socketid);
|
||||
} else {
|
||||
var id = msg.id;
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass), true));
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].vote === false)) {
|
||||
ListChange.vote(coll, id, guid, socket, false, false);
|
||||
if(msg.type == "del") {
|
||||
ListChange.del(msg, socket, socketid);
|
||||
} else {
|
||||
socket.emit("toast", "listhaspass");
|
||||
var id = msg.id;
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass), true));
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].vote === false)) {
|
||||
ListChange.vote(coll, id, guid, socket, false, false);
|
||||
} else {
|
||||
socket.emit("toast", "listhaspass");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
@@ -315,9 +319,7 @@ function shuffle(msg, coll, guid, offline, socket) {
|
||||
var socketid = socket.zoff_id;
|
||||
|
||||
|
||||
if(!msg.hasOwnProperty("adminpass") || !msg.hasOwnProperty("channel") ||
|
||||
!msg.hasOwnProperty("pass") || typeof(msg.adminpass) != "string" ||
|
||||
typeof(msg.channel) != "string" || typeof(msg.pass) != "string") {
|
||||
if(!msg.hasOwnProperty("channel") || typeof(msg.channel) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -337,61 +339,65 @@ function shuffle(msg, coll, guid, offline, socket) {
|
||||
}
|
||||
coll = msg.channel.toLowerCase();
|
||||
|
||||
db.collection("timeout_api").find({
|
||||
type: "shuffle",
|
||||
guid: coll,
|
||||
}, function(err, docs) {
|
||||
if(docs.length > 0) {
|
||||
var date = new Date(docs[0].createdAt);
|
||||
date.setSeconds(date.getSeconds() + 5);
|
||||
var now = new Date();
|
||||
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
||||
if(retry_in > 0) {
|
||||
socket.emit("toast", "wait_longer");
|
||||
return;
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
msg.adminpass = adminpass;
|
||||
msg.pass = userpass;
|
||||
db.collection("timeout_api").find({
|
||||
type: "shuffle",
|
||||
guid: coll,
|
||||
}, function(err, docs) {
|
||||
if(docs.length > 0) {
|
||||
var date = new Date(docs[0].createdAt);
|
||||
date.setSeconds(date.getSeconds() + 5);
|
||||
var now = new Date();
|
||||
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
||||
if(retry_in > 0) {
|
||||
socket.emit("toast", "wait_longer");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
var now_date = new Date();
|
||||
db.collection("timeout_api").update({type: "shuffle", guid: coll}, {
|
||||
$set: {
|
||||
"createdAt": now_date,
|
||||
type: "shuffle",
|
||||
guid: coll,
|
||||
},
|
||||
}, {upsert: true}, function(err, docs) {
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
var hash;
|
||||
if(msg.adminpass === "") hash = msg.adminpass;
|
||||
else hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass),true));
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64")))) {
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash || docs[0].adminpass === "") || docs[0].shuffle === false))
|
||||
var now_date = new Date();
|
||||
db.collection("timeout_api").update({type: "shuffle", guid: coll}, {
|
||||
$set: {
|
||||
"createdAt": now_date,
|
||||
type: "shuffle",
|
||||
guid: coll,
|
||||
},
|
||||
}, {upsert: true}, function(err, docs) {
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
var hash;
|
||||
if(msg.adminpass === "") hash = msg.adminpass;
|
||||
else hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass),true));
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64")))) {
|
||||
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){
|
||||
if(!docs){
|
||||
List.send_list(coll, undefined, false, true, false, true);
|
||||
socket.emit("toast", "shuffled");
|
||||
|
||||
return;
|
||||
}else{
|
||||
num = Math.floor(Math.random()*1000000);
|
||||
db.collection(coll).update({id:docs.id}, {$set:{added:num}});
|
||||
}
|
||||
});
|
||||
}else
|
||||
socket.emit("toast", "wrongpass");
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
|
||||
var complete = function(tot, curr){
|
||||
if(tot == curr)
|
||||
{
|
||||
db.collection(coll).find({now_playing:false}).forEach(function(err, docs){
|
||||
if(!docs){
|
||||
List.send_list(coll, undefined, false, true, false, true);
|
||||
socket.emit("toast", "shuffled");
|
||||
|
||||
return;
|
||||
}else{
|
||||
num = Math.floor(Math.random()*1000000);
|
||||
db.collection(coll).update({id:docs.id}, {$set:{added:num}});
|
||||
}
|
||||
});
|
||||
}else
|
||||
socket.emit("toast", "wrongpass");
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
List.send_list(coll, undefined, false, true, false);
|
||||
List.getNextSong(coll);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var complete = function(tot, curr){
|
||||
if(tot == curr)
|
||||
{
|
||||
List.send_list(coll, undefined, false, true, false);
|
||||
List.getNextSong(coll);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -427,9 +433,7 @@ function del(params, socket, socketid) {
|
||||
function delete_all(msg, coll, guid, offline, socket) {
|
||||
var socketid = socket.zoff_id;
|
||||
if(typeof(msg) == 'object' ) {
|
||||
if(!msg.hasOwnProperty('channel') || !msg.hasOwnProperty('adminpass') ||
|
||||
!msg.hasOwnProperty('pass') || typeof(msg.channel) != "string" ||
|
||||
typeof(msg.adminpass) != "string" || typeof(msg.pass) != "string") {
|
||||
if(!msg.hasOwnProperty('channel') || typeof(msg.channel) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -447,22 +451,25 @@ function delete_all(msg, coll, guid, offline, socket) {
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass),true));
|
||||
var hash_userpass = crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64");
|
||||
db.collection(coll + "_settings").find(function(err, conf) {
|
||||
if(conf.length == 1 && conf) {
|
||||
conf = conf[0];
|
||||
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) {
|
||||
List.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) {});
|
||||
socket.emit("toast", "deleted_songs");
|
||||
});
|
||||
} else {
|
||||
socket.emit("toast", "listhaspass");
|
||||
}
|
||||
}
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
|
||||
msg.adminpass = adminpass;
|
||||
msg.pass = userpass;
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass),true));
|
||||
var hash_userpass = crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64");
|
||||
db.collection(coll + "_settings").find(function(err, conf) {
|
||||
if(conf.length == 1 && conf) {
|
||||
conf = conf[0];
|
||||
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) {
|
||||
List.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) {});
|
||||
socket.emit("toast", "deleted_songs");
|
||||
});
|
||||
} else {
|
||||
socket.emit("toast", "listhaspass");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
function password(inp, coll, guid, offline, socket) {
|
||||
var sessionId = Functions.getSession(socket);
|
||||
if(sessionId == "") sessionId = "empty";
|
||||
if(inp !== undefined && inp !== null && inp !== "")
|
||||
{
|
||||
if(!inp.hasOwnProperty("password") || !inp.hasOwnProperty("channel") ||
|
||||
@@ -17,7 +19,6 @@ function password(inp, coll, guid, offline, socket) {
|
||||
return;
|
||||
}
|
||||
pw = inp.password;
|
||||
opw = inp.password;
|
||||
try {
|
||||
coll = inp.channel;
|
||||
if(coll.length == 0) return;
|
||||
@@ -32,28 +33,40 @@ function password(inp, coll, guid, offline, socket) {
|
||||
uncrypted = pw;
|
||||
pw = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, pw), true);
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
if(inp.oldpass)
|
||||
{
|
||||
opw = inp.oldpass;
|
||||
}
|
||||
opw = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, opw), true);
|
||||
Functions.getSessionAdminUser(sessionId, coll, function(userpass, adminpass) {
|
||||
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs !== null && docs.length !== 0)
|
||||
{
|
||||
if(docs[0].adminpass === "" || docs[0].adminpass == Functions.hash_pass(opw))
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs !== null && docs.length !== 0)
|
||||
{
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){
|
||||
if(inp.oldpass)
|
||||
socket.emit("toast", "changedpass");
|
||||
else
|
||||
socket.emit("toast", "correctpass");
|
||||
socket.emit("pw", true);
|
||||
});
|
||||
}else
|
||||
socket.emit("toast", "wrongpass");
|
||||
socket.emit("pw", false);
|
||||
}
|
||||
if(docs[0].adminpass === "" || docs[0].adminpass == Functions.hash_pass(pw))
|
||||
{
|
||||
Functions.setSessionAdminPass(sessionId, inp.password, coll, function() {
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){
|
||||
if(adminpass != pw) {
|
||||
socket.emit("toast", "changedpass");
|
||||
} else {
|
||||
socket.emit("toast", "correctpass");
|
||||
}
|
||||
socket.emit("pw", true);
|
||||
});
|
||||
});
|
||||
} else if(docs[0].adminpass === "" || docs[0].adminpass == Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, adminpass), true))) {
|
||||
Functions.setSessionAdminPass(sessionId, inp.password, coll, function() {
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){
|
||||
if(adminpass != pw) {
|
||||
socket.emit("toast", "changedpass");
|
||||
}
|
||||
socket.emit("pw", true);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
Functions.setSessionAdminPass(Functions.getSession(socket), "", coll, function() {
|
||||
socket.emit("toast", "wrongpass");
|
||||
socket.emit("pw", false);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
@@ -89,125 +102,133 @@ function conf_function(params, coll, guid, offline, socket) {
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
|
||||
if(gotten) {
|
||||
params.adminpass = adminpass;
|
||||
if(!params.userpass_changed) params.userpass = userpass;
|
||||
|
||||
if(!params.hasOwnProperty('voting') || !params.hasOwnProperty('addsongs') ||
|
||||
!params.hasOwnProperty('longsongs') || !params.hasOwnProperty('frontpage') ||
|
||||
!params.hasOwnProperty('allvideos') || !params.hasOwnProperty('removeplay') ||
|
||||
!params.hasOwnProperty('adminpass') || !params.hasOwnProperty('skipping') ||
|
||||
!params.hasOwnProperty('shuffling') || !params.hasOwnProperty('channel') ||
|
||||
typeof(params.userpass) != "string" || typeof(params.adminpass) != "string" ||
|
||||
typeof(params.voting) != "boolean" || typeof(params.addsongs) != "boolean" ||
|
||||
typeof(params.longsongs) != "boolean" || typeof(params.frontpage) != "boolean" ||
|
||||
typeof(params.allvideos) != "boolean" || typeof(params.removeplay) != "boolean" ||
|
||||
typeof(params.skipping) != "boolean" || typeof(params.shuffling) != "boolean" ||
|
||||
typeof(params.userpass_changed) != "boolean") {
|
||||
var result = {
|
||||
adminpass: {
|
||||
expected: "string",
|
||||
got: params.hasOwnProperty("adminpass") ? typeof(params.adminpass) : undefined,
|
||||
},
|
||||
userpass: {
|
||||
expected: "string",
|
||||
got: params.hasOwnProperty("userpass") ? typeof(params.userpass) : undefined,
|
||||
},
|
||||
vote: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("vote") ? typeof(params.vote) : undefined,
|
||||
},
|
||||
addsongs: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("addsongs") ? typeof(params.addsongs) : undefined,
|
||||
},
|
||||
longsongs: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("longsongs") ? typeof(params.longsongs) : undefined,
|
||||
},
|
||||
frontpage: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("frontpage") ? typeof(params.frontpage) : undefined,
|
||||
},
|
||||
skipping: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("skipping") ? typeof(params.skipping) : undefined,
|
||||
},
|
||||
shuffling: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("shuffling") ? typeof(params.shuffling) : undefined,
|
||||
},
|
||||
userpass_changed: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("userpass_changed") ? typeof(params.userpass_changed) : undefined,
|
||||
}
|
||||
};
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
var voting = params.voting;
|
||||
var addsongs = params.addsongs;
|
||||
var longsongs = params.longsongs;
|
||||
var frontpage = params.frontpage;
|
||||
var allvideos = params.allvideos;
|
||||
var removeplay = params.removeplay;
|
||||
var adminpass = params.adminpass;
|
||||
var skipping = params.skipping;
|
||||
var shuffling = params.shuffling;
|
||||
var userpass = Functions.decrypt_string(socket.zoff_id, params.userpass);
|
||||
|
||||
|
||||
if((!params.userpass_changed && frontpage) || (params.userpass_changed && userpass == "")) {
|
||||
userpass = "";
|
||||
} else if(params.userpass_changed && userpass != "") {
|
||||
frontpage = false;
|
||||
}
|
||||
var description = "";
|
||||
var hash;
|
||||
if(params.description) description = params.description;
|
||||
if(adminpass !== "") {
|
||||
hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, adminpass), true));
|
||||
} else {
|
||||
hash = adminpass;
|
||||
}
|
||||
if(userpass != "") {
|
||||
userpass = crypto.createHash('sha256').update(userpass).digest("base64");
|
||||
}
|
||||
db.collection(coll + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs !== null && docs.length !== 0 && (docs[0].adminpass === "" || docs[0].adminpass == hash)) {
|
||||
var obj = {
|
||||
addsongs:addsongs,
|
||||
allvideos:allvideos,
|
||||
frontpage:frontpage,
|
||||
skip:skipping,
|
||||
vote:voting,
|
||||
removeplay:removeplay,
|
||||
shuffle:shuffling,
|
||||
longsongs:longsongs,
|
||||
adminpass:hash,
|
||||
desc: description,
|
||||
};
|
||||
if(params.userpass_changed) {
|
||||
obj["userpass"] = userpass;
|
||||
} else if (frontpage) {
|
||||
obj["userpass"] = "";
|
||||
}
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {
|
||||
$set:obj
|
||||
}, function(err, docs){
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||
else docs[0].userpass = false;
|
||||
io.to(coll).emit("conf", docs);
|
||||
socket.emit("toast", "savedsettings");
|
||||
|
||||
db.collection("frontpage_lists").update({_id: coll}, {$set:{
|
||||
frontpage:frontpage, accessed: Functions.get_time()}
|
||||
if(!params.hasOwnProperty('voting') || !params.hasOwnProperty('addsongs') ||
|
||||
!params.hasOwnProperty('longsongs') || !params.hasOwnProperty('frontpage') ||
|
||||
!params.hasOwnProperty('allvideos') || !params.hasOwnProperty('removeplay') ||
|
||||
!params.hasOwnProperty('adminpass') || !params.hasOwnProperty('skipping') ||
|
||||
!params.hasOwnProperty('shuffling') || !params.hasOwnProperty('channel') ||
|
||||
typeof(params.userpass) != "string" || typeof(params.adminpass) != "string" ||
|
||||
typeof(params.voting) != "boolean" || typeof(params.addsongs) != "boolean" ||
|
||||
typeof(params.longsongs) != "boolean" || typeof(params.frontpage) != "boolean" ||
|
||||
typeof(params.allvideos) != "boolean" || typeof(params.removeplay) != "boolean" ||
|
||||
typeof(params.skipping) != "boolean" || typeof(params.shuffling) != "boolean" ||
|
||||
typeof(params.userpass_changed) != "boolean") {
|
||||
var result = {
|
||||
adminpass: {
|
||||
expected: "string",
|
||||
got: params.hasOwnProperty("adminpass") ? typeof(params.adminpass) : undefined,
|
||||
},
|
||||
{upsert:true}, function(err, docs){});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
socket.emit("toast", "wrongpass");
|
||||
userpass: {
|
||||
expected: "string",
|
||||
got: params.hasOwnProperty("userpass") ? typeof(params.userpass) : undefined,
|
||||
},
|
||||
vote: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("vote") ? typeof(params.vote) : undefined,
|
||||
},
|
||||
addsongs: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("addsongs") ? typeof(params.addsongs) : undefined,
|
||||
},
|
||||
longsongs: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("longsongs") ? typeof(params.longsongs) : undefined,
|
||||
},
|
||||
frontpage: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("frontpage") ? typeof(params.frontpage) : undefined,
|
||||
},
|
||||
skipping: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("skipping") ? typeof(params.skipping) : undefined,
|
||||
},
|
||||
shuffling: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("shuffling") ? typeof(params.shuffling) : undefined,
|
||||
},
|
||||
userpass_changed: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("userpass_changed") ? typeof(params.userpass_changed) : undefined,
|
||||
}
|
||||
};
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
var voting = params.voting;
|
||||
var addsongs = params.addsongs;
|
||||
var longsongs = params.longsongs;
|
||||
var frontpage = params.frontpage;
|
||||
var allvideos = params.allvideos;
|
||||
var removeplay = params.removeplay;
|
||||
var adminpass = params.adminpass;
|
||||
var skipping = params.skipping;
|
||||
var shuffling = params.shuffling;
|
||||
var userpass = Functions.decrypt_string(socket.zoff_id, params.userpass);
|
||||
|
||||
|
||||
if((!params.userpass_changed && frontpage) || (params.userpass_changed && userpass == "")) {
|
||||
userpass = "";
|
||||
} else if(params.userpass_changed && userpass != "") {
|
||||
frontpage = false;
|
||||
}
|
||||
var description = "";
|
||||
var hash;
|
||||
if(params.description) description = params.description;
|
||||
if(adminpass !== "") {
|
||||
hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, adminpass), true));
|
||||
} else {
|
||||
hash = adminpass;
|
||||
}
|
||||
if(userpass != "") {
|
||||
userpass = crypto.createHash('sha256').update(userpass).digest("base64");
|
||||
}
|
||||
db.collection(coll + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs !== null && docs.length !== 0 && (docs[0].adminpass === "" || docs[0].adminpass == hash)) {
|
||||
var obj = {
|
||||
addsongs:addsongs,
|
||||
allvideos:allvideos,
|
||||
frontpage:frontpage,
|
||||
skip:skipping,
|
||||
vote:voting,
|
||||
removeplay:removeplay,
|
||||
shuffle:shuffling,
|
||||
longsongs:longsongs,
|
||||
adminpass:hash,
|
||||
desc: description,
|
||||
};
|
||||
if(params.userpass_changed) {
|
||||
obj["userpass"] = userpass;
|
||||
} else if (frontpage) {
|
||||
obj["userpass"] = "";
|
||||
}
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {
|
||||
$set:obj
|
||||
}, function(err, docs){
|
||||
Functions.setSessionUserPass(Functions.getSession(socket), params.userpass, coll, function() {
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||
else docs[0].userpass = false;
|
||||
io.to(coll).emit("conf", docs);
|
||||
socket.emit("toast", "savedsettings");
|
||||
|
||||
db.collection("frontpage_lists").update({_id: coll}, {$set:{
|
||||
frontpage:frontpage, accessed: Functions.get_time()}
|
||||
},
|
||||
{upsert:true}, function(err, docs){});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
socket.emit("toast", "wrongpass");
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
@@ -218,6 +239,7 @@ function conf_function(params, coll, guid, offline, socket) {
|
||||
}
|
||||
socket.emit('update_required', result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.password = password;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function thumbnail(msg, coll, guid, offline, socket) {
|
||||
if(msg.thumbnail && msg.channel && msg.adminpass && msg.thumbnail.indexOf("i.imgur.com") > -1){
|
||||
if(typeof(msg.channel) != "string" || typeof(msg.thumbnail) != "string" ||
|
||||
typeof(msg.adminpass) != "string" || typeof(msg.pass) != "string") {
|
||||
if(msg.thumbnail && msg.channel && msg.thumbnail.indexOf("i.imgur.com") > -1){
|
||||
if(typeof(msg.channel) != "string" || typeof(msg.thumbnail) != "string")
|
||||
{
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -23,21 +23,26 @@ function thumbnail(msg, coll, guid, offline, socket) {
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, "");
|
||||
if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail;
|
||||
var channel = msg.channel.toLowerCase();
|
||||
var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass));
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64")))) {
|
||||
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){
|
||||
Notifications.requested_change("thumbnail", msg.thumbnail, channel);
|
||||
socket.emit("toast", "suggested_thumbnail");
|
||||
});
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
msg.userpass = userpass;
|
||||
msg.adminpass = adminpass;
|
||||
|
||||
msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, "");
|
||||
if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail;
|
||||
var channel = msg.channel.toLowerCase();
|
||||
var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass));
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64")))) {
|
||||
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){
|
||||
Notifications.requested_change("thumbnail", msg.thumbnail, channel);
|
||||
socket.emit("toast", "suggested_thumbnail");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
socket.emit("toast", "thumbnail_denied");
|
||||
@@ -45,9 +50,8 @@ function thumbnail(msg, coll, guid, offline, socket) {
|
||||
}
|
||||
|
||||
function description(msg, coll, guid, offline, socket) {
|
||||
if(msg.description && msg.channel && msg.adminpass && msg.description.length < 100){
|
||||
if(typeof(msg.channel) != "string" || typeof(msg.description) != "string" ||
|
||||
typeof(msg.adminpass) != "string" || typeof(msg.pass) != "string") {
|
||||
if(msg.description && msg.channel && msg.description.length < 100){
|
||||
if(typeof(msg.channel) != "string" || typeof(msg.description) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -69,19 +73,24 @@ function description(msg, coll, guid, offline, socket) {
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
var channel = msg.channel.toLowerCase();
|
||||
var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass));
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64")))) {
|
||||
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){
|
||||
Notifications.requested_change("description", msg.description, channel);
|
||||
socket.emit("toast", "suggested_description");
|
||||
});
|
||||
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
|
||||
msg.userpass = userpass;
|
||||
msg.adminpass = adminpass;
|
||||
var channel = msg.channel.toLowerCase();
|
||||
var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass));
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64")))) {
|
||||
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){
|
||||
Notifications.requested_change("description", msg.description, channel);
|
||||
socket.emit("toast", "suggested_description");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
socket.emit("toast", "description_denied");
|
||||
|
||||
Reference in New Issue
Block a user