mirror of https://github.com/calzoneman/sync.git
Fixes and improvements
This commit is contained in:
parent
c08b89d68a
commit
1a3d92c903
12
acp.js
12
acp.js
|
@ -7,7 +7,7 @@ module.exports = {
|
||||||
init: function(user) {
|
init: function(user) {
|
||||||
ActionLog.record(user.ip, user.name, "acp-init");
|
ActionLog.record(user.ip, user.name, "acp-init");
|
||||||
user.socket.on("acp-announce", function(data) {
|
user.socket.on("acp-announce", function(data) {
|
||||||
ActionLog.record(user.ip, user.name, ["acp-announce", data]);
|
ActionLog.record(user.ip, user.name, "acp-announce", [data]);
|
||||||
Server.announcement = data;
|
Server.announcement = data;
|
||||||
Server.io.sockets.emit("announcement", data);
|
Server.io.sockets.emit("announcement", data);
|
||||||
});
|
});
|
||||||
|
@ -18,13 +18,13 @@ module.exports = {
|
||||||
});
|
});
|
||||||
|
|
||||||
user.socket.on("acp-global-ban", function(data) {
|
user.socket.on("acp-global-ban", function(data) {
|
||||||
ActionLog.record(user.ip, user.name, ["acp-global-ban", data.ip]);
|
ActionLog.record(user.ip, user.name, "acp-global-ban", [data.ip]);
|
||||||
Database.globalBanIP(data.ip, data.note);
|
Database.globalBanIP(data.ip, data.note);
|
||||||
user.socket.emit("acp-global-banlist", Database.refreshGlobalBans());
|
user.socket.emit("acp-global-banlist", Database.refreshGlobalBans());
|
||||||
});
|
});
|
||||||
|
|
||||||
user.socket.on("acp-global-unban", function(ip) {
|
user.socket.on("acp-global-unban", function(ip) {
|
||||||
ActionLog.record(user.ip, user.name, ["acp-global-unban", data.ip]);
|
ActionLog.record(user.ip, user.name, "acp-global-unban", [data.ip]);
|
||||||
Database.globalUnbanIP(ip);
|
Database.globalUnbanIP(ip);
|
||||||
user.socket.emit("acp-global-banlist", Database.refreshGlobalBans());
|
user.socket.emit("acp-global-banlist", Database.refreshGlobalBans());
|
||||||
});
|
});
|
||||||
|
@ -55,7 +55,7 @@ module.exports = {
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
var hash = Database.generatePasswordReset(user.ip, data.name, data.email);
|
var hash = Database.generatePasswordReset(user.ip, data.name, data.email);
|
||||||
ActionLog.record(user.ip, user.name, ["acp-reset-password", data.name]);
|
ActionLog.record(user.ip, user.name, "acp-reset-password", [data.name]);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
user.socket.emit("acp-reset-password", {
|
user.socket.emit("acp-reset-password", {
|
||||||
|
@ -90,7 +90,7 @@ module.exports = {
|
||||||
if(!db)
|
if(!db)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ActionLog.record(user.ip, user.name, ["acp-set-rank", data]);
|
ActionLog.record(user.ip, user.name, "acp-set-rank", [data]);
|
||||||
var query = Database.createQuery(
|
var query = Database.createQuery(
|
||||||
"UPDATE registrations SET global_rank=? WHERE uname=?",
|
"UPDATE registrations SET global_rank=? WHERE uname=?",
|
||||||
[data.name, data.rank]
|
[data.name, data.rank]
|
||||||
|
@ -139,7 +139,7 @@ module.exports = {
|
||||||
|
|
||||||
user.socket.on("acp-actionlog-clear", function(data) {
|
user.socket.on("acp-actionlog-clear", function(data) {
|
||||||
ActionLog.clear(data);
|
ActionLog.clear(data);
|
||||||
ActionLog.record(user.ip, user.name, "acp-actionlog-clear");
|
ActionLog.record(user.ip, user.name, "acp-actionlog-clear", data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
43
actionlog.js
43
actionlog.js
|
@ -1,12 +1,14 @@
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
var Logger = require("./logger");
|
||||||
|
|
||||||
var buffer = [];
|
var buffer = [];
|
||||||
|
|
||||||
exports.record = function(ip, name, action) {
|
exports.record = function(ip, name, action, args) {
|
||||||
buffer.push(JSON.stringify({
|
buffer.push(JSON.stringify({
|
||||||
ip: ip,
|
ip: ip,
|
||||||
name: name,
|
name: name,
|
||||||
action: action,
|
action: action,
|
||||||
|
args: args ? args : [],
|
||||||
time: Date.now()
|
time: Date.now()
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -24,11 +26,40 @@ exports.flush = function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.clear = function() {
|
exports.clear = function(actions) {
|
||||||
try {
|
clearInterval(FLUSH_TMR);
|
||||||
fs.renameSync("action.log", "action-until-"+Date.now()+".log");
|
var rs = fs.createReadStream("action.log");
|
||||||
|
var ws = fs.createWriteStream("action.log.tmp");
|
||||||
|
function handleLine(ln) {
|
||||||
|
try {
|
||||||
|
js = JSON.parse(ln);
|
||||||
|
if(actions.indexOf(js.action) == -1)
|
||||||
|
ws.write(ln + "\n");
|
||||||
|
}
|
||||||
|
catch(e) { }
|
||||||
}
|
}
|
||||||
catch(e) { }
|
var buffer = "";
|
||||||
|
rs.on("data", function(chunk) {
|
||||||
|
buffer += chunk;
|
||||||
|
if(buffer.indexOf("\n") != -1) {
|
||||||
|
var lines = buffer.split("\n");
|
||||||
|
buffer = lines[lines.length - 1];
|
||||||
|
lines.length = lines.length - 1;
|
||||||
|
lines.forEach(handleLine);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rs.on("end", function() {
|
||||||
|
handleLine(buffer);
|
||||||
|
ws.end();
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
fs.renameSync("action.log.tmp", "action.log");
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
Logger.errlog.log("Failed to move action.log.tmp => action.log");
|
||||||
|
Logger.errlog.log(e);
|
||||||
|
}
|
||||||
|
FLUSH_TMR = setInterval(exports.flush, 15000);
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(exports.flush, 15000);
|
var FLUSH_TMR = setInterval(exports.flush, 15000);
|
||||||
|
|
2
api.js
2
api.js
|
@ -429,7 +429,7 @@ function handleEmailChange(params, req, res) {
|
||||||
var row = Auth.login(name, pw);
|
var row = Auth.login(name, pw);
|
||||||
if(row) {
|
if(row) {
|
||||||
var success = Database.setUserEmail(name, email);
|
var success = Database.setUserEmail(name, email);
|
||||||
ActionLog.record(getClientIP(req), name, ["email-update", email]);
|
ActionLog.record(getClientIP(req), name, "email-update", [email]);
|
||||||
sendJSON(res, {
|
sendJSON(res, {
|
||||||
success: success,
|
success: success,
|
||||||
error: success ? "" : "Email update failed",
|
error: success ? "" : "Email update failed",
|
||||||
|
|
|
@ -269,14 +269,14 @@ function incrementalDump(chan) {
|
||||||
|
|
||||||
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", this.name]);
|
ActionLog.record(user.ip, user.name, "channel-register-failure", [this.name]);
|
||||||
user.socket.emit("registerChannel", {
|
user.socket.emit("registerChannel", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "This channel is already registered"
|
error: "This channel is already registered"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(!user.loggedIn) {
|
else if(!user.loggedIn) {
|
||||||
ActionLog.record(user.ip, user.name, ["channel-register-failure", this.name]);
|
ActionLog.record(user.ip, user.name, "channel-register-failure", [this.name]);
|
||||||
user.socket.emit("registerChannel", {
|
user.socket.emit("registerChannel", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "You must log in to register a channel"
|
error: "You must log in to register a channel"
|
||||||
|
@ -284,7 +284,7 @@ Channel.prototype.tryRegister = function(user) {
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(!Rank.hasPermission(user, "registerChannel")) {
|
else if(!Rank.hasPermission(user, "registerChannel")) {
|
||||||
ActionLog.record(user.ip, user.name, ["channel-register-failure", this.name]);
|
ActionLog.record(user.ip, user.name, "channel-register-failure", [this.name]);
|
||||||
user.socket.emit("registerChannel", {
|
user.socket.emit("registerChannel", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "You don't have permission to register this channel"
|
error: "You don't have permission to register this channel"
|
||||||
|
@ -292,7 +292,7 @@ Channel.prototype.tryRegister = function(user) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(Database.registerChannel(this.name)) {
|
if(Database.registerChannel(this.name)) {
|
||||||
ActionLog.record(user.ip, user.name, ["channel-register-success", this.name]);
|
ActionLog.record(user.ip, user.name, "channel-register-success", [this.name]);
|
||||||
this.registered = true;
|
this.registered = true;
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
this.saveDump();
|
this.saveDump();
|
||||||
|
|
16
www/acp.html
16
www/acp.html
|
@ -46,6 +46,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="span12">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
|
@ -179,19 +181,23 @@
|
||||||
<h3>Action Log</h3>
|
<h3>Action Log</h3>
|
||||||
<select multiple="multiple" id="actionlog_filter">
|
<select multiple="multiple" id="actionlog_filter">
|
||||||
</select>
|
</select>
|
||||||
<button class="btn btn-danger" id="actionlog_clear">Clear</button>
|
<button class="btn btn-danger" id="actionlog_clear">Clear Selected</button>
|
||||||
|
<button class="btn" id="actionlog_refresh">Refresh</button>
|
||||||
<table class="table table-bordered table-striped table-compact">
|
<table class="table table-bordered table-striped table-compact">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>IP Address</th>
|
<th id="actionlog_ip">IP Address</th>
|
||||||
<th>Name</th>
|
<th id="actionlog_name">Name</th>
|
||||||
<th>Action</th>
|
<th id="actionlog_action">Action</th>
|
||||||
<th>Time</th>
|
<th>Args</th>
|
||||||
|
<th id="actionlog_time">Time</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div> <!-- /container -->
|
</div> <!-- /container -->
|
||||||
<div class="push"></div>
|
<div class="push"></div>
|
||||||
<div id="sitefooter">
|
<div id="sitefooter">
|
||||||
|
|
|
@ -73,21 +73,53 @@ $("#show_actionlog").click(getActionLog);
|
||||||
$("#actionlog_filter").click(function() {
|
$("#actionlog_filter").click(function() {
|
||||||
var actions = $(this).val();
|
var actions = $(this).val();
|
||||||
$("#actionlog tbody").remove();
|
$("#actionlog tbody").remove();
|
||||||
$("#actionlog table").data("entries").forEach(function(e) {
|
var entries = [];
|
||||||
if(typeof e.action == "string" && actions.indexOf(e.action) == -1)
|
$("#actionlog table").data("allentries").forEach(function(e) {
|
||||||
|
if(actions.indexOf(e.action) == -1)
|
||||||
return;
|
return;
|
||||||
if(typeof e.action == "object" && "0" in e.action && actions.indexOf(e.action[0]) == -1)
|
entries.push(e);
|
||||||
return;
|
|
||||||
|
|
||||||
var tr = $("<tr/>").appendTo($("#actionlog table"));
|
|
||||||
$("<td/>").text(e.ip).appendTo(tr);
|
|
||||||
$("<td/>").text(e.name).appendTo(tr);
|
|
||||||
$("<td/>").text(e.action).appendTo(tr);
|
|
||||||
$("<td/>").text(new Date(e.time).toTimeString()).appendTo(tr);
|
|
||||||
});
|
});
|
||||||
|
$("#actionlog_pagination").remove();
|
||||||
|
if(entries.length > 20) {
|
||||||
|
var pag = $("<div/>").addClass("pagination")
|
||||||
|
.attr("id", "actionlog_pagination")
|
||||||
|
.insertAfter($("#actionlog table"));
|
||||||
|
var btns = $("<ul/>").appendTo(pag);
|
||||||
|
for(var i = 0; i < data.length / 20; i++) {
|
||||||
|
var li = $("<li/>").appendTo(btns);
|
||||||
|
(function(i) {
|
||||||
|
$("<a/>").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);
|
||||||
});
|
});
|
||||||
$("#actionlog_clear").click(function() {
|
$("#actionlog_clear").click(function() {
|
||||||
socket.emit("acp-actionlog-clear");
|
socket.emit("acp-actionlog-clear", $("#actionlog_filter").val());
|
||||||
|
getActionLog();
|
||||||
|
});
|
||||||
|
$("#actionlog_refresh").click(function() {
|
||||||
|
getActionLog();
|
||||||
|
});
|
||||||
|
$("#actionlog_ip").click(function() {
|
||||||
|
tableResort($("#actionlog table"), "ip");
|
||||||
|
});
|
||||||
|
$("#actionlog_name").click(function() {
|
||||||
|
tableResort($("#actionlog table"), "name");
|
||||||
|
});
|
||||||
|
$("#actionlog_action").click(function() {
|
||||||
|
tableResort($("#actionlog table"), "action");
|
||||||
|
});
|
||||||
|
$("#actionlog_time").click(function() {
|
||||||
|
tableResort($("#actionlog table"), "time");
|
||||||
});
|
});
|
||||||
|
|
||||||
function getSyslog() {
|
function getSyslog() {
|
||||||
|
@ -110,20 +142,24 @@ function getActionLog() {
|
||||||
var entry;
|
var entry;
|
||||||
try {
|
try {
|
||||||
entry = JSON.parse(ln);
|
entry = JSON.parse(ln);
|
||||||
if(typeof entry.action == "string") {
|
if(actions.indexOf(entry.action) == -1)
|
||||||
if(actions.indexOf(entry.action) == -1)
|
actions.push(entry.action);
|
||||||
actions.push(entry.action);
|
|
||||||
}
|
|
||||||
else if(typeof entry.action == "object" && "0" in entry.action) {
|
|
||||||
if(actions.indexOf(entry.action[0]) == -1)
|
|
||||||
actions.push(entry.action[0]);
|
|
||||||
}
|
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
}
|
}
|
||||||
catch(e) { }
|
catch(e) { }
|
||||||
});
|
});
|
||||||
entries.sort(function(a, b) {
|
var tbl = $("#actionlog table");
|
||||||
return a.time == b.time ? 0 : (a.time < b.time ? 1 : -1);
|
tbl.data("sortby", "time");
|
||||||
|
tbl.data("sort_desc", true);
|
||||||
|
tbl.data("entries", entries);
|
||||||
|
tbl.data("allentries", entries);
|
||||||
|
tbl.data("generator", function(e) {
|
||||||
|
var tr = $("<tr/>").appendTo($("#actionlog table"));
|
||||||
|
$("<td/>").text(e.ip).appendTo(tr);
|
||||||
|
$("<td/>").text(e.name).appendTo(tr);
|
||||||
|
$("<td/>").text(e.action).appendTo(tr);
|
||||||
|
$("<td/>").text(e.args.join(", ")).appendTo(tr);
|
||||||
|
$("<td/>").text(new Date(e.time).toTimeString()).appendTo(tr);
|
||||||
});
|
});
|
||||||
$("#actionlog table").data("entries", entries);
|
$("#actionlog table").data("entries", entries);
|
||||||
$("#actionlog_filter").html("");
|
$("#actionlog_filter").html("");
|
||||||
|
@ -133,6 +169,7 @@ function getActionLog() {
|
||||||
actions.forEach(function(a) {
|
actions.forEach(function(a) {
|
||||||
$("<option/>").text(a).val(a).appendTo($("#actionlog_filter"));
|
$("<option/>").text(a).val(a).appendTo($("#actionlog_filter"));
|
||||||
});
|
});
|
||||||
|
loadPage(tbl, 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getChanlog() {
|
function getChanlog() {
|
||||||
|
@ -201,7 +238,7 @@ function loadPage(tbl, page) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i = page * 20; i < page * 20 + 20; i++) {
|
for(var i = page * 20; i < page * 20 + 20 && i < e.length; i++) {
|
||||||
generator(e[i]);
|
generator(e[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,6 +393,13 @@ function setupCallbacks() {
|
||||||
|
|
||||||
socket.on("acp-list-loaded", function(data) {
|
socket.on("acp-list-loaded", function(data) {
|
||||||
$("#channellist tbody").remove();
|
$("#channellist tbody").remove();
|
||||||
|
data.sort(function(a, b) {
|
||||||
|
if(a.usercount == b.usercount) {
|
||||||
|
var x = a.name, y = b.name;
|
||||||
|
return x == y ? 0 : (x < y ? -1 : 1);
|
||||||
|
}
|
||||||
|
return a.usercount < b.usercount ? -1 : 1;
|
||||||
|
});
|
||||||
var total = 0;
|
var total = 0;
|
||||||
data.forEach(function(c) {
|
data.forEach(function(c) {
|
||||||
total += c.usercount;
|
total += c.usercount;
|
||||||
|
|
|
@ -12,6 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||||
var NotWebsocket = function() {
|
var NotWebsocket = function() {
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
this.polltmr = false;
|
this.polltmr = false;
|
||||||
|
this.nws = true;
|
||||||
$.getJSON(WEB_URL + "/nws/connect?callback=?", function(data) {
|
$.getJSON(WEB_URL + "/nws/connect?callback=?", function(data) {
|
||||||
this.hash = data;
|
this.hash = data;
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
|
|
|
@ -515,10 +515,12 @@ function applyOpts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(USEROPTS.altsocket) {
|
if(USEROPTS.altsocket) {
|
||||||
if(socket && socket.disconnect)
|
if(!socket.nws) {
|
||||||
socket.disconnect();
|
if(socket && socket.disconnect)
|
||||||
socket = new NotWebsocket();
|
socket.disconnect();
|
||||||
setupCallbacks();
|
socket = new NotWebsocket();
|
||||||
|
setupCallbacks();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Switch from NotWebsocket => Socket.io
|
// Switch from NotWebsocket => Socket.io
|
||||||
else if(socket && typeof socket.poll !== "undefined") {
|
else if(socket && typeof socket.poll !== "undefined") {
|
||||||
|
|
Loading…
Reference in New Issue