1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006-2009, Adam Chlipala
3 * Copyright (c
) 2013 Clinton Ebadi
5 * This program is free software
; you can redistribute it
and/or
6 * modify it under the terms
of the GNU General Public License
7 * as published by the Free Software Foundation
; either version
2
8 * of the License
, or (at your option
) any later version
.
10 * This program is distributed
in the hope that it will be useful
,
11 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
13 * GNU General Public License for more details
.
15 * You should have received a copy
of the GNU General Public License
16 * along
with this program
; if not
, write to the Free Software
17 * Foundation
, Inc
., 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA
.
20 (* Apache HTTPD handling
*)
22 structure Apache
:> APACHE
= struct
26 val dl
= ErrorMsg
.dummyLoc
29 List.exists (fn (x
, _
) => x
= node
) Config
.Apache
.webNodes_all
30 orelse (Domain
.hasPriv
"www"
31 andalso List.exists (fn (x
, _
) => x
= node
) Config
.Apache
.webNodes_admin
)
33 val _
= Env
.type_one
"web_node"
37 val _
= Env
.registerFunction ("web_node_to_node",
41 fun webPlace (EApp ((EVar
"web_place_default", _
), (EString node
, _
)), _
) =
42 SOME (node
, Domain
.nodeIp node
)
43 |
webPlace (EApp ((EApp ((EVar
"web_place", _
), (EString node
, _
)), _
), (EString ip
, _
)), _
) =
47 fun webPlaceDefault node
= (EApp ((EVar
"web_place_default", dl
), (EString node
, dl
)), dl
)
49 val _
= Env
.registerFunction ("web_place_to_web_node",
50 fn [e
] => Option
.map (fn (node
, _
) => (EString node
, dl
)) (webPlace e
)
53 val _
= Env
.registerFunction ("web_place_to_node",
54 fn [e
] => Option
.map (fn (node
, _
) => (EString node
, dl
)) (webPlace e
)
57 val _
= Env
.registerFunction ("web_place_to_ip",
58 fn [e
] => Option
.map (fn (_
, ip
) => (EString ip
, dl
)) (webPlace e
)
61 val _
= Env
.type_one
"proxy_port"
65 val _
= Env
.type_one
"proxy_target"
69 fun default () = List.exists (fn s
' => s
= s
') Config
.Apache
.proxyTargets
71 case String.fields (fn ch
=> ch
= #
":") s
of
72 "http" :: host
:: rest
=>
74 val rest
= String.concatWith
":" rest
76 if List.exists (fn h
' => host
= h
') (map (fn h
=> String.concat
["//", h
]) Config
.Apache
.proxyHosts
)
78 CharVector
.all (fn ch
=> Char.isPrint ch
andalso not (Char.isSpace ch
)
79 andalso ch
<> #
"\"" andalso ch
<> #
"'") rest
80 andalso case String.fields (fn ch
=> ch
= #
"/") rest
of
82 (case Int.fromString port
of
84 | SOME n
=> n
> 1024 orelse default ())
92 val _
= Env
.type_one
"rewrite_arg"
94 (CharVector
.all
Char.isAlphaNum
)
96 val _
= Env
.type_one
"suexec_flag"
98 (fn b
=> b
orelse Domain
.hasPriv
"www")
100 val _
= Env
.type_one
"regexp"
104 fun validLocation s
=
105 size s
> 0 andalso size s
< 1000 andalso CharVector
.all
106 (fn ch
=> Char.isAlphaNum ch
113 val _
= Env
.type_one
"location"
117 fun validCert s
= Acl
.query
{user
= Domain
.getUser (),
121 val _
= Env
.type_one
"ssl_cert_path"
125 fun ssl e
= case e
of
126 (EVar
"no_ssl", _
) => SOME NONE
127 |
(EApp ((EVar
"use_cert", _
), s
), _
) => Option
.map
SOME (Env
.string s
)
130 fun validExtension s
=
133 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"_") s
135 val _
= Env
.type_one
"file_extension"
139 val defaults
= [("WebPlaces",
140 (TList (TBase
"web_place", dl
), dl
),
141 (fn () => (EList (map webPlaceDefault Config
.Apache
.webNodes_default
), dl
))),
144 (fn () => (EVar
"no_ssl", dl
))),
146 (TBase
"your_user", dl
),
147 (fn () => (EString (Domain
.getUser ()), dl
))),
149 (TBase
"your_group", dl
),
150 (fn () => (EString
"nogroup", dl
))),
152 (TBase
"your_path", dl
),
153 (fn () => (EString (Domain
.homedir () ^
"/" ^ Config
.Apache
.public_html
), dl
))),
156 (fn () => (EString (Domain
.getUser () ^
"@" ^ Config
.defaultDomain
), dl
))),
158 (TBase
"suexec_flag", dl
),
159 (fn () => (EVar
"true", dl
))),
161 (TBase
"php_version", dl
),
162 (fn () => (EVar
"php4", dl
)))]
164 val () = app Defaults
.registerDefault defaults
166 val redirect_code
= fn (EVar
"temp", _
) => SOME
"temp"
167 |
(EVar
"permanent", _
) => SOME
"permanent"
168 |
(EVar
"seeother", _
) => SOME
"seeother"
169 |
(EVar
"redir300", _
) => SOME
"300"
170 |
(EVar
"redir301", _
) => SOME
"301"
171 |
(EVar
"redir302", _
) => SOME
"302"
172 |
(EVar
"redir303", _
) => SOME
"303"
173 |
(EVar
"redir304", _
) => SOME
"304"
174 |
(EVar
"redir305", _
) => SOME
"305"
175 |
(EVar
"redir307", _
) => SOME
"307"
178 val flag
= fn (EVar
"redirect", _
) => SOME
"R"
179 |
(EVar
"forbidden", _
) => SOME
"F"
180 |
(EVar
"gone", _
) => SOME
"G"
181 |
(EVar
"last", _
) => SOME
"L"
182 |
(EVar
"chain", _
) => SOME
"C"
183 |
(EVar
"nosubreq", _
) => SOME
"NS"
184 |
(EVar
"nocase", _
) => SOME
"NC"
185 |
(EVar
"qsappend", _
) => SOME
"QSA"
186 |
(EVar
"noescape", _
) => SOME
"NE"
187 |
(EVar
"passthrough", _
) => SOME
"PT"
188 |
(EApp ((EVar
"mimeType", _
), e
), _
) =>
189 Option
.map (fn s
=> "T=" ^ s
) (Env
.string e
)
190 |
(EApp ((EVar
"redirectWith", _
), e
), _
) =>
191 Option
.map (fn s
=> "R=" ^ s
) (redirect_code e
)
192 |
(EApp ((EVar
"skip", _
), e
), _
) =>
193 Option
.map (fn n
=> "S=" ^
Int.toString n
) (Env
.int e
)
194 |
(EApp ((EApp ((EVar
"env", _
), e1
), _
), e2
), _
) =>
195 (case Env
.string e1
of
197 | SOME s1
=> Option
.map (fn s2
=> "E=" ^ s1 ^
":" ^ s2
)
202 val cond_flag
= fn (EVar
"cond_nocase", _
) => SOME
"NC"
203 |
(EVar
"ornext", _
) => SOME
"OR"
206 val apache_option
= fn (EVar
"execCGI", _
) => SOME
"ExecCGI"
207 |
(EVar
"includesNOEXEC", _
) => SOME
"IncludesNOEXEC"
208 |
(EVar
"indexes", _
) => SOME
"Indexes"
209 |
(EVar
"followSymLinks", _
) => SOME
"FollowSymLinks"
210 |
(EVar
"multiViews", _
) => SOME
"MultiViews"
213 val autoindex_width
= fn (EVar
"autofit", _
) => SOME
"*"
214 |
(EApp ((EVar
"characters", _
), n
), _
) =>
215 Option
.map
Int.toString (Env
.int n
)
218 val autoindex_option
= fn (EApp ((EVar
"descriptionWidth", _
), w
), _
) =>
219 Option
.map (fn w
=> ("DescriptionWidth", SOME w
))
221 |
(EVar
"fancyIndexing", _
) => SOME ("FancyIndexing", NONE
)
222 |
(EVar
"foldersFirst", _
) => SOME ("FoldersFirst", NONE
)
223 |
(EVar
"htmlTable", _
) => SOME ("HTMLTable", NONE
)
224 |
(EVar
"iconsAreLinks", _
) => SOME ("IconsAreLinks", NONE
)
225 |
(EApp ((EVar
"iconHeight", _
), n
), _
) =>
226 Option
.map (fn w
=> ("IconHeight", SOME (Int.toString w
)))
228 |
(EApp ((EVar
"iconWidth", _
), n
), _
) =>
229 Option
.map (fn w
=> ("IconWidth", SOME (Int.toString w
)))
231 |
(EVar
"ignoreCase", _
) => SOME ("IgnoreCase", NONE
)
232 |
(EVar
"ignoreClient", _
) => SOME ("IgnoreClient", NONE
)
233 |
(EApp ((EVar
"nameWidth", _
), w
), _
) =>
234 Option
.map (fn w
=> ("NameWidth", SOME w
))
236 |
(EVar
"scanHtmlTitles", _
) => SOME ("ScanHTMLTitles", NONE
)
237 |
(EVar
"suppressColumnSorting", _
) => SOME ("SuppressColumnSorting", NONE
)
238 |
(EVar
"suppressDescription", _
) => SOME ("SuppressDescription", NONE
)
239 |
(EVar
"suppressHtmlPreamble", _
) => SOME ("SuppressHTMLPreamble", NONE
)
240 |
(EVar
"suppressIcon", _
) => SOME ("SuppressIcon", NONE
)
241 |
(EVar
"suppressLastModified", _
) => SOME ("SuppressLastModified", NONE
)
242 |
(EVar
"suppressRules", _
) => SOME ("SuppressRules", NONE
)
243 |
(EVar
"suppressSize", _
) => SOME ("SuppressSize", NONE
)
244 |
(EVar
"trackModified", _
) => SOME ("TrackModified", NONE
)
245 |
(EVar
"versionSort", _
) => SOME ("VersionSort", NONE
)
246 |
(EVar
"xhtml", _
) => SOME ("XHTML", NONE
)
250 val interval_base
= fn (EVar
"access", _
) => SOME
"access"
251 |
(EVar
"modification", _
) => SOME
"modification"
254 val interval
= fn (EVar
"years", _
) => SOME
"years"
255 |
(EVar
"months", _
) => SOME
"months"
256 |
(EVar
"weeks", _
) => SOME
"weeks"
257 |
(EVar
"days", _
) => SOME
"days"
258 |
(EVar
"hours", _
) => SOME
"hours"
259 |
(EVar
"minutes", _
) => SOME
"minutes"
260 |
(EVar
"seconds", _
) => SOME
"seconds"
263 val vhostsChanged
= ref
false
264 val logDeleted
= ref
false
265 val delayedLogMoves
= ref (fn () => ())
267 val () = Slave
.registerPreHandler
268 (fn () => (vhostsChanged
:= false;
270 delayedLogMoves
:= (fn () => print
"Executing delayed log moves/deletes.\n")))
272 fun findVhostUser fname
=
274 val inf
= TextIO.openIn fname
277 case TextIO.inputLine inf
of
280 if String.isPrefix
"# Owner: " line
then
281 case String.tokens
Char.isSpace line
of
282 [_
, _
, user
] => SOME user
288 before TextIO.closeIn inf
291 val webNodes_full
= Config
.Apache
.webNodes_all @ Config
.Apache
.webNodes_admin
293 fun isVersion1 node
=
294 List.exists (fn (n
, {version
= ConfigTypes
.APACHE_1_3
, ...}) => n
= node
295 | _
=> false) webNodes_full
297 fun imVersion1 () = isVersion1 (Slave
.hostname ())
300 List.exists (fn (n
, {auth
= ConfigTypes
.MOD_WAKLOG
, ...}) => n
= node
301 | _
=> false) webNodes_full
303 fun down () = if imVersion1 () then Config
.Apache
.down1
else Config
.Apache
.down
304 fun undown () = if imVersion1 () then Config
.Apache
.undown1
else Config
.Apache
.undown
305 fun reload () = if imVersion1 () then Config
.Apache
.reload1
else Config
.Apache
.reload
306 fun fixperms () = if imVersion1 () then Config
.Apache
.fixperms1
else Config
.Apache
.fixperms
308 fun logDir
{user
, node
, vhostId
} =
309 String.concat
[Config
.Apache
.logDirOf (isVersion1 node
) user
,
315 fun realLogDir
{user
, node
, vhostId
} =
316 String.concat
[Config
.Apache
.realLogDirOf user
,
322 val () = Slave
.registerFileHandler (fn fs
=>
324 val spl
= OS
.Path
.splitDirFile (#file fs
)
326 if String.isSuffix
".vhost" (#file spl
)
327 orelse String.isSuffix
".vhost_ssl" (#file spl
) then let
328 val realVhostFile
= OS
.Path
.joinDirFile
329 {dir
= Config
.Apache
.confDir
,
332 val user
= findVhostUser (#file fs
)
333 val oldUser
= case #action fs
of
334 Slave
.Delete
false => user
335 | _
=> findVhostUser realVhostFile
337 if (oldUser
= NONE
andalso #action fs
<> Slave
.Add
)
338 orelse (user
= NONE
andalso not (Slave
.isDelete (#action fs
))) then
339 print ("Can't find user in " ^ #file fs ^
" or " ^ realVhostFile ^
"! Taking no action.\n")
342 val vhostId
= if OS
.Path
.ext (#file spl
) = SOME
"vhost_ssl" then
343 OS
.Path
.base (#file spl
) ^
".ssl"
345 OS
.Path
.base (#file spl
)
347 fun realLogDir user
=
348 logDir
{user
= valOf user
,
349 node
= Slave
.hostname (),
354 {dir
= Config
.Apache
.backupLogDirOf
355 (isVersion1 (Slave
.hostname ())),
358 vhostsChanged
:= true;
362 val ldir
= realLogDir oldUser
363 val dlm
= !delayedLogMoves
368 ((*ignore (OS
.Process
.system (down ()));*)
369 ignore (OS
.Process
.system (fixperms ()));
371 ignore (OS
.Process
.system (Config
.rm
374 delayedLogMoves
:= (fn () => (dlm ();
375 Slave
.moveDirCreate
{from
= ldir
,
376 to
= backupLogs ()}))
380 val rld
= realLogDir user
382 ignore (OS
.Process
.system (Config
.cp
387 if Posix
.FileSys
.access (rld
, []) then
390 Slave
.moveDirCreate
{from
= backupLogs (),
395 (ignore (OS
.Process
.system (Config
.cp
400 if user
<> oldUser
then
402 val old
= realLogDir oldUser
403 val rld
= realLogDir user
405 val dlm
= !delayedLogMoves
410 ((*ignore (OS
.Process
.system (down ()));*)
412 delayedLogMoves
:= (fn () => (dlm ();
413 ignore (OS
.Process
.system (Config
.rm
415 ^ realLogDir oldUser
))));
416 if Posix
.FileSys
.access (rld
, []) then
429 val () = Slave
.registerPostHandler
431 (if !vhostsChanged
then
432 (Slave
.shellF ([reload ()],
433 fn cl
=> "Error reloading Apache with " ^ cl
);
434 if !logDeleted
then !delayedLogMoves () else ())
438 val vhostFiles
: (string * TextIO.outstream
) list ref
= ref
[]
439 fun write
' s
= app (fn (node
, file
) => TextIO.output (file
, s node
)) (!vhostFiles
)
440 fun write s
= app (fn (_
, file
) => TextIO.output (file
, s
)) (!vhostFiles
)
442 val rewriteEnabled
= ref
false
443 val localRewriteEnabled
= ref
false
444 val expiresEnabled
= ref
false
445 val localExpiresEnabled
= ref
false
446 val currentVhost
= ref
""
447 val currentVhostId
= ref
""
448 val sslEnabled
= ref
false
450 val pre
= ref (fn _
: {user
: string, nodes
: string list
, id
: string, hostname
: string} => ())
455 pre
:= (fn x
=> (old x
; f x
))
458 val post
= ref (fn () => ())
463 post
:= (fn () => (old (); f ()))
467 fun doPost () = !post ()
469 val aliaser
= ref (fn _
: string => ())
470 fun registerAliaser f
=
474 aliaser
:= (fn x
=> (old x
; f x
))
477 fun vhostPost () = (!post ();
478 write
"</VirtualHost>\n";
479 app (TextIO.closeOut
o #
2) (!vhostFiles
))
481 val php_version
= fn (EVar
"php4", _
) => SOME
4
482 |
(EVar
"php5", _
) => SOME
5
485 fun vhostBody (env
, makeFullHost
) =
487 val places
= Env
.env (Env
.list webPlace
) (env
, "WebPlaces")
489 val ssl
= Env
.env
ssl (env
, "SSL")
490 val user
= Env
.env Env
.string (env
, "User")
491 val group
= Env
.env Env
.string (env
, "Group")
492 val docroot
= Env
.env Env
.string (env
, "DocumentRoot")
493 val sadmin
= Env
.env Env
.string (env
, "ServerAdmin")
494 val suexec
= Env
.env Env
.bool (env
, "SuExec")
495 val php
= Env
.env
php_version (env
, "PhpVersion")
497 val fullHost
= makeFullHost (Domain
.currentDomain ())
498 val vhostId
= fullHost ^
(if Option
.isSome ssl
then ".ssl" else "")
499 val confFile
= fullHost ^
(if Option
.isSome ssl
then ".vhost_ssl" else ".vhost")
501 currentVhost
:= fullHost
;
502 currentVhostId
:= vhostId
;
503 sslEnabled
:= Option
.isSome ssl
;
505 rewriteEnabled
:= false;
506 localRewriteEnabled
:= false;
507 expiresEnabled
:= false;
508 localExpiresEnabled
:= false;
509 vhostFiles
:= map (fn (node
, ip
) =>
511 val file
= Domain
.domainFile
{node
= node
,
514 val ld
= logDir
{user
= user
, node
= node
, vhostId
= vhostId
}
516 TextIO.output (file
, "# Owner: ");
517 TextIO.output (file
, user
);
518 TextIO.output (file
, "\n<VirtualHost ");
519 TextIO.output (file
, ip
);
520 TextIO.output (file
, ":");
521 TextIO.output (file
, case ssl
of
524 TextIO.output (file
, ">\n");
525 TextIO.output (file
, "\tErrorLog ");
526 TextIO.output (file
, ld
);
527 TextIO.output (file
, "/error.log\n\tCustomLog ");
528 TextIO.output (file
, ld
);
529 TextIO.output (file
, "/access.log combined\n");
530 TextIO.output (file
, "\tServerName ");
531 TextIO.output (file
, fullHost
);
533 (fn dom
=> (TextIO.output (file
, "\n\tServerAlias ");
534 TextIO.output (file
, makeFullHost dom
)))
535 (Domain
.currentAliasDomains ());
538 if isVersion1 node
then
539 (TextIO.output (file
, "\n\tUser ");
540 TextIO.output (file
, user
);
541 TextIO.output (file
, "\n\tGroup ");
542 TextIO.output (file
, group
))
544 (TextIO.output (file
, "\n\tSuexecUserGroup ");
545 TextIO.output (file
, user
);
546 TextIO.output (file
, " ");
547 TextIO.output (file
, group
);
548 TextIO.output (file
, "\n\tsuPHP_UserGroup ");
549 TextIO.output (file
, user
);
550 TextIO.output (file
, " ");
551 TextIO.output (file
, group
))
555 if isWaklog node
then
556 (TextIO.output (file
, "\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
557 TextIO.output (file
, user
);
558 TextIO.output (file
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
559 TextIO.output (file
, user
))
563 TextIO.output (file
, "\n\tDAVLockDB /var/lock/apache2/dav/");
564 TextIO.output (file
, user
);
565 TextIO.output (file
, "/DAVLock");
567 if php
<> Config
.Apache
.defaultPhpVersion
then
568 (TextIO.output (file
, "\n\tAddHandler x-httpd-php");
569 TextIO.output (file
, Int.toString php
);
570 TextIO.output (file
, " .php .phtml"))
577 write
"\n\tDocumentRoot ";
579 write
"\n\tServerAdmin ";
583 (write
"\n\tSSLEngine on\n\tSSLCertificateFile ";
587 !pre
{user
= user
, nodes
= map #
1 places
, id
= vhostId
, hostname
= fullHost
};
588 app (fn dom
=> !aliaser (makeFullHost dom
)) (Domain
.currentAliasDomains ())
591 val () = Env
.containerV_one
"vhost"
593 (fn (env
, host
) => vhostBody (env
, fn dom
=> host ^
"." ^ dom
),
596 val () = Env
.containerV_none
"vhostDefault"
597 (fn env
=> vhostBody (env
, fn dom
=> dom
),
600 val inLocal
= ref
false
602 val () = Env
.container_one
"location"
603 ("prefix", Env
.string)
605 (write
"\t<Location ";
609 fn () => (write
"\t</Location>\n";
611 localRewriteEnabled
:= false;
612 localExpiresEnabled
:= false))
614 val () = Env
.container_one
"directory"
615 ("directory", Env
.string)
617 (write
"\t<Directory ";
621 fn () => (write
"\t</Directory>\n";
623 localRewriteEnabled
:= false;
624 localExpiresEnabled
:= false))
626 val () = Env
.container_one
"filesMatch"
627 ("regexp", Env
.string)
629 (write
"\t<FilesMatch \"";
632 fn () => (write
"\t</FilesMatch>\n";
633 localRewriteEnabled
:= false;
634 localExpiresEnabled
:= false))
636 fun checkRewrite () =
638 if !localRewriteEnabled
then
641 (write
"\tRewriteEngine on\n";
642 localRewriteEnabled
:= true)
643 else if !rewriteEnabled
then
646 (write
"\tRewriteEngine on\n";
647 rewriteEnabled
:= true)
649 fun checkExpires () =
651 if !localExpiresEnabled
then
654 (write
"\tExpiresActive on\n";
655 localExpiresEnabled
:= true)
656 else if !expiresEnabled
then
659 (write
"\tExpiresActive on\n";
660 expiresEnabled
:= true)
662 val () = Env
.action_three
"localProxyRewrite"
663 ("from", Env
.string, "to", Env
.string, "port", Env
.int)
664 (fn (from
, to
, port
) =>
666 write
"\tRewriteRule\t\"";
668 write
"\"\thttp://localhost:";
669 write (Int.toString port
);
674 val () = Env
.action_four
"expiresByType"
675 ("mime", Env
.string, "base", interval_base
, "num", Env
.int, "inter", interval
)
676 (fn (mime
, base
, num
, inter
) =>
678 write
"\tExpiresByType\t\"";
685 write (Int.toString (~num
)))
687 write (Int.toString num
);
692 val () = Env
.action_two
"proxyPass"
693 ("from", Env
.string, "to", Env
.string)
695 (write
"\tProxyPass\t";
701 val () = Env
.action_two
"proxyPassReverse"
702 ("from", Env
.string, "to", Env
.string)
704 (write
"\tProxyPassReverse\t";
710 val () = Env
.action_three
"rewriteRule"
711 ("from", Env
.string, "to", Env
.string, "flags", Env
.list flag
)
712 (fn (from
, to
, flags
) =>
714 write
"\tRewriteRule\t\"";
721 | flag
::rest
=> (write
" [";
723 app (fn flag
=> (write
",";
728 val () = Env
.action_three
"rewriteCond"
729 ("test", Env
.string, "pattern", Env
.string, "flags", Env
.list cond_flag
)
730 (fn (from
, to
, flags
) =>
732 write
"\tRewriteCond\t\"";
739 | flag
::rest
=> (write
" [";
741 app (fn flag
=> (write
",";
746 val () = Env
.action_one
"rewriteBase"
747 ("prefix", Env
.string)
750 write
"\tRewriteBase\t\"";
754 val () = Env
.action_one
"rewriteLogLevel"
758 write
"\tRewriteLog ";
760 write
"/rewrite.log\n\tRewriteLogLevel ";
761 write (Int.toString level
);
764 val () = Env
.action_two
"alias"
765 ("from", Env
.string, "to", Env
.string)
773 val () = Env
.action_two
"scriptAlias"
774 ("from", Env
.string, "to", Env
.string)
776 (write
"\tScriptAlias\t";
782 val () = Env
.action_two
"errorDocument"
783 ("code", Env
.string, "handler", Env
.string)
784 (fn (code
, handler
) =>
786 val hasSpaces
= CharVector
.exists
Char.isSpace handler
794 write
"\tErrorDocument\t";
803 val () = Env
.action_one
"options"
804 ("options", Env
.list apache_option
)
808 | _
=> (write
"\tOptions";
809 app (fn opt
=> (write
" "; write opt
)) opts
;
812 val () = Env
.action_one
"set_options"
813 ("options", Env
.list apache_option
)
817 | _
=> (write
"\tOptions";
818 app (fn opt
=> (write
" +"; write opt
)) opts
;
821 val () = Env
.action_one
"unset_options"
822 ("options", Env
.list apache_option
)
826 | _
=> (write
"\tOptions";
827 app (fn opt
=> (write
" -"; write opt
)) opts
;
830 val () = Env
.action_one
"cgiExtension"
831 ("extension", Env
.string)
832 (fn ext
=> (write
"\tAddHandler cgi-script ";
836 val () = Env
.action_one
"directoryIndex"
837 ("filenames", Env
.list Env
.string)
839 (write
"\tDirectoryIndex";
840 app (fn opt
=> (write
" "; write opt
)) opts
;
843 val () = Env
.action_one
"serverAliasHost"
846 (write
"\tServerAlias ";
851 val () = Env
.action_one
"serverAlias"
857 val full
= host ^
"." ^ dom
859 write
"\tServerAlias ";
864 (Domain
.currentDomains ())))
866 val () = Env
.action_none
"serverAliasDefault"
870 (write
"\tServerAlias ";
874 (Domain
.currentDomains ())))
876 val authType
= fn (EVar
"basic", _
) => SOME
"basic"
877 |
(EVar
"digest", _
) => SOME
"digest"
878 |
(EVar
"kerberos", _
) => SOME
"kerberos"
881 fun allowAuthType
"kerberos" = !sslEnabled
882 | allowAuthType _
= true
884 val () = Env
.action_one
"authType"
887 if allowAuthType ty
then
888 (write
"\tAuthType ";
893 write
"\tKrbMethodNegotiate off\n\tKrbMethodK5Passwd on\n\tKrbVerifyKDC off\n\tKrbAuthRealms HCOOP.NET\n\tKrbSaveCredentials on\n"
896 print
"WARNING: Skipped Kerberos authType because this isn't an SSL vhost.\n")
898 val () = Env
.action_one
"authName"
901 (write
"\tAuthName \"";
905 val () = Env
.action_one
"authUserFile"
908 (write
"\tAuthUserFile ";
912 val () = Env
.action_none
"requireValidUser"
913 (fn () => write
"\tRequire valid-user\n")
915 val () = Env
.action_one
"requireUser"
916 ("users", Env
.list Env
.string)
920 | _
=> (write
"\tRequire user";
921 app (fn name
=> (write
" "; write name
)) names
;
924 val () = Env
.action_one
"requireGroup"
925 ("groups", Env
.list Env
.string)
929 | _
=> (write
"\tRequire group";
930 app (fn name
=> (write
" "; write name
)) names
;
933 val () = Env
.action_none
"orderAllowDeny"
934 (fn () => write
"\tOrder allow,deny\n")
936 val () = Env
.action_none
"orderDenyAllow"
937 (fn () => write
"\tOrder deny,allow\n")
939 val () = Env
.action_none
"allowFromAll"
940 (fn () => write
"\tAllow from all\n")
942 val () = Env
.action_one
"allowFrom"
943 ("entries", Env
.list Env
.string)
947 | _
=> (write
"\tAllow from";
948 app (fn name
=> (write
" "; write name
)) names
;
951 val () = Env
.action_none
"denyFromAll"
952 (fn () => write
"\tDeny from all\n")
954 val () = Env
.action_one
"denyFrom"
955 ("entries", Env
.list Env
.string)
959 | _
=> (write
"\tDeny from";
960 app (fn name
=> (write
" "; write name
)) names
;
963 val () = Env
.action_none
"satisfyAll"
964 (fn () => write
"\tSatisfy all\n")
966 val () = Env
.action_none
"satisfyAny"
967 (fn () => write
"\tSatisfy any\n")
969 val () = Env
.action_one
"forceType"
971 (fn ty
=> (write
"\tForceType ";
975 val () = Env
.action_none
"forceTypeOff"
976 (fn () => write
"\tForceType None\n")
978 val () = Env
.action_two
"action"
979 ("what", Env
.string, "how", Env
.string)
980 (fn (what
, how
) => (write
"\tAction ";
986 val () = Env
.action_one
"addDefaultCharset"
987 ("charset", Env
.string)
988 (fn ty
=> (write
"\tAddDefaultCharset ";
992 (*val () = Env
.action_one
"davSvn"
994 (fn path
=> (write
"\tDAV svn\n\tSVNPath ";
998 val () = Env
.action_one
"authzSvnAccessFile"
1000 (fn path
=> (write
"\tAuthzSVNAccessFile ";
1004 val () = Env
.action_none
"davFilesystem"
1005 (fn path
=> write
"\tDAV filesystem\n")
1007 val () = Env
.action_two
"addDescription"
1008 ("description", Env
.string, "patterns", Env
.list Env
.string)
1012 | _
=> (write
"\tAddDescription \"";
1013 write (String.toString desc
);
1015 app (fn pat
=> (write
" "; write pat
)) pats
;
1018 val () = Env
.action_two
"addIcon"
1019 ("icon", Env
.string, "patterns", Env
.list Env
.string)
1023 | _
=> (write
"\tAddIcon \"";
1026 app (fn pat
=> (write
" "; write pat
)) pats
;
1029 val () = Env
.action_one
"indexOptions"
1030 ("options", Env
.list autoindex_option
)
1034 | _
=> (write
"\tIndexOptions";
1035 app (fn (opt
, arg
) =>
1038 Option
.app (fn arg
=>
1039 (write
"="; write arg
)) arg
)) opts
;
1042 val () = Env
.action_one
"indexIgnore"
1043 ("patterns", Env
.list Env
.string)
1047 | _
=> (write
"\tIndexIgnore";
1048 app (fn pat
=> (write
" "; write pat
)) pats
;
1051 val () = Env
.action_one
"set_indexOptions"
1052 ("options", Env
.list autoindex_option
)
1056 | _
=> (write
"\tIndexOptions";
1057 app (fn (opt
, arg
) =>
1060 Option
.app (fn arg
=>
1061 (write
"="; write arg
)) arg
)) opts
;
1064 val () = Env
.action_one
"unset_indexOptions"
1065 ("options", Env
.list autoindex_option
)
1069 | _
=> (write
"\tIndexOptions";
1075 val () = Env
.action_one
"headerName"
1076 ("name", Env
.string)
1077 (fn name
=> (write
"\tHeaderName ";
1081 val () = Env
.action_one
"readmeName"
1082 ("name", Env
.string)
1083 (fn name
=> (write
"\tReadmeName ";
1087 val () = Env
.action_two
"setEnv"
1088 ("key", Env
.string, "value", Env
.string)
1089 (fn (key
, value
) => (write
"\tSetEnv \"";
1092 write (String.translate (fn #
"\"" => "\\\""
1093 | ch
=> str ch
) value
);
1096 val () = Env
.action_one
"diskCache"
1097 ("path", Env
.string)
1098 (fn path
=> (write
"\tCacheEnable disk \"";
1102 val () = Env
.action_one
"phpVersion"
1103 ("version", php_version
)
1104 (fn version
=> (write
"\tAddHandler x-httpd-php";
1105 write (Int.toString version
);
1106 write
" .php .phtml\n"))
1108 val () = Env
.action_two
"addType"
1109 ("mime type", Env
.string, "extension", Env
.string)
1110 (fn (mt
, ext
) => (write
"\tAddType ";
1116 val filter
= fn (EVar
"includes", _
) => SOME
"INCLUDES"
1117 |
(EVar
"deflate", _
) => SOME
"DEFLATE"
1120 val () = Env
.action_two
"addOutputFilter"
1121 ("filters", Env
.list filter
, "extensions", Env
.list Env
.string)
1122 (fn (f
:: fs
, exts
as (_
:: _
)) =>
1123 (write
"\tAddOutputFilter ";
1125 app (fn f
=> (write
";"; write f
)) fs
;
1126 app (fn ext
=> (write
" "; write ext
)) exts
;
1130 val () = Domain
.registerResetLocal (fn () =>
1131 ignore (OS
.Process
.system (Config
.rm ^
" -rf /var/domtool/vhosts/*")))
1133 val () = Domain
.registerDescriber (Domain
.considerAll
1134 [Domain
.Extension
{extension
= "vhost",
1135 heading
= fn host
=> "Web vhost " ^ host ^
":"},
1136 Domain
.Extension
{extension
= "vhost_ssl",
1137 heading
= fn host
=> "SSL web vhost " ^ host ^
":"}])
1139 val () = Env
.action_none
"testNoHtaccess"
1140 (fn path
=> write
"\tAllowOverride None\n")
1142 fun writeWaklogUserFile () =
1144 val users
= Acl
.users ()
1145 val outf
= TextIO.openOut Config
.Apache
.waklogUserFile
1147 app (fn user
=> if String.isSuffix
"_admin" user
then
1150 (TextIO.output (outf
, "<Location /~");
1151 TextIO.output (outf
, user
);
1152 TextIO.output (outf
, ">\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
1153 TextIO.output (outf
, user
);
1154 TextIO.output (outf
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
1155 TextIO.output (outf
, user
);
1156 TextIO.output (outf
, "\n</Location>\n\n"))) users
;
1157 TextIO.closeOut outf
1160 val () = Domain
.registerOnUsersChange writeWaklogUserFile