def testFunction(domain_url):

    view = {"domain_url":domain_url}

    if ( domainNameLookup(domain_url)[0] != 0 ):
        view["warning"] = "%s not found!" % (domain_url)
        return warning(view)

    (status, b, m, answers) = xmppServerServiceRecordLookup(domain_url)
    if ( status != 0 ):
        wiew["warning"] = "XMPP Server of domain %s not found!" % (domain_url)
        return warning(view)

    xmpp = sleekxmpp.ClientXMPP("*****@*****.**", "ei3tseq")

    situation = {}

    for answer in answers:

        conn_address = answer["domain"], answer["port"]
        view["xmpp_server"] = conn_address[0]

        if ( not xmpp.connect(conn_address, reattempt=False, use_ssl=False, use_tls=False) ):
             situation[conn_address] = make_output_builder(view,
                 xmpp_connection_problem)
             continue

        xmpp.process(block=False)

        try:
            DISCO_ITEMS_NS = 'http://jabber.org/protocol/disco#items'
            iq = xmpp.make_iq_get(queryxmlns=DISCO_ITEMS_NS,
                ito=domain_url, ifrom=xmpp.boundjid)

            try:
                view["disco_type"] = "disco#items"
                response = iq.send(block=True, timeout=5)
            except Exception as e:
                if ( str(e) != "" ):
                    view["error"] = str(e)
                situation[conn_address] = make_output_builder(view,
                    xmpp_disco_query_send_error)
                continue

            if ( len(response.xml.findall("iq[@type='error']")) != 0 ):
                view["error"] = response.xml.findall("iq[@type='error']")[0]
                situation[conn_address] = make_output_builder(view,
                    xmpp_server_error)
                continue

            its = response.xml.findall(
                "{%s}query/{%s}item" % ((DISCO_ITEMS_NS,)*2))
            for item in its:
                item_jid = item.attrib['jid']

                DISCO_INFO_NS = 'http://jabber.org/protocol/disco#info'
                iq = xmpp.make_iq_get(queryxmlns=DISCO_INFO_NS,
                    ito=item_jid, ifrom=xmpp.boundjid)

                try:
                    view["disco_type"] = "disco#info"
                    response = iq.send(block=True, timeout=5)
                except Exception as e:
                    if ( str(e) != "" ):
                        view["error"] = str(e)
                    situation[conn_address] = make_output_builder(view,
                        xmpp_disco_query_send_error)
                    continue

                if ( len(response.xml.findall("iq[@type='error']")) != 0 ):
                    view["error"] = response.xml.findall("iq[@type='error']")[0]
                    situation[conn_address] = make_output_builder(view,
                        xmpp_server_error)
                    continue

                ids = response.xml.findall(
                    "{%s}query/{%s}identity" % ((DISCO_INFO_NS,)*2))
                for identity in ids:
                    identity_category = identity.attrib['category']
                    identity_type = identity.attrib['type']

                    view["discovery"] = True
                    view["channel_server"] = item_jid
                    if ( identity_category == 'pubsub'
                        and identity_type == 'channels' ):

                        try:
                            resolver = dns.resolver.Resolver()
                            nameserver = getAuthoritativeNameserver(domain_url)
                            resolver.nameservers = [nameserver]
                            resolver.lifetime = 5
                            PTR_name = "_buddycloud-server._tcp." + domain_url
                            answer = resolver.query(PTR_name, dns.rdatatype.PTR)
                        except Exception:
                            pass
                        else:
                            #TODO check if PTR record and DISCO are pointing
                            # to the same place -- they must!
                            view["ptr_record"] = True
                        return is_buddycloud_enabled(view)

            if not conn_address in situation:
                situation[conn_address] = make_output_builder(view,
                    not_buddycloud_enabled)

        finally:
            xmpp.disconnect()

    try:
        resolver = dns.resolver.Resolver()
        nameserver = getAuthoritativeNameserver(domain_url)
        resolver.nameservers = [nameserver]
        resolver.lifetime = 5
        PTR_name = "_buddycloud-server._tcp." + domain_url
        answer = resolver.query(PTR_name, dns.rdatatype.PTR)
    except (NXDOMAIN, NoAnswer, Timeout):
        pass
    except Exception:
        pass
    else:
        view["ptr_record"] = True
        #view["channel_server"] = answer
        return is_buddycloud_enabled(view)

    if ( len(situation) == 1 ):
       return situation[situation.keys()[0]]() 

    view["xmpp_servers"] = []

    status = 2
    for xmpp_server in situation:
        output = situation[xmpp_server]()
        if ( output[0] == 1 ):
            status = 1
        view["xmpp_servers"].append({
            "name" : "%s through port %s" %(xmpp_server),
            "error" : output[2]
        })

    view["status"] = status

    return multiple_problems(view)
def testFunction(domain_url):

	(status, briefing, message, output) = domainNameLookup(domain_url)
	if ( status != 0 ):
		return (status, briefing, message, None)

	classified_as = checkBuddycloudCompatibility(domain_url)

	description =  descriptions[classified_as] % ("<strong>"+domain_url+"</strong>")
	briefing = description.split("<br/>")[0]
	message = description

	if ( classified_as == "BUDDYCLOUD_ENABLED" ):
		status = 0
	elif ( classified_as == "SERVER_ERROR"
	    or classified_as == "NOT_BUDDYCLOUD_ENABLED" ):
		status = 1

		(sts, brf, mes, out) = buddycloudChannelSRVLookup(domain_url)
		if ( sts != 0 ):

			message += "<br/>You need to set up a SRV record "
			
			(sts2, brf2, mes2, xmpp_server_names) = xmppServerServiceRecordLookup(domain_url)
			if ( sts2 != 0 ):

				message += "similar to the following:"
				message += "<br/><br/><em>(assuming your XMPP server is called"
				message += " <strong>bc.%s</strong>)</em><br/>" % domain_url
				message += "<strong>_xmpp-server._tcp.channels." + domain_url + "."
				message += "\tSRV\t5\t0\t5269\tbc.%s.</strong>" % domain_url

			else:
				message += "exactly like the following:"
				
				if ( len(xmpp_server_names) > 1 ):
					message += " (only one of them)"

				message += "<br/><br/>"

				for xmpp_server in xmpp_server_names:

					xmpp_server = xmpp_server['domain']
					message += "<strong>_xmpp-server._tcp.channels.%s." %domain_url
					message += "\tSRV\t5\t0\t5269\t%s.<br/><br/></strong>" %xmpp_server

		else:

			message += "<br/>Please ensure your buddycloud channel server is running "
			message += "at <strong>%s</strong> and if that's not the case, run:<br/>" % domain_url
			message += "<br/><strong>sudo /etc/init.d/buddycloud-server"
			message += " start</strong><br/><br/>...to start your buddycloud channel server.<br/>"
			message += "See more information at <a href='https://buddycloud.org/wiki/Install"
			message += "#buddycloud_Channel_Server' target='_blank'>"
			message += "https://buddycloud.org/wiki/Install#buddycloud_Channel_Server</a>."
	else:
		status = 2

		(sts, brf, mes, out) = xmppServerConnection(domain_url)
		if ( sts != 0 ):

			status = 1
			message = briefing + "<br/>"
			message += "Reason: <br/>"
			message += mes
			return (status, briefing, message, None)

	return (status, briefing, message, None)
示例#3
0
def testFunction(domain_url):

	answers = []
	skipped = {}

	status, briefing, message, server_srvs = xmppServerServiceRecordLookup(domain_url)
	if ( status != 0 ):
		skipped["xmpp_server_srv_lookup"] = message
	else:
		answers += server_srvs

#	status, briefing, message, client_srvs = xmppClientServiceRecordLookup(domain_url)
#	if ( status != 0 ):
#		skipped["xmpp_client_srv_lookup"] = message
#	else:
#		answers += client_srvs

#	if ( len(skipped.keys()) == 2 ):
	if ( len(skipped.keys()) == 1 ):
		return doSkip(skipped)


	classified = { 'A' : [], 'CNAME' : [] }
	domainsPointedBySRV = {}

	for answer in answers:

		domainsPointedBySRV[answer['domain']] = True

		answer_classified = classifyDomainByRecord(answer['domain'])
		
		if ( answer_classified['type'] == 'NONEXISTENT' ):
			continue

		elif ( answer_classified['type'] == 'PROBLEM' ):

			status = 2
			briefing = "A problem happened while searching for the " + answer_classified['name'] + ": "
			briefing += answer['domain'] + "!"
			message = "Something odd happened while we were searching for the "
			message += answer_classified['name'] + ": " + answer['domain'] + "!"
			message += "<br/>This is the exception we got: {"+str(e)+"}"
			message += "<br/>It is probably a temporary issue with domain " + domain_url + "."
			message += "<br/>But it could also be a bug in our Inspector."
			message += " Let us know at <a href='https://github.com/buddycloud/buddycloud-tests-framework/issues'>our issue tracker</a> if you think so." 
			return (status, briefing, message, None)

		answer_classified['port'] = answer['port']

		classified[answer_classified['type']].append(answer_classified)

	domainsPointedBySRV = domainsPointedBySRV.keys()

	if ( len(classified['A']) == 0 ):

		status = 1
		briefing = "No XMPP server A record found!"
		message = "There is no A record being pointed by your XMPP SRV record."
		message += suggestPossibleARecords(domain_url, domainsPointedBySRV)
		message += "<br/>Check at <a href='http://buddycloud.org/wiki/Install#buddycloud_DNS'"
		message += " target='_blank'>http://buddycloud.org/wiki/Install#buddycloud_DNS</a>"
		message += " for more information on how to setup the DNS for your domain."
		return (status, briefing, message, None)


	if ( len(classified['CNAME']) != 0 ):

		CNAME_records = []

		for categorized in classified['CNAME']:
			answers = categorized['addresses']
			for answer in answers:
				CNAME_record = "buddycloud." + categorized['domain'] + " IN CNAME " + str(answer)
				CNAME_records.append(CNAME_record)

		status = 1
		briefing = "There is a XMPP server SRV record pointing to a <strong>CNAME record</strong>!"
		briefing += "<br/>Should be to an <strong>A record</strong> instead."
		message = "We found a CNAME record pointing to your XMPP SRV record."
		message += "<br/>You MUST NOT have these in your DNS.<br/>"
		message += "<strong><br/>" + string.join(CNAME_records, "<br/>") + "<br/></strong>"		
		message += "<br/>Instead, you should have A records being pointed by your XMPP SRV record."
		message += suggestPossibleARecords(domain_url, domainsPointedBySRV)
		message += "<br/>Check at <a href='http://buddycloud.org/wiki/Install#buddycloud_DNS'"
		message += " target='_blank'>http://buddycloud.org/wiki/Install#buddycloud_DNS</a>"
		message += " for more information on how to setup the DNS for your domain."
		return (status, briefing, message, None)


	if ( len(classified['A']) != 0 ):
		
		addresses = []
		A_records = []
		
		for categorized in classified['A']:
			answers = categorized['addresses']
			for answer in answers:

				A_record = categorized['domain'] + " IN A " + str(answer)
				if not A_record in A_records:
					A_records.append(A_record)

				addresses.append({
					'domain' : categorized['domain'],
					'address' : str(answer),
					'port' : categorized['port']
				})

		status = 0
		briefing = "XMPP server A records found: "
		briefing += "<strong>" + string.join(A_records, " | ") + "</strong>"
		message = "Congratulations! You've set up your A records appropriately."
		message += "<br/>You are pointing your XMPP server SRV records to the following valid A records: <br/>"
		message += "<strong><br/>" + string.join(A_records, "<br/>") + "<br/></strong>"
		message += "<br/>Now, we expect that at least one of them is leading us to your buddycloud server."
		return (status, briefing, message, addresses)
def testFunction(domain_url):

    answers = []
    skipped = {}

    status, briefing, message, server_srvs = xmppServerServiceRecordLookup(domain_url)
    if status != 0:
        skipped["xmpp_server_srv_lookup"] = message
    else:
        answers += server_srvs

    if len(skipped.keys()) == 1:
        return doSkip(skipped)

    classified = {"A": [], "CNAME": []}
    domainsPointedBySRV = {}

    for answer in answers:

        domainsPointedBySRV[answer["domain"]] = True

        answer_classified = classifyDomainByRecord(answer["domain"])

        if answer_classified["type"] == "NONEXISTENT":
            continue

        elif answer_classified["type"] == "PROBLEM":

            status = 2
            briefing = "A problem happened while searching for the " + answer_classified["name"] + ": "
            briefing += answer["domain"] + "!"
            message = "Something odd happened while we were searching for the "
            message += answer_classified["name"] + ": " + answer["domain"] + "!"
            message += "<br/>This is the exception we got: {" + answer_classified["value"] + "}"
            message += "<br/>It is probably a temporary issue with domain " + domain_url + "."
            message += "<br/>But it could also be a bug in our Inspector."
            message += " Let us know at <a href='https://github.com/buddycloud/buddycloud-tests-framework/issues'>our issue tracker</a> if you think so."
            return (status, briefing, message, None)

        answer_classified["port"] = answer["port"]

        classified[answer_classified["type"]].append(answer_classified)

    domainsPointedBySRV = domainsPointedBySRV.keys()

    if len(classified["A"]) == 0:

        status = 1
        briefing = "No XMPP server A record found!"
        message = "There is no A record being pointed by your XMPP SRV record."
        message += suggestPossibleARecords(domain_url, domainsPointedBySRV)
        message += "<br/>Check at <a href='http://buddycloud.org/wiki/Install#buddycloud_DNS'"
        message += " target='_blank'>http://buddycloud.org/wiki/Install#buddycloud_DNS</a>"
        message += " for more information on how to setup the DNS for your domain."
        return (status, briefing, message, None)

    if len(classified["CNAME"]) != 0:

        CNAME_records = []

        for categorized in classified["CNAME"]:
            answers = categorized["addresses"]
            for answer in answers:
                CNAME_record = "buddycloud." + categorized["domain"] + " IN CNAME " + str(answer)
                CNAME_records.append(CNAME_record)

        status = 1
        briefing = "There is a XMPP server SRV record pointing to a <strong>CNAME record</strong>!"
        briefing += "<br/>Should be to an <strong>A record</strong> instead."
        message = "We found a CNAME record pointing to your XMPP SRV record."
        message += "<br/>You MUST NOT have these in your DNS.<br/>"
        message += "<strong><br/>" + string.join(CNAME_records, "<br/>") + "<br/></strong>"
        message += "<br/>Instead, you should have A records being pointed by your XMPP SRV record."
        message += suggestPossibleARecords(domain_url, domainsPointedBySRV)
        message += "<br/>Check at <a href='http://buddycloud.org/wiki/Install#buddycloud_DNS'"
        message += " target='_blank'>http://buddycloud.org/wiki/Install#buddycloud_DNS</a>"
        message += " for more information on how to setup the DNS for your domain."
        return (status, briefing, message, None)

    if len(classified["A"]) != 0:

        addresses = []
        A_records = []

        for categorized in classified["A"]:
            answers = categorized["addresses"]
            for answer in answers:

                A_record = categorized["domain"] + " IN A " + str(answer)
                if not A_record in A_records:
                    A_records.append(A_record)

                addresses.append({"domain": categorized["domain"], "address": str(answer), "port": categorized["port"]})

        status = 0
        briefing = "XMPP server A records found: "
        briefing += "<strong>" + string.join(A_records, " | ") + "</strong>"
        message = "Congratulations! You've set up your A records appropriately."
        message += "<br/>You are pointing your XMPP server SRV records to the following valid A records: <br/>"
        message += "<strong><br/>" + string.join(A_records, "<br/>") + "<br/></strong>"
        message += "<br/>Now, we expect that at least one of them is leading us to your buddycloud server."
        return (status, briefing, message, addresses)
def testFunction(domain_url):

    view = {"domain_url": domain_url}

    if (domainNameLookup(domain_url)[0] != 0):
        view["warning"] = "%s not found!" % (domain_url)
        return warning(view)

    (status, b, m, answers) = xmppServerServiceRecordLookup(domain_url)
    if (status != 0):
        wiew["warning"] = "XMPP Server of domain %s not found!" % (domain_url)
        return warning(view)

    xmpp = sleekxmpp.ClientXMPP("*****@*****.**", "ei3tseq")

    situation = {}

    for answer in answers:

        conn_address = answer["domain"], answer["port"]
        view["xmpp_server"] = conn_address[0]

        if (not xmpp.connect(
                conn_address, reattempt=False, use_ssl=False, use_tls=False)):
            situation[conn_address] = make_output_builder(
                view, xmpp_connection_problem)
            continue

        xmpp.process(block=False)

        try:
            DISCO_ITEMS_NS = 'http://jabber.org/protocol/disco#items'
            iq = xmpp.make_iq_get(queryxmlns=DISCO_ITEMS_NS,
                                  ito=domain_url,
                                  ifrom=xmpp.boundjid)

            try:
                view["disco_type"] = "disco#items"
                response = iq.send(block=True, timeout=5)
            except Exception as e:
                if (str(e) != ""):
                    view["error"] = str(e)
                situation[conn_address] = make_output_builder(
                    view, xmpp_disco_query_send_error)
                continue

            if (len(response.xml.findall("iq[@type='error']")) != 0):
                view["error"] = response.xml.findall("iq[@type='error']")[0]
                situation[conn_address] = make_output_builder(
                    view, xmpp_server_error)
                continue

            its = response.xml.findall("{%s}query/{%s}item" %
                                       ((DISCO_ITEMS_NS, ) * 2))
            for item in its:
                item_jid = item.attrib['jid']

                DISCO_INFO_NS = 'http://jabber.org/protocol/disco#info'
                iq = xmpp.make_iq_get(queryxmlns=DISCO_INFO_NS,
                                      ito=item_jid,
                                      ifrom=xmpp.boundjid)

                try:
                    view["disco_type"] = "disco#info"
                    response = iq.send(block=True, timeout=5)
                except Exception as e:
                    if (str(e) != ""):
                        view["error"] = str(e)
                    situation[conn_address] = make_output_builder(
                        view, xmpp_disco_query_send_error)
                    continue

                if (len(response.xml.findall("iq[@type='error']")) != 0):
                    view["error"] = response.xml.findall(
                        "iq[@type='error']")[0]
                    situation[conn_address] = make_output_builder(
                        view, xmpp_server_error)
                    continue

                ids = response.xml.findall("{%s}query/{%s}identity" %
                                           ((DISCO_INFO_NS, ) * 2))
                for identity in ids:
                    identity_category = identity.attrib['category']
                    identity_type = identity.attrib['type']

                    view["discovery"] = True
                    view["channel_server"] = item_jid
                    if (identity_category == 'pubsub'
                            and identity_type == 'channels'):

                        try:
                            resolver = dns.resolver.Resolver()
                            nameserver = getAuthoritativeNameserver(domain_url)
                            resolver.nameservers = [nameserver]
                            resolver.lifetime = 5
                            PTR_name = "_buddycloud-server._tcp." + domain_url
                            answer = resolver.query(PTR_name,
                                                    dns.rdatatype.PTR)
                        except Exception:
                            pass
                        else:
                            #TODO check if PTR record and DISCO are pointing
                            # to the same place -- they must!
                            view["ptr_record"] = True
                        return is_buddycloud_enabled(view)

            if not conn_address in situation:
                situation[conn_address] = make_output_builder(
                    view, not_buddycloud_enabled)

        finally:
            xmpp.disconnect()

    try:
        resolver = dns.resolver.Resolver()
        nameserver = getAuthoritativeNameserver(domain_url)
        resolver.nameservers = [nameserver]
        resolver.lifetime = 5
        PTR_name = "_buddycloud-server._tcp." + domain_url
        answer = resolver.query(PTR_name, dns.rdatatype.PTR)
    except (NXDOMAIN, NoAnswer, Timeout):
        pass
    except Exception:
        pass
    else:
        view["ptr_record"] = True
        #view["channel_server"] = answer
        return is_buddycloud_enabled(view)

    if (len(situation) == 1):
        return situation[situation.keys()[0]]()

    view["xmpp_servers"] = []

    status = 2
    for xmpp_server in situation:
        output = situation[xmpp_server]()
        if (output[0] == 1):
            status = 1
        view["xmpp_servers"].append({
            "name":
            "%s through port %s" % (xmpp_server),
            "error":
            output[2]
        })

    view["status"] = status

    return multiple_problems(view)