|
|
@ -1,8 +1,5 @@
|
|
|
|
console.log("Welcome to Uptime Kuma");
|
|
|
|
console.log("Welcome to Uptime Kuma");
|
|
|
|
|
|
|
|
|
|
|
|
// Alias
|
|
|
|
|
|
|
|
const server = module.exports;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check Node.js Version
|
|
|
|
// Check Node.js Version
|
|
|
|
const nodeVersion = parseInt(process.versions.node.split(".")[0]);
|
|
|
|
const nodeVersion = parseInt(process.versions.node.split(".")[0]);
|
|
|
|
const requiredVersion = 14;
|
|
|
|
const requiredVersion = 14;
|
|
|
@ -52,12 +49,25 @@ const notp = require("notp");
|
|
|
|
const base32 = require("thirty-two");
|
|
|
|
const base32 = require("thirty-two");
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Main monitor list
|
|
|
|
* `module.exports` (alias: `server`) should be inside this class, in order to avoid circular dependency issue.
|
|
|
|
* @type {{}}
|
|
|
|
* @type {UptimeKumaServer}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
server.monitorList = {};
|
|
|
|
class UptimeKumaServer {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Main monitor list
|
|
|
|
|
|
|
|
* @type {{}}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
monitorList = {};
|
|
|
|
|
|
|
|
entryPage = "dashboard";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async sendMonitorList(socket) {
|
|
|
|
|
|
|
|
let list = await getMonitorJSONList(socket.userID);
|
|
|
|
|
|
|
|
io.to(socket.userID).emit("monitorList", list);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// `module.exports` (alias: `server`) should be before this line, to avoid circular dependency issue
|
|
|
|
const server = module.exports = new UptimeKumaServer();
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Importing this project modules");
|
|
|
|
console.log("Importing this project modules");
|
|
|
|
debug("Importing Monitor");
|
|
|
|
debug("Importing Monitor");
|
|
|
@ -196,8 +206,6 @@ try {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.entryPage = "dashboard";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
(async () => {
|
|
|
|
Database.init(args);
|
|
|
|
Database.init(args);
|
|
|
|
await initDatabase(testMode);
|
|
|
|
await initDatabase(testMode);
|
|
|
@ -606,7 +614,7 @@ exports.entryPage = "dashboard";
|
|
|
|
|
|
|
|
|
|
|
|
await updateMonitorNotification(bean.id, notificationIDList);
|
|
|
|
await updateMonitorNotification(bean.id, notificationIDList);
|
|
|
|
|
|
|
|
|
|
|
|
await sendMonitorList(socket);
|
|
|
|
await server.sendMonitorList(socket);
|
|
|
|
await startMonitor(socket.userID, bean.id);
|
|
|
|
await startMonitor(socket.userID, bean.id);
|
|
|
|
|
|
|
|
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
@ -669,7 +677,7 @@ exports.entryPage = "dashboard";
|
|
|
|
await restartMonitor(socket.userID, bean.id);
|
|
|
|
await restartMonitor(socket.userID, bean.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await sendMonitorList(socket);
|
|
|
|
await server.sendMonitorList(socket);
|
|
|
|
|
|
|
|
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
ok: true,
|
|
|
|
ok: true,
|
|
|
@ -689,7 +697,7 @@ exports.entryPage = "dashboard";
|
|
|
|
socket.on("getMonitorList", async (callback) => {
|
|
|
|
socket.on("getMonitorList", async (callback) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
checkLogin(socket);
|
|
|
|
checkLogin(socket);
|
|
|
|
await sendMonitorList(socket);
|
|
|
|
await server.sendMonitorList(socket);
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
ok: true,
|
|
|
|
ok: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -763,7 +771,7 @@ exports.entryPage = "dashboard";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
checkLogin(socket);
|
|
|
|
checkLogin(socket);
|
|
|
|
await startMonitor(socket.userID, monitorID);
|
|
|
|
await startMonitor(socket.userID, monitorID);
|
|
|
|
await sendMonitorList(socket);
|
|
|
|
await server.sendMonitorList(socket);
|
|
|
|
|
|
|
|
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
ok: true,
|
|
|
|
ok: true,
|
|
|
@ -782,7 +790,7 @@ exports.entryPage = "dashboard";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
checkLogin(socket);
|
|
|
|
checkLogin(socket);
|
|
|
|
await pauseMonitor(socket.userID, monitorID);
|
|
|
|
await pauseMonitor(socket.userID, monitorID);
|
|
|
|
await sendMonitorList(socket);
|
|
|
|
await server.sendMonitorList(socket);
|
|
|
|
|
|
|
|
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
ok: true,
|
|
|
|
ok: true,
|
|
|
@ -818,7 +826,7 @@ exports.entryPage = "dashboard";
|
|
|
|
msg: "Deleted Successfully.",
|
|
|
|
msg: "Deleted Successfully.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await sendMonitorList(socket);
|
|
|
|
await server.sendMonitorList(socket);
|
|
|
|
// Clear heartbeat list on client
|
|
|
|
// Clear heartbeat list on client
|
|
|
|
await sendImportantHeartbeatList(socket, monitorID, true, true);
|
|
|
|
await sendImportantHeartbeatList(socket, monitorID, true, true);
|
|
|
|
|
|
|
|
|
|
|
@ -1308,7 +1316,7 @@ exports.entryPage = "dashboard";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await sendNotificationList(socket);
|
|
|
|
await sendNotificationList(socket);
|
|
|
|
await sendMonitorList(socket);
|
|
|
|
await server.sendMonitorList(socket);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
@ -1471,17 +1479,11 @@ async function checkOwner(userID, monitorID) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function sendMonitorList(socket) {
|
|
|
|
|
|
|
|
let list = await getMonitorJSONList(socket.userID);
|
|
|
|
|
|
|
|
io.to(socket.userID).emit("monitorList", list);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function afterLogin(socket, user) {
|
|
|
|
async function afterLogin(socket, user) {
|
|
|
|
socket.userID = user.id;
|
|
|
|
socket.userID = user.id;
|
|
|
|
socket.join(user.id);
|
|
|
|
socket.join(user.id);
|
|
|
|
|
|
|
|
|
|
|
|
let monitorList = await sendMonitorList(socket);
|
|
|
|
let monitorList = await server.sendMonitorList(socket);
|
|
|
|
sendNotificationList(socket);
|
|
|
|
sendNotificationList(socket);
|
|
|
|
sendProxyList(socket);
|
|
|
|
sendProxyList(socket);
|
|
|
|
|
|
|
|
|
|
|
|