{= # # # delete_profile.cfv # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.get_web_server_root_path"; include "templates.admin_pages.profiles.delete_profile_util"; include "templates.util.profiles.get_profile_data_util"; include "templates.util.backup_util"; debug_message("\n\n#### delete_profile.cfv \n\n"); debug_message("\n" . node_as_string("v.fp") . "\n"); string session_id = volatile.session_id; bool is_valid_profile = v.fp.is_valid_profile; string profile_name = v.fp.profile_name; string page_token = v.fp.page_token; bool drop_database = v.fp.drop_database; string version = v.fp.version; # Make sure the user has permission to delete this profile bool is_delete_permission = get_is_delete_profile_permission(profile_name); if (is_delete_permission and get_is_valid_page_token(session_id, "profiles", page_token)) then ( bool is_root_admin = get_is_root_admin(); string user_node_name = node_name(volatile.authenticated_user_node_path); string client_profiles_list_checksum = v.fp.profiles_list_checksum; node profiles = "profiles"; string task_id; string active_task_message; # string profiles_dat; # int number_of_all_profiles; string profile_changes_dat; if (profiles?{profile_name}) then ( # Create a backup of the profile in backup/deleted_profiles backup_profile_in_deleted_profiles_backup(profile_name); # Get profiles checksum before the profile becomes deleted! string profiles_list_checksum_before_profile_modification = get_profiles_list_checksum(session_id, is_root_admin, user_node_name); if (is_valid_profile or version eq "8.0") then ( debug_message("#### delete_profile.cfv - profile_name: " . profile_name . "\n"); node database_server = profiles{profile_name}{"database"}{"options"}{"server"}; string database_type = @database_server{"type"}; string database_name = @database_server{"database_name"}; # If no database_name is defined then the database_name is the profile_name if (database_name eq "") then ( database_name = profile_name; ); debug_message("#### delete_profile.cfv - database_type: " . database_type . "\n"); debug_message("#### delete_profile.cfv - database_name: " . database_name . "\n"); string lai_dir = LOGANALYSISINFO_DIRECTORY; string web_server_root_dir = get_web_server_root_path(); node user; # Delete the profile # Note, erase_database() and drop database # requires the profile node! # # # Delete the database # # if (database_type eq "internal_sql" or database_type eq "odbc_oracle") then ( # Erase the database before deleting the profile node because # the profile node is required by erase_database(). erase_database(profile_name); ) else ( # Delete database directory in # LogAnalysisInfo/Databases/profile_name regardless # if DROP DATABASE is checked. # If DROP DATABASE is checked we delete that directory # before we drop the SQL database so that any error in # DROP DATABASE doesn't prevent deletion of that directory. delete_database_directory(profile_name); if (drop_database) then ( # Drop the MySQL or MS SQL database. Note, drop database is optional, # it must be checked/unchecked by the user upon profile deletion. # Drop database could take longer, depending on the system and database size, # so we start a new process which doesn't halt the response. We will also delete # the profile file, regardless of the drop database deletion state. # Deletion of database directory in # LogAnalysisInfo/Databases/profile_name is handled # delete_database.cvf string cmd = ""; v.options.1 = "background"; v.options.2 = "-dp"; v.options.3 = "templates.admin_pages.profiles.delete_database"; v.options.4 = "-p"; v.options.5 = profile_name; v.options.6 = "volatile.database_name"; v.options.7 = database_name; v.options.8 = "volatile.session_id"; v.options.9 = session_id; v.options.10 = "volatile.page_token"; v.options.11 = page_token; string task_id = exec(cmd, "v.options", false); # Give above process some time to make sure the profile is loaded # before we delete the profile file. sleep_milliseconds(1500); ); ); # # Delete the profile # if (!drop_database) then ( # Delete the profile node delete_node(profiles{profile_name}); ) else ( # A separate DROP Database process is active. # Don't delete the profile node but the profile file because # the profile node, which is in memory, may still be required # by DROP DATABASE ... in database_sql_query() handle_delete_profile_by_pathname(lai_dir . "profiles/" . profile_name . ".cfg"); # Set active task message volatile.param1 = database_name; if (database_type eq "mysql") then ( active_task_message = expand(lang_admin.profiles.deleting_mysql_database); ) else ( active_task_message = expand(lang_admin.profiles.deleting_mssql_database); ); ); # Get profile_changes_dat profile_changes_dat = get_profiles_list_data_after_profiles_changes( session_id, is_root_admin, user_node_name, client_profiles_list_checksum, profiles_list_checksum_before_profile_modification, profile_name, "delete_profile"); # # # Delete caches and dependencies # # # The deleted profile has to be handled/removed in: # - schedule.cfg # - users.cfg # - filters_cache/profile_name # - profiles_cache/profile_name # - users_cache/user_node_name/profiles/profile_name # - WebServerRoot/csv_export/username/profile_name # - WebServerRoot/graphs/profile_name # - profiles_dashboard.cfg # # # Handle schedule handle_delete_profile_in_schedule(profile_name); # Handle users handle_delete_profile_in_users(profile_name); # Handle filters_cache handle_delete_profile_by_pathname(lai_dir . "filters_cache/" . profile_name); # Handle profiles_cache handle_delete_profile_by_pathname(lai_dir . "profiles_cache/" . profile_name); # Handle WebServerRoot/graphs/ handle_delete_profile_by_pathname(web_server_root_dir . "graphs/" . profile_name); # # Handle delete per user items (users_cache and WebServerRoot/csv_export/) # foreach user "users" ( user_node_name = node_name(user); # Handle users_cache handle_delete_profile_by_pathname(lai_dir . "users_cache/" . user_node_name . "/profiles/" . profile_name); # Handle WebServerRoot/csv_export/ handle_delete_profile_by_pathname(web_server_root_dir . "csv_export/" . user_node_name . "/" . profile_name); ); # # Handle delete profile in profiles_dashboard # handle_delete_profile_in_profiles_dashboard(profile_name); ) else ( # This is an invalid version 7 profile, we just delete the profile. delete_node(profiles{profile_name}); # Get profile_changes_dat profile_changes_dat = get_profiles_list_data_after_profiles_changes( session_id, is_root_admin, user_node_name, client_profiles_list_checksum, profiles_list_checksum_before_profile_modification, profile_name, "delete_profile"); ); # Delete backup files (this is different from backup/deleted_profiles) delete_backup_files("profiles/" . profile_name); ) else ( # TODO, the profile does not anymore exist! # Show an error? ); # # # Get fresh profile data # # string dat = "{"; # dat .= add_json("profilesDb", profiles_dat, "obj"); # dat .= add_json("numberOfAllProfiles", number_of_all_profiles, "int"); dat .= add_json("profileChanges", profile_changes_dat, "obj"); dat .= add_json("dropDatabase", drop_database, "bool"); dat .= add_json("taskId", task_id, "string"); dat .= add_json("activeTaskMessage", active_task_message, "string"); dat = close_json(dat); # # # Send response # # 'deleteProfile.deleteProfileResponse(' . dat . ')'; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); debug_message("#### delete_profile.cfv END \n\n"); =}