5 # Copyright:: 2011, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 include_recipe "networking"
21 include_recipe "prometheus"
30 package "exim4-daemon-heavy" do
31 only_if { ::File.exist?("/var/run/clamav/clamd.ctl") }
34 group "Debian-exim" do
38 only_if { ::File.exist?("/var/run/clamav/clamd.ctl") }
47 if node[:exim][:certificate_names]
48 include_recipe "apache"
50 apache_site node[:exim][:certificate_names].first do
52 variables :aliases => node[:exim][:certificate_names].drop(1)
55 ssl_certificate node[:exim][:certificate_names].first do
56 domains node[:exim][:certificate_names]
57 notifies :restart, "service[exim4]"
60 openssl_x509_certificate "/etc/ssl/certs/exim.pem" do
61 key_file "/etc/ssl/private/exim.key"
66 email "postmaster@openstreetmap.org"
67 common_name node[:fqdn]
69 notifies :restart, "service[exim4]"
74 action [:enable, :start]
75 supports :status => true, :restart => true, :reload => true
78 relay_to_domains = node[:exim][:relay_to_domains]
80 node[:exim][:routes].each_value do |route|
81 relay_to_domains |= route[:domains] if route[:host]
84 relay_from_hosts = node[:exim][:relay_from_hosts]
86 if node[:exim][:smarthost_name]
87 search(:node, "exim_smarthost_via:*?").each do |host|
88 relay_from_hosts |= host.ipaddresses(:role => :external)
91 domains = node[:exim][:certificate_names].select { |c| c =~ /^a\.mx\./ }.collect { |c| c.sub(/^a\.mx./, "") }
92 primary_domain = domains.first
94 directory "/srv/mta-sts.#{primary_domain}" do
100 domains.each do |domain|
101 template "/srv/mta-sts.#{primary_domain}/#{domain}.txt" do
106 variables :domain => domain
110 ssl_certificate "mta-sts.#{primary_domain}" do
111 domains domains.collect { |d| "mta-sts.#{d}" }
112 notifies :reload, "service[apache2]"
115 apache_site "mta-sts.#{primary_domain}" do
116 template "apache-mta-sts.erb"
117 directory "/srv/mta-sts.#{primary_domain}"
118 variables :domains => domains
122 file "/etc/exim4/blocked-senders" do
128 file "/etc/exim4/blocked-sender-domains" do
134 if node[:exim][:dkim_selectors]
135 keys = data_bag_item("exim", "dkim")
137 template "/etc/exim4/dkim-domains" do
139 source "dkim-domains.erb"
144 template "/etc/exim4/dkim-selectors" do
146 source "dkim-selectors.erb"
151 directory "/etc/exim4/dkim-keys" do
157 node[:exim][:dkim_selectors].each do |domain, _selector|
158 file "/etc/exim4/dkim-keys/#{domain}" do
159 content keys[domain].join("\n")
167 template "/etc/default/exim4" do
172 notifies :restart, "service[exim4]"
175 template "/etc/exim4/exim4.conf" do
176 source "exim4.conf.erb"
180 variables :relay_to_domains => relay_to_domains.sort,
181 :relay_from_hosts => relay_from_hosts.sort
182 notifies :restart, "service[exim4]"
185 search(:accounts, "*:*").each do |account|
187 details = node[:accounts][:users][name] || {}
189 if details[:status] && account["email"]
190 node.default[:exim][:aliases][name] = account["email"]
194 if node[:exim][:private_aliases]
195 aliases = data_bag_item("exim", "aliases")
197 aliases[node[:exim][:private_aliases]].each do |name, address|
198 node.default[:exim][:aliases][name] = address
202 template "/etc/aliases" do
209 remote_directory "/etc/exim4/noreply" do
215 files_group "Debian-exim"
220 template "/etc/mail.rc" do
227 prometheus_exporter "exim" do
230 protect_proc "default"
233 if node[:exim][:smarthost_name]
234 firewall_rule "accept-inbound-smtp" do
238 dest_ports node[:exim][:daemon_smtp_ports]
239 source_ports "1024-65535"
244 search(:node, "exim_smarthost_name:*?").each do |host|
245 smarthosts |= host.ipaddresses(:role => :external)
248 firewall_rule "accept-inbound-smtp" do
253 dest_ports node[:exim][:daemon_smtp_ports]
254 source_ports "1024-65535"
255 not_if { smarthosts.empty? }
259 if node[:exim][:smarthost_via]
260 firewall_rule "deny-outbound-smtp" do