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 = $("").appendTo(pag);
- for(var i = 0; i < entries.length / 20; i++) {
- var li = $("").appendTo(btns);
- (function(i) {
- $("").attr("href", "javascript:void(0)")
- .text(i+1)
- .click(function() {
- loadPage(tbl, i);
- })
- .appendTo(li);
- })(i);
- }
- tbl.data("pagination", pag);
- }
-
- $("#actionlog table").data("entries", entries);
- loadPage($("#actionlog table"), 0);
+$("#show_actionlog").click(function () {
+ socket.emit("acp-actionlog-list");
});
+$("#actionlog_filter").click(getActionLog);
$("#actionlog_searchbtn").click(function() {
var tbl = $("#actionlog table");
$("#actionlog tbody").remove();
@@ -151,9 +121,11 @@ $("#actionlog_searchbtn").click(function() {
});
$("#actionlog_clear").click(function() {
socket.emit("acp-actionlog-clear", $("#actionlog_filter").val());
+ socket.emit("acp-actionlog-list");
getActionLog();
});
$("#actionlog_refresh").click(function() {
+ socket.emit("acp-actionlog-list");
getActionLog();
});
$("#actionlog_ip").click(function() {
@@ -193,12 +165,31 @@ function getErrlog() {
}
$("#errlog").click(getErrlog);
function getActionLog() {
- $.getJSON(WEB_URL+"/api/json/readactionlog?"+AUTH+"&callback=?").done(function(data) {
- var entries = data;
- var actions = [];
+ var types = "&actions=" + $("#actionlog_filter").val().join(",");
+ $.getJSON(WEB_URL+"/api/json/readactionlog?"+AUTH+types+"&callback=?").done(function(entries) {
+ var tbl = $("#actionlog table");
+ $("#actionlog tbody").remove();
+ $("#actionlog_pagination").remove();
+ if(entries.length > 20) {
+ var pag = $("").addClass("pagination")
+ .attr("id", "actionlog_pagination")
+ .insertAfter($("#actionlog table"));
+ var btns = $("").appendTo(pag);
+ for(var i = 0; i < entries.length / 20; i++) {
+ var li = $("").appendTo(btns);
+ (function(i) {
+ $("").attr("href", "javascript:void(0)")
+ .text(i+1)
+ .click(function() {
+ loadPage(tbl, i);
+ })
+ .appendTo(li);
+ })(i);
+ }
+ tbl.data("pagination", pag);
+ }
+
entries.forEach(function (e) {
- if(actions.indexOf(e.action) == -1)
- actions.push(e.action);
e.time = parseInt(e.time);
});
var tbl = $("#actionlog table");
@@ -225,15 +216,7 @@ function getActionLog() {
$(" | ").text(e.args).appendTo(tr);
$(" | ").text(new Date(e.time).toString()).appendTo(tr);
});
- $("#actionlog table").data("entries", entries);
- $("#actionlog_filter").html("");
- actions.sort(function(a, b) {
- return a == b ? 0 : (a < b ? -1 : 1);
- });
- actions.forEach(function(a) {
- $("").text(a).val(a).appendTo($("#actionlog_filter"));
- });
- tbl.find("tbody").remove();
+ loadPage($("#actionlog table"), 0);
});
}
function getChanlog() {
@@ -564,6 +547,16 @@ function setupCallbacks() {
new Chart($("#stat_channels")[0].getContext("2d")).Line(chan_data);
new Chart($("#stat_mem")[0].getContext("2d")).Line(mem_data);
});
+
+ socket.on("acp-actionlog-list", function (alist) {
+ $("#actionlog_filter").html("");
+ alist.sort(function(a, b) {
+ return a == b ? 0 : (a < b ? -1 : 1);
+ });
+ alist.forEach(function(a) {
+ $("").text(a).val(a).appendTo($("#actionlog_filter"));
+ });
+ });
}
/* cookie util */