From 873df63c76c0eb3e093eed82b5dff5470f28dbdf Mon Sep 17 00:00:00 2001 From: johnnyq Date: Wed, 30 Oct 2024 14:40:02 -0400 Subject: [PATCH] FEATURE: Added Credential Tagging Support --- admin_tag.php | 2 ++ admin_tag_add_modal.php | 1 + admin_tag_edit_modal.php | 1 + client_login_add_modal.php | 21 +++++++++++ client_login_edit_modal.php | 21 +++++++++++ client_logins.php | 70 ++++++++++++++++++++++++++++++++++--- post/user/credential.php | 18 ++++++++++ 7 files changed, 130 insertions(+), 4 deletions(-) diff --git a/admin_tag.php b/admin_tag.php index faf50495..2ac68281 100644 --- a/admin_tag.php +++ b/admin_tag.php @@ -76,6 +76,8 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $tag_type_display = "Location Tag"; } elseif ( $tag_type == 3) { $tag_type_display = "Contact Tag"; + } elseif ( $tag_type == 4) { + $tag_type_display = "Credential Tag"; } else { $tag_type_display = "Unknown Tag"; } diff --git a/admin_tag_add_modal.php b/admin_tag_add_modal.php index 5cd0705c..4406de2e 100644 --- a/admin_tag_add_modal.php +++ b/admin_tag_add_modal.php @@ -32,6 +32,7 @@ + diff --git a/admin_tag_edit_modal.php b/admin_tag_edit_modal.php index f0fb9574..80f3df07 100644 --- a/admin_tag_edit_modal.php +++ b/admin_tag_edit_modal.php @@ -32,6 +32,7 @@ + diff --git a/client_login_add_modal.php b/client_login_add_modal.php index 43e426b4..0afd75e1 100644 --- a/client_login_add_modal.php +++ b/client_login_add_modal.php @@ -228,6 +228,27 @@ +
+ +
+
+ +
+ +
+
+ diff --git a/client_login_edit_modal.php b/client_login_edit_modal.php index a89ac4cf..8731cb1e 100644 --- a/client_login_edit_modal.php +++ b/client_login_edit_modal.php @@ -233,6 +233,27 @@ +
+ +
+
+ +
+ +
+
+ diff --git a/client_logins.php b/client_logins.php index ae2370e7..07f953a6 100644 --- a/client_logins.php +++ b/client_logins.php @@ -12,6 +12,21 @@ enforceUserPermission('module_credential'); // Log when users load the Credentials/Logins page mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Credential', log_action = 'View', log_description = '$session_name viewed the Credentials page for client', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id"); +// Tags Filter +if (isset($_GET['tags']) && is_array($_GET['tags']) && !empty($_GET['tags'])) { + // Sanitize each element of the status array + $sanitizedTags = array(); + foreach ($_GET['tags'] as $tag) { + // Escape each status to prevent SQL injection + $sanitizedTags[] = "'" . intval($tag) . "'"; + } + + // Convert the sanitized tags into a comma-separated string + $sanitizedTagsString = implode(",", $sanitizedTags); + $tag_query = "AND tags.tag_id IN ($sanitizedTagsString)"; +} else { + $tag_query = ''; +} // Location Filter if (isset($_GET['location']) & !empty($_GET['location'])) { @@ -31,10 +46,13 @@ $url_query_strings_sort = http_build_query($get_copy); $sql = mysqli_query( $mysqli, - "SELECT SQL_CALC_FOUND_ROWS * + "SELECT SQL_CALC_FOUND_ROWS l.login_id AS l_login_id, l.*, login_tags.*, tags.* FROM logins l + LEFT JOIN login_tags ON login_tags.login_id = l.login_id + LEFT JOIN tags ON tags.tag_id = login_tags.tag_id $location_query_innerjoin WHERE l.login_client_id = $client_id + $tag_query AND l.login_$archive_query AND (l.login_name LIKE '%$q%' OR l.login_description LIKE '%$q%' OR l.login_uri LIKE '%$q%') $location_query @@ -104,7 +122,23 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); -
+
+
+ +
+
+ +
"> @@ -172,7 +206,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $login_tag_name"; + } + $login_tags_display = implode('', $login_tag_name_display_array); + // Check if shared $sql_shared = mysqli_query( $mysqli, @@ -246,8 +302,14 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
--
+ +
+ +
+
diff --git a/post/user/credential.php b/post/user/credential.php index 6cd7c5eb..2fc0ca37 100644 --- a/post/user/credential.php +++ b/post/user/credential.php @@ -14,6 +14,14 @@ if (isset($_POST['add_login'])) { $login_id = mysqli_insert_id($mysqli); + // Add Tags + if (isset($_POST['tags'])) { + foreach($_POST['tags'] as $tag) { + $tag = intval($tag); + mysqli_query($mysqli, "INSERT INTO login_tags SET login_id = $login_id, tag_id = $tag"); + } + } + // Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Credential', log_action = 'Create', log_description = '$session_name created login $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $login_id"); @@ -42,6 +50,16 @@ if (isset($_POST['edit_login'])) { // Update the login entry with the new details mysqli_query($mysqli,"UPDATE logins SET login_name = '$name', login_description = '$description', login_uri = '$uri', login_uri_2 = '$uri_2', login_username = '$username', login_password = '$password', login_otp_secret = '$otp_secret', login_note = '$note', login_important = $important, login_contact_id = $contact_id, login_vendor_id = $vendor_id, login_asset_id = $asset_id, login_software_id = $software_id WHERE login_id = $login_id"); + // Tags + // Delete existing tags + mysqli_query($mysqli, "DELETE FROM login_tags WHERE login_id = $login_id"); + + // Add new tags + foreach($_POST['tags'] as $tag) { + $tag = intval($tag); + mysqli_query($mysqli, "INSERT INTO login_tags SET login_id = $login_id, tag_id = $tag"); + } + // Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Credential', log_action = 'Modify', log_description = '$session_name modified login $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $login_id");