Пример #1
0
 def doDBCheckChangeOwner(self, *args, **kwargs):
     """
     Action method.
     """
     if not self.target_domain:
         return
     # update registrant of the domain if it is known
     if self.target_domain.registrant != self.known_registrant:
         if not self.change_owner_allowed:
             self.event(
                 'error',
                 zerrors.EPPRegistrantAuthFailed(
                     'domain already have another registrant in local DB'))
             return
         logger.info('domain %r going to switch registrant %r to %r',
                     self.target_domain, self.target_domain.registrant,
                     self.known_registrant)
         zdomains.domain_change_registrant(self.target_domain,
                                           self.known_registrant)
     # make sure owner of the domain is correct
     if self.target_domain.owner != self.known_registrant.owner:
         # just in case given user have multiple registrant contacts...
         if not self.change_owner_allowed:
             self.event(
                 'error',
                 zerrors.EPPRegistrantAuthFailed(
                     'domain already have another owner in local DB'))
             return
         logger.info('domain %r going to switch owner %r to %r',
                     self.target_domain, self.target_domain.owner,
                     self.known_registrant.owner)
         zdomains.domain_change_owner(self.target_domain,
                                      self.known_registrant.owner)
Пример #2
0
 def doEppDomainInfo(self, *args, **kwargs):
     """
     Action method.
     """
     if self.skip_info:
         self.check_results = {dn: (dn in self.existing_domains) for dn in self.target_domain_names}
         self.event('skip-info')
         return
     try:
         response = zclient.cmd_domain_info(
             domain=self.current_domain_name,
         )
     except zerrors.EPPError as exc:
         self.log(self.debug_level, 'Exception in doEppDomainInfo: %s' % exc)
         self.event('error', exc)
     else:
         if self.verify_registrant:
             known_domain = zdomains.domain_find(domain_name=self.current_domain_name)
             known_registrant_epp_id = None if not known_domain else known_domain.registrant.epp_id
             real_registrant_epp_id = response['epp']['response']['resData']['infData'].get('registrant', None)
             if real_registrant_epp_id and known_registrant_epp_id and known_registrant_epp_id != real_registrant_epp_id:
                 logger.warn('domain %s suppose to belong to another registrant: %r, but received another id: %r', 
                              self.current_domain_name, known_registrant_epp_id, real_registrant_epp_id)
                 self.event('error', zerrors.EPPRegistrantAuthFailed(response=response))
                 return
         self.check_results[self.current_domain_name] = True
         self.event('response', response)
Пример #3
0
 def doVerifyRegistrant(self, *args, **kwargs):
     """
     Action method.
     """
     if not self.verify_registrant:
         return
     self.registrant_epp_id = args[0]['epp']['response']['resData']['infData'].get('registrant', None)
     if not self.registrant_epp_id:
         logger.error('domain registrant unknown from response: %s' % self.target_domain.name)
         self.event('error', zerrors.EPPRegistrantUnknown(response=args[0]))
         return
     known_domain = zdomains.domain_find(domain_name=self.target_domain.name)
     if not known_domain:
         return
     if known_domain.registrant.epp_id == self.registrant_epp_id:
         return
     logger.error('domain known to belong to another registrant: %s' % self.current_domain_name)
     self.event('error', zerrors.EPPRegistrantAuthFailed(response=args[0]))
Пример #4
0
 def doDBCheckCreateUpdateContacts(self, *args, **kwargs):
     """
     Action method.
     """
     if self.rewrite_contacts:
         return
     received_contacts_info = args[0]
     # even if domain not exist yet make sure all contacts really exists in DB and in sync with back-end
     for role in [
             'admin',
             'billing',
             'tech',
     ]:
         received_contact_id = received_contacts_info.get(
             role, {
                 'id': None,
             })['id']
         if not received_contact_id:
             continue
         existing_contact = zcontacts.by_epp_id(epp_id=received_contact_id)
         if existing_contact:
             if existing_contact.owner != self.known_registrant.owner:
                 logger.error(
                     'existing contact have another owner in local DB')
                 self.event(
                     'error',
                     zerrors.EPPRegistrantAuthFailed(
                         'existing contact have another owner in local DB'))
                 return
             zcontacts.contact_refresh(
                 epp_id=received_contact_id,
                 contact_info_response=received_contacts_info[role]
                 ['response'],
             )
         else:
             zcontacts.contact_create(
                 epp_id=received_contact_id,
                 owner=self.known_registrant.owner,
                 contact_info_response=received_contacts_info[role]
                 ['response'],
             )
Пример #5
0
    def doEppDomainInfo(self, *args, **kwargs):
        """
        Action method.
        """
        try:
            response = zclient.cmd_domain_info(
                domain=self.domain_name,
                raise_for_result=False,
            )
        except zerrors.EPPError as exc:
            self.log(self.debug_level,
                     'Exception in doEppDomainInfo: %s' % exc)
            self.event('error', exc)
            return

        # catch "2201 Authorization error" result, that means domain exists, but have another owner
        try:
            code = int(response['epp']['response']['result']['@code'])
        except (
                ValueError,
                IndexError,
                TypeError,
        ) as exc:
            self.log(self.debug_level,
                     'Exception in doEppDomainInfo: %s' % exc)
            self.event('error', exc)
            return

        if code == 2201:
            self.domain_info_response = response
            self.event('response', response)
            return

        # read create/expire date
        try:
            datetime.datetime.strptime(
                response['epp']['response']['resData']['infData']['exDate'],
                '%Y-%m-%dT%H:%M:%S.%fZ',
            )
            datetime.datetime.strptime(
                response['epp']['response']['resData']['infData']['crDate'],
                '%Y-%m-%dT%H:%M:%S.%fZ',
            )
        except Exception as exc:
            self.log(self.debug_level,
                     'Exception in doEppDomainInfo: %s' % exc)
            raise zerrors.EPPBadResponse('response field not recognized')

        # detect current nameservers
        try:
            current_nameservers = response['epp']['response']['resData'][
                'infData']['ns']['hostObj']
        except:
            current_nameservers = []
        if not isinstance(current_nameservers, list):
            current_nameservers = [
                current_nameservers,
            ]
        self.received_nameservers = current_nameservers

        # detect current contacts
        try:
            current_contacts = response['epp']['response']['resData'][
                'infData']['contact']
        except:
            current_contacts = []
        if not isinstance(current_contacts, list):
            current_contacts = [
                current_contacts,
            ]
        self.received_contacts = [{
            'type': i['@type'],
            'id': i['#text'],
        } for i in current_contacts]
        self.new_domain_contacts = {
            i['@type']: i['#text']
            for i in current_contacts
        }

        # compare known contacts we have in DB with contacts received from back-end
        if not self.target_domain:
            self.contacts_changed = True
        else:
            add_contacts, remove_contacts, change_registrant = zdomains.compare_contacts(
                domain_object=self.target_domain,
                domain_info_response=response,
            )
            if add_contacts or remove_contacts or change_registrant:
                self.contacts_changed = True

        # detect current registrant
        try:
            self.received_registrant_epp_id = response['epp']['response'][
                'resData']['infData']['registrant']
        except Exception as exc:
            self.log(self.debug_level,
                     'Exception in doEppDomainInfo: %s' % exc)
            self.event('error',
                       zerrors.EPPRegistrantUnknown(response=response))
            return

        self.domain_info_response = response

        if self.expected_owner:
            # if pending order exists, select registrant from the owner
            self.known_registrant = self.expected_owner.registrants.first()
            logger.info('trying to use registrant from existing owner: %r',
                        self.known_registrant)
        else:
            # find registrant in local DB
            self.known_registrant = zcontacts.registrant_find(
                self.received_registrant_epp_id)
            logger.info('trying to find registrant by epp id %r: %r',
                        self.received_registrant_epp_id, self.known_registrant)

        if self.rewrite_contacts and self.known_registrant:
            logger.info(
                'going to rewrite domain %r contacts from existing owner %r',
                self.domain_name, self.known_registrant.owner)
            self.event('rewrite-contacts', response)
            return

        if self.known_registrant:
            logger.info('registrant for domain %r is known: %r',
                        self.domain_name, self.known_registrant)
            self.event('response', response)
            return

        if not self.create_new_owner_allowed:
            if self.domain_transferred_away:
                logger.error('domain %r is marked as transferred away',
                             self.domain_name)
                self.event('domain-transferred-away')
            else:
                # fail if registrant not exist in local DB
                # that means owner of the domain changed, or his contact is not in sync with back-end
                # this also happens when domain is transferred to Zenaida, but user account not exist yet
                logger.error('registrant %r not exist in local DB',
                             self.received_registrant_epp_id)
                self.event(
                    'error',
                    zerrors.EPPRegistrantAuthFailed(
                        'registrant not exist in local DB'))
            return

        # currently registrant not exist in local DB, user account needs to be checked and created first
        logger.info(
            'registrant not exist in local DB, going to create new registrant')
        self.event('registrant-unknown', response)