{= # # # log_source/save_data.cfv # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.backup_util"; include "templates.util.profiles.get_profile_data_util"; debug_message("\n\n#### log_source/save_data.cfv \n"); string profile_name = internal.profile_name; string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); string page_token = v.fp.page_token; # # Check RBAC permissions # if ((is_root_admin or get_config_feature_permission(session_id, profile_name, "log_source", "edit")) and get_is_valid_page_token(session_id, "log_source", page_token)) then ( debug_message("\n" . node_as_string("v.fp") . "\n"); string user_node_name = node_name(volatile.authenticated_user_node_path); string client_profiles_list_checksum = v.fp.profiles_list_checksum; # Get profiles checksum before the profile becomes saved! string profiles_list_checksum_before_profile_modification = get_profiles_list_checksum(session_id, is_root_admin, user_node_name); node profile = "profiles." . profile_name; node log = profile{"log"}; node new_log_source = "v.fp.source"; node item; node server_item; string password; # # # Delete existing log sourc # # if (log?{"source"}) then ( delete_node(log{"source"}); ); # debug_message("\n#### log_source after deleting existsing sources:\n" . node_as_string(log) . "\n"); # # # Handle new log source # # int number_new_log_sources = num_subnodes(new_log_source); if (number_new_log_sources > 0) then ( if (number_new_log_sources > 1) then ( # Sort new log source by position node sort(new_log_source, "field:position,integer,ascending"); ); # debug_message("\n#### new_log_source after sort():\n" . node_as_string(new_log_source) . "\n"); # Encrypt passwords, if any, and # remove position nodes foreach item new_log_source ( # Handle FTP and SFTP password if (item?{"password"} and @item{"password"} ne "") then ( password = @item{"password"}; # Encrypt the password @item{"password"} = format(password, "!encrypt"); ) # else handle MS SQL ODBC and Oracle ODBC password else if (item?{"server"}) then ( server_item = item{"server"}; if (@server_item{"password"} ne "") then ( password = @server_item{"password"}; # Encrypt the password @server_item{"password"} = format(password, "!encrypt"); ); ); # Remove position node delete_node(item{"position"}); ); # Clone new log source to profile clone_node(new_log_source, log{"source"}); ); # # # Save profile # # # KHP 08/Aug/2013 - Changed save_node() to save_and_backup_profile() # save_node(profile); save_and_backup_profile(profile_name, profile); # Get profile_changes_dat, also in case of an error! string 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, "save_profile"); # # # Response # # string dat = "{"; dat .= add_json("profileChanges", profile_changes_dat, "obj"); dat = close_json(dat); 'saveChangesResponse(' . dat . ')\n'; ) else ( # No permission to access this resource (URL) display_no_permission_html(); ); =}