mirror of https://github.com/calzoneman/sync.git
Work on ban list and channel ranks
This commit is contained in:
parent
2d7b0fe2ac
commit
9306200a87
|
@ -7,6 +7,7 @@ var Logger = require("./logger");
|
||||||
var AsyncQueue = require("./asyncqueue");
|
var AsyncQueue = require("./asyncqueue");
|
||||||
var MakeEmitter = require("./emitter");
|
var MakeEmitter = require("./emitter");
|
||||||
var InfoGetter = require("./get-info");
|
var InfoGetter = require("./get-info");
|
||||||
|
var ChatCommand = require("./chatcommand");
|
||||||
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
@ -664,7 +665,7 @@ Channel.prototype.handleNameBan = function (actor, name, reason) {
|
||||||
// If in the channel already, kick the banned user
|
// If in the channel already, kick the banned user
|
||||||
for (var i = 0; i < self.users.length; i++) {
|
for (var i = 0; i < self.users.length; i++) {
|
||||||
if (self.users[i].name.toLowerCase() == name) {
|
if (self.users[i].name.toLowerCase() == name) {
|
||||||
self.kick(self.users[i], "You're banned!");
|
self.users[i].kick("You're banned!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -785,7 +786,7 @@ Channel.prototype.banIP = function (actor, ip, name, reason, range) {
|
||||||
// If in the channel already, kick the banned user
|
// If in the channel already, kick the banned user
|
||||||
for (var i = 0; i < self.users.length; i++) {
|
for (var i = 0; i < self.users.length; i++) {
|
||||||
if (self.users[i].ip === ip) {
|
if (self.users[i].ip === ip) {
|
||||||
self.kick(self.users[i], "You're banned!");
|
self.users[i].kick("You're banned!");
|
||||||
break;
|
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) {
|
users.forEach(function (u) {
|
||||||
if (!self.hasPermission(u, "ban")) {
|
if (!self.hasPermission(u, "ban")) {
|
||||||
return;
|
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
|
* Sends the chat filter list
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -297,19 +297,19 @@ function handleKick(chan, user, args) {
|
||||||
chan.logger.log("*** " + user.name + " kicked " + args[0]);
|
chan.logger.log("*** " + user.name + " kicked " + args[0]);
|
||||||
args[0] = "";
|
args[0] = "";
|
||||||
var reason = args.join(" ");
|
var reason = args.join(" ");
|
||||||
chan.kick(kickee, reason);
|
kickee.kick(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleIPBan(chan, user, args) {
|
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
|
// Ban the name too for good measure
|
||||||
chan.tryNameBan(user, args[0]);
|
chan.handleNameBan(user, args[0], "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleBan(chan, user, args) {
|
function handleBan(chan, user, args) {
|
||||||
chan.tryNameBan(user, args[0]);
|
chan.handleNameBan(user, args[0], "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUnban(chan, user, args) {
|
function handleUnban(chan, user, args) {
|
||||||
|
|
|
@ -549,7 +549,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
db.query("INSERT INTO `chan_" + chan + "_bans` (ip, name, reason, bannedby) " +
|
db.query("INSERT INTO `chan_" + chan + "_bans` (ip, name, reason, bannedby) " +
|
||||||
"VALUES (?, ?, ?, ?)", [ip, name, reason, bannedby], callback);
|
"VALUES (?, ?, ?, ?)", [ip, name, note, bannedby], callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -225,7 +225,7 @@ Server.prototype.isChannelLoaded = function (name) {
|
||||||
Server.prototype.getChannel = function (name) {
|
Server.prototype.getChannel = function (name) {
|
||||||
var cname = name.toLowerCase();
|
var cname = name.toLowerCase();
|
||||||
for (var i = 0; i < this.channels.length; i++) {
|
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];
|
return this.channels[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -376,6 +376,10 @@ User.prototype.initChannelCallbacks = function () {
|
||||||
self.channel.sendBanlist([self]);
|
self.channel.sendBanlist([self]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
wrap("requestChannelRanks", function () {
|
||||||
|
self.channel.sendChannelRanks([self]);
|
||||||
|
});
|
||||||
|
|
||||||
wrap("requestChatFilter", function () {
|
wrap("requestChatFilter", function () {
|
||||||
self.channel.sendChatFilters([self]);
|
self.channel.sendChatFilters([self]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -167,8 +167,8 @@ html(lang="en")
|
||||||
li: a(href="#cs-motdeditor", data-toggle="tab", tabindex="-1") Edit MOTD
|
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-csseditor", data-toggle="tab", tabindex="-1") Edit CSS
|
||||||
li: a(href="#cs-jseditor", data-toggle="tab", tabindex="-1") Edit Javascript
|
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-chanranks", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestChannelRanks')") Edit user ranks
|
||||||
li: a(href="#cs-banlist", data-toggle="tab", tabindex="-1") Ban list
|
li: a(href="#cs-banlist", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestBanlist')") Ban list
|
||||||
.modal-body
|
.modal-body
|
||||||
.tab-content
|
.tab-content
|
||||||
include channeloptions
|
include channeloptions
|
||||||
|
|
|
@ -78,7 +78,6 @@ mixin banlist
|
||||||
th Unban
|
th Unban
|
||||||
th IP
|
th IP
|
||||||
th Name
|
th Name
|
||||||
th Aliases
|
|
||||||
th Banned by
|
th Banned by
|
||||||
|
|
||||||
mixin recentjoins
|
mixin recentjoins
|
||||||
|
|
|
@ -12,10 +12,7 @@ html(lang="en")
|
||||||
ul.nav.navbar-nav
|
ul.nav.navbar-nav
|
||||||
mixin navdefaultlinks("/login")
|
mixin navdefaultlinks("/login")
|
||||||
if loggedIn
|
if loggedIn
|
||||||
if redirect
|
mixin navlogoutform()
|
||||||
mixin navlogoutform(redirect)
|
|
||||||
else
|
|
||||||
mixin navlogoutform("/login")
|
|
||||||
section#mainpage.container
|
section#mainpage.container
|
||||||
if wasAlreadyLoggedIn
|
if wasAlreadyLoggedIn
|
||||||
.col-lg-6.col-lg-offset-3.col-md-6.col-md-offset-3
|
.col-lg-6.col-lg-offset-3.col-md-6.col-md-offset-3
|
||||||
|
@ -47,4 +44,4 @@ html(lang="en")
|
||||||
br
|
br
|
||||||
a(href=redirect) Return to previous page
|
a(href=redirect) Return to previous page
|
||||||
include footer
|
include footer
|
||||||
mixin footer()
|
mixin footer()
|
||||||
|
|
|
@ -443,37 +443,27 @@ Callbacks = {
|
||||||
},
|
},
|
||||||
|
|
||||||
banlist: function(entries) {
|
banlist: function(entries) {
|
||||||
var tbl = $("#banlist table");
|
var tbl = $("#cs-banlist table");
|
||||||
// I originally added this check because of a race condition
|
tbl.find("tbody").remove();
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
for(var i = 0; i < entries.length; i++) {
|
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")
|
var remove = $("<button/>").addClass("btn btn-xs btn-danger")
|
||||||
.appendTo($("<td/>").appendTo(tr));
|
.appendTo($("<td/>").appendTo(tr));
|
||||||
$("<span/>").addClass("glyphicon glyphicon-remove-circle").appendTo(remove);
|
$("<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 name = $("<td/>").text(entries[i].name).appendTo(tr);
|
||||||
var aliases = $("<td/>").text(entries[i].aliases.join(", ")).appendTo(tr);
|
var bannedby = $("<td/>").text(entries[i].bannedby).appendTo(tr);
|
||||||
var banner = $("<td/>").text(entries[i].banner).appendTo(tr);
|
|
||||||
|
|
||||||
var callback = (function(ip_hidden, name) { return function() {
|
(function (reason) {
|
||||||
socket.emit("unban", {
|
reason = "Kept spamming links";
|
||||||
ip_hidden: ip_hidden,
|
tr.popover({
|
||||||
name: name
|
title: "Ban Reason",
|
||||||
|
content: reason,
|
||||||
|
placement: "left",
|
||||||
|
trigger: "hover"
|
||||||
});
|
});
|
||||||
} })(entries[i].ip_hidden, entries[i].name);
|
})(entries[i].reason);
|
||||||
remove.click(callback);
|
tr.appendTo(tbl);
|
||||||
|
|
||||||
$(tr).appendTo(tbl);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -502,79 +492,65 @@ Callbacks = {
|
||||||
},
|
},
|
||||||
|
|
||||||
channelRanks: function(entries) {
|
channelRanks: function(entries) {
|
||||||
var tbl = $("#channelranks table");
|
var tbl = $("#cs-chanranks table");
|
||||||
// I originally added this check because of a race condition
|
tbl.find("tbody").remove();
|
||||||
// Now it seems to work without but I don't trust it
|
|
||||||
if(!tbl.hasClass("table")) {
|
|
||||||
setTimeout(function() {
|
|
||||||
Callbacks.channelRanks(entries);
|
|
||||||
}, 100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
entries.sort(function(a, b) {
|
entries.sort(function(a, b) {
|
||||||
var x = a.name.toLowerCase();
|
if (a.rank === b.rank) {
|
||||||
var y = b.name.toLowerCase();
|
var x = a.name.toLowerCase();
|
||||||
return y == x ? 0 : (x < y ? -1 : 1);
|
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) {
|
entries.forEach(function (entry) {
|
||||||
$(tbl.children()[1]).remove();
|
var tr = $("<tr/>");
|
||||||
}
|
var name = $("<td/>").text(entry.name).appendTo(tr);
|
||||||
var p = tbl.data("paginator");
|
name.addClass(getNameColor(entry.rank));
|
||||||
if(p) {
|
var rankwrap = $("<td/>");
|
||||||
p.items = entries;
|
var rank = $("<span/>").text(entry.rank).appendTo(rankwrap);
|
||||||
p.loadPage(0);
|
var rankedit = $("<button/>")
|
||||||
}
|
.addClass("btn btn-xs btn-default")
|
||||||
else {
|
.css("margin-right", "10px")
|
||||||
var opts = {
|
.text("Edit")
|
||||||
preLoadPage: function (p) {
|
.prependTo(rankwrap);
|
||||||
tbl.find("tbody").remove();
|
if (entry.rank >= CLIENT.rank) {
|
||||||
tbl.data("page", p);
|
rankedit.addClass("disabled");
|
||||||
},
|
} else {
|
||||||
generator: function (item, page, index) {
|
var editbox = null;
|
||||||
var tr = $("<tr/>").appendTo(tbl);
|
rankedit.click(function () {
|
||||||
var name = $("<td/>").text(item.name).appendTo(tr);
|
rankedit.hide();
|
||||||
name.addClass(getNameColor(item.rank));
|
rank.hide();
|
||||||
var rank = $("<td/>").text(item.rank)
|
editbox = $("<input/>").addClass("form-control")
|
||||||
.css("min-width", "220px")
|
.attr("placeholder", entry.rank)
|
||||||
.appendTo(tr);
|
.appendTo(rankwrap)
|
||||||
rank.click(function() {
|
.focus();
|
||||||
if(this.find(".rank-edit").length > 0)
|
|
||||||
return;
|
var finish = function () {
|
||||||
var r = this.text();
|
if (editbox != null) {
|
||||||
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);
|
|
||||||
socket.emit("setChannelRank", {
|
socket.emit("setChannelRank", {
|
||||||
user: item.name,
|
user: entry.name,
|
||||||
rank: parseInt(r)
|
rank: parseInt(editbox.val())
|
||||||
});
|
});
|
||||||
|
editbox.remove();
|
||||||
}
|
}
|
||||||
edit.blur(save.bind(edit));
|
|
||||||
edit.keydown(function(ev) {
|
rankedit.show();
|
||||||
if(ev.keyCode == 13)
|
rank.show();
|
||||||
save.bind(edit)();
|
};
|
||||||
});
|
|
||||||
}.bind(rank));
|
editbox.blur(finish);
|
||||||
}
|
editbox.keydown(function (ev) {
|
||||||
};
|
if (ev.keyCode === 13) {
|
||||||
var p = Paginate(entries, opts);
|
finish();
|
||||||
p.paginator.insertBefore($("#channelranks table"));
|
}
|
||||||
tbl.data("paginator", p);
|
});
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
rankwrap.appendTo(tr);
|
||||||
|
tr.appendTo(tbl);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setChannelRank: function(data) {
|
setChannelRank: function(data) {
|
||||||
|
|
Loading…
Reference in New Issue