From c79be19ec348129b6734aaf4ee2131880c2e01e4 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Mon, 23 Aug 2021 00:05:48 +0200 Subject: [PATCH 01/27] Added DNS Monitor Type --- db/patch7.sql | 80 +++++++++++++++++++++++++++++++++++++++ server/database.js | 2 +- server/model/monitor.js | 42 +++++++++++++++++++- server/server.js | 2 + server/util-server.js | 25 ++++++++++++ src/pages/EditMonitor.vue | 55 +++++++++++++++++++++++++++ 6 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 db/patch7.sql diff --git a/db/patch7.sql b/db/patch7.sql new file mode 100644 index 000000000..9e4ab13fa --- /dev/null +++ b/db/patch7.sql @@ -0,0 +1,80 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +PRAGMA foreign_keys = off; + +BEGIN TRANSACTION; + +create table monitor_dg_tmp ( + id INTEGER not null primary key autoincrement, + name VARCHAR(150), + active BOOLEAN default 1 not null, + user_id INTEGER references user on update cascade on delete + set + null, + interval INTEGER default 20 not null, + url TEXT, + type VARCHAR(20), + weight INTEGER default 2000, + hostname VARCHAR(255), + port INTEGER, + created_date DATETIME default (DATETIME('now')) not null, + keyword VARCHAR(255), + maxretries INTEGER NOT NULL DEFAULT 0, + ignore_tls BOOLEAN default 0 not null, + upside_down BOOLEAN default 0 not null, + maxredirects INTEGER default 10 not null, + accepted_statuscodes_json TEXT default '["200-299"]' not null, + dns_resolve_type VARCHAR(5), + dns_resolve_server VARCHAR(255) +); + +insert into + monitor_dg_tmp( + id, + name, + active, + user_id, + interval, + url, + type, + weight, + hostname, + port, + created_date, + keyword, + maxretries, + ignore_tls, + upside_down, + maxredirects, + accepted_statuscodes_json + ) +select + id, + name, + active, + user_id, + interval, + url, + type, + weight, + hostname, + port, + created_date, + keyword, + maxretries, + ignore_tls, + upside_down, + maxredirects, + accepted_statuscodes_json +from + monitor; + +drop table monitor; + +alter table + monitor_dg_tmp rename to monitor; + +create index user_id on monitor (user_id); + +COMMIT; + +PRAGMA foreign_keys = on; diff --git a/server/database.js b/server/database.js index ff0304f1f..802e24197 100644 --- a/server/database.js +++ b/server/database.js @@ -9,7 +9,7 @@ class Database { static templatePath = "./db/kuma.db" static path = "./data/kuma.db"; - static latestVersion = 6; + static latestVersion = 7; static noReject = true; static sqliteInstance = null; diff --git a/server/model/monitor.js b/server/model/monitor.js index 2b4839824..9420312f1 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -7,7 +7,7 @@ dayjs.extend(timezone) const axios = require("axios"); const { Prometheus } = require("../prometheus"); const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util"); -const { tcping, ping, checkCertificate, checkStatusCode } = require("../util-server"); +const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode } = require("../util-server"); const { R } = require("redbean-node"); const { BeanModel } = require("redbean-node/dist/bean-model"); const { Notification } = require("../notification") @@ -48,6 +48,8 @@ class Monitor extends BeanModel { upsideDown: this.isUpsideDown(), maxredirects: this.maxredirects, accepted_statuscodes: this.getAcceptedStatuscodes(), + dns_resolve_type: this.dns_resolve_type, + dns_resolve_server: this.dns_resolve_server, notificationIDList, }; } @@ -175,6 +177,44 @@ class Monitor extends BeanModel { bean.ping = await ping(this.hostname); bean.msg = "" bean.status = UP; + } else if (this.type === "dns") { + let startTime = dayjs().valueOf(); + + var dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type); + + var dnsMessage = ""; + + if (this.dns_resolve_type == 'A' || this.dns_resolve_type == 'AAAA' || this.dns_resolve_type == 'CNAME' || this.dns_resolve_type == 'PTR') { + var dnsMessage = dnsRes[0]; + } else if (this.dns_resolve_type == 'CAA') { + var dnsMessage = dnsRes[0].issue; + } else if (this.dns_resolve_type == 'MX') { + dnsRes.forEach(record => { + dnsMessage += `Server: ${record.exchange} - Priority: ${record.priority} | `; + }); + var dnsMessage = dnsMessage.slice(0, -2) + } else if (this.dns_resolve_type == 'NS') { + dnsRes.forEach(record => { + dnsMessage += `Server: ${record} | `; + }); + var dnsMessage = dnsMessage.slice(0, -2) + } else if (this.dns_resolve_type == 'SOA') { + dnsMessage += `NS-Name: ${dnsRes.nsname} | Hostmaster: ${dnsRes.hostmaster} | Serial: ${dnsRes.serial} | Refresh: ${dnsRes.refresh} | Retry: ${dnsRes.retry} | Expire: ${dnsRes.expire} | MinTTL: ${dnsRes.minttl}`; + } else if (this.dns_resolve_type == 'SRV') { + dnsRes.forEach(record => { + dnsMessage += `Name: ${record.name} | Port: ${record.port} | Priority: ${record.priority} | Weight: ${record.weight} | `; + }); + var dnsMessage = dnsMessage.slice(0, -2) + } else if (this.dns_resolve_type == 'TXT') { + dnsRes.forEach(record => { + dnsMessage += `Record: ${record} | `; + }); + var dnsMessage = dnsMessage.slice(0, -2) + } + + bean.msg = dnsMessage; + bean.ping = dayjs().valueOf() - startTime; + bean.status = UP; } if (this.isUpsideDown()) { diff --git a/server/server.js b/server/server.js index 7c4441187..6fd15f73e 100644 --- a/server/server.js +++ b/server/server.js @@ -293,6 +293,8 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); bean.upsideDown = monitor.upsideDown; bean.maxredirects = monitor.maxredirects; bean.accepted_statuscodes_json = JSON.stringify(monitor.accepted_statuscodes); + bean.dns_resolve_type = monitor.dns_resolve_type; + bean.dns_resolve_server = monitor.dns_resolve_server; await R.store(bean) diff --git a/server/util-server.js b/server/util-server.js index 8a2f03879..2628a4fe5 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -4,6 +4,7 @@ const { R } = require("redbean-node"); const { debug } = require("../src/util"); const passwordHash = require("./password-hash"); const dayjs = require("dayjs"); +const { Resolver } = require('dns'); /** * Init or reset JWT secret @@ -76,6 +77,30 @@ exports.pingAsync = function (hostname, ipv6 = false) { }); } +exports.dnsResolve = function (hostname, resolver_server, rrtype) { + const resolver = new Resolver(); + resolver.setServers([resolver_server]); + return new Promise((resolve, reject) => { + if (rrtype == 'PTR') { + resolver.reverse(hostname, (err, records) => { + if (err) { + reject(err); + } else { + resolve(records); + } + }); + } else { + resolver.resolve(hostname, rrtype, (err, records) => { + if (err) { + reject(err); + } else { + resolve(records); + } + }); + } + }) +} + exports.setting = async function (key) { let value = await R.getCell("SELECT `value` FROM setting WHERE `key` = ? ", [ key, diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 749921ea1..f55b8d4a6 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -23,6 +23,9 @@ + @@ -54,6 +57,41 @@ +
+ + +
+ +
+ + +
+ Cloudflare is the default server, you can change the resolver server anytime. +
+
+ +
+ + + + +
+ Select the RR-Type you want to monitor +
+
+
@@ -170,6 +208,8 @@ export default { notificationIDList: {}, }, acceptedStatusCodeOptions: [], + dnsresolvetypeOptions: [], + ipRegex: "((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))", } }, @@ -200,11 +240,25 @@ export default { "500-599", ]; + let dnsresolvetypeOptions = [ + "A", + "AAAA", + "CAA", + "CNAME", + "MX", + "NS", + "PTR", + "SOA", + "SRV", + "TXT", + ]; + for (let i = 100; i <= 999; i++) { acceptedStatusCodeOptions.push(i.toString()); } this.acceptedStatusCodeOptions = acceptedStatusCodeOptions; + this.dnsresolvetypeOptions = dnsresolvetypeOptions; }, methods: { init() { @@ -221,6 +275,7 @@ export default { upsideDown: false, maxredirects: 10, accepted_statuscodes: ["200-299"], + dns_resolve_server: "1.1.1.1", } } else if (this.isEdit) { this.$root.getSocket().emit("getMonitor", this.$route.params.id, (res) => { From e5981b10ce6c84485efcf07912bbda33756b9d7b Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Mon, 23 Aug 2021 00:05:48 +0200 Subject: [PATCH 02/27] Replaced var with let and removed re-declaration --- server/model/monitor.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 9420312f1..4fa8e2979 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -179,41 +179,40 @@ class Monitor extends BeanModel { bean.status = UP; } else if (this.type === "dns") { let startTime = dayjs().valueOf(); + let dnsMessage = ""; - var dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type); - - var dnsMessage = ""; + let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type); + bean.ping = dayjs().valueOf() - startTime; if (this.dns_resolve_type == 'A' || this.dns_resolve_type == 'AAAA' || this.dns_resolve_type == 'CNAME' || this.dns_resolve_type == 'PTR') { - var dnsMessage = dnsRes[0]; + dnsMessage = dnsRes[0]; } else if (this.dns_resolve_type == 'CAA') { - var dnsMessage = dnsRes[0].issue; + dnsMessage = dnsRes[0].issue; } else if (this.dns_resolve_type == 'MX') { dnsRes.forEach(record => { dnsMessage += `Server: ${record.exchange} - Priority: ${record.priority} | `; }); - var dnsMessage = dnsMessage.slice(0, -2) + dnsMessage = dnsMessage.slice(0, -2) } else if (this.dns_resolve_type == 'NS') { dnsRes.forEach(record => { dnsMessage += `Server: ${record} | `; }); - var dnsMessage = dnsMessage.slice(0, -2) + dnsMessage = dnsMessage.slice(0, -2) } else if (this.dns_resolve_type == 'SOA') { dnsMessage += `NS-Name: ${dnsRes.nsname} | Hostmaster: ${dnsRes.hostmaster} | Serial: ${dnsRes.serial} | Refresh: ${dnsRes.refresh} | Retry: ${dnsRes.retry} | Expire: ${dnsRes.expire} | MinTTL: ${dnsRes.minttl}`; } else if (this.dns_resolve_type == 'SRV') { dnsRes.forEach(record => { dnsMessage += `Name: ${record.name} | Port: ${record.port} | Priority: ${record.priority} | Weight: ${record.weight} | `; }); - var dnsMessage = dnsMessage.slice(0, -2) + dnsMessage = dnsMessage.slice(0, -2) } else if (this.dns_resolve_type == 'TXT') { dnsRes.forEach(record => { dnsMessage += `Record: ${record} | `; }); - var dnsMessage = dnsMessage.slice(0, -2) + dnsMessage = dnsMessage.slice(0, -2) } bean.msg = dnsMessage; - bean.ping = dayjs().valueOf() - startTime; bean.status = UP; } From b2041cb36b5824eac89eacf1763591264c1f732e Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Mon, 23 Aug 2021 16:30:11 +0200 Subject: [PATCH 03/27] Fixed ESLint Errors --- server/model/monitor.js | 14 +++++++------- server/util-server.js | 4 ++-- src/pages/EditMonitor.vue | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 4fa8e2979..bdfa59555 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -184,28 +184,28 @@ class Monitor extends BeanModel { let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type); bean.ping = dayjs().valueOf() - startTime; - if (this.dns_resolve_type == 'A' || this.dns_resolve_type == 'AAAA' || this.dns_resolve_type == 'CNAME' || this.dns_resolve_type == 'PTR') { + if (this.dns_resolve_type == "A" || this.dns_resolve_type == "AAAA" || this.dns_resolve_type == "CNAME" || this.dns_resolve_type == "PTR") { dnsMessage = dnsRes[0]; - } else if (this.dns_resolve_type == 'CAA') { + } else if (this.dns_resolve_type == "CAA") { dnsMessage = dnsRes[0].issue; - } else if (this.dns_resolve_type == 'MX') { + } else if (this.dns_resolve_type == "MX") { dnsRes.forEach(record => { dnsMessage += `Server: ${record.exchange} - Priority: ${record.priority} | `; }); dnsMessage = dnsMessage.slice(0, -2) - } else if (this.dns_resolve_type == 'NS') { + } else if (this.dns_resolve_type == "NS") { dnsRes.forEach(record => { dnsMessage += `Server: ${record} | `; }); dnsMessage = dnsMessage.slice(0, -2) - } else if (this.dns_resolve_type == 'SOA') { + } else if (this.dns_resolve_type == "SOA") { dnsMessage += `NS-Name: ${dnsRes.nsname} | Hostmaster: ${dnsRes.hostmaster} | Serial: ${dnsRes.serial} | Refresh: ${dnsRes.refresh} | Retry: ${dnsRes.retry} | Expire: ${dnsRes.expire} | MinTTL: ${dnsRes.minttl}`; - } else if (this.dns_resolve_type == 'SRV') { + } else if (this.dns_resolve_type == "SRV") { dnsRes.forEach(record => { dnsMessage += `Name: ${record.name} | Port: ${record.port} | Priority: ${record.priority} | Weight: ${record.weight} | `; }); dnsMessage = dnsMessage.slice(0, -2) - } else if (this.dns_resolve_type == 'TXT') { + } else if (this.dns_resolve_type == "TXT") { dnsRes.forEach(record => { dnsMessage += `Record: ${record} | `; }); diff --git a/server/util-server.js b/server/util-server.js index 2628a4fe5..a30bcfec0 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -4,7 +4,7 @@ const { R } = require("redbean-node"); const { debug } = require("../src/util"); const passwordHash = require("./password-hash"); const dayjs = require("dayjs"); -const { Resolver } = require('dns'); +const { Resolver } = require("dns"); /** * Init or reset JWT secret @@ -81,7 +81,7 @@ exports.dnsResolve = function (hostname, resolver_server, rrtype) { const resolver = new Resolver(); resolver.setServers([resolver_server]); return new Promise((resolve, reject) => { - if (rrtype == 'PTR') { + if (rrtype == "PTR") { resolver.reverse(hostname, (err, records) => { if (err) { reject(err); diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index f55b8d4a6..17754c694 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -64,7 +64,7 @@
- +
Cloudflare is the default server, you can change the resolver server anytime.
From 054186370e210b7d3c0f77bdf0233c639c7453c4 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 24 Aug 2021 15:00:30 +0800 Subject: [PATCH 04/27] add source of ipRegex --- src/pages/EditMonitor.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 17754c694..6b75805cd 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -209,6 +209,8 @@ export default { }, acceptedStatusCodeOptions: [], dnsresolvetypeOptions: [], + + // Source: https://digitalfortress.tech/tips/top-15-commonly-used-regex/ ipRegex: "((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))", } }, From 44d9fa63f06ec97f72bc258404a48a87c651954c Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Tue, 24 Aug 2021 11:47:12 +0200 Subject: [PATCH 05/27] Adjusted the output for A and AAAA records --- server/model/monitor.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index bdfa59555..40abf1f1d 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -184,18 +184,25 @@ class Monitor extends BeanModel { let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type); bean.ping = dayjs().valueOf() - startTime; - if (this.dns_resolve_type == "A" || this.dns_resolve_type == "AAAA" || this.dns_resolve_type == "CNAME" || this.dns_resolve_type == "PTR") { + if (this.dns_resolve_type == "A" || this.dns_resolve_type == "AAAA") { + dnsMessage += "Records: "; + dnsRes.forEach(record => { + dnsMessage += `${record} | `; + }); + dnsMessage = dnsMessage.slice(0, -2) + } else if (this.dns_resolve_type == "CNAME" || this.dns_resolve_type == "PTR") { dnsMessage = dnsRes[0]; } else if (this.dns_resolve_type == "CAA") { dnsMessage = dnsRes[0].issue; } else if (this.dns_resolve_type == "MX") { dnsRes.forEach(record => { - dnsMessage += `Server: ${record.exchange} - Priority: ${record.priority} | `; + dnsMessage += `Hostname: ${record.exchange} - Priority: ${record.priority} | `; }); dnsMessage = dnsMessage.slice(0, -2) } else if (this.dns_resolve_type == "NS") { + dnsMessage += "Servers: "; dnsRes.forEach(record => { - dnsMessage += `Server: ${record} | `; + dnsMessage += `${record} | `; }); dnsMessage = dnsMessage.slice(0, -2) } else if (this.dns_resolve_type == "SOA") { From d313a06d5c21f90376a88280324e74de57d10bb6 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Wed, 25 Aug 2021 09:31:42 +0200 Subject: [PATCH 06/27] Optimizations for output handling --- server/model/monitor.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 40abf1f1d..69fc2c917 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -184,12 +184,9 @@ class Monitor extends BeanModel { let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type); bean.ping = dayjs().valueOf() - startTime; - if (this.dns_resolve_type == "A" || this.dns_resolve_type == "AAAA") { + if (this.dns_resolve_type == "A" || this.dns_resolve_type == "AAAA" || this.dns_resolve_type == "TXT") { dnsMessage += "Records: "; - dnsRes.forEach(record => { - dnsMessage += `${record} | `; - }); - dnsMessage = dnsMessage.slice(0, -2) + dnsMessage += dnsRes.join(" | "); } else if (this.dns_resolve_type == "CNAME" || this.dns_resolve_type == "PTR") { dnsMessage = dnsRes[0]; } else if (this.dns_resolve_type == "CAA") { @@ -201,10 +198,7 @@ class Monitor extends BeanModel { dnsMessage = dnsMessage.slice(0, -2) } else if (this.dns_resolve_type == "NS") { dnsMessage += "Servers: "; - dnsRes.forEach(record => { - dnsMessage += `${record} | `; - }); - dnsMessage = dnsMessage.slice(0, -2) + dnsMessage += dnsRes.join(" | "); } else if (this.dns_resolve_type == "SOA") { dnsMessage += `NS-Name: ${dnsRes.nsname} | Hostmaster: ${dnsRes.hostmaster} | Serial: ${dnsRes.serial} | Refresh: ${dnsRes.refresh} | Retry: ${dnsRes.retry} | Expire: ${dnsRes.expire} | MinTTL: ${dnsRes.minttl}`; } else if (this.dns_resolve_type == "SRV") { @@ -212,11 +206,6 @@ class Monitor extends BeanModel { dnsMessage += `Name: ${record.name} | Port: ${record.port} | Priority: ${record.priority} | Weight: ${record.weight} | `; }); dnsMessage = dnsMessage.slice(0, -2) - } else if (this.dns_resolve_type == "TXT") { - dnsRes.forEach(record => { - dnsMessage += `Record: ${record} | `; - }); - dnsMessage = dnsMessage.slice(0, -2) } bean.msg = dnsMessage; From 02a12e68b81ce51e8e67c2d3fdbf1733a420bb81 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Wed, 25 Aug 2021 12:45:47 +0200 Subject: [PATCH 07/27] Used ALTER TABLE instead of rebuilding the table --- db/patch7.sql | 78 +++------------------------------------------------ 1 file changed, 4 insertions(+), 74 deletions(-) diff --git a/db/patch7.sql b/db/patch7.sql index 9e4ab13fa..2e8eba15c 100644 --- a/db/patch7.sql +++ b/db/patch7.sql @@ -1,80 +1,10 @@ -- You should not modify if this have pushed to Github, unless it does serious wrong with the db. -PRAGMA foreign_keys = off; - BEGIN TRANSACTION; -create table monitor_dg_tmp ( - id INTEGER not null primary key autoincrement, - name VARCHAR(150), - active BOOLEAN default 1 not null, - user_id INTEGER references user on update cascade on delete - set - null, - interval INTEGER default 20 not null, - url TEXT, - type VARCHAR(20), - weight INTEGER default 2000, - hostname VARCHAR(255), - port INTEGER, - created_date DATETIME default (DATETIME('now')) not null, - keyword VARCHAR(255), - maxretries INTEGER NOT NULL DEFAULT 0, - ignore_tls BOOLEAN default 0 not null, - upside_down BOOLEAN default 0 not null, - maxredirects INTEGER default 10 not null, - accepted_statuscodes_json TEXT default '["200-299"]' not null, - dns_resolve_type VARCHAR(5), - dns_resolve_server VARCHAR(255) -); - -insert into - monitor_dg_tmp( - id, - name, - active, - user_id, - interval, - url, - type, - weight, - hostname, - port, - created_date, - keyword, - maxretries, - ignore_tls, - upside_down, - maxredirects, - accepted_statuscodes_json - ) -select - id, - name, - active, - user_id, - interval, - url, - type, - weight, - hostname, - port, - created_date, - keyword, - maxretries, - ignore_tls, - upside_down, - maxredirects, - accepted_statuscodes_json -from - monitor; - -drop table monitor; +ALTER TABLE monitor + ADD dns_resolve_type VARCHAR(5); -alter table - monitor_dg_tmp rename to monitor; - -create index user_id on monitor (user_id); +ALTER TABLE monitor + ADD dns_resolve_server VARCHAR(255); COMMIT; - -PRAGMA foreign_keys = on; From 8318c2e8ffb375573cd9b36ac495806dacdd079d Mon Sep 17 00:00:00 2001 From: LouisLam Date: Thu, 26 Aug 2021 01:50:27 +0800 Subject: [PATCH 08/27] add a simple dns server for testing, and disable ipRegex for dev only (need to input port) --- extra/simple-dns-server.js | 58 ++++++++++++++++++++++++++++++++++++++ package-lock.json | 13 +++++++++ package.json | 4 ++- src/pages/EditMonitor.vue | 15 ++++++++-- 4 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 extra/simple-dns-server.js diff --git a/extra/simple-dns-server.js b/extra/simple-dns-server.js new file mode 100644 index 000000000..bf50aed03 --- /dev/null +++ b/extra/simple-dns-server.js @@ -0,0 +1,58 @@ +/* + * Simple DNS Server + * For testing DNS monitoring type, dev only + */ +const dns2 = require("dns2"); + +const { Packet } = dns2; + +const server = dns2.createServer({ + udp: true +}); + +server.on("request", (request, send, rinfo) => { + for (let question of request.questions) { + console.log(question.name, type(question.type), question.class); + + const response = Packet.createResponseFromRequest(request); + + if (question.name === "existing.com") { + + if (question.type === Packet.TYPE.A) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + address: "1.2.3.4" + }); + } + + // TODO: all other types + + } + + send(response); + } +}); + +server.on("listening", () => { + console.log("Listening"); + console.log(server.addresses()); +}); + +server.on("close", () => { + console.log("server closed"); +}); + +server.listen({ + udp: 5300 +}); + +function type(code) { + for (let name in Packet.TYPE) { + if (Packet.TYPE[name] === code) { + return name; + } + } +} diff --git a/package-lock.json b/package-lock.json index cc1feebc5..61bab41eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,6 +53,7 @@ "@vitejs/plugin-vue": "^1.4.0", "@vue/compiler-sfc": "^3.2.2", "core-js": "^3.16.1", + "dns2": "^2.0.1", "eslint": "^7.32.0", "eslint-plugin-vue": "^7.16.0", "sass": "^1.37.5", @@ -2457,6 +2458,12 @@ "node": ">=8" } }, + "node_modules/dns2": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/dns2/-/dns2-2.0.1.tgz", + "integrity": "sha512-jHRTCcS2h/MEQjhcCnOWGENtz5A4RrLoK1YFqlHCejGfK5zYu99C8cxVwTsIY7JUqolhDN8zuGlyqnbEe6azqg==", + "dev": true + }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -9441,6 +9448,12 @@ "path-type": "^4.0.0" } }, + "dns2": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/dns2/-/dns2-2.0.1.tgz", + "integrity": "sha512-jHRTCcS2h/MEQjhcCnOWGENtz5A4RrLoK1YFqlHCejGfK5zYu99C8cxVwTsIY7JUqolhDN8zuGlyqnbEe6azqg==", + "dev": true + }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", diff --git a/package.json b/package.json index 2d20c4094..24e67373f 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "test-install-script-alpine3": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/alpine3.dockerfile .", "test-install-script-ubuntu": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu.dockerfile .", "test-install-script-ubuntu1604": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu1604.dockerfile .", - "test-install-script-debian": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/debian.dockerfile ." + "test-install-script-debian": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/debian.dockerfile .", + "simple-dns-server": "node extra/simple-dns-server.js" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.36", @@ -79,6 +80,7 @@ "@vitejs/plugin-vue": "^1.4.0", "@vue/compiler-sfc": "^3.2.2", "core-js": "^3.16.1", + "dns2": "^2.0.1", "eslint": "^7.32.0", "eslint-plugin-vue": "^7.16.0", "sass": "^1.37.5", diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index f597f0742..4c0675252 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -193,6 +193,7 @@ import NotificationDialog from "../components/NotificationDialog.vue"; import { useToast } from "vue-toastification" import VueMultiselect from "vue-multiselect" +import { isDev } from "../util.ts"; const toast = useToast() export default { @@ -209,13 +210,23 @@ export default { }, acceptedStatusCodeOptions: [], dnsresolvetypeOptions: [], - + // Source: https://digitalfortress.tech/tips/top-15-commonly-used-regex/ - ipRegex: "((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))", + ipRegexPattern: "((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))", } }, computed: { + + ipRegex() { + + // Allow to test with simple dns server with port (127.0.0.1:5300) + if (! isDev) { + return this.ipRegexPattern; + } + return null; + }, + pageName() { return this.$t((this.isAdd) ? "Add New Monitor" : "Edit"); }, From 508586fcfdbab19a8ae87f63e59a25faa3289bee Mon Sep 17 00:00:00 2001 From: LouisLam Date: Thu, 26 Aug 2021 20:36:58 +0800 Subject: [PATCH 09/27] add codesandbox config for demo --- package.json | 3 ++- sandbox.config.json | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 sandbox.config.json diff --git a/package.json b/package.json index 24e67373f..b4075b474 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "test-install-script-ubuntu": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu.dockerfile .", "test-install-script-ubuntu1604": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu1604.dockerfile .", "test-install-script-debian": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/debian.dockerfile .", - "simple-dns-server": "node extra/simple-dns-server.js" + "simple-dns-server": "node extra/simple-dns-server.js", + "codesandbox": "npm run build && npm run start-server" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.36", diff --git a/sandbox.config.json b/sandbox.config.json new file mode 100644 index 000000000..d51303a5d --- /dev/null +++ b/sandbox.config.json @@ -0,0 +1,10 @@ +{ + "infiniteLoopProtection": true, + "hardReloadOnChange": false, + "view": "browser", + "container": { + "node": "14", + "port": 3001, + "startScript": "codesandbox" + } +} From 177af2d58807fa922cdc10d80f970f4963f465af Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Fri, 27 Aug 2021 17:32:50 +0200 Subject: [PATCH 10/27] Added more dns types to simple-dns-server --- extra/simple-dns-server.js | 87 +++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/extra/simple-dns-server.js b/extra/simple-dns-server.js index bf50aed03..e84e57426 100644 --- a/extra/simple-dns-server.js +++ b/extra/simple-dns-server.js @@ -26,10 +26,95 @@ server.on("request", (request, send, rinfo) => { ttl: 300, address: "1.2.3.4" }); + } if (question.type === Packet.TYPE.AAAA) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + address: "fe80::::1234:5678:abcd:ef00", + }); + } else if (question.type === Packet.TYPE.CNAME) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + domain: "cname1.existing.com", + }); + } else if (question.type === Packet.TYPE.MX) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + exchange: "mx1.existing.com", + priority: 5 + }); + } else if (question.type === Packet.TYPE.NS) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + ns: "ns1.existing.com", + }); + } else if (question.type === Packet.TYPE.PTR) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + domain: "ptr1.existing.com", + }); + } else if (question.type === Packet.TYPE.SOA) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + primary: "existing.com", + admin: "admin@existing.com", + serial: 2021082701, + refresh: 300, + retry: 3, + expiration: 10, + minimum: 10, + }); + } else if (question.type === Packet.TYPE.SRV) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + priority: 5, + weight: 5, + port: 8080, + target: "srv1.existing.com", + }); + } else if (question.type === Packet.TYPE.TXT) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + data: "#v=spf1 include:_spf.existing.com ~all", + }); } - // TODO: all other types + // TODO: CAA type + } + if (question.name === "4.3.2.1.in-addr.arpa") { + if (question.type === Packet.TYPE.PTR) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + domain: "ptr1.existing.com", + }); + } } send(response); From acd5cf63fd29a348b77b302228b56dff1e788e33 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Fri, 27 Aug 2021 17:41:22 +0200 Subject: [PATCH 11/27] Removed wrong PTR answer --- extra/simple-dns-server.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/extra/simple-dns-server.js b/extra/simple-dns-server.js index e84e57426..4be3f68e8 100644 --- a/extra/simple-dns-server.js +++ b/extra/simple-dns-server.js @@ -59,14 +59,6 @@ server.on("request", (request, send, rinfo) => { ttl: 300, ns: "ns1.existing.com", }); - } else if (question.type === Packet.TYPE.PTR) { - response.answers.push({ - name: question.name, - type: question.type, - class: question.class, - ttl: 300, - domain: "ptr1.existing.com", - }); } else if (question.type === Packet.TYPE.SOA) { response.answers.push({ name: question.name, From 03b4086372d1be7dfde9062cd1aa0c1bb0c5dc69 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Fri, 27 Aug 2021 23:57:42 +0800 Subject: [PATCH 12/27] add CAA test and remove some files added by mistake --- extra/simple-dns-server.js | 11 ++++++++++- package.json | 3 +-- sandbox.config.json | 10 ---------- 3 files changed, 11 insertions(+), 13 deletions(-) delete mode 100644 sandbox.config.json diff --git a/extra/simple-dns-server.js b/extra/simple-dns-server.js index 4be3f68e8..5e5745f04 100644 --- a/extra/simple-dns-server.js +++ b/extra/simple-dns-server.js @@ -92,9 +92,18 @@ server.on("request", (request, send, rinfo) => { ttl: 300, data: "#v=spf1 include:_spf.existing.com ~all", }); + } else if (question.type === Packet.TYPE.CAA) { + response.answers.push({ + name: question.name, + type: question.type, + class: question.class, + ttl: 300, + flags: 0, + tag: "issue", + value: "ca.existing.com", + }); } - // TODO: CAA type } if (question.name === "4.3.2.1.in-addr.arpa") { diff --git a/package.json b/package.json index b4075b474..24e67373f 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,7 @@ "test-install-script-ubuntu": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu.dockerfile .", "test-install-script-ubuntu1604": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu1604.dockerfile .", "test-install-script-debian": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/debian.dockerfile .", - "simple-dns-server": "node extra/simple-dns-server.js", - "codesandbox": "npm run build && npm run start-server" + "simple-dns-server": "node extra/simple-dns-server.js" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.36", diff --git a/sandbox.config.json b/sandbox.config.json deleted file mode 100644 index d51303a5d..000000000 --- a/sandbox.config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "infiniteLoopProtection": true, - "hardReloadOnChange": false, - "view": "browser", - "container": { - "node": "14", - "port": 3001, - "startScript": "codesandbox" - } -} From 6464207f4b2a4bcac928330c686b36bb0bd8a753 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Fri, 27 Aug 2021 18:41:58 +0200 Subject: [PATCH 13/27] Added German language for DNS Monitor --- src/languages/de-DE.js | 3 +++ src/languages/en.js | 2 ++ src/pages/EditMonitor.vue | 8 ++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/languages/de-DE.js b/src/languages/de-DE.js index b2bb6081d..93d3da1d1 100644 --- a/src/languages/de-DE.js +++ b/src/languages/de-DE.js @@ -99,4 +99,7 @@ export default { keywordDescription: "Suche nach einen Schlüsselwort in einer schlichten HTML oder JSON Ausgabe. Bitte beachte, es wird in der Groß-/Kleinschreibung unterschieden.", deleteMonitorMsg: "Bist du sicher das du den Monitor löschen möchtest?", deleteNotificationMsg: "Möchtest du diese Benachrichtigung wirklich für alle Monitore löschen?", + resoverserverDescription: "Cloudflare ist der Standardserver, dieser kann jederzeit geändern werden.", + "Resolver Server": "Auflösungsserver", + rrtypeDescription: "Wähle den RR-Typ aus, welchen du überwachen möchtest.", } diff --git a/src/languages/en.js b/src/languages/en.js index 05e3fc929..ebacfac8e 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -13,4 +13,6 @@ export default { pauseDashboardHome: "Pause", deleteMonitorMsg: "Are you sure want to delete this monitor?", deleteNotificationMsg: "Are you sure want to delete this notification for all monitors?", + resoverserverDescription: "Cloudflare is the default server, you can change the resolver server anytime.", + rrtypeDescription: "Select the RR-Type you want to monitor", } diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 33dc16217..c3692783b 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -43,7 +43,7 @@
- {{ $t("keywordDescription")}} + {{ $t("keywordDescription") }}
@@ -63,10 +63,10 @@
- +
- Cloudflare is the default server, you can change the resolver server anytime. + {{ $t("resoverserverDescription") }}
@@ -88,7 +88,7 @@ >
- Select the RR-Type you want to monitor + {{ $t("rrtypeDescription") }}
From d4dd650bfe77c5488afd39c6b573f1f12d210a25 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sat, 28 Aug 2021 11:20:02 +0800 Subject: [PATCH 14/27] translate for zh-hk --- src/languages/zh-HK.js | 4 ++++ src/pages/EditMonitor.vue | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/languages/zh-HK.js b/src/languages/zh-HK.js index c61434d45..d0cd334a6 100644 --- a/src/languages/zh-HK.js +++ b/src/languages/zh-HK.js @@ -99,4 +99,8 @@ export default { "Certificate Info": "憑證詳細資料", deleteMonitorMsg: "是否確定刪除這個監測器", deleteNotificationMsg: "是否確定刪除這個通知設定?如監測器啟用了這個通知,將會收不到通知。", + "Resolver Server": "DNS 伺服器", + "Resource Record Type": "DNS 記錄類型", + resoverserverDescription: "預設值為 Cloudflare DNS 伺服器,你可以轉用其他 DNS 伺服器。", + rrtypeDescription: "請選擇 DNS 記錄類型", } diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index c3692783b..18663ae57 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -71,7 +71,7 @@
- + Date: Sat, 28 Aug 2021 11:46:26 +0800 Subject: [PATCH 15/27] set default value for dns resolve type and code refactor --- src/pages/EditMonitor.vue | 122 ++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 18663ae57..552261735 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -47,50 +47,51 @@
-
+ +
+
-
- - -
- -
- - -
- {{ $t("resoverserverDescription") }} + +
@@ -124,35 +125,38 @@
-
- - -
- {{ $t("maxRedirectDescription") }} + +
@@ -207,6 +211,7 @@ export default { processing: false, monitor: { notificationIDList: {}, + // Do not add default value here, please check init() method }, acceptedStatusCodeOptions: [], dnsresolvetypeOptions: [], @@ -288,6 +293,7 @@ export default { upsideDown: false, maxredirects: 10, accepted_statuscodes: ["200-299"], + dns_resolve_type: "A", dns_resolve_server: "1.1.1.1", } } else if (this.isEdit) { From 59e93156473f8507a93adfe9c446a051f0a0208e Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sat, 28 Aug 2021 11:48:34 +0800 Subject: [PATCH 16/27] show dns type and hostname in Details.vue --- src/pages/Details.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/Details.vue b/src/pages/Details.vue index 1c389a910..f06f9e138 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -10,6 +10,7 @@
{{ $t("Keyword") }}: {{ monitor.keyword }} + [{{ monitor.dns_resolve_type }}] {{ monitor.hostname }}

From 46dcd31142891d098d6e268f9723dd5760b849ce Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 28 Aug 2021 12:29:57 +0800 Subject: [PATCH 17/27] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 025510f52..eece23e7d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ It is a self-hosted monitoring tool like "Uptime Robot". * Monitoring uptime for HTTP(s) / TCP / Ping. * Fancy, Reactive, Fast UI/UX. -* Notifications via Webhook, Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP) and more by Apprise. +* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP) and [70+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/issues/284). * 20 seconds interval. ## 🔧 How to Install From 309fbfa0943166c3c256573de6014f18df7bbff6 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 28 Aug 2021 12:32:35 +0800 Subject: [PATCH 18/27] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eece23e7d..2ba5d91c1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It is a self-hosted monitoring tool like "Uptime Robot". ## ⭐ Features -* Monitoring uptime for HTTP(s) / TCP / Ping. +* Monitoring uptime for HTTP(s) / TCP / Ping / DNS Record. * Fancy, Reactive, Fast UI/UX. * Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP) and [70+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/issues/284). * 20 seconds interval. From a14c40f9bb8c8a3deb9118924c11390bfc4bd515 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 28 Aug 2021 12:33:10 +0800 Subject: [PATCH 19/27] move k8s to advanced installation section --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 2ba5d91c1..4bd10c789 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,6 @@ docker run -d --restart=always -p 3001:3001 -v uptime-kuma:/app/data --name upti Browse to http://localhost:3001 after started. -### ☸️ Kubernetes - -See more [here](kubernetes/README.md) - - ### Advanced Installation If you need more options or need to browse via a reserve proxy, please read: From 0e676060f2ad4269ac6f02a43858c82656f581ad Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 28 Aug 2021 13:46:47 +0800 Subject: [PATCH 20/27] Update CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5bbf343a1..0734285c7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,13 +22,13 @@ If you are not sure, feel free to create an empty pull request draft first. ### *️⃣ Requires one more reviewer -I do not have such knowledge to test it +I do not have such knowledge to test it. - Add k8s supports ### *️⃣ Low Priority -It chnaged my current workflow and require further studies. +It changed my current workflow and require further studies. - Change my release approach From 27a4dbb722f7db8778ce9420be3962be93196e74 Mon Sep 17 00:00:00 2001 From: Arnish Baruah <61318157+arnishb@users.noreply.github.com> Date: Sat, 28 Aug 2021 16:40:32 +0530 Subject: [PATCH 21/27] fix-readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4bd10c789..d5f0d317e 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,14 @@ It is a self-hosted monitoring tool like "Uptime Robot". * Monitoring uptime for HTTP(s) / TCP / Ping / DNS Record. * Fancy, Reactive, Fast UI/UX. -* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP) and [70+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/issues/284). +* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [70+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/issues/284). * 20 seconds interval. ## 🔧 How to Install -### 🚀 Installer via cli +### 🚀 Installer via CLI -Interactive cli installer, supports Docker or without Docker. +Interactive CLI installer, supports Docker or without Docker. ```bash curl -o kuma_install.sh https://raw.githubusercontent.com/louislam/uptime-kuma/master/install.sh && sudo bash kuma_install.sh @@ -71,7 +71,7 @@ Telegram Notification Sample: ## Motivation -* I was looking for a self-hosted monitoring tool like "Uptime Robot", but it is hard to find a suitable one. One of the close one is statping. Unfortunately, it is not stable and unmaintained. +* I was looking for a self-hosted monitoring tool like "Uptime Robot", but it is hard to find a suitable one. One of the close ones is statping. Unfortunately, it is not stable and unmaintained. * Want to build a fancy UI. * Learn Vue 3 and vite.js. * Show the power of Bootstrap 5. @@ -84,6 +84,6 @@ If you love this project, please consider giving me a ⭐. If you want to report a bug or request a new feature. Free feel to open a new issue. -If you want to modify Uptime Kuma, this guideline maybe useful for you: https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md +If you want to modify Uptime Kuma, this guideline may be useful for you: https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md -English proofreading is needed too, because my grammar is not that great sadly. Feel free to correct my grammar in this Readme, source code or wiki. +English proofreading is needed too because my grammar is not that great sadly. Feel free to correct my grammar in this readme, source code, or wiki. From 303adbf9b13975636f48d9d33b1962e2685a28c9 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Sat, 28 Aug 2021 21:20:25 +0200 Subject: [PATCH 22/27] Show latest dns result in Details.vue --- db/patch7.sql | 3 +++ server/model/monitor.js | 12 ++++++++++++ src/pages/Details.vue | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/db/patch7.sql b/db/patch7.sql index 2e8eba15c..4085daf3f 100644 --- a/db/patch7.sql +++ b/db/patch7.sql @@ -7,4 +7,7 @@ ALTER TABLE monitor ALTER TABLE monitor ADD dns_resolve_server VARCHAR(255); +ALTER TABLE monitor + ADD dns_last_result VARCHAR(255); + COMMIT; diff --git a/server/model/monitor.js b/server/model/monitor.js index f5efadc1f..a01dd6142 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -50,6 +50,7 @@ class Monitor extends BeanModel { accepted_statuscodes: this.getAcceptedStatuscodes(), dns_resolve_type: this.dns_resolve_type, dns_resolve_server: this.dns_resolve_server, + dns_last_result: this.dns_last_result, notificationIDList, }; } @@ -207,6 +208,17 @@ class Monitor extends BeanModel { dnsMessage = dnsMessage.slice(0, -2) } + let dnsLastResult = await R.findOne("monitor", "id = ?", [ + this.id, + ]); + + if (dnsLastResult.dnsLastResult !== dnsMessage) { + R.exec("UPDATE `monitor` SET dns_last_result = ? WHERE id = ? ", [ + dnsMessage, + this.id + ]); + } + bean.msg = dnsMessage; bean.status = UP; } diff --git a/src/pages/Details.vue b/src/pages/Details.vue index f06f9e138..8da1112b6 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -10,7 +10,7 @@
{{ $t("Keyword") }}: {{ monitor.keyword }} - [{{ monitor.dns_resolve_type }}] {{ monitor.hostname }} + [{{ monitor.dns_resolve_type }}] {{ monitor.hostname }} [ {{ monitor.dns_last_result }} ]

From 2bb182b2b4251914e6cf5d883f597c887bbd9a2a Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 29 Aug 2021 03:28:40 +0800 Subject: [PATCH 23/27] Create FUNDING.yml --- .github/FUNDING.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..6e53fa086 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +#github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +#patreon: # Replace with a single Patreon username +open_collective: uptime-kuma # Replace with a single Open Collective username +#ko_fi: # Replace with a single Ko-fi username +#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +#liberapay: # Replace with a single Liberapay username +#issuehunt: # Replace with a single IssueHunt username +#otechie: # Replace with a single Otechie username +#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] From 858affa8089f5e0da98be8aa80538b55d2eafe4f Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Sat, 28 Aug 2021 21:29:24 +0200 Subject: [PATCH 24/27] Removed useless database query --- server/model/monitor.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index a01dd6142..6d0d812bd 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -208,11 +208,7 @@ class Monitor extends BeanModel { dnsMessage = dnsMessage.slice(0, -2) } - let dnsLastResult = await R.findOne("monitor", "id = ?", [ - this.id, - ]); - - if (dnsLastResult.dnsLastResult !== dnsMessage) { + if (this.dnsLastResult !== dnsMessage) { R.exec("UPDATE `monitor` SET dns_last_result = ? WHERE id = ? ", [ dnsMessage, this.id From 93edb8817dae96a35fa60c5a42e008a56bab52ef Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Sun, 29 Aug 2021 03:57:26 +0200 Subject: [PATCH 25/27] More uniform look --- src/languages/de-DE.js | 1 + src/pages/Details.vue | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/languages/de-DE.js b/src/languages/de-DE.js index 93d3da1d1..a4d84e76d 100644 --- a/src/languages/de-DE.js +++ b/src/languages/de-DE.js @@ -102,4 +102,5 @@ export default { resoverserverDescription: "Cloudflare ist der Standardserver, dieser kann jederzeit geändern werden.", "Resolver Server": "Auflösungsserver", rrtypeDescription: "Wähle den RR-Typ aus, welchen du überwachen möchtest.", + "Last Result": "Letztes Ergebnis", } diff --git a/src/pages/Details.vue b/src/pages/Details.vue index 8da1112b6..10a27a9a3 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -10,7 +10,10 @@
{{ $t("Keyword") }}: {{ monitor.keyword }} - [{{ monitor.dns_resolve_type }}] {{ monitor.hostname }} [ {{ monitor.dns_last_result }} ] + [{{ monitor.dns_resolve_type }}] {{ monitor.hostname }} +
+ {{ $t("Last Result") }}: {{ monitor.dns_last_result }} +

From dd877cfc7043cb87fc91900ead911e615d1a048a Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Sun, 29 Aug 2021 04:03:55 +0200 Subject: [PATCH 26/27] Added translation to pause monitor confirmation --- src/languages/de-DE.js | 1 + src/languages/en.js | 1 + src/pages/Details.vue | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/languages/de-DE.js b/src/languages/de-DE.js index a4d84e76d..ba852cf32 100644 --- a/src/languages/de-DE.js +++ b/src/languages/de-DE.js @@ -103,4 +103,5 @@ export default { "Resolver Server": "Auflösungsserver", rrtypeDescription: "Wähle den RR-Typ aus, welchen du überwachen möchtest.", "Last Result": "Letztes Ergebnis", + pauseMonitorMsg: "Bist du sicher das du den Monitor pausieren möchtest?", } diff --git a/src/languages/en.js b/src/languages/en.js index ebacfac8e..75c25dd57 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -15,4 +15,5 @@ export default { deleteNotificationMsg: "Are you sure want to delete this notification for all monitors?", resoverserverDescription: "Cloudflare is the default server, you can change the resolver server anytime.", rrtypeDescription: "Select the RR-Type you want to monitor", + pauseMonitorMsg: "Are you sure want to pause?", } diff --git a/src/pages/Details.vue b/src/pages/Details.vue index 10a27a9a3..cc45e4034 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -165,8 +165,8 @@
- - Are you sure want to pause? + + {{ $t("pauseMonitorMsg") }} From ada660621786e259af299c7532154a938d583030 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sun, 29 Aug 2021 11:16:06 +0800 Subject: [PATCH 27/27] move the new sql to patch8.sql --- db/patch8.sql | 7 +++++++ server/database.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 db/patch8.sql diff --git a/db/patch8.sql b/db/patch8.sql new file mode 100644 index 000000000..d63a59476 --- /dev/null +++ b/db/patch8.sql @@ -0,0 +1,7 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +ALTER TABLE monitor + ADD dns_last_result VARCHAR(255); + +COMMIT; diff --git a/server/database.js b/server/database.js index 2b9b715cf..7ce81be11 100644 --- a/server/database.js +++ b/server/database.js @@ -6,7 +6,7 @@ class Database { static templatePath = "./db/kuma.db" static path = "./data/kuma.db"; - static latestVersion = 7; + static latestVersion = 8; static noReject = true; static sqliteInstance = null;