Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.
feat: allow selecting tls or ssl for email notifications (#237)
Miguel Ribeiro246243574328
diff --git a/endpoints/cronjobs/sendnotifications.php b/endpoints/cronjobs/sendnotifications.phpindex b1705a7..2e27247 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"] : "[email protected]";@@ -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.phpindex 4d09e9f..79bbce5 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 notificationsSET 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.phpindex 009ca48..1596aca 100644--- a/endpoints/notifications/sendtestmail.php+++ b/endpoints/notifications/sendtestmail.php@@ -23,6 +23,12 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {];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 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {$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.phpindex d955cae..316c0b5 100644--- a/includes/i18n/de.php+++ b/includes/i18n/de.php@@ -111,6 +111,8 @@ $i18n = ["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.phpindex e686213..316011e 100644--- a/includes/i18n/el.php+++ b/includes/i18n/el.php@@ -111,6 +111,8 @@ $i18n = ["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.phpindex 90743de..c7e76d7 100644--- a/includes/i18n/en.php+++ b/includes/i18n/en.php@@ -111,6 +111,8 @@ $i18n = ["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.phpindex b7d3f13..2ee6244 100644--- a/includes/i18n/es.php+++ b/includes/i18n/es.php@@ -111,6 +111,8 @@ $i18n = ["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.phpindex 0d50800..729e9db 100644--- a/includes/i18n/fr.php+++ b/includes/i18n/fr.php@@ -111,6 +111,8 @@ $i18n = ["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.phpindex f7843b4..94ad3f3 100644--- a/includes/i18n/jp.php+++ b/includes/i18n/jp.php@@ -111,6 +111,8 @@ $i18n = ["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.phpindex 790a96d..a0f708e 100644--- a/includes/i18n/pt.php+++ b/includes/i18n/pt.php@@ -111,6 +111,8 @@ $i18n = ["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.phpindex eac5f76..b37a225 100644--- a/includes/i18n/pt_br.php+++ b/includes/i18n/pt_br.php@@ -109,6 +109,8 @@ $i18n = ["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.phpindex 3b63bf7..c2fe732 100644--- a/includes/i18n/tr.php+++ b/includes/i18n/tr.php@@ -111,6 +111,8 @@ $i18n = ["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.phpindex c14a45c..2dedb9b 100644--- a/includes/i18n/zh_cn.php+++ b/includes/i18n/zh_cn.php@@ -118,6 +118,8 @@ $i18n = ["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.phpindex 47c20d2..aebd653 100644--- a/includes/i18n/zh_tw.php+++ b/includes/i18n/zh_tw.php@@ -111,6 +111,8 @@ $i18n = ["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.phpindex a413fd9..1309ce2 100644--- a/includes/version.php+++ b/includes/version.php@@ -1,3 +1,3 @@<?php- $version = "v1.16.3";+ $version = "v1.17.0";?>\ No newline at end of filediff --git a/migrations/000012.php b/migrations/000012.phpnew file mode 100644index 0000000..6b8be85--- /dev/null+++ b/migrations/000012.php@@ -0,0 +1,12 @@+<?php+ // This migration adds a "encryption" column to the notifications table so that the encryption type can be stored.++ /** @noinspection PhpUndefinedVariableInspection */+ $columnQuery = $db->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 filediff --git a/scripts/settings.js b/scripts/settings.jsindex cd89e4b..ed07b03 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: fromEmaildiff --git a/settings.php b/settings.phpindex 83f4731..b505330 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 @@<input type="text" name="smtpaddress" id="smtpaddress" placeholder="<?= translate('smtp_address', $i18n) ?>" value="<?= $notifications['smtp_address'] ?>" /><input type="text" name="smtpport" id="smtpport" placeholder="<?= translate('port', $i18n) ?>" class="one-third" value="<?= $notifications['smtp_port'] ?>" /></div>+ <div class="form-group-inline">+ <input type="radio" name="encryption" id="encryptiontls" value="tls" <?= $notifications['encryption'] == "tls" ? "checked" : "" ?> />+ <label for="encryptiontls"><?= translate('tls', $i18n) ?></label>+ <input type="radio" name="encryption" id="encryptionssl" value="ssl" <?= $notifications['encryption'] == "ssl" ? "checked" : "" ?> />+ <label for="encryptionssl"><?= translate('ssl', $i18n) ?></label>+ </div><div class="form-group-inline"><input type="text" name="smtpusername" id="smtpusername" placeholder="<?= translate('smtp_username', $i18n) ?>" value="<?= $notifications['smtp_username'] ?>" /></div>diff --git a/styles/styles.css b/styles/styles.cssindex 6c2eb9c..a24f66b 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;