Add Turnstile protection and harden export workflow
This commit is contained in:
+29
-23
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/app.php';
|
||||
require_once "PHPMailer.php";
|
||||
require_once "SMTP.php";
|
||||
require_once "Exception.php";
|
||||
@@ -7,39 +9,43 @@ require_once "Exception.php";
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
|
||||
function sendEmail($emailAddress, $filename, $smtppassword)
|
||||
function sendEmail(string $emailAddress, string $downloadToken, string $smtpPassword): bool
|
||||
{
|
||||
$mail = new PHPMailer();
|
||||
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = 'mxe98c.netcup.net; mxe98c.netcup.net'; // Specify main and backup SMTP servers
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = 'info@silias.ch'; // SMTP username
|
||||
$mail->Password = $smtppassword; // SMTP password
|
||||
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
|
||||
$mail->Port = 465; // TCP port to connect to
|
||||
$mail->isSMTP();
|
||||
$mail->Host = app_env('SMTP_HOST', 'mxe98c.netcup.net');
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = app_env('SMTP_USERNAME', 'info@silias.ch');
|
||||
$mail->Password = $smtpPassword;
|
||||
$mail->SMTPSecure = app_env('SMTP_SECURE', 'ssl');
|
||||
$mail->Port = app_env_int('SMTP_PORT', 465, 1, 65535);
|
||||
$mail->CharSet = 'UTF-8';
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->setFrom('info@silias.ch', 'Silias Zefix Export');
|
||||
$mail->addAddress($emailAddress);
|
||||
$mail->addBCC('info@silias.ch');
|
||||
$bccAddress = app_env('EXPORT_BCC_EMAIL');
|
||||
if ($bccAddress !== '' && filter_var($bccAddress, FILTER_VALIDATE_EMAIL)) {
|
||||
$mail->addBCC($bccAddress);
|
||||
}
|
||||
$mail->addReplyTo('info@silias.ch', 'Silias KLG');
|
||||
$mail->Subject = 'Ihr Export von Zefix ist bereit';
|
||||
$mail->Body = 'Nutzen Sie den folgenden Link um ihre Daten herunterzuladen.<br><a href="https://zefix.silias.ch/'.$filename.'">https://zefix.silias.ch/'.$filename.'</a>';
|
||||
$downloadUrl = app_public_base_url() . '/download.php?token=' . rawurlencode($downloadToken);
|
||||
$escapedUrl = htmlspecialchars($downloadUrl, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
$retentionHours = app_env_int('DOWNLOAD_RETENTION_HOURS', 48, 1, 720);
|
||||
$mail->Body = 'Nutzen Sie den folgenden Link, um Ihre Daten herunterzuladen:<br><a href="' . $escapedUrl . '">' . $escapedUrl . '</a><br><br>Der Link ist ' . $retentionHours . ' Stunden gültig.';
|
||||
$mail->AltBody = "Nutzen Sie den folgenden Link, um Ihre Daten herunterzuladen:\n" . $downloadUrl . "\n\nDer Link ist " . $retentionHours . ' Stunden gültig.';
|
||||
|
||||
|
||||
if($mail->send()){
|
||||
$status = "success";
|
||||
$response = "Email is sent!";
|
||||
}
|
||||
else{
|
||||
$status = "failed";
|
||||
$response = "Something is wrong: <br>" . $mail->ErrorInfo;
|
||||
if ($smtpPassword === '') {
|
||||
error_log('SMTP password is not configured.');
|
||||
return false;
|
||||
}
|
||||
|
||||
echo "Email status:".$status;
|
||||
echo "Email Response:".$response;
|
||||
if (!$mail->send()) {
|
||||
error_log('Export email failed: ' . $mail->ErrorInfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user