Add banlist interface

This commit is contained in:
calzoneman 2013-03-23 22:45:10 -05:00
parent 3a585cbb60
commit a5ca7d227e
6 changed files with 129 additions and 2 deletions

View file

@ -280,6 +280,7 @@ Channel.prototype.banIP = function(banner, bannee) {
// It is assumed that the banner has permission at this point // It is assumed that the banner has permission at this point
this.ipbans[bannee.ip] = [bannee.name, banner.name]; this.ipbans[bannee.ip] = [bannee.name, banner.name];
bannee.socket.disconnect(); bannee.socket.disconnect();
this.broadcastIpbans();
if(!this.registered) if(!this.registered)
return false; return false;
var db = mysql.createConnectionSync(); var db = mysql.createConnectionSync();
@ -302,6 +303,33 @@ Channel.prototype.banIP = function(banner, bannee) {
return results; return results;
} }
Channel.prototype.unbanIP = function(ip) {
this.ipbans[ip] = null;
this.broadcastIpbans();
if(!this.registered)
return false;
var db = mysql.createConnectionSync();
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
if(!db.connectedSync()) {
console.log("MySQL Connection Failed");
return false;
}
var query = 'DELETE FROM chan_{1}_bans WHERE `ip` = "{2}"'
.replace(/\{1\}/, this.name)
.replace(/\{2\}/, ip);
results = db.querySync(query);
if(!results) {
console.log("Delete from ban table failed");
return;
}
db.closeSync();
return results;
}
// Searches the local library for media titles containing query // Searches the local library for media titles containing query
Channel.prototype.searchLibrary = function(query) { Channel.prototype.searchLibrary = function(query) {
query = query.toLowerCase(); query = query.toLowerCase();
@ -362,6 +390,17 @@ Channel.prototype.userJoin = function(user) {
user.socket.emit('newPoll', this.poll.packUpdate()); user.socket.emit('newPoll', this.poll.packUpdate());
} }
user.socket.emit('channelOpts', this.opts); user.socket.emit('channelOpts', this.opts);
var ents = [];
for(var ip in this.ipbans) {
if(this.ipbans[ip] != null) {
ents.push({
ip: ip,
name: this.ipbans[ip][0],
banner: this.ipbans[ip][1]
});
}
}
user.socket.emit('banlist', {entries: ents});
if(user.playerReady) if(user.playerReady)
this.sendMediaUpdate(user); this.sendMediaUpdate(user);
console.log("/" + user.ip + " joined channel " + this.name); console.log("/" + user.ip + " joined channel " + this.name);
@ -780,6 +819,20 @@ Channel.prototype.broadcastOpts = function() {
this.sendAll('channelOpts', this.opts); this.sendAll('channelOpts', this.opts);
} }
Channel.prototype.broadcastIpbans = function() {
var ents = [];
for(var ip in this.ipbans) {
if(this.ipbans[ip] != null) {
ents.push({
ip: ip,
name: this.ipbans[ip][0],
banner: this.ipbans[ip][1]
});
}
}
this.sendAll('banlist', {entries: ents});
}
// Send to ALL the clients! // Send to ALL the clients!
Channel.prototype.sendAll = function(message, data) { Channel.prototype.sendAll = function(message, data) {
io.sockets.in(this.name).emit(message, data); io.sockets.in(this.name).emit(message, data);

View file

@ -28,6 +28,9 @@ function handle(chan, user, msg) {
else if(msg.indexOf("/ban ") == 0) { else if(msg.indexOf("/ban ") == 0) {
handleBan(chan, user, msg.substring(5).split(' ')); handleBan(chan, user, msg.substring(5).split(' '));
} }
else if(msg.indexOf("/unban ") == 0) {
handleUnban(chan, user, msg.substring(7).split(' '));
}
else if(msg.indexOf("/poll ") == 0) { else if(msg.indexOf("/poll ") == 0) {
handlePoll(chan, user, msg.substring(6)); handlePoll(chan, user, msg.substring(6));
} }
@ -63,6 +66,12 @@ function handleBan(chan, user, args) {
} }
} }
function handleUnban(chan, user, args) {
if(Rank.hasPermission(user, "ipban") && args.length > 0) {
chan.unbanIP(args[0]);
}
}
function handlePoll(chan, user, msg) { function handlePoll(chan, user, msg) {
if(Rank.hasPermission(user, "poll")) { if(Rank.hasPermission(user, "poll")) {
var args = msg.split(','); var args = msg.split(',');

View file

@ -55,6 +55,7 @@ function initCallbacks() {
addUserDropdown(users[i], users[i].children[1].innerHTML); addUserDropdown(users[i], users[i].children[1].innerHTML);
} }
$('#modnav').show();
$('#chancontrols').show(); $('#chancontrols').show();
} }
RANK = data.rank; RANK = data.rank;
@ -105,6 +106,10 @@ function initCallbacks() {
rebuildPlaylist(); rebuildPlaylist();
}); });
socket.on('banlist', function(data) {
updateBanlist(data.entries);
});
socket.on('usercount', function(data) { socket.on('usercount', function(data) {
$('#usercount').text(data.count + " connected users"); $('#usercount').text(data.count + " connected users");
}); });

View file

@ -235,6 +235,19 @@ $('#opt_submit').click(function() {
socket.emit('channelOpts', opts); socket.emit('channelOpts', opts);
}); });
$('#show_chancontrols').click(function() {
$('#show_chancontrols').parent().addClass("active");
$('#show_banlist').parent().removeClass("active");
$('#banlist').hide();
$('#chancontrols').show();
});
$('#show_banlist').click(function() {
$('#show_chancontrols').parent().removeClass("active");
$('#show_banlist').parent().addClass("active");
$('#banlist').show();
$('#chancontrols').hide();
});
function searchLibrary() { function searchLibrary() {
socket.emit('searchLibrary', { socket.emit('searchLibrary', {

View file

@ -599,3 +599,26 @@ function showAnnouncement(title, text) {
$('<h3/>').text(title).appendTo(div); $('<h3/>').text(title).appendTo(div);
$('<p/>').html(text).appendTo(div); $('<p/>').html(text).appendTo(div);
} }
function updateBanlist(entries) {
var tbl = $('#banlist table');
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
for(var i = 0; i < entries.length; i++) {
var tr = $('<tr/>').appendTo(tbl);
var remove = $('<button/>').addClass("btn btn-mini btn-danger")
.appendTo($('<td/>').appendTo(tr));
$('<i/>').addClass("icon-remove-circle").appendTo(remove);
var ip = $('<td/>').text(entries[i].ip).appendTo(tr);
var name = $('<td/>').text(entries[i].name).appendTo(tr);
var banner = $('<td/>').text(entries[i].banner).appendTo(tr);
var callback = (function(ip) { return function() {
socket.emit('chatMsg', {
msg: "/unban " + ip
});
} })(entries[i].ip);
remove.click(callback);
}
}

View file

@ -93,8 +93,20 @@
</ul> </ul>
</div> </div>
</div> </div>
<div class="row" style="margin-top: 20px; display: none" id="chancontrols"> <div class="row" style="display: none;" id="modnav">
<div class="span10 offset1 well"> <div class="span10 offset1">
<ul class="nav nav-tabs">
<li class="active">
<a href="javascript:void(0)" id="show_chancontrols">Channel Controls</a>
</li>
<li>
<a href="javascript:void(0)" id="show_banlist">Ban List</a>
</li>
</ul>
</div>
</div>
<div class="row" style="display: none" id="chancontrols">
<div class="span10 offset1">
<form action="javascript:void(0)"> <form action="javascript:void(0)">
<fieldset> <fieldset>
<legend>Channel Options</legend> <legend>Channel Options</legend>
@ -134,6 +146,18 @@
</form> </form>
</div> </div>
</div> </div>
<div class="row" id="banlist" style="display: none;">
<div class="span10 offset1">
<table class="table table-striped">
<thead>
<th></th>
<th>IP</th>
<th>Name</th>
<th>Banned By</th>
</thead>
</table>
</div>
</div>
</div> <!-- /container --> </div> <!-- /container -->
<script src="https://w.soundcloud.com/player/api.js"></script> <script src="https://w.soundcloud.com/player/api.js"></script>