From 54aa68ec5883ce419917b59c93a3445df43201c3 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Wed, 15 Sep 2021 22:07:28 +0200 Subject: [PATCH 1/7] Added import/export compatibility for version 1.7 --- server/server.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/server/server.js b/server/server.js index b8d0c90f8..b284d868b 100644 --- a/server/server.js +++ b/server/server.js @@ -948,6 +948,8 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); await R.exec("DELETE FROM monitor_notification"); await R.exec("DELETE FROM monitor_tls_info"); await R.exec("DELETE FROM notification"); + await R.exec("DELETE FROM monitor_tag"); + await R.exec("DELETE FROM tag"); await R.exec("DELETE FROM monitor"); } @@ -972,11 +974,18 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); for (let i = 0; i < monitorListData.length; i++) { if ((importHandle == "skip" && monitorNameListString.includes(monitorListData[i].name) == false) || importHandle == "keep" || importHandle == "overwrite") { + if (backupData.version.includes("1.7")) { + var retryInterval = monitorListData[i].retryInterval; + } else { + var retryInterval = 0; + } + let monitor = { name: monitorListData[i].name, type: monitorListData[i].type, url: monitorListData[i].url, interval: monitorListData[i].interval, + retryInterval: retryInterval, hostname: monitorListData[i].hostname, maxretries: monitorListData[i].maxretries, port: monitorListData[i].port, @@ -1002,6 +1011,34 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); bean.user_id = socket.userID await R.store(bean) + if (backupData.version.includes("1.7")) { + if (monitorListData[i].tags.length >= 1) { + for (let o = 0; o < monitorListData[i].tags.length; o++) { + + let tag = await R.findOne("tag", " name = ?", [ + monitorListData[i].tags[o].name, + ]) + + if (! tag) { + let beanTag = R.dispense("tag") + beanTag.name = monitorListData[i].tags[o].name + beanTag.color = monitorListData[i].tags[o].color + await R.store(beanTag) + + var tagId = beanTag.id + } else { + var tagId = tag.id + } + + await R.exec("INSERT INTO monitor_tag (tag_id, monitor_id, value) VALUES (?, ?, ?)", [ + tagId, + bean.id, + monitorListData[i].tags[o].value, + ]) + } + } + } + await updateMonitorNotification(bean.id, notificationIDList) if (monitorListData[i].active == 1) { From 8b463e70df7bb65bacc594ae6526ecadc3409b10 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Thu, 16 Sep 2021 12:29:33 +0200 Subject: [PATCH 2/7] Apply suggestions from @Saibamen Co-authored-by: Adam Stachowicz --- server/server.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/server.js b/server/server.js index b284d868b..9f6b889de 100644 --- a/server/server.js +++ b/server/server.js @@ -974,10 +974,10 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); for (let i = 0; i < monitorListData.length; i++) { if ((importHandle == "skip" && monitorNameListString.includes(monitorListData[i].name) == false) || importHandle == "keep" || importHandle == "overwrite") { + let retryInterval = 0; + if (backupData.version.includes("1.7")) { - var retryInterval = monitorListData[i].retryInterval; - } else { - var retryInterval = 0; + retryInterval = monitorListData[i].retryInterval; } let monitor = { @@ -1019,15 +1019,15 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); monitorListData[i].tags[o].name, ]) + let tagId = tag.id + if (! tag) { let beanTag = R.dispense("tag") beanTag.name = monitorListData[i].tags[o].name beanTag.color = monitorListData[i].tags[o].color await R.store(beanTag) - var tagId = beanTag.id - } else { - var tagId = tag.id + tagId = beanTag.id } await R.exec("INSERT INTO monitor_tag (tag_id, monitor_id, value) VALUES (?, ?, ?)", [ From 4bdada36a90d35eeb20d1a589f88824c2ef32293 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Thu, 16 Sep 2021 20:18:31 +0200 Subject: [PATCH 3/7] Removed if includes version --- server/server.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/server.js b/server/server.js index 9f6b889de..20f902ee5 100644 --- a/server/server.js +++ b/server/server.js @@ -933,6 +933,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); checkLogin(socket) let backupData = JSON.parse(uploadedJSON); + let version = backupData.version.replace(/\./g, ""); console.log(`Importing Backup, User ID: ${socket.userID}, Version: ${backupData.version}`) @@ -976,7 +977,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); let retryInterval = 0; - if (backupData.version.includes("1.7")) { + if (version >= 170) { retryInterval = monitorListData[i].retryInterval; } @@ -1011,7 +1012,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); bean.user_id = socket.userID await R.store(bean) - if (backupData.version.includes("1.7")) { + if (version >= 170) { if (monitorListData[i].tags.length >= 1) { for (let o = 0; o < monitorListData[i].tags.length; o++) { From 1b5e723f60ab1d8c843e02986468eed23602b15b Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Fri, 17 Sep 2021 03:25:18 +0200 Subject: [PATCH 4/7] Added descriptions to uploadBackup function --- server/server.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/server/server.js b/server/server.js index 20f902ee5..e9219a452 100644 --- a/server/server.js +++ b/server/server.js @@ -931,16 +931,19 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); socket.on("uploadBackup", async (uploadedJSON, importHandle, callback) => { try { checkLogin(socket) + console.log(`Importing Backup, User ID: ${socket.userID}, Version: ${backupData.version}`) let backupData = JSON.parse(uploadedJSON); - let version = backupData.version.replace(/\./g, ""); - - console.log(`Importing Backup, User ID: ${socket.userID}, Version: ${backupData.version}`) let notificationListData = backupData.notificationList; let monitorListData = backupData.monitorList; + // Converts the Uptime Kuma Version to a Number | 1.6.0 => 160 + let version = backupData.version.replace(/\./g, ""); + + // If the import option is "overwrite" it'll clear most of the tables, except "settings" and "user" if (importHandle == "overwrite") { + // Stops every monitor first, so it doesn't execute any heartbeat while importing for (let id in monitorList) { let monitor = monitorList[id] await monitor.stop() @@ -954,11 +957,14 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); await R.exec("DELETE FROM monitor"); } + // Only starts importing if the backup file contains at least one notification if (notificationListData.length >= 1) { + // Get every existing notification name and puts them in one simple string let notificationNameList = await R.getAll("SELECT name FROM notification"); let notificationNameListString = JSON.stringify(notificationNameList); for (let i = 0; i < notificationListData.length; i++) { + // Only starts importing the notification if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists if ((importHandle == "skip" && notificationNameListString.includes(notificationListData[i].name) == false) || importHandle == "keep" || importHandle == "overwrite") { let notification = JSON.parse(notificationListData[i].config); @@ -968,20 +974,34 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); } } + // Only starts importing if the backup file contains at least one monitor if (monitorListData.length >= 1) { + // Get every existing monitor name and puts them in one simple string let monitorNameList = await R.getAll("SELECT name FROM monitor"); let monitorNameListString = JSON.stringify(monitorNameList); for (let i = 0; i < monitorListData.length; i++) { + // Only starts importing the monitor if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists if ((importHandle == "skip" && monitorNameListString.includes(monitorListData[i].name) == false) || importHandle == "keep" || importHandle == "overwrite") { + // Define in here every new variable for monitors which where implemented after the first version of the Import/Export function (1.6.0) + // --- Start --- + + // Define default values let retryInterval = 0; + /* + Only replace the default value with the backup file data for the specific version, where it appears the first time + More information about that where "let version" will be defined + */ if (version >= 170) { retryInterval = monitorListData[i].retryInterval; } + // --- End --- + let monitor = { + // Define the new variable from earlier here name: monitorListData[i].name, type: monitorListData[i].type, url: monitorListData[i].url, @@ -1012,16 +1032,21 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); bean.user_id = socket.userID await R.store(bean) + // Only for backup files with the version 1.7.0 or higher, since there was the tag feature implemented if (version >= 170) { + // Only import if the specific monitor has tags assigned if (monitorListData[i].tags.length >= 1) { for (let o = 0; o < monitorListData[i].tags.length; o++) { + // Check if tag already exists and get data -> let tag = await R.findOne("tag", " name = ?", [ monitorListData[i].tags[o].name, ]) + // Set tagId to vaule from database let tagId = tag.id + // -> If it doesn't, create new tag from backup file if (! tag) { let beanTag = R.dispense("tag") beanTag.name = monitorListData[i].tags[o].name @@ -1031,6 +1056,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); tagId = beanTag.id } + // Assign the new created tag to the monitor await R.exec("INSERT INTO monitor_tag (tag_id, monitor_id, value) VALUES (?, ?, ?)", [ tagId, bean.id, @@ -1042,6 +1068,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); await updateMonitorNotification(bean.id, notificationIDList) + // If monitor was active start it immediately, otherwise pause it if (monitorListData[i].active == 1) { await startMonitor(socket.userID, bean.id); } else { From d3d43630310fbd05ab257ce9cfa48256bef37ab7 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Thu, 23 Sep 2021 17:15:11 +0200 Subject: [PATCH 5/7] Used compare-version instead of replace --- server/server.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/server/server.js b/server/server.js index 54970ecda..27d07378b 100644 --- a/server/server.js +++ b/server/server.js @@ -951,9 +951,8 @@ exports.entryPage = "dashboard"; let notificationListData = backupData.notificationList; let monitorListData = backupData.monitorList; - // Converts the Uptime Kuma Version to a Number | 1.6.0 => 160 - let version = backupData.version.replace(/\./g, ""); - + let version17x = compareVersions.compare(backupData.version, '1.7.0', '>=') + // If the import option is "overwrite" it'll clear most of the tables, except "settings" and "user" if (importHandle == "overwrite") { // Stops every monitor first, so it doesn't execute any heartbeat while importing @@ -1007,7 +1006,7 @@ exports.entryPage = "dashboard"; Only replace the default value with the backup file data for the specific version, where it appears the first time More information about that where "let version" will be defined */ - if (version >= 170) { + if (version17x) { retryInterval = monitorListData[i].retryInterval; } @@ -1046,7 +1045,7 @@ exports.entryPage = "dashboard"; await R.store(bean); // Only for backup files with the version 1.7.0 or higher, since there was the tag feature implemented - if (version >= 170) { + if (version17x) { // Only import if the specific monitor has tags assigned if (monitorListData[i].tags.length >= 1) { for (let o = 0; o < monitorListData[i].tags.length; o++) { From 7fb55b8875a79f7314a514112b454a7480e91e1d Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Thu, 23 Sep 2021 17:31:01 +0200 Subject: [PATCH 6/7] Fixed issues --- server/server.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/server.js b/server/server.js index 27d07378b..a19169063 100644 --- a/server/server.js +++ b/server/server.js @@ -26,6 +26,8 @@ debug("Importing http-graceful-shutdown"); const gracefulShutdown = require("http-graceful-shutdown"); debug("Importing prometheus-api-metrics"); const prometheusAPIMetrics = require("prometheus-api-metrics"); +debug("Importing compare-versions"); +const compareVersions = require("compare-versions"); debug("Importing 2FA Modules"); const notp = require("notp"); @@ -944,10 +946,11 @@ exports.entryPage = "dashboard"; socket.on("uploadBackup", async (uploadedJSON, importHandle, callback) => { try { checkLogin(socket) - console.log(`Importing Backup, User ID: ${socket.userID}, Version: ${backupData.version}`) let backupData = JSON.parse(uploadedJSON); + console.log(`Importing Backup, User ID: ${socket.userID}, Version: ${backupData.version}`) + let notificationListData = backupData.notificationList; let monitorListData = backupData.monitorList; From 720ea850e1628b21e4fcc96fe6d7bc03c0874755 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Thu, 23 Sep 2021 17:33:23 +0200 Subject: [PATCH 7/7] Added space between Dashboard and settings button --- src/layouts/Layout.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/Layout.vue b/src/layouts/Layout.vue index 2342ed1a8..6228d4fb8 100644 --- a/src/layouts/Layout.vue +++ b/src/layouts/Layout.vue @@ -23,7 +23,7 @@ {{ $t("Status Page") }} -