diff --git a/server/model/monitor.js b/server/model/monitor.js index eaafb7755..e1dc00e67 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, setSetting } = require("../util-server"); const { R } = require("redbean-node"); const { BeanModel } = require("redbean-node/dist/bean-model"); const { Notification } = require("../notification"); @@ -826,10 +826,19 @@ class Monitor extends BeanModel { if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) { const notificationList = await Monitor.getNotificationList(this); - log.debug("monitor", "call sendCertNotificationByTargetDays"); - await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 21, notificationList); - await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 14, notificationList); - await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 7, notificationList); + let notifyDays = await setting("tlsExpiryNotifyDays"); + if (notifyDays == null || !Array.isArray(notifyDays)) { + // Reset Default + setSetting("tlsExpiryNotifyDays", [ 7, 14, 21 ], "general"); + notifyDays = [ 7, 14, 21 ]; + } + + if (notifyDays != null && Array.isArray(notifyDays)) { + for (const day of notifyDays) { + log.debug("monitor", "call sendCertNotificationByTargetDays", day); + await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, day, notificationList); + } + } } } diff --git a/src/components/ActionInput.vue b/src/components/ActionInput.vue new file mode 100644 index 000000000..00cb3aab6 --- /dev/null +++ b/src/components/ActionInput.vue @@ -0,0 +1,62 @@ + + + diff --git a/src/components/settings/Notifications.vue b/src/components/settings/Notifications.vue index b2cbcf48a..187f4b7d5 100644 --- a/src/components/settings/Notifications.vue +++ b/src/components/settings/Notifications.vue @@ -20,16 +20,74 @@ +
+

{{ $t("settingsCertificateExpiry") }}

+

{{ $t("certificationExpiryDescription") }}

+
+
+ {{ day }} {{ $t("day(s)") }} + +
+
+
+ +
+
+ +
+
+ @@ -43,4 +101,16 @@ export default { color: $dark-font-color; } } + +.cert-exp-days .cert-exp-day-row { + border-bottom: 1px solid rgba(0, 0, 0, 0.125); + + .dark & { + border-bottom: 1px solid $dark-border-color; + } +} + +.cert-exp-days .cert-exp-day-row:last-child { + border: none; +} diff --git a/src/languages/en.js b/src/languages/en.js index af6ec32b3..d21e40ef0 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -515,4 +515,6 @@ export default { "Go back to the previous page.": "Go back to the previous page.", "Coming Soon": "Coming Soon", wayToGetClickSendSMSToken: "You can get API Username and API Key from {0} .", + settingsCertificateExpiry: "TLS Certificate Expiry", + certificationExpiryDescription: "HTTPS Monitors trigger notification when TLS certificate expires in:", }; diff --git a/src/pages/Settings.vue b/src/pages/Settings.vue index 11d3a1be3..cb5f027c4 100644 --- a/src/pages/Settings.vue +++ b/src/pages/Settings.vue @@ -145,6 +145,10 @@ export default { this.settings.keepDataPeriodDays = 180; } + if (this.settings.tlsExpiryNotifyDays === undefined) { + this.settings.tlsExpiryNotifyDays = []; + } + this.settingsLoaded = true; }); },