1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006, Adam Chlipala
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
.
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
.
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
.
19 (* Mailman mailing list handling
*)
21 structure Mailman
:> MAILMAN
= struct
25 val () = Env
.type_one
"mailman_node"
27 (fn node
=> Apache
.webNode node
orelse node
= Config
.Mailman
.node
)
29 val dl
= ErrorMsg
.dummyLoc
31 val () = Env
.registerFunction ("mailman_node",
32 fn [] => SOME (EString Config
.Mailman
.node
, dl
)
35 val () = Env
.registerFunction ("mailman_node_to_node",
39 fun 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
, _
)), _
) =
43 | mailmanPlace _
= NONE
45 fun mailmanPlaceDefault node
= (EApp ((EVar
"mailman_place_default", dl
), (EString node
, dl
)), dl
)
47 val _
= Env
.registerFunction ("mailman_place_to_web_node",
48 fn [e
] => Option
.map (fn (node
, _
) => (EString node
, dl
)) (mailmanPlace e
)
51 val _
= Env
.registerFunction ("mailman_place_to_node",
52 fn [e
] => Option
.map (fn (node
, _
) => (EString node
, dl
)) (mailmanPlace e
)
55 val _
= Env
.registerFunction ("mailman_place_to_ip",
56 fn [e
] => Option
.map (fn (_
, ip
) => (EString ip
, dl
)) (mailmanPlace e
)
59 val () = Defaults
.registerDefault
61 (TList (TBase
"mailman_place", dl
), dl
),
62 (fn () => (EList
[mailmanPlaceDefault Config
.Mailman
.node
], dl
)))
64 val files
= ref ([] : TextIO.outstream list
)
65 val write
= ref (fn _
: string => ())
67 val () = Env
.action_one
"mailmanWebHost"
68 ("hostname", Env
.string)
71 val {write
, writeDom
, close
} = Domain
.domainsFile
{node
= Config
.Mailman
.node
,
72 name
= "mailman.conf"}
82 val () = Env
.actionV_one
"mailmanVhost"
86 val places
= Env
.env (Env
.list mailmanPlace
) (env
, "MailmanPlaces")
88 val ssl
= Env
.env Apache
.ssl (env
, "SSL")
89 val user
= Env
.env Env
.string (env
, "User")
90 val sadmin
= Env
.env Env
.string (env
, "ServerAdmin")
92 val fullHost
= host ^
"." ^ Domain
.currentDomain ()
93 val vhostId
= fullHost ^
(if Option
.isSome ssl
then ".ssl" else "")
94 val confFile
= fullHost ^
(if Option
.isSome ssl
then ".vhost_ssl" else ".vhost")
98 val file
= Domain
.domainFile
{node
= node
,
100 fun print s
= TextIO.output (file
, s
)
102 val ld
= Apache
.logDir
{user
= user
, node
= node
, vhostId
= vhostId
}
107 print
"<VirtualHost ";
114 print
" ServerName ";
117 print (Domain
.currentDomain ());
119 print
" ServerAdmin ";
122 print
" SuexecUserGroup list list\n";
126 print
"/error.log\n";
129 print
"/access.log combined\n";
131 print
" RewriteEngine on\n";
133 print
" # Default to showing listinfo page\n";
134 print
" RewriteRule ^/$ http";
137 | SOME _
=> print
"s";
140 print
"/listinfo/\n";
142 print
" Alias /images/mailman /usr/share/images/mailman\n";
143 print
" Alias /pipermail /var/lib/mailman/archives/public\n";
145 print
" DocumentRoot /usr/lib/cgi-bin/mailman\n";
146 print
" <Directory /usr/lib/cgi-bin/mailman>\n";
147 print
" AllowOverride None\n";
148 print
" Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch\n";
149 print
" ForceType cgi-script\n";
150 print
" Order allow,deny\n";
151 print
" Allow from all\n";
152 print
" </Directory>\n";
154 print
" <Directory /usr/share/doc/mailman>\n";
155 print
" Order allow,deny\n";
156 print
" Allow from all\n";
157 print
" </Directory>\n";
159 Apache
.doPre
{user
= user
, nodes
= map #
1 places
, id
= vhostId
, hostname
= fullHost
};
161 print
"</VirtualHost>\n";
163 TextIO.closeOut file
;
169 val mailmanChanged
= ref
false
171 val () = Slave
.registerPreHandler (fn () => mailmanChanged
:= false)
173 val () = Slave
.registerFileHandler (fn fs
=>
175 val spl
= OS
.Path
.splitDirFile (#file fs
)
178 "mailman.conf" => mailmanChanged
:= true
182 val () = Slave
.registerPostHandler (fn () =>
183 if !mailmanChanged
then
184 (Slave
.concatTo (fn s
=> s
= "mailman.conf")
185 Config
.Mailman
.mapFile
;
186 Slave
.enumerateTo (fn s
=> s
= "mailman.conf") ":"
187 Config
.Mailman
.handleDomains
;
188 Slave
.shellF ([Config
.Mailman
.reload
],
189 fn cl
=> "Error reloading Mailman with " ^ cl
))
193 val () = Domain
.registerDescriber (Domain
.considerAll
194 [Domain
.Filename
{filename
= "mailman.conf",
195 heading
= "Mailman web host mapping:",