From a5ca7d227e373c1ced06bd2cb24ab488c97c6ec1 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 23 Mar 2013 22:45:10 -0500 Subject: [PATCH] Add banlist interface --- channel.js | 53 ++++++++++++++++++++++++++++++++++++++ chatcommand.js | 9 +++++++ www/assets/js/callbacks.js | 5 ++++ www/assets/js/client.js | 13 ++++++++++ www/assets/js/functions.js | 23 +++++++++++++++++ www/index.html | 28 ++++++++++++++++++-- 6 files changed, 129 insertions(+), 2 deletions(-) diff --git a/channel.js b/channel.js index 9ba12e70..058b20be 100644 --- a/channel.js +++ b/channel.js @@ -280,6 +280,7 @@ Channel.prototype.banIP = function(banner, bannee) { // It is assumed that the banner has permission at this point this.ipbans[bannee.ip] = [bannee.name, banner.name]; bannee.socket.disconnect(); + this.broadcastIpbans(); if(!this.registered) return false; var db = mysql.createConnectionSync(); @@ -302,6 +303,33 @@ Channel.prototype.banIP = function(banner, bannee) { 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 Channel.prototype.searchLibrary = function(query) { query = query.toLowerCase(); @@ -362,6 +390,17 @@ Channel.prototype.userJoin = function(user) { user.socket.emit('newPoll', this.poll.packUpdate()); } 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) this.sendMediaUpdate(user); console.log("/" + user.ip + " joined channel " + this.name); @@ -780,6 +819,20 @@ Channel.prototype.broadcastOpts = function() { 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! Channel.prototype.sendAll = function(message, data) { io.sockets.in(this.name).emit(message, data); diff --git a/chatcommand.js b/chatcommand.js index 72f9e343..bca3cbfb 100644 --- a/chatcommand.js +++ b/chatcommand.js @@ -28,6 +28,9 @@ function handle(chan, user, msg) { else if(msg.indexOf("/ban ") == 0) { 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) { 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) { if(Rank.hasPermission(user, "poll")) { var args = msg.split(','); diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 750cbafa..f7ebf428 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -55,6 +55,7 @@ function initCallbacks() { addUserDropdown(users[i], users[i].children[1].innerHTML); } + $('#modnav').show(); $('#chancontrols').show(); } RANK = data.rank; @@ -105,6 +106,10 @@ function initCallbacks() { rebuildPlaylist(); }); + socket.on('banlist', function(data) { + updateBanlist(data.entries); + }); + socket.on('usercount', function(data) { $('#usercount').text(data.count + " connected users"); }); diff --git a/www/assets/js/client.js b/www/assets/js/client.js index 775cdbb9..47d73e26 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -235,6 +235,19 @@ $('#opt_submit').click(function() { 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() { socket.emit('searchLibrary', { diff --git a/www/assets/js/functions.js b/www/assets/js/functions.js index 3cc1cf0d..30d47c7d 100644 --- a/www/assets/js/functions.js +++ b/www/assets/js/functions.js @@ -599,3 +599,26 @@ function showAnnouncement(title, text) { $('

').text(title).appendTo(div); $('

').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 = $('').appendTo(tbl); + var remove = $('