From 0a480515d785a7d7231ee8eb79ab401cc6ea25c5 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Fri, 7 Feb 2014 10:45:28 -0600 Subject: [PATCH] ACP event log --- lib/acp.js | 23 +++++++++++++++++++- lib/web/account.js | 2 ++ lib/web/acp.js | 8 +++++++ templates/acp.jade | 3 ++- www/css/acp.css | 15 +++++++++++++ www/js/acp.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 101 insertions(+), 2 deletions(-) diff --git a/lib/acp.js b/lib/acp.js index 114e3153..ad5a4773 100644 --- a/lib/acp.js +++ b/lib/acp.js @@ -16,6 +16,10 @@ var util = require("./utilities"); var Config = require("./config"); var Server = require("./server"); +function eventUsername(user) { + return user.name + "@" + user.ip; +} + function handleAnnounce(user, data) { var sv = Server.getServer(); @@ -24,10 +28,14 @@ function handleAnnounce(user, data) { text: data.content, from: user.name }); + + Logger.eventlog.log("[acp] " + eventUsername(user) + " opened announcement `" + + data.title + "`"); } function handleAnnounceClear(user) { Server.getServer().announce(null); + Logger.eventlog.log("[acp] " + eventUsername(user) + " cleared announcement"); } function handleGlobalBan(user, data) { @@ -39,6 +47,8 @@ function handleGlobalBan(user, data) { return; } + Logger.eventlog.log("[acp] " + eventUsername(user) + " global banned " + data.ip); + db.listGlobalBans(function (err, bans) { if (err) { user.socket.emit("errMessage", { @@ -68,6 +78,9 @@ function handleGlobalBanDelete(user, data) { return; } + Logger.eventlog.log("[acp] " + eventUsername(user) + " un-global banned " + + data.ip); + db.listGlobalBans(function (err, bans) { if (err) { user.socket.emit("errMessage", { @@ -144,6 +157,8 @@ function handleSetRank(user, data) { msg: err }); } else { + Logger.eventlog.log("[acp] " + eventUsername(user) + " set " + name + + "'s global_rank to " + rank); user.socket.emit("acp-set-rank", data); } }); @@ -181,6 +196,9 @@ function handleResetPassword(user, data) { return; } + Logger.eventlog.log("[acp] " + eventUsername(user) + " initialized a " + + "password recovery for " + name); + user.socket.emit("errMessage", { msg: "Reset link: " + Config.get("http.domain") + "/account/passwordrecover/" + hash @@ -229,6 +247,7 @@ function handleDeleteChannel(user, data) { } db.channels.drop(name, function (err) { + Logger.eventlog.log("[acp] " + eventUsername(user) + " deleted channel " + name); if (err) { user.socket.emit("errMessage", { msg: err @@ -262,6 +281,8 @@ function handleForceUnload(user, data) { users.forEach(function (u) { u.kick("Channel shutting down"); }); + + Logger.eventlog.log("[acp] " + eventUsername(user) + " forced unload of " + name); } function init(user) { @@ -295,7 +316,7 @@ function init(user) { } user.socket.emit("acp-gbanlist", flat); }); - Logger.eventlog.log("[acp] Initialized ACP for " + user.name + "@" + user.ip); + Logger.eventlog.log("[acp] Initialized ACP for " + eventUsername(user)); } module.exports.init = init; diff --git a/lib/web/account.js b/lib/web/account.js index 74da374f..1a6e425f 100644 --- a/lib/web/account.js +++ b/lib/web/account.js @@ -370,6 +370,7 @@ function handleDeleteChannel(req, res) { }); return; } + db.channels.drop(name, function (err) { if (!err) { Logger.eventlog.log("[channel] " + loginName + "@" + @@ -688,6 +689,7 @@ function handlePasswordRecover(req, res) { } db.deletePasswordReset(hash); + Logger.eventlog.log("[account] " + ip + " recovered password for " + row.name); sendJade(res, "account-passwordrecover", { recovered: true, diff --git a/lib/web/acp.js b/lib/web/acp.js index b359803c..7c91a260 100644 --- a/lib/web/acp.js +++ b/lib/web/acp.js @@ -100,6 +100,13 @@ function handleReadHttplog(req, res) { readLog(res, path.join(__dirname, "..", "..", "http.log"), 1048576); } +/** + * Handles a request to read the event log + */ +function handleReadEventlog(req, res) { + readLog(res, path.join(__dirname, "..", "..", "events.log"), 1048576); +} + /** * Handles a request to read a channel log */ @@ -117,6 +124,7 @@ module.exports = { app.get("/acp/syslog", checkAdmin(handleReadSyslog)); app.get("/acp/errlog", checkAdmin(handleReadErrlog)); app.get("/acp/httplog", checkAdmin(handleReadHttplog)); + app.get("/acp/eventlog", checkAdmin(handleReadEventlog)); app.get("/acp/chanlog/:name", checkAdmin(handleReadChanlog)); } }; diff --git a/templates/acp.jade b/templates/acp.jade index ffacaf9d..bfee6fbd 100644 --- a/templates/acp.jade +++ b/templates/acp.jade @@ -114,7 +114,8 @@ html(lang="en") h3 Event Log strong Filter event types select#acp-eventlog-filter.form-control(multiple="multiple", style="max-width: 25%") - pre#acp-eventlog-text(style="margin-top: 20px") + button#acp-eventlog-refresh.btn.btn-default Refresh + pre#acp-eventlog-text #acp-stats.acp-panel.col-md-12(style="display: none") h3 User Count canvas#stat_users(width="100%", height="400") diff --git a/www/css/acp.css b/www/css/acp.css index d006649e..ea5bb385 100644 --- a/www/css/acp.css +++ b/www/css/acp.css @@ -11,3 +11,18 @@ overflow-y: scroll; overflow-x: hidden; } + +#acp-eventlog-text { + border-top-left-radius: 0; + border-top-right-radius: 0; + max-height: 500px; + overflow-y: scroll; + overflow-x: hidden; +} + +#acp-eventlog-refresh { + margin-top: 20px; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; + border-bottom: 0; +} diff --git a/www/js/acp.js b/www/js/acp.js index 38aa4d79..1143a146 100644 --- a/www/js/acp.js +++ b/www/js/acp.js @@ -7,6 +7,7 @@ window.socket.on("connect", function () { window.socket.emit("initACP"); window.socket.emit("acp-list-activechannels"); + readEventlog(); }); window.socket.on("errMessage", function (data) { @@ -57,6 +58,12 @@ function readHttplog() { }); } +function readEventlog() { + $.ajax(location.protocol + "//" + location.host + "/acp/eventlog").done(function (data) { + handleEventLog(data); + }); +} + function readChanlog(name) { $.ajax(location.protocol + "//" + location.host + "/acp/chanlog/" + name).done(function (data) { $("#acp-log").text(data); @@ -389,6 +396,51 @@ $("#acp-lchannels-refresh").click(function () { socket.emit("acp-list-activechannels"); }); +/* Event log */ + +function getEventKey(line) { + var left = line.indexOf("[", 1); + var right = line.indexOf("]", left); + return line.substring(left+1, right); +} + +function handleEventLog(data) { + data = data.split("\n").filter(function (ln) { return ln.indexOf("[") === 0; }); + var keys = {}; + data.forEach(function (ln) { + keys[getEventKey(ln)] = true; + }); + + $("#acp-eventlog-text").data("lines", data); + + $("#acp-eventlog-filter").html(""); + for (var k in keys) { + $("