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 template "/tmp/exim.ssl.cnf" do
 
  41     File.exists?("/etc/ssl/certs/exim.pem") and File.exists?("/etc/ssl/private/exim.key")
 
  45 execute "/etc/ssl/certs/exim.pem" do
 
  46   command "openssl req -x509 -newkey rsa:2048 -keyout /etc/ssl/private/exim.key -out /etc/ssl/certs/exim.pem -days 3650 -nodes -config /tmp/exim.ssl.cnf"
 
  50     File.exists?("/etc/ssl/certs/exim.pem") and File.exists?("/etc/ssl/private/exim.key")
 
  55   action [ :enable, :start ]
 
  56   supports :status => true, :restart => true, :reload => true
 
  57   subscribes :restart, "execute[/etc/ssl/certs/exim.pem]"
 
  60 relay_to_domains = node[:exim][:relay_to_domains]
 
  62 node[:exim][:routes].each_value do |route|
 
  63   relay_to_domains = relay_to_domains | route[:domains] if route[:host]
 
  66 relay_from_hosts = node[:exim][:relay_from_hosts]
 
  68 if node[:exim][:smarthost_name]
 
  69   search(:node, "exim_smarthost_via:#{node[:exim][:smarthost_name]}\\:*").each do |host|
 
  70     relay_from_hosts = relay_from_hosts | host.ipaddresses(:role => :external)
 
  74 template "/etc/exim4/exim4.conf" do
 
  75   source "exim4.conf.erb"
 
  79   variables :relay_to_domains => relay_to_domains.sort,
 
  80             :relay_from_hosts => relay_from_hosts.sort
 
  81   notifies :restart, "service[exim4]"
 
  84 search(:accounts, "*:*").each do |account|
 
  86   details = node[:accounts][:users][name] || {}
 
  88   if details[:status] and account["email"]
 
  89     node.default[:exim][:aliases][name] = account["email"]
 
  93 if node[:exim][:private_aliases]
 
  94   aliases = data_bag_item("exim", "aliases")
 
  96   aliases[node[:exim][:private_aliases]].each do |name,address|
 
  97     node.default[:exim][:aliases][name] = address
 
 101 template "/etc/aliases" do
 
 108 remote_directory "/etc/exim4/noreply" do
 
 114   files_group "Debian-exim"
 
 119 munin_plugin "exim_mailqueue"
 
 120 munin_plugin "exim_mailstats"
 
 122 if node[:exim][:smarthost_name]
 
 123   node[:exim][:daemon_smtp_ports].each do |port|
 
 124     firewall_rule "accept-inbound-smtp-#{port}" do
 
 134   node[:exim][:daemon_smtp_ports].each do |port|
 
 135     firewall_rule "accept-inbound-smtp-#{port}" do
 
 137       source "bm:mail.openstreetmap.org"
 
 146 if node[:exim][:smarthost_via]
 
 147   firewall_rule "deny-outbound-smtp" do