Esempio n. 1
0
def GetWmiUserPass(machWithBackSlashes):
    # WmiConnect cimom=\\\\rchateau-HP\\:. wmiNamspace=aspnet
    # cleanMachNam = machWithBackSlashes.replace("\\","").lower()
    cleanMachNam = machWithBackSlashes.replace("\\", "")

    #sys.stderr.write("GetWmiUserPass cimom=%s cleanMachNam=%s\n" % ( machWithBackSlashes, cleanMachNam ) )

    wmiUserPass = lib_credentials.GetCredentials("WMI", cleanMachNam)

    #sys.stderr.write("GetWmiUserPass wmiUserPass=%s\n" % ( str(wmiUserPass) ) )

    if wmiUserPass[0]:
        return cleanMachNam, wmiUserPass[0], wmiUserPass[1]

    # WMI does not do local connection with the local IP.
    try:
        machIP = lib_util.GlobalGetHostByName(cleanMachNam)
    except:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml(
            "GetWmiUserPass: Cannot connect to WMI server:%s" % cleanMachNam)

    #sys.stderr.write("GetWmiUserPass machIP=%s\n" % ( machIP ) )

    wmiUserPass = lib_credentials.GetCredentials("WMI", machIP)
    return machIP, wmiUserPass[0], wmiUserPass[1]
Esempio n. 2
0
def _enumerate_services(grph, subscription_name):
    subscription_id, certificate_path = lib_credentials.GetCredentials(
        "Azure", subscription_name)

    sms = ServiceManagementService(subscription_id, certificate_path)

    subscription_node = subscription.MakeUri(subscription_name)

    try:
        lst_srvs = sms.list_hosted_services()
    except Exception as exc:
        lib_common.ErrorMessageHtml("Unexpected error:" + str(exc))

    for srv in lst_srvs:
        serv_node = service.MakeUri(srv.service_name, subscription_name)
        grph.add(
            (subscription_node, lib_common.MakeProp("Service"), serv_node))

        # There will be duplicates.
        loca_node = location.MakeUri(srv.hosted_service_properties.location,
                                     subscription_name)
        grph.add((serv_node, lib_common.MakeProp("Location"), loca_node))

        grph.add((serv_node, pc.property_rdf_data_nolist1,
                  lib_common.NodeUrl(srv.url)))
Esempio n. 3
0
def _enumerate_locations(grph, subscription_name):
    #   "Azure": {
    #     "Visual Studio Professional": [
    #       "hexahexa-hexa-hexa-hexa-hexahexahexa",
    #       "AzureCertificate"
    #     ]
    #   },

    # "hexahexa-hexa-hexa-hexa-hexahexahexa", "AzureCertificate"
    subscription_id, certificate_path = lib_credentials.GetCredentials(
        "Azure", subscription_name)

    sms = ServiceManagementService(subscription_id, certificate_path)

    subscription_node = subscription.MakeUri(subscription_name)

    try:
        # This throws when running with Apache. OK with cgiserver.py
        lst_locas = sms.list_locations()
    except Exception as exc:
        lib_common.ErrorMessageHtml("Unexpected error:" + str(exc))

    for loca in lst_locas:
        loca_node = location.MakeUri(loca.name, subscription_name)
        grph.add(
            (subscription_node, lib_common.MakeProp("Location"), loca_node))
Esempio n. 4
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    config_nam = cgiEnv.m_entity_id_dict["Url"]
    nam_v_host = cgiEnv.m_entity_id_dict["VHost"]

    node_manager = survol_rabbitmq_manager.MakeUri(config_nam)

    creds = lib_credentials.GetCredentials("RabbitMQ", config_nam)

    # cl = Client('localhost:12345', 'guest', '*****')
    cl = Client(config_nam, creds[0], creds[1])

    grph = cgiEnv.GetGraph()

    nod_v_host = survol_rabbitmq_vhost.MakeUri(config_nam, nam_v_host)
    grph.add(
        (node_manager, lib_common.MakeProp("virtual host node"), nod_v_host))

    for obj_exchange in cl.get_exchanges(nam_v_host):
        nam_exchange = obj_exchange["name"]
        logging.debug("nam_exchange=%s", nam_exchange)

        node_exchange = survol_rabbitmq_exchange.MakeUri(
            config_nam, nam_v_host, nam_exchange)

        management_url = rabbitmq.ManagementUrlPrefix(config_nam, "exchanges",
                                                      nam_v_host, nam_exchange)

        grph.add((node_exchange, lib_common.MakeProp("Management"),
                  lib_common.NodeUrl(management_url)))

        grph.add((nod_v_host, lib_common.MakeProp("Exchange"), node_exchange))

    cgiEnv.OutCgiRdf()
Esempio n. 5
0
def Main():

    cgiEnv = lib_common.CgiEnv()

    configNam = cgiEnv.m_entity_id_dict["Url"]
    namVHost = cgiEnv.m_entity_id_dict["VHost"]

    nodeManager = survol_rabbitmq_manager.MakeUri(configNam)

    creds = lib_credentials.GetCredentials("RabbitMQ", configNam)

    # cl = Client('localhost:12345', 'guest', 'guest')
    cl = Client(configNam, creds[0], creds[1])

    grph = cgiEnv.GetGraph()

    nodVHost = survol_rabbitmq_vhost.MakeUri(configNam, namVHost)
    grph.add((nodeManager, lib_common.MakeProp("virtual host node"), nodVHost))

    for quList in cl.get_queues(namVHost):
        namQueue = quList["name"]
        DEBUG("q=%s", namQueue)

        nodeQueue = survol_rabbitmq_queue.MakeUri(configNam, namVHost,
                                                  namQueue)

        managementUrl = rabbitmq.ManagementUrlPrefix(configNam, "queues",
                                                     namVHost, namQueue)

        grph.add((nodeQueue, lib_common.MakeProp("Management"),
                  lib_common.NodeUrl(managementUrl)))

        grph.add((nodVHost, lib_common.MakeProp("Queue"), nodeQueue))

    cgiEnv.OutCgiRdf()
Esempio n. 6
0
def Main():
	cgiEnv = lib_common.CgiEnv()

	grph = cgiEnv.GetGraph()

	credNames = lib_credentials.GetCredentialsNames( "MySql" )
	DEBUG("Mysql servers")

	for instanceMySql in credNames:
		DEBUG("MySql servers instanceMySql=%s",instanceMySql)

		# Do not use sources_types.mysql
		hostMySql = instanceMySql.split(":")[0]

		# TODO: Display the connection socket ?
		nodeHostMySql = lib_common.gUriGen.HostnameUri( hostMySql )

		nodeInstance = survol_mysql_instance.MakeUri(instanceMySql)

		aCred = lib_credentials.GetCredentials( "MySql", instanceMySql )

		grph.add( ( nodeInstance, lib_common.MakeProp("Mysql user")	, lib_common.NodeLiteral(aCred[0]) ) )
		grph.add( ( nodeInstance, lib_common.MakeProp("Mysql instance"), nodeHostMySql ) )

	cgiEnv.OutCgiRdf()
Esempio n. 7
0
def Main():
    cgiEnv = lib_oracle.OracleEnv()

    grph = cgiEnv.GetGraph()

    database = cgiEnv.m_oraDatabase

    ora_user, ora_pwd = lib_credentials.GetCredentials("Oracle", database)

    conn_str = ora_user + "/" + ora_pwd + "@" + database

    # The Oracle user needs: grant select any dictionary to <user>;
    qry_select = """
    SELECT sess.status, sess.username, sess.schemaname, sql.sql_text,sql.sql_fulltext,proc.spid
      FROM v$session sess,
           v$sql     sql,
           v$process proc
     WHERE sql.sql_id(+) = sess.sql_id
       AND sess.type     = 'USER'
       and sess.paddr = proc.addr
    """

    prop_sql_query = lib_common.MakeProp("SQL query")

    ora_parser = OraCallbackParseQry(grph, database, prop_sql_query)

    # This calls the callback for each retrieved row.
    try:
        lib_oracle.CallbackQuery(conn_str, qry_select, ora_parser.oracallback)
    except Exception as exc:
        lib_common.ErrorMessageHtml("CallbackQuery exception:%s in %s" %
                                    (str(exc), qry_select))

    cgiEnv.OutCgiRdf("LAYOUT_RECT", [prop_sql_query])
Esempio n. 8
0
def _create_credentials_map():
    """This lists the content of credentials and associates a variable name to each element.
    This variable name which must be unique, is later used to build a HTML form."""
    cred_type_list = lib_credentials.get_credentials_types()

    cred_types_dict = dict()

    for cred_type in sorted(cred_type_list):

        cred_types_dict[cred_type] = dict()

        # This is a homogeneous list, for example of machines names, or databases.
        cred_nams = lib_credentials.get_credentials_names(cred_type)

        for cred_name in sorted(cred_nams):
            cred = lib_credentials.GetCredentials(cred_type, cred_name)

            cred_input_prefix = cred_type + "_" + cred_name + "_" + cred[0]
            cred_input_password = cred_input_prefix + "_UPDATE_PASSWORD"
            cred_input_name_del = cred_input_prefix + "_DELETE_CREDENTIAL"

            cred_name_url = _cred_type_name_to_url(cred_type, cred_name)

            cred_types_dict[cred_type][cred_name] = [
                cred[0],
                cred[1],
                cred_input_password,
                cred_input_name_del,
                cred_name_url]

    return cred_types_dict
Esempio n. 9
0
def Main():

    cgiEnv = lib_common.ScriptEnvironment()

    configNam = cgiEnv.GetId()

    nodeManager = survol_rabbitmq_manager.MakeUri(configNam)

    creds = lib_credentials.GetCredentials("RabbitMQ", configNam)

    # cl = Client('localhost:12345', 'guest', 'guest')
    cl = Client(configNam, creds[0], creds[1])

    grph = cgiEnv.GetGraph()

    try:
        lstOverview = cl.get_overview()
    except Exception as exc:
        lib_common.ErrorMessageHtml("Caught:" + str(exc))

    for keyOverview in lstOverview:
        valOverview = lstOverview[keyOverview]

        valClean = valOverview
        # Otherwise it does not work as these chars should be espaced.
        # TODO: Nice display for Python lists and dicts.
        valClean = str(valClean).replace("{", "").replace("}", "")
        grph.add((nodeManager, lib_common.MakeProp(keyOverview),
                  lib_util.NodeLiteral(valClean)))

    cgiEnv.OutCgiRdf()
Esempio n. 10
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    grph = cgiEnv.GetGraph()

    cred_names = lib_credentials.get_credentials_names("MySql")
    logging.debug("Mysql servers")

    for instance_my_sql in cred_names:
        logging.debug("MySql servers instance_my_sql=%s", instance_my_sql)

        # Do not use sources_types.mysql
        host_my_sql = instance_my_sql.split(":")[0]

        # TODO: Display the connection socket ?
        node_host_my_sql = lib_uris.gUriGen.HostnameUri(host_my_sql)

        node_instance = survol_mysql_instance.MakeUri(instance_my_sql)

        a_cred = lib_credentials.GetCredentials("MySql", instance_my_sql)

        grph.add((node_instance, lib_common.MakeProp("Mysql user"),
                  lib_util.NodeLiteral(a_cred[0])))
        grph.add((node_instance, lib_common.MakeProp("Mysql instance"),
                  node_host_my_sql))

    cgiEnv.OutCgiRdf()
Esempio n. 11
0
def Main():
	cgiEnv = lib_common.CgiEnv()

	grph = cgiEnv.GetGraph()

	credNames = lib_credentials.GetCredentialsNames( "MySql" )
	sys.stderr.write("Mysql servers\n")

	for instanceMySql in credNames:
		sys.stderr.write("WbemServersList instanceMySql=%s\n"%(instanceMySql))

		# Do not use sources_types.mysql
		hostMySql = instanceMySql.split(":")[0]

		# TODO: Display the connection socket ?
		nodeHostMySql = lib_common.gUriGen.HostnameUri( hostMySql )

		# Intentionaly, it does not use mysql package.
		# nodeInstance = lib_common.gUriGen.UriMakeFromDict("mysql/instance", { "Instance": instanceMySql } )
		nodeInstance = survol_mysql_instance.MakeUri(instanceMySql)

		aCred = lib_credentials.GetCredentials( "MySql", instanceMySql )

		grph.add( ( nodeInstance, pc.property_user, lib_common.NodeLiteral(aCred[0]) ) )
		grph.add( ( nodeInstance, lib_common.MakeProp("Mysql instance"), nodeHostMySql ) )



	try:
		pass
	except Exception:
		exc = sys.exc_info()[1]
		lib_common.ErrorMessageHtml("tnsnam="+tnsnam+" err="+str(exc))

	cgiEnv.OutCgiRdf()
Esempio n. 12
0
def CreateCredentialsMap():
    credTypeList = lib_credentials.get_credentials_types()

    credTypesDict = dict()

    for credType in sorted(credTypeList):

        credTypesDict[credType] = dict()

        # This is a homogeneous list, for example of machines names, or databases.
        credNams = lib_credentials.GetCredentialsNames( credType )

        for credName in sorted(credNams):

            cred = lib_credentials.GetCredentials( credType, credName )

            credInputPrefix = credType + "_" + credName + "_" + cred[0]
            credInputPassword = credInputPrefix + "_UPDATE_PASSWORD"
            credInputNameDel = credInputPrefix + "_DELETE_CREDENTIAL"

            credNameUrl = CredTypeNameToUrl(credType, credName)

            credTypesDict[credType][credName] = [cred[0],cred[1],credInputPassword,credInputNameDel,credNameUrl]

    return credTypesDict
Esempio n. 13
0
def Main():

    cgiEnv = lib_common.CgiEnv()

    configNam = cgiEnv.m_entity_id_dict["Url"]
    namVHost = cgiEnv.m_entity_id_dict["VHost"]

    nodeManager = survol_rabbitmq_manager.MakeUri(configNam)

    creds = lib_credentials.GetCredentials("RabbitMQ", configNam)

    # cl = Client('localhost:12345', 'guest', 'guest')
    cl = Client(configNam, creds[0], creds[1])

    grph = cgiEnv.GetGraph()

    nodVHost = survol_rabbitmq_vhost.MakeUri(configNam, namVHost)
    grph.add((nodeManager, lib_common.MakeProp("virtual host node"), nodVHost))

    for objExchange in cl.get_exchanges(namVHost):
        namExchange = objExchange["name"]
        sys.stderr.write("namExchange=%s\n" % (namExchange))

        nodeExchange = survol_rabbitmq_exchange.MakeUri(
            configNam, namVHost, namExchange)

        managementUrl = rabbitmq.ManagementUrlPrefix(configNam, "exchanges",
                                                     namVHost, namExchange)

        grph.add((nodeExchange, lib_common.MakeProp("Management"),
                  lib_common.NodeUrl(managementUrl)))

        grph.add((nodVHost, lib_common.MakeProp("Exchange"), nodeExchange))

    cgiEnv.OutCgiRdf()
Esempio n. 14
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    # subscriptionName=Azure.DefaultSubscription()
    subscriptionName = cgiEnv.m_entity_id_dict["Subscription"]

    (subscription_id, certificate_path) = lib_credentials.GetCredentials(
        "Azure", subscriptionName)

    sms = ServiceManagementService(subscription_id, certificate_path)

    subscriptionNode = subscription.MakeUri(subscriptionName)

    try:
        # This throws when running with Apache. OK with cgiserver.py
        lstLocations = sms.list_locations()
    except:
        lib_common.ErrorMessageHtml("Unexpected error:" + str(sys.exc_info()))

    result = lstLocations
    for loca in result:
        locaNode = location.MakeUri(loca.name, subscriptionName)

        grph.add((subscriptionNode, lib_common.MakeProp("Location"), locaNode))

    cgiEnv.OutCgiRdf()
Esempio n. 15
0
def AddInfo(grph, node, entity_ids_arr):
    subscriptionName = entity_ids_arr[0]

    # This function is called from entity.py which does not connect to anything,
    # so we can do it here. Beware if there are too many connections,
    # because we could connect to all of them.
    try:
        (subscription_id, certificate_path) = lib_credentials.GetCredentials(
            "Azure", subscriptionName)
        if not subscription_id:
            errMsg = "No credential for subscriptionName=%s" % subscriptionName
            grph.add((node, lib_common.MakeProp("Azure Error"),
                      lib_common.NodeLiteral(errMsg)))
            return
        sms = ServiceManagementService(subscription_id, certificate_path)
    except:
        exc = sys.exc_info()[1]
        errMsg = "subscriptionName=%s:%s" % (subscriptionName, str(exc))
        grph.add((node, lib_common.MakeProp("Azure Error"),
                  lib_common.NodeLiteral(errMsg)))
        return

    # There are a lot of informations
    grph.add((node, lib_common.MakeProp(".cert_file"),
              lib_common.NodeLiteral(sms.cert_file)))
    grph.add((node, lib_common.MakeProp(".requestid"),
              lib_common.NodeLiteral(sms.requestid)))
    grph.add((node, lib_common.MakeProp(".x_ms_version"),
              lib_common.NodeLiteral(sms.x_ms_version)))
Esempio n. 16
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    config_nam = cgiEnv.m_entity_id_dict["Url"]
    nam_connection = cgiEnv.m_entity_id_dict["Connection"]

    node_manager = survol_rabbitmq_manager.MakeUri(config_nam)

    creds = lib_credentials.GetCredentials("RabbitMQ", config_nam)

    cl = Client(config_nam, creds[0], creds[1])

    grph = cgiEnv.GetGraph()

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

    nod_connection = survol_rabbitmq_connection.MakeUri(config_nam, nam_connection)

    grph.add((node_manager, lib_common.MakeProp("Connection"), nod_connection))

    try:
        connect_list = cl.get_connection(nam_connection)
    except Exception as exc:
        lib_common.ErrorMessageHtml("Caught:" + str(exc))

    for connect_key in connect_list:
        connect_val = connect_list[connect_key]

        if connect_key == "vhost":
            nod_v_host = survol_rabbitmq_vhost.MakeUri(config_nam, connect_val)
            grph.add((nod_connection, lib_common.MakeProp("Virtual host"), nod_v_host))
        elif connect_key == "user":
            nod_user = survol_rabbitmq_user.MakeUri(config_nam, connect_val)
            grph.add((nod_connection, lib_common.MakeProp("User"), nod_user))
        elif connect_key == "host":
            nod_host = lib_uris.gUriGen.HostnameUri(connect_val)
            grph.add((nod_connection, lib_common.MakeProp("Host"), nod_host))
        elif connect_key in ["name", "peer_host", "peer_port"]:
            pass
        else:
            if isinstance(connect_val, six.string_types):
                connect_val = connect_val.replace(">", "@")

                logging.debug("connect_key=%s connect_val=%s", connect_key, connect_val)
            elif isinstance(connect_val, dict):
                pass
            elif isinstance(connect_val, tuple):
                pass
            elif isinstance(connect_val, list):
                pass
            else:
                pass

            logging.debug("Literal=%s", lib_util.NodeLiteral(connect_val))

            grph.add((nod_connection, lib_common.MakeProp(connect_key), lib_util.NodeLiteral(connect_val)))

    survol_rabbitmq_connection.AddSockets(grph, nod_connection, nam_connection)

    cgiEnv.OutCgiRdf()
Esempio n. 17
0
def MakeImpersonate(machineName):
    currentUserName = win32api.GetUserName()
    sys.stderr.write("MakeImpersonate: machineName=%s currentUserName=%s\n" %
                     (machineName, currentUserName))

    # "titi" ou "Titi" ? Arp retourne "Titi".
    (usernam, passwd) = lib_credentials.GetCredentials("Login", machineName)
    sys.stderr.write("MakeImpersonate: usernam=%s\n" % (usernam))

    if usernam != '':
        if usernam == currentUserName:
            sys.stderr.write("MakeImpersonate: Already %s\n" % currentUserName)
            imper = None
        else:
            try:
                imper = Impersonate(usernam, passwd, machineName)
            except Exception:
                sys.stderr.write("MakeImpersonate: Caught %s\n" %
                                 (str(sys.exc_info())))
                imper = None
    else:
        sys.stderr.write(
            "MakeImpersonate: No impersonate on %s. Returning None.\n" %
            machineName)
        imper = None

    # If running on the local machine, pass the host as None otherwise authorization is checked
    # just like a remote machine, which means User Account Control (UAC) disabling,
    # and maybe setting LocalAccountTokenFilterPolicy=1
    if machineName == lib_util.currentHostname:
        machName_or_None = None
    else:
        machName_or_None = machineName

    return machName_or_None, imper
Esempio n. 18
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    # subscriptionName=Azure.DefaultSubscription()
    subscriptionName = cgiEnv.m_entity_id_dict["Subscription"]

    (subscription_id, certificate_path) = lib_credentials.GetCredentials(
        "Azure", subscriptionName)

    sms = ServiceManagementService(subscription_id, certificate_path)

    subscriptionNode = subscription.MakeUri(subscriptionName)

    try:
        # This throws when running with Apache. OK with cgiserver.py
        lstSrvs = sms.list_hosted_services()
    except:
        lib_common.ErrorMessageHtml("Unexpected error:" + str(sys.exc_info()))

    for srv in lstSrvs:
        servNode = service.MakeUri(srv.service_name, subscriptionName)
        grph.add((subscriptionNode, lib_common.MakeProp("Service"), servNode))

        # There will be duplicates.
        locaNode = location.MakeUri(srv.hosted_service_properties.location,
                                    subscriptionName)
        grph.add((servNode, lib_common.MakeProp("Location"), locaNode))

        grph.add((servNode, pc.property_rdf_data_nolist1,
                  lib_common.NodeUrl(srv.url)))

    cgiEnv.OutCgiRdf()
Esempio n. 19
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    grph = cgiEnv.GetGraph()

    subscription_name = cgiEnv.m_entity_id_dict["Subscription"]

    subscription_id, certificate_path = lib_credentials.GetCredentials( "Azure", subscription_name)

    sms = ServiceManagementService(subscription_id, certificate_path)

    subscription_node = subscription.MakeUri(subscription_name)

    # Some information printed
    grph.add((subscription_node, lib_common.MakeProp(".requestid"), lib_util.NodeLiteral(sms.requestid)))
    grph.add((subscription_node, lib_common.MakeProp(".x_ms_version"), lib_util.NodeLiteral(sms.x_ms_version)))

    prop_disk = lib_common.MakeProp("Disk")
    prop_disk_label = lib_common.MakeProp("Label")
    prop_disk_location = lib_common.MakeProp("Location")
    prop_media_link = lib_common.MakeProp("Media Link")

    try:
        lst_disks = sms.list_disks()
    except Exception as exc:
        lib_common.ErrorMessageHtml("Unexpected error:" + str(exc))

    for dsk in lst_disks:
        logging.debug("dsk=%s", str(dir(dsk)))
        node_disk = disk.MakeUri(dsk.name, subscription_name)
        grph.add((subscription_node, prop_disk, node_disk))
        grph.add((node_disk, lib_common.MakeProp("Size"), lib_util.NodeLiteral(dsk.logical_disk_size_in_gb)))

        url_disk = dsk.media_link
        grph.add((node_disk, prop_media_link, lib_common.NodeUrl(url_disk)))

        if dsk.affinity_group:
            aff_group = dsk.affinity_group
            grph.add((node_disk, lib_common.MakeProp("Affinity group"), lib_util.NodeLiteral(aff_group)))

        grph.add((node_disk, lib_common.MakeProp("Source image name"), lib_util.NodeLiteral(dsk.source_image_name)))
        grph.add((node_disk, lib_util.NodeLiteral("Operating System"), lib_util.NodeLiteral(dsk.os)))
        # grph.add((node_disk, lib_util.NodeLiteral("Hosted Service Name"),
        #          lib_util.NodeLiteral(dsk.hosted_service_name)))

        if dsk.is_corrupted:
            grph.add((node_disk, lib_util.NodeLiteral("Corrupted"), lib_util.NodeLiteral(dsk.is_corrupted)))

        grph.add((node_disk, lib_util.NodeLiteral("Label"), lib_util.NodeLiteral(dsk.label)))
        # grph.add((node_disk, lib_common.MakeProp("Affinity group"), lib_util.NodeLiteral("dsk.affinity_group")))
        logging.debug("dsk.attached_to=%s",str(dir(dsk.attached_to)))

        node_location = location.MakeUri(dsk.location, subscription_name)
        grph.add((node_disk, prop_disk_location, node_location))

    # cgiEnv.OutCgiRdf("LAYOUT_RECT",[prop_disk,prop_disk_location,prop_media_link])
    # cgiEnv.OutCgiRdf("LAYOUT_RECT",[prop_disk,prop_disk_location])
    # cgiEnv.OutCgiRdf("LAYOUT_RECT",[prop_disk])
    cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
Esempio n. 20
0
def Main():

    cgiEnv = lib_common.ScriptEnvironment()

    configNam = cgiEnv.GetId()

    nodeManager = survol_rabbitmq_manager.MakeUri(configNam)

    creds = lib_credentials.GetCredentials("RabbitMQ", configNam)

    # cl = Client('localhost:12345', 'guest', 'guest')
    cl = Client(configNam, creds[0], creds[1])

    grph = cgiEnv.GetGraph()

    # >>> cl.get_all_vhosts()
    # http://localhost:12345/api/vhosts
    # [{u'name': u'/', u'tracing': False, u'messages_details': {u'rate': 0.0}, u'messages': 0, u'message_stats': {u'deliver_no_ack': 0, u'
    # publish_out': 0, u'get_no_ack': 13, u'return_unroutable': 0, u'confirm': 0, u'deliver_get': 13, u'publish': 13, u'confirm_details':
    # {u'rate': 0.0}, u'ack_details': {u'rate': 0.0}, u'get': 0, u'deliver': 0, u'publish_out_details': {u'rate': 0.0}, u'redeliver_detail
    # s': {u'rate': 0.0}, u'deliver_details': {u'rate': 0.0}, u'deliver_get_details': {u'rate': 0.0}, u'publish_details': {u'rate': 0.0},
    # u'publish_in_details': {u'rate': 0.0}, u'ack': 0, u'publish_in': 0, u'return_unroutable_details': {u'rate': 0.0}, u'get_details': {u
    # 'rate': 0.0}, u'get_no_ack_details': {u'rate': 0.0}, u'deliver_no_ack_details': {u'rate': 0.0}, u'redeliver': 0}, u'messages_unackno
    # wledged_details': {u'rate': 0.0}, u'messages_ready_details': {u'rate': 0.0}, u'messages_unacknowledged': 0, u'messages_ready': 0}]

    try:
        #
        listVHosts = cl.get_all_vhosts()
    except Exception as exc:
        lib_common.ErrorMessageHtml("Caught:" + str(exc))

    for objVHost in listVHosts:
        namVHost = objVHost["name"]
        logging.debug("q=%s", namVHost)

        nodeVHost = survol_rabbitmq_vhost.MakeUri(configNam, namVHost)

        try:
            grph.add((nodeVHost, lib_common.MakeProp("tracing"),
                      lib_util.NodeLiteral(objVHost["tracing"])))
        except KeyError:
            pass

        try:
            grph.add((nodeVHost, lib_common.MakeProp("messages"),
                      lib_util.NodeLiteral(objVHost["messages"])))
        except KeyError:
            pass

        # http://127.0.0.1:12345/#/vhosts//
        managementUrl = rabbitmq.ManagementUrlPrefix(configNam, "vhosts",
                                                     namVHost)

        grph.add((nodeVHost, lib_common.MakeProp("Management"),
                  lib_common.NodeUrl(managementUrl)))

        grph.add((nodeManager, lib_common.MakeProp("Virtual host"), nodeVHost))

    cgiEnv.OutCgiRdf()
Esempio n. 21
0
def set_events_credentials():
    """This sets the global parameter telling where the events are stored."""
    storage_credential = lib_credentials.GetCredentials("Storage", "Events")
    if not storage_credential:
        credentials_filename = lib_credentials.credentials_filename()
        raise Exception("No storage credential in:%s" % credentials_filename)

    storage_style, storage_url = storage_credential
    lib_kbase.set_storage_style(storage_style, storage_url)
Esempio n. 22
0
def Main():

	cgiEnv = lib_common.CgiEnv( )

	instanceName = cgiEnv.m_entity_id_dict["Instance"]
	instanceNode = survol_mysql_instance.MakeUri(instanceName)

	(hostname,hostport) = survol_mysql.InstanceToHostPort(instanceName)

	cgiEnv = lib_common.CgiEnv()

	grph = cgiEnv.GetGraph()

	hostAddr = lib_util.GlobalGetHostByName(hostname)

	# BEWARE: The rule whether we use the host name or the host IP is not very clear !
	# The IP address would be unambiguous but less clear.
	hostNode = lib_common.gUriGen.HostnameUri(hostname)

	# BEWARE: This is duplicated.
	propDb = lib_common.MakeProp("Mysql database")

	aCred = lib_credentials.GetCredentials("MySql", instanceName)

	# If user/password incorrect, nothing we can do.
	try:
		aUser = aCred[0]
		connMysql = survol_mysql.MysqlConnect(instanceName,aUser,aPass=aCred[1])
	except :
		exc = sys.exc_info()
		lib_common.ErrorMessageHtml("Cannot connect to instance=%s user=%s:%s"%(instanceName,aUser,str(exc)))

	cursorMysql = connMysql.cursor()

	cursorMysql.execute("show databases")

	propDb = lib_common.MakeProp("Mysql database")

	grph.add( ( hostNode, lib_common.MakeProp("Mysql instance"), instanceNode ) )

	for dbInfo in cursorMysql:
		#('information_schema',)
		#('primhilltcsrvdb1',)
		sys.stderr.write("dbInfo=%s\n"%str(dbInfo))
		dbNam = dbInfo[0]

		nodeMysqlDatabase = survol_mysql_database.MakeUri(instanceName,dbNam)

		# Create a node for each database.
		grph.add( ( nodeMysqlDatabase, pc.property_user, lib_common.NodeLiteral(aCred[0]) ) )
		grph.add( ( instanceNode, propDb, nodeMysqlDatabase ) )

	cursorMysql.close()
	connMysql.close()

	cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
Esempio n. 23
0
def MakeOdbcConnectionStringFromDsn(dsnNam):
	pairUsrnamPass = lib_credentials.GetCredentials("ODBC",dsnNam)
	# With SqlServer, there is some implicit connection if this is the local machine.
	if pairUsrnamPass[0] == "":
		# Maybe we could add ";Trusted_Connection=yes"
		connectStr = "DSN=%s" % dsnNam
	else:
		connectStr = "DSN=%s;UID=%s;PWD=%s" % (dsnNam,pairUsrnamPass[0],pairUsrnamPass[1])

	return connectStr
Esempio n. 24
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    instance_name = cgiEnv.m_entity_id_dict["Instance"]
    instance_node = survol_mysql_instance.MakeUri(instance_name)

    hostname, hostport = survol_mysql.InstanceToHostPort(instance_name)

    cgiEnv = lib_common.ScriptEnvironment()

    grph = cgiEnv.GetGraph()

    # BEWARE: The rule whether we use the host name or the host IP is not very clear !
    # The IP address would be unambiguous but less clear.
    host_node = lib_uris.gUriGen.HostnameUri(hostname)

    prop_db = lib_common.MakeProp("Mysql database")

    a_cred = lib_credentials.GetCredentials("MySql", instance_name)

    # If user/password incorrect, nothing we can do.
    try:
        a_user = a_cred[0]
        conn_mysql = survol_mysql.MysqlConnect(instance_name,
                                               a_user,
                                               aPass=a_cred[1])
    except Exception as exc:
        lib_common.ErrorMessageHtml(
            "Cannot connect to instance=%s user=%s:%s" %
            (instance_name, a_user, str(exc)))

    cursor_mysql = conn_mysql.cursor()

    cursor_mysql.execute("show databases")

    grph.add((host_node, lib_common.MakeProp("Mysql instance"), instance_node))

    for db_info in cursor_mysql:
        #('information_schema',)
        #('primhilltcsrvdb1',)
        logging.debug("db_info=%s", str(db_info))
        db_nam = db_info[0]

        node_mysql_database = survol_mysql_database.MakeUri(
            instance_name, db_nam)

        # Create a node for each database.
        user_node = lib_uris.gUriGen.UserUri(a_cred[0])
        grph.add((node_mysql_database, pc.property_user, user_node))
        grph.add((instance_node, prop_db, node_mysql_database))

    cursor_mysql.close()
    conn_mysql.close()

    cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
Esempio n. 25
0
def Main():

    cgiEnv = lib_common.CgiEnv()

    configNam = cgiEnv.GetId()

    nodeManager = survol_rabbitmq_manager.MakeUri(configNam)

    creds = lib_credentials.GetCredentials("RabbitMQ", configNam)

    # cl = Client('localhost:12345', 'guest', 'guest')
    cl = Client(configNam, creds[0], creds[1])

    grph = cgiEnv.GetGraph()

    # cl.is_alive()

    #>>> cl.get_users()
    #[{u'hashing_algorithm': u'rabbit_password_hashing_sha256', u'name': u'guest', u'tags': u'administrator', u'password_hash': u'xxxxxx'}]
    try:
        #
        listUsers = cl.get_users()
    except:
        #
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Caught:" + str(exc))

    for objUser in listUsers:
        namUser = objUser["name"]
        DEBUG("q=%s", namUser)

        nodeUser = survol_rabbitmq_user.MakeUri(configNam, namUser)

        try:
            grph.add((nodeUser, lib_common.MakeProp("Tags"),
                      lib_common.NodeLiteral(objUser["tags"])))
        except KeyError:
            pass

        try:
            grph.add((nodeUser, lib_common.MakeProp("Hashing algorithm"),
                      lib_common.NodeLiteral(objUser["hashing_algorithm"])))
        except KeyError:
            pass

        # http://127.0.0.1:12345/#/users/guest
        managementUrl = rabbitmq.ManagementUrlPrefix(configNam, "users",
                                                     namUser)

        grph.add((nodeUser, lib_common.MakeProp("Management"),
                  lib_common.NodeUrl(managementUrl)))

        grph.add((nodeManager, lib_common.MakeProp("User"), nodeUser))

    cgiEnv.OutCgiRdf()
Esempio n. 26
0
def WbemConnection(cgi_url):
    """For the moment, it cannot connect to https:
    #https://github.com/Napsty/check_esxi_hardware/issues/7 """
    creden = lib_credentials.GetCredentials("WBEM", cgi_url)

    #if creden == ('', ''):
    #    raise Exception("WbemConnection: No credentials for %s" % cgi_url)

    logging.debug("WbemConnection creden=%s", str(creden))
    # Beware: If username/password is wrong, it will only be detected at the first data access.
    conn = pywbem.WBEMConnection(cgi_url, creden)
    return conn
Esempio n. 27
0
def WNetAddConnect(machine_name_no_backslash):
    # Nothing to do if this is the current machine.
    if not machine_name_no_backslash:
        return
    # "machine" or "Machine" ? Arp returns "Machine".
    usernam, passwd = lib_credentials.GetCredentials(
        "Login", machine_name_no_backslash)

    mach_nam_with_backslash = "\\\\" + machine_name_no_backslash

    win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_ANY, None,
                                 mach_nam_with_backslash, None, usernam,
                                 passwd, 0)
Esempio n. 28
0
def WbemConnection(cgiUrl):
    try:
        creden = lib_credentials.GetCredentials("WBEM", cgiUrl)

        # ATTENTION: Si probleme de connection, on ne le voit pas ici mais au moment du veritable acces.
        conn = pywbem.WBEMConnection(cgiUrl, creden)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Connecting to :" + cgiUrl + " Caught:" +
                                    str(exc) + "<br>")

    # TestCookie(url)
    return conn
Esempio n. 29
0
def Main():
	cgiEnv = lib_common.CgiEnv()

	# TODO: The subscription will become a parameter with a default value.
	# serviceName = cgiEnv.GetId()
	diskName = cgiEnv.m_entity_id_dict["Disk"]

	# TODO: This should be a parameter.
	subscriptionName = cgiEnv.m_entity_id_dict["Subscription"]
	# subscriptionName=Azure.DefaultSubscription()

	grph = cgiEnv.GetGraph()

	(subscription_id,certificate_path) = lib_credentials.GetCredentials( "Azure", subscriptionName )

	sms = ServiceManagementService(subscription_id, certificate_path)

	subscriptionNode = subscription.MakeUri( subscriptionName )

	dsk = sms.get_disk(diskName)

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

	diskNode = disk.MakeUri( diskName, subscriptionName )
	grph.add( ( subscriptionNode, lib_common.MakeProp("Service"), diskNode ) )

	# grph.add( ( diskNode, lib_common.MakeProp("xxx"), lib_common.NodeLiteral(str(dir(dsk))) ) )

	grph.add( ( diskNode, lib_common.MakeProp("affinity_group"), lib_common.NodeLiteral(dsk.affinity_group)))
	# grph.add( ( diskNode, lib_common.MakeProp("attached_to"), lib_common.NodeLiteral(str(dir(dsk.attached_to)))) )
	grph.add( ( diskNode, lib_common.MakeProp("has_operating_system"), lib_common.NodeLiteral(dsk.has_operating_system)))
	grph.add( ( diskNode, lib_common.MakeProp("is_corrupted"), lib_common.NodeLiteral(dsk.is_corrupted)) )
	grph.add( ( diskNode, lib_common.MakeProp("label"), lib_common.NodeLiteral(dsk.label)) )
	grph.add( ( diskNode, lib_common.MakeProp("Size"), lib_common.NodeLiteral(dsk.logical_disk_size_in_gb)))
	grph.add( ( diskNode, lib_common.MakeProp("name"), lib_common.NodeLiteral(dsk.name)))
	grph.add( ( diskNode, lib_common.MakeProp("os"), lib_common.NodeLiteral(dsk.os)))
	grph.add( ( diskNode, lib_common.MakeProp("source_image_name"), lib_common.NodeLiteral(dsk.source_image_name)))
	grph.add( ( diskNode, lib_common.MakeProp("media link"), lib_common.NodeUrl(dsk.media_link)))

	locaNode = location.MakeUri( dsk.location, subscriptionName )
	grph.add( ( diskNode, lib_common.MakeProp("Location"), locaNode ) )

	srvNode = service.MakeUri( dsk.attached_to.hosted_service_name, subscriptionName )
	grph.add( ( srvNode, lib_common.MakeProp("Role"), lib_common.NodeLiteral(dsk.attached_to.role_name) ) )
	grph.add( ( srvNode, lib_common.MakeProp("Deployment"), lib_common.NodeLiteral(dsk.attached_to.deployment_name) ) )
	grph.add( ( diskNode, lib_common.MakeProp("Service"), srvNode ) )

	# media_link

	cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
Esempio n. 30
0
def WNetAddConnect(machineNameNoBackslash):
    # Nothing to do if this is the current machine.
    if not machineNameNoBackslash:
        return
    # "titi" ou "Titi" ? Arp retourne "Titi".
    (usernam, passwd) = lib_credentials.GetCredentials("Login",
                                                       machineNameNoBackslash)

    # 	"Titi":["titi\\[email protected]", "trxxxxxxa"],

    machNamWithBackslash = "\\\\" + machineNameNoBackslash

    ## CA MARCHE !!!!!!!!
    win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_ANY, None,
                                 machNamWithBackslash, None, usernam, passwd,
                                 0)