コード例 #1
0
        public bool Update(UpdateSettingsViewModel viewModel)
        {
            if (viewModel.ClientIdleTimeout < 0 ||
                viewModel.ReceiveTimeout < 0 ||
                viewModel.SendTimeout < 0)
            {
                return(false);
            }

            List <IPAddress> relayingIps = new List <IPAddress>();

            foreach (string str in viewModel.IpAddressesForRelaying)
            {
                relayingIps.Add(IPAddress.Parse(str));
            }

            CfgPara.SetClientIdleTimeout(viewModel.ClientIdleTimeout);
            CfgPara.SetReceiveTimeout(viewModel.ReceiveTimeout);
            CfgPara.SetSendTimeout(viewModel.SendTimeout);
            CfgPara.SetDefaultVirtualMtaGroupID(viewModel.DefaultVirtualMtaGroupID);
            CfgPara.SetEventForwardingHttpPostUrl(viewModel.EventUrl);
            CfgPara.SetDaysToKeepSmtpLogsFor(viewModel.DaysToKeepSmtpLogsFor);
            CfgPara.SetMaxTimeInQueueMinutes(viewModel.MaxTimeInQueueHours * 60);
            CfgPara.SetRetryIntervalBaseMinutes(viewModel.RetryIntervalBase);
            CfgRelayingPermittedIP.SetRelayingPermittedIPAddresses(relayingIps.ToArray());
            CfgPara.SetReturnPathLocalDomain(viewModel.ReturnPathLocalDomainID);

            var domains = CfgLocalDomains.GetLocalDomainsArray();

            CfgLocalDomains.ClearLocalDomains();
            foreach (string localDomain in viewModel.LocalDomains)
            {
                if (string.IsNullOrWhiteSpace(localDomain))
                {
                    continue;
                }
                LocalDomain ld = domains.SingleOrDefault(d => d.Hostname.Equals(localDomain, StringComparison.OrdinalIgnoreCase));
                if (ld == null)
                {
                    ld = new LocalDomain {
                        Hostname = localDomain.Trim()
                    }
                }
                ;
                CfgLocalDomains.Save(ld);
            }

            return(true);
        }
    }
コード例 #2
0
        public bool Update(int clientIdleTimeout, int receiveTimeout, int sendTimeout, int defaultVirtualMtaGroupID, string eventUrl, int daysToKeepSmtpLogsFor,
                           int maxTimeInQueueHours, int retryIntervalBase, string[] ipAddressesForRelaying, int returnPathLocalDomainID, string[] localDomains)
        {
            if (clientIdleTimeout < 0 ||
                receiveTimeout < 0 ||
                sendTimeout < 0)
            {
                return(false);
            }

            List <IPAddress> relayingIps = new List <IPAddress>();

            foreach (string str in ipAddressesForRelaying)
            {
                relayingIps.Add(IPAddress.Parse(str));
            }

            CfgPara.SetClientIdleTimeout(clientIdleTimeout);
            CfgPara.SetReceiveTimeout(receiveTimeout);
            CfgPara.SetSendTimeout(sendTimeout);
            CfgPara.SetDefaultVirtualMtaGroupID(defaultVirtualMtaGroupID);
            CfgPara.SetEventForwardingHttpPostUrl(eventUrl);
            CfgPara.SetDaysToKeepSmtpLogsFor(daysToKeepSmtpLogsFor);
            CfgPara.SetMaxTimeInQueueMinutes(maxTimeInQueueHours * 60);
            CfgPara.SetRetryIntervalBaseMinutes(retryIntervalBase);
            CfgRelayingPermittedIP.SetRelayingPermittedIPAddresses(relayingIps.ToArray());
            CfgPara.SetReturnPathLocalDomain(returnPathLocalDomainID);

            LocalDomainCollection domains = CfgLocalDomains.GetLocalDomainsArray();

            CfgLocalDomains.ClearLocalDomains();
            foreach (string localDomain in localDomains)
            {
                if (string.IsNullOrWhiteSpace(localDomain))
                {
                    continue;
                }
                LocalDomain ld = domains.SingleOrDefault(d => d.Hostname.Equals(localDomain, StringComparison.OrdinalIgnoreCase));
                if (ld == null)
                {
                    ld = new LocalDomain {
                        Hostname = localDomain.Trim()
                    }
                }
                ;
                CfgLocalDomains.Save(ld);
            }
            return(true);
        }
    }
コード例 #3
0
        /// <summary>
        /// Saves a local domain to the database.
        /// </summary>
        /// <param name="domain">Domain to add. Does nothing if domain already exists.</param>
        public static void Save(LocalDomain localDomain)
        {
            using (SqlConnection conn = MantaDB.GetSqlConnection())
            {
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = @"
IF EXISTS (SELECT 1 FROM man_cfg_localDomain WHERE cfg_localDomain_id = @id)
	UPDATE man_cfg_localDomain
	SET cfg_localDomain_domain = @domain,
	cfg_localDomain_name = @name,
	cfg_localDomain_description = @description
	WHERE cfg_localDomain_domain = @id
ELSE
	BEGIN
	IF(@id > 0)
		BEGIN
			SET IDENTITY_INSERT man_cfg_localDomain ON

			INSERT INTO man_cfg_localDomain (cfg_localDomain_id, cfg_localDomain_domain, cfg_localDomain_name, cfg_localDomain_description)
			VALUES(@id, @domain, @name, @description)

			SET IDENTITY_INSERT man_cfg_localDomain OFF
		END
	ELSE
		INSERT INTO man_cfg_localDomain (cfg_localDomain_domain, cfg_localDomain_name, cfg_localDomain_description)
		VALUES(@domain, @name, @description)

	END"    ;
                cmd.Parameters.AddWithValue("@id", localDomain.ID);
                cmd.Parameters.AddWithValue("@domain", localDomain.Hostname);
                cmd.Parameters.AddWithValue("@name", localDomain.Name);

                if (localDomain.Description == null)
                {
                    cmd.Parameters.AddWithValue("@description", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@description", localDomain.Description);
                }
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        }
コード例 #4
0
        private async Task <string> ExpandMacroAsync(Match pattern, IPAddress ip, DomainName domain, string sender, CancellationToken token)
        {
            switch (pattern.Value)
            {
            case "%%":
                return("%");

            case "%_":
                return("_");

            case "%-":
                return("-");

            default:
                string letter;
                switch (pattern.Groups["letter"].Value)
                {
                case "s":
                    letter = sender;
                    break;

                case "l":
                    // no boundary check needed, sender is validated on start of CheckHost
                    letter = sender.Split('@')[0];
                    break;

                case "o":
                    // no boundary check needed, sender is validated on start of CheckHost
                    letter = sender.Split('@')[1];
                    break;

                case "d":
                    letter = domain.ToString();
                    break;

                case "i":
                    letter = String.Join(".", ip.GetAddressBytes().Select(b => b.ToString()));
                    break;

                case "p":
                    letter = "unknown";

                    DnsResolveResult <PtrRecord> dnsResult = await ResolveDnsAsync <PtrRecord>(ip.GetReverseLookupDomain(), RecordType.Ptr, token);

                    if ((dnsResult == null) || ((dnsResult.ReturnCode != ReturnCode.NoError) && (dnsResult.ReturnCode != ReturnCode.NxDomain)))
                    {
                        break;
                    }

                    int ptrCheckedCount = 0;
                    foreach (PtrRecord ptrRecord in dnsResult.Records)
                    {
                        if (++ptrCheckedCount == 10)
                        {
                            break;
                        }

                        bool?isPtrMatch = await IsIpMatchAsync(ptrRecord.PointerDomainName, ip, 0, 0, token);

                        if (isPtrMatch.HasValue && isPtrMatch.Value)
                        {
                            if (letter == "unknown" || ptrRecord.PointerDomainName.IsSubDomainOf(domain))
                            {
                                // use value, if first record or subdomain
                                // but evaluate the other records
                                letter = ptrRecord.PointerDomainName.ToString();
                            }
                            else if (ptrRecord.PointerDomainName.Equals(domain))
                            {
                                // ptr equal domain --> best match, use it
                                letter = ptrRecord.PointerDomainName.ToString();
                                break;
                            }
                        }
                    }
                    break;

                case "v":
                    letter = (ip.AddressFamily == AddressFamily.InterNetworkV6) ? "ip6" : "in-addr";
                    break;

                case "h":
                    letter = HeloDomain?.ToString() ?? "unknown";
                    break;

                case "c":
                    IPAddress address =
                        LocalIP
                        ?? NetworkInterface.GetAllNetworkInterfaces()
                        .Where(n => (n.OperationalStatus == OperationalStatus.Up) && (n.NetworkInterfaceType != NetworkInterfaceType.Loopback))
                        .SelectMany(n => n.GetIPProperties().UnicastAddresses)
                        .Select(u => u.Address)
                        .FirstOrDefault(a => a.AddressFamily == ip.AddressFamily)
                        ?? ((ip.AddressFamily == AddressFamily.InterNetwork) ? IPAddress.Loopback : IPAddress.IPv6Loopback);
                    letter = address.ToString();
                    break;

                case "r":
                    letter = LocalDomain?.ToString() ?? System.Net.Dns.GetHostName();
                    break;

                case "t":
                    letter = ((int)(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) - DateTime.Now).TotalSeconds).ToString();
                    break;

                default:
                    return(null);
                }

                // only letter
                if (pattern.Value.Length == 4)
                {
                    return(letter);
                }

                char[] delimiters = pattern.Groups["delimiter"].Value.ToCharArray();
                if (delimiters.Length == 0)
                {
                    delimiters = new[] { '.' }
                }
                ;

                string[] parts = letter.Split(delimiters);

                if (pattern.Groups["reverse"].Value == "r")
                {
                    parts = parts.Reverse().ToArray();
                }

                int count = Int32.MaxValue;
                if (!String.IsNullOrEmpty(pattern.Groups["count"].Value))
                {
                    count = Int32.Parse(pattern.Groups["count"].Value);
                }

                if (count < 1)
                {
                    return(null);
                }

                count = Math.Min(count, parts.Length);

                return(String.Join(".", parts, (parts.Length - count), count));
            }
        }
    }