Work on ban list and channel ranks

This commit is contained in:
calzoneman 2014-01-08 20:12:02 -06:00
parent 2d7b0fe2ac
commit 9306200a87
9 changed files with 118 additions and 108 deletions

View File

@ -7,6 +7,7 @@ var Logger = require("./logger");
var AsyncQueue = require("./asyncqueue");
var MakeEmitter = require("./emitter");
var InfoGetter = require("./get-info");
var ChatCommand = require("./chatcommand");
var fs = require("fs");
var path = require("path");
@ -664,7 +665,7 @@ Channel.prototype.handleNameBan = function (actor, name, reason) {
// If in the channel already, kick the banned user
for (var i = 0; i < self.users.length; i++) {
if (self.users[i].name.toLowerCase() == name) {
self.kick(self.users[i], "You're banned!");
self.users[i].kick("You're banned!");
break;
}
}
@ -785,7 +786,7 @@ Channel.prototype.banIP = function (actor, ip, name, reason, range) {
// If in the channel already, kick the banned user
for (var i = 0; i < self.users.length; i++) {
if (self.users[i].ip === ip) {
self.kick(self.users[i], "You're banned!");
self.users[i].kick("You're banned!");
break;
}
}
@ -842,6 +843,21 @@ Channel.prototype.sendBanlist = function (users) {
});
}
for (var name in self.namebans) {
bans.push({
ip: "*",
name: name,
reason: self.namebans[name].reason,
bannedby: self.namebans[name].bannedby
});
unmaskedbans.push({
ip: "*",
name: name,
reason: self.namebans[name].reason,
bannedby: self.namebans[name].bannedby
});
}
users.forEach(function (u) {
if (!self.hasPermission(u, "ban")) {
return;
@ -855,6 +871,24 @@ Channel.prototype.sendBanlist = function (users) {
});
};
/**
* Sends the channel ranks list
*/
Channel.prototype.sendChannelRanks = function (users) {
var self = this;
db.channels.allRanks(self.name, function (err, ranks) {
if (err) {
return;
}
users.forEach(function (u) {
if (u.rank >= 3) {
u.socket.emit("channelRanks", ranks);
}
});
});
};
/**
* Sends the chat filter list
*/

View File

@ -297,19 +297,19 @@ function handleKick(chan, user, args) {
chan.logger.log("*** " + user.name + " kicked " + args[0]);
args[0] = "";
var reason = args.join(" ");
chan.kick(kickee, reason);
kickee.kick(reason);
}
}
}
function handleIPBan(chan, user, args) {
chan.tryIPBan(user, args[0], args[1]);
chan.handleBanAllIP(user, args[0], "", args[1]);
// Ban the name too for good measure
chan.tryNameBan(user, args[0]);
chan.handleNameBan(user, args[0], "");
}
function handleBan(chan, user, args) {
chan.tryNameBan(user, args[0]);
chan.handleNameBan(user, args[0], "");
}
function handleUnban(chan, user, args) {

View File

@ -549,7 +549,7 @@ module.exports = {
}
db.query("INSERT INTO `chan_" + chan + "_bans` (ip, name, reason, bannedby) " +
"VALUES (?, ?, ?, ?)", [ip, name, reason, bannedby], callback);
"VALUES (?, ?, ?, ?)", [ip, name, note, bannedby], callback);
},
/**

View File

@ -225,7 +225,7 @@ Server.prototype.isChannelLoaded = function (name) {
Server.prototype.getChannel = function (name) {
var cname = name.toLowerCase();
for (var i = 0; i < this.channels.length; i++) {
if (this.channels[i].canonical_name === cname)
if (this.channels[i].uniqueName === cname)
return this.channels[i];
}

View File

@ -376,6 +376,10 @@ User.prototype.initChannelCallbacks = function () {
self.channel.sendBanlist([self]);
});
wrap("requestChannelRanks", function () {
self.channel.sendChannelRanks([self]);
});
wrap("requestChatFilter", function () {
self.channel.sendChatFilters([self]);
});

View File

@ -167,8 +167,8 @@ html(lang="en")
li: a(href="#cs-motdeditor", data-toggle="tab", tabindex="-1") Edit MOTD
li: a(href="#cs-csseditor", data-toggle="tab", tabindex="-1") Edit CSS
li: a(href="#cs-jseditor", data-toggle="tab", tabindex="-1") Edit Javascript
li: a(href="#cs-chanranks", data-toggle="tab", tabindex="-1") Edit user ranks
li: a(href="#cs-banlist", data-toggle="tab", tabindex="-1") Ban list
li: a(href="#cs-chanranks", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestChannelRanks')") Edit user ranks
li: a(href="#cs-banlist", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestBanlist')") Ban list
.modal-body
.tab-content
include channeloptions

View File

@ -78,7 +78,6 @@ mixin banlist
th Unban
th IP
th Name
th Aliases
th Banned by
mixin recentjoins

View File

@ -12,10 +12,7 @@ html(lang="en")
ul.nav.navbar-nav
mixin navdefaultlinks("/login")
if loggedIn
if redirect
mixin navlogoutform(redirect)
else
mixin navlogoutform("/login")
mixin navlogoutform()
section#mainpage.container
if wasAlreadyLoggedIn
.col-lg-6.col-lg-offset-3.col-md-6.col-md-offset-3
@ -47,4 +44,4 @@ html(lang="en")
br
a(href=redirect) Return to previous page
include footer
mixin footer()
mixin footer()

View File

@ -443,37 +443,27 @@ Callbacks = {
},
banlist: function(entries) {
var tbl = $("#banlist table");
// I originally added this check because of a race condition
// Now it seems to work without but I don't trust it
if(!tbl.hasClass("table")) {
setTimeout(function() {
Callbacks.banlist(entries);
}, 100);
return;
}
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
var tbl = $("#cs-banlist table");
tbl.find("tbody").remove();
for(var i = 0; i < entries.length; i++) {
var tr = document.createElement("tr");
var tr = $("<tr/>");
var remove = $("<button/>").addClass("btn btn-xs btn-danger")
.appendTo($("<td/>").appendTo(tr));
$("<span/>").addClass("glyphicon glyphicon-remove-circle").appendTo(remove);
var ip = $("<td/>").text(entries[i].ip_displayed).appendTo(tr);
var ip = $("<td/>").text(entries[i].ip).appendTo(tr);
var name = $("<td/>").text(entries[i].name).appendTo(tr);
var aliases = $("<td/>").text(entries[i].aliases.join(", ")).appendTo(tr);
var banner = $("<td/>").text(entries[i].banner).appendTo(tr);
var bannedby = $("<td/>").text(entries[i].bannedby).appendTo(tr);
var callback = (function(ip_hidden, name) { return function() {
socket.emit("unban", {
ip_hidden: ip_hidden,
name: name
(function (reason) {
reason = "Kept spamming links";
tr.popover({
title: "Ban Reason",
content: reason,
placement: "left",
trigger: "hover"
});
} })(entries[i].ip_hidden, entries[i].name);
remove.click(callback);
$(tr).appendTo(tbl);
})(entries[i].reason);
tr.appendTo(tbl);
}
},
@ -502,79 +492,65 @@ Callbacks = {
},
channelRanks: function(entries) {
var tbl = $("#channelranks table");
// I originally added this check because of a race condition
// Now it seems to work without but I don't trust it
if(!tbl.hasClass("table")) {
setTimeout(function() {
Callbacks.channelRanks(entries);
}, 100);
return;
}
var tbl = $("#cs-chanranks table");
tbl.find("tbody").remove();
entries.sort(function(a, b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return y == x ? 0 : (x < y ? -1 : 1);
if (a.rank === b.rank) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return y == x ? 0 : (x < y ? -1 : 1);
}
return b.rank - a.rank;
});
$("#channelranks").data("entries", entries);
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
var p = tbl.data("paginator");
if(p) {
p.items = entries;
p.loadPage(0);
}
else {
var opts = {
preLoadPage: function (p) {
tbl.find("tbody").remove();
tbl.data("page", p);
},
generator: function (item, page, index) {
var tr = $("<tr/>").appendTo(tbl);
var name = $("<td/>").text(item.name).appendTo(tr);
name.addClass(getNameColor(item.rank));
var rank = $("<td/>").text(item.rank)
.css("min-width", "220px")
.appendTo(tr);
rank.click(function() {
if(this.find(".rank-edit").length > 0)
return;
var r = this.text();
this.text("");
var edit = $("<input/>").attr("type", "text")
.attr("placeholder", r)
.addClass("rank-edit")
.appendTo(this)
.focus();
if(parseInt(r) >= CLIENT.rank) {
edit.attr("disabled", true);
}
function save() {
var r = this.val();
var r2 = r;
if(r.trim() == "" || parseInt(r) >= CLIENT.rank || parseInt(r) < 1)
r = this.attr("placeholder");
r = parseInt(r) + "";
this.parent().text(r);
entries.forEach(function (entry) {
var tr = $("<tr/>");
var name = $("<td/>").text(entry.name).appendTo(tr);
name.addClass(getNameColor(entry.rank));
var rankwrap = $("<td/>");
var rank = $("<span/>").text(entry.rank).appendTo(rankwrap);
var rankedit = $("<button/>")
.addClass("btn btn-xs btn-default")
.css("margin-right", "10px")
.text("Edit")
.prependTo(rankwrap);
if (entry.rank >= CLIENT.rank) {
rankedit.addClass("disabled");
} else {
var editbox = null;
rankedit.click(function () {
rankedit.hide();
rank.hide();
editbox = $("<input/>").addClass("form-control")
.attr("placeholder", entry.rank)
.appendTo(rankwrap)
.focus();
var finish = function () {
if (editbox != null) {
socket.emit("setChannelRank", {
user: item.name,
rank: parseInt(r)
user: entry.name,
rank: parseInt(editbox.val())
});
editbox.remove();
}
edit.blur(save.bind(edit));
edit.keydown(function(ev) {
if(ev.keyCode == 13)
save.bind(edit)();
});
}.bind(rank));
}
};
var p = Paginate(entries, opts);
p.paginator.insertBefore($("#channelranks table"));
tbl.data("paginator", p);
}
rankedit.show();
rank.show();
};
editbox.blur(finish);
editbox.keydown(function (ev) {
if (ev.keyCode === 13) {
finish();
}
});
});
}
rankwrap.appendTo(tr);
tr.appendTo(tbl);
});
},
setChannelRank: function(data) {