示例#1
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()
    entity_id = cgiEnv.m_entity_id

    name_space, entity_type = cgiEnv.get_namespace_type()

    grph = cgiEnv.GetGraph()

    root_node = lib_util.RootUri()

    entity_ids_arr = lib_util.EntityIdToArray(entity_type, entity_id)

    mode_disp = lib_util.GuessDisplayMode()
    logging.debug("entity_type=%s mode_disp=%s", entity_type, mode_disp)

    if not entity_type:
        lib_common.ErrorMessageHtml("entity_mime.py needs an object")

    entity_module = lib_util.GetEntityModule(entity_type)
    if not entity_module:
        lib_common.ErrorMessageHtml(
            "entity_mime.py entity_type=%s needs a module" % entity_type)

    try:
        entity_module.DisplayAsMime(grph, root_node, entity_ids_arr)
    except Exception as exc:
        lib_common.ErrorMessageHtml(
            __file__ + " DisplayAsMime fails: %s %s: %s. File=%s.\n" %
            (entity_type, entity_id, str(exc), entity_module.__file__))
示例#2
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    entity_id = cgiEnv.m_entity_id
    entity_host = cgiEnv.GetHost()

    (nameSpace, entity_type, entity_namespace_type) = cgiEnv.GetNamespaceType()

    grph = cgiEnv.GetGraph()

    rootNode = lib_util.RootUri()

    entity_ids_arr = lib_util.EntityIdToArray(entity_type, entity_id)

    modeDisp = lib_util.GuessDisplayMode()
    sys.stderr.write("entity_mime.py entity_type=%s modeDisp=%s\n" %
                     (entity_type, modeDisp))

    if not entity_type:
        lib_common.ErrorMessageHtml("entity_mime.py needs an object")

    entity_module = lib_util.GetEntityModule(entity_type)
    if not entity_module:
        lib_common.ErrorMessageHtml(
            "entity_mime.py entity_type=%s needs a module" % (entity_type))

    try:
        entity_module.DisplayAsMime(grph, rootNode, entity_ids_arr)
    except:
        exc = sys.exc_info()[1]
        sys.stderr.write("entity_mime.py No DisplayAsMime for %s %s: %s\n" %
                         (entity_type, entity_id, str(exc)))
        lib_common.ErrorMessageHtml(
            "entity_mime.py No DisplayAsMime for %s %s: %s\n" %
            (entity_type, entity_id, str(exc)))
示例#3
0
def Main():
    # This can process remote hosts because it does not call any script, just shows them.
    cgiEnv = lib_common.ScriptEnvironment(
                    can_process_remote=True,
                    parameters={lib_util.paramkeyShowAll: False})
    entity_id = cgiEnv.m_entity_id
    entity_host = cgiEnv.GetHost()
    flag_show_all = int(cgiEnv.get_parameters(lib_util.paramkeyShowAll))

    name_space, entity_type = cgiEnv.get_namespace_type()

    if lib_util.is_local_address(entity_host):
        entity_host = ""

    logging.debug("entity: entity_host=%s entity_type=%s entity_id=%s", entity_host, entity_type, entity_id)

    grph = cgiEnv.GetGraph()

    root_node = lib_util.RootUri()

    if entity_id != "" or entity_type == "":
        def callback_grph_add(tripl, depth_call):
            grph.add(tripl)

        recursive_walk_on_scripts(callback_grph_add, root_node, entity_type, entity_id, entity_host, flag_show_all)

    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_directory, pc.property_script])
示例#4
0
def Main():
    # This can process remote hosts because it does not call any script, just shows them.
    cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True)
    entity_id = cgiEnv.m_entity_id

    name_space, entity_type = cgiEnv.get_namespace_type()

    grph = cgiEnv.GetGraph()

    root_node = lib_util.RootUri()

    _add_information(grph, root_node, entity_id, entity_type)

    cgiEnv.OutCgiRdf()
示例#5
0
def Main():
    # This can process remote hosts because it does not call any script, just shows them.
    cgiEnv = lib_common.CgiEnv(can_process_remote=True)
    entity_id = cgiEnv.m_entity_id
    entity_host = cgiEnv.GetHost()

    nameSpace, entity_type = cgiEnv.get_namespace_type()

    grph = cgiEnv.GetGraph()

    rootNode = lib_util.RootUri()

    AddInformation(grph, rootNode, entity_id, entity_type)

    cgiEnv.OutCgiRdf()
示例#6
0
def Main():
    # This can process remote hosts because it calls scripts which can access remote data. I hope.
    cgiEnv = lib_common.CgiEnv(can_process_remote=True)

    # entity_type = cgiEnv.m_entity_type
    (nameSpace, className, entity_type) = cgiEnv.GetNamespaceType()

    # UNE SEQUENCE QUI NE MARCHE PAS VRAIMENT
    # http://rchateau-hp:8000/survol/class_type_all.py?xid=CIM_ComputerSystem. OK bien que plein de "Undefined class CIM_ComputerSystem"
    # http://rchateau-hp:8000/survol/class_wbem.py?xid=http%3A%252F%252F192.168.0.17%3A5988%2FCIM_ComputerSystem.
    # http://rchateau-hp:8000/survol/class_type_all.py?xid=http%3A%2F%2F192.168.0.17%3A5988%2F%3ACIM_ComputerSystem.

    # CA NON PLUS:
    # http://192.168.0.17/Survol/survol/class_type_all.py?xid=http%3A%2F%2F192.168.0.17%3A5988%2Froot%2Fcimv2%3ACIM_Process.

    # Just in case ...
    if nameSpace == "/":
        nameSpace = ""

    entity_host = cgiEnv.GetHost()
    entity_id = cgiEnv.m_entity_id

    # QUERY_STRING=xid=http%3A%2F%2F192.168.1.88%3A5988%2Froot%2FPG_Internal%3APG_WBEMSLPTemplate
    sys.stderr.write("class_type_all entity_host=%s entity_id=%s\n" %
                     (entity_host, entity_id))

    grph = cgiEnv.GetGraph()

    # TODO: Utiliser la bonne fonction !!!
    rootNode = lib_util.RootUri()

    objtypeNode = lib_common.NodeUrl(lib_util.uriRoot + '/objtypes.py')
    grph.add((rootNode, pc.property_rdf_data_nolist2, objtypeNode))

    # This displays the documentation of the Python module of this entity class.
    entity_module = lib_util.GetEntityModule(className)
    entDoc = entity_module.__doc__
    if entDoc:
        grph.add((rootNode, pc.property_information,
                  lib_common.NodeLiteral(entDoc)))

    CreateOurNode(grph, rootNode, entity_host, nameSpace, className, entity_id)

    # Do this for each intermediary entity type (Between slashes).
    AddCIMClasses(grph, rootNode, entity_host, nameSpace, className, entity_id)

    cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
示例#7
0
def Main():
    """This should be able to process remote hosts because it calls scripts which can access remote data."""
    cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True)

    name_space, class_name = cgiEnv.get_namespace_type()

    # If name_space is not provided, it is set to "root/CIMV2" by default.
    if not class_name:
        lib_common.ErrorMessageHtml("Class name should not be empty")

    # Just in case ...
    if name_space == "/":
        name_space = ""

    entity_host = cgiEnv.GetHost()
    entity_id = cgiEnv.m_entity_id

    # QUERY_STRING=xid=http%3A%2F%2F192.168.1.88%3A5988%2Froot%2FPG_Internal%3APG_WBEMSLPTemplate
    logging.debug("class_type_all entity_host=%s entity_id=%s", entity_host,
                  entity_id)

    grph = cgiEnv.GetGraph()

    root_node = lib_util.RootUri()

    objtypeNode = lib_common.NodeUrl(lib_util.uriRoot + '/objtypes.py')
    grph.add((root_node, pc.property_rdf_data_nolist2, objtypeNode))

    # This displays the documentation of the Python module of this entity class.
    entity_module = lib_util.GetEntityModule(class_name)
    ent_doc = entity_module.__doc__
    if ent_doc:
        ent_doc = ent_doc.strip()
        grph.add((root_node, pc.property_information,
                  lib_util.NodeLiteral(ent_doc)))

    _create_our_node(grph, root_node, entity_host, name_space, class_name,
                     entity_id)

    # Do this for each intermediary entity type (Between slashes).
    AddCIMClasses(grph, root_node, entity_host, name_space, class_name,
                  entity_id)

    cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
示例#8
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    rootNode = lib_util.RootUri()

    # This assumes that we have no namespace.
    for entity_type in lib_util.ObjectTypes():

        tmpNode = rootNode
        idx = 0

        while idx >= 0:
            nextSlash = entity_type.find("/", idx + 1)
            if nextSlash == -1:
                intermedType = entity_type
            else:
                intermedType = entity_type[:nextSlash]

            entityNode = lib_util.EntityClassNode(intermedType)
            grph.add((tmpNode, pc.property_directory, entityNode))

            try:
                # This reloads all classes without cache because if it does not load
                # we want to see the error message.
                entity_module = lib_util.GetEntityModuleNoCatch(entity_type)
                entDoc = entity_module.__doc__
            except:
                exc = sys.exc_info()[1]
                entDoc = "Error:" + str(exc)

            if entDoc:
                entDoc = entDoc.strip()
                grph.add((entityNode, pc.property_information,
                          lib_common.NodeLiteral(entDoc)))

            # TODO: If this is a CIM class, add WMI or WBEM documentation, or add the link.

            tmpNode = entityNode
            idx = nextSlash

    cgiEnv.OutCgiRdf("LAYOUT_RECT")
示例#9
0
def Main():

    # This can process remote hosts because it does not call any script, just shows them.
    cgiEnv = lib_common.CgiEnv(can_process_remote=True,
                               parameters={lib_util.paramkeyShowAll: False})
    entity_id = cgiEnv.m_entity_id
    entity_host = cgiEnv.GetHost()
    flagShowAll = int(cgiEnv.get_parameters(lib_util.paramkeyShowAll))

    nameSpace, entity_type = cgiEnv.get_namespace_type()

    if lib_util.IsLocalAddress(entity_host):
        entity_host = ""

    DEBUG("entity: entity_host=%s entity_type=%s entity_id=%s", entity_host,
          entity_type, entity_id)

    grph = cgiEnv.GetGraph()

    rootNode = lib_util.RootUri()

    if entity_id != "" or entity_type == "":
        entity_ids_arr = lib_util.EntityIdToArray(entity_type, entity_id)

        # TODO: Plutot qu'attacher tous les sous-directory a node parent,
        # ce serait peut-etre mieux d'avoir un seul lien, et d'afficher
        # les enfants dans une table, un record etc...
        # OU: Certaines proprietes arborescentes seraient representees en mettant
        # les objets dans des boites imbriquees: Tables ou records.
        # Ca peut marcher quand la propriete forme PAR CONSTRUCTION
        # un DAG (Direct Acyclic Graph) qui serait alors traite de facon specifique.

        def CallbackGrphAdd(tripl, depthCall):
            grph.add(tripl)

        DirToMenu(CallbackGrphAdd, rootNode, entity_type, entity_id,
                  entity_host, flagShowAll)

    cgiEnv.OutCgiRdf("LAYOUT_RECT",
                     [pc.property_directory, pc.property_script])
示例#10
0
def Main():

    # This can process remote hosts because it does not call any script, just shows them.
    cgiEnv = lib_common.CgiEnv(can_process_remote=True,
                               parameters={lib_util.paramkeyShowAll: False})
    entity_id = cgiEnv.m_entity_id
    entity_host = cgiEnv.GetHost()
    flagShowAll = int(cgiEnv.GetParameters(lib_util.paramkeyShowAll))

    (nameSpace, entity_type, entity_namespace_type) = cgiEnv.GetNamespaceType()

    grph = cgiEnv.GetGraph()

    rootNode = lib_util.RootUri()

    entity_ids_arr = lib_util.EntityIdToArray(entity_type, entity_id)
    # entity_info_only.AddInformation(grph,rootNode,entity_id, entity_type)

    # Each entity type ("process","file" etc... ) can have a small library
    # of its own, for displaying a rdf node of this type.
    if entity_type:
        entity_module = lib_util.GetEntityModule(entity_type)
        if entity_module:
            try:
                entity_module.AddInfo(grph, rootNode, entity_ids_arr)
            except AttributeError:
                exc = sys.exc_info()[1]
                sys.stderr.write("No AddInfo for %s %s: %s\n" %
                                 (entity_type, entity_id, str(exc)))
    else:
        sys.stderr.write("No lib_entities for %s %s\n" %
                         (entity_type, entity_id))

    # When displaying in json mode, the scripts are shown with a contextual menu, not with D3 modes..
    if lib_util.GuessDisplayMode() not in ["json", "html"]:

        # This function is called for each script which applies to the given entity.
        # It receives a triplet: (subject,property,object) and the depth in the tree.
        # Here, this simply stores the scripts in a graph. The depth is not used yet,
        # but can help debugging.
        def CallbackGrphAdd(tripl, depthCall):
            grph.add(tripl)

        entity_dirmenu_only.DirToMenu(CallbackGrphAdd, rootNode, entity_type,
                                      entity_id, entity_host, flagShowAll)

        # This adds WBEM and WMI urls related to the current object.
        if entity_type != "":
            CIM_ComputerSystem.AddWbemWmiServers(grph, rootNode, entity_host,
                                                 nameSpace, entity_type,
                                                 entity_id)

        AddDefaultScripts(grph, rootNode, entity_host)

        # Special case if the currententity we are displaying, is a machine,
        # we might as well try to connect to its WMI or WBEM server, running on this machine.
        if entity_type == "CIM_ComputerSystem":
            AddDefaultScripts(grph, rootNode, entity_id)

    AddDefaultNodes(grph, rootNode, entity_host)

    cgiEnv.OutCgiRdf("LAYOUT_RECT",
                     [pc.property_directory, pc.property_script])
示例#11
0
def Main():

    # This can process remote hosts because it does not call any script, just shows them.
    cgiEnv = lib_common.ScriptEnvironment(
        can_process_remote=True, parameters={lib_util.paramkeyShowAll: False})
    entity_id = cgiEnv.m_entity_id
    entity_host = cgiEnv.GetHost()
    logging.debug("entity_host=%s", entity_host)
    flag_show_all = int(cgiEnv.get_parameters(lib_util.paramkeyShowAll))

    # This optional parameter must not be edited.
    # It contains the name of an associator, and the associated objects must be displayed.
    associator_attribute = cgiEnv.get_parameters("__associator_attribute__")
    logging.debug("associator_attribute=%s", associator_attribute)
    if associator_attribute and associator_attribute.find(".") <= 0:
        lib_common.ErrorMessageHtml(
            "Associator attribute '%s' should be 'associator.role'" %
            associator_attribute)

    name_space, entity_type = cgiEnv.get_namespace_type()

    grph = cgiEnv.GetGraph()

    root_node = lib_util.RootUri()
    logging.debug("root_node=%s", root_node)

    entity_ids_arr = lib_util.EntityIdToArray(entity_type, entity_id)

    # Each entity type ("process","file" etc... ) can have a small library
    # of its own, for displaying a rdf node of this type.
    if entity_type:
        entity_module = lib_util.GetEntityModule(entity_type)
        if entity_module:
            try:
                entity_module.AddInfo(grph, root_node, entity_ids_arr)
            except AttributeError as exc:
                logging.info("No AddInfo for %s %s: %s", entity_type,
                             entity_id, str(exc))
            except Exception as exc:
                logging.info("Unexpected exception for %s %s: %s", entity_type,
                             entity_id, str(exc))

        if associator_attribute:
            # Should we display the associated instances for this associator and role ?
            lib_associators.add_associated_instances(grph, root_node,
                                                     entity_type, entity_id,
                                                     associator_attribute)
    else:
        # This behaves as the top-level page, without instances to display.
        logging.info("No lib_entities for %s %s", entity_type, entity_id)

    # When displaying in json mode, the scripts are shown with a contextual menu, not with D3 modes..
    if lib_util.GuessDisplayMode() not in ["json", "html"]:

        # This function is called for each script which applies to the given entity.
        # It receives a triplet: (subject,property,object) and the depth in the tree.
        # Here, this simply stores the scripts in a graph. The depth is not used yet,
        # but can help debugging.
        def callback_grph_add(tripl, depthCall):
            try:
                grph.add(tripl)
            except Exception as exc:
                logging.error("callback_grph_add: tripl=%s exception=%s" %
                              (str(tripl), str(exc)))
                raise

        try:
            # This displays the scripts associated to this instance.
            entity_dirmenu_only.recursive_walk_on_scripts(
                callback_grph_add, root_node, entity_type, entity_id,
                entity_host, flag_show_all)
        except Exception as exc:
            logging.error("Caught in recursive_walk_on_scripts:%s. Trace=%s",
                          exc, traceback.format_exc())

        # This adds WBEM and WMI urls related to the current object.
        # They can display more information about this instance.
        if entity_type != "":
            # This solves the case where one of the values of the ontology predicates contains commas.
            # These commands were quoted, then separated of other arguments by a comma.
            # TODO: It would be probably be  simpler to encode predicates values just like CGI arguments.
            _add_wbem_wmi_servers(grph, root_node, entity_host, name_space,
                                  entity_type, entity_id)

        _add_default_scripts(grph, root_node, entity_host)

        # Special case if the current entity we are displaying, is a machine,
        # we might as well try to connect to its WMI or WBEM server, running on this machine.
        if entity_type == "CIM_ComputerSystem":
            _add_default_scripts(grph, root_node, entity_id)

    _add_default_nodes(grph, root_node, entity_host)

    cgiEnv.OutCgiRdf("LAYOUT_RECT",
                     [pc.property_directory, pc.property_script])
示例#12
0
#!/usr/bin/env python

# This is a technical script used only for testing.
# It depends only on low-level libraries and returns their internal results
# which cannot not normally be printed clearly.
# BEWARE: This does not work with WSGI.

import json
import sys

import lib_util

internal_data = {
    "uriRoot": lib_util.uriRoot,
    "HttpPrefix": lib_util.HttpPrefix(),
    "RootUri": lib_util.RootUri(),
    "RequestUri": lib_util.RequestUri()
}
json_data = json.dumps(internal_data)

sys.stdout.write(
    """Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Methods: POST,GET,OPTIONS
Access-Control-Allow-Origin:*
Content-Type: application/json; charset=utf-8
Content-Length: %d

""" % len(json_data))

ret_dict = {
    "uriRoot": lib_util.uriRoot,