From e38742a2d0d4846cd72df127833dd6dcf87ba28d Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Mon, 11 Apr 2022 19:58:31 +0100 Subject: [PATCH 1/3] [empty commit] pull request for #1059 From b893d50e450dd9bfbe956cceafd9398df1236274 Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Wed, 13 Apr 2022 21:02:19 +0100 Subject: [PATCH 2/3] Implement specify Port for DNS Monitor #1059 This commit should fully implement #1059. When the user selects the DNS monitor option, a new input box has been added below the resolver address allowing the user to implement the port to access the resolver on. This uses the same `monitor.port` as the TCP monitor but a monitor has been added to prefill the port value to the default of `53` if the value in this field has not already been set. This is then cleared if the user selects a different monitor type and has not changed the port value. A translation has also been added explaining what this field does in order to reduce any confusion. JSDoc documentation has also been added to the `dnsResolve` function in `util-server.js`. Signed-off-by: Matthew Nickson --- server/model/monitor.js | 2 +- server/util-server.js | 12 ++++++++++-- src/languages/en.js | 1 + src/pages/EditMonitor.vue | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index c4441d63..682fd72e 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -249,7 +249,7 @@ class Monitor extends BeanModel { let startTime = dayjs().valueOf(); let dnsMessage = ""; - let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type); + let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.port, this.dns_resolve_type); bean.ping = dayjs().valueOf() - startTime; if (this.dns_resolve_type == "A" || this.dns_resolve_type == "AAAA" || this.dns_resolve_type == "TXT") { diff --git a/server/util-server.js b/server/util-server.js index 2264ebea..ad30f610 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -89,9 +89,17 @@ exports.pingAsync = function (hostname, ipv6 = false) { }); }; -exports.dnsResolve = function (hostname, resolver_server, rrtype) { +/** + * Resolves a given record using the specified DNS server + * @param {string} hostname The hostname of the record to lookup + * @param {string} resolver_server The DNS server to use + * @param {string} resolver_port The port the DNS server is listening on + * @param {string} rrtype The type of record to request + * @returns {Promise} Promise object represents DNS lookup result + */ +exports.dnsResolve = function (hostname, resolver_server, resolver_port, rrtype) { const resolver = new Resolver(); - resolver.setServers([resolver_server]); + resolver.setServers([`${resolver_server}:${resolver_port}`]); return new Promise((resolve, reject) => { if (rrtype == "PTR") { resolver.reverse(hostname, (err, records) => { diff --git a/src/languages/en.js b/src/languages/en.js index 47513466..3f7f7c7e 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -14,6 +14,7 @@ export default { 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.", + dnsPortDescription: "DNS server port. Defaults to 53. You can change the port at any time.", rrtypeDescription: "Select the RR type you want to monitor", pauseMonitorMsg: "Are you sure want to pause?", enableDefaultNotificationDescription: "This notification will be enabled by default for new monitors. You can still disable the notification separately for each monitor.", diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 4b6a920c..f52eac8f 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -91,6 +91,15 @@ + +
+ + +
+ {{ $t("dnsPortDescription") }} +
+
+
@@ -386,6 +395,15 @@ export default { this.monitor.pushToken = genSecret(10); } } + + // Set default port for DNS if not already defined + if (! this.monitor.port || this.monitor.port === "53") { + if (this.monitor.type === "dns") { + this.monitor.port = "53"; + } else { + this.monitor.port = ""; + } + } } }, From a680331dd77902a160e7876f650f5204e26d0499 Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Fri, 15 Apr 2022 19:59:32 +0100 Subject: [PATCH 3/3] Fixes issue with ::1 port 5300 requests Now the address is wrapped in `[]` in order to prevent ::1 port 5300 being interpreted as ::1:5300. Wrapping the IPv4 address in `[]` does seem to have any effect on correct domain name resolution. In order to prevent issues if a user inputs an address with brackets, they are removed from the string if present before being re-added when it is passed to `setServers`. I have also removed the JSDoc comment as this will be added in a seperate PR Signed-off-by: Matthew Nickson --- server/util-server.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index 367f4ffb..f7c0ce02 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -88,17 +88,12 @@ exports.pingAsync = function (hostname, ipv6 = false) { }); }; -/** - * Resolves a given record using the specified DNS server - * @param {string} hostname The hostname of the record to lookup - * @param {string} resolver_server The DNS server to use - * @param {string} resolver_port The port the DNS server is listening on - * @param {string} rrtype The type of record to request - * @returns {Promise} Promise object represents DNS lookup result - */ exports.dnsResolve = function (hostname, resolver_server, resolver_port, rrtype) { const resolver = new Resolver(); - resolver.setServers([`${resolver_server}:${resolver_port}`]); + // Remove brackets from IPv6 addresses so we can re-add them to + // prevent issues with ::1:5300 (::1 port 5300) + resolver_server = resolver_server.replace("[", "").replace("]", ""); + resolver.setServers([`[${resolver_server}]:${resolver_port}`]); return new Promise((resolve, reject) => { if (rrtype == "PTR") { resolver.reverse(hostname, (err, records) => {