Skip to content

Commit

Permalink
support for relays without authentication and encryption (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgon authored Dec 20, 2024
1 parent 37cad66 commit 153a6a4
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 39 deletions.
11 changes: 8 additions & 3 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,14 @@
class="one-third" value="<?= $settings['smtp_port'] ?>" />
</div>
<div class="form-group-inline">
<div>
<input type="radio" name="encryption" id="encryptionnone" value="none"
<?= empty($settings['encryption']) || $settings['encryption'] == "none" ? "checked" : "" ?> />
<label for="encryptionnone"><?= translate('none', $i18n) ?></label>
</div>
<div>
<input type="radio" name="encryption" id="encryptiontls" value="tls"
<?= empty($settings['encryption']) || $settings['encryption'] == "tls" ? "checked" : "" ?> />
<?= $settings['encryption'] == "tls" ? "checked" : "" ?> />
<label for="encryptiontls"><?= translate('tls', $i18n) ?></label>
</div>
<div>
Expand Down Expand Up @@ -245,7 +250,7 @@ class="one-third" value="<?= $settings['smtp_port'] ?>" />
}

// find unused upload logos

// Get all logos in the subscriptions table
$query = 'SELECT logo FROM subscriptions';
$stmt = $db->prepare($query);
Expand Down Expand Up @@ -396,4 +401,4 @@ class="one-third" value="<?= $settings['smtp_port'] ?>" />

<?php
require_once 'includes/footer.php';
?>
?>
16 changes: 11 additions & 5 deletions endpoints/cronjobs/sendcancellationnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,21 @@
$message .= $subscription['name'] . " for " . $subscription['price'] ."\n";
}

$smtpAuth = (isset($email["smtpUsername"]) && $email["smtpUsername"] != "") || (isset($email["smtpPassword"]) && $email["smtpPassword"] != "");

$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
$mail->isSMTP();

$mail->Host = $email['smtpAddress'];
$mail->SMTPAuth = true;
$mail->Username = $email['smtpUsername'];
$mail->Password = $email['smtpPassword'];
$mail->SMTPSecure = $email['encryption'];
$mail->SMTPAuth = $smtpAuth;
if ($smtpAuth) {
$mail->Username = $email['smtpUsername'];
$mail->Password = $email['smtpPassword'];
}
if ($email['encryption'] != "none") {
$mail->SMTPSecure = $email['encryption'];
}
$mail->Port = $email['smtpPort'];

$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
Expand Down Expand Up @@ -501,4 +507,4 @@

}

?>
?>
16 changes: 11 additions & 5 deletions endpoints/cronjobs/sendnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,21 @@ function getDaysText($days) {
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
}

$smtpAuth = (isset($email["smtpUsername"]) && $email["smtpUsername"] != "") || (isset($email["smtpPassword"]) && $email["smtpPassword"] != "");

$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
$mail->isSMTP();

$mail->Host = $email['smtpAddress'];
$mail->SMTPAuth = true;
$mail->Username = $email['smtpUsername'];
$mail->Password = $email['smtpPassword'];
$mail->SMTPSecure = $email['encryption'];
$mail->SMTPAuth = $smtpAuth;
if ($smtpAuth) {
$mail->Username = $email['smtpUsername'];
$mail->Password = $email['smtpPassword'];
}
if ($email['encryption'] != "none") {
$mail->SMTPSecure = $email['encryption'];
}
$mail->Port = $email['smtpPort'];

$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
Expand Down Expand Up @@ -711,4 +717,4 @@ function getDaysText($days) {

}

?>
?>
15 changes: 10 additions & 5 deletions endpoints/cronjobs/sendresetpasswordemails.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
$fromEmail = empty($admin['from_email']) ? '[email protected]' : $admin['from_email'];
$encryption = $admin['encryption'];
$server_url = $admin['server_url'];
$smtpAuth = (isset($admin["smtp_username"]) && $admin["smtp_username"] != "") || (isset($admin["smtp_password"]) && $admin["smtp_password"] != "");

require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';
require __DIR__ . '/../../libs/PHPMailer/SMTP.php';
Expand All @@ -38,10 +39,14 @@
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = $smtpAddress;
$mail->SMTPAuth = true;
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
$mail->SMTPSecure = $encryption;
$mail->SMTPAuth = $smtpAuth;
if ($smtpAuth) {
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
}
if ($encryption != "none") {
$mail->SMTPSecure = $encryption;
}
$mail->Port = $smtpPort;
$mail->setFrom($fromEmail);

Expand Down Expand Up @@ -86,4 +91,4 @@
exit();
}

?>
?>
15 changes: 10 additions & 5 deletions endpoints/cronjobs/sendverificationemails.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
$fromEmail = empty($admin['from_email']) ? '[email protected]' : $admin['from_email'];
$encryption = $admin['encryption'];
$server_url = $admin['server_url'];
$smtpAuth = (isset($admin["smtp_username"]) && $admin["smtp_username"] != "") || (isset($admin["smtp_password"]) && $admin["smtp_password"] != "");

require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';
require __DIR__ . '/../../libs/PHPMailer/SMTP.php';
Expand All @@ -45,10 +46,14 @@
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = $smtpAddress;
$mail->SMTPAuth = true;
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
$mail->SMTPSecure = $encryption;
$mail->SMTPAuth = $smtpAuth;
if ($smtpAuth) {
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
}
if ($encryption != "none") {
$mail->SMTPSecure = $encryption;
}
$mail->Port = $smtpPort;
$mail->setFrom($fromEmail);

Expand Down Expand Up @@ -92,4 +97,4 @@
exit();
}

?>
?>
6 changes: 2 additions & 4 deletions endpoints/notifications/saveemailnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

if (
!isset($data["smtpaddress"]) || $data["smtpaddress"] == "" ||
!isset($data["smtpport"]) || $data["smtpport"] == "" ||
!isset($data["smtpusername"]) || $data["smtpusername"] == "" ||
!isset($data["smtppassword"]) || $data["smtppassword"] == ""
!isset($data["smtpport"]) || $data["smtpport"] == ""
) {
$response = [
"success" => false,
Expand Down Expand Up @@ -86,4 +84,4 @@
}
}
}
?>
?>
25 changes: 15 additions & 10 deletions endpoints/notifications/testemailnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@

if (
!isset($data["smtpaddress"]) || $data["smtpaddress"] == "" ||
!isset($data["smtpport"]) || $data["smtpport"] == "" ||
!isset($data["smtpusername"]) || $data["smtpusername"] == "" ||
!isset($data["smtppassword"]) || $data["smtppassword"] == ""
!isset($data["smtpport"]) || $data["smtpport"] == ""
) {
$response = [
"success" => false,
"message" => translate('fill_all_fields', $i18n)
];
die(json_encode($response));
} else {
$enxryption = "tls";
$encryption = "none";
if (isset($data["encryption"])) {
$encryption = $data["encryption"];
}

$smtpAuth = (isset($data["smtpusername"]) && $data["smtpusername"] != "") || (isset($data["smtppassword"]) && $data["smtppassword"] != "");

require '../../libs/PHPMailer/PHPMailer.php';
require '../../libs/PHPMailer/SMTP.php';
require '../../libs/PHPMailer/Exception.php';
Expand All @@ -49,10 +49,15 @@
$mail->isSMTP();

$mail->Host = $smtpAddress;
$mail->SMTPAuth = true;
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
$mail->SMTPSecure = $encryption;
$mail->SMTPAuth = $smtpAuth;
if ($smtpAuth) {
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
}

if ($encryption != "none") {
$mail->SMTPSecure = $encryption;
}
$mail->Port = $smtpPort;

$getUser = "SELECT * FROM user WHERE id = 1";
Expand Down Expand Up @@ -84,10 +89,10 @@
"message" => translate('email_error', $i18n) . $e->getMessage()
];
}

die(json_encode($response));

}
}

?>
?>
9 changes: 7 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
</style>
<section class="contain settings">

<section class="account-section">
<header>
<h2><?= translate('monthly_budget', $i18n) ?></h2>
Expand Down Expand Up @@ -358,6 +358,11 @@ class="thin mobile-grow" />
class="one-third" value="<?= $notificationsEmail['smtp_port'] ?>" />
</div>
<div class="form-group-inline">
<div>
<input type="radio" name="encryption" id="encryptionnone" value="none"
<?= $notificationsEmail['encryption'] == "none" ? "checked" : "" ?> />
<label for="encryptionnone"><?= translate('none', $i18n) ?></label>
</div>
<div>
<input type="radio" name="encryption" id="encryptiontls" value="tls"
<?= $notificationsEmail['encryption'] == "tls" ? "checked" : "" ?> />
Expand Down Expand Up @@ -1224,4 +1229,4 @@ class="thin"><?= $settings['customCss'] ?? "" ?></textarea>

<?php
require_once 'includes/footer.php';
?>
?>

0 comments on commit 153a6a4

Please sign in to comment.