Exemplo n.º 1
0
        public Task GetRecordInfo([FromForm] int id, [FromForm] int siteId)
        {
            DomainRecord record = SiteAgent.Instance().GetRecordInfo(id);

            if (record == null)
            {
                return(this.ShowError("记录不存在"));
            }
            SiteDomain domain = SiteAgent.Instance().GetDomainInfo(siteId, record.DomainID);

            if (domain == null)
            {
                return(this.ShowError("记录数据错误"));
            }
            return(this.GetResult(new
            {
                record.ID,
                record.DomainID,
                record.CDNType,
                record.CName,
                record.Status,
                record.SubName,
                domain.Domain
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="recordId"></param>
        /// <returns></returns>
        public bool DeleteRecord(int recordId)
        {
            DomainRecord record = this.WriteDB.ReadInfo <DomainRecord>(t => t.ID == recordId);

            if (record == null)
            {
                return(this.FaildMessage("记录不存在"));
            }
            SiteDomain domain = this.ReadDB.ReadInfo <SiteDomain>(t => t.ID == record.DomainID);

            List <DomainCDN> cdnlist = this.ReadDB.ReadList <DomainCDN>(t => t.RecordID == record.ID);

            // 调用CDN接口,删除CDN记录
            foreach (DomainCDN cdn in cdnlist)
            {
                if (cdn.CDNType != CDNProviderType.Manual)
                {
                    CDNProvider provider = ProviderAgent.Instance().GetCDNProviderInfo(cdn.CDNType);
                    if (provider != null || provider.Setting != null)
                    {
                        if (!provider.Setting.Delete(cdn.CName, out string msg))
                        {
                            return(this.FaildMessage(msg));
                        }
                    }
                }
                this.WriteDB.Delete <DomainCDN>(t => t.ID == cdn.ID && t.RecordID == recordId);
            }

            // 此处调用DNSPOD接口,删除别名记录
            // do something
            this.WriteDB.Delete <DomainRecord>(t => t.ID == recordId);

            return(this.AccountInfo.Log(LogType.Site, $"删除商户{domain.SiteID}域名记录{record.SubName}.{domain.Domain}"));
        }
Exemplo n.º 3
0
        private bool UpdateDdnsInfo(IDdnsService ddns, string ip, DomainsItem domain)
        {
            if (ddns == null)
            {
                throw new Exception("Ddns service provider is null.");
            }
            //检查域名解析是否存在
            List <DomainRecord> records          = ddns.DescribeSubDomainRecords(domain.Domain);
            DomianInfo          configDomainInfo = DomianInfo(domain.Domain);
            DomainRecord        domainInfo       = null;

            foreach (var item in records)
            {
                if ($"{item.RR}.{item.DomainName}".ToLower() == domain.Domain.ToLower())
                {
                    domainInfo = item;
                    break;
                }
            }
            if (records.Count > 1)
            {
                ddns.DeleteSubDomainRecords(new DeleteDomainRecordParam()
                {
                    RR         = domainInfo.RR,
                    DomainName = domainInfo.DomainName
                });
                domainInfo = null;
            }
            if (domainInfo == null)
            {
                ddns.AddDomainRecord(new AddDomainRecordParam()
                {
                    DomainName = configDomainInfo.DomainName,
                    RR         = configDomainInfo.RR,
                    Type       = DdnsSDK.Model.Enum.DomainRecordType.A,
                    Value      = ip,
                    TTL        = domain.TTL
                });
            }
            else
            {
                if (domainInfo.RR == configDomainInfo.RR &&
                    domainInfo.TTL == domain.TTL &&
                    domainInfo.Value == ip)
                {
                    return(false);
                }
                ddns.UpdateDomainRecord(new UpdateDomainRecordParam()
                {
                    DomainName = configDomainInfo.DomainName,
                    RecordId   = domainInfo.RecordId,
                    RR         = configDomainInfo.RR,
                    Type       = DdnsSDK.Model.Enum.DomainRecordType.A,
                    Value      = ip,
                    TTL        = domain.TTL
                });
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 添加域名
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domain">根域名</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomain(int siteId, string domain, string[] subName, CDNProviderType provider)
        {
            domain = WebAgent.GetTopDomain(domain);
            if (string.IsNullOrEmpty(domain))
            {
                return(this.FaildMessage("域名错误"));
            }
            if (this.ReadDB.Exists <SiteDomain>(t => t.Domain == domain))
            {
                return(this.FaildMessage("域名已被添加"));
            }
            foreach (string name in subName)
            {
                if (!Regex.IsMatch(name, @"^@$|^\*$|^\w+$"))
                {
                    return(this.FaildMessage($"子域名{name}不符合规范"));
                }
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadCommitted))
            {
                SiteDomain siteDomain = new SiteDomain()
                {
                    SiteID = siteId,
                    Domain = domain
                };
                siteDomain.AddIdentity(db);

                foreach (string name in subName.Distinct())
                {
                    // 添加域名记录
                    DomainRecord record = new DomainRecord()
                    {
                        CDNType  = provider,
                        CName    = this.CreateRecordCName(name, domain),
                        DomainID = siteDomain.ID,
                        Status   = DomainRecord.RecordStatus.Wait,
                        SubName  = name
                    };
                    record.AddIdentity(db);

                    // 添加CDN记录
                    DomainCDN cdn = new DomainCDN()
                    {
                        RecordID = record.ID,
                        Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                        CName    = string.Empty,
                        CDNType  = provider,
                        Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                    };
                    cdn.Add(db);
                }
                db.Commit();
            }

            return(true);
        }
        /// <summary>
        /// Gets a record.  The record must be available to the authenticated user in the given view.
        /// </summary>
        /// <param name="viewId">viewId view identifier in which to get records</param>
        /// <param name="recordId">recordId unique record identifier</param>
        /// <returns></returns>
        /// <exception cref="TrackViaApiException">if the service fails to process this request</exception>
        /// <exception cref="TrackviaClientException">if an error occurs outside the service, failing the request</exception>
        public DomainRecord <T> getRecord <T>(long viewId, long recordId)
        {
            string path = String.Format("{0}/openapi/views/{1}/records/{2}", this._baseUriPath, viewId, recordId);

            HttpClientResponse Response = getCommonSharedCode(path);

            DomainRecord <T> record = JsonConvert.DeserializeObject <DomainRecord <T> >(Response.Content);

            return(record);
        }
Exemplo n.º 6
0
        private static DomainRecord ConvertToDomainRecord(DnsRecord dnsRecord, string zoneName)
        {
            DomainRecord domainRecord = new DomainRecord();

            domainRecord.Data       = dnsRecord.RecordData;
            domainRecord.DomainName = zoneName;
            domainRecord.Priority   = dnsRecord.MxPriority;
            domainRecord.RecordType = dnsRecord.RecordType.ToString();
            domainRecord.HostName   = dnsRecord.RecordName;

            return(domainRecord);
        }
        /*
         * Talking with John from TrackVia this should work in theory, but generating
         * errors. Need to work with TrackVia to see if this is possible. It would
         * GREATLY speed up the update process
         *
         */
        /*
         * /// <summary>
         * /// Updates a record in a view accessible to the authenticated user.
         * /// </summary>
         * /// <param name="viewId">view identifier in which to update the record</param>
         * /// <param name="data">enumerable data instance of RecordData</param>
         * /// <returns>RecordSet of updated records</returns>
         * /// <exception cref="TrackViaApiException">if the service fails to process this request</exception>
         * /// <exception cref="TrackviaClientException">if an error occurs outside the service, failing the request</exception>
         * public RecordSet updateRecords(long viewId, IEnumerable<RecordData> data)
         * {
         *  string path = String.Format("{0}/openapi/views/{1}/records/0", this._baseUriPath, viewId);
         *
         *  RecordDataBatch batch = new RecordDataBatch(data);
         *
         *  string jsonSerializedData = JsonConvert.SerializeObject(batch);
         *
         *  HttpClientResponse Response = postCommonSharedCode(path, jsonSerializedData);
         *
         *  RecordSet rsResponse = JsonConvert.DeserializeObject<RecordSet>(Response.Content);
         *
         *  return rsResponse;
         * }
         *
         */

        /// <summary>
        /// Updates a record in a view accessible to the authenticated user using the typed object.
        /// </summary>
        /// <param name="viewId">view identifier in which to update the record</param>
        /// <param name="recordId">unique record identifier</param>
        /// <param name="data">instance of an application-defined class, representing the record data</param>
        /// <returns></returns>
        /// <exception cref="TrackViaApiException">if the service fails to process this request</exception>
        /// <exception cref="TrackviaClientException">if an error occurs outside the service, failing the request</exception>
        public DomainRecord <T> updateRecord <T>(long viewId, long recordId, T data)
        {
            string path = String.Format("{0}/openapi/views/{1}/records/{2}", this._baseUriPath, viewId, recordId);

            DomainRecordDataBatch <T> batch = new DomainRecordDataBatch <T>(new T[] { data });
            string jsonSerializedData       = JsonConvert.SerializeObject(batch);

            HttpClientResponse Response = postCommonSharedCode(path, jsonSerializedData);

            DomainRecordSet <T> recordSet = JsonConvert.DeserializeObject <DomainRecordSet <T> >(Response.Content);

            DomainRecord <T> record = (recordSet != null && recordSet.Data != null && recordSet.Data.Count == 1) ?
                                      new DomainRecord <T>(recordSet.Structure, recordSet.Data[0])
                : null;

            return(record);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 添加域名记录
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domainId">根域名ID</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomainRecord(int siteId, int domainId, string subName, CDNProviderType provider)
        {
            if (string.IsNullOrEmpty(subName) || !Regex.IsMatch(subName, @"^@$|^\*$|^\w+$"))
            {
                return(this.FaildMessage($"子域名{subName}不符合规范"));
            }
            SiteDomain domain = this.GetDomainInfo(siteId, domainId);

            if (domain == null)
            {
                return(this.FaildMessage("域名ID错误"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <DomainRecord>(t => t.DomainID == domainId && t.SubName == subName))
                {
                    return(this.FaildMessage("子域名记录已经存在"));
                }

                DomainRecord record = new DomainRecord()
                {
                    CDNType  = provider,
                    CName    = this.CreateRecordCName(subName, domain.Domain),
                    DomainID = domainId,
                    Status   = DomainRecord.RecordStatus.Wait,
                    SubName  = subName
                };
                record.AddIdentity(db);

                // 添加CDN记录
                DomainCDN cdn = new DomainCDN()
                {
                    RecordID = record.ID,
                    Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                    CName    = string.Empty,
                    CDNType  = provider,
                    Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                };
                cdn.Add(db);

                db.Commit();
            }
            return(true);
        }
Exemplo n.º 9
0
        public void TrackViaClient_GetRecordAsDomainClass_ShouldReturnRecordAsType()
        {
            // Assemble
            Record record = TestData.getUnitTestRecord1();

            Mock <IAsyncHttpClientHelper> httpClient = new Mock <IAsyncHttpClientHelper>();

            TestHelper.HttpClient_SetupGetRequest(HttpStatusCode.OK, record, httpClient);

            TrackViaClient client = new TrackViaClient(httpClient.Object, TestHelper.HostName_Fake, TestHelper.ApiKey_Fake);

            // Act
            DomainRecord <TestData.Contact> contactRecord = client.getRecord <TestData.Contact>(1, 1);

            // Assert
            contactRecord.ShouldNotBeNull();
            contactRecord.Data.ShouldNotBeNull();
            contactRecord.Data.Id.ShouldEqual(record.Data.Id);
        }
        public void IntegrationTest_TrackViaClient_GetDomainRecord_SimpleCrmAccount()
        {
            TestHelper.EnsureProductionValuesBeforeRunningIntegrationTests(IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW <= 0 ||
                                                                           IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW_VALIDACCOUNTRECORDID <= 0);

            // Assemble
            TrackViaClient client = new TrackViaClient(IntegrationTestConfig.TRACKVIA_HOSTNAME, IntegrationTestConfig.TRACKVIA_USERNAME,
                                                       IntegrationTestConfig.TRACKVIA_PASSWORD, IntegrationTestConfig.TRACKVIA_API_KEY);

            // Act
            DomainRecord <TestData.SimpleCrmContact> record = client.getRecord <TestData.SimpleCrmContact>(
                IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW,
                IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW_VALIDACCOUNTRECORDID);

            // Assert
            record.ShouldNotBeNull();
            record.Data.ShouldNotBeNull();
            record.Data.Id.ShouldEqual(IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW_VALIDACCOUNTRECORDID);
        }
Exemplo n.º 11
0
        public void AddZoneRecord(string zoneName, DnsRecord record)
        {
            if (string.IsNullOrEmpty(zoneName))
            {
                throw new ArgumentNullException("zoneName");
            }

            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            DomainRecord rec = ConvertToDomainRecord(record, zoneName);
            DnsResult    res = proxy.AddRecord(Login, Password, rec);

            if (res.Status != Success)
            {
                throw new Exception(string.Format("Could not add zone record. Error code {0}. {1}", res.Status, res.Description));
            }
        }
Exemplo n.º 12
0
        public void C()
        {
            var record = new DomainRecord(
                id: 19345,
                name: "*",
                path: "ai/processor/*",
                type: DnsRecordType.CNAME,
                value: "hosted.accelerator.net",
                ttl: null,
                flags: DomainRecordFlags.Alias
                );

            Assert.Equal(19345, record.Id);
            Assert.Equal("*", record.Name);
            Assert.Equal("ai/processor/*", record.Path);
            Assert.Equal(5, (int)record.Type);
            Assert.Equal("hosted.accelerator.net", record.Value);
            Assert.Equal(DomainRecordFlags.Alias, record.Flags);
            Assert.Null(record.Ttl);
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Get(string domain)
        {
            var Record = new DomainRecord()
            {
                Whois   = _WhoisService.GetWhoisInfo(domain),
                Dns     = await _DnsService.GetDnsInfoAsync(domain),
                Summary = new SummaryRecord()
            };

            try
            {
                Record.Summary.DomainOwner = Record.Whois.Registrant.Email;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Ok(Record));
        }
Exemplo n.º 14
0
        private static DnsRecord ConvertToDnsRecord(DomainRecord record)
        {
            DnsRecord dnsRecord = new DnsRecord();

            dnsRecord.RecordName = record.HostName;
            dnsRecord.MxPriority = record.Priority;
            dnsRecord.RecordData = record.Data;

            switch (record.RecordType)
            {
            case "A":
                dnsRecord.RecordType = DnsRecordType.A;
                break;

            case "AAAA":
                dnsRecord.RecordType = DnsRecordType.AAAA;
                break;

            case "MX":
                dnsRecord.RecordType = DnsRecordType.MX;
                break;

            case "CNAME":
                dnsRecord.RecordType = DnsRecordType.CNAME;
                break;

            case "NS":
                dnsRecord.RecordType = DnsRecordType.NS;
                break;

            case "SOA":
                dnsRecord.RecordType = DnsRecordType.SOA;
                break;

            case "TXT":
                dnsRecord.RecordType = DnsRecordType.TXT;
                break;
            }

            return(dnsRecord);
        }
Exemplo n.º 15
0
        public void TrackViaClient_UpdateRecordAsDomainClass_ShouldUpdateRecordAndReturn()
        {
            // Assemble
            RecordSet rs = TestData.getUnitTestRecordSet3();

            Mock <IAsyncHttpClientHelper> httpClient = new Mock <IAsyncHttpClientHelper>();

            TestHelper.HttpClient_SetupPutJsonRequest(HttpStatusCode.OK, rs, httpClient);

            TrackViaClient client = new TrackViaClient(httpClient.Object, TestHelper.HostName_Fake, TestHelper.ApiKey_Fake);

            TestData.Contact contact = TestData.getUnitTestContact1();

            // Act
            DomainRecord <TestData.Contact> responseRecord = client.updateRecord <TestData.Contact>(1L, contact.Id, contact);

            // Assert
            responseRecord.ShouldNotBeNull();
            responseRecord.Data.ShouldNotBeNull();
            responseRecord.Data.Id.ShouldEqual(contact.Id);
        }
Exemplo n.º 16
0
        public void B()
        {
            var name = DomainName.Parse("www.processor.ai");

            var record = new DomainRecord(
                id: ScopedId.Create(456, 1),
                name: "www",
                path: name.Path,
                type: DnsRecordType.A,
                value: "192.168.1.1",
                ttl: 600,
                flags: DomainRecordFlags.None
                );

            Assert.Equal(1912602625, record.Id);
            Assert.Equal("www", record.Name);
            Assert.Equal("ai/processor/www", record.Path);
            Assert.Equal(456, record.DomainId);
            Assert.Equal(1, (int)record.Type);
            Assert.Equal("192.168.1.1", record.Value);
            Assert.Equal(600, record.Ttl);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 切换域名记录的CDN供应商
        /// </summary>
        /// <param name="recordId">域名记录</param>
        /// <param name="type">CDN供应商</param>
        /// <param name="cname">自定义的别名记录</param>
        /// <returns></returns>
        public bool UpdateCDNProvider(int recordId, CDNProviderType type, string cname)
        {
            DomainRecord record = this.GetRecordInfo(recordId);

            if (record == null)
            {
                return(this.FaildMessage("域名记录错误"));
            }
            if (type == CDNProviderType.Manual && string.IsNullOrEmpty(cname))
            {
                return(this.FaildMessage("请手动设置CDN别名"));
            }
            if (!IsCDNProvider(type))
            {
                return(this.FaildMessage("当前不支持该供应商"));
            }

            SiteDomain domain = this.ReadDB.ReadInfo <SiteDomain>(t => t.ID == record.DomainID);

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                bool isExists = db.Exists <DomainCDN>(t => t.RecordID == recordId && t.CDNType == type);
                switch (type)
                {
                case CDNProviderType.Manual:
                {
                    if (isExists)
                    {
                        db.Update(new DomainCDN()
                            {
                                Status = DomainCDN.CDNStatus.Finish,
                                CName  = cname
                            }, t => t.RecordID == recordId && t.CDNType == type, t => t.Status, t => t.CName);
                    }
                    else
                    {
                        new DomainCDN()
                        {
                            RecordID = recordId,
                            CName    = cname,
                            Status   = DomainCDN.CDNStatus.Finish,
                            CDNType  = type
                        }.Add(db);
                    }

                    record.Status = DomainRecord.RecordStatus.Finish;

                    db.AddCallback(() =>
                        {
                            // 调用DNS供应商的接口,设定记录的别名指向到此处手动设定的CDN别名地址
                        });
                }
                break;

                default:
                {
                    if (isExists)
                    {
                        db.Update(new DomainCDN()
                            {
                                Status = DomainCDN.CDNStatus.Wait
                            }, t => t.RecordID == recordId && t.CDNType == type, t => t.Status);
                    }
                    else
                    {
                        new DomainCDN()
                        {
                            RecordID = recordId,
                            Status   = DomainCDN.CDNStatus.Wait,
                            CDNType  = type
                        }.Add(db);
                    }
                    record.Status = DomainRecord.RecordStatus.Wait;
                }
                break;
                }

                record.CDNType = type;
                record.Update(db, t => t.Status, t => t.CDNType);

                db.Commit();
            }
            return(this.AccountInfo.Log(LogType.Site, $"设定域名{record.SubName}.{domain.Domain}的CDN供应商为:{type.GetDescription()}"));
        }