From 665c263c03936c063a3528047aa33001ce42801e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Bratovi=C4=87?= Date: Tue, 2 Nov 2021 11:51:45 +0100 Subject: [PATCH 01/17] Add db migrations for new basic auth fields --- db/patch-monitor-basicauth.sql | 10 ++++++++++ server/database.js | 1 + 2 files changed, 11 insertions(+) create mode 100644 db/patch-monitor-basicauth.sql diff --git a/db/patch-monitor-basicauth.sql b/db/patch-monitor-basicauth.sql new file mode 100644 index 000000000..3a33350d7 --- /dev/null +++ b/db/patch-monitor-basicauth.sql @@ -0,0 +1,10 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +ALTER TABLE monitor + ADD basicauth_user TEXT default null; + +ALTER TABLE monitor + ADD basicauth_pass TEXT default null; + +COMMIT; diff --git a/server/database.js b/server/database.js index 41d91e858..cc7247f1c 100644 --- a/server/database.js +++ b/server/database.js @@ -52,6 +52,7 @@ class Database { "patch-http-monitor-method-body-and-headers.sql": true, "patch-2fa-invalidate-used-token.sql": true, "patch-notification_sent_history.sql": true, + "patch-monitor-basicauth.sql": true, } /** From 23736549f90eb86afcca919e99e06abfe66c3105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Bratovi=C4=87?= Date: Tue, 2 Nov 2021 12:30:44 +0100 Subject: [PATCH 02/17] Implement HTTP basic auth feature --- server/model/monitor.js | 20 ++++++++++++++++++++ server/server.js | 4 ++++ src/pages/EditMonitor.vue | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/server/model/monitor.js b/server/model/monitor.js index fc3292317..c80e941e9 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -58,6 +58,8 @@ class Monitor extends BeanModel { method: this.method, body: this.body, headers: this.headers, + basicauth_user: this.basicauth_user, + basicauth_pass: this.basicauth_pass, hostname: this.hostname, port: this.port, maxretries: this.maxretries, @@ -80,6 +82,15 @@ class Monitor extends BeanModel { }; } + /** + * Encode user and password to Base64 encoding + * for HTTP "basic" auth, as per RFC-7617 + * @returns {string} + */ + encodeB64(user, pass) { + return btoa(user + ":" + pass); + } + /** * Parse to boolean * @returns {boolean} @@ -141,6 +152,14 @@ class Monitor extends BeanModel { // Do not do any queries/high loading things before the "bean.ping" let startTime = dayjs().valueOf(); + // HTTP basic auth + let basicauthHeader = {}; + if (this.basicauth_user) { + basicauthHeader = { + "Authorization": "Basic " + this.encodeB64(this.basicauth_user, this.basicauth_pass) + } + } + const options = { url: this.url, method: (this.method || "get").toLowerCase(), @@ -150,6 +169,7 @@ class Monitor extends BeanModel { "Accept": "*/*", "User-Agent": "Uptime-Kuma/" + version, ...(this.headers ? JSON.parse(this.headers) : {}), + ...(basicauthHeader) }, httpsAgent: new https.Agent({ maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940) diff --git a/server/server.js b/server/server.js index d1fd7ff29..76d456c54 100644 --- a/server/server.js +++ b/server/server.js @@ -575,6 +575,8 @@ exports.entryPage = "dashboard"; bean.method = monitor.method; bean.body = monitor.body; bean.headers = monitor.headers; + bean.basicauth_user = monitor.basicauth_user; + bean.basicauth_pass = monitor.basicauth_pass; bean.interval = monitor.interval; bean.retryInterval = monitor.retryInterval; bean.hostname = monitor.hostname; @@ -1139,6 +1141,8 @@ exports.entryPage = "dashboard"; method: monitorListData[i].method || "GET", body: monitorListData[i].body, headers: monitorListData[i].headers, + basicauth_user: monitorListData[i].basicauth_user, + basicauth_pass: monitorListData[i].basicauth_pass, interval: monitorListData[i].interval, retryInterval: retryInterval, hostname: monitorListData[i].hostname, diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 65c3dad6e..18954968a 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -265,6 +265,15 @@ + + +

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

+
+ + + + +
@@ -487,6 +496,7 @@ export default { this.monitor.headers = JSON.stringify(JSON.parse(this.monitor.headers), null, 4); } + if (this.isAdd) { this.$root.add(this.monitor, async (res) => { From 0dcb7aed21fe9d63ffbdc6c866e0d4cd4485b6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Bratovi=C4=87?= Date: Tue, 2 Nov 2021 13:11:33 +0100 Subject: [PATCH 03/17] Delinting --- server/model/monitor.js | 6 +++--- src/pages/EditMonitor.vue | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index c80e941e9..95ef39336 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -87,9 +87,9 @@ class Monitor extends BeanModel { * for HTTP "basic" auth, as per RFC-7617 * @returns {string} */ - encodeB64(user, pass) { + encodeB64(user, pass) { return btoa(user + ":" + pass); - } + } /** * Parse to boolean @@ -157,7 +157,7 @@ class Monitor extends BeanModel { if (this.basicauth_user) { basicauthHeader = { "Authorization": "Basic " + this.encodeB64(this.basicauth_user, this.basicauth_pass) - } + }; } const options = { diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 18954968a..f5099aa3a 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -266,7 +266,7 @@ - +

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

@@ -496,7 +496,6 @@ export default { this.monitor.headers = JSON.stringify(JSON.parse(this.monitor.headers), null, 4); } - if (this.isAdd) { this.$root.add(this.monitor, async (res) => { From 179ca232bc85d6a7a0bbedc05d10be5f6e6a003e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Bratovi=C4=87?= Date: Thu, 4 Nov 2021 10:12:06 +0100 Subject: [PATCH 04/17] Minor refactor - change variable names and add commas to object definitions --- ...-basicauth.sql => patch-monitor-basic-auth.sql} | 4 ++-- server/database.js | 2 +- server/model/monitor.js | 14 +++++++------- server/server.js | 8 ++++---- src/pages/EditMonitor.vue | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) rename db/{patch-monitor-basicauth.sql => patch-monitor-basic-auth.sql} (66%) diff --git a/db/patch-monitor-basicauth.sql b/db/patch-monitor-basic-auth.sql similarity index 66% rename from db/patch-monitor-basicauth.sql rename to db/patch-monitor-basic-auth.sql index 3a33350d7..de4bdefd9 100644 --- a/db/patch-monitor-basicauth.sql +++ b/db/patch-monitor-basic-auth.sql @@ -2,9 +2,9 @@ BEGIN TRANSACTION; ALTER TABLE monitor - ADD basicauth_user TEXT default null; + ADD basic_auth_user TEXT default null; ALTER TABLE monitor - ADD basicauth_pass TEXT default null; + ADD basic_auth_pass TEXT default null; COMMIT; diff --git a/server/database.js b/server/database.js index cc7247f1c..dfc739e0a 100644 --- a/server/database.js +++ b/server/database.js @@ -52,7 +52,7 @@ class Database { "patch-http-monitor-method-body-and-headers.sql": true, "patch-2fa-invalidate-used-token.sql": true, "patch-notification_sent_history.sql": true, - "patch-monitor-basicauth.sql": true, + "patch-monitor-basic-auth.sql": true, } /** diff --git a/server/model/monitor.js b/server/model/monitor.js index 95ef39336..f3c823c3b 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -58,8 +58,8 @@ class Monitor extends BeanModel { method: this.method, body: this.body, headers: this.headers, - basicauth_user: this.basicauth_user, - basicauth_pass: this.basicauth_pass, + basic_auth_user: this.basic_auth_user, + basic_auth_pass: this.basic_auth_pass, hostname: this.hostname, port: this.port, maxretries: this.maxretries, @@ -153,10 +153,10 @@ class Monitor extends BeanModel { let startTime = dayjs().valueOf(); // HTTP basic auth - let basicauthHeader = {}; - if (this.basicauth_user) { - basicauthHeader = { - "Authorization": "Basic " + this.encodeB64(this.basicauth_user, this.basicauth_pass) + let basicAuthHeader = {}; + if (this.basic_auth_user) { + basicAuthHeader = { + "Authorization": "Basic " + this.encodeB64(this.basic_auth_user, this.basic_auth_pass), }; } @@ -169,7 +169,7 @@ class Monitor extends BeanModel { "Accept": "*/*", "User-Agent": "Uptime-Kuma/" + version, ...(this.headers ? JSON.parse(this.headers) : {}), - ...(basicauthHeader) + ...(basicAuthHeader), }, httpsAgent: new https.Agent({ maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940) diff --git a/server/server.js b/server/server.js index 76d456c54..b1678198a 100644 --- a/server/server.js +++ b/server/server.js @@ -575,8 +575,8 @@ exports.entryPage = "dashboard"; bean.method = monitor.method; bean.body = monitor.body; bean.headers = monitor.headers; - bean.basicauth_user = monitor.basicauth_user; - bean.basicauth_pass = monitor.basicauth_pass; + bean.basic_auth_user = monitor.basic_auth_user; + bean.basic_auth_pass = monitor.basic_auth_pass; bean.interval = monitor.interval; bean.retryInterval = monitor.retryInterval; bean.hostname = monitor.hostname; @@ -1141,8 +1141,8 @@ exports.entryPage = "dashboard"; method: monitorListData[i].method || "GET", body: monitorListData[i].body, headers: monitorListData[i].headers, - basicauth_user: monitorListData[i].basicauth_user, - basicauth_pass: monitorListData[i].basicauth_pass, + basic_auth_user: monitorListData[i].basic_auth_user, + basic_auth_pass: monitorListData[i].basic_auth_pass, interval: monitorListData[i].interval, retryInterval: retryInterval, hostname: monitorListData[i].hostname, diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index f5099aa3a..8b3157eab 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -270,9 +270,9 @@

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

- + - +
From 0481a241f3905dc23421a41de6b0ca80836f233c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Bratovi=C4=87?= Date: Thu, 4 Nov 2021 10:22:42 +0100 Subject: [PATCH 05/17] Add translated placeholders for editing basic auth --- src/pages/EditMonitor.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 8b3157eab..108defb74 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -270,9 +270,9 @@

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

- + - +
From f9bb48de137eb83c458c9cdc2275a736b9d2ab83 Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Wed, 20 Oct 2021 18:54:20 +0800 Subject: [PATCH 06/17] WIP: Convert Settings to components --- src/assets/vars.scss | 1 + src/components/MonitorList.vue | 2 +- src/components/settings/About.vue | 25 + src/components/settings/Appearance.vue | 149 +++++ src/components/settings/Backup.vue | 213 ++++++ src/components/settings/General.vue | 191 ++++++ src/components/settings/MonitorHistory.vue | 127 ++++ src/components/settings/Notifications.vue | 46 ++ src/components/settings/Security.vue | 323 +++++++++ src/languages/en.js | 1 + src/layouts/Layout.vue | 4 +- src/pages/Settings.vue | 741 +++------------------ 12 files changed, 1190 insertions(+), 633 deletions(-) create mode 100644 src/components/settings/About.vue create mode 100644 src/components/settings/Appearance.vue create mode 100644 src/components/settings/Backup.vue create mode 100644 src/components/settings/General.vue create mode 100644 src/components/settings/MonitorHistory.vue create mode 100644 src/components/settings/Notifications.vue create mode 100644 src/components/settings/Security.vue diff --git a/src/assets/vars.scss b/src/assets/vars.scss index 2f4369832..91ab917e5 100644 --- a/src/assets/vars.scss +++ b/src/assets/vars.scss @@ -12,6 +12,7 @@ $dark-font-color2: #020b05; $dark-bg: #0d1117; $dark-bg2: #070a10; $dark-border-color: #1d2634; +$dark-header-bg: #161b22; $easing-in: cubic-bezier(0.54, 0.78, 0.55, 0.97); $easing-out: cubic-bezier(0.25, 0.46, 0.45, 0.94); diff --git a/src/components/MonitorList.vue b/src/components/MonitorList.vue index bd771f8f0..ef51e89cd 100644 --- a/src/components/MonitorList.vue +++ b/src/components/MonitorList.vue @@ -137,7 +137,7 @@ export default { justify-content: space-between; .dark & { - background-color: #161b22; + background-color: $dark-header-bg; border-bottom: 0; } } diff --git a/src/components/settings/About.vue b/src/components/settings/About.vue new file mode 100644 index 000000000..baa72f39a --- /dev/null +++ b/src/components/settings/About.vue @@ -0,0 +1,25 @@ + + + + + diff --git a/src/components/settings/Appearance.vue b/src/components/settings/Appearance.vue new file mode 100644 index 000000000..e0a3d6430 --- /dev/null +++ b/src/components/settings/Appearance.vue @@ -0,0 +1,149 @@ + + + + + diff --git a/src/components/settings/Backup.vue b/src/components/settings/Backup.vue new file mode 100644 index 000000000..6ac28d468 --- /dev/null +++ b/src/components/settings/Backup.vue @@ -0,0 +1,213 @@ + + + + + diff --git a/src/components/settings/General.vue b/src/components/settings/General.vue new file mode 100644 index 000000000..308f21aee --- /dev/null +++ b/src/components/settings/General.vue @@ -0,0 +1,191 @@ + + + + + diff --git a/src/components/settings/MonitorHistory.vue b/src/components/settings/MonitorHistory.vue new file mode 100644 index 000000000..85853ea1a --- /dev/null +++ b/src/components/settings/MonitorHistory.vue @@ -0,0 +1,127 @@ + + + + + diff --git a/src/components/settings/Notifications.vue b/src/components/settings/Notifications.vue new file mode 100644 index 000000000..b2cbcf48a --- /dev/null +++ b/src/components/settings/Notifications.vue @@ -0,0 +1,46 @@ + + + + + diff --git a/src/components/settings/Security.vue b/src/components/settings/Security.vue new file mode 100644 index 000000000..1cbfb034e --- /dev/null +++ b/src/components/settings/Security.vue @@ -0,0 +1,323 @@ + + + + + diff --git a/src/languages/en.js b/src/languages/en.js index 15c3cd0f3..a503b5235 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -307,4 +307,5 @@ export default { steamApiKeyDescription: "For monitoring a Steam Game Server you need a Steam Web-API key. You can register your API key here: ", "Current User": "Current User", recent: "Recent", + shrinkDatabaseDescription: "Trigger database VACCUM for SQLite. If your database is created after 1.10.0, AUTO_VACCUM is already enabled and this action is not needed.", }; diff --git a/src/layouts/Layout.vue b/src/layouts/Layout.vue index 7228a460d..2f4f689ab 100644 --- a/src/layouts/Layout.vue +++ b/src/layouts/Layout.vue @@ -188,8 +188,8 @@ main { .dark { header { - background-color: #161b22; - border-bottom-color: #161b22 !important; + background-color: $dark-header-bg; + border-bottom-color: $dark-header-bg !important; span { color: #f0f6fc; diff --git a/src/pages/Settings.vue b/src/pages/Settings.vue index 9d501407d..9ff234150 100644 --- a/src/pages/Settings.vue +++ b/src/pages/Settings.vue @@ -7,521 +7,90 @@
-
-

{{ $t("Appearance") }}

- -
- - +
+ - -
- - -
-
- - - - - - - - -
-
-
- -
- -
-
- - - - - - - - -
-
-
- - -

{{ $t("General") }}

- -
- -
- - -
- - -
- - -
- - -
-
- - -
-
- - -
- - -
- - -
- -
- - -
-
- - -
- - -
- - -
- -
-
-
- - -
- - -
- {{ $t("steamApiKeyDescription") }}https://steamcommunity.com/dev -
-
- - -
-

{{ $t("Monitor History") }}

-
- - -
-
- - -
- -
-
- -
- -
-
- - -
-

{{ $t("Notifications") }}

-

- {{ $t("Not available, please setup.") }} -

-

- {{ $t("notificationDescription") }} -

- - - - +
+
+ {{ subMenus[currentSubMenu].title }} +
+
+
- - -

{{ $t("Info") }}

- - {{ $t("Version") }}: {{ $root.info.version }}
- {{ $t("Check Update On GitHub") }}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {{ $t("confirmClearStatisticsMsg") }} - - - {{ $t("confirmImportMsg") }} -
@@ -667,37 +126,8 @@ export default { .shadow-box { padding: 20px; -} - -.btn-check:active + .btn-outline-primary, -.btn-check:checked + .btn-outline-primary, -.btn-check:hover + .btn-outline-primary { - color: #fff; -} - -.dark { - .list-group-item { - background-color: $dark-bg2; - color: $dark-font-color; - } - - .btn-check:active + .btn-outline-primary, - .btn-check:checked + .btn-outline-primary, - .btn-check:hover + .btn-outline-primary { - color: #000; - } - - #importBackup { - &::file-selector-button { - color: $primary; - background-color: $dark-bg; - } - - &:hover:not(:disabled):not([readonly])::file-selector-button { - color: $dark-font-color2; - background-color: $primary; - } - } + min-height: calc(100vh - 155px); + max-height: calc(100vh - 30px); } footer { @@ -707,4 +137,55 @@ footer { padding-bottom: 30px; text-align: center; } + +.settings-menu { + flex: 0 0 auto; + width: 300px; + + .menu-item { + border-radius: 10px; + margin: 0.5em; + padding: 0.7em 1em; + cursor: pointer; + } + + .menu-item:hover { + background: $highlight-white; + + .dark & { + background: $dark-header-bg; + } + } + + .menu-item.active { + background: $highlight-white; + border-left: 4px solid $primary; + border-top-left-radius: 0; + border-bottom-left-radius: 0; + + .dark & { + background: $dark-header-bg; + } + } +} + +.settings-content { + flex: 0 0 auto; + width: calc(100% - 300px); + + .settings-content-header { + width: calc(100% + 20px); + border-bottom: 1px solid #dee2e6; + border-radius: 0 10px 0 0; + margin-top: -20px; + margin-right: -20px; + padding: 12.5px 1em; + font-size: 26px; + + .dark & { + background: $dark-header-bg; + border-bottom: 0; + } + } +} From 369cad90c1c2e938a7651947dbffaed6bd2ebd4f Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Wed, 3 Nov 2021 17:03:40 +0800 Subject: [PATCH 07/17] WIP: Convert to use vue-router & improve layout WIP: Fix security page & improve layout WIP: Fix displaying current page UI: Improve spacing Chore: Improve styling --- src/components/settings/General.vue | 6 +-- src/components/settings/MonitorHistory.vue | 8 ++-- src/components/settings/Security.vue | 10 ++--- src/pages/Settings.vue | 51 ++++++++++------------ src/router.js | 46 +++++++++++++++++++ 5 files changed, 82 insertions(+), 39 deletions(-) diff --git a/src/components/settings/General.vue b/src/components/settings/General.vue index 308f21aee..a1b42d85f 100644 --- a/src/components/settings/General.vue +++ b/src/components/settings/General.vue @@ -163,13 +163,13 @@ export default { computed: { settings() { - return this.$parent.$parent.settings; + return this.$parent.$parent.$parent.settings; }, saveSettings() { - return this.$parent.$parent.saveSettings; + return this.$parent.$parent.$parent.saveSettings; }, settingsLoaded() { - return this.$parent.$parent.settingsLoaded; + return this.$parent.$parent.$parent.settingsLoaded; }, guessTimezone() { return dayjs.tz.guess(); diff --git a/src/components/settings/MonitorHistory.vue b/src/components/settings/MonitorHistory.vue index 85853ea1a..95efff0e2 100644 --- a/src/components/settings/MonitorHistory.vue +++ b/src/components/settings/MonitorHistory.vue @@ -23,7 +23,7 @@ -
{{ $t("shrinkDatabaseDescription") }}
+
{{ $t("shrinkDatabaseDescription") }}

{{ $t("Change Password") }}
@@ -60,7 +61,7 @@ -
+
{{ $t("Two Factor Authentication") }}
@@ -82,7 +83,6 @@
-
@@ -244,13 +244,13 @@ export default { computed: { settings() { - return this.$parent.$parent.settings; + return this.$parent.$parent.$parent.settings; }, saveSettings() { - return this.$parent.$parent.saveSettings; + return this.$parent.$parent.$parent.saveSettings; }, settingsLoaded() { - return this.$parent.$parent.settingsLoaded; + return this.$parent.$parent.$parent.settingsLoaded; } }, diff --git a/src/pages/Settings.vue b/src/pages/Settings.vue index 9ff234150..0cff13678 100644 --- a/src/pages/Settings.vue +++ b/src/pages/Settings.vue @@ -8,21 +8,25 @@
- + +
- {{ subMenus[currentSubMenu].title }} + {{ subMenus[$route.name.split("-")[1]].title }}
- +
@@ -32,16 +36,6 @@