def DoTheRest(grph, beginning, physical, file_split): file_depth = len(file_split) if file_depth == 0: if beginning != physical: nodePhys = lib_common.gUriGen.FileUri(physical) CIM_DataFile.AddInfo(grph, nodePhys, [physical]) nodeLink = lib_common.gUriGen.FileUri(beginning) CIM_DataFile.AddInfo(grph, nodeLink, [beginning]) grph.add((nodePhys, pc.property_symlink, nodeLink)) return ext = "/" + file_split[0] DoTheRest(grph, beginning + ext, physical + ext, file_split[1:]) try: new_begin = beginning + ext # print("Test symlink:" + new_begin) lnk_path = os.readlink(new_begin) # BEWARE, the link is absolute or relative. # It's a bit nonsensical because it depends on the current path. if lnk_path[0] == '/': full_path = lnk_path else: full_path = beginning + "/" + lnk_path # print("link=" + lnk_path + "=>" + full_path) DoTheRest(grph, full_path, physical + ext, file_split[1:]) except: # print("Not a symlink:"+beginning) return
def Main(): cgiEnv = lib_common.CgiEnv() fileSharedLib = cgiEnv.GetId() if not lib_util.isPlatformLinux: lib_common.ErrorMessageHtml("LDD on Linux platform only") grph = cgiEnv.GetGraph() # Maybe the file does not contain its path so it must be added. if (fileSharedLib[0] != '/'): fileSharedLib = os.getcwd() + '/' + fileSharedLib nodeSharedLib = lib_common.gUriGen.SharedLibUri(fileSharedLib) CIM_DataFile.AddInfo(grph, nodeSharedLib, [fileSharedLib]) stream = os.popen("ldd " + fileSharedLib) # Line read are such as: # linux-gate.so.1 => (0xffffe000) # libdl.so.2 => /lib/libdl.so.2 (0xb7dae000) # libc.so.6 => /lib/i686/libc.so.6 (0xb7c6a000) # /lib/ld-linux.so.2 (0x80000000) # Do not know what to do with the lines without an arrow. # Do not know what happens if a library name contains a space. rgx = re.compile(r'^.*=> *([^ ]+) \(') for line in stream: matchObj = re.match(rgx, line) if matchObj: AddDepends(grph, nodeSharedLib, matchObj.group(1)) # The dependencies are flattened which may be is a mistake. cgiEnv.OutCgiRdf("LAYOUT_RECT")
def _add_file_or_dir(grph, file_path): if os.path.isdir(file_path): node_path = lib_uris.gUriGen.FileUri(file_path) CIM_DataFile.AddInfo(grph, node_path, [file_path]) else: node_path = lib_uris.gUriGen.DirectoryUri(file_path) CIM_Directory.AddInfo(grph, node_path, [file_path]) return node_path
def Main(): cgiEnv = lib_common.ScriptEnvironment() memmap_name = cgiEnv.GetId() grph = cgiEnv.GetGraph() uri_memmap = lib_uris.gUriGen.MemMapUri(memmap_name) CIM_DataFile.AddInfo(grph, uri_memmap, [memmap_name]) cgiEnv.OutCgiRdf()
def AddExtraInformationtoProcess(grph, node_process, proc_obj): CIM_Process.AddInfo(grph, node_process, [str(proc_obj.pid)]) usrNam = lib_common.format_username(CIM_Process.PsutilProcToUser(proc_obj)) userNode = lib_common.gUriGen.UserUri(usrNam) grph.add((userNode, pc.property_owner, node_process)) (execName, execErrMsg) = CIM_Process.PsutilProcToExe(proc_obj) if execName != "": execNod = lib_common.gUriGen.FileUri(execName) grph.add((node_process, pc.property_runs, execNod)) lib_entity_file.AddInfo(grph, execNod, [execName])
def Main(): cgiEnv = lib_common.CgiEnv() filNam = cgiEnv.GetId() #filNam = filNam.replace("\\","/") sys.stderr.write("filNam=%s\n" % filNam ) filNode = lib_common.gUriGen.FileUri(filNam ) grph = cgiEnv.GetGraph() info = CIM_DataFile.GetInfoStat(filNam) # st_mode: protection bits. # st_ino: inode number. # st_dev: device. CIM_DataFile.AddDevice(grph,filNode,info) CIM_DataFile.AddStatNode( grph, filNode, info ) CIM_DataFile.AddMagic( grph, filNode, filNam ) # st_nlink: number of hard links. CIM_DataFile.AffFileOwner(grph, filNode, filNam) # Displays the file and the parent directories/ currFilNam = filNam currNode = filNode while True: dirPath = os.path.dirname( currFilNam ) if dirPath == currFilNam: break if dirPath == "": break dirNode = lib_common.gUriGen.DirectoryUri( dirPath ) grph.add( ( dirNode, pc.property_directory, currNode ) ) sys.stderr.write("dirPath=%s\n" % dirPath) statPath = os.stat(dirPath) CIM_DataFile.AddStatNode( grph, dirNode, statPath ) CIM_DataFile.AddFileProperties(grph,currNode,currFilNam) currFilNam = dirPath currNode = dirNode # If windows, print more information: DLL version etc... # http://stackoverflow.com/questions/580924/python-windows-file-version-attribute # cgiEnv.OutCgiRdf() # cgiEnv.OutCgiRdf("LAYOUT_TWOPI") cgiEnv.OutCgiRdf("LAYOUT_RECT_RL")
def Main(): cgiEnv = lib_common.ScriptEnvironment() file_name = cgiEnv.GetId() logging.debug("file_name=%s", file_name) file_node = lib_uris.gUriGen.FileUri(file_name) grph = cgiEnv.GetGraph() info = CIM_DataFile.GetInfoStat(file_name) # st_mode: protection bits. # st_ino: inode number. # st_dev: device. CIM_DataFile.AddDevice(grph, file_node, info) CIM_DataFile.AddStatNode(grph, file_node, info) CIM_DataFile.AddMagic(grph, file_node, file_name) # st_nlink: number of hard links. CIM_DataFile.AffFileOwner(grph, file_node, file_name) # Displays the file and the parent directories. current_file_name = file_name current_node = file_node while True: dir_path = os.path.dirname(current_file_name) if dir_path == current_file_name: break if dir_path == "": break dir_node = lib_uris.gUriGen.DirectoryUri(dir_path) grph.add((dir_node, pc.property_directory, current_node)) logging.debug("file_stat.py dir_path=%s", dir_path) stat_path = os.stat(dir_path) CIM_DataFile.AddStatNode(grph, dir_node, stat_path) CIM_DataFile.AddFileProperties(grph, current_node, current_file_name) current_file_name = dir_path current_node = dir_node # If windows, print more information: DLL version etc... # http://stackoverflow.com/questions/580924/python-windows-file-version-attribute cgiEnv.OutCgiRdf("LAYOUT_RECT_RL")
def Main(): cgiEnv = lib_common.CgiEnv() filNam = cgiEnv.GetId() # Maybe this is a disk name, on Windows, such as "A:", "C:" etc... if lib_util.isPlatformWindows : # Remove the trailing backslash. if re.match(r"^[a-zA-Z]:\\$", filNam): filNam = filNam[:2] # Add a slash at the end, otherwise it does not work. if re.match("^[a-zA-Z]:$", filNam): filNam += "/" filNode = lib_common.gUriGen.DirectoryUri(filNam) grph = cgiEnv.GetGraph() if lib_util.isPlatformLinux: isTopDirectory = filNam == '/' elif lib_util.isPlatformWindows: # Should be "E:/" but in case it would be "E:". isTopDirectory = (len(filNam) == 2 and filNam[1] == ':') or (len(filNam) == 3 and filNam[1:3] == ':/') else: isTopDirectory = False DEBUG("file_directory.py filNam=%s isTopDirectory=%d", filNam, isTopDirectory) if not isTopDirectory: topdir = os.path.dirname(filNam) DEBUG("topdir=%s", topdir) if topdir: topdirNode = lib_common.gUriGen.DirectoryUri(topdir) grph.add((topdirNode, pc.property_directory, filNode)) url_mime = UriDirectoryDirectScript( topdir ) grph.add((topdirNode, pc.property_rdf_data_nolist2, lib_common.NodeUrl(url_mime))) if os.path.isdir(filNam): # sys.stderr.write("filNam=%s\n"%(filNam)) # In case we do not loop at all, the value must be set. dirs = None # This takes the list of files and directories of this directory, without recursing. for subdir, dirs, files in os.walk(filNam): break if dirs == None: lib_common.ErrorMessageHtml("No files in:" + filNam) # Special case if top of the filesystem, on Linux. filNam_slash = filNam if filNam != "/": filNam_slash += "/" for one_directory in dirs: fullDirPath = filNam_slash + one_directory subdirNode = lib_common.gUriGen.DirectoryUri(fullDirPath.replace("&","&")) grph.add((filNode, pc.property_directory, subdirNode)) url_dir_node = UrlDirectory(fullDirPath) if not url_dir_node is None: grph.add((subdirNode, pc.property_rdf_data_nolist1, url_dir_node)) url_mime = UriDirectoryDirectScript(fullDirPath) grph.add((subdirNode, pc.property_rdf_data_nolist2, lib_common.NodeUrl(url_mime))) # TODO: If this is a script, checks if this is executable ? for one_file in files: fullFilePath = filNam_slash + one_file # First replace the ampersand, then encode. fullFilePath = lib_util.urllib_quote(fullFilePath, safe='/:! ') file_path_replace_encoded = fullFilePath.replace("&", "&") # There might be non-ascii chars, accents etc... # filNam='C://Users/Yana\xeblle \xe0 la plage.jpg' # filNam='C://Users/Yanaelle a la plage.jpg' # Typical Graphviz error: # Error: not well-formed (invalid token) in line 1 # ... <u>Yana (e trema) lle et Constantin (a grave accent) Boulogne-sur-Mer.IMG-20190806-WA0000.jpg ... subfilNode = lib_common.gUriGen.FileUri(file_path_replace_encoded) grph.add((filNode, pc.property_directory, subfilNode)) CIM_DataFile.AddStat(grph, subfilNode, fullFilePath) CIM_DataFile.AddHtml(grph, subfilNode, fullFilePath) cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_directory])
def AddDepends(grph, nodeSharedLib, library): libNode = lib_common.gUriGen.SharedLibUri(library) grph.add((nodeSharedLib, pc.property_library_depends, libNode)) # This assumes that shared libraries are a special sort of file. # This is true, but not completely used. CIM_DataFile.AddInfo(grph, libNode, [library])
def Main(): cgiEnv = lib_common.CgiEnv() filNam = cgiEnv.GetId() # Maybe this is a disk name, on Windows, such as "A:", "C:" etc... if lib_util.isPlatformWindows: # Remove the trailing backslash. if re.match(r"^[a-zA-Z]:\\$", filNam): filNam = filNam[:2] # Add a slash at the end, otherwise it does not work. if re.match("^[a-zA-Z]:$", filNam): filNam += "/" # filNode = lib_common.gUriGen.FileUri(filNam ) filNode = lib_common.gUriGen.DirectoryUri(filNam) grph = cgiEnv.GetGraph() if lib_util.isPlatformLinux: isTopDirectory = filNam == '/' elif lib_util.isPlatformWindows: # Should be "E:/" but in case it would be "E:". isTopDirectory = (len(filNam) == 2 and filNam[1] == ':') or (len(filNam) == 3 and filNam[1:3] == ':/') else: isTopDirectory = False sys.stderr.write("file_directory.py filNam=%s isTopDirectory=%d\n" % (filNam, isTopDirectory)) if not isTopDirectory: topdir = os.path.dirname(filNam) sys.stderr.write("topdir=%s\n" % (topdir)) if topdir: topdirNode = lib_common.gUriGen.DirectoryUri(topdir) grph.add((topdirNode, pc.property_directory, filNode)) url_mime = UriDirectoryDirectScript(topdir) grph.add((topdirNode, pc.property_rdf_data_nolist2, lib_common.NodeUrl(url_mime))) if os.path.isdir(filNam): # sys.stderr.write("filNam=%s\n"%(filNam)) # In case we do not loop at all. dirs = None for subdir, dirs, files in os.walk(filNam): break if dirs == None: lib_common.ErrorMessageHtml("No files in:" + filNam) # Special case if top of the filesystem, on Linux. filNam_slash = filNam if filNam != "/": filNam_slash += "/" for dir in dirs: fullDirPath = filNam_slash + dir subdirNode = lib_common.gUriGen.DirectoryUri( fullDirPath.replace("&", "&")) grph.add((filNode, pc.property_directory, subdirNode)) url_dir_node = UrlDirectory(fullDirPath) if not url_dir_node is None: grph.add( (subdirNode, pc.property_rdf_data_nolist1, url_dir_node)) url_mime = UriDirectoryDirectScript(fullDirPath) grph.add((subdirNode, pc.property_rdf_data_nolist2, lib_common.NodeUrl(url_mime))) # On peut ajouter des liens en rdf_data mais leur nom est normalement une "info". # Donc en affichage horizontal, il faut aussi virer ce sous-noeud. # C est vraiment un cas special car le noeud "info" du noed "rdf_data" doit etre utilise # comme titre de l'url, et il doit y en avoir un et un seul. # Que se passe--til si le noeud rdf_data pointe vers d'autres noeuds? # On pourrait avoir propriete=rdf_data mais la valeur serait un literal ? # TODO: Quand c'est un script, verifier qu'on peut l'executer !!! for file in files: fullFilePath = filNam_slash + file # OK WinXP: On remplace d'abord le ampersand, et on encode ensuite, car le remplacement ne marche pas dans l'autre sens. subfilNode = lib_common.gUriGen.FileUri( fullFilePath.replace("&", "&")) grph.add((filNode, pc.property_directory, subfilNode)) CIM_DataFile.AddStat(grph, subfilNode, fullFilePath) CIM_DataFile.AddHtml(grph, subfilNode, fullFilePath) cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_directory])