Allow channel admins to read channel logs

This commit is contained in:
calzoneman 2013-08-06 14:20:47 -04:00
parent 07249f3589
commit a371ff629d
6 changed files with 88 additions and 0 deletions

View File

@ -278,6 +278,66 @@ function incrementalDump(chan) {
} }
} }
Channel.prototype.readLog = function (filterIp, callback) {
var maxLen = 100000; // Most recent 100KB
var file = this.logger.filename;
fs.stat(file, function (err, data) {
if(err) {
callback(err, null);
return;
}
var start = data.size - maxLen;
if(start < 0) {
start = 0;
}
var end = data.size - 1;
var rs = fs.createReadStream(file, {
start: start,
end: end
});
var buffer = "";
rs.on("data", function (data) {
buffer += data;
});
rs.on("end", function () {
if(filterIp) {
buffer = buffer.replace(
/(\d{1,3}\.){2}(\d{1,3})\.(\d{1,3})/g,
"x.x.$2.$3"
);
}
callback(false, buffer);
});
});
}
Channel.prototype.tryReadLog = function (user) {
if(user.rank < 3)
return;
var filterIp = true;
if(user.global_rank >= 255)
filterIp = false;
this.readLog(filterIp, function (err, data) {
if(err) {
user.socket.emit("readChanLog", {
success: false
});
} else {
user.socket.emit("readChanLog", {
success: true,
data: data
});
}
});
}
Channel.prototype.tryRegister = function(user) { Channel.prototype.tryRegister = function(user) {
if(this.registered) { if(this.registered) {
ActionLog.record(user.ip, user.name, "channel-register-failure", [ ActionLog.record(user.ip, user.name, "channel-register-failure", [

View File

@ -521,6 +521,12 @@ User.prototype.initCallbacks = function() {
}); });
}.bind(this)); }.bind(this));
this.socket.on("readChanLog", function () {
if(this.channel !== null) {
this.channel.tryReadLog(this);
}
}.bind(this));
this.socket.on("acp-init", function() { this.socket.on("acp-init", function() {
if(this.global_rank >= Rank.Siteadmin) if(this.global_rank >= Rank.Siteadmin)
this.server.acp.init(this); this.server.acp.init(this);

View File

@ -497,6 +497,19 @@ Callbacks = {
); );
}, },
readChanLog: function (data) {
var log = $("#chanlog_contents");
if(log.length == 0)
return;
if(data.success) {
log.text(data.data);
} else {
log.text("Error reading channel log");
}
log.scrollTop(log.prop("scrollHeight"));
},
voteskip: function(data) { voteskip: function(data) {
if(data.count > 0) { if(data.count > 0) {
$("#voteskip").text("Voteskip ("+data.count+"/"+data.need+")"); $("#voteskip").text("Voteskip ("+data.count+"/"+data.need+")");

View File

@ -45,6 +45,10 @@
$("#show_channelranks").click(function() { $("#show_channelranks").click(function() {
socket.emit("requestChannelRanks"); socket.emit("requestChannelRanks");
}); });
clickHandler("#show_chanlog", "#chanlog");
$("#show_chanlog").click(function () {
socket.emit("readChanLog");
});
genPermissionsEditor(); genPermissionsEditor();

View File

@ -812,6 +812,7 @@ function handleModPermissions() {
setVisible("#jsedit_tab", CLIENT.rank >= 3); setVisible("#jsedit_tab", CLIENT.rank >= 3);
setVisible("#filteredit_tab", hasPermission("filteredit")); setVisible("#filteredit_tab", hasPermission("filteredit"));
setVisible("#channelranks_tab", CLIENT.rank >= 3); setVisible("#channelranks_tab", CLIENT.rank >= 3);
setVisible("#chanlog_tab", CLIENT.rank >= 3);
setVisible("#chanopts_unregister_wrap", CLIENT.rank >= 10); setVisible("#chanopts_unregister_wrap", CLIENT.rank >= 10);
} }

View File

@ -15,6 +15,7 @@
<li id="banlist_tab"><a href="javascript:void(0);" id="show_banlist">Ban List</a></li> <li id="banlist_tab"><a href="javascript:void(0);" id="show_banlist">Ban List</a></li>
<li id="channelranks_tab"><a href="javascript:void(0);" id="show_channelranks">Channel Ranks</a></li> <li id="channelranks_tab"><a href="javascript:void(0);" id="show_channelranks">Channel Ranks</a></li>
<li id="loginhistory_tab"><a href="javascript:void(0);" id="show_loginhistory">Recent Connections</a></li> <li id="loginhistory_tab"><a href="javascript:void(0);" id="show_loginhistory">Recent Connections</a></li>
<li id="chanlog_tab"><a href="javascript:void(0);" id="show_chanlog">Channel Log</a></li>
</ul> </ul>
</div> </div>
<hr> <hr>
@ -223,3 +224,6 @@
</thead> </thead>
</table> </table>
</div> </div>
<div id="chanlog" class="span12">
<pre id="chanlog_contents" style="max-height: 400px; overflow-y: scroll"></pre>
</div>