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