public bool UpdateDomainNameServers(ReqUpdateDomainNameServers req) { MemberDomain md = Provider.Database.Read <MemberDomain>("DomainName = {0}", req.DomainName); if (md == null) { throw new APIException("Domain name not found: " + req.DomainName); } MemberProduct mp = Provider.Database.Read <MemberProduct>("Id = {0}", md.Id); if (mp == null) { throw new APIException("Critical error: MemberDomain exists but MemberProduct doesn't, for domain : " + req.DomainName); } if (mp.MemberId != Provider.CurrentMember.Id) { throw new APIException("Creditentials not authorized for this domain: " + req.DomainName); } EppAPI eppApi = new EppAPI(); var res = eppApi.HostCheck(new DealerSafe.DTO.Epp.Request.ReqHostCheck { DomainName = req.DomainName, HostNames = req.NameServers }); foreach (var hostInfo in res.HostInfos) { if (hostInfo.Available) { var res2 = eppApi.HostCreate(new DealerSafe.DTO.Epp.Request.ReqHostCreate { DomainName = req.DomainName, HostName = hostInfo.HostName }); } } var res3 = eppApi.DomainUpdate(new DealerSafe.DTO.Epp.Request.ReqDomainUpdate { Rem = new Epp.Protocol.Domains.DomainAddRemType { NameServers = new Epp.Protocol.Domains.NameServerList(md.NameServers.SplitWithTrim(',').Select(ns => new NameServerInfo { HostName = ns })) }, Add = new Epp.Protocol.Domains.DomainAddRemType { NameServers = new Epp.Protocol.Domains.NameServerList(req.NameServers.Select(ns => new NameServerInfo { HostName = ns })) }, DomainName = req.DomainName }); return(true); }
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); }