Beispiel #1
0
def PyFilNode(proc_obj, filNam, ignoreEnvs):
    fullFileName = None

    if os.path.isabs(filNam):
        fullFileName = filNam
    else:
        # Check if the file exists in the current directory.
        currPwd, errMsg = CIM_Process.PsutilProcCwd(proc_obj)
        if not currPwd:
            sys.stderr.write("PyFilNode: %s\n" % errMsg)
            return None

        allDirsToSearch = [currPwd]

        # With this option, do not use environment variable.
        if not ignoreEnvs:
            pathPython = CIM_Process.GetEnvVarProcess("PYTHONPATH",
                                                      proc_obj.pid)
            if pathPython:
                pathPythonSplit = pathPython.split(":")
                allDirsToSearch += pathPythonSplit

        # Now tries all possible dirs, starting with current directory.
        for aDir in allDirsToSearch:
            fullPath = os.path.join(aDir, filNam)
            if os.path.isfile(fullPath):
                fullFileName = fullPath
                break

    if fullFileName:
        filNode = lib_common.gUriGen.FileUri(fullFileName)
        return filNode
    else:
        return None
Beispiel #2
0
def Main():
	cgiEnv = lib_common.CgiEnv()
	try:
		top_pid = int( cgiEnv.GetId() )
	except Exception:
		lib_common.ErrorMessageHtml("Must provide a pid")

	grph = cgiEnv.GetGraph()

	proc_obj = CIM_Process.PsutilGetProcObj(top_pid)

	node_process = lib_common.gUriGen.PidUri(top_pid)
	CIM_Process.AddInfo( grph, node_process, [ str(top_pid) ] )

	proc_cwd,proc_msg = CIM_Process.PsutilProcCwd(proc_obj)

	if proc_cwd:
		# proc_cwd = proc_cwd.replace("\\","/") # "Our" normalisation.
		node_cwd = lib_common.gUriGen.FileUri( proc_cwd )
		grph.add( ( node_process, pc.property_cwd, node_cwd ) )
	else:
		# The PID is added to the message such as "Access denied", so it is specific to the process
		# and prevents nodes with the same text to be merged in RDF or when displayed in Javascript.
		msgSpecific = "%s:Pid=%d" % (proc_msg,top_pid)
		grph.add( ( node_process, pc.property_information, lib_common.NodeLiteral(msgSpecific)) )

	cgiEnv.OutCgiRdf()
Beispiel #3
0
def _py_fil_node(proc_obj, fil_nam, ignore_envs):
    full_file_name = None

    if os.path.isabs(fil_nam):
        full_file_name = fil_nam
    else:
        # Check if the file exists in the current directory.
        curr_pwd, err_msg = CIM_Process.PsutilProcCwd(proc_obj)
        if not curr_pwd:
            logging.debug("_py_fil_node: %s", err_msg)
            return None

        all_dirs_to_search = [curr_pwd]

        # With this option, do not use environment variable.
        if not ignore_envs:
            path_python = CIM_Process.GetEnvVarProcess("PYTHONPATH",
                                                       proc_obj.pid)
            if path_python:
                path_python_split = path_python.split(":")
                all_dirs_to_search += path_python_split

        # Now tries all possible dirs, starting with current directory.
        for a_dir in all_dirs_to_search:
            full_path = os.path.join(a_dir, fil_nam)
            if os.path.isfile(full_path):
                full_file_name = full_path
                break

    if full_file_name:
        fil_node = lib_uris.gUriGen.FileUri(full_file_name)
        return fil_node
    else:
        return None
Beispiel #4
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    pidProc = int(cgiEnv.GetId())

    grph = cgiEnv.GetGraph()

    node_process = lib_common.gUriGen.PidUri(pidProc)
    proc_obj = CIM_Process.PsutilGetProcObj(pidProc)

    # Now we are parsing the command line.
    cmd_line = CIM_Process.PsutilProcToCmdline(proc_obj)

    sys.stderr.write("cmd_line=%s\n" % str(cmd_line))

    # Similar to split, but ignores white spaces in double quotes.
    argvArray = re.findall(r'(?:[^\s "]|"(?:\\.|[^"])*")+', cmd_line)

    sys.stderr.write("argvArray=%s\n" % str(argvArray))

    # This extracts the command file name and creates a node for it.
    for theArg in argvArray[1:]:
        if theArg[0] == "/":
            continue

        # Check if the file exists in the current directory.
        currPwd, errMsg = CIM_Process.PsutilProcCwd(proc_obj)
        if not currPwd:
            sys.stderr.write("PyFilNode: %s\n" % errMsg)
            break

        allDirsToSearch = [currPwd]

        envPath = CIM_Process.GetEnvVarProcess("PATH", proc_obj.pid)
        if envPath:
            allDirsToSearch += envPath.split(";")

        # Now tries all possible dirs, starting with current directory.
        for aDir in allDirsToSearch:
            fullScriptPath = os.path.join(aDir, theArg)
            if os.path.isfile(fullScriptPath):
                sys.stderr.write("fullScriptPath=%s\n" % fullScriptPath)
                scriptNode = lib_common.gUriGen.FileUri(fullScriptPath)
                grph.add((node_process, pc.property_runs, scriptNode))
                break

        break

    cgiEnv.OutCgiRdf()
Beispiel #5
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    pidProc = int(cgiEnv.GetId())

    grph = cgiEnv.GetGraph()

    node_process = lib_common.gUriGen.PidUri(pidProc)
    proc_obj = CIM_Process.PsutilGetProcObj(pidProc)

    # Python 2
    # cmd_arr=['C:\\Python27\\python.exe', 'test_survol_client_library.py', '--debug', 'SurvolLocalTest.test_msdos_current_batch']
    # Python 3
    # cmd_arr=['C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\python.exe', 'test_survol_client_library.py', '--debug', 'SurvolLocalTest.test_msdos_current_batch']
    argvArray = CIM_Process.PsutilProcToCmdlineArray(proc_obj)
    DEBUG("argvArray=%s", str(argvArray))

    # This extracts the command file name and creates a node for it.
    for theArg in argvArray[1:]:
        if theArg[0] == "/":
            continue

        # Check if the file exists in the current directory.
        currPwd, errMsg = CIM_Process.PsutilProcCwd(proc_obj)
        if not currPwd:
            break

        allDirsToSearch = [currPwd]

        envPath = CIM_Process.GetEnvVarProcess("PATH", proc_obj.pid)
        if envPath:
            allDirsToSearch += envPath.split(";")

        # Now tries all possible dirs, starting with current directory.
        for aDir in allDirsToSearch:
            fullScriptPath = os.path.join(aDir, theArg)
            DEBUG("fullScriptPath=%s", fullScriptPath)
            if os.path.isfile(fullScriptPath):
                DEBUG("fullScriptPath=%s", fullScriptPath)
                scriptNode = lib_common.gUriGen.FileUri(fullScriptPath)
                grph.add((node_process, pc.property_runs, scriptNode))
                break

        break

    cgiEnv.OutCgiRdf()
Beispiel #6
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()
    pid_proc = int(cgiEnv.GetId())

    grph = cgiEnv.GetGraph()

    node_process = lib_uris.gUriGen.PidUri(pid_proc)
    proc_obj = CIM_Process.PsutilGetProcObj(pid_proc)

    argv_array = CIM_Process.PsutilProcToCmdlineArray(proc_obj)
    logging.debug("argv_array=%s", str(argv_array))

    # This extracts the command file name and creates a node for it.
    for the_arg in argv_array[1:]:
        if the_arg[0] == "/":
            continue

        # Check if the file exists in the current directory.
        curr_pwd, err_msg = CIM_Process.PsutilProcCwd(proc_obj)
        if not curr_pwd:
            break

        all_dirs_to_search = [curr_pwd]

        env_path = CIM_Process.GetEnvVarProcess("PATH", proc_obj.pid)
        if env_path:
            all_dirs_to_search += env_path.split(";")

        # Now tries all possible dirs, starting with current directory.
        for a_dir in all_dirs_to_search:
            full_script_path = os.path.join(a_dir, the_arg)
            logging.debug("full_script_path=%s", full_script_path)
            if os.path.isfile(full_script_path):
                script_node = lib_uris.gUriGen.FileUri(full_script_path)
                grph.add((node_process, pc.property_runs, script_node))
                break

        break
    cgiEnv.OutCgiRdf()