def doDBCheckCreateUpdateContacts(self, *args, **kwargs): """ Action method. """ if self.rewrite_contacts: # that indicates that we actually want to overwrite domain contacts on back-end if self.target_domain: # when domain exists - skip return first_contact = self.known_registrant.owner.contacts.first() if not first_contact: first_contact = zcontacts.contact_create_from_profile( self.known_registrant.owner, self.known_registrant.owner.profile) # only populate Admin contact from one of the existing contacts that must already exist! self.new_domain_contacts = { 'admin': first_contact.epp_id, } 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: if self.change_owner_allowed: continue logger.error( 'existing contact have another owner in local DB') self.event( 'error', zerrors.RegistrantAuthFailed( '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'], )
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'], )
def test_contact_create(): tester = testsupport.prepare_tester_account(email='*****@*****.**') tester_contact = zcontacts.contact_create( epp_id='abcd', owner=tester, person_name='Tester Tester', organization_name='TestingCorp', address_street='TestStreet', address_city='TestCity', address_province='TestProvince', address_postal_code='TestPostalCode', address_country='AI', contact_voice='1234567890', contact_fax='1234567890', contact_email='*****@*****.**', ) assert tester_contact.owner.email == '*****@*****.**'
def prepare_tester_contact(tester=None, epp_id=None, create_new=False): if not tester: tester = prepare_tester_account() tester_contact = tester.contacts.first() if not tester_contact or create_new: tester_contact = zcontacts.contact_create( epp_id=epp_id, owner=tester, person_name='Tester Tester', organization_name='TestingCorp', address_street='TestStreet', address_city='TestCity', address_province='TestProvince', address_postal_code='TestPostalCode', address_country='AI', contact_voice='1234567890', contact_fax='1234567890', contact_email='*****@*****.**', ) return tester_contact
def domain_regenerate_from_csv_row(csv_row, headers, wanted_registrar='whois_ai', dry_run=True): """ """ errors = [] try: csv_record = split_csv_row(csv_row, headers) csv_info = get_csv_domain_info(csv_row, headers) domain = csv_info['name'] except Exception as exc: errors.append('failed processing csv record: ' + str(exc)) return errors if not zdomains.is_valid(domain): #--- invalid domain name errors.append('invalid domain name') return errors #--- lookup existing domain known_domain = zdomains.domain_find(domain) real_registrar_id = csv_record.get('registrar_id_9') if wanted_registrar and real_registrar_id != wanted_registrar: #--- belong to another registrar errors.append('%s: csv record belongs to another registrar %s' % (domain, real_registrar_id, )) return errors real_expiry_date = csv_info['expiry_date'] real_create_date = csv_info['create_date'] real_epp_id = csv_record.get('roid_0') real_auth_key = csv_record.get('auth_info_password_2') real_registrant_contact_id = csv_record.get('registrant_contact_id_24') real_admin_contact_id = csv_record.get('admin_contact_id_54') real_tech_contact_id = csv_record.get('tech_contact_id_69') real_billing_contact_id = csv_record.get('billing_contact_id_39') real_registrant_email = csv_info['registrant']['contact_email'] real_admin_email = csv_info['admin']['contact_email'] real_tech_email = csv_info['tech']['contact_email'] real_billing_email = csv_info['billing']['contact_email'] real_nameservers = csv_info['nameservers'] known_expiry_date = None known_create_date = None known_epp_id = None known_auth_key = None known_registrant_contact_id = None known_admin_contact_id = None known_tech_contact_id = None known_billing_contact_id = None known_nameservers = ['', ] * 4 new_domain = None new_registrant_contact = None new_admin_contact = None new_tech_contact = None new_billing_contact = None need_registrant = False need_admin_contact = False need_tech_contact = False need_billing_contact = False owner_account = zusers.find_account(real_registrant_email) if not owner_account: if dry_run: errors.append('account %s not exist' % real_registrant_email) return errors #--- account check/create new_password=zusers.generate_password(length=10) owner_account = zusers.create_account( email=real_registrant_email, account_password=new_password, is_active=True, ) logger.info('generated new account and password for %s : %s', real_registrant_email, new_password) if known_domain: known_expiry_date = known_domain.expiry_date known_create_date = known_domain.create_date known_epp_id = known_domain.epp_id known_auth_key = known_domain.auth_key known_registrant_contact_id = None if not known_domain.registrant else known_domain.registrant.epp_id known_admin_contact_id = None if not known_domain.contact_admin else known_domain.contact_admin.epp_id known_billing_contact_id = None if not known_domain.contact_billing else known_domain.contact_billing.epp_id known_tech_contact_id = None if not known_domain.contact_tech else known_domain.contact_tech.epp_id known_nameservers = known_domain.list_nameservers() if real_admin_contact_id or real_tech_contact_id or real_billing_contact_id: if known_domain: if not known_tech_contact_id and not known_admin_contact_id and not known_billing_contact_id: if dry_run: errors.append('%s: no contacts present for known domain' % domain) return errors else: errors.append('%s: no csv contacts provided for domain' % domain) return errors if real_registrant_contact_id: #--- registrant check _errs, need_registrant = check_contact_to_be_created( domain_name=domain, known_epp_contact_id=known_registrant_contact_id, real_epp_contact_id=real_registrant_contact_id, real_owner=owner_account, ) if dry_run: errors.extend(_errs) if real_admin_contact_id: #--- admin contact check _errs, need_admin_contact = check_contact_to_be_created( domain_name=domain, known_epp_contact_id=known_admin_contact_id, real_epp_contact_id=real_admin_contact_id, real_owner=owner_account, ) if dry_run: errors.extend(_errs) if real_tech_contact_id: #--- tech contact check _errs, need_tech_contact = check_contact_to_be_created( domain_name=domain, known_epp_contact_id=known_tech_contact_id, real_epp_contact_id=real_tech_contact_id, real_owner=owner_account, ) if dry_run: errors.extend(_errs) if real_billing_contact_id: #--- billing contact check _errs, need_billing_contact = check_contact_to_be_created( domain_name=domain, known_epp_contact_id=known_billing_contact_id, real_epp_contact_id=real_billing_contact_id, real_owner=owner_account, ) if dry_run: errors.extend(_errs) if not dry_run: if need_registrant: #--- registrant create new_registrant_contact = zcontacts.registrant_create( epp_id=real_registrant_contact_id, owner=owner_account, **csv_info['registrant'], ) # TODO: make sure contact was assigned to the domain else: zcontacts.registrant_update( epp_id=real_registrant_contact_id, **csv_info['registrant'], ) if need_admin_contact: #--- admin contact create new_admin_contact = zcontacts.contact_create( epp_id=real_admin_contact_id, owner=owner_account, **csv_info['admin'], ) # TODO: make sure contact was assigned to the domain else: if real_admin_contact_id and real_admin_email: zcontacts.contact_update( epp_id=real_admin_contact_id, **csv_info['admin'], ) if need_tech_contact: #--- tech contact create new_tech_contact = zcontacts.contact_create( epp_id=real_tech_contact_id, owner=owner_account, **csv_info['tech'], ) # TODO: make sure contact was assigned to the domain else: if real_tech_contact_id and real_tech_email: zcontacts.contact_update( epp_id=real_tech_contact_id, **csv_info['tech'], ) if need_billing_contact: #--- billing contact create new_billing_contact = zcontacts.contact_create( epp_id=real_billing_contact_id, owner=owner_account, **csv_info['billing'], ) # TODO: make sure contact was assigned to the domain else: if real_billing_contact_id and real_billing_email: zcontacts.contact_update( epp_id=real_billing_contact_id, **csv_info['billing'], ) if not known_domain: if dry_run: #--- domain not found errors.append('%s: domain not exist' % domain) return errors #--- create new domain new_domain = zdomains.domain_create( domain_name=domain, owner=owner_account, expiry_date=real_expiry_date, create_date=real_create_date, epp_id=real_epp_id, auth_key=real_auth_key, registrar=real_registrar_id, registrant=new_registrant_contact, contact_admin=new_admin_contact, contact_tech=new_tech_contact, contact_billing=new_billing_contact, nameservers=real_nameservers, ) if new_domain: #--- DONE, new domain created return [] if known_expiry_date: dt = real_expiry_date - known_expiry_date dt_hours = float(dt.total_seconds()) / (60.0 * 60.0) if dt_hours >= 24: #--- domain expiry date not in sync if dry_run: errors.append('expiry date not in sync for %s, known is %s, real is %s' % ( domain, known_expiry_date, real_expiry_date, )) return errors known_domain.expiry_date = real_expiry_date known_domain.save() logger.debug('known expiry date updated for %s : %s', known_domain, real_expiry_date) else: if known_domain: #--- expiry date was not set if real_expiry_date: if dry_run: errors.append('expiry date was not set for %s, real is %s' % ( domain, real_expiry_date, )) return errors known_domain.expiry_date = real_expiry_date known_domain.save() logger.debug('expiry date was not set, now updated for %s : %s', known_domain, real_expiry_date) if known_create_date: dt = real_create_date - known_create_date dt_hours = float(dt.total_seconds()) / (60.0 * 60.0) if dt_hours >= 24: #--- domain create date not in sync if dry_run: errors.append('create date not in sync for %s, known is %s, real is %s' % ( domain, known_create_date, real_create_date, )) return errors known_domain.create_date = real_create_date known_domain.save() logger.debug('known create date updated for %s : %s', known_domain, real_create_date) else: if known_domain: if real_create_date: #--- create date was not set if dry_run: errors.append('create date was not set for %s, real is %s' % ( domain, real_create_date, )) return errors known_domain.create_date = real_create_date known_domain.save() logger.debug('create date was not set, now updated for %s : %s', known_domain, real_create_date) #--- check known epp_id if known_epp_id: if known_epp_id != real_epp_id: if dry_run: errors.append('epp_id not in sync for %s, known is %s, real is %s' % ( domain, known_epp_id, real_epp_id, )) return errors known_domain.epp_id = real_epp_id known_domain.save() logger.debug('known epp_id for %s updated : %s', known_domain, real_epp_id) else: if real_epp_id: if known_domain: if dry_run: errors.append('epp_id was not set for %s, real is %s' % ( domain, real_epp_id, )) return errors known_domain.epp_id = real_epp_id known_domain.save() logger.debug('epp_id was not set for %s, now updated : %s', known_domain, real_epp_id) #--- check auth_key if known_auth_key: if known_auth_key != real_auth_key: if dry_run: errors.append('auth_key not in sync for %s, known is %s, real is %s' % ( domain, known_auth_key, real_auth_key, )) return errors known_domain.auth_key = real_auth_key known_domain.save() logger.debug('known auth_key for %s updated : %s', known_domain, real_auth_key) else: if real_auth_key: if known_domain: if dry_run: errors.append('auth_key was not set for %s, real is %s' % ( domain, real_auth_key, )) return errors known_domain.auth_key = real_auth_key known_domain.save() logger.debug('auth_key was not set for %s, now updated : %s', known_domain, real_auth_key) #--- check nameservers for i in range(4): if real_nameservers[i] != known_nameservers[i]: if dry_run: errors.append('nameserver at position %s not in sync for %s, known is %s, real is %s' % ( domain, known_nameservers[i], real_nameservers[i], )) return errors #--- update nameservers if not dry_run: zdomains.update_nameservers(known_domain, real_nameservers) if errors and dry_run: return errors #--- DONE, existing domain updated return errors