diff --git a/ajax.php b/ajax.php index 625fa529..1fac541c 100644 --- a/ajax.php +++ b/ajax.php @@ -230,6 +230,7 @@ if (isset($_GET['share_generate_link'])) { $client_id = intval($_GET['client_id']); $item_type = sanitizeInput($_GET['type']); $item_id = intval($_GET['id']); + $item_email = sanitizeInput($_GET['contact_email']); $item_note = sanitizeInput($_GET['note']); $item_view_limit = intval($_GET['views']); $item_expires = sanitizeInput($_GET['expires']); @@ -266,18 +267,38 @@ if (isset($_GET['share_generate_link'])) { } // Insert entry into DB - $sql = mysqli_query($mysqli, "INSERT INTO shared_items SET item_active = 1, item_key = '$item_key', item_type = '$item_type', item_related_id = $item_id, item_encrypted_username = '$item_encrypted_username', item_encrypted_credential = '$item_encrypted_credential', item_note = '$item_note', item_views = 0, item_view_limit = $item_view_limit, item_expire_at = '$item_expires', item_client_id = $client_id"); + $sql = mysqli_query($mysqli, "INSERT INTO shared_items SET item_active = 1, item_key = '$item_key', item_type = '$item_type', item_related_id = $item_id, item_encrypted_username = '$item_encrypted_username', item_encrypted_credential = '$item_encrypted_credential', item_note = '$item_note', item_views = 0, item_view_limit = $item_view_limit, item_expire_at = NOW() + INTERVAL + $item_expires, item_client_id = $client_id"); $share_id = $mysqli->insert_id; // Return URL if ($item_type == "Login") { - $url = "$config_base_url/guest_view_item.php?id=$share_id&key=$item_key&ek=$login_encryption_key"; + $url = "https://$config_base_url/guest_view_item.php?id=$share_id&key=$item_key&ek=$login_encryption_key"; } else { - $url = "$config_base_url/guest_view_item.php?id=$share_id&key=$item_key"; + $url = "https://$config_base_url/guest_view_item.php?id=$share_id&key=$item_key"; } + + // Send user e-mail, if specified + if(!empty($config_smtp_host) && filter_var($item_email, FILTER_VALIDATE_EMAIL)){ + + $subject = "Time sensitive encrypted link enclosed"; + $body = "Hello,

$session_name from $session_company_name sent you a time sensitive encrypted link which will expire in $item_expires and may only be viewed $item_view_limit times, before the link is destroyed. The sender will recieved a notification when the link is viewed. Please click the link below to view your shared secret

Click Here

~
$session_company_name
Support Department
$config_ticket_from_email"; + + $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port, + $config_ticket_from_email, $config_ticket_from_name, + $item_email, $item_email, + $subject, $body); + + if ($mail !== true) { + mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $item_email'"); + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $item_email regarding $subject. $item_mail', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id"); + } + + } + echo json_encode($url); + // Logging mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Sharing', log_action = 'Create', log_description = '$session_name created shared link for $item_type - $item_name', log_client_id = $client_id, log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id"); diff --git a/js/share_modal.js b/js/share_modal.js index 55637119..9adbce4b 100644 --- a/js/share_modal.js +++ b/js/share_modal.js @@ -21,13 +21,14 @@ function generateShareLink() { let item_note = document.getElementById("share_note").value; let item_views = document.getElementById("share_views").value; let item_expires = document.getElementById("share_expires").value; + let contact_email = document.getElementById("share_email").value; // Check values are provided if (item_views && item_expires && item_note) { // Send a GET request to ajax.php as ajax.php?share_generate_link=true.... jQuery.get( "ajax.php", - {share_generate_link: 'true', client_id: client_id, type: item_type, id: item_ref_id, note: item_note ,views: item_views, expires: item_expires}, + {share_generate_link: 'true', client_id: client_id, type: item_type, id: item_ref_id, note: item_note ,views: item_views, expires: item_expires, contact_email}, function(data) { // If we get a response from ajax.php, parse it as JSON diff --git a/share_modal.php b/share_modal.php index 082a6b2a..26420ac1 100644 --- a/share_modal.php +++ b/share_modal.php @@ -32,16 +32,43 @@
- +
- + +
+
+ +
+ +
-

Note: Logins are shared "as is" and will not update

+
+ +

@@ -55,7 +82,7 @@