]> git.openstreetmap.org Git - chef.git/blob - cookbooks/exim/recipes/default.rb
Drop some old dev sites
[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
22 package "exim4"
23 package "openssl"
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 template "/tmp/exim.ssl.cnf" do
36   source "ssl.cnf.erb"
37   owner "root"
38   group "root"
39   mode 0644
40    not_if do
41     File.exists?("/etc/ssl/certs/exim.pem") and File.exists?("/etc/ssl/private/exim.key")
42   end 
43 end
44
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"
47   user "root"
48   group "ssl-cert"
49   not_if do
50     File.exists?("/etc/ssl/certs/exim.pem") and File.exists?("/etc/ssl/private/exim.key")
51   end
52 end
53
54 service "exim4" do
55   action [ :enable, :start ]
56   supports :status => true, :restart => true, :reload => true
57   subscribes :restart, "execute[/etc/ssl/certs/exim.pem]"
58 end
59
60 relay_to_domains = node[:exim][:relay_to_domains]
61
62 node[:exim][:routes].each_value do |route|
63   relay_to_domains = relay_to_domains | route[:domains] if route[:host]
64 end
65
66 relay_from_hosts = node[:exim][:relay_from_hosts]
67
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)
71   end
72 end
73
74 template "/etc/exim4/exim4.conf" do
75   source "exim4.conf.erb"
76   owner "root"
77   group "Debian-exim"
78   mode 0644
79   variables :relay_to_domains => relay_to_domains.sort,
80             :relay_from_hosts => relay_from_hosts.sort
81   notifies :restart, "service[exim4]"
82 end
83
84 template "/etc/exim4/callout_exempt_senders" do
85   source "callout_exempt_senders.erb"
86   owner "root"
87   group "Debian-exim"
88   mode 0644
89 end
90
91 search(:accounts, "*:*").each do |account|
92   name = account["id"]
93   details = node[:accounts][:users][name] || {}
94
95   if details[:status] and account["email"]
96     node.default[:exim][:aliases][name] = account["email"]
97   end
98 end
99
100 if node[:exim][:private_aliases]
101   aliases = data_bag_item("exim", "aliases")
102
103   aliases[node[:exim][:private_aliases]].each do |name,address|
104     node.default[:exim][:aliases][name] = address
105   end
106 end
107
108 template "/etc/aliases" do
109   source "aliases.erb"
110   owner "root"
111   group "root"
112   mode 0644
113 end
114
115 remote_directory "/etc/exim4/noreply" do
116   source "noreply"
117   owner "root"
118   group "Debian-exim"
119   mode 0755
120   files_owner "root"
121   files_group "Debian-exim"
122   files_mode 0755
123   purge true
124 end
125
126 munin_plugin "exim_mailqueue"
127 munin_plugin "exim_mailstats"
128
129 if node[:exim][:smarthost_name]
130   node[:exim][:daemon_smtp_ports].each do |port|
131     firewall_rule "accept-inbound-smtp-#{port}" do
132       action :accept
133       source "net"
134       dest "fw"
135       proto "tcp:syn"
136       dest_ports port
137       source_ports "1024:"
138     end
139   end
140 else
141   node[:exim][:daemon_smtp_ports].each do |port|
142     firewall_rule "accept-inbound-smtp-#{port}" do
143       action :accept
144       source "bm:mail.openstreetmap.org"
145       dest "fw"
146       proto "tcp:syn"
147       dest_ports port
148       source_ports "1024:"
149     end
150   end
151 end
152
153 if node[:exim][:smarthost_via]
154   firewall_rule "deny-outbound-smtp" do
155     action :reject
156     source "fw"
157     dest "net"
158     proto "tcp:syn"
159     dest_ports "smtp"
160   end
161 end