{= # # # # validate_database_options.cfv # # # include "templates.util.base_util"; include "templates.util.encoding"; include "templates.util.rbac.rbac_util"; debug_message("\n\n#### validate_database_options.cfv START \n\n"); 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_admin_feature_permission(session_id, "profiles", "add")) and get_is_valid_page_token(session_id, "new_profile_wizard", page_token)) then ( debug_message("\n" . node_as_string("v.fp.db_server") . "\n"); node db_server = "v.fp.db_server"; string database_type = @db_server{"type"}; bool is_error = false; string error_message; if (database_type eq "internal_sql") then ( # This must be a database with a custom database directory # Make sure that no database exists in the given directory string database_directory_in_utf8 = @db_server{"database_directory"}; string database_directory_in_local_code_page = convert_utf8_to_local_code_page(database_directory_in_utf8); string dir_divider = (if _PLATFORM eq "Win32" then "\\" else "/"); string database_config_directory = database_directory_in_local_code_page; if (!ends_with(database_config_directory, dir_divider)) then ( # Append directory divider database_config_directory .= dir_divider; ); database_config_directory .= "main" . dir_divider . "config"; if (file_exists(database_config_directory)) then ( # A database altready exists in the custom directory, throw an error is_error = true; error_message = lang_admin.database.database_directory_already_exists; ); ) else ( # This is a MySQL, MS SQL or Oracle database # If a database name is given we check that the database name # does not already exist as profile_name and as database # in the database server. # We also check for a valid database connection # # Verify database server connection # bool is_valid_db_server_connection = verify_database_server_connection(db_server); string database_name = @db_server{"database_name"}; if (!is_valid_db_server_connection) then ( is_error = true; error_message = lang_admin.database.database_server_connection_failed; # Append error details if available if (?("volatile.error_message")) then ( error_message .= "\n" . volatile.error_message; ); ) else if (database_name ne "") then ( # Make sure that database doesn't yet exist within the database server # and as a profile name because the database_name is also used within # the internal databases directory! # Disabled profiles check because the database_name is already checked against all profile names on client side # if (?("profiles." . database_name)) then ( # is_error = true; # error_message = "The database name is already used in another profile. Please define a different database name."; # ); # ToDo, check database server for database_name existence! ); ); debug_message("#### is_error: " . is_error . "\n"); debug_message("#### error_message: " . error_message . "\n"); # # Response # string dat = "{"; dat .= add_json("isError", is_error, "bool"); dat .= add_json("errorMessage", error_message, "string"); dat = close_json(dat); 'validateDatabaseOptionsOnServerSideResponse(' . dat . ')\n'; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); debug_message("\n#### validate_database_options.cfv END \n\n"); =}