From 246243574328ead6d95d45b81b055761b01040a7 Mon Sep 17 00:00:00 2001 From: Miguel Ribeiro Date: Sun, 17 Mar 2024 22:56:30 +0100 Subject: [PATCH] feat: allow selecting tls or ssl for email notifications (#237) --- endpoints/cronjobs/sendnotifications.php | 3 ++- endpoints/notifications/save.php | 11 ++++++++--- endpoints/notifications/sendtestmail.php | 8 +++++++- includes/i18n/de.php | 2 ++ includes/i18n/el.php | 2 ++ includes/i18n/en.php | 2 ++ includes/i18n/es.php | 2 ++ includes/i18n/fr.php | 2 ++ includes/i18n/jp.php | 2 ++ includes/i18n/pt.php | 2 ++ includes/i18n/pt_br.php | 2 ++ includes/i18n/tr.php | 2 ++ includes/i18n/zh_cn.php | 2 ++ includes/i18n/zh_tw.php | 2 ++ includes/version.php | 2 +- migrations/000012.php | 12 ++++++++++++ scripts/settings.js | 4 ++++ settings.php | 7 +++++++ styles/styles.css | 1 - 19 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 migrations/000012.php diff --git a/endpoints/cronjobs/sendnotifications.php b/endpoints/cronjobs/sendnotifications.php index b1705a721..2e2724714 100644 --- a/endpoints/cronjobs/sendnotifications.php +++ b/endpoints/cronjobs/sendnotifications.php @@ -14,6 +14,7 @@ $days = $row['days']; $smtpAddress = $row["smtp_address"]; $smtpPort = $row["smtp_port"]; + $encryption = $row["encryption"]; $smtpUsername = $row["smtp_username"]; $smtpPassword = $row["smtp_password"]; $fromEmail = $row["from_email"] ? $row["from_email"] : "wallos@wallosapp.com"; @@ -76,7 +77,7 @@ $mail->SMTPAuth = true; $mail->Username = $smtpUsername; $mail->Password = $smtpPassword; - $mail->SMTPSecure = 'tls'; + $mail->SMTPSecure = $encryption; $mail->Port = $smtpPort; $stmt = $db->prepare('SELECT * FROM household WHERE id = :userId'); diff --git a/endpoints/notifications/save.php b/endpoints/notifications/save.php index 4d09e9f12..79bbce5b1 100644 --- a/endpoints/notifications/save.php +++ b/endpoints/notifications/save.php @@ -23,6 +23,10 @@ $days = $data["days"]; $smtpAddress = $data["smtpaddress"]; $smtpPort = $data["smtpport"]; + $encryption = "tls"; + if (isset($data["encryption"])) { + $encryption = $data["encryption"]; + } $smtpUsername = $data["smtpusername"]; $smtpPassword = $data["smtppassword"]; $fromEmail = $data["fromemail"]; @@ -38,12 +42,12 @@ echo json_encode($response); } else { if ($result == 0) { - $query = "INSERT INTO notifications (enabled, days, smtp_address, smtp_port, smtp_username, smtp_password, from_email) - VALUES (:enabled, :days, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword, :fromEmail)"; + $query = "INSERT INTO notifications (enabled, days, smtp_address, smtp_port, smtp_username, smtp_password, from_email, encryption) + VALUES (:enabled, :days, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword, :fromEmail, :encryption)"; } else { $query = "UPDATE notifications SET enabled = :enabled, days = :days, smtp_address = :smtpAddress, smtp_port = :smtpPort, - smtp_username = :smtpUsername, smtp_password = :smtpPassword, from_email = :fromEmail"; + smtp_username = :smtpUsername, smtp_password = :smtpPassword, from_email = :fromEmail, encryption = :encryption"; } $stmt = $db->prepare($query); @@ -54,6 +58,7 @@ $stmt->bindValue(':smtpUsername', $smtpUsername, SQLITE3_TEXT); $stmt->bindValue(':smtpPassword', $smtpPassword, SQLITE3_TEXT); $stmt->bindValue(':fromEmail', $fromEmail, SQLITE3_TEXT); + $stmt->bindValue(':encryption', $encryption, SQLITE3_TEXT); if ($stmt->execute()) { $response = [ diff --git a/endpoints/notifications/sendtestmail.php b/endpoints/notifications/sendtestmail.php index 009ca489c..1596acab3 100644 --- a/endpoints/notifications/sendtestmail.php +++ b/endpoints/notifications/sendtestmail.php @@ -23,6 +23,12 @@ ]; echo json_encode($response); } else { + $enxryption = "tls"; + if (isset($data["encryption"])) { + $encryption = $data["encryption"]; + } + + require '../../libs/PHPMailer/PHPMailer.php'; require '../../libs/PHPMailer/SMTP.php'; require '../../libs/PHPMailer/Exception.php'; @@ -41,7 +47,7 @@ $mail->SMTPAuth = true; $mail->Username = $smtpUsername; $mail->Password = $smtpPassword; - $mail->SMTPSecure = 'tls'; + $mail->SMTPSecure = $encryption; $mail->Port = $smtpPort; $getUser = "SELECT * FROM user WHERE id = 1"; diff --git a/includes/i18n/de.php b/includes/i18n/de.php index d955cae37..316c0b5ca 100644 --- a/includes/i18n/de.php +++ b/includes/i18n/de.php @@ -111,6 +111,8 @@ "days_before" => "Tage bevor", "smtp_address" => "SMTP Adresse", "port" => "Port", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "SMTP Benutzername", "smtp_password" => "SMTP Passwort", "from_email" => "Absender E-Mail Adresse (optional)", diff --git a/includes/i18n/el.php b/includes/i18n/el.php index e68621304..316011e14 100644 --- a/includes/i18n/el.php +++ b/includes/i18n/el.php @@ -111,6 +111,8 @@ "days_before" => "ημέρες πριν", "smtp_address" => "SMTP Address", "port" => "Θύρα", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "SMTP χρήστης", "smtp_password" => "SMTP κωδικός", "from_email" => "Από (Προαιρετικό)", diff --git a/includes/i18n/en.php b/includes/i18n/en.php index 90743de7c..c7e76d74b 100644 --- a/includes/i18n/en.php +++ b/includes/i18n/en.php @@ -111,6 +111,8 @@ "days_before" => "days before", "smtp_address" => "SMTP Address", "port" => "Port", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "SMTP Username", "smtp_password" => "SMTP Password", "from_email" => "From email (Optional)", diff --git a/includes/i18n/es.php b/includes/i18n/es.php index b7d3f133b..2ee624414 100644 --- a/includes/i18n/es.php +++ b/includes/i18n/es.php @@ -111,6 +111,8 @@ "days_before" => "días antes", "smtp_address" => "Dirección SMTP", "port" => "Puerto", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "Nombre de usuario SMTP", "smtp_password" => "Contraseña SMTP", "from_email" => "Correo electrónico de origen (Opcional)", diff --git a/includes/i18n/fr.php b/includes/i18n/fr.php index 0d5080017..729e9db7e 100644 --- a/includes/i18n/fr.php +++ b/includes/i18n/fr.php @@ -111,6 +111,8 @@ "days_before" => "jours avant", "smtp_address" => "Adresse SMTP", "port" => "Port", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "Nom d'utilisateur SMTP", "smtp_password" => "Mot de passe SMTP", "from_email" => "De l'adresse courriel (facultatif)", diff --git a/includes/i18n/jp.php b/includes/i18n/jp.php index f7843b45d..94ad3f329 100644 --- a/includes/i18n/jp.php +++ b/includes/i18n/jp.php @@ -111,6 +111,8 @@ "days_before" => "日前", "smtp_address" => "SMTPアドレス", "port" => "ポート番号", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "SMTPユーザー名", "smtp_password" => "SMTPパスワード", "from_email" => "送信元アドレス (オプション)", diff --git a/includes/i18n/pt.php b/includes/i18n/pt.php index 790a96dd0..a0f708ea6 100644 --- a/includes/i18n/pt.php +++ b/includes/i18n/pt.php @@ -111,6 +111,8 @@ "days_before" => "dias antes", "smtp_address" => "Endereço SMTP", "port" => "Porto", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "Utilizador SMTP", "smtp_password" => "Password SMTP", "from_email" => "Email de envio (Opcional)", diff --git a/includes/i18n/pt_br.php b/includes/i18n/pt_br.php index eac5f76f2..b37a22502 100644 --- a/includes/i18n/pt_br.php +++ b/includes/i18n/pt_br.php @@ -109,6 +109,8 @@ "days_before" => "dias antes", "smtp_address" => "Endereço SMTP", "port" => "Porta", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "Usuário SMTP", "smtp_password" => "Senha SMTP", "from_email" => "Email de envio (Opcional)", diff --git a/includes/i18n/tr.php b/includes/i18n/tr.php index 3b63bf72e..c2fe7326c 100644 --- a/includes/i18n/tr.php +++ b/includes/i18n/tr.php @@ -111,6 +111,8 @@ "days_before" => "günler önce", "smtp_address" => "SMTP Adresi", "port" => "Port", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "SMTP Kullanıcı Adı", "smtp_password" => "SMTP Şifresi", "from_email" => "Gönderen e-posta (İsteğe bağlı)", diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.php index c14a45ce5..2dedb9b9d 100644 --- a/includes/i18n/zh_cn.php +++ b/includes/i18n/zh_cn.php @@ -118,6 +118,8 @@ "days_before" => "天", "smtp_address" => "SMTP 地址", "port" => "端口", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "SMTP 用户名", "smtp_password" => "SMTP 密码", "from_email" => "发件人邮箱(可选)", diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.php index 47c20d2f9..aebd65301 100644 --- a/includes/i18n/zh_tw.php +++ b/includes/i18n/zh_tw.php @@ -111,6 +111,8 @@ "days_before" => "天", "smtp_address" => "SMTP 信箱地址", "port" => "連接埠", + "tls" => "TLS", + "ssl" => "SSL", "smtp_username" => "SMTP 使用者名稱", "smtp_password" => "SMTP 密碼", "from_email" => "寄件人信箱(可選)", diff --git a/includes/version.php b/includes/version.php index a413fd91d..1309ce29e 100644 --- a/includes/version.php +++ b/includes/version.php @@ -1,3 +1,3 @@ \ No newline at end of file diff --git a/migrations/000012.php b/migrations/000012.php new file mode 100644 index 000000000..6b8be8546 --- /dev/null +++ b/migrations/000012.php @@ -0,0 +1,12 @@ +query("SELECT * FROM pragma_table_info('notifications') WHERE name='encryption'"); + $columnRequired = $columnQuery->fetchArray(SQLITE3_ASSOC) === false; + + if ($columnRequired) { + $db->exec('ALTER TABLE notifications ADD COLUMN `encryption` TEXT DEFAULT "tls"'); + $db->exec('UPDATE notifications SET `encryption` = "tls"'); + } +?> \ No newline at end of file diff --git a/scripts/settings.js b/scripts/settings.js index cd89e4b2a..ed07b0389 100644 --- a/scripts/settings.js +++ b/scripts/settings.js @@ -801,6 +801,7 @@ function saveNotificationsButton() { const days = document.getElementById("days").value; const smtpAddress = document.getElementById("smtpaddress").value; const smtpPort = document.getElementById("smtpport").value; + const encryption = document.querySelector('input[name="encryption"]:checked').value; const smtpUsername = document.getElementById("smtpusername").value; const smtpPassword = document.getElementById("smtppassword").value; const fromEmail = document.getElementById("fromemail").value; @@ -810,6 +811,7 @@ function saveNotificationsButton() { days: days, smtpaddress: smtpAddress, smtpport: smtpPort, + encryption: encryption, smtpusername: smtpUsername, smtppassword: smtpPassword, fromemail: fromEmail @@ -843,6 +845,7 @@ function testNotificationButton() { const smtpAddress = document.getElementById("smtpaddress").value; const smtpPort = document.getElementById("smtpport").value; + const encryption = document.querySelector('input[name="encryption"]:checked').value; const smtpUsername = document.getElementById("smtpusername").value; const smtpPassword = document.getElementById("smtppassword").value; const fromEmail = document.getElementById("fromemail").value; @@ -850,6 +853,7 @@ function testNotificationButton() { const data = { smtpaddress: smtpAddress, smtpport: smtpPort, + encryption: encryption, smtpusername: smtpUsername, smtppassword: smtpPassword, fromemail: fromEmail diff --git a/settings.php b/settings.php index 83f473189..b50533054 100644 --- a/settings.php +++ b/settings.php @@ -184,6 +184,7 @@ $notifications['smtp_username'] = ""; $notifications['smtp_password'] = ""; $notifications['from_email'] = ""; + $notifications['encryption'] = "tls"; } ?> @@ -217,6 +218,12 @@ +
+ /> + + /> + +
diff --git a/styles/styles.css b/styles/styles.css index 6c2eb9c84..a24f66b07 100644 --- a/styles/styles.css +++ b/styles/styles.css @@ -743,7 +743,6 @@ label { } .form-group-inline label { - font-weight: 300; font-size: 16px; margin-bottom: 0px; margin-left: 0px;