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 # http://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"
25 if File.exist?("/var/run/clamav/clamd.ctl")
26 package "exim4-daemon-heavy"
35 execute "/etc/ssl/certs/exim.pem" do
36 command "openssl req -x509 -newkey rsa:2048 -keyout /etc/ssl/private/exim.key -out /etc/ssl/certs/exim.pem -days 3650 -nodes -subj='/O=OpenStreetMap/CN=#{node[:name]}'"
40 File.exists?("/etc/ssl/certs/exim.pem") && File.exists?("/etc/ssl/private/exim.key")
45 action [ :enable, :start ]
46 supports :status => true, :restart => true, :reload => true
47 subscribes :restart, "execute[/etc/ssl/certs/exim.pem]"
50 relay_to_domains = node[:exim][:relay_to_domains]
52 node[:exim][:routes].each_value do |route|
53 relay_to_domains = relay_to_domains | route[:domains]
56 relay_from_hosts = node[:exim][:relay_from_hosts]
58 if node[:exim][:smarthost_name]
59 search(:node, "exim_smarthost_via:#{node[:exim][:smarthost_name]}\\:*").each do |host|
60 relay_from_hosts = relay_from_hosts | host.ipaddresses(:role => :external)
64 template "/etc/exim4/exim4.conf" do
65 source "exim4.conf.erb"
69 variables :relay_to_domains => relay_to_domains.sort,
70 :relay_from_hosts => relay_from_hosts.sort
71 notifies :restart, resources(:service => "exim4")
74 search(:accounts, "*:*").each do |account|
76 details = node[:accounts][:users][name] || {}
78 if details[:status] and account["email"]
79 node.default[:exim][:aliases][name] = account["email"]
83 if node[:exim][:private_aliases]
84 aliases = data_bag_item("exim", "aliases")
86 aliases[node[:exim][:private_aliases]].each do |name,address|
87 node.default[:exim][:aliases][name] = address
91 template "/etc/aliases" do
98 remote_directory "/etc/exim4/noreply" do
104 files_group "Debian-exim"
109 munin_plugin "exim_mailqueue"
110 munin_plugin "exim_mailstats"
112 if not relay_to_domains.empty? or not node[:exim][:local_domains].empty?
113 node[:exim][:daemon_smtp_ports].each do |port|
114 firewall_rule "accept-inbound-smtp-#{port}" do
125 if node[:exim][:smarthost_via]
126 firewall_rule "deny-outbound-smtp" do