(function () {
var chosenServer = IO_SERVERS[0]; // Is the array even necessary for the ACP?
var opts = {
secure: chosenServer.secure
};
window.socket = io.connect(chosenServer.url, opts);
window.socket.on("connect", function () {
window.socket.emit("initACP");
window.socket.emit("acp-list-activechannels");
readEventlog();
});
window.socket.on("errMessage", function (data) {
alert(data.msg);
});
})();
function addMenuItem(target, text) {
var ul = $("#nav-acp-section ul");
var li = $("
").appendTo(tr);
var del = $("").addClass("btn btn-xs btn-danger")
.html("")
.click(function () {
socket.emit("acp-gban-delete", b);
})
.appendTo(td);
td = $("
").appendTo(tr).html("" + b.ip + "");
td = $("
").appendTo(tr).text(b.note);
});
});
/* User listing */
(function () {
var doSearch = function () {
if ($("#acp-ulookup-query").val().trim() === "") {
if (!confirm("You are about to list the entire users table. " +
"This table might be very large and take a long " +
"time to query. Continue?")) {
return;
}
}
socket.emit("acp-list-users", {
value: $("#acp-ulookup-query").val(),
field: $(this).data()["field"]
});
};
$("#acp-ulookup-btn-name").click(doSearch);
$("#acp-ulookup-btn-email").click(doSearch);
$("#acp-ulookup-query").keyup(function (ev) {
if (ev.keyCode === 13) {
$("#acp-ulookup-btn-name").click();
}
});
})();
socket.on("acp-list-users", function (users) {
var tbl = $("#acp-user-lookup table");
tbl.data("entries", users);
var p = tbl.data("paginator");
if (p) {
p.paginator.remove();
}
var opts = {
preLoadPage: function () {
tbl.find("tbody").remove();
},
generator: function (u, page, index) {
var tr = $("
").appendTo(tbl);
tr.attr("title", u.name + " joined on " + new Date(u.time) + " from IP " + u.ip);
$("
").text(u.id).appendTo(tr);
$("
").text(u.name).appendTo(tr);
var rank = $("
").text(u.global_rank).appendTo(tr);
$("
").text(u.email).appendTo(tr);
var reset = $("
").appendTo(tr);
// Rank editor
rank.click(function () {
if (rank.find(".rank-edit").length > 0) {
return;
}
var old = rank.text();
rank.text("");
var editor = $("").addClass("rank-edit form-control")
.attr("type", "text")
.attr("placeholder", old)
.appendTo(rank)
.focus();
var save = function () {
var newrank = editor.val();
if (newrank.trim() === "") {
newrank = old;
}
rank.text(old);
if (newrank === old) {
return;
}
socket.emit("acp-set-rank", {
name: u.name,
rank: parseInt(newrank)
});
};
editor.blur(save);
editor.keydown(function (ev) {
if (ev.keyCode === 13) {
save();
}
});
});
// Password reset
$("").addClass("btn btn-xs btn-danger")
.text("Reset password")
.click(function () {
if (!confirm("Really reset password for " + u.name + "?")) {
return;
}
socket.emit("acp-reset-password", {
name: u.name,
email: u.email
}, function (result) {
if (result.error) {
modalAlert({
title: "Error",
textContent: result.error
});
} else {
var link = new URL("/account/passwordrecover/" + result.hash,
new URL(location));
modalAlert({
title: "Reset Link",
textContent: link
});
}
});
}).appendTo(reset);
}
};
p = Paginate(users, opts);
p.paginator.css("margin-top", "20px");
p.paginator.insertBefore(tbl);
tbl.data("paginator", p);
});
socket.on("acp-set-rank", function (data) {
var table = $("#acp-user-lookup table");
var p = table.data("paginator");
var e = table.data("entries");
if (e) {
for (var i = 0; i < e.length; i++) {
if (e[i].name === data.name) {
e[i].rank = data.rank;
break;
}
}
if (p) {
p.items = e;
}
}
table.find("td:contains('" + data.name + "')")
.parent()
.children()[2]
.innerHTML = data.rank;
});
/* Channel listing */
(function () {
var doSearch = function () {
if ($("#acp-clookup-value").val().trim() === "") {
if (!confirm("You are about to list the entire channels table. " +
"This table might be very large and take a long " +
"time to query. Continue?")) {
return;
}
}
socket.emit("acp-list-channels", {
field: $("#acp-clookup-field").val(),
value: $("#acp-clookup-value").val()
});
};
$("#acp-clookup-submit").click(doSearch);
$("#acp-clookup-value").keyup(function (ev) {
if (ev.keyCode === 13) {
doSearch();
}
});
})();
socket.on("acp-list-channels", function (channels) {
var tbl = $("#acp-channel-lookup table");
tbl.data("entries", channels);
var p = tbl.data("paginator");
if (p) {
p.paginator.remove();
}
var opts = {
preLoadPage: function () {
tbl.find("tbody").remove();
},
generator: function (c, page, index) {
var tr = $("
").appendTo(tbl);
tr.attr("title", c.name + " was registered on " + new Date(c.time));
$("
").text(c.id).appendTo(tr);
$("
").text(c.name).appendTo(tr);
$("
").text(c.owner).appendTo(tr);
$("
").text(c.last_loaded).appendTo(tr);
$("
").text(c.owner_last_seen).appendTo(tr);
var remove = $("
").appendTo(tr);
// Drop channel
$("").addClass("btn btn-xs btn-danger")
.text("Delete channel")
.click(function () {
if (!confirm("Really delete " + c.owner + "/" + c.name + "?")) {
return;
}
socket.emit("acp-delete-channel", {
name: c.name,
});
}).appendTo(remove);
}
};
p = Paginate(channels, opts);
p.paginator.css("margin-top", "20px");
p.paginator.insertBefore(tbl);
tbl.data("paginator", p);
});
socket.on("acp-delete-channel", function (data) {
var table = $("#acp-channel-lookup table");
var p = table.data("paginator");
var e = table.data("entries");
var found = -1;
if (e) {
for (var i = 0; i < e.length; i++) {
if (e[i].name === data.name) {
found = i;
break;
}
}
if (found > 0) {
e.splice(found, 1);
}
if (p) {
p.items = e;
}
}
table.find("td:contains('" + data.name + "')")
.parent()
.remove();
});
/* Active channels */
function showChannelDetailModal(c) {
var wrap = $("").addClass("modal fade").appendTo($("body"));
var dialog = $("").addClass("modal-dialog").appendTo(wrap);
var content = $("").addClass("modal-content").appendTo(dialog);
var head = $("").addClass("modal-header").appendTo(content);
$("").addClass("close")
.attr("data-dismiss", "modal")
.attr("data-hidden", "true")
.html("×")
.appendTo(head);
$("").addClass("modal-title").text(c.name).appendTo(head);
var body = $("").addClass("modal-body").appendTo(content);
var table = $("
").addClass("table table-striped table-compact")
.appendTo(body);
var tr;
tr = $("