| 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_web_node" |
| 26 | Env.string |
| 27 | (fn node => Apache.webNode node orelse node = Config.Mailman.node) |
| 28 | |
| 29 | val dl = ErrorMsg.dummyLoc |
| 30 | |
| 31 | val () = Defaults.registerDefault |
| 32 | ("MailmanWebNodes", |
| 33 | (TList (TBase "mailman_web_node", dl), dl), |
| 34 | (fn () => (EList [(EString Config.Mailman.node, dl)], dl))) |
| 35 | |
| 36 | val files = ref ([] : TextIO.outstream list) |
| 37 | val write = ref (fn _ : string => ()) |
| 38 | |
| 39 | val () = Env.action_one "mailmanWebHost" |
| 40 | ("hostname", Env.string) |
| 41 | (fn host => |
| 42 | let |
| 43 | val {write, writeDom, close} = Domain.domainsFile {node = Config.Mailman.node, |
| 44 | name = "mailman"} |
| 45 | in |
| 46 | write "\t'"; |
| 47 | write host; |
| 48 | write "' : '"; |
| 49 | writeDom (); |
| 50 | write "',\n"; |
| 51 | close () |
| 52 | end) |
| 53 | |
| 54 | val () = Env.actionV_one "mailmanVhost" |
| 55 | ("host", Env.string) |
| 56 | (fn (env, host) => |
| 57 | let |
| 58 | val nodes = Env.env (Env.list Env.string) (env, "MailmanWebNodes") |
| 59 | |
| 60 | val ssl = Env.env Apache.ssl (env, "SSL") |
| 61 | val user = Env.env Env.string (env, "User") |
| 62 | |
| 63 | val fullHost = host ^ "." ^ Domain.currentDomain () |
| 64 | val vhostId = fullHost ^ (if Option.isSome ssl then ".ssl" else "") |
| 65 | val confFile = fullHost ^ (if Option.isSome ssl then ".vhost_ssl" else ".vhost") |
| 66 | in |
| 67 | app (fn node => |
| 68 | let |
| 69 | val file = Domain.domainFile {node = node, |
| 70 | name = confFile} |
| 71 | fun print s = TextIO.output (file, s) |
| 72 | |
| 73 | val ld = Apache.logDir {user = user, node = node, vhostId = vhostId} |
| 74 | in |
| 75 | print "# Owner: "; |
| 76 | print user; |
| 77 | print "\n"; |
| 78 | print "<VirtualHost "; |
| 79 | print (Domain.nodeIp node); |
| 80 | print ":"; |
| 81 | print (case ssl of |
| 82 | SOME _ => "443" |
| 83 | | NONE => "80"); |
| 84 | print ">\n"; |
| 85 | print " ServerName $LISTDOMAIN\n"; |
| 86 | print " ServerAdmin "; |
| 87 | print user; |
| 88 | print "@hcoop.net\n"; |
| 89 | print " SuexecUserGroup list list\n"; |
| 90 | print "\n"; |
| 91 | print " ErrorLog "; |
| 92 | print ld; |
| 93 | print "/error.log\n"; |
| 94 | print " CustomLog "; |
| 95 | print ld; |
| 96 | print "/access.log combined\n"; |
| 97 | print "\n"; |
| 98 | print " RewriteEngine on\n"; |
| 99 | print "\n"; |
| 100 | print " # Default to showing listinfo page\n"; |
| 101 | print " RewriteRule ^/$ http://"; |
| 102 | print fullHost; |
| 103 | print "/listinfo/\n"; |
| 104 | print "\n"; |
| 105 | print " Alias /images/mailman /usr/share/images/mailman\n"; |
| 106 | print " Alias /pipermail /var/lib/mailman/archives/public\n"; |
| 107 | print "\n"; |
| 108 | print " DocumentRoot /usr/lib/cgi-bin/mailman\n"; |
| 109 | print " <Directory /usr/lib/cgi-bin/mailman>\n"; |
| 110 | print " AllowOverride None\n"; |
| 111 | print " Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch\n"; |
| 112 | print " ForceType cgi-script\n"; |
| 113 | print " Order allow,deny\n"; |
| 114 | print " Allow from all\n"; |
| 115 | print " </Directory>\n"; |
| 116 | print "\n"; |
| 117 | print " <Directory /usr/share/doc/mailman>\n"; |
| 118 | print " Order allow,deny\n"; |
| 119 | print " Allow from all\n"; |
| 120 | print " </Directory>\n"; |
| 121 | print "</VirtualHost>\n"; |
| 122 | |
| 123 | TextIO.closeOut file |
| 124 | end) nodes |
| 125 | end) |
| 126 | |
| 127 | val mailmanChanged = ref false |
| 128 | |
| 129 | val () = Slave.registerPreHandler (fn () => mailmanChanged := false) |
| 130 | |
| 131 | val () = Slave.registerFileHandler (fn fs => |
| 132 | let |
| 133 | val spl = OS.Path.splitDirFile (#file fs) |
| 134 | in |
| 135 | case #file spl of |
| 136 | "mailman" => mailmanChanged := true |
| 137 | | _ => () |
| 138 | end) |
| 139 | |
| 140 | val () = Slave.registerPostHandler (fn () => |
| 141 | if !mailmanChanged then |
| 142 | (Slave.concatTo (fn s => s = "mailman") |
| 143 | Config.Mailman.mapFile; |
| 144 | Slave.enumerateTo (fn s => s = "mailman") ":" |
| 145 | Config.Mailman.handleDomains; |
| 146 | Slave.shellF ([Config.Mailman.reload], |
| 147 | fn cl => "Error reloading Mailman with " ^ cl)) |
| 148 | else |
| 149 | ()) |
| 150 | |
| 151 | val () = Domain.registerDescriber (Domain.considerAll |
| 152 | [Domain.Filename {filename = "mailman", |
| 153 | heading = "Mailman web host mapping", |
| 154 | showEmpty = false}]) |
| 155 | |
| 156 | end |