From 3a188017228b2437820133827c36b03a7b9597f7 Mon Sep 17 00:00:00 2001 From: Justin Tisdale Date: Wed, 10 Aug 2022 21:46:43 -0400 Subject: [PATCH 01/17] Add Body Encoding field --- src/languages/en.js | 1 + src/pages/EditMonitor.vue | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/languages/en.js b/src/languages/en.js index b9951612..4433e2a5 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -553,4 +553,5 @@ export default { disableCloudflaredNoAuthMsg: "You are in No Auth mode, password is not require.", trustProxyDescription: "Trust 'X-Forwarded-*' headers. If you want to get the correct client IP and your Uptime Kuma is behind such as Nginx or Apache, you should enable this.", wayToGetLineNotifyToken: "You can get an access token from {0}", + "Body Encoding": "Body Encoding" }; diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index ac6a3e2e..7dcc7d64 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -396,6 +396,22 @@ + +
+ + +
+
@@ -644,6 +660,7 @@ export default { mqttTopic: "", mqttSuccessMessage: "", authMethod: null, + bodyEncoding: null }; if (this.$root.proxyList && !this.monitor.proxyId) { From 2b9bf095a609bbf2f2c517209b13cb57dbd1e1b1 Mon Sep 17 00:00:00 2001 From: Justin Tisdale Date: Thu, 11 Aug 2022 20:57:03 -0400 Subject: [PATCH 02/17] Add non-json support for http body --- db/patch-http-body-encoding.sql | 6 ++++++ server/database.js | 1 + server/model/monitor.js | 20 +++++++++++++++++++- server/server.js | 1 + src/pages/EditMonitor.vue | 13 +++++++------ 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 db/patch-http-body-encoding.sql diff --git a/db/patch-http-body-encoding.sql b/db/patch-http-body-encoding.sql new file mode 100644 index 00000000..de02bede --- /dev/null +++ b/db/patch-http-body-encoding.sql @@ -0,0 +1,6 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +ALTER TABLE [monitor] ADD http_body_encoding TEXT; + +COMMIT; diff --git a/server/database.js b/server/database.js index b234d67d..ecf6af72 100644 --- a/server/database.js +++ b/server/database.js @@ -62,6 +62,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-http-body-encoding.sql": true }; /** diff --git a/server/model/monitor.js b/server/model/monitor.js index 2feef135..af3d162a 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -103,6 +103,7 @@ class Monitor extends BeanModel { authMethod: this.authMethod, authWorkstation: this.authWorkstation, authDomain: this.authDomain, + httpBodyEncoding: this.httpBodyEncoding }; if (includeSensitiveData) { @@ -241,16 +242,33 @@ class Monitor extends BeanModel { log.debug("monitor", `[${this.name}] Prepare Options for axios`); + // Set content-type header and body values based on the httpBodyEncoding type selected + // TODO: Check if this.headers already contains a content-type header set by the user; if so, don't inject one + let bodyValue = null; + let contentType = null; + + if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json"){ + bodyValue = JSON.parse(this.body); + contentType = "application/json"; + } else if (this.body && (this.httpBodyEncoding === "xml")) { + bodyValue = this.body; + contentType = "text/xml"; + } else if (this.body && (this.httpBodyEncoding === "form")) { + bodyValue = this.body; + contentType = "application/x-www-form-urlencoded"; + } + const options = { url: this.url, method: (this.method || "get").toLowerCase(), - ...(this.body ? { data: JSON.parse(this.body) } : {}), + ...(bodyValue ? { data: bodyValue } : {}), timeout: this.interval * 1000 * 0.8, headers: { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "User-Agent": "Uptime-Kuma/" + version, ...(this.headers ? JSON.parse(this.headers) : {}), ...(basicAuthHeader), + ...(contentType ? { "Content-Type": contentType } : {}) }, maxRedirects: this.maxredirects, validateStatus: (status) => { diff --git a/server/server.js b/server/server.js index 2a2c4bf6..616a10cd 100644 --- a/server/server.js +++ b/server/server.js @@ -693,6 +693,7 @@ let needSetup = false; bean.authMethod = monitor.authMethod; bean.authWorkstation = monitor.authWorkstation; bean.authDomain = monitor.authDomain; + bean.httpBodyEncoding = monitor.httpBodyEncoding; await R.store(bean); diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 7dcc7d64..b4aceba7 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -398,8 +398,8 @@
- - @@ -660,7 +660,7 @@ export default { mqttTopic: "", mqttSuccessMessage: "", authMethod: null, - bodyEncoding: null + httpBodyEncoding: "json" }; if (this.$root.proxyList && !this.monitor.proxyId) { @@ -698,7 +698,8 @@ export default { * @returns {boolean} Is the form input valid? */ isInputValid() { - if (this.monitor.body) { + //TODO: Handle validation for all 3 possible options + null value + if (this.monitor.body && (!this.monitor.httpBodyEncoding || this.monitor.httpBodyEncoding === "json")) { try { JSON.parse(this.monitor.body); } catch (err) { @@ -729,8 +730,8 @@ export default { return; } - // Beautify the JSON format - if (this.monitor.body) { + // Beautify the JSON format (only if httpBodyEncoding is not set or === json) + if (this.monitor.body && (!this.monitor.httpBodyEncoding || this.monitor.httpBodyEncoding === "json")) { this.monitor.body = JSON.stringify(JSON.parse(this.monitor.body), null, 4); } From 31cc328839c9462169070b4b67ba4044fb6716d8 Mon Sep 17 00:00:00 2001 From: Justin Tisdale Date: Thu, 11 Aug 2022 21:08:13 -0400 Subject: [PATCH 03/17] fix lint --- server/model/monitor.js | 2 +- src/languages/en.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 5d9c4cd4..8f30a0c1 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -252,7 +252,7 @@ class Monitor extends BeanModel { let bodyValue = null; let contentType = null; - if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json"){ + if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json") { bodyValue = JSON.parse(this.body); contentType = "application/json"; } else if (this.body && (this.httpBodyEncoding === "xml")) { diff --git a/src/languages/en.js b/src/languages/en.js index e338d778..31d92628 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -559,5 +559,5 @@ export default { disableCloudflaredNoAuthMsg: "You are in No Auth mode, password is not require.", trustProxyDescription: "Trust 'X-Forwarded-*' headers. If you want to get the correct client IP and your Uptime Kuma is behind such as Nginx or Apache, you should enable this.", wayToGetLineNotifyToken: "You can get an access token from {0}", - "Body Encoding": "Body Encoding" + "Body Encoding": "Body Encoding", }; From 5809088f27eb9604b043b782ac375f1feecc2e5a Mon Sep 17 00:00:00 2001 From: Justin Tisdale Date: Mon, 26 Sep 2022 15:52:43 -0400 Subject: [PATCH 04/17] Don't override a user-defined content-type header --- server/model/monitor.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 509b841c..c541ecf3 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -249,20 +249,28 @@ class Monitor extends BeanModel { log.debug("monitor", `[${this.name}] Prepare Options for axios`); - // Set content-type header and body values based on the httpBodyEncoding type selected - // TODO: Check if this.headers already contains a content-type header set by the user; if so, don't inject one - let bodyValue = null; - let contentType = null; + + // Check if this.headers already contains a content-type header set by the user; if so, don't inject one + let contentTypeUserDefinedHeader = this.headers.find(function(header) { + return header[0].toLowerCase() == "content-type"; + }); + + let contentType = contentTypeUserDefinedHeader ? + contentTypeUserDefinedHeader[1] : + null; + + let bodyValue = null; + if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json") { bodyValue = JSON.parse(this.body); - contentType = "application/json"; + contentType = contentType ? contentType : "application/json"; } else if (this.body && (this.httpBodyEncoding === "xml")) { bodyValue = this.body; - contentType = "text/xml"; + contentType = contentType ? contentType : "text/xml"; } else if (this.body && (this.httpBodyEncoding === "form")) { bodyValue = this.body; - contentType = "application/x-www-form-urlencoded"; + contentType = contentType ? contentType : "application/x-www-form-urlencoded"; } const options = { From 6537f4fe746c157c8a87ff25bbcefeb7a62522f3 Mon Sep 17 00:00:00 2001 From: Justin Tisdale Date: Mon, 26 Sep 2022 17:09:10 -0400 Subject: [PATCH 05/17] content-type change --- server/model/monitor.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index c541ecf3..48b0b1d3 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -249,28 +249,18 @@ class Monitor extends BeanModel { log.debug("monitor", `[${this.name}] Prepare Options for axios`); - - - // Check if this.headers already contains a content-type header set by the user; if so, don't inject one - let contentTypeUserDefinedHeader = this.headers.find(function(header) { - return header[0].toLowerCase() == "content-type"; - }); - - let contentType = contentTypeUserDefinedHeader ? - contentTypeUserDefinedHeader[1] : - null; - + let contentType = null; let bodyValue = null; if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json") { bodyValue = JSON.parse(this.body); - contentType = contentType ? contentType : "application/json"; + contentType = "application/json"; } else if (this.body && (this.httpBodyEncoding === "xml")) { bodyValue = this.body; - contentType = contentType ? contentType : "text/xml"; + contentType = "text/xml"; } else if (this.body && (this.httpBodyEncoding === "form")) { bodyValue = this.body; - contentType = contentType ? contentType : "application/x-www-form-urlencoded"; + contentType = "application/x-www-form-urlencoded"; } const options = { From f6919aef1d3b59dd23229feef6f2815004f34a80 Mon Sep 17 00:00:00 2001 From: Justin Tisdale Date: Mon, 26 Sep 2022 17:10:56 -0400 Subject: [PATCH 06/17] remove TODO --- src/pages/EditMonitor.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index ba667670..ea246c60 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -741,7 +741,6 @@ export default { * @returns {boolean} Is the form input valid? */ isInputValid() { - //TODO: Handle validation for all 3 possible options + null value if (this.monitor.body && (!this.monitor.httpBodyEncoding || this.monitor.httpBodyEncoding === "json")) { try { JSON.parse(this.monitor.body); From 3adc9e65d6d5cd461abc461929f29513bc41e21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Sat, 14 Jan 2023 16:33:21 +0300 Subject: [PATCH 07/17] Add only xml support to http monitors --- server/model/monitor.js | 7 ++----- src/pages/EditMonitor.vue | 23 ++++++++--------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 48b0b1d3..d93fd6dd 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -251,16 +251,13 @@ class Monitor extends BeanModel { let contentType = null; let bodyValue = null; - + if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json") { bodyValue = JSON.parse(this.body); contentType = "application/json"; } else if (this.body && (this.httpBodyEncoding === "xml")) { bodyValue = this.body; - contentType = "text/xml"; - } else if (this.body && (this.httpBodyEncoding === "form")) { - bodyValue = this.body; - contentType = "application/x-www-form-urlencoded"; + contentType = "text/xml; charset=utf-8"; } const options = { diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index ea246c60..05b89ab0 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -438,21 +438,14 @@
- -
- - -
+ +
+ + +
From 15c64d458b69489b455ee90b13dd610446a091ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Sat, 14 Jan 2023 16:48:12 +0300 Subject: [PATCH 08/17] Fix lint --- src/pages/EditMonitor.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index a68a1206..65680109 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -463,13 +463,13 @@
-
- - -
+
+ + +
From 9890a0754b409d458d7563c0d9a31dcbb20d76b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Sat, 14 Jan 2023 16:48:26 +0300 Subject: [PATCH 09/17] Fix lint --- src/pages/EditMonitor.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 65680109..8d5e3e9d 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -462,7 +462,7 @@
- +
- - + +
From aef85078eb5fbb0e48db31cd40f5d7eaf6c06792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Fri, 20 Jan 2023 12:29:56 +0300 Subject: [PATCH 11/17] reorder fix --- server/model/monitor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index c0721c48..ec56ba45 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -290,9 +290,9 @@ class Monitor extends BeanModel { headers: { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "User-Agent": "Uptime-Kuma/" + version, - ...(this.headers ? JSON.parse(this.headers) : {}), + ...(contentType ? { "Content-Type": contentType } : {}), ...(basicAuthHeader), - ...(contentType ? { "Content-Type": contentType } : {}) + ...(this.headers ? JSON.parse(this.headers) : {}) }, maxRedirects: this.maxredirects, validateStatus: (status) => { From 2673b509a598c9dc311b00cf9205a0353c9b5609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Wed, 25 Jan 2023 20:22:50 +0300 Subject: [PATCH 12/17] Add "Body Encoding" to en.json --- src/lang/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lang/en.json b/src/lang/en.json index f2f16693..d01ccd20 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -682,5 +682,6 @@ "onebotUserOrGroupId": "Group/User ID", "onebotSafetyTips": "For safety, must set access token", "PushDeer Key": "PushDeer Key", - "wayToGetClickSendSMSToken": "You can get API Username and API Key from {0} ." + "wayToGetClickSendSMSToken": "You can get API Username and API Key from {0} .", + "Body Encoding": "Body Encoding" } From b2ddb5c9eb47105d9855106960e44295e04e427c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Thu, 2 Feb 2023 19:50:14 +0300 Subject: [PATCH 13/17] Dummy commit for build --- src/lang/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang/en.json b/src/lang/en.json index dc5663f1..e1d7abec 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -691,5 +691,5 @@ "PushDeer Key": "PushDeer Key", "wayToGetClickSendSMSToken": "You can get API Username and API Key from {0} .", "Custom Monitor Type": "Custom Monitor Type", - "Body Encoding": "Body Encoding" + "Body Encoding": "Body Encoding", } From 603b3a7fb6145c196114f9786637430e65e6b561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Thu, 2 Feb 2023 19:50:29 +0300 Subject: [PATCH 14/17] Dummy commit for build --- src/lang/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang/en.json b/src/lang/en.json index e1d7abec..dc5663f1 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -691,5 +691,5 @@ "PushDeer Key": "PushDeer Key", "wayToGetClickSendSMSToken": "You can get API Username and API Key from {0} .", "Custom Monitor Type": "Custom Monitor Type", - "Body Encoding": "Body Encoding", + "Body Encoding": "Body Encoding" } From c9b4a7f53ef502a5ea58faf970102b6098d0b479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Fri, 17 Feb 2023 17:59:43 +0300 Subject: [PATCH 15/17] Change column type --- db/patch-http-body-encoding.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/patch-http-body-encoding.sql b/db/patch-http-body-encoding.sql index de02bede..fa75ae90 100644 --- a/db/patch-http-body-encoding.sql +++ b/db/patch-http-body-encoding.sql @@ -1,6 +1,6 @@ -- You should not modify if this have pushed to Github, unless it does serious wrong with the db. BEGIN TRANSACTION; -ALTER TABLE [monitor] ADD http_body_encoding TEXT; +ALTER TABLE [monitor] ADD http_body_encoding VARCHAR(25); COMMIT; From 9e3a77f4194b43bc617fb22756521f99b05e1aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Sat, 18 Feb 2023 17:02:56 +0300 Subject: [PATCH 16/17] Customize body placeholder for body encoding --- src/pages/EditMonitor.vue | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index d36693bb..2d28195e 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -732,6 +732,15 @@ message HealthCheckResponse { ` ]); }, bodyPlaceholder() { + if (this.monitor && this.monitor.httpBodyEncoding && this.monitor.httpBodyEncoding === "xml") { + return this.$t("Example:", [ ` + + + + Kuma + +` ]); + } return this.$t("Example:", [ ` { "key": "value" From 3ab0faee91d5aae3b0d0dc6a54b8ceeafa64e337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Faruk=20Gen=C3=A7?= Date: Sat, 18 Feb 2023 22:18:48 +0300 Subject: [PATCH 17/17] Add update query for old monitors and save new data correctly --- db/patch-http-body-encoding.sql | 8 +++++++- src/pages/EditMonitor.vue | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/db/patch-http-body-encoding.sql b/db/patch-http-body-encoding.sql index fa75ae90..322c8b89 100644 --- a/db/patch-http-body-encoding.sql +++ b/db/patch-http-body-encoding.sql @@ -1,6 +1,12 @@ -- You should not modify if this have pushed to Github, unless it does serious wrong with the db. BEGIN TRANSACTION; -ALTER TABLE [monitor] ADD http_body_encoding VARCHAR(25); +ALTER TABLE monitor ADD http_body_encoding VARCHAR(25); + +COMMIT; + +BEGIN TRANSACTION; + +UPDATE monitor SET http_body_encoding = 'json' WHERE (type = 'http' or type = 'keyword') AND http_body_encoding IS NULL; COMMIT; diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 2d28195e..dbf44d73 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -952,6 +952,7 @@ message HealthCheckResponse { * @returns {void} */ async submit() { + this.processing = true; if (!this.isInputValid()) { @@ -964,6 +965,10 @@ message HealthCheckResponse { this.monitor.body = JSON.stringify(JSON.parse(this.monitor.body), null, 4); } + if (this.monitor.type && this.monitor.type !== "http" && this.monitor.type !== "keyword") { + this.monitor.httpBodyEncoding = null; + } + if (this.monitor.headers) { this.monitor.headers = JSON.stringify(JSON.parse(this.monitor.headers), null, 4); }