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"
 
  28 package "exim4-daemon-heavy" if File.exist?("/var/run/clamav/clamd.ctl")
 
  36 template "/tmp/exim.ssl.cnf" do
 
  42     File.exist?("/etc/ssl/certs/exim.pem") && File.exist?("/etc/ssl/private/exim.key")
 
  46 execute "/etc/ssl/certs/exim.pem" do
 
  47   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"
 
  51     File.exist?("/etc/ssl/certs/exim.pem") && File.exist?("/etc/ssl/private/exim.key")
 
  56   action [:enable, :start]
 
  57   supports :status => true, :restart => true, :reload => true
 
  58   subscribes :restart, "execute[/etc/ssl/certs/exim.pem]"
 
  61 relay_to_domains = node[:exim][:relay_to_domains]
 
  63 node[:exim][:routes].each_value do |route|
 
  64   relay_to_domains |= route[:domains] if route[:host]
 
  67 relay_from_hosts = node[:exim][:relay_from_hosts]
 
  69 if node[:exim][:smarthost_name]
 
  70   search(:node, "exim_smarthost_via:#{node[:exim][:smarthost_name]}\\:*").each do |host|
 
  71     relay_from_hosts |= host.ipaddresses(:role => :external)
 
  75 file "/etc/exim4/blocked-senders" do
 
  81 template "/etc/exim4/exim4.conf" do
 
  82   source "exim4.conf.erb"
 
  86   variables :relay_to_domains => relay_to_domains.sort,
 
  87             :relay_from_hosts => relay_from_hosts.sort
 
  88   notifies :restart, "service[exim4]"
 
  91 search(:accounts, "*:*").each do |account|
 
  93   details = node[:accounts][:users][name] || {}
 
  95   if details[:status] && account["email"]
 
  96     node.default[:exim][:aliases][name] = account["email"]
 
 100 if node[:exim][:private_aliases]
 
 101   aliases = data_bag_item("exim", "aliases")
 
 103   aliases[node[:exim][:private_aliases]].each do |name, address|
 
 104     node.default[:exim][:aliases][name] = address
 
 108 template "/etc/aliases" do
 
 115 remote_directory "/etc/exim4/noreply" do
 
 121   files_group "Debian-exim"
 
 126 munin_plugin "exim_mailqueue"
 
 127 munin_plugin "exim_mailstats"
 
 129 if node[:exim][:smarthost_name]
 
 130   node[:exim][:daemon_smtp_ports].each do |port|
 
 131     firewall_rule "accept-inbound-smtp-#{port}" do
 
 141   node[:exim][:daemon_smtp_ports].each do |port|
 
 142     firewall_rule "accept-inbound-smtp-#{port}" do
 
 144       source "bm:mail.openstreetmap.org"
 
 153 if node[:exim][:smarthost_via] # ~FC023
 
 154   firewall_rule "deny-outbound-smtp" do