From 2b7d3e5d2a8811c2b1f011091675403dbbf6325d Mon Sep 17 00:00:00 2001 From: James Pattinson Date: Fri, 7 Mar 2025 18:38:47 +0000 Subject: [PATCH] Email PPR --- cancelppr.php | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ functions.php | 36 ++++++++++- newppr.php | 52 ++++++++++++++- 3 files changed, 255 insertions(+), 3 deletions(-) create mode 100644 cancelppr.php diff --git a/cancelppr.php b/cancelppr.php new file mode 100644 index 0000000..ca8ea6a --- /dev/null +++ b/cancelppr.php @@ -0,0 +1,170 @@ + + + + + + + + Row Details + + + + +query($sql); + + if ($result->num_rows > 0) { + // Output data of the row + $row = $result->fetch_assoc(); + echo '
'; + echo '

Aircraft Reg: ' . $row['ac_reg'] . "

"; + echo "

Aircraft Type: " . $row['ac_type'] . "

"; + echo "

Callsign: " . $row['ac_call'] . "

"; + echo "

Captain's Name: " . $row['captain'] . "

"; + echo "

Arriving From: " . $row['in_from'] . "

"; + echo "

POB IN: " . $row['pob_in'] . "

"; + echo "

ETA: " . $row['eta'] . "

"; + + echo "

Fuel Required: " . $row['fuel'] . "

"; + + echo "

POB OUT: " . $row['pob_out'] . "

"; + echo "

Outbound To: " . $row['out_to'] . "

"; + echo "

ETD: " . $row['etd'] . "

"; + + echo "

Email Address: " . $row['email'] . "

"; + echo "

Phone: " . $row['phone'] . "

"; + + echo "

Notes: " . $row['notes'] . "

"; + + } else { + echo "No details found for the given ID."; + } + + $conn->close(); + + echo ''; + +} + +?> + + + + + + + + diff --git a/functions.php b/functions.php index 9c68543..2050442 100644 --- a/functions.php +++ b/functions.php @@ -90,4 +90,38 @@ function require_auth() { echo 'Text to send if user hits Cancel button'; exit; } -} \ No newline at end of file +} + +function generateSecureToken($email, $entryId) { + $secretKey = "your-very-secret-key"; // Use an environment variable for this + $timestamp = time(); + $data = "$email|$entryId|$timestamp"; + $hash = hash_hmac('sha256', $data, $secretKey); + return base64_encode("$data|$hash"); +} + + +function validateSecureToken($token) { + $secretKey = "your-very-secret-key"; + $decoded = base64_decode($token); + + if (!$decoded) return false; + + list($email, $entryId, $timestamp, $hash) = explode('|', $decoded); + + // Check expiration (e.g., valid for 1 hour) + if (time() - $timestamp > 3600) { + return false; + } + + // Verify hash + $data = "$email|$entryId|$timestamp"; + $validHash = hash_hmac('sha256', $data, $secretKey); + + if (!hash_equals($validHash, $hash)) { + return false; + } + + return ['email' => $email, 'entryId' => $entryId]; +} + diff --git a/newppr.php b/newppr.php index b7eddae..cb8aa26 100644 --- a/newppr.php +++ b/newppr.php @@ -1,4 +1,10 @@ query($sql) === TRUE) { - echo "

Data successfully inserted into database.

"; - echo ''; + $lastId = $conn->insert_id; + echo "

Data successfully inserted into database with id = " . $lastId . "

"; + if (!empty($_POST['email'])) { + echo "Email is set to " . $_POST['email']; + generatePprEmail($lastId); + } else { + echo "Username is not set."; + } + + //echo ''; } else { echo "

Error inserting data: " . $conn->error . "

"; } @@ -32,5 +46,39 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { echo "

No POST data received.

"; } +function generatePprEmail($entryId) { + $token = generateSecureToken($_POST['email'], $entryId); + $secureLink = "https://ppr.swansea-airport.wales/dev/cancelppr.php?op=view&token=" . urlencode($token); + echo $secureLink; + + $mail = new PHPMailer(true); + + try { + $mail->isSMTP(); + $mail->Host = 'send.one.com'; // Your SMTP server + $mail->SMTPAuth = true; + $mail->Username = 'noreply@swansea-airport.wales'; + $mail->Password = 'SASAGoForward2155'; + $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; + $mail->Port = 465; + + $mail->setFrom('noreply@swansea-airport.wales', 'Swansea Airport'); + $mail->addAddress($_POST['email']); + + $mail->isHTML(true); + $mail->Subject = "Edit Your Entry"; + $mail->Body = " +

Click the button below to edit your entry securely:

+ Edit Entry + "; + + $mail->send(); + echo "Email sent successfully!"; + } catch (Exception $e) { + echo "Email sending failed: {$mail->ErrorInfo}"; + } + +} + ?>