示例#1
0
        public List <ServerDomainData> GetDomains(IDaoFactory daoFactory)
        {
            var serverDomainDao = daoFactory.CreateServerDomainDao(Tenant);

            var listDomains = serverDomainDao.GetDomains();

            if (!listDomains.Any())
            {
                return(new List <ServerDomainData>());
            }

            var serverDnsDao = daoFactory.CreateServerDnsDao(Tenant, User);

            var list = new List <ServerDomainData>();

            foreach (var domain in listDomains)
            {
                var dnsData = UpdateDnsStatus(domain, serverDnsDao, serverDomainDao);

                var serverDomain = ToServerDomainData(domain, dnsData);

                list.Add(serverDomain);
            }

            return(list);
        }
示例#2
0
        public ServerDomainDnsData GetOrCreateUnusedDnsData(IDaoFactory daoFactory, Entities.Server server)
        {
            var serverDnsDao = daoFactory.CreateServerDnsDao(Tenant, User);

            var dnsSettings = serverDnsDao.GetFree();

            if (dnsSettings == null)
            {
                string privateKey, publicKey;
                CryptoUtil.GenerateDkimKeys(out privateKey, out publicKey);

                var domainCheckValue = PasswordGenerator.GenerateNewPassword(16);
                var domainCheck      = Defines.ServerDnsDomainCheckPrefix + ": " + domainCheckValue;

                var serverDns = new ServerDns
                {
                    Id              = 0,
                    Tenant          = Tenant,
                    User            = User,
                    DomainId        = Defines.UNUSED_DNS_SETTING_DOMAIN_ID,
                    DomainCheck     = domainCheck,
                    DkimSelector    = Defines.ServerDnsDkimSelector,
                    DkimPrivateKey  = privateKey,
                    DkimPublicKey   = publicKey,
                    DkimTtl         = Defines.ServerDnsDefaultTtl,
                    DkimVerified    = false,
                    DkimDateChecked = null,
                    Spf             = Defines.ServerDnsSpfRecordValue,
                    SpfTtl          = Defines.ServerDnsDefaultTtl,
                    SpfVerified     = false,
                    SpfDateChecked  = null,
                    Mx              = server.MxRecord,
                    MxTtl           = Defines.ServerDnsDefaultTtl,
                    MxVerified      = false,
                    MxDateChecked   = null,
                    TimeModified    = DateTime.UtcNow
                };

                serverDns.Id = serverDnsDao.Save(serverDns);

                dnsSettings = serverDns;
            }

            var dnsData = new ServerDomainDnsData
            {
                Id       = dnsSettings.Id,
                MxRecord = new ServerDomainMxRecordData
                {
                    Host       = dnsSettings.Mx,
                    IsVerified = false,
                    Priority   = Defines.ServerDnsMxRecordPriority
                },
                DkimRecord = new ServerDomainDkimRecordData
                {
                    Selector   = dnsSettings.DkimSelector,
                    IsVerified = false,
                    PublicKey  = dnsSettings.DkimPublicKey
                },
                DomainCheckRecord = new ServerDomainDnsRecordData
                {
                    Name       = Defines.DNS_DEFAULT_ORIGIN,
                    IsVerified = false,
                    Value      = dnsSettings.DomainCheck
                },
                SpfRecord = new ServerDomainDnsRecordData
                {
                    Name       = Defines.DNS_DEFAULT_ORIGIN,
                    IsVerified = false,
                    Value      = dnsSettings.Spf
                }
            };

            return(dnsData);
        }