# # # # # rename_profile_util.cfv # # rename_profile_database() # # # # rename_profile_directory_path() # handle_rename_profile_dependencies_in_users() # handle_rename_profile_dependencies() # # # # # # # rename_profile_database() # # # subroutine(rename_profile_database( string source_profile_name, string new_profile_name), ( # This renames the profile database directory in LogAnalsysisInfo/Databases/profile_name # for internal and external databases. # Already built external databases (MySQL, etc.) are not renamed. debug_message("\n\n#### rename_profile_database() START \n"); string source_database_path = LOGANALYSISINFO_DIRECTORY . "/Databases/" . source_profile_name; if (file_exists(source_database_path)) then ( # We move the Sawmill database directory (also for external databases) from source_profile_name # to new_profile_name directory. Note, the database_name is not relevant for LogAnalysisInfo/Databases/profile_name, # we always use the profile_name. debug_message("#### source_database_path EXISTS \n"); string new_database_path = LOGANALYSISINFO_DIRECTORY . "/Databases/" . new_profile_name; # # Move files # move_file(source_database_path, new_database_path); ); debug_message("#### rename_profile_database() END \n\n"); )); # # # # rename_profile_directory_path() # # # subroutine(rename_profile_directory_path( string sub_path, string source_profile_name, string new_profile_name), ( string source_path = LOGANALYSISINFO_DIRECTORY . "/" . sub_path . "/" . source_profile_name; if (file_exists(source_path)) then ( string new_path = LOGANALYSISINFO_DIRECTORY . "/" . sub_path . "/" . new_profile_name; move_file(source_path, new_path); ); )); # # # # handle_rename_profile_dependencies_in_users() # # # subroutine(handle_rename_profile_dependencies_in_users( string source_profile_name, string new_profile_name), ( # This handles rename profile dependencies in user.cfg and in LogAnalysisInfo/users_cache node user_item; string user_node_name; string users_cache_path; node access; node access_item; node user_profiles; node profile_item; string profile_name; bool is_renamed_profile_in_users = false; foreach user_item "users" ( user_node_name = node_name(user_item); # # Handle profiles in LAI/users_cache # users_cache_path = "users_cache/" . user_node_name . "/profiles"; rename_profile_directory_path(users_cache_path, source_profile_name, new_profile_name); # # Handle profiles in user_node_name.access.profiles node # if (user_item?{"access"}) then ( access = user_item{"access"}; foreach access_item access ( if (access_item?{"profiles"}) then ( user_profiles = access_item{"profiles"}; foreach profile_item user_profiles ( profile_name = @profile_item; if (profile_name eq source_profile_name) then ( # Rename source_profile_name to new_profile_name @profile_item = new_profile_name; is_renamed_profile_in_users = true; ); ); ); ); ); ); if (is_renamed_profile_in_users) then ( # Save the changes in users.cfg save_node("users"); ); )); # # # # handle_rename_profile_dependencies_in_schedule() # # # subroutine(handle_rename_profile_dependencies_in_schedule( string source_profile_name, string new_profile_name), ( # This handles rename profile dependencies in schedule.cfg node schedule_item; node action_item; node actions; string profile_name; bool profile_is_pattern; bool is_renamed_profile_in_schedule = false; foreach schedule_item "schedule" ( if (schedule_item?{"actions"}) then ( actions = schedule_item{"actions"}; foreach action_item actions ( profile_is_pattern = @action_item{"profile_is_pattern"}; if (!profile_is_pattern) then ( if (@action_item{"profile"} eq source_profile_name) then ( # Rename source_profile_name to new_profile_name @action_item{"profile"} = new_profile_name; is_renamed_profile_in_schedule = true; ); ); ); ); ); if (is_renamed_profile_in_schedule) then ( # Save the changes in schedule.cfg save_node("schedule"); ); )); # # # # handle_rename_profile_dependencies() # # # subroutine(handle_rename_profile_dependencies( string source_profile_name, string new_profile_name), ( # # Handle filters_cache # rename_profile_directory_path("filters_cache", source_profile_name, new_profile_name); # # Handle profiles_cache # rename_profile_directory_path("profiles_cache", source_profile_name, new_profile_name); # # Handle sessions_cache # string profile_sessions_path = "sessions_cache/" . volatile.session_id . "/profiles"; rename_profile_directory_path(profile_sessions_path, source_profile_name, new_profile_name); # # Handle users.cfg and users_cache # handle_rename_profile_dependencies_in_users(source_profile_name, new_profile_name); # # Handle schedule.cfg # handle_rename_profile_dependencies_in_schedule(source_profile_name, new_profile_name); ));