diff --git a/server/EVENTS.md b/server/EVENTS.md index a453c152..b1cd6d2d 100644 --- a/server/EVENTS.md +++ b/server/EVENTS.md @@ -35,6 +35,14 @@ pass: Base64(channel_pass) } +// Imports songs from another zoff-channel +'import_zoff', { + channel: CHANNELNAME, + new_channel: CHANNELNAME-TO-IMPORT-FROM, + adminpass: Base64(PASSWORD), + userpass: Bse64(CHANNEL_PASSWORD) +} + // Tells the server to disconnect the user from the current channel, is used for remote controlling on the host side 'change_channel', { channel: channel_name diff --git a/server/apps/addtype.js b/server/apps/addtype.js index 7891c7c3..e3ca0e98 100644 --- a/server/apps/addtype.js +++ b/server/apps/addtype.js @@ -6,7 +6,7 @@ var settings = []; db.getCollectionNames(function(err, docs) { for(var i = 0; i < docs.length; i++) { - if(docs[i].indexOf("_settings")) { + if(docs[i].indexOf("_settings") == -1) { t(docs[i]); } } @@ -26,10 +26,12 @@ db.getCollectionNames(function(err, docs) { }) function t(docs) { - db.collection(docs).find({id: "config"}, function(e, _docs) { - if(_docs.length > 0 && _docs[0].userpass == undefined) { - console.log(docs); - }) + db.collection(docs).find({id: {$exists: true}}, function(e, _docs) { + if(_docs.length > 0) { + db.collection(docs).createIndex({id: 1}, {unique: true}, function(e,d){ + console.log(docs); + }); + } }) } diff --git a/server/apps/client.js b/server/apps/client.js index 49023020..9b551460 100755 --- a/server/apps/client.js +++ b/server/apps/client.js @@ -95,14 +95,12 @@ app.use(function (req, res, next) { maxAge: 365 * 10000 * 3600000, httpOnly: true, secure: secure, - domain: "zoff.me" }); } else { res.cookie('_uI', cookie, { maxAge: 365 * 10000 * 3600000, httpOnly: true, secure: secure, - domain: "zoff.me" }); } res.header("Access-Control-Allow-Origin", "*"); diff --git a/server/handlers/chat.js b/server/handlers/chat.js index 1255eb2b..be11ab8c 100644 --- a/server/handlers/chat.js +++ b/server/handlers/chat.js @@ -14,7 +14,9 @@ function get_history(channel, all, socket) { var pass = ""; if(!query.all) { Functions.getSessionAdminUser(Functions.getSession(socket), channel, function(userpass) { - pass = userpass; + if(userpass != "" || pass == undefined) { + 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')) { @@ -66,7 +68,9 @@ function chat(msg, guid, offline, socket) { } var coll = msg.channel.toLowerCase().replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) { - msg.pass = userpass; + if(userpass != "" || msg.pass == undefined) { + 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; diff --git a/server/handlers/functions.js b/server/handlers/functions.js index 8d481241..4d262619 100644 --- a/server/handlers/functions.js +++ b/server/handlers/functions.js @@ -227,7 +227,6 @@ function setSessionUserPass(id, userpass, list, callback) { callback(); return; } - connected_db.collection(id).update({_id: list}, {$set: {userpass: userpass}}, {upsert: true}, function(e, d){ callback(); return; diff --git a/server/handlers/io.js b/server/handlers/io.js index 18f12e25..bae1bbfb 100644 --- a/server/handlers/io.js +++ b/server/handlers/io.js @@ -233,6 +233,10 @@ module.exports = function() { Frontpage.frontpage_lists(msg, socket); }); + socket.on('import_zoff', function(msg) { + ListChange.addFromOtherList(msg, guid, socket); + }) + socket.on('now_playing', function(list, fn) { List.now_playing(list, fn, socket); @@ -448,7 +452,9 @@ module.exports = function() { db.collection(coll + "_settings").find(function(err, docs) { Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { - obj.pass = userpass; + if(userpass != "" || obj.pass == undefined) { + 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); diff --git a/server/handlers/list.js b/server/handlers/list.js index f28e59d3..5e719f42 100644 --- a/server/handlers/list.js +++ b/server/handlers/list.js @@ -78,12 +78,14 @@ function list(msg, guid, coll, offline, socket) { }); } 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); + db.collection(coll).createIndex({ id: 1}, {unique: true}, function(e, d) { + 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); + }); }); }); } @@ -142,8 +144,12 @@ function skip(list, guid, coll, offline, socket) { return; } Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { - list.pass = adminpass; - list.userpass = userpass; + if(adminpass != "" || list.pass == undefined) { + list.pass = adminpass; + } + if(userpass != "" || list.userpass == undefined) { + list.userpass = userpass; + } 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")))) { @@ -539,7 +545,9 @@ function end(obj, coll, guid, offline, socket) { } coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) { - obj.pass = userpass; + if(userpass != "" || obj.pass == undefined) { + 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")))) { diff --git a/server/handlers/list_change.js b/server/handlers/list_change.js index b8f4e7ae..ab8f2772 100644 --- a/server/handlers/list_change.js +++ b/server/handlers/list_change.js @@ -1,3 +1,97 @@ +function addFromOtherList(arr, guid, socket) { + var MongoClient = require('mongodb').MongoClient; + var socketid = socket.zoff_id; + if(typeof(arr) == "object") { + if(!arr.hasOwnProperty("channel") || !arr.hasOwnProperty("new_channel") + || typeof(arr.channel) != "string" || typeof(arr.new_channel) != "string") { + var result = { + channel: { + expected: "string", + got: arr.hasOwnProperty("channel") ? typeof(arr.channel) : undefined + }, + new_channel: { + expected: "string", + got: arr.hasOwnProperty("new_channel") ? typeof(arr.new_channel) : undefined + } + }; + socket.emit('update_required', result); + return; + } + var channel = arr.channel.replace(/ /g,'').toLowerCase(); + var new_channel = arr.new_channel.replace(/ /g, '').toLowerCase(); + db.collection("frontpage_lists").find({_id: new_channel}, function(err, fp) { + if(fp.length == 0) { + socket.emit("toast", "nolist"); + return; + } + + Functions.getSessionAdminUser(Functions.getSession(socket), channel, function(userpass) { + if(userpass != "" || arr.userpass == undefined) { + arr.userpass = userpass; + } + Functions.getSessionAdminUser(Functions.getSession(socket), new_channel, function(userpass) { + var otheruser = ""; + if(userpass != "") { + otheruser = userpass; + } + db.collection(channel).find({now_playing: true}, function(e, np) { + + var project_object = { + "id": 1, + "added": 1, + "guids": { "$literal": [] }, + "now_playing": 1, + "title": 1, + "votes": { "$literal": 0 }, + "start": 1, + "duration": 1, + "end": 1, + "type": 1 + }; + if(np.length > 0) project_object.now_playing = { "$literal": false }; + db.collection(new_channel + "_settings").find({id: "config"}, function(e, new_conf) { + if(new_conf.length > 0 && (new_conf[0].userpass == "" || !new_conf[0].userpass || new_conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, otheruser)).digest("base64"))) { + db.collection(channel + "_settings").find({id: "config"}, function(e, this_conf) { + if(this_conf.userpass == "" || !this_conf.userpass || this_conf.userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, arr.userpass)).digest("base64")) { + db.collection(new_channel).aggregate([ + { + "$match": { type: "video" } + }, + { + "$project": project_object + } + ], function(e, docs) { + var path = require('path'); + var mongo_config = require(path.join(path.join(__dirname, '../config/'), 'mongo_config.js')); + var MongoClient = require('mongodb').MongoClient; + var url = "mongodb://" + mongo_config.host + ":" + mongo_config.port + "/"; + MongoClient.connect(url, function(err, _db) { + var dbo = _db.db(mongo_config.config); + dbo.collection(channel).insertMany(docs, {ordered: false}, function(err, res) { + List.send_list(channel, undefined, false, true, false); + List.send_play(channel, undefined); + socket.emit("toast", "addedplaylist"); + _db.close(); + }); + }); + }) + } else { + socket.emit("auth_required"); + return; + } + }) + } else { + socket.emit("toast", "other_list_pass"); + return; + } + }) + }); + }); + }); + }); + } +} + function add_function(arr, coll, guid, offline, socket) { var socketid = socket.zoff_id; if(typeof(arr) === 'object' && arr !== undefined && arr !== null && arr !== "" && !isNaN(parseInt(arr.duration))) @@ -91,8 +185,12 @@ function add_function(arr, coll, guid, offline, socket) { } coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { - arr.adminpass = adminpass; - arr.userpass = userpass; + if(adminpass != "" || arr.adminpass == undefined) { + arr.adminpass = adminpass; + } + if(userpass != "" || arr.userpass == undefined) { + 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")))) { @@ -280,8 +378,12 @@ function voteUndecided(msg, coll, guid, offline, socket) { } coll = msg.channel.toLowerCase().replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { - msg.adminpass = adminpass; - msg.pass = userpass; + if(adminpass != "" || msg.adminpass == undefined) { + msg.adminpass = adminpass; + } + if(userpass != "" || msg.pass == undefined) { + 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")))) { @@ -341,8 +443,12 @@ function shuffle(msg, coll, guid, offline, socket) { coll = msg.channel.toLowerCase().replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { - msg.adminpass = adminpass; - msg.pass = userpass; + if(adminpass != "" || msg.adminpass == undefined) { + msg.adminpass = adminpass; + } + if(userpass != "" || msg.pass == undefined) { + msg.pass = userpass; + } db.collection("timeout_api").find({ type: "shuffle", guid: coll, @@ -454,8 +560,12 @@ function delete_all(msg, coll, guid, offline, socket) { } coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) { - msg.adminpass = adminpass; - msg.pass = userpass; + if(adminpass != "" || msg.adminpass == undefined) { + msg.adminpass = adminpass; + } + if(userpass != "" || msg.pass == undefined) { + 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) { @@ -505,6 +615,7 @@ function vote(coll, id, guid, socket, full_list, last) { }); } +module.exports.addFromOtherList = addFromOtherList; module.exports.add_function = add_function; module.exports.voteUndecided = voteUndecided; module.exports.shuffle = shuffle; diff --git a/server/handlers/suggestions.js b/server/handlers/suggestions.js index 78c6b29c..f6ddfef7 100644 --- a/server/handlers/suggestions.js +++ b/server/handlers/suggestions.js @@ -25,8 +25,12 @@ function thumbnail(msg, coll, guid, offline, socket) { } coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { - msg.userpass = userpass; - msg.adminpass = adminpass; + if(userpass != "" || msg.userpass == undefined) { + msg.userpass = userpass; + } + if(adminpass != "" || msg.adminpass == undefined) { + msg.adminpass = adminpass; + } msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, ""); if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail; @@ -76,8 +80,12 @@ function description(msg, coll, guid, offline, socket) { } coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) { - msg.userpass = userpass; - msg.adminpass = adminpass; + if(userpass != "" || msg.userpass == undefined) { + msg.userpass = userpass; + } + if(adminpass != "" || msg.adminpass == undefined) { + 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){ diff --git a/server/public/assets/css/style.css b/server/public/assets/css/style.css index 13739c18..ae61e041 100755 --- a/server/public/assets/css/style.css +++ b/server/public/assets/css/style.css @@ -334,7 +334,7 @@ li.disabled span { color: white !important; } -.import-spotify-auth, .import-youtube, .export-spotify-auth, .export-youtube, .exported-playlist{ +.import-spotify-auth, .import-youtube, .export-spotify-auth, .export-youtube, .exported-playlist, .import-zoff{ color:white !important; height:40px !important; line-height: 40px !important; @@ -701,7 +701,7 @@ input[type=text]:focus:not([readonly]) + label, input[type=password]:focus:not([ background-color: #ff9800 !important; } -#import, #import_spotify{ +#import, #import_spotify, #import_zoff{ width: 65%; padding-left: 35px; color: rgb(68,68,68); @@ -710,6 +710,10 @@ input[type=text]:focus:not([readonly]) + label, input[type=password]:focus:not([ height: 64px; } +#import_zoff { + width: 100%; +} + #password{ width: 84%; margin-left: 30px; @@ -1194,6 +1198,14 @@ margin:-1px; top:20px; } +.zoff-image-import { + height: 36px; +} + +.zoff-color { + background: #2d2d2d !important; +} + .side_away { -webkit-transition: all .3s !important; -moz-transition: all .3s !important; diff --git a/server/public/assets/js/functions.js b/server/public/assets/js/functions.js index 54eccabc..13832dd1 100644 --- a/server/public/assets/js/functions.js +++ b/server/public/assets/js/functions.js @@ -596,6 +596,12 @@ function change_offline(enabled, already_offline){ function toast(msg) { switch(msg) { + case "other_list_pass": + msg = "The other list has a pass, can't import the songs.."; + break; + case "nolist": + msg = "There is no list with that name"; + break; case "suggested_thumbnail": if(embed) return; msg = "The thumbnail has been suggested!"; diff --git a/server/public/assets/js/listeners.js b/server/public/assets/js/listeners.js index a7a9dc8e..fa359425 100755 --- a/server/public/assets/js/listeners.js +++ b/server/public/assets/js/listeners.js @@ -876,6 +876,22 @@ $(document).on("submit", "#listImport", function(e){ document.getElementById("import").value = ""; }); +$(document).on("submit", "#listImportZoff", function(e) { + e.preventDefault(); + var new_channel = $("#import_zoff").val(); + if(new_channel == "") { + Materialize.toast("It seems you've entered a invalid channel-name.", 4000); + return; + } + socket.emit("import_zoff", {channel: chan.toLowerCase(), new_channel: new_channel.toLowerCase()}); +}); + +$(document).on("click", ".import-zoff", function(e) { + e.preventDefault(); + $(".import-zoff-container").addClass("hide"); + $(".zoff_add_field").removeClass("hide"); +}); + $(document).on("submit", "#listImportSpotify", function(e){ e.preventDefault(); if(spotify_authenticated && $("#import_spotify").val() !== ""){ diff --git a/server/public/partials/channel/panel.handlebars b/server/public/partials/channel/panel.handlebars index 26855bcf..34e60449 100755 --- a/server/public/partials/channel/panel.handlebars +++ b/server/public/partials/channel/panel.handlebars @@ -332,6 +332,24 @@ +