| 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) |
| 41 | | mailmanPlace (EApp ((EApp ((EVar "mailman_place", _), (EString node, _)), _), (EString ip, _)), _) = |
| 42 | SOME (node, ip) |
| 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 files = ref ([] : TextIO.outstream list) |
| 58 | val write = ref (fn _ : string => ()) |
| 59 | |
| 60 | val () = Env.action_one "mailmanWebHost" |
| 61 | ("hostname", Env.string) |
| 62 | (fn host => |
| 63 | let |
| 64 | val {write, writeDom, close} = Domain.domainsFile {node = Config.Mailman.node, |
| 65 | name = "mailman.conf"} |
| 66 | in |
| 67 | write "\t'"; |
| 68 | write host; |
| 69 | write "' : '"; |
| 70 | writeDom (); |
| 71 | write "',\n"; |
| 72 | close () |
| 73 | end) |
| 74 | |
| 75 | val () = Env.actionV_one "mailmanVhost" |
| 76 | ("host", Env.string) |
| 77 | (fn (env, host) => |
| 78 | let |
| 79 | val places = Env.env (Env.list mailmanPlace) (env, "MailmanPlaces") |
| 80 | |
| 81 | val ssl = Env.env Apache.ssl (env, "SSL") |
| 82 | val user = Env.env Env.string (env, "User") |
| 83 | val sadmin = Env.env Env.string (env, "ServerAdmin") |
| 84 | |
| 85 | val fullHost = host ^ "." ^ Domain.currentDomain () |
| 86 | val vhostId = fullHost ^ (if Option.isSome ssl then ".ssl" else "") |
| 87 | val confFile = fullHost ^ (if Option.isSome ssl then ".vhost_ssl" else ".vhost") |
| 88 | in |
| 89 | app (fn (node, ip) => |
| 90 | let |
| 91 | val file = Domain.domainFile {node = node, |
| 92 | name = confFile} |
| 93 | fun print s = TextIO.output (file, s) |
| 94 | |
| 95 | val ld = Apache.logDir {user = user, node = node, vhostId = vhostId} |
| 96 | in |
| 97 | print "# Owner: "; |
| 98 | print user; |
| 99 | print "\n"; |
| 100 | print "<VirtualHost "; |
| 101 | print ip; |
| 102 | print ":"; |
| 103 | print (case ssl of |
| 104 | SOME _ => "443" |
| 105 | | NONE => "80"); |
| 106 | print ">\n"; |
| 107 | print " ServerName "; |
| 108 | print host; |
| 109 | print "."; |
| 110 | print (Domain.currentDomain ()); |
| 111 | print "\n"; |
| 112 | print " ServerAdmin "; |
| 113 | print sadmin; |
| 114 | print "\n"; |
| 115 | (* |
| 116 | print " SuexecUserGroup list list\n"; |
| 117 | print "\n"; |
| 118 | *) |
| 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 | case ssl of |
| 131 | NONE => () |
| 132 | | SOME _ => print "s"; |
| 133 | print "://"; |
| 134 | print fullHost; |
| 135 | print "/listinfo/\n"; |
| 136 | print "\n"; |
| 137 | print " Alias /images/mailman /usr/share/images/mailman\n"; |
| 138 | print " Alias /pipermail /var/lib/mailman/archives/public\n"; |
| 139 | print "\n"; |
| 140 | print " DocumentRoot /usr/lib/cgi-bin/mailman\n"; |
| 141 | print " <Directory /usr/lib/cgi-bin/mailman>\n"; |
| 142 | print " AllowOverride None\n"; |
| 143 | print " Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch\n"; |
| 144 | print " ForceType cgi-script\n"; |
| 145 | print " Order allow,deny\n"; |
| 146 | print " Allow from all\n"; |
| 147 | print " </Directory>\n"; |
| 148 | print "\n"; |
| 149 | print " <Directory /usr/share/doc/mailman>\n"; |
| 150 | print " Order allow,deny\n"; |
| 151 | print " Allow from all\n"; |
| 152 | print " </Directory>\n"; |
| 153 | print "\n"; |
| 154 | print "\n"; |
| 155 | print " <Directory /usr/share/images/mailman>\n"; |
| 156 | print " Order allow,deny\n"; |
| 157 | print " Allow from all\n"; |
| 158 | print " </Directory>\n"; |
| 159 | print "\n"; |
| 160 | print " <Directory /var/lib/mailman/archives/public/>\n"; |
| 161 | print " Options +SymlinksIfOwnerMatch -ExecCGI +Indexes\n"; |
| 162 | print " Order allow,deny\n"; |
| 163 | print " Allow from all\n"; |
| 164 | print " </Directory>\n"; |
| 165 | |
| 166 | Apache.doPre {user = user, nodes = map #1 places, id = vhostId, hostname = fullHost}; |
| 167 | |
| 168 | print "</VirtualHost>\n"; |
| 169 | |
| 170 | TextIO.closeOut file; |
| 171 | |
| 172 | Apache.doPost () |
| 173 | end) places |
| 174 | end) |
| 175 | |
| 176 | val mailmanChanged = ref false |
| 177 | |
| 178 | val () = Slave.registerPreHandler (fn () => mailmanChanged := false) |
| 179 | |
| 180 | val () = Slave.registerFileHandler (fn fs => |
| 181 | let |
| 182 | val spl = OS.Path.splitDirFile (#file fs) |
| 183 | in |
| 184 | case #file spl of |
| 185 | "mailman.conf" => mailmanChanged := true |
| 186 | | _ => () |
| 187 | end) |
| 188 | |
| 189 | val () = Slave.registerPostHandler (fn () => |
| 190 | if !mailmanChanged then |
| 191 | (Slave.concatTo (fn s => s = "mailman.conf") |
| 192 | Config.Mailman.mapFile; |
| 193 | Slave.enumerateTo (fn s => s = "mailman.conf") ":" |
| 194 | Config.Mailman.handleDomains; |
| 195 | Slave.shellF ([Config.Mailman.reload], |
| 196 | fn cl => "Error reloading Mailman with " ^ cl)) |
| 197 | else |
| 198 | ()) |
| 199 | |
| 200 | val () = Domain.registerDescriber (Domain.considerAll |
| 201 | [Domain.Filename {filename = "mailman.conf", |
| 202 | heading = "Mailman web host mapping:", |
| 203 | showEmpty = false}]) |
| 204 | |
| 205 | end |