diff --git a/db/knex_migrations/2025-01-01-0000-add-smtp.js b/db/knex_migrations/2025-01-01-0000-add-smtp.js new file mode 100644 index 000000000..00d4835f5 --- /dev/null +++ b/db/knex_migrations/2025-01-01-0000-add-smtp.js @@ -0,0 +1,12 @@ +exports.up = function (knex) { + return knex.schema + .alterTable("monitor", function (table) { + table.string("smtp_security").defaultTo(null); + }); +}; + +exports.down = function (knex) { + return knex.schema.alterTable("monitor", function (table) { + table.dropColumn("smtp_security"); + }); +}; diff --git a/package-lock.json b/package-lock.json index 8d3f58b4d..ccf1a628c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "uptime-kuma", - "version": "2.0.0-beta.0", + "version": "2.0.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "uptime-kuma", - "version": "2.0.0-beta.0", + "version": "2.0.0-beta.1", "license": "MIT", "dependencies": { "@grpc/grpc-js": "~1.8.22", diff --git a/server/model/monitor.js b/server/model/monitor.js index 3ad8cfafc..e8ec54c14 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -153,6 +153,7 @@ class Monitor extends BeanModel { snmpOid: this.snmpOid, jsonPathOperator: this.jsonPathOperator, snmpVersion: this.snmpVersion, + smtpSecurity: this.smtpSecurity, rabbitmqNodes: JSON.parse(this.rabbitmqNodes), conditions: JSON.parse(this.conditions), }; diff --git a/server/monitor-types/smtp.js b/server/monitor-types/smtp.js new file mode 100644 index 000000000..6683b83ec --- /dev/null +++ b/server/monitor-types/smtp.js @@ -0,0 +1,47 @@ +const { MonitorType } = require("./monitor-type"); +const { UP, log, evaluateJsonQuery } = require("../../src/util"); +const nodemailer = require("nodemailer"); + +class SMTPMonitorType extends MonitorType { + name = "smtp"; + + isSMTPS(smtpSecurity) { + return smtpSecurity === 'secure'; + } + + isIgnoreTLS(smtpSecurity) { + return smtpSecurity === 'nostarttls'; + } + + isRequireTLS(smtpSecurity) { + return smtpSecurity === 'starttls'; + } + + /** + * @inheritdoc + */ + async check(monitor, heartbeat, _server) { + let options = { + port: monitor.port || 25, + host: monitor.hostname, + secure: this.isSMTPS(monitor.smtpSecurity), // use SMTPS (not STARTTLS) + ignoreTLS: this.isIgnoreTLS(monitor.smtpSecurity), // don't use STARTTLS even if it's available + requireTLS: this.isRequireTLS(monitor.smtpSecurity), // use STARTTLS or fail + } + let transporter = nodemailer.createTransport(options); + try { + await transporter.verify(); + + heartbeat.status = UP; + heartbeat.msg = `SMTP connection verifies successfully`; + } catch (e) { + throw new Error(`SMTP connection doesn't verify: ${e}`); + } finally { + transporter.close(); + } + } +} + +module.exports = { + SMTPMonitorType, +}; \ No newline at end of file diff --git a/server/server.js b/server/server.js index ec5ad49f6..e2968ed68 100644 --- a/server/server.js +++ b/server/server.js @@ -866,8 +866,10 @@ let needSetup = false; monitor.kafkaProducerAllowAutoTopicCreation; bean.gamedigGivenPortOnly = monitor.gamedigGivenPortOnly; bean.remote_browser = monitor.remote_browser; + bean.smtpSecurity = monitor.smtpSecurity; bean.snmpVersion = monitor.snmpVersion; bean.snmpOid = monitor.snmpOid; + bean.smtpSecurity = monitor.smtpSecurity; bean.jsonPathOperator = monitor.jsonPathOperator; bean.timeout = monitor.timeout; bean.rabbitmqNodes = JSON.stringify(monitor.rabbitmqNodes); diff --git a/server/uptime-kuma-server.js b/server/uptime-kuma-server.js index 062f098d7..135feca2c 100644 --- a/server/uptime-kuma-server.js +++ b/server/uptime-kuma-server.js @@ -113,6 +113,7 @@ class UptimeKumaServer { UptimeKumaServer.monitorTypeList["tailscale-ping"] = new TailscalePing(); UptimeKumaServer.monitorTypeList["dns"] = new DnsMonitorType(); UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType(); + UptimeKumaServer.monitorTypeList["smtp"] = new SMTPMonitorType(); UptimeKumaServer.monitorTypeList["snmp"] = new SNMPMonitorType(); UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType(); UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType(); @@ -551,6 +552,7 @@ const { RealBrowserMonitorType } = require("./monitor-types/real-browser-monitor const { TailscalePing } = require("./monitor-types/tailscale-ping"); const { DnsMonitorType } = require("./monitor-types/dns"); const { MqttMonitorType } = require("./monitor-types/mqtt"); +const { SMTPMonitorType } = require("./monitor-types/smtp"); const { SNMPMonitorType } = require("./monitor-types/snmp"); const { MongodbMonitorType } = require("./monitor-types/mongodb"); const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq"); diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index a83f91cab..0f597a349 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -24,6 +24,9 @@ + @@ -281,8 +284,8 @@ - -
+ +
-
+
@@ -329,6 +332,15 @@
+
+ + +
+