private bool CheckDomainDns(DnsCheckTaskDto taskDto)
        {
            if (string.IsNullOrEmpty(taskDto.domain_name))
            {
                return(false);
            }

            try
            {
                var dnsLookup = new DnsLookup();

                var mxVerified = dnsLookup.IsDomainMxRecordExists(taskDto.domain_name, taskDto.mx_record);

                var spfVerified = dnsLookup.IsDomainTxtRecordExists(taskDto.domain_name, taskDto.spf);

                var dkimVerified = dnsLookup.IsDomainDkimRecordExists(taskDto.domain_name, taskDto.dkim_selector,
                                                                      taskDto.dkim_public_key);

                _log.Info("Domain '{0}' MX={1} SPF={2} DKIM={3}", taskDto.domain_name, mxVerified, spfVerified,
                          dkimVerified);

                return(mxVerified && spfVerified && dkimVerified);
            }
            catch (Exception ex)
            {
                _log.Error("CheckDomainDns() Exception: \r\n {0} \r\n", ex.ToString());
            }

            return(false);
        }
        public bool CheckDomainOwnership(string name)
        {
            if (!IsAdmin)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(@"Invalid domain name.", "name");
            }

            if (name.Length > 255)
            {
                throw new ArgumentException(@"Domain name exceed limitation of 255 characters.", "name");
            }

            if (!Parser.IsDomainValid(name))
            {
                throw new ArgumentException(@"Incorrect domain name.", "name");
            }

            var domainName = name.ToLowerInvariant();

            var dns = GetUnusedDnsRecords();

            var dnsLookup = new DnsLookup();

            return(dnsLookup.IsDomainTxtRecordExists(domainName, dns.DomainCheckRecord.Value));
        }
Esempio n. 3
0
        public void TxtSpfExists()
        {
            const string domain     = "onlyoffice.com";
            const string txt_record = "v=spf1 a mx mx:avsmedia.net a:smtp1.uservoice.com a:qamail.teamlab.info include:amazonses.com -all";

            var dnsLoopup = new DnsLookup();

            var exists = dnsLoopup.IsDomainTxtRecordExists(domain, txt_record);

            Assert.IsTrue(exists);
        }
        public WebDomainData AddDomain(string name, int id_dns)
        {
            if (!IsAdmin)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(@"Invalid domain name.", "name");
            }

            if (name.Length > 255)
            {
                throw new ArgumentException(@"Domain name exceed limitation of 255 characters.", "name");
            }

            if (!Parser.IsDomainValid(name))
            {
                throw new ArgumentException(@"Incorrect domain name.", "name");
            }

            var domainName = name.ToLowerInvariant();

            var freeDns = MailServer.GetFreeDnsRecords(MailServerFactory);

            if (freeDns.Id != id_dns)
            {
                throw new InvalidDataException("This dkim public key is already in use. Please reopen wizard again.");
            }

            var dnsLookup = new DnsLookup();

            if (!dnsLookup.IsDomainTxtRecordExists(domainName, freeDns.DomainCheckRecord))
            {
                throw new InvalidOperationException("txt record is not correct.");
            }

            var isVerified = freeDns.CheckDnsStatus(domainName);

            var webDomain = MailServer.CreateWebDomain(domainName, isVerified, MailServerFactory);

            webDomain.AddDns(id_dns, MailServerFactory);

            return(webDomain.ToWebDomainData(freeDns.ToDnsData()));
        }
Esempio n. 5
0
        public bool CheckDnsStatus(string domainName = "")
        {
            var checkDomainName = string.IsNullOrEmpty(DomainName)
                                 ? domainName
                                 : DomainName;

            if (string.IsNullOrEmpty(checkDomainName))
            {
                return(false);
            }

            var dnsLookup = new DnsLookup();

            MxVerified = dnsLookup.IsDomainMxRecordExists(checkDomainName, MxHost);

            SpfVerified = dnsLookup.IsDomainTxtRecordExists(checkDomainName, SpfRecord);

            DkimVerified = dnsLookup.IsDomainDkimRecordExists(checkDomainName, DkimSelector, DkimPublicKey);

            return(MxVerified && SpfVerified && DkimVerified);
        }
        public static bool CheckDnsStatus(this ServerDomainDnsData dnsData, string domain)
        {
            if (string.IsNullOrEmpty(domain))
            {
                return(false);
            }

            var dnsLookup = new DnsLookup();

            var mxVerified = dnsLookup.IsDomainMxRecordExists(domain, dnsData.MxRecord.Host);

            dnsData.MxRecord.IsVerified = mxVerified;

            var spfVerified = dnsLookup.IsDomainTxtRecordExists(domain, dnsData.SpfRecord.Value);

            dnsData.SpfRecord.IsVerified = spfVerified;

            var dkimVerified = dnsLookup.IsDomainDkimRecordExists(domain, dnsData.DkimRecord.Selector,
                                                                  dnsData.DkimRecord.PublicKey);

            dnsData.DkimRecord.IsVerified = dkimVerified;

            return(mxVerified && spfVerified && dkimVerified);
        }
Esempio n. 7
0
        public ServerDomainData AddDomain(string domain, int dnsId)
        {
            if (!IsAdmin)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (string.IsNullOrEmpty(domain))
            {
                throw new ArgumentException(@"Invalid domain name.", "domain");
            }

            if (domain.Length > 255)
            {
                throw new ArgumentException(@"Domain name exceed limitation of 255 characters.", "domain");
            }

            if (!Parser.IsDomainValid(domain))
            {
                throw new ArgumentException(@"Incorrect domain name.", "domain");
            }

            var domainName = domain.ToLowerInvariant();

            var engine = new EngineFactory(Tenant, User);

            var dnsLookup = new DnsLookup();

            using (var daoFactory = new DaoFactory())
            {
                var serverDao = daoFactory.CreateServerDao();

                var server = serverDao.Get(Tenant);

                var freeDns = engine.ServerEngine.GetOrCreateUnusedDnsData(daoFactory, server);

                if (freeDns.Id != dnsId)
                {
                    throw new InvalidDataException("This dkim public key is already in use. Please reopen wizard again.");
                }

                if (!CoreContext.Configuration.Standalone &&
                    !dnsLookup.IsDomainTxtRecordExists(domainName, freeDns.DomainCheckRecord.Value))
                {
                    throw new InvalidOperationException("txt record is not correct.");
                }

                var isVerified = freeDns.CheckDnsStatus(domainName);

                using (var tx = daoFactory.DbManager.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    var serverDomainDao = daoFactory.CreateServerDomainDao(Tenant);

                    var utcNow = DateTime.UtcNow;

                    var mailServerEngine = new Server.Core.ServerEngine(server.Id, server.ConnectionString);

                    var mailServerDomain = new Server.Core.Entities.Domain
                    {
                        Name        = domainName,
                        Active      = true,
                        Description = string.Format("Domain created in UtcTime: {0}, for tenant: {1}", utcNow, Tenant),
                        Created     = utcNow,
                        Modified    = utcNow
                    };

                    mailServerEngine.SaveDomain(mailServerDomain);

                    var serverDomain = new ServerDomain
                    {
                        Id          = 0,
                        Tenant      = Tenant,
                        Name        = domainName,
                        IsVerified  = isVerified,
                        DateAdded   = utcNow,
                        DateChecked = utcNow
                    };

                    serverDomain.Id = serverDomainDao.Save(serverDomain);

                    var serverDnsDao = daoFactory.CreateServerDnsDao(Tenant, User);
                    var serverDns    = serverDnsDao.GetById(freeDns.Id);

                    var mailServerDkim = new Server.Core.Entities.Dkim
                    {
                        DomainName = domainName,
                        Selector   = serverDns.DkimSelector,
                        PrivateKey = serverDns.DkimPrivateKey,
                        PublicKey  = serverDns.DkimPublicKey
                    };

                    mailServerEngine.SaveDkim(mailServerDkim);

                    serverDns.DomainId     = serverDomain.Id;
                    serverDns.TimeModified = utcNow;
                    serverDnsDao.Save(serverDns);

                    tx.Commit();

                    return(ToServerDomainData(serverDomain, freeDns));
                }
            }
        }