Added function for rules, and moved thumbnail/data somewhat around for better readability

This commit is contained in:
Kasper Rynning-Tønnesen
2018-09-27 22:03:23 +02:00
parent 5a84a4bc70
commit 0b3e7177b1
12 changed files with 599 additions and 208 deletions

View File

@@ -190,6 +190,17 @@ module.exports = function() {
Suggestions.description(msg, coll, guid, offline, socket);
});
socket.on('suggest_rules', function(msg){
if(msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1){
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
msg.channel = _list;
}
if(msg.hasOwnProperty("channel")) {
msg.channel = Functions.encodeChannelName(msg.channel);
}
Suggestions.rules(msg, coll, guid, offline, socket);
});
socket.on("namechange", function(msg) {
if(msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1){
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));

View File

@@ -120,5 +120,64 @@ function description(msg, coll, guid, offline, socket) {
}
}
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");
}
}
module.exports.thumbnail = thumbnail;
module.exports.description = description;
module.exports.rules = rules;