| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,124 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+/** |
|
| 4 |
+ * @copyright 2024 Double Bastion LLC <www.doublebastion.com> |
|
| 5 |
+ * |
|
| 6 |
+ * @author Double Bastion LLC |
|
| 7 |
+ * |
|
| 8 |
+ * @license GNU AGPL version 3 or any later version |
|
| 9 |
+ * |
|
| 10 |
+ * This program is free software; you can redistribute it and/or |
|
| 11 |
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
| 12 |
+ * License as published by the Free Software Foundation; either |
|
| 13 |
+ * version 3 of the License, or any later version. |
|
| 14 |
+ * |
|
| 15 |
+ * This program is distributed in the hope that it will be useful, |
|
| 16 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 17 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 18 |
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
| 19 |
+ * |
|
| 20 |
+ * You should have received a copy of the GNU Affero General Public |
|
| 21 |
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 22 |
+ * |
|
| 23 |
+ */ |
|
| 24 |
+ |
|
| 25 |
+session_start(); |
|
| 26 |
+ |
|
| 27 |
+if (isset($_POST['verifyToken']) && ($_POST['verifyToken'] == $_SESSION['forgotpass_access'])) {
|
|
| 28 |
+ |
|
| 29 |
+define('ACCESSCONST', TRUE);
|
|
| 30 |
+ |
|
| 31 |
+require('db-connect.php');
|
|
| 32 |
+ |
|
| 33 |
+ $currentSentEmail = $_POST['emailforgot']; |
|
| 34 |
+ $currentMessage = $_POST['messageToUser']; |
|
| 35 |
+ |
|
| 36 |
+ if (($currentSentEmail != '') && ($currentMessage == '')) {
|
|
| 37 |
+ |
|
| 38 |
+ // Search the database for the specified email |
|
| 39 |
+ try {
|
|
| 40 |
+ $query0 = $mysqli->prepare("SELECT id, username, emailaddress FROM panelusers WHERE emailaddress=?");
|
|
| 41 |
+ $query0->bind_param("s", $currentSentEmail);
|
|
| 42 |
+ $query0->execute(); |
|
| 43 |
+ $fetchres = $query0->get_result(); |
|
| 44 |
+ $fetchData = $fetchres->fetch_row(); |
|
| 45 |
+ $query0->close(); |
|
| 46 |
+ |
|
| 47 |
+ if (empty($fetchData)) {
|
|
| 48 |
+ |
|
| 49 |
+ $result = 'failure'; |
|
| 50 |
+ $messageonrequest = "Your email address hasn't been found !"; |
|
| 51 |
+ |
|
| 52 |
+ } else {
|
|
| 53 |
+ |
|
| 54 |
+ /** |
|
| 55 |
+ * Send the verification email |
|
| 56 |
+ */ |
|
| 57 |
+ |
|
| 58 |
+ // Generate a random string to be used as the termination of the verification link |
|
| 59 |
+ function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
|
|
| 60 |
+ $pieces = []; |
|
| 61 |
+ $max = mb_strlen($keyspace, '8bit') - 1; |
|
| 62 |
+ |
|
| 63 |
+ for ($i = 0; $i < $length; ++$i) {
|
|
| 64 |
+ $pieces []= $keyspace[random_int(0, $max)]; |
|
| 65 |
+ } |
|
| 66 |
+ return implode('', $pieces);
|
|
| 67 |
+ } |
|
| 68 |
+ |
|
| 69 |
+ $token = random_str(55); |
|
| 70 |
+ |
|
| 71 |
+ // Update the appropriate fields for the user having the given email address |
|
| 72 |
+ $initPassword = random_str(14); |
|
| 73 |
+ $newPassword = password_hash($initPassword, PASSWORD_DEFAULT); |
|
| 74 |
+ |
|
| 75 |
+ $userID = $fetchData[0]; |
|
| 76 |
+ |
|
| 77 |
+ $query1 = $mysqli->query("UPDATE panelusers SET password = '$newPassword', registered = '0', token = '$token', temporary = '$initPassword' WHERE id = '$userID'");
|
|
| 78 |
+ |
|
| 79 |
+ // Create the verification email |
|
| 80 |
+ $verificationLink = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . "/forgotpass-verification.php?token=" . $token; |
|
| 81 |
+ |
|
| 82 |
+ $domaininit = explode(".", $_SERVER['HTTP_HOST']);
|
|
| 83 |
+ array_shift($domaininit); |
|
| 84 |
+ $domain = implode(".", $domaininit);
|
|
| 85 |
+ |
|
| 86 |
+ $headers = "MIME-Version: 1.0" . "\r\n"; |
|
| 87 |
+ $headers .= "Content-type: text/html; charset=UTF-8" . "\r\n"; |
|
| 88 |
+ |
|
| 89 |
+ $headers .= "From: " . "no-reply@" . $domain . "\r\n"; |
|
| 90 |
+ |
|
| 91 |
+ $subject = "RED SCARF Suite Panel email address verification"; |
|
| 92 |
+ |
|
| 93 |
+ $message = "Hello, <br><br> |
|
| 94 |
+ We have received your request related to regaining access to your account. Please verify your email address by clicking on |
|
| 95 |
+ the link below: <br><br> |
|
| 96 |
+ <a href='".$verificationLink."'>".$verificationLink."</a><br><br> |
|
| 97 |
+ Alternatively, you can copy the link and paste it in the address bar of your browser.<br><br> |
|
| 98 |
+ After email address verification you will receive a new email with further instructions.<br><br> |
|
| 99 |
+ Thank you,<br> |
|
| 100 |
+ RED SCARF Suite Panel<br> |
|
| 101 |
+ Host: '" . $_SERVER['HTTP_HOST'] . "'"; |
|
| 102 |
+ |
|
| 103 |
+ // Send the email |
|
| 104 |
+ mail($currentSentEmail, $subject, $message, $headers); |
|
| 105 |
+ |
|
| 106 |
+ $result = 'success'; |
|
| 107 |
+ $messageonrequest = "An email has been sent to your email address. Please follow the instructions in the received email to regain access to your |
|
| 108 |
+ panel account."; |
|
| 109 |
+ } |
|
| 110 |
+ |
|
| 111 |
+ } catch (mysqli_sql_exception $e) {
|
|
| 112 |
+ $result = 'failure'; |
|
| 113 |
+ $messageonrequest = "An error occurred while processing your request. You can try sending your request again after a few moments !"; |
|
| 114 |
+ } |
|
| 115 |
+ |
|
| 116 |
+ $reqresponse = array('result' => $result, 'messageonrequest' => $messageonrequest);
|
|
| 117 |
+ echo json_encode($reqresponse); |
|
| 118 |
+ } |
|
| 119 |
+ |
|
| 120 |
+} else {
|
|
| 121 |
+ header("Location: panel-login.php");
|
|
| 122 |
+} |
|
| 123 |
+ |
|
| 124 |
+?> |