feat: allow selecting tls or ssl for email notifications (#237)
This commit is contained in:
parent
e1cc9254ac
commit
2462435743
@ -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');
|
||||
|
||||
@ -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 = [
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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)",
|
||||
|
||||
@ -111,6 +111,8 @@ $i18n = [
|
||||
"days_before" => "ημέρες πριν",
|
||||
"smtp_address" => "SMTP Address",
|
||||
"port" => "Θύρα",
|
||||
"tls" => "TLS",
|
||||
"ssl" => "SSL",
|
||||
"smtp_username" => "SMTP χρήστης",
|
||||
"smtp_password" => "SMTP κωδικός",
|
||||
"from_email" => "Από (Προαιρετικό)",
|
||||
|
||||
@ -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)",
|
||||
|
||||
@ -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)",
|
||||
|
||||
@ -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)",
|
||||
|
||||
@ -111,6 +111,8 @@ $i18n = [
|
||||
"days_before" => "日前",
|
||||
"smtp_address" => "SMTPアドレス",
|
||||
"port" => "ポート番号",
|
||||
"tls" => "TLS",
|
||||
"ssl" => "SSL",
|
||||
"smtp_username" => "SMTPユーザー名",
|
||||
"smtp_password" => "SMTPパスワード",
|
||||
"from_email" => "送信元アドレス (オプション)",
|
||||
|
||||
@ -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)",
|
||||
|
||||
@ -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)",
|
||||
|
||||
@ -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ı)",
|
||||
|
||||
@ -118,6 +118,8 @@ $i18n = [
|
||||
"days_before" => "天",
|
||||
"smtp_address" => "SMTP 地址",
|
||||
"port" => "端口",
|
||||
"tls" => "TLS",
|
||||
"ssl" => "SSL",
|
||||
"smtp_username" => "SMTP 用户名",
|
||||
"smtp_password" => "SMTP 密码",
|
||||
"from_email" => "发件人邮箱(可选)",
|
||||
|
||||
@ -111,6 +111,8 @@ $i18n = [
|
||||
"days_before" => "天",
|
||||
"smtp_address" => "SMTP 信箱地址",
|
||||
"port" => "連接埠",
|
||||
"tls" => "TLS",
|
||||
"ssl" => "SSL",
|
||||
"smtp_username" => "SMTP 使用者名稱",
|
||||
"smtp_password" => "SMTP 密碼",
|
||||
"from_email" => "寄件人信箱(可選)",
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
<?php
|
||||
$version = "v1.16.3";
|
||||
$version = "v1.17.0";
|
||||
?>
|
||||
12
migrations/000012.php
Normal file
12
migrations/000012.php
Normal file
@ -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"');
|
||||
}
|
||||
?>
|
||||
@ -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
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -743,7 +743,6 @@ label {
|
||||
}
|
||||
|
||||
.form-group-inline label {
|
||||
font-weight: 300;
|
||||
font-size: 16px;
|
||||
margin-bottom: 0px;
|
||||
margin-left: 0px;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user