def test_domain_regenerate_from_csv_row(): filename = os.path.abspath( os.path.join(os.path.dirname(__file__), 'domains_sample.csv')) assert csv_import.load_from_csv(filename, dry_run=False) == 2 domain1 = zdomains.domain_find('test-import-1.ai') user1 = zusers.find_account('*****@*****.**') assert domain1 is not None assert user1 is not None assert domain1.registrant.epp_id == 'epp2025164ehqs' assert domain1.contact_admin.epp_id == 'epp2024611d4ru' assert domain1.list_nameservers() == [ 'facebook.com', 'google.com', '', '', ] domain2 = zdomains.domain_find('test-import-2.ai') user2 = zusers.find_account('*****@*****.**') assert user2 is not None assert domain2 is not None assert domain2.registrant.epp_id == 'epp583472wixr' assert domain2.contact_admin.epp_id == 'epp583456ht51' assert domain2.list_nameservers() == [ 'ns1.google.com', 'ns2.google.com', 'ns3.google.com', '' ]
def test_domain_regenerate_from_csv_row_dry_run(): filename = os.path.abspath( os.path.join(os.path.dirname(__file__), 'domains_sample.csv')) assert csv_import.load_from_csv(filename, dry_run=True) == 2 assert zdomains.domain_find('test-import-1.ai') is None assert zdomains.domain_find('test-import-2.ai') is None assert zusers.find_account('*****@*****.**') is None assert zusers.find_account('*****@*****.**') is None
def post(self, request, *args, **kwargs): order_items = request.POST.getlist('order_items') to_be_ordered = [] for domain_name in order_items: domain_object = zdomains.domain_find(domain_name=domain_name) if not domain_object: raise Http404 if domain_object.owner != request.user: logging.critical( 'User %s tried to make an order with domain from another owner' % request.user) raise exceptions.SuspiciousOperation() try: item_type, item_price, item_name = billing_orders.prepare_register_renew_restore_item( domain_object) except billing_errors.DomainBlockedError as err: messages.error(request, str(err)) return shortcuts.redirect('account_domains') to_be_ordered.append( dict( item_type=item_type, item_price=item_price, item_name=item_name, )) if not to_be_ordered: messages.error(request, self.error_message) return shortcuts.redirect('account_domains') new_order = billing_orders.order_multiple_items( owner=request.user, order_items=to_be_ordered, ) return shortcuts.render(request, 'billing/order_details.html', {'order': new_order})
def form_valid(self, form): domain_name = form.cleaned_data.get('domain_name', '').strip().lower() zmaster.domain_synchronize_from_backend( domain_name=domain_name, refresh_contacts=True, rewrite_contacts=False, change_owner_allowed=True, create_new_owner_allowed=True, soft_delete=True, raise_errors=True, log_events=True, log_transitions=True, ) domain_in_db = zdomains.domain_find(domain_name=domain_name) if domain_in_db: logger.info(f'domain {domain_name} is successfully synchronized') messages.success( self.request, f'Domain {domain_name} is successfully synchronized') else: messages.warning( self.request, f'Something went wrong during synchronization of {domain_name}' ) return super().form_valid(form)
def doInit(self, *args, **kwargs): """ Action method. """ self.domain_name = kwargs['domain_name'] self.target_domain = zdomains.domain_find(domain_name=self.domain_name) self.change_owner_allowed = kwargs.get('change_owner_allowed', False) self.create_new_owner_allowed = kwargs.get('create_new_owner_allowed', False) self.refresh_contacts = kwargs.get('refresh_contacts', False) self.soft_delete = kwargs.get('soft_delete', True) self.domain_transferred_away = kwargs.get('domain_transferred_away', False) self.expected_owner = None self.rewrite_contacts = kwargs.get('rewrite_contacts', False) pending_order_items = orders.find_pending_domain_transfer_order_items( domain_name=self.domain_name) if len(pending_order_items) > 1: logger.critical( 'found more than one pending order for domain %s transfer: %r', self.domain_name, pending_order_items) if len(pending_order_items) > 0: related_order_item = pending_order_items[0] self.expected_owner = related_order_item.order.owner if 'rewrite_contacts' in related_order_item.details: self.rewrite_contacts = related_order_item.details[ 'rewrite_contacts'] logger.info( 'found expected owner from one pending order %r : %r rewrite_contacts=%r', related_order_item, self.expected_owner, self.rewrite_contacts) else: logger.info('no pending orders for %r', self.domain_name)
def do_domain_transfer_in(domain): logger.info('domain %s transferred to Zenaida', domain) try: outputs = zmaster.domain_synchronize_from_backend( domain_name=domain, refresh_contacts=True, rewrite_contacts=True, change_owner_allowed=True, create_new_owner_allowed=True, ) except rpc_error.EPPError: logger.exception('failed to synchronize domain %s from back-end' % domain) return False if not outputs: logger.critical('synchronize domain %s failed with empty result' % domain) return False if not outputs[-1] or isinstance(outputs[-1], Exception): logger.critical('synchronize domain %s failed with result: %r', domain, outputs[-1]) return False logger.info('outputs: %r', outputs) domain_object = zdomains.domain_find(domain_name=domain) if not domain_object: logger.critical( 'synchronize domain %s failed, no domain object found' % domain) return False return True
def execute_one_item(order_item): target_domain = zdomains.domain_find(order_item.name) if not target_domain: logging.critical('Domain not exist', order_item.name) update_order_item(order_item, new_status='failed', charge_user=False, save=True) return False if target_domain.owner != order_item.order.owner: logging.critical( 'User %s tried to execute an order with domain from another owner' % order_item.order.owner) raise exceptions.SuspiciousOperation() if order_item.type == 'domain_register': return execute_domain_register(order_item, target_domain) if order_item.type == 'domain_renew': return execute_domain_renew(order_item, target_domain) if order_item.type == 'domain_restore': return execute_domain_restore(order_item, target_domain) logging.critical('Order item %s have a wrong type' % order_item) return False
def form_valid(self, form): domain_name = self.kwargs.get('domain_name', '').strip().lower() domain_tld = domain_name.split('.')[-1] if not zzones.is_supported(domain_tld): messages.error(self.request, f'Domain zone "{domain_tld}" is not supported') return shortcuts.redirect('account_domains') existing_domain = zdomains.domain_find(domain_name=domain_name) if existing_domain: if existing_domain.epp_id: # If domain has EPP id, it means that domain is already owned someone. messages.error(self.request, 'Domain name already registered') return super().form_valid(form) if existing_domain.create_date.replace( tzinfo=None) + datetime.timedelta( hours=1) < datetime.datetime.utcnow(): # If domain was on someone's basket more than an hour, remove that from database in order to make it # available for current user. zdomains.domain_delete(domain_id=existing_domain.id) else: # If domain is on someone's basket, domain becomes unavailable. messages.warning(self.request, 'Domain name is not available at the moment') return super().form_valid(form) domain_obj = form.save(commit=False) for nameserver in domain_obj.list_nameservers(): if nameserver.strip().lower().endswith(domain_name): messages.error( self.request, f'Please use another nameserver instead of {nameserver}, "glue" records are not supported yet.' ) return super().form_valid(form) domain_creation_date = timezone.now() zdomains.domain_create( domain_name=domain_name, owner=self.request.user, create_date=domain_creation_date, expiry_date=domain_creation_date + relativedelta(years=2), registrant=zcontacts.get_oldest_registrant(self.request.user), contact_admin=domain_obj.contact_admin, contact_tech=domain_obj.contact_tech, contact_billing=domain_obj.contact_billing, nameservers=[ domain_obj.nameserver1, domain_obj.nameserver2, domain_obj.nameserver3, domain_obj.nameserver4, ], save=True, ) messages.success(self.request, self.success_message) return shortcuts.redirect('billing_order_register', domain_name=domain_name)
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 = rpc_client.cmd_domain_info( domain=self.current_domain_name, auth_info=self.auth_info or None, ) except rpc_error.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.RegistrantAuthFailed(response=response)) return self.check_results[self.current_domain_name] = True self.event('response', response)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({'order': kwargs.get('order')}) context['domain_expiry_date'] = '' domain = zdomains.domain_find(domain_name=kwargs.get('domain_name')) if domain: context['domain_expiry_date'] = domain.expiry_date return context
def test_domain_find_not_registered(): tester_domain = testsupport.prepare_tester_domain( domain_name='abc.ai', domain_epp_id=None, create_date=None, expiry_date=None, ) assert zdomains.domain_find(domain_name='abc.ai').id == tester_domain.id
def post(self, request, *args, **kwargs): existing_order = orders.get_order_by_id_and_owner( order_id=kwargs.get('order_id'), owner=request.user, log_action='execute') for order_item in existing_order.items.all(): if order_item.type == 'domain_register': domain = zdomains.domain_find(domain_name=order_item.name) if domain and domain.status == 'inactive' and not domain.epp_id: zdomains.domain_delete(domain_name=order_item.name) orders.cancel_and_remove_order(existing_order) messages.success( request, f'Order of {existing_order.description} is cancelled.') return shortcuts.redirect('billing_orders')
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) new_order = billing_orders.order_single_item( owner=self.request.user, item_type='domain_register', item_price=settings.ZENAIDA_DOMAIN_PRICE, item_name=kwargs.get('domain_name'), ) context.update({'order': new_order}) context['domain_expiry_date'] = '' domain = zdomains.domain_find(domain_name=kwargs.get('domain_name')) if domain: context['domain_expiry_date'] = domain.expiry_date return context
def test_domain_restore(): if os.environ.get('E2E', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable if os.environ.get('MANUAL', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable # first need to read existing domain from back-end and create it in local DB testsupport.prepare_tester_registrant(epp_id='tester087401xo2c', create_new=True) zmaster.domain_synchronize_from_backend( 'test-restore-0.ai', refresh_contacts=True, change_owner_allowed=False, soft_delete=False, ) tester_domain = zdomains.domain_find(domain_name='test-restore-0.ai') assert tester_domain.epp_id is not None # now try to restore it scenario = [] dr = domain_resurrector.DomainResurrector( log_events=True, log_transitions=True, raise_errors=True, ) dr.add_state_changed_callback( cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append(( oldstate, newstate, event, )), ) dr.event('run', domain_object=tester_domain) outputs = list(dr.outputs) del dr # this domain must be restored now and renew for 2 years assert scenario == [ ('AT_STARTUP', 'VERIFY?', 'run'), ('VERIFY?', 'RESTORE!', 'verify-ok'), ('RESTORE!', 'REFRESH', 'response'), ('REFRESH', 'RENEW', 'refresh-ok'), ('RENEW', 'RENEW', 'refresh-ok'), ] assert len(outputs) == 7 assert tester_domain.epp_id is not None
def post(self, request, *args, **kwargs): # Check if there is already an order that started. If so, redirect user to that order. started_orders = orders.list_orders(owner=self.request.user, exclude_cancelled=True, include_statuses=['started']) if started_orders: messages.warning( self.request, 'There is an order you did not complete yet. ' 'Please confirm or cancel this order to create a new one') return shortcuts.redirect('billing_order_details', order_id=started_orders[0].id) order_items = request.POST.getlist('order_items') to_be_ordered = [] for domain_name in order_items: domain_object = zdomains.domain_find(domain_name=domain_name) if not domain_object: raise Http404 if domain_object.owner != request.user: logging.critical( 'user %r tried to make an order with domain from another owner' % request.user) raise SuspiciousOperation() try: item_type, item_price, item_name = orders.prepare_register_renew_restore_item( domain_object) except exceptions.DomainBlockedError as err: messages.error(request, str(err)) return shortcuts.redirect('account_domains') to_be_ordered.append( dict( item_type=item_type, item_price=item_price, item_name=item_name, )) if not to_be_ordered: messages.error(request, self.error_message) return shortcuts.redirect('account_domains') new_order = orders.order_multiple_items( owner=request.user, order_items=to_be_ordered, ) return shortcuts.render(request, 'billing/order_details.html', {'order': new_order})
def test_domain_pending_delete_status_not_set(): if os.environ.get('E2E', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable # first need to read existing domain from back-end and create it in local DB testsupport.prepare_tester_registrant(epp_id='tester065480yp60', create_new=True) test_domain_name = 'test-pending-delete-status-not-set.%s' % settings.ZENAIDA_SUPPORTED_ZONES[ 0] zmaster.domain_synchronize_from_backend( domain_name=test_domain_name, refresh_contacts=True, change_owner_allowed=False, soft_delete=False, ) tester_domain = zdomains.domain_find(domain_name=test_domain_name) assert tester_domain.epp_id is not None # now try to restore it scenario = [] dr = domain_resurrector.DomainResurrector( log_events=True, log_transitions=True, raise_errors=True, ) dr.add_state_changed_callback( cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append(( oldstate, newstate, event, )), ) dr.event('run', domain_object=tester_domain) outputs = list(dr.outputs) del dr # this domain is not possible to restore because status is not pending delete assert scenario == [ ('AT_STARTUP', 'VERIFY?', 'run'), ('VERIFY?', 'RESTORE!', 'verify-ok'), ('RESTORE!', 'FAILED', 'error'), ] assert tester_domain.epp_id is not None assert len(outputs) == 5 assert isinstance(outputs[-1], Exception)
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]))
def form_valid(self, form): domain_name = self.kwargs.get('domain_name') domain_tld = domain_name.split('.')[-1].lower() if not zzones.is_supported(domain_tld): messages.error(self.request, f'Domain zone "{domain_tld}" is not supported.') return shortcuts.redirect('account_domains') existing_domain = zdomains.domain_find(domain_name=domain_name) if existing_domain: if existing_domain.epp_id: # If domain has EPP id, it means that domain is already owned someone. messages.error(self.request, 'This domain is already registered.') return super().form_valid(form) if existing_domain.create_date.replace(tzinfo=None) + datetime.timedelta(hours=1) < datetime.datetime.utcnow(): # If domain was on someone's basket more than an hour, remove that from database in order to make it # available for current user. zdomains.domain_delete(domain_id=existing_domain.id) else: # If domain is on someone's basket, domain becomes unavailable. messages.warning(self.request, 'This domain is not available now.') return super().form_valid(form) domain_obj = form.save(commit=False) zdomains.domain_create( domain_name=domain_name, owner=self.request.user, create_date=timezone.now(), expiry_date=timezone.now() + datetime.timedelta(days=365), registrant=zcontacts.get_registrant(self.request.user), contact_admin=domain_obj.contact_admin, contact_tech=domain_obj.contact_tech, contact_billing=domain_obj.contact_billing, nameservers=[ domain_obj.nameserver1, domain_obj.nameserver2, domain_obj.nameserver3, ], save=True, ) messages.success(self.request, self.success_message) return super().form_valid(form)
def test_domain_find(): tester_domain = testsupport.prepare_tester_domain(domain_name='abc.ai') assert zdomains.domain_find(domain_name='abc.ai').id == tester_domain.id
def execute_domain_transfer(order_item): """ Execute domain transfer take-over order fulfillment and update order item, status will be "pending". """ if hasattr(order_item, 'details') and order_item.details.get('internal'): domain = zdomains.domain_find(order_item.name) if not domain: logger.info( 'domain name %r was not found in local DB, sync from back-end', order_item.name) zmaster.domain_synchronize_from_backend( domain_name=order_item.name, refresh_contacts=True, rewrite_contacts=False, change_owner_allowed=True, create_new_owner_allowed=True, soft_delete=False, domain_transferred_away=False, raise_errors=True, log_events=True, log_transitions=True, ) domain = zdomains.domain_find(order_item.name) if not domain: logger.critical( 'failed to synchronize domain %r, not possible to finish internal transfer', order_item.name) return False if domain.auth_key and domain.auth_key != order_item.details.get( 'transfer_code'): logger.critical( 'failed to finish internal domain transfer of %r because of invalid transfer code', domain) return False # Change the owner of the domain with removing his/her contact and updating the new contact oldest_registrant = zcontacts.get_oldest_registrant( order_item.order.owner) zdomains.domain_change_registrant(domain, oldest_registrant, True) zdomains.domain_detach_contact(domain, 'admin') zdomains.domain_detach_contact(domain, 'billing') zdomains.domain_detach_contact(domain, 'tech') zdomains.domain_join_contact(domain, 'admin', order_item.order.owner.contacts.first()) domain.refresh_from_db() # Override info on back-end zmaster.domain_synchronize_from_backend( domain_name=domain.name, refresh_contacts=False, rewrite_contacts=True, change_owner_allowed=False, expected_owner=order_item.order.owner, soft_delete=True, raise_errors=True, log_events=True, log_transitions=True, ) domain.refresh_from_db() # Override registrant on back-end zmaster.domain_synchronize_contacts( domain, merge_duplicated_contacts=True, rewrite_registrant=True, new_registrant=None, raise_errors=True, log_events=True, log_transitions=True, ) domain.refresh_from_db() try: zmaster.domain_set_auth_info(domain) except Exception as e: logger.exception( 'failed changing auth code for %r after internal transfer' % domain) update_order_item(order_item, new_status='failed', charge_user=False, save=True, details={ 'error': str(e), }) return False domain.refresh_from_db() # Auth key shouldn't be used anymore as transfer is done. domain.auth_key = '' domain.save() # In the end, order is done so, update order item as processed. update_order_item(order_item, new_status='processed', charge_user=True, save=True) return True if not zmaster.domain_transfer_request( domain=order_item.name, auth_info=order_item.details.get('transfer_code'), ): update_order_item(order_item, new_status='failed', charge_user=False, save=True) return False return update_order_item(order_item, new_status='pending', charge_user=False, save=True)
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
def execute_one_item(order_item): """ Based on type of OrderItem executes corresponding fulfillment procedure. """ logger.info('executing %r with %r', order_item, order_item.details) update_order_item(order_item, new_status='executing', charge_user=False, save=True) try: if order_item.type == 'domain_transfer': return execute_domain_transfer(order_item) target_domain = zdomains.domain_find(order_item.name) if not target_domain: logger.critical('domain %r not exists in local db', order_item.name) update_order_item(order_item, new_status='blocked', charge_user=False, save=True, details={ 'error': 'domain was not prepared or not exist', }) return False if target_domain.owner != order_item.order.owner: logger.critical( 'user %r tried to execute an order with domain from another owner' % order_item.order.owner) raise SuspiciousOperation() if order_item.type == 'domain_register': return execute_domain_register(order_item, target_domain) if order_item.type == 'domain_renew': return execute_domain_renew(order_item, target_domain) if order_item.type == 'domain_restore': return execute_domain_restore(order_item, target_domain) except Exception as e: logger.critical('order item %r execution has failed: %r' % ( order_item, e, )) update_order_item(order_item, new_status='failed', charge_user=False, save=True, details={ 'error': str(e), }) return False logger.critical('order item %r has a wrong type' % order_item) return False