Ejemplo n.º 1
0
def on_queue_message(msgQ):
    try:
        json_input = json.loads(
            xml2json.xml2json(msgQ['msg']['#text'],
                              XML2JsonOptions(),
                              strip_ns=1,
                              strip=1))
    except:
        logger.exception('can not process queue message: %s' % msgQ)
        return False

    if 'offlineUpdate' in json_input:
        try:
            domain = str(json_input['offlineUpdate']['domain']['name'])
            change = str(json_input['offlineUpdate']['domain']['change'])
            details = str(json_input['offlineUpdate']['domain']['details'])
        except:
            logger.exception('can not process queue json message: %s' %
                             json_input)
            return False

        if change == 'TRANSFER':
            if details.lower() == 'domain transferred away':
                return do_domain_transfer_away(domain)

            if details.lower() == 'domain transferred':
                return do_domain_transfer_to_us(domain)

        if change == 'DELETION':
            if details.lower() == 'domain deleted':
                return do_domain_deleted(domain)
            if details.lower() == 'domain pending delete' or details.lower(
            ) == 'domain pending deletion':
                return do_domain_status_changed(domain)

        if change == 'RESTORED':
            if details.lower() in [
                    'domain restored',
                    'domain restored via ui',
            ]:
                return do_domain_status_changed(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'STATE_CHANGE':
            if details.lower() == 'domain status updated':
                return do_domain_status_changed(domain)
            if details.lower() == 'domain activated':
                return do_domain_status_changed(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'EXCLUSION':
            if details.lower() == 'domain excluded':
                return do_domain_status_changed(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'SUSPENSION':
            if details.lower() == 'domain suspended':
                return do_domain_status_changed(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'DETAILS_CHANGED':
            if details.lower() == 'domain expiry date updated':
                return do_domain_expiry_date_updated(domain)
            if details.lower() == 'domain create date modified':
                return do_domain_create_date_updated(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'CONTACTS_CHANGED':
            return do_domain_contacts_changed(domain)

        if change == 'NAMESERVERS_CHANGED':
            return do_domain_nameservers_changed(domain)

        if change == 'UNKNOWN':
            if details.lower().count('domain epp statuses updated'):
                return do_domain_status_changed(domain)
            if details.lower() == 'none':
                return do_domain_transfer_away(domain)

    logger.error('UNKNOWN message: %s' % json_input)
    return False
Ejemplo n.º 2
0
def on_queue_message(msgQ):
    try:
        json_input = json.loads(
            xml2json.xml2json(msgQ['msg']['#text'],
                              XML2JsonOptions(),
                              strip_ns=1,
                              strip=1))
    except:
        logger.exception('can not process queue message: %s' % msgQ)
        return False

    if 'offlineUpdate' in json_input:
        try:
            domain = str(json_input['offlineUpdate']['domain']['name'])
            change = str(json_input['offlineUpdate']['domain']['change'])
            details = str(json_input['offlineUpdate']['domain']['details'])
        except:
            logger.exception('can not process queue json message: %s' %
                             json_input)
            return False

        if change == 'TRANSFER':
            if details.lower() == 'domain transferred away':
                return do_domain_transfer_away(domain)

            if details.lower() == 'domain transferred':
                return do_domain_transfer_in(domain)

        if change == 'DELETION':
            if details.lower() == 'domain deleted':
                return do_domain_deleted(domain)
            if details.lower() == 'domain pending delete' or details.lower(
            ) == 'domain pending deletion':
                return do_domain_status_changed(domain)

        if change == 'RENEWAL':
            return do_domain_renewal(domain)

        if change == 'RESTORED':
            if details.lower() in [
                    'domain restored',
                    'domain restored via ui',
            ]:
                return do_domain_status_changed(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'STATE_CHANGE':
            if details.lower() == 'domain status updated':
                return do_domain_status_changed(domain)
            if details.lower() == 'domain activated':
                return do_domain_status_changed(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'EXCLUSION':
            if details.lower() == 'domain excluded':
                return do_domain_status_changed(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'SUSPENSION':
            if details.lower() == 'domain suspended':
                return do_domain_status_changed(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'DETAILS_CHANGED':
            if details.lower() == 'domain expiry date updated':
                return do_domain_expiry_date_updated(domain)
            if details.lower() == 'domain create date modified':
                return do_domain_create_date_updated(domain)
            # TODO: domain to be sync, check other scenarios ?

        if change == 'CONTACTS_CHANGED':
            return do_domain_contacts_changed(domain)

        if change == 'NAMESERVERS_CHANGED':
            return do_domain_nameservers_changed(domain)

        if change == 'STATE_CHANGE':
            if details.lower() == 'domain deleted':
                return do_domain_deleted(domain)
            if details.lower().count('addperiod_grace'):
                logger.debug('SKIP message: %r', json_input)
                return True
            if details.lower().count('redemption_period'):
                logger.debug('SKIP message: %r', json_input)
                return True

        if change == 'UNKNOWN':
            if details.lower().count('domain epp statuses updated'):
                return do_domain_status_changed(domain)
            # TODO: found that when you change domain auth code directly on backend epp messages coming to Zenaida like that:
            # {'offlineUpdate': {'domain': {'name': 'lala.ai', 'change': 'UNKNOWN', 'details': None}}}
            # need to ask guys from COCCA about that...
            if not details or details.lower() == 'none':
                # for now we can try to do a simple domain sync to at least try to solve the most issues
                return do_domain_change_unknown(domain)

    logger.error('UNKNOWN poll message: %s' % json_input)
    return False
Ejemplo n.º 3
0
def run(json_request, raise_for_result=True, unserialize=True, logs=True):
    try:
        json_input = json.dumps(json_request)
    except Exception as exc:
        logger.error('epp request failed, invalid json input')
        raise zerrors.EPPBadResponse('epp request failed, invalid json input')

    if logs:
        logger.info('>>> %s\n' % json_input)

    try:
        out = do_rpc_request(json_request)
    except zerrors.EPPError as exc:
        logger.error('epp request failed with known error: %s' % exc)
        raise exc
    except Exception as exc:
        logger.error('epp request failed, unexpected error: %s' %
                     traceback.format_exc())
        raise zerrors.EPPBadResponse('epp request failed: %s' % exc)

    if not out:
        logger.error('empty response from epp_gate, connection error')
        raise zerrors.EPPBadResponse(
            'epp request failed: empty response, connection error')

    json_output = None
    if unserialize:
        try:
            try:
                json_output = json.loads(
                    xml2json.xml2json(out,
                                      XML2JsonOptions(),
                                      strip_ns=1,
                                      strip=1))
            except UnicodeEncodeError:
                json_output = json.loads(
                    xml2json.xml2json(out.encode('ascii', errors='ignore'),
                                      XML2JsonOptions(),
                                      strip_ns=1,
                                      strip=1))
        except Exception as exc:
            logger.error('epp response unserialize failed: %s' %
                         traceback.format_exc())
            raise zerrors.EPPBadResponse(
                'epp response unserialize failed: %s' % exc)

    if raise_for_result:
        if json_output:
            try:
                code = json_output['epp']['response']['result']['@code']
                msg = json_output['epp']['response']['result']['msg'].replace(
                    'Command failed;', '')
            except:
                if logs:
                    logger.error('bad formatted response: ' + json_output)
                raise zerrors.EPPBadResponse(
                    'bad formatted response, response code not found')
            good_response_codes = [
                '1000',
            ]
            if True:  # just to be able to debug poll script packets
                good_response_codes.extend([
                    '1300',
                    '1301',
                ])
            if code not in good_response_codes:
                if logs:
                    logger.error('response code failed: ' +
                                 json.dumps(json_output, indent=2))
                raise zerrors.EPPResponseFailed(message=msg, code=code)
        else:
            if out.count('Command completed successfully') == 0:
                if logs:
                    logger.error('response message failed: ' +
                                 json.dumps(json_output, indent=2))
                raise zerrors.EPPResponseFailed('Command failed')

    if logs:
        logger.info('<<< %s\n' % json.dumps(json_output, indent=2))

    return json_output or out