예제 #1
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True)

    entity_host = cgiEnv.GetHost()

    logging.debug("entity_host=%s", entity_host)
    entity_host = lib_wmi.NormalHostName(entity_host)

    cimom_url = entity_host

    logging.debug("cimom_url=%s", cimom_url)

    grph = cgiEnv.GetGraph()

    # There is no consensus on the WMI class for namespaces,
    # so we have ours which must be correctly mapped.
    namespace_class = "wmi_namespace"
    # root_node = lib_util.EntityUri(namespace_class,"")
    root_node = lib_util.EntityUri(namespace_class)

    for nskey in _hardcoded_namespaces:
        # _sub_namespace( root_node, grph, nskey )
        try: # "root\\" +
            # _sub_namespace( root_node, grph, nskey, cimom_url )
            _sub_namespace(root_node, grph, nskey, cimom_url)
        except Exception as exc:
            lib_common.ErrorMessageHtml("namespaces_wmi.py cimom_url=%s nskey=%s Caught:%s" % ( cimom_url, nskey , str(exc) ) )

    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_cim_subnamespace])
예제 #2
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True)

    cimom_url = cgiEnv.GetHost()

    grph = cgiEnv.GetGraph()

    # There is no consensus on the WBEM class for namespaces,
    # so we have ours which must be correctly mapped.
    namespace_class = "wbem_namespace"
    root_node = lib_util.EntityUri(namespace_class, "")

    try:
        conn_wbem = lib_wbem.WbemConnection(cimom_url)
        nsd = lib_wbem.EnumNamespacesCapabilities(conn_wbem)
    except Exception as exc:
        lib_common.ErrorMessageHtml("Namespaces from :" + cimom_url +
                                    " Caught:" + str(exc))

    # TODO: We should draw a namespaces tree but more examples needed.
    for nskey in nsd:

        cnt = nsd[nskey]
        wbem_url = lib_wbem.NamespaceUrl(nskey, cimom_url)
        wbem_node = lib_common.NodeUrl(wbem_url)

        grph.add((root_node, pc.property_cim_subnamespace, wbem_node))
        grph.add(
            (wbem_node, pc.property_information, lib_util.NodeLiteral(nskey)))
        grph.add(
            (wbem_node, pc.property_information, lib_util.NodeLiteral(cnt)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT")
예제 #3
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    entity_type = "dbus/connection"

    Main.busAddr = cgiEnv.m_entity_id_dict["Bus"]
    Main.connectName = cgiEnv.m_entity_id_dict["Connect"]

    try:
        Main.theBus = lib_dbus.MakeBusFromAddress(Main.busAddr)
    except Exception as exc:
        lib_common.ErrorMessageHtml("busAddr=%s Caught:%s" % (Main.busAddr, str(exc)))

    connectNode = lib_util.EntityUri(entity_type, Main.busAddr, Main.connectName)

    grph = cgiEnv.GetGraph()

    Main.localPropDbusPath = lib_util.NodeLiteral("dbus-path")

    try:
        _recursive_obj_walk(grph, "/", connectNode)
    except dbus.exceptions.DBusException as exc:
        lib_common.ErrorMessageHtml("Caught DBusException busAddr=%s %s" % (Main.busAddr, str(exc)))
    except dbus.proxies as exc:
        lib_common.ErrorMessageHtml("Caught proxies busAddr=%s %s" % (Main. busAddr, str(exc)))

    cgiEnv.OutCgiRdf()
예제 #4
0
 def GetConnectNode(busAddr, connectName):
     try:
         return Main.connectNameToNode[connectName]
     except KeyError:
         connectNode = lib_util.EntityUri("dbus/connection", busAddr,
                                          connectName)
         Main.connectNameToNode[connectName] = connectNode
         return connectNode
예제 #5
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    grph = cgiEnv.GetGraph()

    listBuses = ["system", "session"]

    for busName in listBuses:
        uriBus = lib_util.EntityUri("dbus/bus", busName)
        grph.add((lib_common.nodeMachine, lib_common.MakeProp("DBus"), uriBus))

    cgiEnv.OutCgiRdf()
예제 #6
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()
    fname = cgiEnv.GetId()

    grph = cgiEnv.GetGraph()

    fname_mystery_node = lib_uris.gUriGen.ComTypeLibUri(fname)

    # TODO: Difficulty, many entries.

    HLITypeKinds = {
            pythoncom.TKIND_ENUM      : 'Enumeration',
            pythoncom.TKIND_RECORD    : 'Record',
            pythoncom.TKIND_MODULE    : 'Module',
            pythoncom.TKIND_INTERFACE : 'Interface',
            pythoncom.TKIND_DISPATCH  : 'Dispatch',
            pythoncom.TKIND_COCLASS   : 'CoClass',
            pythoncom.TKIND_ALIAS     : 'Alias',
            pythoncom.TKIND_UNION     : 'Union'
      }


    try:
        tlb = pythoncom.LoadTypeLib(fname)
    except pythoncom.com_error:
        lib_common.ErrorMessageHtml("Cannot load:" + fname)

    for idx in range(tlb.GetTypeInfoCount()):
        try:
            info_typ = tlb.GetTypeInfoType(idx)

            typ_nam = HLITypeKinds[info_typ]

            sub_entity_type = lib_util.ComposeTypes("com", "type_lib_entry", typ_nam.lower())

            name_com_entry_uri = "%s_(%d)" % (fname, idx)

            # TODO: Maybe this will be cleaner. Quick and dirty solution for the moment.
            # UriNodeCreatorName = "ComTypeLibEntry" + typ_nam + "Uri"
            # funcCreate = getattr( lib_common, UriNodeCreatorName )
            # entry_node = funcCreate( "%s_(%d)" % ( fname, idx ) )
            entry_node = lib_util.EntityUri(sub_entity_type, name_com_entry_uri)

            name, doc, ctx, helpFile = tlb.GetDocumentation(idx)

            grph.add((entry_node, pc.property_information, lib_util.NodeLiteral("name=%s" % name)))
            grph.add((entry_node, pc.property_information, lib_util.NodeLiteral("type=%s" % typ_nam)))
            grph.add((fname_mystery_node, pc.property_com_entry, entry_node))

        except pythoncom.com_error as exc:
            lib_common.ErrorMessageHtml("Caught:" + exc)

    cgiEnv.OutCgiRdf("LAYOUT_RECT")
예제 #7
0
def Main():
	cgiEnv = lib_common.CgiEnv(can_process_remote = True)

	# See differences and similarities between these.
	# entity_host = cgiEnv.GetHost()
	# entity_host = cgiEnv.GetParameters("xid")
	entity_host = cgiEnv.GetHost()

	sys.stderr.write("entity_host=%s\n" % entity_host)
	entity_host = lib_wmi.NormalHostName(entity_host)

	cimomUrl = entity_host

	sys.stderr.write("namespaces_wmi.py cimomUrl=%s\n" % cimomUrl)

	grph = cgiEnv.GetGraph()

	# There is no consensus on the WMI class for namespaces,
	# so we have ours which must be correctly mapped.
	namespace_class = "wmi_namespace"
	rootNode = lib_util.EntityUri(namespace_class,"")



	##########  test seulement
	# Unexpected COM Error (-2147023174, 'The RPC server is unavailable.', None, None)

	# Erreur possible si on se connecte a l adresse courante:
	# 'SWbemLocator', u'User credentials cannot be used for local connections '

	# http://timgolden.me.uk/python/wmi/tutorial.html
	# connWMI = lib_wmi.WmiConnect(cimomUrl,"Microsoft")
	# connWMI = wmi.WMI("192.168.1.67",user="******", password="******") # The RPC server is unavailable
	# connWMI = wmi.WMI("192.168.1.78",user="******", password="******") # The RPC server is unavailable
	# c = wmi.WMI(namespace="WMI")
	#
	# c = wmi.WMI("MachineB", user=r"MachineB\fred", password="******")


	for nskey in hardcodedNamespaces:
		# SubNamespace( rootNode, grph, nskey )
		try: # "root\\" +
			# SubNamespace( rootNode, grph, nskey, cimomUrl )
			SubNamespace( rootNode, grph, nskey, cimomUrl )
		#except wmi.x_wmi:
		#	exc = sys.exc_info()[1]
		#	lib_common.ErrorMessageHtml("EXCEPT WMI nskey=%s Caught:%s" % ( nskey , str(exc) ) )
		except Exception:
			exc = sys.exc_info()[1]
			lib_common.ErrorMessageHtml("namespaces_wmi.py cimomUrl=%s nskey=%s Caught:%s" % ( cimomUrl, nskey , str(exc) ) )

	cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_cim_subnamespace])
예제 #8
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    busAddr = cgiEnv.GetId()

    grph = cgiEnv.GetGraph()

    try:
        theBus = lib_dbus.MakeBusFromAddress(busAddr)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("busAddr=%s Caught:%s" %
                                    (busAddr, str(exc)))

    nodeBus = lib_util.EntityUri("dbus/bus", busAddr)

    # This property should maybe stored at the central file.
    localPropDbusConnect = lib_common.MakeProp("dbus connect")
    localPropDbusWellKnown = lib_common.MakeProp("well known")

    Main.connectNameToNode = dict()

    def GetConnectNode(busAddr, connectName):
        try:
            return Main.connectNameToNode[connectName]
        except KeyError:
            connectNode = lib_util.EntityUri("dbus/connection", busAddr,
                                             connectName)
            Main.connectNameToNode[connectName] = connectNode
            return connectNode

    for connectName in theBus.list_names():
        connectNode = GetConnectNode(busAddr, connectName)

        try:
            ownrNam = theBus.get_name_owner(connectName)
            sys.stderr.write("connectName=%s ownr=%s\n" %
                             (connectName, ownrNam))
            if connectName != ownrNam:
                ownrNode = GetConnectNode(busAddr, ownrNam)
                sys.stderr.write("TO CONNECT %s\n" % (connectName))

                # TODO: BUG, Display does not work if "Well Known" property.
                # grph.add( (ownrNode, localPropDbusWellKnown, connectNode ) )
                grph.add((ownrNode, localPropDbusConnect, connectNode))
        except ValueError:
            sys.stderr.write("22 CONNECT %s\n" % (connectName))
            grph.add((nodeBus, localPropDbusConnect, connectNode))

    # TODO: The ordering is: 1.1,1.11,1.2, so we should have a special sort function.

    cgiEnv.OutCgiRdf("LAYOUT_RECT",
                     [localPropDbusConnect, localPropDbusWellKnown])
예제 #9
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()
    bus_addr = cgiEnv.GetId()

    grph = cgiEnv.GetGraph()

    try:
        the_bus = lib_dbus.MakeBusFromAddress(bus_addr)
    except Exception as exc:
        lib_common.ErrorMessageHtml("bus_addr=%s Caught:%s" %
                                    (bus_addr, str(exc)))

    node_bus = lib_util.EntityUri("dbus/bus", bus_addr)

    # This property should maybe stored at the central file.
    local_prop_dbus_connect = lib_common.MakeProp("dbus connect")
    local_prop_dbus_well_known = lib_common.MakeProp("well known")

    Main.connectNameToNode = dict()

    def get_connect_node(bus_addr, connect_name):
        try:
            return Main.connectNameToNode[connect_name]
        except KeyError:
            connectNode = lib_util.EntityUri("dbus/connection", bus_addr,
                                             connect_name)
            Main.connectNameToNode[connect_name] = connectNode
            return connectNode

    for connect_name in the_bus.list_names():
        connect_node = get_connect_node(bus_addr, connect_name)

        try:
            ownr_nam = the_bus.get_name_owner(connect_name)
            logging.debug("connect_name=%s ownr=%s", connect_name, ownr_nam)
            if connect_name != ownr_nam:
                ownr_node = get_connect_node(bus_addr, ownr_nam)
                logging.debug("TO CONNECT %s", connect_name)

                # TODO: BUG, Display does not work if "Well Known" property.
                # grph.add((ownr_node, local_prop_dbus_well_known, connect_node))
                grph.add((ownr_node, local_prop_dbus_connect, connect_node))
        except ValueError:
            logging.debug("22 CONNECT %s", connect_name)
            grph.add((node_bus, local_prop_dbus_connect, connect_node))

    # TODO: The ordering is: 1.1,1.11,1.2, so we should use natsort.

    cgiEnv.OutCgiRdf("LAYOUT_RECT",
                     [local_prop_dbus_connect, local_prop_dbus_well_known])
예제 #10
0
def RecursiveObjWalk(grph,object_path, rootNode):
	DEBUG("RecursiveObjWalk %s", object_path)
	objNode = lib_util.EntityUri( "dbus/object", Main.busAddr, Main.connectName, object_path )
	grph.add( (rootNode, Main.localPropDbusPath, objNode ) )

	obj = Main.theBus.get_object(Main.connectName, object_path)
	iface = dbus.Interface(obj, 'org.freedesktop.DBus.Introspectable')
	xml_string = iface.Introspect()

	if object_path == '/':
		object_path = ''
	for child in ElementTree.fromstring(xml_string):
		if child.tag == 'node':
			new_path = '/'.join((object_path, child.attrib['name']))
			RecursiveObjWalk( grph, new_path, objNode)
예제 #11
0
def _get_daemons_data():
    """
    This returns in a dictionary, the list of deamons.
    These daemons can then be displayed in plain HTML or in a Jinja2 template.
    Some control is also provided by the interface of supervisord library, so its link is displayed.
    Some CGI scripts can run in two modes: "web" mode (CGI or WSGI), as usual, but also in daemon mode:
    their daemon process runs endlessly and instead of returning their events to the caller of the CGI script,
    these events are inserted into a RDF triplestore.
    This RDF triplestore is defined as an URL in the credentials: Any type of triplestore
    is allowed as long as it is supported by rdflib persistence API,
    see details here: https://rdflib.readthedocs.io/en/stable/persistence.html .
    Then, when the script is later run in "normal", CGI mode, the events are returned from this triplestore database.
    This allows to accumulate a complete history of events stored as RDF triples.
    
    Each of these daemons is associated with a CGI script and also an object, defined with its class and the values 
    of the attributes listes in the ontology of the class.
    Of course, if this is a top-level script not associated with a class, there are no arguments.
    """

    urls_daemons_dict = lib_daemon.get_running_daemons()
    for daemon_url, daemon_object in urls_daemons_dict.items():
        logging.debug("daemon_url=%s" % daemon_url)

        url_label, entity_type, entity_id = lib_naming.ParseEntityUri(
            daemon_url, long_display=True)
        logging.debug("url_label=%s" % url_label)
        logging.debug("entity_type=%s" % entity_type)
        logging.debug("entity_id=%s" % entity_id)

        daemon_object['url_title'] = url_label

        # Now that we have the class and the key-value pairs of the object related to the script, builds its url.
        # TODO: Simplify this, because it splits the id path to join it afterwards.
        # It might help to reorder properly the key-value pairs.
        entity_ids_arr = lib_util.EntityIdToArray(entity_type, entity_id)
        entity_url = lib_util.EntityUri(entity_type, *entity_ids_arr)
        logging.debug("entity_url=%s" % entity_url)
        daemon_object['object_url'] = entity_url
        entity_label = lib_naming.entity_to_label(entity_type, entity_id,
                                                  lib_util.HostName())
        logging.debug("entity_label=%s" % entity_label)
        daemon_object['object_title'] = entity_label
        daemon_object['triples_number'] = lib_kbase.context_events_count(
            daemon_url)
        daemon_object['start_time'] = datetime.datetime.fromtimestamp(
            daemon_object['start']).strftime("%m/%d/%Y, %H:%M:%S")

    return urls_daemons_dict
예제 #12
0
def Main():
    cgiEnv = lib_common.CgiEnv(can_process_remote=True)

    cimomUrl = cgiEnv.GetHost()

    grph = cgiEnv.GetGraph()

    # There is no consensus on the WBEM class for namespaces,
    # so we have ours which must be correctly mapped.
    namespace_class = "wbem_namespace"
    rootNode = lib_util.EntityUri(namespace_class, "")

    connWbem = lib_wbem.WbemConnection(cimomUrl)

    try:
        nsd = lib_wbem.EnumNamespacesCapabilities(connWbem)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Namespaces from :" + cimomUrl +
                                    " Caught:" + str(exc))

    # TODO: We should draw a namespaces tree but more examples needed.
    for nskey in nsd:

        cnt = nsd[nskey]
        # Special case because it is not displayed like a normal entity.
        # Oui mais ca marche aussi avec wmi ?
        # Pourrait-on combiner namespace+classe ? entity_type="root/cim_v2/CIM_Process" ?
        # Si l'entity_type termine par un slash, donc c'est un namespace ?
        # Ca nous permettrait de creer des namespaces dans notre ontologie,
        # par exemple pour Oracle. Ce serait simplement un directory.
        # ATTENTION: Avoir la liste de nos entity_types sera moins immediat.
        wbemUrl = lib_wbem.NamespaceUrl(nskey, cimomUrl)
        wbemNode = lib_common.NodeUrl(wbemUrl)

        grph.add((rootNode, pc.property_cim_subnamespace, wbemNode))
        grph.add(
            (wbemNode, pc.property_information, lib_common.NodeLiteral(nskey)))
        grph.add(
            (wbemNode, pc.property_information, lib_common.NodeLiteral(cnt)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT")
예제 #13
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    entity_type = "dbus/connection"
    # entity_id = cgiEnv.m_entity_id
    # entity_ids_arr = lib_util.EntityIdToArray( entity_type, entity_id )
    # entity_ids_dict = lib_util.SplitMoniker(entity_id)

    # busAddr = entity_ids_arr[0]
    # connectName = entity_ids_arr[1]
    Main.busAddr = cgiEnv.m_entity_id_dict["Bus"]
    Main.connectName = cgiEnv.m_entity_id_dict["Connect"]

    try:
        Main.theBus = lib_dbus.MakeBusFromAddress(Main.busAddr)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("busAddr=%s Caught:%s" %
                                    (Main.busAddr, str(exc)))

    connectNode = lib_util.EntityUri(entity_type, Main.busAddr,
                                     Main.connectName)

    grph = cgiEnv.GetGraph()

    Main.localPropDbusPath = lib_common.NodeLiteral("dbus-path")

    try:
        RecursiveObjWalk(grph, "/", connectNode)
    except dbus.exceptions.DBusException as exc:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Caught DBusException busAddr=%s %s" %
                                    (Main.busAddr, str(exc)))
    except dbus.proxies as exc:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Caught proxies busAddr=%s %s" %
                                    (Main.busAddr, str(exc)))

    cgiEnv.OutCgiRdf()
예제 #14
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    fname = cgiEnv.GetId()

    grph = cgiEnv.GetGraph()

    fnameMysteryNode = lib_common.gUriGen.ComTypeLibUri(fname)

    # TODO: Difficulte: On se retrouve qvec des dizaines d'entries,
    # qui correspondent a ces types, et on ne sait pas comment
    # les afficher differemment: C'est le meme probleme que les fichiers
    # qui sont des sous-classes.
    # DONC:
    # - Dans l'affichages des listes, prevoir des types de children:
    #   Le type du fichier, ou bien [Enumeration,CoClass,Dispatch] etc...
    # - Il faut que les sous-classes puissent etre definies par defaut.
    # - Pourquoi ne pas definir "file/dll", "file/exe" d'une part,
    #   "com_type_lib_entry/dispatch", "com_type_lib_entry/coclass" etc...
    #   Et dans la foulee, on remplace "BY_hostname" par "entities/hostname"
    # - L'affichage en liste HTML va detecter les entity_type dans les children
    #   d'un meme parent pour une propriete donnee, et va segmenter
    #   par entity_type et donc entity_subtype.

    HLITypeKinds = {
        pythoncom.TKIND_ENUM: 'Enumeration',
        pythoncom.TKIND_RECORD: 'Record',
        pythoncom.TKIND_MODULE: 'Module',
        pythoncom.TKIND_INTERFACE: 'Interface',
        pythoncom.TKIND_DISPATCH: 'Dispatch',
        pythoncom.TKIND_COCLASS: 'CoClass',
        pythoncom.TKIND_ALIAS: 'Alias',
        pythoncom.TKIND_UNION: 'Union'
    }

    try:
        tlb = pythoncom.LoadTypeLib(fname)
    except pythoncom.com_error:
        lib_common.ErrorMessageHtml("Cannot load:" + fname)

    for idx in range(tlb.GetTypeInfoCount()):
        try:
            infoTyp = tlb.GetTypeInfoType(idx)

            typNam = HLITypeKinds[infoTyp]

            sub_entity_type = lib_util.ComposeTypes("com/type_lib_entry",
                                                    typNam.lower())

            nameComEntryUri = "%s_(%d)" % (fname, idx)

            # TODO: Maybe this will be cleaner. Quick and dirty solution for the moment.
            # UriNodeCreatorName = "ComTypeLibEntry" + typNam + "Uri"
            # funcCreate = getattr( lib_common, UriNodeCreatorName )
            # entryNode = funcCreate( "%s_(%d)" % ( fname, idx ) )
            entryNode = lib_util.EntityUri(sub_entity_type, nameComEntryUri)

            name, doc, ctx, helpFile = tlb.GetDocumentation(idx)

            grph.add((entryNode, pc.property_information,
                      lib_common.NodeLiteral("name=%s" % name)))
            grph.add((entryNode, pc.property_information,
                      lib_common.NodeLiteral("type=%s" % typNam)))
            grph.add((fnameMysteryNode, pc.property_com_entry, entryNode))

        except pythoncom.com_error:
            ret.append(browser.MakeHLI("The type info can not be loaded!"))

    cgiEnv.OutCgiRdf("LAYOUT_RECT")
예제 #15
0
 def MakeUri(self, entity_type, **kwArgs):
     return lib_util.EntityUri(entity_type, {"Db": self.m_oraDatabase},
                               **kwArgs)