Example #1
0
        private JobStates domainRestore(Job job)
        {
            // according to https://tools.ietf.org/html/rfc3915

            var orderItem = Provider.Database.Read <OrderItem>("Id={0}", job.RelatedEntityId);
            var member    = orderItem.Order().Member();


            var memberDomain = Provider.Database.Read <MemberDomain>("DomainName={0}", orderItem.DisplayName);

            if (memberDomain == null)
            {
                throw new Exception("MemberDomain record not found. If a domain name is not in our database, cannot be restored.");
            }

            var eppApi = new EppAPI();

            var req = new ReqDomainInfo();

            req.DomainName = memberDomain.DomainName;

            var res = eppApi.DomainInfo(req);

            // eğer domain state OK ise restore işlemi tamamlanmıştır
            if (res.Statuses.FirstOrDefault(s => s.Status == Epp.Protocol.Shared.Status.Ok) != null)
            {
                var memberProduct = Provider.Database.Read <MemberProduct>("Id={0}", memberDomain.Id);
                if (memberProduct == null)
                {
                    //null olmaması gerekir ama bir hatadan dolayı null ise hemen create edelim. bi sakınca yok
                    memberProduct = new MemberProduct
                    {
                        StartDate   = res.CreationDate.Value,
                        OrderItemId = job.RelatedEntityId,
                        MemberId    = member.Id,
                    };
                }

                memberProduct.EndDate = res.ExpirationDate.Value;
                memberProduct.Save();

                memberDomain.RegistryStatus = res.Statuses.StringJoin(",");
                memberDomain.RGPStatus      = res.ExtRgp == null ? statusValueType.NONE : res.ExtRgp.rgpStatus.FirstOrDefault().s;

                memberDomain.Save();

                return(JobStates.Done);
            }

            // eğer domain state OK değilse, pendingDelete de değilse, restore'da ne işin var kardeşim?
            if (res.Statuses.FirstOrDefault(s => s.Status == Epp.Protocol.Shared.Status.PendingDelete) == null)
            {
                throw new Exception("A domain with no pendingDelete status cannot be restored.");
            }

            // eğer domain redemptionPeriod'da ise, restore request komutunu göndeririz
            if (res.ExtRgp.rgpStatus.FirstOrDefault(s => s.s == statusValueType.redemptionPeriod) != null)
            {
                var reqRestore = new ReqDomainUpdate
                {
                    DomainName = memberDomain.DomainName,
                    ExtRgp     = new DealerSafe.DTO.Epp.Protocol.Rgp.updateType
                    {
                        restore = new DealerSafe.DTO.Epp.Protocol.Rgp.restoreType
                        {
                            op = DealerSafe.DTO.Epp.Protocol.Rgp.rgpOpType.request
                        }
                    }
                };

                var resRestore = eppApi.DomainUpdate(reqRestore);

                job.StartDate = Provider.Database.Now.AddMinutes(10);

                return(JobStates.TryAgain);
            }

            // eğer domain pendingRestore'da ise, restore report komutunu göndeririz
            if (res.ExtRgp.rgpStatus.FirstOrDefault(s => s.s == statusValueType.pendingRestore) != null)
            {
                var reqReport = new ReqDomainUpdate
                {
                    DomainName = memberDomain.DomainName,
                    ExtRgp     = new DealerSafe.DTO.Epp.Protocol.Rgp.updateType
                    {
                        restore = new DealerSafe.DTO.Epp.Protocol.Rgp.restoreType
                        {
                            op = DealerSafe.DTO.Epp.Protocol.Rgp.rgpOpType.report
                        }
                    }
                };

                var resRestore = eppApi.DomainUpdate(reqReport);

                job.StartDate = Provider.Database.Now.AddMinutes(10);

                return(JobStates.TryAgain);
            }

            job.StartDate = Provider.Database.Now.AddMinutes(10);
            return(JobStates.TryAgain);
        }
Example #2
0
        private JobStates domainRegister(Job job)
        {
            var orderItem = Provider.Database.Read <OrderItem>("Id={0}", job.RelatedEntityId);

            if (orderItem == null)
            {
                throw new Exception("OrderItem not found (in worker method domainRegister)");
            }

            var domainName = orderItem.DisplayName;

            var member = orderItem.Order().Member();

            var memberDomain =
                Provider.Database.Read <MemberDomain>("DomainName={0}", domainName)
                ??
                member.CreateNewMemberDomain(orderItem.DisplayName, orderItem.Id);

            var memberProduct = Provider.Database.Read <MemberProduct>("Id={0}", memberDomain.Id);

            if (memberProduct.CurrentPhase != LifeCyclePhases.None)
            {
                throw new Exception("Domain name (" + domainName + " #" + memberDomain.Id + ") already created (in worker method domainRegister)");
            }

            var product = memberProduct.OrderItem().Product();

            // Aşağıdaki işlemler RFC 5731 dikkate alınarak yazılmıştır. (https://tools.ietf.org/html/rfc5731#page-18)
            var eppApi = new EppAPI();

            var req = new ReqDomainCreate();

            // 1. ContactCheck
            if (product.GetProperty("WhoisServerHolder") == "Registry")
            {
                var reqContactCheck = new ReqContactCheck()
                {
                    DomainName = domainName
                };

                // 1.1. contact id'lerin hepsini bir seferde check edelim
                reqContactCheck.ContactIDs = new List <string>();
                if (!memberDomain.OwnerDomainContactId.IsEmpty())
                {
                    reqContactCheck.ContactIDs.Add(memberDomain.OwnerDomainContactId);
                }
                if (!memberDomain.AdminDomainContactId.IsEmpty())
                {
                    reqContactCheck.ContactIDs.Add(memberDomain.AdminDomainContactId);
                }
                if (!memberDomain.BillingDomainContactId.IsEmpty())
                {
                    reqContactCheck.ContactIDs.Add(memberDomain.BillingDomainContactId);
                }
                if (!memberDomain.TechDomainContactId.IsEmpty())
                {
                    reqContactCheck.ContactIDs.Add(memberDomain.TechDomainContactId);
                }
                reqContactCheck.ContactIDs = reqContactCheck.ContactIDs.Distinct().ToList();

                if (reqContactCheck.ContactIDs.Count > 0)
                {
                    var resContactCheck = eppApi.ContactCheck(reqContactCheck);

                    // 1.2. eğer registry tarafında contact create edilmemişse create edelim
                    if (!memberDomain.OwnerDomainContactId.IsEmpty())
                    {
                        if (resContactCheck.IsAvailable(memberDomain.OwnerDomainContactId))
                        {
                            createContact(memberDomain.OwnerDomainContactId, eppApi, domainName);
                            resContactCheck.ContactInfos.First(ci => ci.ContactId == memberDomain.OwnerDomainContactId).Available = false;
                        }
                        req.Registrant = memberDomain.OwnerDomainContactId;
                    }
                    if (!memberDomain.AdminDomainContactId.IsEmpty())
                    {
                        if (resContactCheck.IsAvailable(memberDomain.AdminDomainContactId))
                        {
                            createContact(memberDomain.AdminDomainContactId, eppApi, domainName);
                            resContactCheck.ContactInfos.First(ci => ci.ContactId == memberDomain.AdminDomainContactId).Available = false;
                        }
                        if (req.Contacts == null)
                        {
                            req.Contacts = new List <DomainContactInfo>();
                        }
                        req.Contacts.Add(new DomainContactInfo(memberDomain.AdminDomainContactId, DomainContactInfo.ContactType.Admin));
                    }
                    if (!memberDomain.BillingDomainContactId.IsEmpty())
                    {
                        if (resContactCheck.IsAvailable(memberDomain.BillingDomainContactId))
                        {
                            createContact(memberDomain.BillingDomainContactId, eppApi, domainName);
                            resContactCheck.ContactInfos.First(ci => ci.ContactId == memberDomain.BillingDomainContactId).Available = false;
                        }
                        if (req.Contacts == null)
                        {
                            req.Contacts = new List <DomainContactInfo>();
                        }
                        req.Contacts.Add(new DomainContactInfo(memberDomain.BillingDomainContactId, DomainContactInfo.ContactType.Billing));
                    }
                    if (!memberDomain.TechDomainContactId.IsEmpty())
                    {
                        if (resContactCheck.IsAvailable(memberDomain.TechDomainContactId))
                        {
                            createContact(memberDomain.TechDomainContactId, eppApi, domainName);
                            resContactCheck.ContactInfos.First(ci => ci.ContactId == memberDomain.TechDomainContactId).Available = false;
                        }
                        if (req.Contacts == null)
                        {
                            req.Contacts = new List <DomainContactInfo>();
                        }
                        req.Contacts.Add(new DomainContactInfo(memberDomain.TechDomainContactId, DomainContactInfo.ContactType.Tech));
                    }
                }
            }

            req.Registrant = memberDomain.OwnerDomainContactId;

            // 2. Nameserver'ları set edelim
            if (!memberDomain.NameServers.IsEmpty())
            {
                foreach (string host in memberDomain.NameServers.SplitWithTrim(";"))
                {
                    if (host.Contains(','))
                    {
                        var parts = host.SplitWithTrim(","); //TODO: IPv6'yı da desteklemek gerekecek gibi
                        req.NameServers.Add(new NameServerInfo {
                            HostName = parts[0], Addresses = new List <IpAddress> {
                                new IpAddress {
                                    Address = parts[1], Type = IpAddress.IpAddressType.V4
                                }
                            }
                        });
                    }
                    else
                    {
                        req.NameServers.Add(new NameServerInfo {
                            HostName = host
                        });
                    }
                }
            }

            // 3. The domain name itself
            req.DomainName = memberDomain.DomainName;

            // 4. Period
            req.RegistrationPeriod = new DomainPeriod
            {
                Units  = orderItem.ProductPrice().Unit == "years" ? DomainPeriod.PeriodUnits.Year : DomainPeriod.PeriodUnits.Month,
                Period = orderItem.Amount
            };

            // 5. AuthInfo
            req.AuthInfo = new Epp.Protocol.Shared.AuthInfo(memberDomain.AuthInfo);

            var res = eppApi.DomainCreate(req);

            memberProduct.StartDate    = res.CreateDate;
            memberProduct.EndDate      = res.ExpireDate.Value;
            memberProduct.CurrentPhase = LifeCyclePhases.Active;

            memberProduct.Save();

            var resInfo = eppApi.DomainInfo(new ReqDomainInfo {
                AuthInfo = req.AuthInfo, DomainName = req.DomainName
            });

            memberDomain.RegistryStates = resInfo.Statuses.Select(s => s.Status).ToList();
            memberDomain.Save();

            return(JobStates.Done);
        }