|
|
@ -52,7 +52,7 @@ console.log("Importing this project modules");
|
|
|
|
debug("Importing Monitor");
|
|
|
|
debug("Importing Monitor");
|
|
|
|
const Monitor = require("./model/monitor");
|
|
|
|
const Monitor = require("./model/monitor");
|
|
|
|
debug("Importing Settings");
|
|
|
|
debug("Importing Settings");
|
|
|
|
const { getSettings, setSettings, setting, initJWTSecret, checkLogin, startUnitTest, FBSD, errorLog } = require("./util-server");
|
|
|
|
const { getSettings, setSettings, setting, initJWTSecret, checkLogin, startUnitTest, FBSD, errorLog, doubleCheckPassword } = require("./util-server");
|
|
|
|
|
|
|
|
|
|
|
|
debug("Importing Notification");
|
|
|
|
debug("Importing Notification");
|
|
|
|
const { Notification } = require("./notification");
|
|
|
|
const { Notification } = require("./notification");
|
|
|
@ -63,7 +63,7 @@ const Database = require("./database");
|
|
|
|
|
|
|
|
|
|
|
|
debug("Importing Background Jobs");
|
|
|
|
debug("Importing Background Jobs");
|
|
|
|
const { initBackgroundJobs } = require("./jobs");
|
|
|
|
const { initBackgroundJobs } = require("./jobs");
|
|
|
|
const { loginRateLimiter } = require("./rate-limiter");
|
|
|
|
const { loginRateLimiter, twoFaRateLimiter } = require("./rate-limiter");
|
|
|
|
|
|
|
|
|
|
|
|
const { basicAuth } = require("./auth");
|
|
|
|
const { basicAuth } = require("./auth");
|
|
|
|
const { login } = require("./auth");
|
|
|
|
const { login } = require("./auth");
|
|
|
@ -305,6 +305,15 @@ exports.entryPage = "dashboard";
|
|
|
|
socket.on("login", async (data, callback) => {
|
|
|
|
socket.on("login", async (data, callback) => {
|
|
|
|
console.log("Login");
|
|
|
|
console.log("Login");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Checking
|
|
|
|
|
|
|
|
if (typeof callback !== "function") {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Login Rate Limit
|
|
|
|
// Login Rate Limit
|
|
|
|
if (! await loginRateLimiter.pass(callback)) {
|
|
|
|
if (! await loginRateLimiter.pass(callback)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -363,14 +372,27 @@ exports.entryPage = "dashboard";
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("logout", async (callback) => {
|
|
|
|
socket.on("logout", async (callback) => {
|
|
|
|
|
|
|
|
// Rate Limit
|
|
|
|
|
|
|
|
if (! await loginRateLimiter.pass(callback)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
socket.leave(socket.userID);
|
|
|
|
socket.leave(socket.userID);
|
|
|
|
socket.userID = null;
|
|
|
|
socket.userID = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof callback === "function") {
|
|
|
|
callback();
|
|
|
|
callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("prepare2FA", async (callback) => {
|
|
|
|
socket.on("prepare2FA", async (currentPassword, callback) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (! await twoFaRateLimiter.pass(callback)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkLogin(socket);
|
|
|
|
checkLogin(socket);
|
|
|
|
|
|
|
|
await doubleCheckPassword(socket, currentPassword);
|
|
|
|
|
|
|
|
|
|
|
|
let user = await R.findOne("user", " id = ? AND active = 1 ", [
|
|
|
|
let user = await R.findOne("user", " id = ? AND active = 1 ", [
|
|
|
|
socket.userID,
|
|
|
|
socket.userID,
|
|
|
@ -405,14 +427,19 @@ exports.entryPage = "dashboard";
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
ok: false,
|
|
|
|
ok: false,
|
|
|
|
msg: "Error while trying to prepare 2FA.",
|
|
|
|
msg: error.message,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("save2FA", async (callback) => {
|
|
|
|
socket.on("save2FA", async (currentPassword, callback) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (! await twoFaRateLimiter.pass(callback)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkLogin(socket);
|
|
|
|
checkLogin(socket);
|
|
|
|
|
|
|
|
await doubleCheckPassword(socket, currentPassword);
|
|
|
|
|
|
|
|
|
|
|
|
await R.exec("UPDATE `user` SET twofa_status = 1 WHERE id = ? ", [
|
|
|
|
await R.exec("UPDATE `user` SET twofa_status = 1 WHERE id = ? ", [
|
|
|
|
socket.userID,
|
|
|
|
socket.userID,
|
|
|
@ -425,14 +452,19 @@ exports.entryPage = "dashboard";
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
ok: false,
|
|
|
|
ok: false,
|
|
|
|
msg: "Error while trying to change 2FA.",
|
|
|
|
msg: error.message,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("disable2FA", async (callback) => {
|
|
|
|
socket.on("disable2FA", async (currentPassword, callback) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (! await twoFaRateLimiter.pass(callback)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkLogin(socket);
|
|
|
|
checkLogin(socket);
|
|
|
|
|
|
|
|
await doubleCheckPassword(socket, currentPassword);
|
|
|
|
await TwoFA.disable2FA(socket.userID);
|
|
|
|
await TwoFA.disable2FA(socket.userID);
|
|
|
|
|
|
|
|
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
@ -442,12 +474,16 @@ exports.entryPage = "dashboard";
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
ok: false,
|
|
|
|
ok: false,
|
|
|
|
msg: "Error while trying to change 2FA.",
|
|
|
|
msg: error.message,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("verifyToken", async (token, callback) => {
|
|
|
|
socket.on("verifyToken", async (token, currentPassword, callback) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
checkLogin(socket);
|
|
|
|
|
|
|
|
await doubleCheckPassword(socket, currentPassword);
|
|
|
|
|
|
|
|
|
|
|
|
let user = await R.findOne("user", " id = ? AND active = 1 ", [
|
|
|
|
let user = await R.findOne("user", " id = ? AND active = 1 ", [
|
|
|
|
socket.userID,
|
|
|
|
socket.userID,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
@ -466,12 +502,19 @@ exports.entryPage = "dashboard";
|
|
|
|
valid: false,
|
|
|
|
valid: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
callback({
|
|
|
|
|
|
|
|
ok: false,
|
|
|
|
|
|
|
|
msg: error.message,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("twoFAStatus", async (callback) => {
|
|
|
|
socket.on("twoFAStatus", async (callback) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
checkLogin(socket);
|
|
|
|
checkLogin(socket);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
let user = await R.findOne("user", " id = ? AND active = 1 ", [
|
|
|
|
let user = await R.findOne("user", " id = ? AND active = 1 ", [
|
|
|
|
socket.userID,
|
|
|
|
socket.userID,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
@ -488,9 +531,10 @@ exports.entryPage = "dashboard";
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.log(error);
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
ok: false,
|
|
|
|
ok: false,
|
|
|
|
msg: "Error while trying to get 2FA status.",
|
|
|
|
msg: error.message,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -936,21 +980,13 @@ exports.entryPage = "dashboard";
|
|
|
|
throw new Error("Password is too weak. It should contain alphabetic and numeric characters. It must be at least 6 characters in length.");
|
|
|
|
throw new Error("Password is too weak. It should contain alphabetic and numeric characters. It must be at least 6 characters in length.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let user = await R.findOne("user", " id = ? AND active = 1 ", [
|
|
|
|
let user = await doubleCheckPassword(socket, password.currentPassword);
|
|
|
|
socket.userID,
|
|
|
|
await user.resetPassword(password.newPassword);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (user && passwordHash.verify(password.currentPassword, user.password)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user.resetPassword(password.newPassword);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
ok: true,
|
|
|
|
ok: true,
|
|
|
|
msg: "Password has been updated successfully.",
|
|
|
|
msg: "Password has been updated successfully.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new Error("Incorrect current password");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
@ -977,10 +1013,14 @@ exports.entryPage = "dashboard";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("setSettings", async (data, callback) => {
|
|
|
|
socket.on("setSettings", async (data, currentPassword, callback) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
checkLogin(socket);
|
|
|
|
checkLogin(socket);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data.disableAuth) {
|
|
|
|
|
|
|
|
await doubleCheckPassword(socket, currentPassword);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await setSettings("general", data);
|
|
|
|
await setSettings("general", data);
|
|
|
|
exports.entryPage = data.entryPage;
|
|
|
|
exports.entryPage = data.entryPage;
|
|
|
|
|
|
|
|
|
|
|
|