|
|
@ -761,10 +761,6 @@ let needSetup = false;
|
|
|
|
|
|
|
|
|
|
|
|
let bean = await R.findOne("monitor", " id = ? ", [ monitor.id ]);
|
|
|
|
let bean = await R.findOne("monitor", " id = ? ", [ monitor.id ]);
|
|
|
|
|
|
|
|
|
|
|
|
if (bean.user_id !== socket.userID) {
|
|
|
|
|
|
|
|
throw new Error("Permission denied.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if Parent is Descendant (would cause endless loop)
|
|
|
|
// Check if Parent is Descendant (would cause endless loop)
|
|
|
|
if (monitor.parent !== null) {
|
|
|
|
if (monitor.parent !== null) {
|
|
|
|
const childIDs = await Monitor.getAllChildrenIDs(monitor.id);
|
|
|
|
const childIDs = await Monitor.getAllChildrenIDs(monitor.id);
|
|
|
@ -924,10 +920,7 @@ let needSetup = false;
|
|
|
|
|
|
|
|
|
|
|
|
log.info("monitor", `Get Monitor: ${monitorID} User ID: ${socket.userID}`);
|
|
|
|
log.info("monitor", `Get Monitor: ${monitorID} User ID: ${socket.userID}`);
|
|
|
|
|
|
|
|
|
|
|
|
let monitor = await R.findOne("monitor", " id = ? AND user_id = ? ", [
|
|
|
|
let monitor = await R.findOne("monitor", " id = ? ", [ monitorID ]);
|
|
|
|
monitorID,
|
|
|
|
|
|
|
|
socket.userID,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
const monitorData = [{ id: monitor.id,
|
|
|
|
const monitorData = [{ id: monitor.id,
|
|
|
|
active: monitor.active
|
|
|
|
active: monitor.active
|
|
|
|
}];
|
|
|
|
}];
|
|
|
@ -1034,10 +1027,7 @@ let needSetup = false;
|
|
|
|
|
|
|
|
|
|
|
|
const startTime = Date.now();
|
|
|
|
const startTime = Date.now();
|
|
|
|
|
|
|
|
|
|
|
|
await R.exec("DELETE FROM monitor WHERE id = ? AND user_id = ? ", [
|
|
|
|
await R.exec("DELETE FROM monitor WHERE id = ? ", [ monitorID ]);
|
|
|
|
monitorID,
|
|
|
|
|
|
|
|
socket.userID,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fix #2880
|
|
|
|
// Fix #2880
|
|
|
|
apicache.clear();
|
|
|
|
apicache.clear();
|
|
|
@ -1638,24 +1628,6 @@ async function updateMonitorNotification(monitorID, notificationIDList) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Check if a given user owns a specific monitor
|
|
|
|
|
|
|
|
* @param {number} userID ID of user to check
|
|
|
|
|
|
|
|
* @param {number} monitorID ID of monitor to check
|
|
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
* @throws {Error} The specified user does not own the monitor
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function checkOwner(userID, monitorID) {
|
|
|
|
|
|
|
|
let row = await R.getRow("SELECT id FROM monitor WHERE id = ? AND user_id = ? ", [
|
|
|
|
|
|
|
|
monitorID,
|
|
|
|
|
|
|
|
userID,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (! row) {
|
|
|
|
|
|
|
|
throw new Error("You do not own this monitor.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Function called after user login
|
|
|
|
* Function called after user login
|
|
|
|
* This function is used to send the heartbeat list of a monitor.
|
|
|
|
* This function is used to send the heartbeat list of a monitor.
|
|
|
@ -1739,14 +1711,9 @@ async function initDatabase(testMode = false) {
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async function startMonitor(userID, monitorID) {
|
|
|
|
async function startMonitor(userID, monitorID) {
|
|
|
|
await checkOwner(userID, monitorID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("manage", `Resume Monitor: ${monitorID} User ID: ${userID}`);
|
|
|
|
log.info("manage", `Resume Monitor: ${monitorID} User ID: ${userID}`);
|
|
|
|
|
|
|
|
|
|
|
|
await R.exec("UPDATE monitor SET active = 1 WHERE id = ? AND user_id = ? ", [
|
|
|
|
await R.exec("UPDATE monitor SET active = 1 WHERE id = ? ", [ monitorID ]);
|
|
|
|
monitorID,
|
|
|
|
|
|
|
|
userID,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let monitor = await R.findOne("monitor", " id = ? ", [
|
|
|
|
let monitor = await R.findOne("monitor", " id = ? ", [
|
|
|
|
monitorID,
|
|
|
|
monitorID,
|
|
|
@ -1777,14 +1744,9 @@ async function restartMonitor(userID, monitorID) {
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async function pauseMonitor(userID, monitorID) {
|
|
|
|
async function pauseMonitor(userID, monitorID) {
|
|
|
|
await checkOwner(userID, monitorID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("manage", `Pause Monitor: ${monitorID} User ID: ${userID}`);
|
|
|
|
log.info("manage", `Pause Monitor: ${monitorID} User ID: ${userID}`);
|
|
|
|
|
|
|
|
|
|
|
|
await R.exec("UPDATE monitor SET active = 0 WHERE id = ? AND user_id = ? ", [
|
|
|
|
await R.exec("UPDATE monitor SET active = 0 WHERE id = ? ", [ monitorID ]);
|
|
|
|
monitorID,
|
|
|
|
|
|
|
|
userID,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (monitorID in server.monitorList) {
|
|
|
|
if (monitorID in server.monitorList) {
|
|
|
|
await server.monitorList[monitorID].stop();
|
|
|
|
await server.monitorList[monitorID].stop();
|
|
|
|