diff --git a/ajax.php b/ajax.php index 1841be1c..8d6265c7 100644 --- a/ajax.php +++ b/ajax.php @@ -194,4 +194,49 @@ if(isset($_GET['ticket_query_views'])){ $response['message'] = ""; } echo json_encode($response); +} + +/* + * Generates public/guest links for sharing logins/docs + */ +if(isset($_GET['share_generate_link'])){ + $client_id = intval($_GET['client_id']); + $item_type = trim(strip_tags(mysqli_real_escape_string($mysqli,$_GET['type']))); + $item_id = intval($_GET['id']); + $item_note = trim(strip_tags(mysqli_real_escape_string($mysqli,$_GET['note']))); + $item_view_limit = intval($_GET['views']); + $item_expires = trim(strip_tags(mysqli_real_escape_string($mysqli,$_GET['expires']))); + $item_key = keygen(); + + if($item_type == "Login"){ + $login = mysqli_query($mysqli, "SELECT login_password FROM logins WHERE login_id = '$item_id' AND login_client_id = '$client_id' LIMIT 1"); + $row = mysqli_fetch_array($login); + + $login_password_cleartext = decryptLoginEntry($row['login_password']); + $login_encryption_key = keygen(); + $iv = keygen(); + $ciphertext = openssl_encrypt($login_password_cleartext, 'aes-128-cbc', $login_encryption_key, 0, $iv); + + $item_encrypted_credential = $iv . $ciphertext; + } + else{ + $item_encrypted_credential = ''; + } + + // 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_credential = '$item_encrypted_credential', item_note = '$item_note', item_views = 0, item_view_limit = '$item_view_limit', item_created_at = NOW(), item_expire_at = '$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"; + } + else{ + $url = "$config_base_url/guest_view_item.php?id=$share_id&key=$item_key"; + } + 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 ID: $item_id', log_client_id = '$client_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_created_at = NOW(), log_user_id = $session_user_id, company_id = $session_company_id"); + } \ No newline at end of file diff --git a/client_routes.php b/client_routes.php index 0a2e87a2..c3c4d505 100644 --- a/client_routes.php +++ b/client_routes.php @@ -102,6 +102,11 @@ if(isset($_GET['tab'])){ elseif($_GET['tab'] == "logs"){ include("client_logs.php"); } + elseif($_GET['tab'] == "shared-items"){ + if($session_user_role > 1){ + include("client_shared_items.php"); + } + } } else{ include("client_overview.php"); diff --git a/client_shared_items.php b/client_shared_items.php new file mode 100644 index 00000000..ee1c5fa6 --- /dev/null +++ b/client_shared_items.php @@ -0,0 +1,152 @@ + $sb, 'o' => $o))); + +$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM shared_items + WHERE item_client_id = $client_id + AND item_active = '1' + AND item_views != item_view_limit + AND item_expire_at > NOW() + AND (item_note LIKE '%$q%') ORDER BY $sb $o LIMIT $record_from, $record_to"); + +$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); + +?> + +
| Item Name | +Item Type | +Share Note | +Views | +Expires | +Action | +
|---|---|---|---|---|---|
| + | + | + | + | + |
+
+
+
+
+
+
+ |
+
Shared Links
+ +