Fix addWordPress
[hcoop/domtool2.git] / src / plugins / mailman.sml
CommitLineData
325285ab
AC
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
21structure Mailman :> MAILMAN = struct
22
de5351c7
AC
23open Ast
24
b5f2d506 25val () = Env.type_one "mailman_node"
de5351c7
AC
26 Env.string
27 (fn node => Apache.webNode node orelse node = Config.Mailman.node)
28
29val dl = ErrorMsg.dummyLoc
30
b5f2d506 31val () = Env.registerFunction ("mailman_node",
e9f528ab
AC
32 fn [] => SOME (EString Config.Mailman.node, dl)
33 | _ => NONE)
34
b5f2d506 35val () = Env.registerFunction ("mailman_node_to_node",
e9f528ab
AC
36 fn [e] => SOME e
37 | _ => NONE)
38
b5f2d506
AC
39fun mailmanPlace (EApp ((EVar "mailman_place_default", _), (EString node, _)), _) =
40 SOME (node, Domain.nodeIp node)
41 | mailmanPlace (EApp ((EApp ((EVar "mailman_place", _), (EString node, _)), _), (EString ip, _)), _) =
42 SOME (node, ip)
43 | mailmanPlace _ = NONE
44
45fun mailmanPlaceDefault node = (EApp ((EVar "mailman_place_default", dl), (EString node, dl)), dl)
46
47val _ = Env.registerFunction ("mailman_place_to_web_node",
48 fn [e] => Option.map (fn (node, _) => (EString node, dl)) (mailmanPlace e)
49 | _ => NONE)
50
51val _ = Env.registerFunction ("mailman_place_to_node",
52 fn [e] => Option.map (fn (node, _) => (EString node, dl)) (mailmanPlace e)
53 | _ => NONE)
54
55val _ = Env.registerFunction ("mailman_place_to_ip",
56 fn [e] => Option.map (fn (_, ip) => (EString ip, dl)) (mailmanPlace e)
57 | _ => NONE)
58
de5351c7 59val () = Defaults.registerDefault
b5f2d506
AC
60 ("MailmanPlaces",
61 (TList (TBase "mailman_place", dl), dl),
62 (fn () => (EList [mailmanPlaceDefault Config.Mailman.node], dl)))
de5351c7 63
325285ab
AC
64val files = ref ([] : TextIO.outstream list)
65val write = ref (fn _ : string => ())
66
67val () = Env.action_one "mailmanWebHost"
68 ("hostname", Env.string)
69 (fn host =>
70 let
85095959
AC
71 val {write, writeDom, close} = Domain.domainsFile {node = Config.Mailman.node,
72 name = "mailman"}
325285ab 73 in
85095959
AC
74 write "\t'";
75 write host;
76 write "' : '";
77 writeDom ();
78 write "',\n";
79 close ()
325285ab
AC
80 end)
81
1c9b5e20
AC
82val () = Env.actionV_one "mailmanVhost"
83 ("host", Env.string)
84 (fn (env, host) =>
85 let
b5f2d506 86 val places = Env.env (Env.list mailmanPlace) (env, "MailmanPlaces")
1c9b5e20
AC
87
88 val ssl = Env.env Apache.ssl (env, "SSL")
89 val user = Env.env Env.string (env, "User")
90
91 val fullHost = host ^ "." ^ Domain.currentDomain ()
92 val vhostId = fullHost ^ (if Option.isSome ssl then ".ssl" else "")
93 val confFile = fullHost ^ (if Option.isSome ssl then ".vhost_ssl" else ".vhost")
94 in
b5f2d506 95 app (fn (node, ip) =>
1c9b5e20
AC
96 let
97 val file = Domain.domainFile {node = node,
98 name = confFile}
99 fun print s = TextIO.output (file, s)
100
101 val ld = Apache.logDir {user = user, node = node, vhostId = vhostId}
102 in
954e17ad
AC
103 print "# Owner: ";
104 print user;
105 print "\n";
1c9b5e20 106 print "<VirtualHost ";
b5f2d506 107 print ip;
1c9b5e20
AC
108 print ":";
109 print (case ssl of
110 SOME _ => "443"
111 | NONE => "80");
de5351c7 112 print ">\n";
1c9b5e20
AC
113 print " ServerName $LISTDOMAIN\n";
114 print " ServerAdmin ";
115 print user;
116 print "@hcoop.net\n";
117 print " SuexecUserGroup list list\n";
118 print "\n";
119 print " ErrorLog ";
120 print ld;
121 print "/error.log\n";
122 print " CustomLog ";
123 print ld;
124 print "/access.log combined\n";
125 print "\n";
126 print " RewriteEngine on\n";
127 print "\n";
128 print " # Default to showing listinfo page\n";
129 print " RewriteRule ^/$ http://";
130 print fullHost;
131 print "/listinfo/\n";
132 print "\n";
133 print " Alias /images/mailman /usr/share/images/mailman\n";
134 print " Alias /pipermail /var/lib/mailman/archives/public\n";
135 print "\n";
136 print " DocumentRoot /usr/lib/cgi-bin/mailman\n";
137 print " <Directory /usr/lib/cgi-bin/mailman>\n";
138 print " AllowOverride None\n";
139 print " Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch\n";
140 print " ForceType cgi-script\n";
141 print " Order allow,deny\n";
142 print " Allow from all\n";
143 print " </Directory>\n";
144 print "\n";
145 print " <Directory /usr/share/doc/mailman>\n";
146 print " Order allow,deny\n";
147 print " Allow from all\n";
148 print " </Directory>\n";
e9f528ab 149
b5f2d506 150 Apache.doPre {user = user, nodes = map #1 places, id = vhostId, hostname = fullHost};
e9f528ab 151
1c9b5e20
AC
152 print "</VirtualHost>\n";
153
e9f528ab
AC
154 TextIO.closeOut file;
155
156 Apache.doPost ()
b5f2d506 157 end) places
1c9b5e20
AC
158 end)
159
325285ab
AC
160val mailmanChanged = ref false
161
162val () = Slave.registerPreHandler (fn () => mailmanChanged := false)
163
164val () = Slave.registerFileHandler (fn fs =>
165 let
166 val spl = OS.Path.splitDirFile (#file fs)
167 in
168 case #file spl of
169 "mailman" => mailmanChanged := true
170 | _ => ()
171 end)
172
173val () = Slave.registerPostHandler (fn () =>
174 if !mailmanChanged then
175 (Slave.concatTo (fn s => s = "mailman")
176 Config.Mailman.mapFile;
5543e924
AC
177 Slave.enumerateTo (fn s => s = "mailman") ":"
178 Config.Mailman.handleDomains;
179 Slave.shellF ([Config.Mailman.reload],
325285ab
AC
180 fn cl => "Error reloading Mailman with " ^ cl))
181 else
182 ())
183
d300166d
AC
184val () = Domain.registerDescriber (Domain.considerAll
185 [Domain.Filename {filename = "mailman",
186 heading = "Mailman web host mapping",
187 showEmpty = false}])
188
325285ab 189end