From b7dc8e3ef84e5deabf165513c26da834a33d27d3 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 13 May 2022 07:22:52 -0500 Subject: [PATCH 2/7] started ui update --- src/pages/EditMonitor.vue | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 43f345273..b42c285cb 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -35,6 +35,9 @@ + @@ -148,6 +151,18 @@ + + +
@@ -336,8 +351,21 @@
- -

{{ $t("HTTP Basic Auth") }}

+ +

{{ $t("HTTP Authentication") }}

+ + +
+ + +
From 23ce7c6623b01fd239ea90337358b95dbff1b9e8 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 13 May 2022 09:06:41 -0500 Subject: [PATCH 3/7] started db update script --- db/patch-add-other-auth.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 db/patch-add-other-auth.sql diff --git a/db/patch-add-other-auth.sql b/db/patch-add-other-auth.sql new file mode 100644 index 000000000..93a1064c4 --- /dev/null +++ b/db/patch-add-other-auth.sql @@ -0,0 +1,15 @@ +BEGIN TRANSACTION; + + ALTER TABLE monitor + ADD auth_method VARCHAR(250); + + COMMIT + + +BEGIN TRANSACTION; + +UPDATE monitor + SET auth_method = 'basic' + WHERE basic_auth_user is not null + +COMMIT; From ef73af391f5b98744cbebe43434fc6684ca67bca Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 13 May 2022 12:58:23 -0500 Subject: [PATCH 4/7] added option for ntlm authorization --- db/patch-add-other-auth.sql | 17 ++++++++------ package-lock.json | 47 +++++++++++++++++++++++++++++++++++++ package.json | 1 + server/database.js | 1 + server/model/monitor.js | 25 ++++++++++++++++---- server/server.js | 6 +++++ server/util-server.js | 21 +++++++++++++++++ src/pages/EditMonitor.vue | 37 ++++++++++++++++++++--------- 8 files changed, 133 insertions(+), 22 deletions(-) diff --git a/db/patch-add-other-auth.sql b/db/patch-add-other-auth.sql index 93a1064c4..b83f1ee76 100644 --- a/db/patch-add-other-auth.sql +++ b/db/patch-add-other-auth.sql @@ -3,13 +3,16 @@ BEGIN TRANSACTION; ALTER TABLE monitor ADD auth_method VARCHAR(250); - COMMIT + ALTER TABLE monitor + ADD auth_domain TEXT; + ALTER TABLE monitor - -BEGIN TRANSACTION; - -UPDATE monitor - SET auth_method = 'basic' - WHERE basic_auth_user is not null + ADD auth_workstation TEXT; COMMIT; + +BEGIN TRANSACTION; + UPDATE monitor + SET auth_method = 'basic' + WHERE basic_auth_user is not null; +COMMIT; diff --git a/package-lock.json b/package-lock.json index 561bdf31c..d4635fd5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "@popperjs/core": "~2.10.2", "args-parser": "~1.3.0", "axios": "~0.26.1", + "axios-ntlm": "^1.3.0", "badge-maker": "^3.3.1", "bcryptjs": "~2.4.3", "bootstrap": "5.1.3", @@ -4129,6 +4130,23 @@ "follow-redirects": "^1.14.8" } }, + "node_modules/axios-ntlm": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/axios-ntlm/-/axios-ntlm-1.3.0.tgz", + "integrity": "sha512-NPNsIMO1SGX5scs3ZWJqsV7iRLvET+DlRl94aZ7Sx14zA8RTQh9EDxsJmxB9cKjardKfp2Vge444uYYLfvWC0Q==", + "dependencies": { + "axios": "^0.21.3", + "dev-null": "^0.1.1" + } + }, + "node_modules/axios-ntlm/node_modules/axios": { + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", + "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "dependencies": { + "follow-redirects": "^1.14.0" + } + }, "node_modules/babel-jest": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-27.5.1.tgz", @@ -5938,6 +5956,11 @@ "node": ">=8" } }, + "node_modules/dev-null": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/dev-null/-/dev-null-0.1.1.tgz", + "integrity": "sha1-WiBc48Ky73e2I41roXnrdMag6Bg=" + }, "node_modules/devtools-protocol": { "version": "0.0.948846", "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.948846.tgz", @@ -19978,6 +20001,25 @@ "follow-redirects": "^1.14.8" } }, + "axios-ntlm": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/axios-ntlm/-/axios-ntlm-1.3.0.tgz", + "integrity": "sha512-NPNsIMO1SGX5scs3ZWJqsV7iRLvET+DlRl94aZ7Sx14zA8RTQh9EDxsJmxB9cKjardKfp2Vge444uYYLfvWC0Q==", + "requires": { + "axios": "^0.21.3", + "dev-null": "^0.1.1" + }, + "dependencies": { + "axios": { + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", + "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "requires": { + "follow-redirects": "^1.14.0" + } + } + } + }, "babel-jest": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-27.5.1.tgz", @@ -21376,6 +21418,11 @@ "integrity": "sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==", "dev": true }, + "dev-null": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/dev-null/-/dev-null-0.1.1.tgz", + "integrity": "sha1-WiBc48Ky73e2I41roXnrdMag6Bg=" + }, "devtools-protocol": { "version": "0.0.948846", "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.948846.tgz", diff --git a/package.json b/package.json index e9b7003bd..2faf89133 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "@popperjs/core": "~2.10.2", "args-parser": "~1.3.0", "axios": "~0.26.1", + "axios-ntlm": "^1.3.0", "badge-maker": "^3.3.1", "bcryptjs": "~2.4.3", "bootstrap": "5.1.3", diff --git a/server/database.js b/server/database.js index b17e7f4ed..58e558263 100644 --- a/server/database.js +++ b/server/database.js @@ -58,6 +58,7 @@ class Database { "patch-monitor-expiry-notification.sql": true, "patch-status-page-footer-css.sql": true, "patch-added-mqtt-monitor.sql": true, + "patch-add-other-auth.sql": { parents: [ "patch-monitor-basic-auth.sql" ] }, }; /** diff --git a/server/model/monitor.js b/server/model/monitor.js index f2d16524b..5ef55c289 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 { log, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util"); -const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mqttAsync } = require("../util-server"); +const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mqttAsync, httpNtlm } = require("../util-server"); const { R } = require("redbean-node"); const { BeanModel } = require("redbean-node/dist/bean-model"); const { Notification } = require("../notification"); @@ -87,7 +87,10 @@ class Monitor extends BeanModel { mqttUsername: this.mqttUsername, mqttPassword: this.mqttPassword, mqttTopic: this.mqttTopic, - mqttSuccessMessage: this.mqttSuccessMessage + mqttSuccessMessage: this.mqttSuccessMessage, + authMethod: this.authMethod, + authWorkstation: this.authWorkstation, + authDomain: this.authDomain, }; if (includeSensitiveData) { @@ -213,7 +216,7 @@ class Monitor extends BeanModel { // HTTP basic auth let basicAuthHeader = {}; - if (this.basic_auth_user) { + if (this.auth_method === "basic") { basicAuthHeader = { "Authorization": "Basic " + this.encodeBase64(this.basic_auth_user, this.basic_auth_pass), }; @@ -264,7 +267,21 @@ class Monitor extends BeanModel { log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`); log.debug("monitor", `[${this.name}] Axios Request`); - let res = await axios.request(options); + let res; + if (this.auth_method === "ntlm") { + options.httpsAgent.keepAlive = true; + + res = await httpNtlm(options, { + username: this.basic_auth_user, + password: this.basic_auth_pass, + domain: this.authDomain, + workstation: this.authWorkstation, + }); + + } else { + res = await axios.request(options); + } + bean.msg = `${res.status} - ${res.statusText}`; bean.ping = dayjs().valueOf() - startTime; diff --git a/server/server.js b/server/server.js index 79cb21026..9f3dea242 100644 --- a/server/server.js +++ b/server/server.js @@ -674,6 +674,9 @@ try { bean.mqttPassword = monitor.mqttPassword; bean.mqttTopic = monitor.mqttTopic; bean.mqttSuccessMessage = monitor.mqttSuccessMessage; + bean.authMethod = monitor.authMethod; + bean.authWorkstation = monitor.authWorkstation; + bean.authDomain = monitor.authDomain; await R.store(bean); @@ -1247,8 +1250,11 @@ try { method: monitorListData[i].method || "GET", body: monitorListData[i].body, headers: monitorListData[i].headers, + authMethod: monitorListData[i].authMethod, basic_auth_user: monitorListData[i].basic_auth_user, basic_auth_pass: monitorListData[i].basic_auth_pass, + authWorkstation: monitorListData[i].authWorkstation, + authDomain: monitorListData[i].authDomain, interval: monitorListData[i].interval, retryInterval: retryInterval, hostname: monitorListData[i].hostname, diff --git a/server/util-server.js b/server/util-server.js index 54974e148..e782cdf03 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -10,6 +10,7 @@ const chardet = require("chardet"); const mqtt = require("mqtt"); const chroma = require("chroma-js"); const { badgeConstants } = require("./config"); +const { NtlmClient } = require("axios-ntlm"); // From ping-lite exports.WIN = /^win/.test(process.platform); @@ -172,6 +173,26 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) { }); }; +/** + * Use NTLM Auth for a http request. + * @param {Object} options The http request options + * @param {Object} ntlmOptions The auth options + * @returns {Promise<(string[]|Object[]|Object)>} + */ +exports.httpNtlm = function (options, ntlmOptions) { + return new Promise((resolve, reject) => { + let client = NtlmClient(ntlmOptions); + + client(options) + .then((resp) => { + resolve(resp); + }) + .catch((err) => { + reject(err); + }); + }); +}; + /** * Resolves a given record using the specified DNS server * @param {string} hostname The hostname of the record to lookup diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index b42c285cb..ab018d776 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -358,24 +358,39 @@
+
From 817f6db4fd851ebcb474d86846f6f6cf88666bd9 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 14 Jun 2022 10:32:38 +0800 Subject: [PATCH 5/7] Remove SQL Server code (which in another pr already) --- src/pages/EditMonitor.vue | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index ab018d776..6d66383fd 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -35,9 +35,6 @@ - @@ -151,18 +148,6 @@ - - -
From f25ca963088694a1cac7295a73df3141089d3250 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 14 Jun 2022 10:37:15 +0800 Subject: [PATCH 6/7] Update package-lock.json --- package-lock.json | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/package-lock.json b/package-lock.json index 481636db3..24f4cca4f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "args-parser": "~1.3.0", "axios": "~0.26.1", "axios-cached-dns-resolve": "^3.0.6", + "axios-ntlm": "^1.3.0", "badge-maker": "^3.3.1", "bcryptjs": "~2.4.3", "bootstrap": "5.1.3", @@ -4647,6 +4648,23 @@ "node": ">=14.0.0" } }, + "node_modules/axios-ntlm": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/axios-ntlm/-/axios-ntlm-1.3.0.tgz", + "integrity": "sha512-NPNsIMO1SGX5scs3ZWJqsV7iRLvET+DlRl94aZ7Sx14zA8RTQh9EDxsJmxB9cKjardKfp2Vge444uYYLfvWC0Q==", + "dependencies": { + "axios": "^0.21.3", + "dev-null": "^0.1.1" + } + }, + "node_modules/axios-ntlm/node_modules/axios": { + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", + "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "dependencies": { + "follow-redirects": "^1.14.0" + } + }, "node_modules/babel-jest": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-27.5.1.tgz", @@ -6635,6 +6653,11 @@ "node": ">=8" } }, + "node_modules/dev-null": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/dev-null/-/dev-null-0.1.1.tgz", + "integrity": "sha512-nMNZG0zfMgmdv8S5O0TM5cpwNbGKRGPCxVsr0SmA3NZZy9CYBbuNLL0PD3Acx9e5LIUgwONXtM9kM6RlawPxEQ==" + }, "node_modules/devtools-protocol": { "version": "0.0.948846", "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.948846.tgz", @@ -22317,6 +22340,25 @@ "pino-pretty": "^7.6.1" } }, + "axios-ntlm": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/axios-ntlm/-/axios-ntlm-1.3.0.tgz", + "integrity": "sha512-NPNsIMO1SGX5scs3ZWJqsV7iRLvET+DlRl94aZ7Sx14zA8RTQh9EDxsJmxB9cKjardKfp2Vge444uYYLfvWC0Q==", + "requires": { + "axios": "^0.21.3", + "dev-null": "^0.1.1" + }, + "dependencies": { + "axios": { + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", + "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "requires": { + "follow-redirects": "^1.14.0" + } + } + } + }, "babel-jest": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-27.5.1.tgz", @@ -23843,6 +23885,11 @@ "integrity": "sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==", "dev": true }, + "dev-null": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/dev-null/-/dev-null-0.1.1.tgz", + "integrity": "sha512-nMNZG0zfMgmdv8S5O0TM5cpwNbGKRGPCxVsr0SmA3NZZy9CYBbuNLL0PD3Acx9e5LIUgwONXtM9kM6RlawPxEQ==" + }, "devtools-protocol": { "version": "0.0.948846", "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.948846.tgz", From d16be6fb7ddeedd2d47e7480ffda103d76e5abea Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 14 Jun 2022 10:49:30 +0800 Subject: [PATCH 7/7] Fix and use null as authMethod None instead of empty string --- src/pages/EditMonitor.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 4c11a9e55..bf0b5655c 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -375,7 +375,7 @@
-