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 fun validCaCert s
= Acl
.query
{user
= Domain
.getUser (),
125 val _
= Env
.type_one
"ssl_cert_path"
129 val _
= Env
.type_one
"ssl_cacert_path"
133 fun ssl e
= case e
of
134 (EVar
"no_ssl", _
) => SOME NONE
135 |
(EApp ((EVar
"use_cert", _
), s
), _
) => Option
.map
SOME (Env
.string s
)
138 fun validExtension s
=
141 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"_") s
143 val _
= Env
.type_one
"file_extension"
147 val _
= Env
.registerFunction ("defaultServerAdmin",
148 fn [] => SOME (EString (Domain
.getUser () ^
"@" ^ Config
.defaultDomain
), dl
)
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"
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
182 | SOME s1
=> Option
.map (fn s2
=> "E=" ^ s1 ^
":" ^ s2
)
187 val cond_flag
= fn (EVar
"cond_nocase", _
) => SOME
"NC"
188 |
(EVar
"ornext", _
) => SOME
"OR"
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 |
(EVar
"multiViews", _
) => SOME
"MultiViews"
198 val autoindex_width
= fn (EVar
"autofit", _
) => SOME
"*"
199 |
(EApp ((EVar
"characters", _
), n
), _
) =>
200 Option
.map
Int.toString (Env
.int n
)
203 val autoindex_option
= fn (EApp ((EVar
"descriptionWidth", _
), w
), _
) =>
204 Option
.map (fn w
=> ("DescriptionWidth", SOME w
))
206 |
(EVar
"fancyIndexing", _
) => SOME ("FancyIndexing", NONE
)
207 |
(EVar
"foldersFirst", _
) => SOME ("FoldersFirst", NONE
)
208 |
(EVar
"htmlTable", _
) => SOME ("HTMLTable", NONE
)
209 |
(EVar
"iconsAreLinks", _
) => SOME ("IconsAreLinks", NONE
)
210 |
(EApp ((EVar
"iconHeight", _
), n
), _
) =>
211 Option
.map (fn w
=> ("IconHeight", SOME (Int.toString w
)))
213 |
(EApp ((EVar
"iconWidth", _
), n
), _
) =>
214 Option
.map (fn w
=> ("IconWidth", SOME (Int.toString w
)))
216 |
(EVar
"ignoreCase", _
) => SOME ("IgnoreCase", NONE
)
217 |
(EVar
"ignoreClient", _
) => SOME ("IgnoreClient", NONE
)
218 |
(EApp ((EVar
"nameWidth", _
), w
), _
) =>
219 Option
.map (fn w
=> ("NameWidth", SOME w
))
221 |
(EVar
"scanHtmlTitles", _
) => SOME ("ScanHTMLTitles", NONE
)
222 |
(EVar
"suppressColumnSorting", _
) => SOME ("SuppressColumnSorting", NONE
)
223 |
(EVar
"suppressDescription", _
) => SOME ("SuppressDescription", NONE
)
224 |
(EVar
"suppressHtmlPreamble", _
) => SOME ("SuppressHTMLPreamble", NONE
)
225 |
(EVar
"suppressIcon", _
) => SOME ("SuppressIcon", NONE
)
226 |
(EVar
"suppressLastModified", _
) => SOME ("SuppressLastModified", NONE
)
227 |
(EVar
"suppressRules", _
) => SOME ("SuppressRules", NONE
)
228 |
(EVar
"suppressSize", _
) => SOME ("SuppressSize", NONE
)
229 |
(EVar
"trackModified", _
) => SOME ("TrackModified", NONE
)
230 |
(EVar
"versionSort", _
) => SOME ("VersionSort", NONE
)
231 |
(EVar
"xhtml", _
) => SOME ("XHTML", NONE
)
235 val interval_base
= fn (EVar
"access", _
) => SOME
"access"
236 |
(EVar
"modification", _
) => SOME
"modification"
239 val interval
= fn (EVar
"years", _
) => SOME
"years"
240 |
(EVar
"months", _
) => SOME
"months"
241 |
(EVar
"weeks", _
) => SOME
"weeks"
242 |
(EVar
"days", _
) => SOME
"days"
243 |
(EVar
"hours", _
) => SOME
"hours"
244 |
(EVar
"minutes", _
) => SOME
"minutes"
245 |
(EVar
"seconds", _
) => SOME
"seconds"
248 val vhostsChanged
= ref
false
249 val logDeleted
= ref
false
250 val delayedLogMoves
= ref (fn () => ())
252 val () = Slave
.registerPreHandler
253 (fn () => (vhostsChanged
:= false;
255 delayedLogMoves
:= (fn () => print
"Executing delayed log moves/deletes.\n")))
257 fun findVhostUser fname
=
259 val inf
= TextIO.openIn fname
262 case TextIO.inputLine inf
of
265 if String.isPrefix
"# Owner: " line
then
266 case String.tokens
Char.isSpace line
of
267 [_
, _
, user
] => SOME user
273 before TextIO.closeIn inf
276 val webNodes_full
= Config
.Apache
.webNodes_all @ Config
.Apache
.webNodes_admin
278 fun isVersion1 node
=
279 List.exists (fn (n
, {version
= ConfigTypes
.APACHE_1_3
, ...}) => n
= node
280 | _
=> false) webNodes_full
282 fun imVersion1 () = isVersion1 (Slave
.hostname ())
285 List.exists (fn (n
, {auth
= ConfigTypes
.MOD_WAKLOG
, ...}) => n
= node
286 | _
=> false) webNodes_full
288 fun down () = if imVersion1 () then Config
.Apache
.down1
else Config
.Apache
.down
289 fun undown () = if imVersion1 () then Config
.Apache
.undown1
else Config
.Apache
.undown
290 fun reload () = if imVersion1 () then Config
.Apache
.reload1
else Config
.Apache
.reload
291 fun fixperms () = if imVersion1 () then Config
.Apache
.fixperms1
else Config
.Apache
.fixperms
293 fun logDir
{user
, node
, vhostId
} =
294 String.concat
[Config
.Apache
.logDirOf (isVersion1 node
) user
,
300 fun realLogDir
{user
, node
, vhostId
} =
301 String.concat
[Config
.Apache
.realLogDirOf user
,
307 val () = Slave
.registerFileHandler (fn fs
=>
309 val spl
= OS
.Path
.splitDirFile (#file fs
)
311 if String.isSuffix
".vhost" (#file spl
)
312 orelse String.isSuffix
".vhost_ssl" (#file spl
) then let
313 val realVhostFile
= OS
.Path
.joinDirFile
314 {dir
= Config
.Apache
.confDir
,
317 val user
= findVhostUser (#file fs
)
318 val oldUser
= case #action fs
of
319 Slave
.Delete
false => user
320 | _
=> findVhostUser realVhostFile
322 if (oldUser
= NONE
andalso #action fs
<> Slave
.Add
)
323 orelse (user
= NONE
andalso not (Slave
.isDelete (#action fs
))) then
324 print ("Can't find user in " ^ #file fs ^
" or " ^ realVhostFile ^
"! Taking no action.\n")
327 val vhostId
= if OS
.Path
.ext (#file spl
) = SOME
"vhost_ssl" then
328 OS
.Path
.base (#file spl
) ^
".ssl"
330 OS
.Path
.base (#file spl
)
332 fun realLogDir user
=
333 logDir
{user
= valOf user
,
334 node
= Slave
.hostname (),
339 {dir
= Config
.Apache
.backupLogDirOf
340 (isVersion1 (Slave
.hostname ())),
343 vhostsChanged
:= true;
347 val ldir
= realLogDir oldUser
348 val dlm
= !delayedLogMoves
353 ((*ignore (OS
.Process
.system (down ()));*)
354 ignore (OS
.Process
.system (fixperms ()));
356 ignore (OS
.Process
.system (Config
.rm
359 delayedLogMoves
:= (fn () => (dlm ();
360 Slave
.moveDirCreate
{from
= ldir
,
361 to
= backupLogs ()}))
365 val rld
= realLogDir user
367 ignore (OS
.Process
.system (Config
.cp
372 if Posix
.FileSys
.access (rld
, []) then
375 Slave
.moveDirCreate
{from
= backupLogs (),
380 (ignore (OS
.Process
.system (Config
.cp
385 if user
<> oldUser
then
387 val old
= realLogDir oldUser
388 val rld
= realLogDir user
390 val dlm
= !delayedLogMoves
395 ((*ignore (OS
.Process
.system (down ()));*)
397 delayedLogMoves
:= (fn () => (dlm ();
398 ignore (OS
.Process
.system (Config
.rm
400 ^ realLogDir oldUser
))));
401 if Posix
.FileSys
.access (rld
, []) then
414 val () = Slave
.registerPostHandler
416 (if !vhostsChanged
then
417 (Slave
.shellF ([reload ()],
418 fn cl
=> "Error reloading Apache with " ^ cl
);
419 if !logDeleted
then !delayedLogMoves () else ())
423 val vhostFiles
: (string * TextIO.outstream
) list ref
= ref
[]
424 fun write
' s
= app (fn (node
, file
) => TextIO.output (file
, s node
)) (!vhostFiles
)
425 fun write s
= app (fn (_
, file
) => TextIO.output (file
, s
)) (!vhostFiles
)
427 val rewriteEnabled
= ref
false
428 val localRewriteEnabled
= ref
false
429 val expiresEnabled
= ref
false
430 val localExpiresEnabled
= ref
false
431 val currentVhost
= ref
""
432 val currentVhostId
= ref
""
433 val sslEnabled
= ref
false
435 val pre
= ref (fn _
: {user
: string, nodes
: string list
, id
: string, hostname
: string} => ())
440 pre
:= (fn x
=> (old x
; f x
))
443 val post
= ref (fn () => ())
448 post
:= (fn () => (old (); f ()))
452 fun doPost () = !post ()
454 val aliaser
= ref (fn _
: string => ())
455 fun registerAliaser f
=
459 aliaser
:= (fn x
=> (old x
; f x
))
462 fun vhostPost () = (!post ();
463 write
"</VirtualHost>\n";
464 app (TextIO.closeOut
o #
2) (!vhostFiles
))
466 val php_version
= fn (EVar
"php5", _
) => SOME
5
469 fun vhostBody (env
, makeFullHost
) =
471 val places
= Env
.env (Env
.list webPlace
) (env
, "WebPlaces")
473 val ssl
= Env
.env
ssl (env
, "SSL")
474 val user
= Env
.env Env
.string (env
, "User")
475 val group
= Env
.env Env
.string (env
, "Group")
476 val docroot
= Env
.env Env
.string (env
, "DocumentRoot")
477 val sadmin
= Env
.env Env
.string (env
, "ServerAdmin")
478 val suexec
= Env
.env Env
.bool (env
, "SuExec")
479 val php
= Env
.env
php_version (env
, "PhpVersion")
481 val fullHost
= makeFullHost (Domain
.currentDomain ())
482 val vhostId
= fullHost ^
(if Option
.isSome ssl
then ".ssl" else "")
483 val confFile
= fullHost ^
(if Option
.isSome ssl
then ".vhost_ssl" else ".vhost")
485 currentVhost
:= fullHost
;
486 currentVhostId
:= vhostId
;
487 sslEnabled
:= Option
.isSome ssl
;
489 rewriteEnabled
:= false;
490 localRewriteEnabled
:= false;
491 expiresEnabled
:= false;
492 localExpiresEnabled
:= false;
493 vhostFiles
:= map (fn (node
, ip
) =>
495 val file
= Domain
.domainFile
{node
= node
,
498 val ld
= logDir
{user
= user
, node
= node
, vhostId
= vhostId
}
500 TextIO.output (file
, "# Owner: ");
501 TextIO.output (file
, user
);
502 TextIO.output (file
, "\n<VirtualHost ");
503 TextIO.output (file
, ip
);
504 TextIO.output (file
, ":");
505 TextIO.output (file
, case ssl
of
508 TextIO.output (file
, ">\n");
509 TextIO.output (file
, "\tErrorLog ");
510 TextIO.output (file
, ld
);
511 TextIO.output (file
, "/error.log\n\tCustomLog ");
512 TextIO.output (file
, ld
);
513 TextIO.output (file
, "/access.log combined\n");
514 TextIO.output (file
, "\tServerName ");
515 TextIO.output (file
, fullHost
);
517 (fn dom
=> (TextIO.output (file
, "\n\tServerAlias ");
518 TextIO.output (file
, makeFullHost dom
)))
519 (Domain
.currentAliasDomains ());
522 if isVersion1 node
then
523 (TextIO.output (file
, "\n\tUser ");
524 TextIO.output (file
, user
);
525 TextIO.output (file
, "\n\tGroup ");
526 TextIO.output (file
, group
))
528 (TextIO.output (file
, "\n\tSuexecUserGroup ");
529 TextIO.output (file
, user
);
530 TextIO.output (file
, " ");
531 TextIO.output (file
, group
);
532 TextIO.output (file
, "\n\tsuPHP_UserGroup ");
533 TextIO.output (file
, user
);
534 TextIO.output (file
, " ");
535 TextIO.output (file
, group
))
539 if isWaklog node
then
540 (TextIO.output (file
, "\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
541 TextIO.output (file
, user
);
542 TextIO.output (file
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
543 TextIO.output (file
, user
))
547 TextIO.output (file
, "\n\tDAVLockDB /var/lock/apache2/dav/");
548 TextIO.output (file
, user
);
549 TextIO.output (file
, "/DAVLock");
551 if php
<> Config
.Apache
.defaultPhpVersion
then
552 (TextIO.output (file
, "\n\tAddHandler x-httpd-php");
553 TextIO.output (file
, Int.toString php
);
554 TextIO.output (file
, " .php .phtml"))
561 write
"\n\tDocumentRoot ";
563 write
"\n\tServerAdmin ";
567 (write
"\n\tSSLEngine on\n\tSSLCertificateFile ";
571 !pre
{user
= user
, nodes
= map #
1 places
, id
= vhostId
, hostname
= fullHost
};
572 app (fn dom
=> !aliaser (makeFullHost dom
)) (Domain
.currentAliasDomains ())
575 val () = Env
.containerV_one
"vhost"
577 (fn (env
, host
) => vhostBody (env
, fn dom
=> host ^
"." ^ dom
),
580 val () = Env
.containerV_none
"vhostDefault"
581 (fn env
=> vhostBody (env
, fn dom
=> dom
),
584 val inLocal
= ref
false
586 val () = Env
.container_one
"location"
587 ("prefix", Env
.string)
589 (write
"\t<Location ";
593 fn () => (write
"\t</Location>\n";
595 localRewriteEnabled
:= false;
596 localExpiresEnabled
:= false))
598 val () = Env
.container_one
"directory"
599 ("directory", Env
.string)
601 (write
"\t<Directory ";
605 fn () => (write
"\t</Directory>\n";
607 localRewriteEnabled
:= false;
608 localExpiresEnabled
:= false))
610 val () = Env
.container_one
"filesMatch"
611 ("regexp", Env
.string)
613 (write
"\t<FilesMatch \"";
616 fn () => (write
"\t</FilesMatch>\n";
617 localRewriteEnabled
:= false;
618 localExpiresEnabled
:= false))
620 fun checkRewrite () =
622 if !localRewriteEnabled
then
625 (write
"\tRewriteEngine on\n";
626 localRewriteEnabled
:= true)
627 else if !rewriteEnabled
then
630 (write
"\tRewriteEngine on\n";
631 rewriteEnabled
:= true)
633 fun checkExpires () =
635 if !localExpiresEnabled
then
638 (write
"\tExpiresActive on\n";
639 localExpiresEnabled
:= true)
640 else if !expiresEnabled
then
643 (write
"\tExpiresActive on\n";
644 expiresEnabled
:= true)
646 val () = Env
.action_three
"localProxyRewrite"
647 ("from", Env
.string, "to", Env
.string, "port", Env
.int)
648 (fn (from
, to
, port
) =>
650 write
"\tRewriteRule\t\"";
652 write
"\"\thttp://localhost:";
653 write (Int.toString port
);
658 val () = Env
.action_four
"expiresByType"
659 ("mime", Env
.string, "base", interval_base
, "num", Env
.int, "inter", interval
)
660 (fn (mime
, base
, num
, inter
) =>
662 write
"\tExpiresByType\t\"";
669 write (Int.toString (~num
)))
671 write (Int.toString num
);
676 val () = Env
.action_two
"proxyPass"
677 ("from", Env
.string, "to", Env
.string)
679 (write
"\tProxyPass\t";
685 val () = Env
.action_two
"proxyPassReverse"
686 ("from", Env
.string, "to", Env
.string)
688 (write
"\tProxyPassReverse\t";
694 val () = Env
.action_three
"rewriteRule"
695 ("from", Env
.string, "to", Env
.string, "flags", Env
.list flag
)
696 (fn (from
, to
, flags
) =>
698 write
"\tRewriteRule\t\"";
705 | flag
::rest
=> (write
" [";
707 app (fn flag
=> (write
",";
712 val () = Env
.action_three
"rewriteCond"
713 ("test", Env
.string, "pattern", Env
.string, "flags", Env
.list cond_flag
)
714 (fn (from
, to
, flags
) =>
716 write
"\tRewriteCond\t\"";
723 | flag
::rest
=> (write
" [";
725 app (fn flag
=> (write
",";
730 val () = Env
.action_one
"rewriteBase"
731 ("prefix", Env
.string)
734 write
"\tRewriteBase\t\"";
738 val () = Env
.action_one
"rewriteLogLevel"
742 write
"\tRewriteLog ";
744 write
"/rewrite.log\n\tRewriteLogLevel ";
745 write (Int.toString level
);
748 val () = Env
.action_two
"alias"
749 ("from", Env
.string, "to", Env
.string)
757 val () = Env
.action_two
"scriptAlias"
758 ("from", Env
.string, "to", Env
.string)
760 (write
"\tScriptAlias\t";
766 val () = Env
.action_two
"errorDocument"
767 ("code", Env
.string, "handler", Env
.string)
768 (fn (code
, handler
) =>
770 val hasSpaces
= CharVector
.exists
Char.isSpace handler
778 write
"\tErrorDocument\t";
787 val () = Env
.action_one
"options"
788 ("options", Env
.list apache_option
)
792 | _
=> (write
"\tOptions";
793 app (fn opt
=> (write
" "; write opt
)) opts
;
796 val () = Env
.action_one
"set_options"
797 ("options", Env
.list apache_option
)
801 | _
=> (write
"\tOptions";
802 app (fn opt
=> (write
" +"; write opt
)) opts
;
805 val () = Env
.action_one
"unset_options"
806 ("options", Env
.list apache_option
)
810 | _
=> (write
"\tOptions";
811 app (fn opt
=> (write
" -"; write opt
)) opts
;
814 val () = Env
.action_one
"cgiExtension"
815 ("extension", Env
.string)
816 (fn ext
=> (write
"\tAddHandler cgi-script ";
820 val () = Env
.action_one
"directoryIndex"
821 ("filenames", Env
.list Env
.string)
823 (write
"\tDirectoryIndex";
824 app (fn opt
=> (write
" "; write opt
)) opts
;
827 val () = Env
.action_one
"serverAliasHost"
830 (write
"\tServerAlias ";
835 val () = Env
.action_one
"serverAlias"
841 val full
= host ^
"." ^ dom
843 write
"\tServerAlias ";
848 (Domain
.currentDomains ())))
850 val () = Env
.action_none
"serverAliasDefault"
854 (write
"\tServerAlias ";
858 (Domain
.currentDomains ())))
860 val authType
= fn (EVar
"basic", _
) => SOME
"basic"
861 |
(EVar
"digest", _
) => SOME
"digest"
862 |
(EVar
"kerberos", _
) => SOME
"kerberos"
865 fun allowAuthType
"kerberos" = !sslEnabled
866 | allowAuthType _
= true
868 val () = Env
.action_one
"authType"
871 if allowAuthType ty
then
872 (write
"\tAuthType ";
877 write
"\tKrbMethodNegotiate off\n\tKrbMethodK5Passwd on\n\tKrbVerifyKDC off\n\tKrbAuthRealms HCOOP.NET\n\tKrbSaveCredentials on\n"
880 print
"WARNING: Skipped Kerberos authType because this isn't an SSL vhost.\n")
882 val () = Env
.action_one
"authName"
885 (write
"\tAuthName \"";
889 val () = Env
.action_one
"authUserFile"
892 (write
"\tAuthUserFile ";
896 val () = Env
.action_one
"authGroupFile"
899 (write
"\tAuthGroupFile ";
903 val () = Env
.action_none
"requireValidUser"
904 (fn () => write
"\tRequire valid-user\n")
906 val () = Env
.action_one
"requireUser"
907 ("users", Env
.list Env
.string)
911 | _
=> (write
"\tRequire user";
912 app (fn name
=> (write
" "; write name
)) names
;
915 val () = Env
.action_one
"requireGroup"
916 ("groups", Env
.list Env
.string)
920 | _
=> (write
"\tRequire group";
921 app (fn name
=> (write
" "; write name
)) names
;
924 val () = Env
.action_none
"orderAllowDeny"
925 (fn () => write
"\tOrder allow,deny\n")
927 val () = Env
.action_none
"orderDenyAllow"
928 (fn () => write
"\tOrder deny,allow\n")
930 val () = Env
.action_none
"allowFromAll"
931 (fn () => write
"\tAllow from all\n")
933 val () = Env
.action_one
"allowFrom"
934 ("entries", Env
.list Env
.string)
938 | _
=> (write
"\tAllow from";
939 app (fn name
=> (write
" "; write name
)) names
;
942 val () = Env
.action_none
"denyFromAll"
943 (fn () => write
"\tDeny from all\n")
945 val () = Env
.action_one
"denyFrom"
946 ("entries", Env
.list Env
.string)
950 | _
=> (write
"\tDeny from";
951 app (fn name
=> (write
" "; write name
)) names
;
954 val () = Env
.action_none
"satisfyAll"
955 (fn () => write
"\tSatisfy all\n")
957 val () = Env
.action_none
"satisfyAny"
958 (fn () => write
"\tSatisfy any\n")
960 val () = Env
.action_one
"forceType"
962 (fn ty
=> (write
"\tForceType ";
966 val () = Env
.action_none
"forceTypeOff"
967 (fn () => write
"\tForceType None\n")
969 val () = Env
.action_two
"action"
970 ("what", Env
.string, "how", Env
.string)
971 (fn (what
, how
) => (write
"\tAction ";
977 val () = Env
.action_one
"addDefaultCharset"
978 ("charset", Env
.string)
979 (fn ty
=> (write
"\tAddDefaultCharset ";
983 (*val () = Env
.action_one
"davSvn"
985 (fn path
=> (write
"\tDAV svn\n\tSVNPath ";
989 val () = Env
.action_one
"authzSvnAccessFile"
991 (fn path
=> (write
"\tAuthzSVNAccessFile ";
995 val () = Env
.action_none
"davFilesystem"
996 (fn path
=> write
"\tDAV filesystem\n")
998 val () = Env
.action_two
"addDescription"
999 ("description", Env
.string, "patterns", Env
.list Env
.string)
1003 | _
=> (write
"\tAddDescription \"";
1004 write (String.toString desc
);
1006 app (fn pat
=> (write
" "; write pat
)) pats
;
1009 val () = Env
.action_two
"addIcon"
1010 ("icon", Env
.string, "patterns", Env
.list Env
.string)
1014 | _
=> (write
"\tAddIcon \"";
1017 app (fn pat
=> (write
" "; write pat
)) pats
;
1020 val () = Env
.action_one
"indexOptions"
1021 ("options", Env
.list autoindex_option
)
1025 | _
=> (write
"\tIndexOptions";
1026 app (fn (opt
, arg
) =>
1029 Option
.app (fn arg
=>
1030 (write
"="; write arg
)) arg
)) opts
;
1033 val () = Env
.action_one
"indexIgnore"
1034 ("patterns", Env
.list Env
.string)
1038 | _
=> (write
"\tIndexIgnore";
1039 app (fn pat
=> (write
" "; write pat
)) pats
;
1042 val () = Env
.action_one
"set_indexOptions"
1043 ("options", Env
.list autoindex_option
)
1047 | _
=> (write
"\tIndexOptions";
1048 app (fn (opt
, arg
) =>
1051 Option
.app (fn arg
=>
1052 (write
"="; write arg
)) arg
)) opts
;
1055 val () = Env
.action_one
"unset_indexOptions"
1056 ("options", Env
.list autoindex_option
)
1060 | _
=> (write
"\tIndexOptions";
1066 val () = Env
.action_one
"headerName"
1067 ("name", Env
.string)
1068 (fn name
=> (write
"\tHeaderName ";
1072 val () = Env
.action_one
"readmeName"
1073 ("name", Env
.string)
1074 (fn name
=> (write
"\tReadmeName ";
1078 val () = Env
.action_two
"setEnv"
1079 ("key", Env
.string, "value", Env
.string)
1080 (fn (key
, value
) => (write
"\tSetEnv \"";
1083 write (String.translate (fn #
"\"" => "\\\""
1084 | ch
=> str ch
) value
);
1087 val () = Env
.action_one
"diskCache"
1088 ("path", Env
.string)
1089 (fn path
=> (write
"\tCacheEnable disk \"";
1093 val () = Env
.action_one
"phpVersion"
1094 ("version", php_version
)
1095 (fn version
=> (write
"\tAddHandler x-httpd-php";
1096 write (Int.toString version
);
1097 write
" .php .phtml\n"))
1099 val () = Env
.action_two
"addType"
1100 ("mime type", Env
.string, "extension", Env
.string)
1101 (fn (mt
, ext
) => (write
"\tAddType ";
1107 val filter
= fn (EVar
"includes", _
) => SOME
"INCLUDES"
1108 |
(EVar
"deflate", _
) => SOME
"DEFLATE"
1111 val () = Env
.action_two
"addOutputFilter"
1112 ("filters", Env
.list filter
, "extensions", Env
.list Env
.string)
1113 (fn (f
:: fs
, exts
as (_
:: _
)) =>
1114 (write
"\tAddOutputFilter ";
1116 app (fn f
=> (write
";"; write f
)) fs
;
1117 app (fn ext
=> (write
" "; write ext
)) exts
;
1121 val () = Env
.action_one
"sslCertificateChainFile"
1122 ("ssl_cacert_path", Env
.string)
1125 (write
"\tSSLCertificateChainFile \"";
1129 print
"WARNING: Skipped sslCertificateChainFile because this isn't an SSL vhost.\n")
1131 val () = Domain
.registerResetLocal (fn () =>
1132 ignore (OS
.Process
.system (Config
.rm ^
" -rf /var/domtool/vhosts/*")))
1134 val () = Domain
.registerDescriber (Domain
.considerAll
1135 [Domain
.Extension
{extension
= "vhost",
1136 heading
= fn host
=> "Web vhost " ^ host ^
":"},
1137 Domain
.Extension
{extension
= "vhost_ssl",
1138 heading
= fn host
=> "SSL web vhost " ^ host ^
":"}])
1140 val () = Env
.action_none
"testNoHtaccess"
1141 (fn path
=> write
"\tAllowOverride None\n")
1143 fun writeWaklogUserFile () =
1145 val users
= Acl
.users ()
1146 val outf
= TextIO.openOut Config
.Apache
.waklogUserFile
1148 app (fn user
=> if String.isSuffix
"_admin" user
then
1151 (TextIO.output (outf
, "<Location /~");
1152 TextIO.output (outf
, user
);
1153 TextIO.output (outf
, ">\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
1154 TextIO.output (outf
, user
);
1155 TextIO.output (outf
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
1156 TextIO.output (outf
, user
);
1157 TextIO.output (outf
, "\n</Location>\n\n"))) users
;
1158 TextIO.closeOut outf
1161 val () = Domain
.registerOnUsersChange writeWaklogUserFile