Prettified som more files and fixed some logging of missing files so they are more similar in fashion

This commit is contained in:
Kasper Rynning-Tønnesen
2019-07-26 08:46:03 +02:00
parent 6369c55252
commit 6ed67ffee6
18 changed files with 5629 additions and 3697 deletions

View File

@@ -1,59 +1,62 @@
var toShowConfig = {
"addsongs": true,
"adminpass": 1,
"allvideos": 1,
"frontpage": 1,
"longsongs": 1,
"removeplay": 1,
"shuffle": 1,
"skip": 1,
"startTime": 1,
"userpass": 1,
"vote": 1,
"toggleChat": { $ifNull: [ "$toggleChat", true ] },
"strictSkip": { $ifNull: [ "$strictSkip", false ] },
"strictSkipNumber": { $ifNull: [ "$strictSkipNumber", 10 ] },
"description": { $ifNull: [ "$description", "" ] },
"thumbnail": { $ifNull: [ "$thumbnail", "" ] },
"rules": { $ifNull: [ "$rules", "" ] },
"_id": 0
addsongs: true,
adminpass: 1,
allvideos: 1,
frontpage: 1,
longsongs: 1,
removeplay: 1,
shuffle: 1,
skip: 1,
startTime: 1,
userpass: 1,
vote: 1,
toggleChat: { $ifNull: ["$toggleChat", true] },
strictSkip: { $ifNull: ["$strictSkip", false] },
strictSkipNumber: { $ifNull: ["$strictSkipNumber", 10] },
description: { $ifNull: ["$description", ""] },
thumbnail: { $ifNull: ["$thumbnail", ""] },
rules: { $ifNull: ["$rules", ""] },
_id: 0
};
var project_object = {
"_id": 0,
"id": 1,
"added": 1,
"now_playing": 1,
"title": 1,
"votes": 1,
"start": 1,
"duration": 1,
"end": 1,
"type": 1,
"source": { $ifNull: [ "$source", "youtube" ] },
"thumbnail": {
$ifNull: [ "$thumbnail", {
$concat : [ "https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
} ]
},
"tags": { $ifNull: [ "$tags", [] ] },
_id: 0,
id: 1,
added: 1,
now_playing: 1,
title: 1,
votes: 1,
start: 1,
duration: 1,
end: 1,
type: 1,
source: { $ifNull: ["$source", "youtube"] },
thumbnail: {
$ifNull: [
"$thumbnail",
{
$concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
}
]
},
tags: { $ifNull: ["$tags", []] }
};
var toShowChannel = {
start: 1,
end: 1,
added: 1,
id: 1,
title: 1,
votes: 1,
duration: 1,
type: 1,
_id: 0,
tags: 1,
now_playing: 1,
type: 1,
source: 1,
thumbnail: 1,
start: 1,
end: 1,
added: 1,
id: 1,
title: 1,
votes: 1,
duration: 1,
type: 1,
_id: 0,
tags: 1,
now_playing: 1,
type: 1,
source: 1,
thumbnail: 1
};
module.exports.project_object = project_object;

File diff suppressed because it is too large Load Diff

View File

@@ -1,39 +1,84 @@
var path = require('path');
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(1);
var mongo_config = require(path.join(
path.join(__dirname, "../config/"),
"mongo_config.js"
));
} catch (e) {
console.log(
"(!) Missing file - /config/mongo_config.js. Have a look at /config/mongo_config.example.js. The server won't run without this existing."
);
process.exit(1);
}
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 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 }, function(){});
db.collection("timeout_api").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 120 }, function(){});
db.collection("api_links").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 86400 }, function(){});
db.on('connected', function(err) {
console.log("connected");
db.collection("chat_logs").createIndex(
{ createdAt: 1 },
{ expireAfterSeconds: 600 },
function() {}
);
db.collection("timeout_api").createIndex(
{ createdAt: 1 },
{ expireAfterSeconds: 120 },
function() {}
);
db.collection("api_links").createIndex(
{ createdAt: 1 },
{ expireAfterSeconds: 86400 },
function() {}
);
db.on("connected", function(err) {
console.log("connected");
});
db.on('error',function(err) {
console.log("\n" + new Date().toString() + "\n Database error: ", err);
db.on("error", function(err) {
console.log("\n" + new Date().toString() + "\n Database error: ", err);
});
db.on('error',function(err) {
console.log("\n" + new Date().toString() + "\n Database error: ", err);
db.on("error", function(err) {
console.log("\n" + new Date().toString() + "\n Database error: ", err);
});
/* Resetting usernames, and connected users */
db.collection("unique_ids").update({"_id": "unique_ids"}, {$set: {unique_ids: []}}, {multi: true, upsert: true}, function(err, docs){});
db.collection("user_names").remove({"guid": {$exists: true}}, {multi: true, upsert: true}, function(err, docs){});
db.collection("user_names").update({"_id": "all_names"}, {$set: {names: []}}, {multi: true, upsert: true}, function(err, docs){});
db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true, upsert: true}, function(err, docs){});
db.collection("connected_users").update({"_id": "total_users"}, {$set: {total_users: []}}, {multi: true, upsert: true}, function(err, docs) {});
db.collection("frontpage_lists").update({viewers: {$ne: 0}}, {$set: {"viewers": 0}}, {multi: true, upsert: true}, function(err, docs) {});
db.collection("unique_ids").update(
{ _id: "unique_ids" },
{ $set: { unique_ids: [] } },
{ multi: true, upsert: true },
function(err, docs) {}
);
db.collection("user_names").remove(
{ guid: { $exists: true } },
{ multi: true, upsert: true },
function(err, docs) {}
);
db.collection("user_names").update(
{ _id: "all_names" },
{ $set: { names: [] } },
{ multi: true, upsert: true },
function(err, docs) {}
);
db.collection("connected_users").update(
{ users: { $exists: true } },
{ $set: { users: [] } },
{ multi: true, upsert: true },
function(err, docs) {}
);
db.collection("connected_users").update(
{ _id: "total_users" },
{ $set: { total_users: [] } },
{ multi: true, upsert: true },
function(err, docs) {}
);
db.collection("frontpage_lists").update(
{ viewers: { $ne: 0 } },
{ $set: { viewers: 0 } },
{ multi: true, upsert: true },
function(err, docs) {}
);
module.exports = db;

View File

@@ -1,104 +1,143 @@
var Functions = require(pathThumbnails + '/handlers/functions.js');
var db = require(pathThumbnails + '/handlers/db.js');
var Functions = require(pathThumbnails + "/handlers/functions.js");
var db = require(pathThumbnails + "/handlers/db.js");
function frontpage_lists(msg, socket) {
if(msg == undefined || !msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) {
var result = {
version: {
expected: VERSION,
got: msg.hasOwnProperty("version") ? msg.version : undefined,
}
};
socket.emit('update_required', result);
return;
}
if (
msg == undefined ||
!msg.hasOwnProperty("version") ||
msg.version != VERSION ||
msg.version == undefined
) {
var result = {
version: {
expected: VERSION,
got: msg.hasOwnProperty("version") ? msg.version : undefined
}
};
socket.emit("update_required", result);
return;
}
db.collection("frontpage_lists").find({frontpage:true}, function(err, docs){
db.collection("connected_users").find({"_id": "total_users"}, function(err, tot){
socket.compress(true).emit("playlists", {channels: docs, viewers: tot[0].total_users.length});
db.collection("frontpage_lists").find({ frontpage: true }, function(
err,
docs
) {
db.collection("connected_users").find({ _id: "total_users" }, function(
err,
tot
) {
socket
.compress(true)
.emit("playlists", {
channels: docs,
viewers: tot[0].total_users.length
});
});
});
}
function get_frontpage_lists(callback) {
var project_object = {
"_id": 1,
"count": 1,
"frontpage": 1,
"id": 1,
"title": 1,
"viewers": 1,
"accessed": 1,
"pinned": { $ifNull: [ "$pinned", 0 ] },
"description": {
$ifNull: [ {$cond: {
"if": {
"$or": [
{ "$eq": [ "$description", ""] },
{ "$eq": [ "$description", null] },
{ "$eq": [ "$description", undefined] }
]
},
then: "This list has no description",
else: "$description"
}}, "This list has no description"]
var project_object = {
_id: 1,
count: 1,
frontpage: 1,
id: 1,
title: 1,
viewers: 1,
accessed: 1,
pinned: { $ifNull: ["$pinned", 0] },
description: {
$ifNull: [
{
$cond: {
if: {
$or: [
{ $eq: ["$description", ""] },
{ $eq: ["$description", null] },
{ $eq: ["$description", undefined] }
]
},
then: "This list has no description",
else: "$description"
}
},
"thumbnail": {
$ifNull: [ {$cond: {
"if": {
"$or": [
{ "$eq": [ "$thumbnail", ""] },
{ "$eq": [ "$thumbnail", null] },
{ "$eq": [ "$thumbnail", undefined] }
]
},
then: {
$concat : [ "https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
},
else: "$thumbnail"
}}, { $concat : [ "https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]}]
"This list has no description"
]
},
thumbnail: {
$ifNull: [
{
$cond: {
if: {
$or: [
{ $eq: ["$thumbnail", ""] },
{ $eq: ["$thumbnail", null] },
{ $eq: ["$thumbnail", undefined] }
]
},
then: {
$concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
},
else: "$thumbnail"
}
},
{ $concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"] }
]
}
};
db.collection("frontpage_lists").aggregate(
[
{
$match: {
frontpage: true,
count: { $gt: 3 }
}
};
db.collection("frontpage_lists").aggregate([
{
"$match": {
frontpage: true,
count: {$gt: 3},
}
},
{
"$project": project_object
},
{
"$sort" : {
"pinned": -1,
"viewers": -1,
"accessed": -1,
"count": -1,
"title": 1
}
},
], callback);
},
{
$project: project_object
},
{
$sort: {
pinned: -1,
viewers: -1,
accessed: -1,
count: -1,
title: 1
}
}
],
callback
);
}
function update_frontpage(coll, id, title, thumbnail, source, callback) {
//coll = coll.replace(/ /g,'');
db.collection("frontpage_lists").find({_id: coll}, function(e, doc) {
var updateObject = {
id: id,
title: title,
accessed: Functions.get_time()
};
if(doc.length > 0 && ((doc[0].thumbnail != "" && doc[0].thumbnail != undefined && (doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 || doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1 || doc[0].thumbnail.indexOf("https://img.youtube.com") > -1)) || (doc[0].thumbnail == "" || doc[0].thumbnail == undefined))) {
updateObject.thumbnail = thumbnail;
if(thumbnail == undefined) updateObject.thumbnail = "";
}
db.collection("frontpage_lists").update({_id: coll}, {$set: updateObject
},{upsert: true}, function(err, returnDocs){
if(typeof(callback) == "function") callback();
});
});
//coll = coll.replace(/ /g,'');
db.collection("frontpage_lists").find({ _id: coll }, function(e, doc) {
var updateObject = {
id: id,
title: title,
accessed: Functions.get_time()
};
if (
doc.length > 0 &&
((doc[0].thumbnail != "" &&
doc[0].thumbnail != undefined &&
(doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 ||
doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1 ||
doc[0].thumbnail.indexOf("https://img.youtube.com") > -1)) ||
(doc[0].thumbnail == "" || doc[0].thumbnail == undefined))
) {
updateObject.thumbnail = thumbnail;
if (thumbnail == undefined) updateObject.thumbnail = "";
}
db.collection("frontpage_lists").update(
{ _id: coll },
{ $set: updateObject },
{ upsert: true },
function(err, returnDocs) {
if (typeof callback == "function") callback();
}
);
});
}
module.exports.get_frontpage_lists = get_frontpage_lists;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,282 +1,397 @@
var Functions = require(pathThumbnails + '/handlers/functions.js');
var crypto = require('crypto');
var Filter = require('bad-words');
var filter = new Filter({ placeHolder: 'x'});
var Functions = require(pathThumbnails + "/handlers/functions.js");
var crypto = require("crypto");
var Filter = require("bad-words");
var filter = new Filter({ placeHolder: "x" });
/*var filter = {
clean: function(str) {
return str;
}
}*/
var projects = require(pathThumbnails + "/handlers/aggregates.js");
var db = require(pathThumbnails + '/handlers/db.js');
var db = require(pathThumbnails + "/handlers/db.js");
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") ||
typeof(inp.password) != "string" || typeof(inp.channel) != "string") {
var result = {
channel: {
expected: "string",
got: inp.hasOwnProperty("channel") ? typeof(inp.channel) : undefined,
},
password: {
expected: "password",
got: inp.hasOwnProperty("password") ? typeof(inp.password) : undefined,
},
};
socket.emit('update_required', result);
return;
var sessionId = Functions.getSession(socket);
if (sessionId == "") sessionId = "empty";
if (inp !== undefined && inp !== null && inp !== "") {
if (
!inp.hasOwnProperty("password") ||
!inp.hasOwnProperty("channel") ||
typeof inp.password != "string" ||
typeof inp.channel != "string"
) {
var result = {
channel: {
expected: "string",
got: inp.hasOwnProperty("channel") ? typeof inp.channel : undefined
},
password: {
expected: "password",
got: inp.hasOwnProperty("password") ? typeof inp.password : undefined
}
pw = inp.password;
try {
coll = inp.channel;
if(coll.length == 0) return;
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
//coll = filter.clean(coll);
} catch(e) {
return;
}
//coll = coll.replace(/ /g,'');
uncrypted = pw;
pw = Functions.hash_pass(Functions.decrypt_string(pw), true);
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 8");
Functions.getSessionAdminUser(sessionId, coll, function(userpass, adminpass) {
adminpass = Functions.hash_pass(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(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 && adminpass != "") {
socket.emit("toast", "changedpass");
} else {
socket.emit("toast", "correctpass");
}
socket.emit("pw", true);
});
});
} else if(docs[0].adminpass === "" || docs[0].adminpass == adminpass) {
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 = {
inp: {
expected: "string",
got: typeof(inpt)
},
};
socket.emit('update_required', result);
};
socket.emit("update_required", result);
return;
}
pw = inp.password;
try {
coll = inp.channel;
if (coll.length == 0) return;
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
//coll = filter.clean(coll);
} catch (e) {
return;
}
//coll = coll.replace(/ /g,'');
uncrypted = pw;
pw = Functions.hash_pass(Functions.decrypt_string(pw), true);
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 8");
Functions.getSessionAdminUser(sessionId, coll, function(
userpass,
adminpass
) {
adminpass = Functions.hash_pass(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(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 && adminpass != "") {
socket.emit("toast", "changedpass");
} else {
socket.emit("toast", "correctpass");
}
socket.emit("pw", true);
}
);
}
);
} else if (
docs[0].adminpass === "" ||
docs[0].adminpass == adminpass
) {
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 = {
inp: {
expected: "string",
got: typeof inpt
}
};
socket.emit("update_required", result);
}
}
function conf_function(params, coll, guid, offline, socket) {
if(params !== undefined && params !== null && params !== "")
{
if(coll !== undefined) {
try {
coll = params.channel;//.replace(/ /g,'');
if(coll.length == 0) return;
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
if (params !== undefined && params !== null && params !== "") {
if (coll !== undefined) {
try {
coll = params.channel; //.replace(/ /g,'');
if (coll.length == 0) return;
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
//coll = filter.clean(coll);
} catch(e) {
return;
}
}
if(coll == "" || coll == undefined || coll == null) {
socket.emit("update_required");
return;
}
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 9");
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(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 !== "" && !gotten) {
hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(adminpass), true));
} else if(adminpass !== "" && gotten) {
hash = Functions.hash_pass(adminpass);
} else {
hash = adminpass;
}
if(userpass != "") {
if(!params.userpass_changed && gotten) {
} else {
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.hasOwnProperty("toggleChat") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) {
obj.toggleChat = params.toggleChat;
}
if(params.hasOwnProperty("strictSkip") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) {
obj.strictSkip = params.strictSkip;
}
if(params.hasOwnProperty("strictSkipNumber") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) {
try {
obj.strictSkipNumber = parseInt(params.strictSkipNumber);
} catch(e) {}
}
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), obj["userpass"], coll, function() {
db.collection(coll + "_settings").aggregate([
{
"$match": {
id: "config"
}
},
{
"$project": projects.toShowConfig
},
], 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 = {
params: {
expected: "object",
got: typeof(params),
}
}
socket.emit('update_required', result);
//coll = filter.clean(coll);
} catch (e) {
return;
}
}
if (coll == "" || coll == undefined || coll == null) {
socket.emit("update_required");
return;
}
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 9");
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(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 !== "" && !gotten) {
hash = Functions.hash_pass(
Functions.hash_pass(Functions.decrypt_string(adminpass), true)
);
} else if (adminpass !== "" && gotten) {
hash = Functions.hash_pass(adminpass);
} else {
hash = adminpass;
}
if (userpass != "") {
if (!params.userpass_changed && gotten) {
} else {
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.hasOwnProperty("toggleChat") &&
docs[0].adminpass != "" &&
docs[0].adminpass != undefined &&
docs[0].adminpass == hash
) {
obj.toggleChat = params.toggleChat;
}
if (
params.hasOwnProperty("strictSkip") &&
docs[0].adminpass != "" &&
docs[0].adminpass != undefined &&
docs[0].adminpass == hash
) {
obj.strictSkip = params.strictSkip;
}
if (
params.hasOwnProperty("strictSkipNumber") &&
docs[0].adminpass != "" &&
docs[0].adminpass != undefined &&
docs[0].adminpass == hash
) {
try {
obj.strictSkipNumber = parseInt(params.strictSkipNumber);
} catch (e) {}
}
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),
obj["userpass"],
coll,
function() {
db.collection(coll + "_settings").aggregate(
[
{
$match: {
id: "config"
}
},
{
$project: projects.toShowConfig
}
],
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 = {
params: {
expected: "object",
got: typeof params
}
};
socket.emit("update_required", result);
}
}
module.exports.password = password;

View File

@@ -1,39 +1,48 @@
var path = require('path');
var path = require("path");
function requested_change(type, string, channel) {
try {
//channel = channel.replace(/ /g,'');
var nodemailer = require('nodemailer');
var mailconfig = require(path.join(__dirname, '../config/mailconfig.js'));
try {
//channel = channel.replace(/ /g,'');
var nodemailer = require("nodemailer");
var mailconfig = require(path.join(__dirname, "../config/mailconfig.js"));
let transporter = nodemailer.createTransport(mailconfig);
let transporter = nodemailer.createTransport(mailconfig);
transporter.verify(function(error, success) {
if (error) {
return;
} else {
var message = "A " + type + " change was requested on <b>" + channel + "</b><br><br>New supposed value is: <br><br><b>" + string + "</b><br><br><br> \
transporter.verify(function(error, success) {
if (error) {
return;
} else {
var message =
"A " +
type +
" change was requested on <b>" +
channel +
"</b><br><br>New supposed value is: <br><br><b>" +
string +
"</b><br><br><br> \
Go to <a href='https://admin.zoff.me/'>https://admin.zoff.me/</a> to accept or decline the request.";
var msg = {
from: mailconfig.from,
to: mailconfig.notify_mail,
subject: 'ZOFF: Requested new ' + type,
text: message,
html: message,
}
transporter.sendMail(msg, (error, info) => {
if (error) {
transporter.close();
return;
}
transporter.close();
});
}
var msg = {
from: mailconfig.from,
to: mailconfig.notify_mail,
subject: "ZOFF: Requested new " + type,
text: message,
html: message
};
transporter.sendMail(msg, (error, info) => {
if (error) {
transporter.close();
return;
}
transporter.close();
});
} catch(e) {
console.log("Mail is not configured and wont work");
console.log("Seems you forgot to create a mailconfig.js in /server/config/. Have a look at the mailconfig.example.js.");
}
}
});
} catch (e) {
console.log("Mail is not configured and wont work");
console.log(
"Seems you forgot to create a mailconfig.js in /server/config/. Have a look at the mailconfig.example.js."
);
}
}
module.exports.requested_change = requested_change;

File diff suppressed because it is too large Load Diff

View File

@@ -1,183 +1,284 @@
var Functions = require(pathThumbnails + '/handlers/functions.js');
var Notifications = require(pathThumbnails + '/handlers/notifications.js');
var crypto = require('crypto');
var db = require(pathThumbnails + '/handlers/db.js');
var Functions = require(pathThumbnails + "/handlers/functions.js");
var Notifications = require(pathThumbnails + "/handlers/notifications.js");
var crypto = require("crypto");
var db = require(pathThumbnails + "/handlers/db.js");
function thumbnail(msg, coll, guid, offline, socket) {
if(msg.thumbnail != undefined && msg.channel && msg.channel != undefined && Functions.isUrl(msg.thumbnail)){
if(typeof(msg.channel) != "string" || typeof(msg.thumbnail) != "string")
{
var result = {
channel: {
expected: "string",
got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined,
},
pass: {
expected: "string",
got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined,
},
thumbnail: {
expected: "string",
got: msg.hasOwnProperty("thumbnail") ? typeof(msg.thumbnail) : undefined,
},
adminpass: {
expected: "string",
got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined,
},
};
socket.emit("update_required", result);
return;
}
//coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
if(userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
} else if(msg.hasOwnProperty("pass")){
msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
}
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = Functions.hash_pass(adminpass);
} else {
msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass),true));
}
if(msg.thumbnail != "") {
msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, "");
if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail;
}
var channel = msg.channel.toLowerCase();
var hash = 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 == msg.pass))) {
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("toast", "thumbnail_denied");
if (
msg.thumbnail != undefined &&
msg.channel &&
msg.channel != undefined &&
Functions.isUrl(msg.thumbnail)
) {
if (typeof msg.channel != "string" || typeof msg.thumbnail != "string") {
var result = {
channel: {
expected: "string",
got: msg.hasOwnProperty("channel") ? typeof msg.channel : undefined
},
pass: {
expected: "string",
got: msg.hasOwnProperty("pass") ? typeof msg.pass : undefined
},
thumbnail: {
expected: "string",
got: msg.hasOwnProperty("thumbnail")
? typeof msg.thumbnail
: undefined
},
adminpass: {
expected: "string",
got: msg.hasOwnProperty("adminpass")
? typeof msg.adminpass
: undefined
}
};
socket.emit("update_required", result);
return;
}
//coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(
userpass,
adminpass
) {
if (userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
} else if (msg.hasOwnProperty("pass")) {
msg.pass = crypto
.createHash("sha256")
.update(Functions.decrypt_string(msg.pass))
.digest("base64");
}
if (adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = Functions.hash_pass(adminpass);
} else {
msg.adminpass = Functions.hash_pass(
Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true)
);
}
if (msg.thumbnail != "") {
msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, "");
if (msg.thumbnail.substring(0, 2) != "//")
msg.thumbnail = "//" + msg.thumbnail;
}
var channel = msg.channel.toLowerCase();
var hash = 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 == msg.pass))
) {
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("toast", "thumbnail_denied");
}
}
function description(msg, coll, guid, offline, socket) {
if(msg.description && msg.channel && msg.description.length < 100){
if(typeof(msg.channel) != "string" || typeof(msg.description) != "string") {
var result = {
channel: {
expected: "string",
got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined,
},
pass: {
expected: "string",
got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined,
},
description: {
expected: "string",
got: msg.hasOwnProperty("description") ? typeof(msg.description) : undefined,
},
adminpass: {
expected: "string",
got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined,
},
};
socket.emit("update_required", result);
return;
}
//coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
if(userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
} else if(msg.hasOwnProperty("pass")) {
msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
}
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = Functions.hash_pass(adminpass);
} else {
msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true));
}
var channel = msg.channel.toLowerCase();
var hash = 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 == msg.pass))) {
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("toast", "description_denied");
if (msg.description && msg.channel && msg.description.length < 100) {
if (typeof msg.channel != "string" || typeof msg.description != "string") {
var result = {
channel: {
expected: "string",
got: msg.hasOwnProperty("channel") ? typeof msg.channel : undefined
},
pass: {
expected: "string",
got: msg.hasOwnProperty("pass") ? typeof msg.pass : undefined
},
description: {
expected: "string",
got: msg.hasOwnProperty("description")
? typeof msg.description
: undefined
},
adminpass: {
expected: "string",
got: msg.hasOwnProperty("adminpass")
? typeof msg.adminpass
: undefined
}
};
socket.emit("update_required", result);
return;
}
//coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(
userpass,
adminpass,
gotten
) {
if (userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
} else if (msg.hasOwnProperty("pass")) {
msg.pass = crypto
.createHash("sha256")
.update(Functions.decrypt_string(msg.pass))
.digest("base64");
}
if (adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = Functions.hash_pass(adminpass);
} else {
msg.adminpass = Functions.hash_pass(
Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true)
);
}
var channel = msg.channel.toLowerCase();
var hash = 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 == msg.pass))
) {
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("toast", "description_denied");
}
}
function rules(msg, coll, guid, offline, socket) {
if(msg.rules && msg.channel && msg.rules.length < 250){
if(typeof(msg.channel) != "string" || typeof(msg.rules) != "string") {
var result = {
channel: {
expected: "string",
got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined,
},
pass: {
expected: "string",
got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined,
},
rules: {
expected: "string",
got: msg.hasOwnProperty("rules") ? typeof(msg.rules) : undefined,
},
adminpass: {
expected: "string",
got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined,
},
};
socket.emit("update_required", result);
return;
}
//coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
if(userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
} else if(msg.hasOwnProperty("pass")) {
msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
}
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = Functions.hash_pass(adminpass);
} else {
msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true));
}
var channel = msg.channel.toLowerCase();
var hash = 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 == msg.pass))) {
if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
db.collection("suggested_rules").update({channel: channel}, {$set:{rules: msg.rules}}, {upsert:true}, function(err, docs){
Notifications.requested_change("rules", msg.rules, channel);
socket.emit("toast", "suggested_rules");
});
}
} else {
socket.emit("auth_required");
}
});
});
} else {
socket.emit("toast", "rules_denied");
if (msg.rules && msg.channel && msg.rules.length < 250) {
if (typeof msg.channel != "string" || typeof msg.rules != "string") {
var result = {
channel: {
expected: "string",
got: msg.hasOwnProperty("channel") ? typeof msg.channel : undefined
},
pass: {
expected: "string",
got: msg.hasOwnProperty("pass") ? typeof msg.pass : undefined
},
rules: {
expected: "string",
got: msg.hasOwnProperty("rules") ? typeof msg.rules : undefined
},
adminpass: {
expected: "string",
got: msg.hasOwnProperty("adminpass")
? typeof msg.adminpass
: undefined
}
};
socket.emit("update_required", result);
return;
}
//coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(
userpass,
adminpass,
gotten
) {
if (userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
} else if (msg.hasOwnProperty("pass")) {
msg.pass = crypto
.createHash("sha256")
.update(Functions.decrypt_string(msg.pass))
.digest("base64");
}
if (adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = Functions.hash_pass(adminpass);
} else {
msg.adminpass = Functions.hash_pass(
Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true)
);
}
var channel = msg.channel.toLowerCase();
var hash = 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 == msg.pass))
) {
if (
docs !== null &&
docs.length !== 0 &&
docs[0].adminpass !== "" &&
docs[0].adminpass == hash
) {
db.collection("suggested_rules").update(
{ channel: channel },
{ $set: { rules: msg.rules } },
{ upsert: true },
function(err, docs) {
Notifications.requested_change("rules", msg.rules, channel);
socket.emit("toast", "suggested_rules");
}
);
}
} else {
socket.emit("auth_required");
}
});
});
} else {
socket.emit("toast", "rules_denied");
}
}
module.exports.thumbnail = thumbnail;
module.exports.description = description;
module.exports.rules = rules;