diff --git a/acp.js b/acp.js index 899a058a..e5993ab6 100644 --- a/acp.js +++ b/acp.js @@ -150,6 +150,12 @@ module.exports = function (Server) { } }); + user.socket.on("acp-actionlog-list", function () { + user.socket.emit("acp-actionlog-list", + ActionLog.getLogTypes() + ); + }); + user.socket.on("acp-actionlog-clear", function(data) { ActionLog.clear(data); ActionLog.record(user.ip, user.name, "acp-actionlog-clear", data); diff --git a/actionlog.js b/actionlog.js index e5c18df4..312a2f74 100644 --- a/actionlog.js +++ b/actionlog.js @@ -105,12 +105,42 @@ exports.tooManyRegistrations = function (ip) { return rows.length > 4; } -exports.readLog = function () { +exports.getLogTypes = function () { + var db = Database.getConnection(); + if(!db) + return false; + + var query = "SELECT DISTINCT action FROM actionlog"; + var result = db.querySync(query); + if(!result) { + Logger.errlog.log("! Failed to read action log"); + return []; + } + + result = result.fetchAllSync(); + var actions = []; + for(var i in result) + actions.push(result[i].action); + + return actions; +} + +exports.readLog = function (actions) { var db = Database.getConnection(); if(!db) return false; var query = "SELECT * FROM actionlog"; + if(actions !== undefined) { + var list = new Array(actions.length); + for(var i in actions) + list[i] = "?"; + list = list.join(","); + query += Database.createQuery( + " WHERE action IN ("+list+")", + actions + ); + } var result = db.querySync(query); if(!result) { Logger.errlog.log("! Failed to read action log"); diff --git a/api.js b/api.js index 03d8ed2c..26a10867 100644 --- a/api.js +++ b/api.js @@ -510,13 +510,15 @@ module.exports = function (Server) { var name = params.name || ""; var pw = params.pw || ""; var session = params.session || ""; + var types = params.actions || ""; var row = Auth.login(name, pw, session); if(!row || row.global_rank < 255) { res.send(403); return; } - var actions = ActionLog.readLog(); + var actiontypes = types.split(","); + var actions = ActionLog.readLog(actiontypes); this.sendJSON(res, actions); }, diff --git a/www/assets/js/acp.js b/www/assets/js/acp.js index e91d1fd8..9cd0a05c 100644 --- a/www/assets/js/acp.js +++ b/www/assets/js/acp.js @@ -70,40 +70,10 @@ $("#listloaded_refresh").click(function() { socket.emit("acp-list-loaded"); }); menuHandler("#show_actionlog", "#actionlog"); -$("#show_actionlog").click(getActionLog); -$("#actionlog_filter").click(function() { - var tbl = $("#actionlog table"); - var actions = $(this).val(); - $("#actionlog tbody").remove(); - var entries = []; - tbl.data("allentries").forEach(function(e) { - if(actions.indexOf(e.action) == -1) - return; - entries.push(e); - }); - $("#actionlog_pagination").remove(); - if(entries.length > 20) { - var pag = $("
").addClass("pagination") - .attr("id", "actionlog_pagination") - .insertAfter($("#actionlog table")); - var btns = $("