]> git.openstreetmap.org Git - chef.git/blob - cookbooks/exim/recipes/default.rb
Fix generation of mail aliases to reflect account changes
[chef.git] / cookbooks / exim / recipes / default.rb
1 #
2 # Cookbook Name:: exim
3 # Recipe:: default
4 #
5 # Copyright 2011, OpenStreetMap Foundation
6 #
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
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "networking"
21 include_recipe "ssl"
22
23 package "exim4"
24
25 if File.exist?("/var/run/clamav/clamd.ctl")
26   package "exim4-daemon-heavy"
27 end
28
29 group "ssl-cert" do
30   action :modify
31   members "Debian-exim"
32   append true
33 end
34
35 service "exim4" do
36   action [ :enable, :start ]
37   supports :status => true, :restart => true, :reload => true
38   subscribes :restart, resources(:cookbook_file => "/etc/ssl/certs/openstreetmap.pem")
39   subscribes :restart, resources(:file => "/etc/ssl/private/openstreetmap.key")
40 end
41
42 relay_to_domains = node[:exim][:relay_to_domains]
43
44 node[:exim][:routes].each_value do |route|
45   relay_to_domains = relay_to_domains | route[:domains]
46 end
47
48 relay_from_hosts = node[:exim][:relay_from_hosts]
49
50 if node[:exim][:smarthost_name]
51   search(:node, "exim_smarthost_via:#{node[:exim][:smarthost_name]}\\:*").each do |host|
52     relay_from_hosts = relay_from_hosts | host.ipaddresses(:role => :external)
53   end
54 end
55
56 template "/etc/exim4/exim4.conf" do
57   source "exim4.conf.erb"
58   owner "root"
59   group "Debian-exim"
60   mode 0644
61   variables :relay_to_domains => relay_to_domains.sort,
62             :relay_from_hosts => relay_from_hosts.sort
63   notifies :restart, resources(:service => "exim4")
64 end
65
66 search(:accounts, "*:*").each do |account|
67   name = account["id"]
68   details = node[:accounts][:users][name] || {}
69
70   if details[:status] and account["email"]
71     node.default[:exim][:aliases][name] = account["email"]
72   end
73 end
74
75 template "/etc/aliases" do
76   source "aliases.erb"
77   owner "root"
78   group "root"
79   mode 0644
80 end
81
82 remote_directory "/etc/exim4/noreply" do
83   source "noreply"
84   owner "root"
85   group "Debian-exim"
86   mode 0755
87   files_owner "root"
88   files_group "Debian-exim"
89   files_mode 0755
90   purge true
91 end
92
93 munin_plugin "exim_mailqueue"
94 munin_plugin "exim_mailstats"
95
96 if not relay_to_domains.empty? or not node[:exim][:local_domains].empty?
97   node[:exim][:daemon_smtp_ports].each do |port|
98     firewall_rule "accept-inbound-smtp-#{port}" do
99       action :accept
100       source "net"
101       dest "fw"
102       proto "tcp:syn"
103       dest_ports port
104       source_ports "1024:"
105     end
106   end
107 end
108
109 if node[:exim][:smarthost_via]
110   firewall_rule "deny-outbound-smtp" do
111     action :reject
112     source "fw"
113     dest "net"
114     proto "tcp:syn"
115     dest_ports "smtp"
116   end
117 end