Пример #1
0
 public CommonDomainEntry(SmartHost smartHost)
 {
     if (smartHost.IsIPAddress)
     {
         this.address = smartHost.Address.ToString();
         return;
     }
     this.address = smartHost.Domain.HostnameString;
 }
 private static void ValidateSmartHostRestrictions(TenantOutboundConnector tenantOutboundConnector, Task task, bool skipIpIsNotReservedValidation)
 {
     if (tenantOutboundConnector.IsChanged(TenantOutboundConnectorSchema.SmartHosts) && !MultiValuedPropertyBase.IsNullOrEmpty(tenantOutboundConnector.SmartHosts))
     {
         MultiValuedProperty <IPRange> multiValuedProperty = null;
         bool flag = false;
         using (MultiValuedProperty <SmartHost> .Enumerator enumerator = tenantOutboundConnector.SmartHosts.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 SmartHost smartHost = enumerator.Current;
                 if (smartHost.IsIPAddress)
                 {
                     if (smartHost.Address.AddressFamily != AddressFamily.InterNetwork || !IPAddressValidation.IsValidIPv4Address(smartHost.Address.ToString()))
                     {
                         task.WriteError(new SmartHostsIPValidationFailedException(smartHost.Address.ToString()), ErrorCategory.InvalidArgument, null);
                     }
                     if (!skipIpIsNotReservedValidation)
                     {
                         if (IPAddressValidation.IsReservedIPv4Address(smartHost.Address.ToString()))
                         {
                             task.WriteError(new IPRangeInConnectorContainsReservedIPAddressesException(smartHost.Address.ToString()), ErrorCategory.InvalidArgument, null);
                         }
                         if (!flag)
                         {
                             if (!HygieneDCSettings.GetFfoDCPublicIPAddresses(out multiValuedProperty))
                             {
                                 task.WriteError(new ConnectorValidationFailedException(), ErrorCategory.ConnectionError, null);
                             }
                             flag = true;
                         }
                         if (!MultiValuedPropertyBase.IsNullOrEmpty(multiValuedProperty))
                         {
                             if (multiValuedProperty.Any((IPRange ffoDCIP) => ffoDCIP.Contains(smartHost.Address)))
                             {
                                 task.WriteError(new IPRangeInConnectorContainsReservedIPAddressesException(smartHost.Address.ToString()), ErrorCategory.InvalidArgument, null);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
        protected static HybridMailflowConfiguration ConvertToHybridMailflowConfiguration(TenantInboundConnector inbound, TenantOutboundConnector outbound)
        {
            ArgumentValidator.ThrowIfNull("inbound", inbound);
            ArgumentValidator.ThrowIfNull("outbound", outbound);
            HybridMailflowConfiguration hybridMailflowConfiguration = new HybridMailflowConfiguration();

            hybridMailflowConfiguration.OutboundDomains = new List <SmtpDomainWithSubdomains>();
            foreach (SmtpDomainWithSubdomains smtpDomainWithSubdomains in outbound.RecipientDomains)
            {
                if (!HybridMailflowTaskBase.IsWildcardDomain(smtpDomainWithSubdomains))
                {
                    hybridMailflowConfiguration.OutboundDomains.Add(new SmtpDomainWithSubdomains(smtpDomainWithSubdomains.Address));
                }
            }
            if (inbound.SenderIPAddresses != null)
            {
                hybridMailflowConfiguration.InboundIPs = new List <IPRange>();
                foreach (IPRange item in inbound.SenderIPAddresses)
                {
                    hybridMailflowConfiguration.InboundIPs.Add(item);
                }
            }
            if (!MultiValuedPropertyBase.IsNullOrEmpty(outbound.SmartHosts))
            {
                SmartHost smartHost = outbound.SmartHosts[0];
                if (smartHost.IsIPAddress)
                {
                    hybridMailflowConfiguration.OnPremisesFQDN = new Fqdn(smartHost.Address.ToString());
                }
                else
                {
                    hybridMailflowConfiguration.OnPremisesFQDN = new Fqdn(smartHost.ToString());
                }
            }
            if (inbound.TlsSenderCertificateName != null)
            {
                hybridMailflowConfiguration.CertificateSubject = inbound.TlsSenderCertificateName.ToString();
            }
            hybridMailflowConfiguration.SecureMailEnabled           = new bool?(inbound.RequireTls && outbound.TlsSettings != null && outbound.TlsSettings == TlsAuthLevel.DomainValidation);
            hybridMailflowConfiguration.CentralizedTransportEnabled = new bool?((inbound.RestrictDomainsToIPAddresses && HybridMailflowTaskBase.IsRecipientDomainsWildcard(outbound.RecipientDomains)) || outbound.RouteAllMessagesViaOnPremises);
            return(hybridMailflowConfiguration);
        }