bab72223cdf86fe2ee3706782699979e432ca6a0
[hcoop/domtool2.git] / src / plugins / mailman.sml
1 (* HCoop Domtool (http://hcoop.sourceforge.net/)
2 * Copyright (c) 2006, Adam Chlipala
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *)
18
19 (* Mailman mailing list handling *)
20
21 structure Mailman :> MAILMAN = struct
22
23 open Ast
24
25 val () = Env.type_one "mailman_node"
26 Env.string
27 (fn node => Apache.webNode node orelse node = Config.Mailman.node)
28
29 val dl = ErrorMsg.dummyLoc
30
31 val () = Env.registerFunction ("mailman_node",
32 fn [] => SOME (EString Config.Mailman.node, dl)
33 | _ => NONE)
34
35 val () = Env.registerFunction ("mailman_node_to_node",
36 fn [e] => SOME e
37 | _ => NONE)
38
39 fun mailmanPlace (EApp ((EVar "mailman_place_default", _), (EString node, _)), _) =
40 SOME (node, Domain.nodeIp node, Domain.nodeIpv6 node)
41 | mailmanPlace (EApp ((EApp ((EApp ((EVar "mailman_place", _), (EString node, _)), _), (EString ip, _)), _), (EString ipv6, _)), _) =
42 SOME (node, ip, ipv6)
43 | mailmanPlace _ = NONE
44
45 val _ = Env.registerFunction ("mailman_place_to_web_node",
46 fn [e] => Option.map (fn (node, _, _) => (EString node, dl)) (mailmanPlace e)
47 | _ => NONE)
48
49 val _ = Env.registerFunction ("mailman_place_to_node",
50 fn [e] => Option.map (fn (node, _, _) => (EString node, dl)) (mailmanPlace e)
51 | _ => NONE)
52
53 val _ = Env.registerFunction ("mailman_place_to_ip",
54 fn [e] => Option.map (fn (_, ip, _) => (EString ip, dl)) (mailmanPlace e)
55 | _ => NONE)
56
57 val _ = Env.registerFunction ("mailman_place_to_ip",
58 fn [e] => Option.map (fn (_, _, ipv6) => (EString ipv6, dl)) (mailmanPlace e)
59 | _ => NONE)
60
61 val files = ref ([] : TextIO.outstream list)
62 val write = ref (fn _ : string => ())
63
64 val () = Env.action_one "mailmanWebHost"
65 ("hostname", Env.string)
66 (fn host =>
67 let
68 val {write, writeDom, close} = Domain.domainsFile {node = Config.Mailman.node,
69 name = "mailman.conf"}
70 in
71 write "\t'";
72 write host;
73 write "' : '";
74 writeDom ();
75 write "',\n";
76 close ()
77 end)
78
79 val () = Env.actionV_one "mailmanVhost"
80 ("host", Env.string)
81 (fn (env, host) =>
82 let
83 val places = Env.env (Env.list mailmanPlace) (env, "MailmanPlaces")
84
85 val ssl = Env.env Apache.ssl (env, "SSL")
86 val user = Env.env Env.string (env, "User")
87 val sadmin = Env.env Env.string (env, "ServerAdmin")
88
89 val fullHost = host ^ "." ^ Domain.currentDomain ()
90 val vhostId = fullHost ^ (if Option.isSome ssl then ".ssl" else "")
91 val confFile = fullHost ^ (if Option.isSome ssl then ".vhost_ssl" else ".vhost")
92 in
93 app (fn (node, ip, ipv6) =>
94 let
95 val file = Domain.domainFile {node = node,
96 name = confFile}
97 fun print s = TextIO.output (file, s)
98
99 val ld = Apache.logDir {user = user, node = node, vhostId = vhostId}
100 in
101 print "# Owner: ";
102 print user;
103 print "\n";
104 print "<VirtualHost ";
105
106 print ip;
107 print ":";
108 print (case ssl of
109 SOME _ => "443"
110 | NONE => "80");
111
112 print " [";
113 print ipv6;
114 print "]";
115 print ":";
116 print (case ssl of
117 SOME _ => "443"
118 | NONE => "80");
119
120 print ">\n";
121 print " ServerName ";
122 print host;
123 print ".";
124 print (Domain.currentDomain ());
125 print "\n";
126 print " ServerAdmin ";
127 print sadmin;
128 print "\n";
129 case ssl of
130 SOME cert =>
131 (print "\n\tSSLEngine on\n\tSSLCertificateFile ";
132 print cert;
133 print "\n")
134 | NONE => ();
135 (*
136 print " SuexecUserGroup list list\n";
137 print "\n";
138 *)
139 print " ErrorLog ";
140 print ld;
141 print "/error.log\n";
142 print " CustomLog ";
143 print ld;
144 print "/access.log combined\n";
145 print "\n";
146 print " RewriteEngine on\n";
147 print "\n";
148 print " # Default to showing listinfo page\n";
149 print " RewriteRule ^/$ http";
150 case ssl of
151 NONE => ()
152 | SOME _ => print "s";
153 print "://";
154 print fullHost;
155 print "/listinfo/\n";
156 print "\n";
157 print " Alias /images/mailman /usr/share/images/mailman\n";
158 print " Alias /pipermail /var/lib/mailman/archives/public\n";
159 print "\n";
160 print " DocumentRoot /usr/lib/cgi-bin/mailman\n";
161 print " <Directory /usr/lib/cgi-bin/mailman>\n";
162 print " AllowOverride None\n";
163 print " Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch\n";
164 print " ForceType cgi-script\n";
165 print " Order allow,deny\n";
166 print " Allow from all\n";
167 print " </Directory>\n";
168 print "\n";
169 print " <Directory /usr/share/doc/mailman>\n";
170 print " Order allow,deny\n";
171 print " Allow from all\n";
172 print " </Directory>\n";
173 print "\n";
174 print "\n";
175 print " <Directory /usr/share/images/mailman>\n";
176 print " Order allow,deny\n";
177 print " Allow from all\n";
178 print " </Directory>\n";
179 print "\n";
180 print " <Directory /var/lib/mailman/archives/public/>\n";
181 print " Options +SymlinksIfOwnerMatch -ExecCGI +Indexes\n";
182 print " Order allow,deny\n";
183 print " Allow from all\n";
184 print " </Directory>\n";
185
186 Apache.doPre {user = user, nodes = map #1 places, id = vhostId, hostname = fullHost};
187
188 print "</VirtualHost>\n";
189
190 TextIO.closeOut file;
191
192 Apache.doPost ()
193 end) places
194 end)
195
196 val mailmanChanged = ref false
197
198 val () = Slave.registerPreHandler (fn () => mailmanChanged := false)
199
200 val () = Slave.registerFileHandler (fn fs =>
201 let
202 val spl = OS.Path.splitDirFile (#file fs)
203 in
204 case #file spl of
205 "mailman.conf" => mailmanChanged := true
206 | _ => ()
207 end)
208
209 val () = Slave.registerPostHandler (fn () =>
210 if !mailmanChanged then
211 (Slave.concatTo (fn s => s = "mailman.conf")
212 Config.Mailman.mapFile;
213 Slave.enumerateTo (fn s => s = "mailman.conf") ":"
214 Config.Mailman.handleDomains;
215 Slave.shellF ([Config.Mailman.reload],
216 fn cl => "Error reloading Mailman with " ^ cl))
217 else
218 ())
219
220 val () = Domain.registerDescriber (Domain.considerAll
221 [Domain.Filename {filename = "mailman.conf",
222 heading = "Mailman web host mapping:",
223 showEmpty = false}])
224
225 end