From 219b00f660790f04285224a33fc36d70b38ad620 Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Wed, 13 Jul 2022 23:08:35 +0100 Subject: [PATCH 01/22] [empty commit] pull request for #1891 set ping size From a54e58b4d6bc5f6eabe161fbdc0709dfadd69189 Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Thu, 14 Jul 2022 08:32:51 +0100 Subject: [PATCH 02/22] Added Ping packet size #1891 This should fully implement #1891 by adding an extra field to the edit monitor page and an extra column to the database. The user can now set the size of the packet to send, it defaults to 56. A maximum limit of 65500 was chosen to ensure that the total size of the packet does not exceed the IPv4 maximum packet size and to comply with the limit imposed by Windows. Signed-off-by: Matthew Nickson --- db/patch-ping-packet-size.sql | 5 +++++ server/database.js | 1 + server/model/monitor.js | 5 +++-- server/ping-lite.js | 8 ++++---- server/server.js | 1 + server/util-server.js | 13 ++++++++----- src/languages/en.js | 1 + src/pages/EditMonitor.vue | 7 +++++++ 8 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 db/patch-ping-packet-size.sql diff --git a/db/patch-ping-packet-size.sql b/db/patch-ping-packet-size.sql new file mode 100644 index 000000000..d65ec8ed8 --- /dev/null +++ b/db/patch-ping-packet-size.sql @@ -0,0 +1,5 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; +ALTER TABLE monitor + ADD packet_size INTEGER DEFAULT 56 NOT NULL; +COMMIT; diff --git a/server/database.js b/server/database.js index 00fd48d9f..3d5508f7e 100644 --- a/server/database.js +++ b/server/database.js @@ -61,6 +61,7 @@ class Database { "patch-add-clickable-status-page-link.sql": true, "patch-add-sqlserver-monitor.sql": true, "patch-add-other-auth.sql": { parents: [ "patch-monitor-basic-auth.sql" ] }, + "patch-ping-packet-size.sql": true, }; /** diff --git a/server/model/monitor.js b/server/model/monitor.js index b8733a0b1..6ce7322b1 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -82,6 +82,7 @@ class Monitor extends BeanModel { expiryNotification: this.isEnabledExpiryNotification(), ignoreTls: this.getIgnoreTls(), upsideDown: this.isUpsideDown(), + packetSize: this.packetSize, maxredirects: this.maxredirects, accepted_statuscodes: this.getAcceptedStatuscodes(), dns_resolve_type: this.dns_resolve_type, @@ -352,7 +353,7 @@ class Monitor extends BeanModel { bean.status = UP; } else if (this.type === "ping") { - bean.ping = await ping(this.hostname); + bean.ping = await ping(this.hostname, this.packetSize); bean.msg = ""; bean.status = UP; } else if (this.type === "dns") { @@ -459,7 +460,7 @@ class Monitor extends BeanModel { bean.msg = res.data.response.servers[0].name; try { - bean.ping = await ping(this.hostname); + bean.ping = await ping(this.hostname, this.packetSize); } catch (_) { } } else { throw new Error("Server not found on Steam"); diff --git a/server/ping-lite.js b/server/ping-lite.js index b7d003b81..c1686dd91 100644 --- a/server/ping-lite.js +++ b/server/ping-lite.js @@ -28,13 +28,13 @@ function Ping(host, options) { if (util.WIN) { this._bin = "c:/windows/system32/ping.exe"; - this._args = (options.args) ? options.args : [ "-n", "1", "-w", timeout * 1000, host ]; + this._args = (options.args) ? options.args : [ "-n", "1", "-w", timeout * 1000, "-l", this._options.size, host ]; this._regmatch = /[><=]([0-9.]+?)ms/; } else if (util.LIN) { this._bin = "/bin/ping"; - const defaultArgs = [ "-n", "-w", timeout, "-c", "1", host ]; + const defaultArgs = [ "-n", "-w", timeout, "-c", "1", "-s", this._options.size, host ]; if (net.isIPv6(host) || options.ipv6) { defaultArgs.unshift("-6"); @@ -51,13 +51,13 @@ function Ping(host, options) { this._bin = "/sbin/ping"; } - this._args = (options.args) ? options.args : [ "-n", "-t", timeout, "-c", "1", host ]; + this._args = (options.args) ? options.args : [ "-n", "-t", timeout, "-c", "1", "-s", this._options.size, host ]; this._regmatch = /=([0-9.]+?) ms/; } else if (util.BSD) { this._bin = "/sbin/ping"; - const defaultArgs = [ "-n", "-t", timeout, "-c", "1", host ]; + const defaultArgs = [ "-n", "-t", timeout, "-c", "1", "-s", this._options.size, host ]; if (net.isIPv6(host) || options.ipv6) { defaultArgs.unshift("-6"); diff --git a/server/server.js b/server/server.js index 2d3f37eeb..72adbb2ac 100644 --- a/server/server.js +++ b/server/server.js @@ -659,6 +659,7 @@ let needSetup = false; bean.ignoreTls = monitor.ignoreTls; bean.expiryNotification = monitor.expiryNotification; bean.upsideDown = monitor.upsideDown; + bean.packetSize = monitor.packetSize; bean.maxredirects = monitor.maxredirects; bean.accepted_statuscodes_json = JSON.stringify(monitor.accepted_statuscodes); bean.dns_resolve_type = monitor.dns_resolve_type; diff --git a/server/util-server.js b/server/util-server.js index f6a0e396c..bc49a6c7c 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -70,15 +70,16 @@ exports.tcping = function (hostname, port) { /** * Ping the specified machine * @param {string} hostname Hostname / address of machine + * @param {number} [size=56] Size of packet to send * @returns {Promise} Time for ping in ms rounded to nearest integer */ -exports.ping = async (hostname) => { +exports.ping = async (hostname, size = 56) => { try { - return await exports.pingAsync(hostname); + return await exports.pingAsync(hostname, false, size ); } catch (e) { // If the host cannot be resolved, try again with ipv6 if (e.message.includes("service not known")) { - return await exports.pingAsync(hostname, true); + return await exports.pingAsync(hostname, true, size); } else { throw e; } @@ -89,12 +90,14 @@ exports.ping = async (hostname) => { * Ping the specified machine * @param {string} hostname Hostname / address of machine to ping * @param {boolean} ipv6 Should IPv6 be used? + * @param {number} [size=56] Size of ping packet to send * @returns {Promise} Time for ping in ms rounded to nearest integer */ -exports.pingAsync = function (hostname, ipv6 = false) { +exports.pingAsync = function (hostname, ipv6 = false, size = 56) { return new Promise((resolve, reject) => { const ping = new Ping(hostname, { - ipv6 + ipv6, + size }); ping.send(function (err, ms, stdout) { diff --git a/src/languages/en.js b/src/languages/en.js index 9aeedd9de..4f3b2abb5 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -536,4 +536,5 @@ export default { "Domain": "Domain", "Workstation": "Workstation", disableCloudflaredNoAuthMsg: "You are in No Auth mode, password is not require.", + "Packet Size": "Packet Size", }; diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index f8791d3f9..737afa70b 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -230,6 +230,12 @@ + +
+ + +
+