From faa78443d6d41659029ce8d3b1c988637c97021d Mon Sep 17 00:00:00 2001 From: Suriya Soutmun Date: Wed, 4 Jan 2023 14:37:03 +0700 Subject: [PATCH 2/6] chore: alter table monitor add column tls_ca, tls_cert, tls_key for certificate data --- db/patch-monitor-tls.sql | 13 +++++++++++++ server/database.js | 1 + 2 files changed, 14 insertions(+) create mode 100644 db/patch-monitor-tls.sql diff --git a/db/patch-monitor-tls.sql b/db/patch-monitor-tls.sql new file mode 100644 index 00000000..ac4edb79 --- /dev/null +++ b/db/patch-monitor-tls.sql @@ -0,0 +1,13 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +ALTER TABLE monitor + ADD tls_ca TEXT default null; + +ALTER TABLE monitor + ADD tls_cert TEXT default null; + +ALTER TABLE monitor + ADD tls_key TEXT default null; + +COMMIT; diff --git a/server/database.js b/server/database.js index 19c09a00..859f12ff 100644 --- a/server/database.js +++ b/server/database.js @@ -70,6 +70,7 @@ class Database { "patch-maintenance-table2.sql": true, "patch-add-gamedig-monitor.sql": true, "patch-add-google-analytics-status-page-tag.sql": true, + "patch-monitor-tls.sql": true, }; /** From 43941fa2c60fbd9370699ff4e304188e176a067d Mon Sep 17 00:00:00 2001 From: Suriya Soutmun Date: Wed, 4 Jan 2023 14:37:30 +0700 Subject: [PATCH 3/6] feat: add mtls authen method in http/http keyword --- server/model/monitor.js | 16 ++++++++++++- server/server.js | 3 +++ src/pages/EditMonitor.vue | 47 +++++++++++++++++++++++++++------------ 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 4cbb56e1..2cb309e0 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -131,6 +131,9 @@ class Monitor extends BeanModel { mqttPassword: this.mqttPassword, authWorkstation: this.authWorkstation, authDomain: this.authDomain, + tlsCa: this.tlsCa, + tlsCert: this.tlsCert, + tlsKey: this.tlsKey, }; } @@ -308,6 +311,18 @@ class Monitor extends BeanModel { options.httpsAgent = new https.Agent(httpsAgentOptions); } + if (this.auth_method === "mtls") { + if (this.tlsCert !== null && this.tlsCert !== "") { + options.httpsAgent.options.cert = Buffer.from(this.tlsCert); + } + if (this.tlsCa !== null && this.tlsCa !== "") { + options.httpsAgent.options.ca = Buffer.from(this.tlsCa); + } + if (this.tlsKey !== null && this.tlsKey !== "") { + options.httpsAgent.options.key = Buffer.from(this.tlsKey); + } + } + log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`); log.debug("monitor", `[${this.name}] Axios Request`); @@ -813,7 +828,6 @@ class Monitor extends BeanModel { domain: this.authDomain, workstation: this.authWorkstation ? this.authWorkstation : undefined }); - } else { res = await axios.request(options); } diff --git a/server/server.js b/server/server.js index 1073f3be..91b0a944 100644 --- a/server/server.js +++ b/server/server.js @@ -688,6 +688,9 @@ let needSetup = false; bean.headers = monitor.headers; bean.basic_auth_user = monitor.basic_auth_user; bean.basic_auth_pass = monitor.basic_auth_pass; + bean.tlsCa = monitor.tlsCa; + bean.tlsCert = monitor.tlsCert; + bean.tlsKey = monitor.tlsKey; bean.interval = monitor.interval; bean.retryInterval = monitor.retryInterval; bean.resendInterval = monitor.resendInterval; diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index e9cbd824..6d7353fe 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -531,28 +531,47 @@ + From 8a115670cd78845693214f5800d44b67fddaf82e Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 25 Feb 2023 17:55:40 +0800 Subject: [PATCH 4/6] Fix label and id Co-authored-by: AlexKraus --- src/pages/EditMonitor.vue | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 6d7353fe..085a60db 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -539,37 +539,37 @@