Skip to content

Commit

Permalink
feat: allow selecting tls or ssl for email notifications (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite authored Mar 17, 2024
1 parent e1cc925 commit 2462435
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 7 deletions.
3 changes: 2 additions & 1 deletion endpoints/cronjobs/sendnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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');
Expand Down
11 changes: 8 additions & 3 deletions endpoints/notifications/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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);
Expand All @@ -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 = [
Expand Down
8 changes: 7 additions & 1 deletion endpoints/notifications/sendtestmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
"days_before" => "ημέρες πριν",
"smtp_address" => "SMTP Address",
"port" => "Θύρα",
"tls" => "TLS",
"ssl" => "SSL",
"smtp_username" => "SMTP χρήστης",
"smtp_password" => "SMTP κωδικός",
"from_email" => "Από (Προαιρετικό)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/jp.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
"days_before" => "日前",
"smtp_address" => "SMTPアドレス",
"port" => "ポート番号",
"tls" => "TLS",
"ssl" => "SSL",
"smtp_username" => "SMTPユーザー名",
"smtp_password" => "SMTPパスワード",
"from_email" => "送信元アドレス (オプション)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/pt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/pt_br.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/tr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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ı)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/zh_cn.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
"days_before" => "",
"smtp_address" => "SMTP 地址",
"port" => "端口",
"tls" => "TLS",
"ssl" => "SSL",
"smtp_username" => "SMTP 用户名",
"smtp_password" => "SMTP 密码",
"from_email" => "发件人邮箱(可选)",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/zh_tw.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
"days_before" => "",
"smtp_address" => "SMTP 信箱地址",
"port" => "連接埠",
"tls" => "TLS",
"ssl" => "SSL",
"smtp_username" => "SMTP 使用者名稱",
"smtp_password" => "SMTP 密碼",
"from_email" => "寄件人信箱(可選)",
Expand Down
2 changes: 1 addition & 1 deletion includes/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
$version = "v1.16.3";
$version = "v1.17.0";
?>
12 changes: 12 additions & 0 deletions migrations/000012.php
Original file line number Diff line number Diff line change
@@ -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"');
}
?>
4 changes: 4 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -810,6 +811,7 @@ function saveNotificationsButton() {
days: days,
smtpaddress: smtpAddress,
smtpport: smtpPort,
encryption: encryption,
smtpusername: smtpUsername,
smtppassword: smtpPassword,
fromemail: fromEmail
Expand Down Expand Up @@ -843,13 +845,15 @@ 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;

const data = {
smtpaddress: smtpAddress,
smtpport: smtpPort,
encryption: encryption,
smtpusername: smtpUsername,
smtppassword: smtpPassword,
fromemail: fromEmail
Expand Down
7 changes: 7 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
$notifications['smtp_username'] = "";
$notifications['smtp_password'] = "";
$notifications['from_email'] = "";
$notifications['encryption'] = "tls";
}

?>
Expand Down Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ label {
}

.form-group-inline label {
font-weight: 300;
font-size: 16px;
margin-bottom: 0px;
margin-left: 0px;
Expand Down

0 comments on commit 2462435

Please sign in to comment.