Catch-all aliases working again
[hcoop/domtool2.git] / src / plugins / apache.sml
1 (* HCoop Domtool (http://hcoop.sourceforge.net/)
2 * Copyright (c) 2006-2007, 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 (* Apache HTTPD handling *)
20
21 structure Apache :> APACHE = struct
22
23 open Ast
24
25 val dl = ErrorMsg.dummyLoc
26
27 fun webNode node =
28 List.exists (fn (x, _) => x = node) Config.Apache.webNodes_all
29 orelse (Domain.hasPriv "www"
30 andalso List.exists (fn (x, _) => x = node) Config.Apache.webNodes_admin)
31
32 val _ = Env.type_one "web_node"
33 Env.string
34 webNode
35
36 val _ = Env.registerFunction ("web_node_to_node",
37 fn [e] => SOME e
38 | _ => NONE)
39
40 fun webPlace (EApp ((EVar "web_place_default", _), (EString node, _)), _) =
41 SOME (node, Domain.nodeIp node)
42 | webPlace (EApp ((EApp ((EVar "web_place", _), (EString node, _)), _), (EString ip, _)), _) =
43 SOME (node, ip)
44 | webPlace _ = NONE
45
46 fun webPlaceDefault node = (EApp ((EVar "web_place_default", dl), (EString node, dl)), dl)
47
48 val _ = Env.registerFunction ("web_place_to_web_node",
49 fn [e] => Option.map (fn (node, _) => (EString node, dl)) (webPlace e)
50 | _ => NONE)
51
52 val _ = Env.registerFunction ("web_place_to_node",
53 fn [e] => Option.map (fn (node, _) => (EString node, dl)) (webPlace e)
54 | _ => NONE)
55
56 val _ = Env.registerFunction ("web_place_to_ip",
57 fn [e] => Option.map (fn (_, ip) => (EString ip, dl)) (webPlace e)
58 | _ => NONE)
59
60 val _ = Env.type_one "proxy_port"
61 Env.int
62 (fn n => n > 1024)
63
64 val _ = Env.type_one "proxy_target"
65 Env.string
66 (fn s =>
67 let
68 fun default () = List.exists (fn s' => s = s') Config.Apache.proxyTargets
69 in
70 case String.fields (fn ch => ch = #":") s of
71 ["http", "//localhost", rest] =>
72 (case String.fields (fn ch => ch = #"/") rest of
73 port :: _ =>
74 (case Int.fromString port of
75 NONE => default ()
76 | SOME n => n > 1024 orelse default ())
77 | _ => default ())
78 | _ => default ()
79 end)
80
81 val _ = Env.type_one "rewrite_arg"
82 Env.string
83 (CharVector.all Char.isAlphaNum)
84
85 val _ = Env.type_one "suexec_flag"
86 Env.bool
87 (fn b => b orelse Domain.hasPriv "www")
88
89 fun validLocation s =
90 size s > 0 andalso size s < 1000 andalso CharVector.all
91 (fn ch => Char.isAlphaNum ch
92 orelse ch = #"-"
93 orelse ch = #"_"
94 orelse ch = #"."
95 orelse ch = #"/") s
96
97 val _ = Env.type_one "location"
98 Env.string
99 validLocation
100
101 fun validCert s = Acl.query {user = Domain.getUser (),
102 class = "cert",
103 value = s}
104
105 val _ = Env.type_one "ssl_cert_path"
106 Env.string
107 validCert
108
109 fun ssl e = case e of
110 (EVar "no_ssl", _) => SOME NONE
111 | (EApp ((EVar "use_cert", _), s), _) => Option.map SOME (Env.string s)
112 | _ => NONE
113
114 val defaults = [("WebPlaces",
115 (TList (TBase "web_place", dl), dl),
116 (fn () => (EList (map webPlaceDefault Config.Apache.webNodes_default), dl))),
117 ("SSL",
118 (TBase "ssl", dl),
119 (fn () => (EVar "no_ssl", dl))),
120 ("User",
121 (TBase "your_user", dl),
122 (fn () => (EString (Domain.getUser ()), dl))),
123 ("Group",
124 (TBase "your_group", dl),
125 (fn () => (EString "nogroup", dl))),
126 ("DocumentRoot",
127 (TBase "your_path", dl),
128 (fn () => (EString (Domain.homedir () ^ "/" ^ Config.Apache.public_html), dl))),
129 ("ServerAdmin",
130 (TBase "email", dl),
131 (fn () => (EString (Domain.getUser () ^ "@" ^ Config.defaultDomain), dl))),
132 ("SuExec",
133 (TBase "suexec_flag", dl),
134 (fn () => (EVar "true", dl)))]
135
136 val () = app Defaults.registerDefault defaults
137
138 val redirect_code = fn (EVar "temp", _) => SOME "temp"
139 | (EVar "permanent", _) => SOME "permanent"
140 | (EVar "seeother", _) => SOME "seeother"
141 | (EVar "redir300", _) => SOME "300"
142 | (EVar "redir301", _) => SOME "301"
143 | (EVar "redir302", _) => SOME "302"
144 | (EVar "redir303", _) => SOME "303"
145 | (EVar "redir304", _) => SOME "304"
146 | (EVar "redir305", _) => SOME "305"
147 | (EVar "redir307", _) => SOME "307"
148 | _ => NONE
149
150 val flag = fn (EVar "redirect", _) => SOME "R"
151 | (EVar "forbidden", _) => SOME "F"
152 | (EVar "gone", _) => SOME "G"
153 | (EVar "last", _) => SOME "L"
154 | (EVar "chain", _) => SOME "C"
155 | (EVar "nosubreq", _) => SOME "NS"
156 | (EVar "nocase", _) => SOME "NC"
157 | (EVar "qsappend", _) => SOME "QSA"
158 | (EVar "noescape", _) => SOME "NE"
159 | (EVar "passthrough", _) => SOME "PT"
160 | (EApp ((EVar "mimeType", _), e), _) =>
161 Option.map (fn s => "T=" ^ s) (Env.string e)
162 | (EApp ((EVar "redirectWith", _), e), _) =>
163 Option.map (fn s => "R=" ^ s) (redirect_code e)
164 | (EApp ((EVar "skip", _), e), _) =>
165 Option.map (fn n => "S=" ^ Int.toString n) (Env.int e)
166 | (EApp ((EApp ((EVar "env", _), e1), _), e2), _) =>
167 (case Env.string e1 of
168 NONE => NONE
169 | SOME s1 => Option.map (fn s2 => "E=" ^ s1 ^ ":" ^ s2)
170 (Env.string e2))
171
172 | _ => NONE
173
174 val cond_flag = fn (EVar "cond_nocase", _) => SOME "NC"
175 | (EVar "ornext", _) => SOME "OR"
176 | _ => NONE
177
178 val apache_option = fn (EVar "execCGI", _) => SOME "ExecCGI"
179 | (EVar "includesNOEXEC", _) => SOME "IncludesNOEXEC"
180 | (EVar "indexes", _) => SOME "Indexes"
181 | (EVar "followSymLinks", _) => SOME "FollowSymLinks"
182 | _ => NONE
183
184 val autoindex_width = fn (EVar "autofit", _) => SOME "*"
185 | (EApp ((EVar "characters", _), n), _) =>
186 Option.map Int.toString (Env.int n)
187 | _ => NONE
188
189 val autoindex_option = fn (EApp ((EVar "descriptionWidth", _), w), _) =>
190 Option.map (fn w => ("DescriptionWidth", SOME w))
191 (autoindex_width w)
192 | (EVar "fancyIndexing", _) => SOME ("FancyIndexing", NONE)
193 | (EVar "foldersFirst", _) => SOME ("FoldersFirst", NONE)
194 | (EVar "htmlTable", _) => SOME ("HTMLTable", NONE)
195 | (EVar "iconsAreLinks", _) => SOME ("IconsAreLinks", NONE)
196 | (EApp ((EVar "iconHeight", _), n), _) =>
197 Option.map (fn w => ("IconHeight", SOME (Int.toString w)))
198 (Env.int n)
199 | (EApp ((EVar "iconWidth", _), n), _) =>
200 Option.map (fn w => ("IconWidth", SOME (Int.toString w)))
201 (Env.int n)
202 | (EVar "ignoreCase", _) => SOME ("IgnoreCase", NONE)
203 | (EVar "ignoreClient", _) => SOME ("IgnoreClient", NONE)
204 | (EApp ((EVar "nameWidth", _), w), _) =>
205 Option.map (fn w => ("NameWidth", SOME w))
206 (autoindex_width w)
207 | (EVar "scanHtmlTitles", _) => SOME ("ScanHTMLTitles", NONE)
208 | (EVar "suppressColumnSorting", _) => SOME ("SuppressColumnSorting", NONE)
209 | (EVar "suppressDescription", _) => SOME ("SuppressDescription", NONE)
210 | (EVar "suppressHtmlPreamble", _) => SOME ("SuppressHTMLPreamble", NONE)
211 | (EVar "suppressIcon", _) => SOME ("SuppressIcon", NONE)
212 | (EVar "suppressLastModified", _) => SOME ("SuppressLastModified", NONE)
213 | (EVar "suppressRules", _) => SOME ("SuppressRules", NONE)
214 | (EVar "suppressSize", _) => SOME ("SuppressSize", NONE)
215 | (EVar "trackModified", _) => SOME ("TrackModified", NONE)
216 | (EVar "versionSort", _) => SOME ("VersionSort", NONE)
217 | (EVar "xhtml", _) => SOME ("XHTML", NONE)
218
219 | _ => NONE
220
221 val vhostsChanged = ref false
222 val logDeleted = ref false
223
224 val () = Slave.registerPreHandler
225 (fn () => (vhostsChanged := false;
226 logDeleted := false))
227
228 fun findVhostUser fname =
229 let
230 val inf = TextIO.openIn fname
231
232 fun loop () =
233 case TextIO.inputLine inf of
234 NONE => NONE
235 | SOME line =>
236 if String.isPrefix "# Owner: " line then
237 case String.tokens Char.isSpace line of
238 [_, _, user] => SOME user
239 | _ => NONE
240 else
241 loop ()
242 in
243 loop ()
244 before TextIO.closeIn inf
245 end handle _ => NONE
246
247 val webNodes_full = Config.Apache.webNodes_all @ Config.Apache.webNodes_admin
248
249 fun isVersion1 node =
250 List.exists (fn (n, {version = ConfigTypes.APACHE_1_3, ...}) => n = node
251 | _ => false) webNodes_full
252
253 fun imVersion1 () = isVersion1 (Slave.hostname ())
254
255 fun isWaklog node =
256 List.exists (fn (n, {auth = ConfigTypes.MOD_WAKLOG, ...}) => n = node
257 | _ => false) webNodes_full
258
259 fun down () = if imVersion1 () then Config.Apache.down1 else Config.Apache.down
260 fun undown () = if imVersion1 () then Config.Apache.undown1 else Config.Apache.undown
261 fun reload () = if imVersion1 () then Config.Apache.reload1 else Config.Apache.reload
262 fun fixperms () = if imVersion1 () then Config.Apache.fixperms1 else Config.Apache.fixperms
263
264 fun logDir {user, node, vhostId} =
265 String.concat [Config.Apache.logDirOf (isVersion1 node) user,
266 "/",
267 node,
268 "/",
269 vhostId]
270
271 fun realLogDir {user, node, vhostId} =
272 String.concat [Config.Apache.realLogDirOf user,
273 "/",
274 node,
275 "/",
276 vhostId]
277
278 val () = Slave.registerFileHandler (fn fs =>
279 let
280 val spl = OS.Path.splitDirFile (#file fs)
281 in
282 if String.isSuffix ".vhost" (#file spl)
283 orelse String.isSuffix ".vhost_ssl" (#file spl) then let
284 val realVhostFile = OS.Path.joinDirFile
285 {dir = Config.Apache.confDir,
286 file = #file spl}
287
288 val user = findVhostUser (#file fs)
289 val oldUser = case #action fs of
290 Slave.Delete false => user
291 | _ => findVhostUser realVhostFile
292 in
293 if (oldUser = NONE andalso #action fs <> Slave.Add)
294 orelse (user = NONE andalso not (Slave.isDelete (#action fs))) then
295 print ("Can't find user in " ^ #file fs ^ " or " ^ realVhostFile ^ "! Taking no action.\n")
296 else
297 let
298 val vhostId = if OS.Path.ext (#file spl) = SOME "vhost_ssl" then
299 OS.Path.base (#file spl) ^ ".ssl"
300 else
301 OS.Path.base (#file spl)
302
303 fun realLogDir user =
304 logDir {user = valOf user,
305 node = Slave.hostname (),
306 vhostId = vhostId}
307
308 fun backupLogs () =
309 OS.Path.joinDirFile
310 {dir = Config.Apache.backupLogDirOf
311 (isVersion1 (Slave.hostname ())),
312 file = vhostId}
313 in
314 vhostsChanged := true;
315 case #action fs of
316 Slave.Delete _ =>
317 let
318 val ldir = realLogDir oldUser
319 in
320 if !logDeleted then
321 ()
322 else
323 (ignore (OS.Process.system (down ()));
324 ignore (OS.Process.system (fixperms ()));
325 logDeleted := true);
326 ignore (OS.Process.system (Config.rm
327 ^ " -rf "
328 ^ realVhostFile));
329 Slave.moveDirCreate {from = ldir,
330 to = backupLogs ()}
331 end
332 | Slave.Add =>
333 let
334 val rld = realLogDir user
335 in
336 ignore (OS.Process.system (Config.cp
337 ^ " "
338 ^ #file fs
339 ^ " "
340 ^ realVhostFile));
341 if Posix.FileSys.access (rld, []) then
342 ()
343 else
344 Slave.moveDirCreate {from = backupLogs (),
345 to = rld}
346 end
347
348 | _ =>
349 (ignore (OS.Process.system (Config.cp
350 ^ " "
351 ^ #file fs
352 ^ " "
353 ^ realVhostFile));
354 if user <> oldUser then
355 let
356 val old = realLogDir oldUser
357 val rld = realLogDir user
358 in
359 if !logDeleted then
360 ()
361 else
362 (ignore (OS.Process.system (down ()));
363 logDeleted := true);
364 ignore (OS.Process.system (Config.rm
365 ^ " -rf "
366 ^ realLogDir oldUser));
367 if Posix.FileSys.access (rld, []) then
368 ()
369 else
370 Slave.mkDirAll rld
371 end
372 else
373 ())
374 end
375 end
376 else
377 ()
378 end)
379
380 val () = Slave.registerPostHandler
381 (fn () =>
382 (if !vhostsChanged then
383 Slave.shellF ([if !logDeleted then undown () else reload ()],
384 fn cl => "Error reloading Apache with " ^ cl)
385 else
386 ()))
387
388 val vhostFiles : (string * TextIO.outstream) list ref = ref []
389 fun write' s = app (fn (node, file) => TextIO.output (file, s node)) (!vhostFiles)
390 fun write s = app (fn (_, file) => TextIO.output (file, s)) (!vhostFiles)
391
392 val rewriteEnabled = ref false
393 val localRewriteEnabled = ref false
394 val currentVhost = ref ""
395 val currentVhostId = ref ""
396 val sslEnabled = ref false
397
398 val pre = ref (fn _ : {user : string, nodes : string list, id : string, hostname : string} => ())
399 fun registerPre f =
400 let
401 val old = !pre
402 in
403 pre := (fn x => (old x; f x))
404 end
405
406 val post = ref (fn () => ())
407 fun registerPost f =
408 let
409 val old = !post
410 in
411 post := (fn () => (old (); f ()))
412 end
413
414 fun doPre x = !pre x
415 fun doPost () = !post ()
416
417 val aliaser = ref (fn _ : string => ())
418 fun registerAliaser f =
419 let
420 val old = !aliaser
421 in
422 aliaser := (fn x => (old x; f x))
423 end
424
425 val () = Env.containerV_one "vhost"
426 ("host", Env.string)
427 (fn (env, host) =>
428 let
429 val places = Env.env (Env.list webPlace) (env, "WebPlaces")
430
431 val ssl = Env.env ssl (env, "SSL")
432 val user = Env.env Env.string (env, "User")
433 val group = Env.env Env.string (env, "Group")
434 val docroot = Env.env Env.string (env, "DocumentRoot")
435 val sadmin = Env.env Env.string (env, "ServerAdmin")
436 val suexec = Env.env Env.bool (env, "SuExec")
437
438 val fullHost = host ^ "." ^ Domain.currentDomain ()
439 val vhostId = fullHost ^ (if Option.isSome ssl then ".ssl" else "")
440 val confFile = fullHost ^ (if Option.isSome ssl then ".vhost_ssl" else ".vhost")
441 in
442 currentVhost := fullHost;
443 currentVhostId := vhostId;
444 sslEnabled := Option.isSome ssl;
445
446 rewriteEnabled := false;
447 localRewriteEnabled := false;
448 vhostFiles := map (fn (node, ip) =>
449 let
450 val file = Domain.domainFile {node = node,
451 name = confFile}
452
453 val ld = logDir {user = user, node = node, vhostId = vhostId}
454 in
455 TextIO.output (file, "# Owner: ");
456 TextIO.output (file, user);
457 TextIO.output (file, "\n<VirtualHost ");
458 TextIO.output (file, ip);
459 TextIO.output (file, ":");
460 TextIO.output (file, case ssl of
461 SOME _ => "443"
462 | NONE => "80");
463 TextIO.output (file, ">\n");
464 TextIO.output (file, "\tErrorLog ");
465 TextIO.output (file, ld);
466 TextIO.output (file, "/error.log\n\tCustomLog ");
467 TextIO.output (file, ld);
468 TextIO.output (file, "/access.log combined\n");
469 TextIO.output (file, "\tServerName ");
470 TextIO.output (file, fullHost);
471 app
472 (fn dom => (TextIO.output (file, "\n\tServerAlias ");
473 TextIO.output (file, host);
474 TextIO.output (file, ".");
475 TextIO.output (file, dom)))
476 (Domain.currentAliasDomains ());
477
478 if suexec then
479 if isVersion1 node then
480 (TextIO.output (file, "\n\tUser ");
481 TextIO.output (file, user);
482 TextIO.output (file, "\n\tGroup ");
483 TextIO.output (file, group))
484 else
485 (TextIO.output (file, "\n\tSuexecUserGroup ");
486 TextIO.output (file, user);
487 TextIO.output (file, " ");
488 TextIO.output (file, group))
489 else
490 ();
491
492 if isWaklog node then
493 (TextIO.output (file, "\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
494 TextIO.output (file, user);
495 TextIO.output (file, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
496 TextIO.output (file, user))
497 else
498 ();
499
500 TextIO.output (file, "\n\tDAVLockDB /var/lock/apache2/dav/");
501 TextIO.output (file, user);
502 TextIO.output (file, "/DAVLock");
503
504 (ld, file)
505 end)
506 places;
507 write "\n\tDocumentRoot ";
508 write docroot;
509 write "\n\tServerAdmin ";
510 write sadmin;
511 case ssl of
512 SOME cert =>
513 (write "\n\tSSLEngine on\n\tSSLCertificateFile ";
514 write cert)
515 | NONE => ();
516 write "\n";
517 !pre {user = user, nodes = map #1 places, id = vhostId, hostname = fullHost};
518 app (fn dom => !aliaser (host ^ "." ^ dom)) (Domain.currentAliasDomains ())
519 end,
520 fn () => (!post ();
521 write "</VirtualHost>\n";
522 app (TextIO.closeOut o #2) (!vhostFiles)))
523
524 val inLocal = ref false
525
526 val () = Env.container_one "location"
527 ("prefix", Env.string)
528 (fn prefix =>
529 (write "\t<Location ";
530 write prefix;
531 write ">\n";
532 inLocal := true),
533 fn () => (write "\t</Location>\n";
534 inLocal := false;
535 localRewriteEnabled := false))
536
537 val () = Env.container_one "directory"
538 ("directory", Env.string)
539 (fn directory =>
540 (write "\t<Directory ";
541 write directory;
542 write ">\n";
543 inLocal := true),
544 fn () => (write "\t</Directory>\n";
545 inLocal := false;
546 localRewriteEnabled := false))
547
548 fun checkRewrite () =
549 if !inLocal then
550 if !localRewriteEnabled then
551 ()
552 else
553 (write "\tRewriteEngine on\n";
554 localRewriteEnabled := true)
555 else if !rewriteEnabled then
556 ()
557 else
558 (write "\tRewriteEngine on\n";
559 rewriteEnabled := true)
560
561 val () = Env.action_three "localProxyRewrite"
562 ("from", Env.string, "to", Env.string, "port", Env.int)
563 (fn (from, to, port) =>
564 (checkRewrite ();
565 write "\tRewriteRule\t";
566 write from;
567 write "\thttp://localhost:";
568 write (Int.toString port);
569 write "/";
570 write to;
571 write " [P]\n"))
572
573 val () = Env.action_two "proxyPass"
574 ("from", Env.string, "to", Env.string)
575 (fn (from, to) =>
576 (write "\tProxyPass\t";
577 write from;
578 write "\t";
579 write to;
580 write "\n"))
581
582 val () = Env.action_two "proxyPassReverse"
583 ("from", Env.string, "to", Env.string)
584 (fn (from, to) =>
585 (write "\tProxyPassReverse\t";
586 write from;
587 write "\t";
588 write to;
589 write "\n"))
590
591 val () = Env.action_three "rewriteRule"
592 ("from", Env.string, "to", Env.string, "flags", Env.list flag)
593 (fn (from, to, flags) =>
594 (checkRewrite ();
595 write "\tRewriteRule\t";
596 write from;
597 write "\t";
598 write to;
599 case flags of
600 [] => ()
601 | flag::rest => (write " [";
602 write flag;
603 app (fn flag => (write ",";
604 write flag)) rest;
605 write "]");
606 write "\n"))
607
608 val () = Env.action_three "rewriteCond"
609 ("test", Env.string, "pattern", Env.string, "flags", Env.list cond_flag)
610 (fn (from, to, flags) =>
611 (checkRewrite ();
612 write "\tRewriteCond\t";
613 write from;
614 write "\t";
615 write to;
616 case flags of
617 [] => ()
618 | flag::rest => (write " [";
619 write flag;
620 app (fn flag => (write ",";
621 write flag)) rest;
622 write "]");
623 write "\n"))
624
625 val () = Env.action_one "rewriteBase"
626 ("prefix", Env.string)
627 (fn prefix =>
628 (checkRewrite ();
629 write "\tRewriteBase\t";
630 write prefix;
631 write "\n"))
632
633 val () = Env.action_one "rewriteLogLevel"
634 ("level", Env.int)
635 (fn level =>
636 (checkRewrite ();
637 write "\tRewriteLog ";
638 write' (fn x => x);
639 write "/rewrite.log\n\tRewriteLogLevel ";
640 write (Int.toString level);
641 write "\n"))
642
643 val () = Env.action_two "alias"
644 ("from", Env.string, "to", Env.string)
645 (fn (from, to) =>
646 (write "\tAlias\t";
647 write from;
648 write " ";
649 write to;
650 write "\n"))
651
652 val () = Env.action_two "scriptAlias"
653 ("from", Env.string, "to", Env.string)
654 (fn (from, to) =>
655 (write "\tScriptAlias\t";
656 write from;
657 write " ";
658 write to;
659 write "\n"))
660
661 val () = Env.action_two "errorDocument"
662 ("code", Env.string, "handler", Env.string)
663 (fn (code, handler) =>
664 let
665 val hasSpaces = CharVector.exists Char.isSpace handler
666
667 fun maybeQuote () =
668 if hasSpaces then
669 write "\""
670 else
671 ()
672 in
673 write "\tErrorDocument\t";
674 write code;
675 write " ";
676 maybeQuote ();
677 write handler;
678 maybeQuote ();
679 write "\n"
680 end)
681
682 val () = Env.action_one "options"
683 ("options", Env.list apache_option)
684 (fn opts =>
685 case opts of
686 [] => ()
687 | _ => (write "\tOptions";
688 app (fn opt => (write " "; write opt)) opts;
689 write "\n"))
690
691 val () = Env.action_one "set_options"
692 ("options", Env.list apache_option)
693 (fn opts =>
694 case opts of
695 [] => ()
696 | _ => (write "\tOptions";
697 app (fn opt => (write " +"; write opt)) opts;
698 write "\n"))
699
700 val () = Env.action_one "unset_options"
701 ("options", Env.list apache_option)
702 (fn opts =>
703 case opts of
704 [] => ()
705 | _ => (write "\tOptions";
706 app (fn opt => (write " -"; write opt)) opts;
707 write "\n"))
708
709 val () = Env.action_one "directoryIndex"
710 ("filenames", Env.list Env.string)
711 (fn opts =>
712 (write "\tDirectoryIndex";
713 app (fn opt => (write " "; write opt)) opts;
714 write "\n"))
715
716 val () = Env.action_one "serverAliasHost"
717 ("host", Env.string)
718 (fn host =>
719 (write "\tServerAlias ";
720 write host;
721 write "\n";
722 !aliaser host))
723
724 val () = Env.action_one "serverAlias"
725 ("host", Env.string)
726 (fn host =>
727 (app
728 (fn dom =>
729 let
730 val full = host ^ "." ^ dom
731 in
732 write "\tServerAlias ";
733 write full;
734 write "\n";
735 !aliaser full
736 end)
737 (Domain.currentDomains ())))
738
739 val () = Env.action_none "serverAliasDefault"
740 (fn () =>
741 (app
742 (fn dom =>
743 (write "\tServerAlias ";
744 write dom;
745 write "\n";
746 !aliaser dom))
747 (Domain.currentDomains ())))
748
749 val authType = fn (EVar "basic", _) => SOME "basic"
750 | (EVar "digest", _) => SOME "digest"
751 | (EVar "kerberos", _) => SOME "kerberos"
752 | _ => NONE
753
754 fun allowAuthType "kerberos" = !sslEnabled
755 | allowAuthType _ = true
756
757 val () = Env.action_one "authType"
758 ("type", authType)
759 (fn ty =>
760 if allowAuthType ty then
761 (write "\tAuthType ";
762 write ty;
763 write "\n";
764 case ty of
765 "kerberos" =>
766 write "\tKrbMethodNegotiate off\n\tKrbMethodK5Passwd on\n\tKrbVerifyKDC off\n\tKrbAuthRealms HCOOP.NET\n\tKrbSaveCredentials on\n"
767 | _ => ())
768 else
769 print "WARNING: Skipped Kerberos authType because this isn't an SSL vhost.\n")
770
771 val () = Env.action_one "authName"
772 ("name", Env.string)
773 (fn name =>
774 (write "\tAuthName \"";
775 write name;
776 write "\"\n"))
777
778 val () = Env.action_one "authUserFile"
779 ("file", Env.string)
780 (fn name =>
781 (write "\tAuthUserFile ";
782 write name;
783 write "\n"))
784
785 val () = Env.action_none "requireValidUser"
786 (fn () => write "\tRequire valid-user\n")
787
788 val () = Env.action_one "requireUser"
789 ("users", Env.list Env.string)
790 (fn names =>
791 case names of
792 [] => ()
793 | _ => (write "\tRequire user";
794 app (fn name => (write " "; write name)) names;
795 write "\n"))
796
797 val () = Env.action_one "requireGroup"
798 ("groups", Env.list Env.string)
799 (fn names =>
800 case names of
801 [] => ()
802 | _ => (write "\tRequire group";
803 app (fn name => (write " "; write name)) names;
804 write "\n"))
805
806 val () = Env.action_none "orderAllowDeny"
807 (fn () => write "\tOrder allow,deny\n")
808
809 val () = Env.action_none "orderDenyAllow"
810 (fn () => write "\tOrder deny,allow\n")
811
812 val () = Env.action_none "allowFromAll"
813 (fn () => write "\tAllow from all\n")
814
815 val () = Env.action_one "allowFrom"
816 ("entries", Env.list Env.string)
817 (fn names =>
818 case names of
819 [] => ()
820 | _ => (write "\tAllow from";
821 app (fn name => (write " "; write name)) names;
822 write "\n"))
823
824 val () = Env.action_none "denyFromAll"
825 (fn () => write "\tDeny from all\n")
826
827 val () = Env.action_one "denyFrom"
828 ("entries", Env.list Env.string)
829 (fn names =>
830 case names of
831 [] => ()
832 | _ => (write "\tDeny from";
833 app (fn name => (write " "; write name)) names;
834 write "\n"))
835
836 val () = Env.action_none "satisfyAll"
837 (fn () => write "\tSatisfy all\n")
838
839 val () = Env.action_none "satisfyAny"
840 (fn () => write "\tSatisfy any\n")
841
842 val () = Env.action_one "forceType"
843 ("type", Env.string)
844 (fn ty => (write "\tForceType ";
845 write ty;
846 write "\n"))
847
848 val () = Env.action_none "forceTypeOff"
849 (fn () => write "\tForceType None\n")
850
851 val () = Env.action_two "action"
852 ("what", Env.string, "how", Env.string)
853 (fn (what, how) => (write "\tAction ";
854 write what;
855 write " ";
856 write how;
857 write "\n"))
858
859 val () = Env.action_one "addDefaultCharset"
860 ("charset", Env.string)
861 (fn ty => (write "\tAddDefaultCharset ";
862 write ty;
863 write "\n"))
864
865 (*val () = Env.action_one "davSvn"
866 ("path", Env.string)
867 (fn path => (write "\tDAV svn\n\tSVNPath ";
868 write path;
869 write "\n"))
870
871 val () = Env.action_one "authzSvnAccessFile"
872 ("path", Env.string)
873 (fn path => (write "\tAuthzSVNAccessFile ";
874 write path;
875 write "\n"))*)
876
877 val () = Env.action_none "davFilesystem"
878 (fn path => write "\tDAV filesystem\n")
879
880 val () = Env.action_two "addDescription"
881 ("description", Env.string, "patterns", Env.list Env.string)
882 (fn (desc, pats) =>
883 case pats of
884 [] => ()
885 | _ => (write "\tAddDescription \"";
886 write (String.toString desc);
887 write "\"";
888 app (fn pat => (write " "; write pat)) pats;
889 write "\n"))
890
891 val () = Env.action_one "indexOptions"
892 ("options", Env.list autoindex_option)
893 (fn opts =>
894 case opts of
895 [] => ()
896 | _ => (write "\tIndexOptions";
897 app (fn (opt, arg) =>
898 (write " ";
899 write opt;
900 Option.app (fn arg =>
901 (write "="; write arg)) arg)) opts;
902 write "\n"))
903
904 val () = Env.action_one "set_indexOptions"
905 ("options", Env.list autoindex_option)
906 (fn opts =>
907 case opts of
908 [] => ()
909 | _ => (write "\tIndexOptions";
910 app (fn (opt, arg) =>
911 (write " +";
912 write opt;
913 Option.app (fn arg =>
914 (write "="; write arg)) arg)) opts;
915 write "\n"))
916
917 val () = Env.action_one "unset_indexOptions"
918 ("options", Env.list autoindex_option)
919 (fn opts =>
920 case opts of
921 [] => ()
922 | _ => (write "\tIndexOptions";
923 app (fn (opt, _) =>
924 (write " -";
925 write opt)) opts;
926 write "\n"))
927
928 val () = Env.action_one "headerName"
929 ("name", Env.string)
930 (fn name => (write "\tHeaderName ";
931 write name;
932 write "\n"))
933
934 val () = Env.action_one "readmeName"
935 ("name", Env.string)
936 (fn name => (write "\tReadmeName ";
937 write name;
938 write "\n"))
939
940 val () = Env.action_two "setEnv"
941 ("key", Env.string, "value", Env.string)
942 (fn (key, value) => (write "\tSetEnv \"";
943 write key;
944 write "\" \"";
945 write (String.translate (fn #"\"" => "\\\""
946 | ch => str ch) value);
947 write "\"\n"))
948
949 val () = Domain.registerResetLocal (fn () =>
950 ignore (OS.Process.system (Config.rm ^ " -rf /var/domtool/vhosts/*")))
951
952 val () = Domain.registerDescriber (Domain.considerAll
953 [Domain.Extension {extension = "vhost",
954 heading = fn host => "Web vhost " ^ host ^ ":"},
955 Domain.Extension {extension = "vhost_ssl",
956 heading = fn host => "SSL web vhost " ^ host ^ ":"}])
957
958 end