{= # # # get_defined_directory.cfv # # include "templates.util.base_util"; include "templates.util.encoding"; include "templates.util.rbac.rbac_util"; include "templates.file_manager.file_manager_util"; debug_message("\n#### get_defined_directory.cfv START\n"); string session_id = volatile.session_id; bool is_file_manager_permission = get_is_file_manager_permission(); string page_token = v.fp.page_token; if (is_file_manager_permission and get_is_valid_page_token(session_id, "file_manager", page_token)) then ( # This subroutine generates the directory tree of the given pathname string pathname_in_utf8 = v.fp.pathname; pathname_in_utf8 = replace_all(pathname_in_utf8, "__HexEsc__5C", "\\"); # If it ends with a directory divider, chop it off because we handle all pathnames # without trailing divider. Otherwise, browsing to /pub/logs/Examples/ will show # the contents of /pub/logs by default. if (ends_with(pathname_in_utf8, internal.directory_divider)) then ( pathname_in_utf8 = substr(pathname_in_utf8, 0, length(pathname_in_utf8) - 1); ); string pathname_in_local_code_page = convert_utf8_to_local_code_page(pathname_in_utf8); debug_message("#### pathname_in_local_code_page: " . pathname_in_local_code_page . "\n"); # # # Check if the defined pathname exists # # bool is_valid_pathname = file_exists(pathname_in_local_code_page); debug_message("#### is_valid_pathname: " . is_valid_pathname . "\n"); # # # Get directory tree # # string root_items_dat; string tree_structure_dat; if (is_valid_pathname) then ( string id_prefix = "i"; # Note, the id_prefix is only right for root_items_dat, # for tree_structure_dat the Id's are wrong, they will be # re-written on the client side when the tree is generated. # # # # Get the root items # # # # # Check if this is a UNC pathname # string unc_pathname_in_local_code_page = ""; if ((_PLATFORM eq "Win32") and starts_with(pathname_in_local_code_page, "\\\\")) then ( unc_pathname_in_local_code_page = pathname_in_local_code_page; ); debug_message("#### unc_pathname_in_local_code_page: " . unc_pathname_in_local_code_page . "\n"); root_items_dat = get_directory_contents_dat(id_prefix, "", unc_pathname_in_local_code_page); # # # Get the tree items # # delete_node("v.temp_tree_structure"); v.temp_tree_structure = ""; node tree_structure = "v.temp_tree_structure"; get_pathname_tree_structure(pathname_in_local_code_page, tree_structure); # Writes tree info to tree_structure node debug_message("#### tree_structure:\n" . node_as_string(tree_structure) . "\n"); tree_structure_dat = "["; int number_of_tree_items = num_subnodes(tree_structure); if (number_of_tree_items > 0) then ( # Start assembling the tree items from top to bottom. # The last item in tree_structure becomes the first item in tree_structure_dat string tree_item_dat; string tree_item_type; string tree_item_pathname_in_local_code_page; string tree_item_pathname_in_utf; string tree_item_items_dat; node tree_item; for (int i = number_of_tree_items - 1; i >= 0; i--) ( tree_item = subnode_by_number(tree_structure, i); tree_item_type = @tree_item{"type"}; tree_item_pathname_in_local_code_page = @tree_item{"pathname"}; tree_item_pathname_in_utf = convert_local_code_page_to_utf8(tree_item_pathname_in_local_code_page); tree_item_items_dat = get_directory_contents_dat(id_prefix, tree_item_pathname_in_local_code_page, ""); # TEMP # tree_item_items_dat = "[]"; tree_item_dat = "{"; tree_item_dat .= add_json("type", tree_item_type, "string"); tree_item_dat .= add_json("pathname", tree_item_pathname_in_utf, "string"); tree_item_dat .= add_json("items", tree_item_items_dat, "obj"); tree_item_dat = close_json(tree_item_dat); tree_structure_dat .= tree_item_dat . ","; ); tree_structure_dat = replace_last(tree_structure_dat, ",", "]"); ) else ( # This case is theoretically not possible (no tree structure), however, we provide it. tree_structure_dat .= "]"; ); ) else ( root_items_dat = "[]"; tree_structure_dat = "[]"; ); # # # # Send response # # # string dat = "{"; dat .= add_json("isValidPathname", is_valid_pathname, "bool"); dat .= add_json("rootItems", root_items_dat, "obj"); dat .= add_json("treeStructure", tree_structure_dat, "obj"); dat = close_json(dat); 'fileManager.getDefinedDirectoryResponse(' . dat . ')\n'; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); =}