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 fun validProxyTarget default s
=
66 case String.fields (fn ch
=> ch
= #
":") s
of
67 "http" :: host
:: rest
=>
69 val rest
= String.concatWith
":" rest
71 if List.exists (fn h
' => host
= h
') (map (fn h
=> String.concat
["//", h
]) Config
.Apache
.proxyHosts
)
73 CharVector
.all (fn ch
=> Char.isPrint ch
andalso not (Char.isSpace ch
)
74 andalso ch
<> #
"\"" andalso ch
<> #
"'") rest
75 andalso case String.fields (fn ch
=> ch
= #
"/") rest
of
77 (case Int.fromString port
of
79 | SOME n
=> n
> 1024 orelse default s
)
86 val _
= Env
.type_one
"proxy_target"
88 (validProxyTarget (fn s
=> List.exists (fn s
' => s
= s
') (Config
.Apache
.proxyTargets @
["!"])))
90 val _
= Env
.type_one
"proxy_reverse_target"
92 (validProxyTarget (fn s
=> List.exists (fn s
' => s
= s
') Config
.Apache
.proxyTargets
))
94 val _
= Env
.type_one
"rewrite_arg"
96 (CharVector
.all
Char.isAlphaNum
)
98 val _
= Env
.type_one
"suexec_flag"
100 (fn b
=> b
orelse Domain
.hasPriv
"www")
102 val _
= Env
.type_one
"regexp"
106 fun validLocation s
=
107 size s
> 0 andalso size s
< 1000 andalso CharVector
.all
108 (fn ch
=> Char.isAlphaNum ch
115 val _
= Env
.type_one
"location"
119 fun validCert s
= Acl
.query
{user
= Domain
.getUser (),
123 fun validCaCert s
= Acl
.query
{user
= Domain
.getUser (),
127 val _
= Env
.type_one
"ssl_cert_path"
131 val _
= Env
.type_one
"ssl_cacert_path"
135 fun ssl e
= case e
of
136 (EVar
"no_ssl", _
) => SOME NONE
137 |
(EApp ((EVar
"use_cert", _
), s
), _
) => Option
.map
SOME (Env
.string s
)
140 fun validExtension s
=
143 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"_") s
145 val _
= Env
.type_one
"file_extension"
149 val _
= Env
.registerFunction ("defaultServerAdmin",
150 fn [] => SOME (EString (Domain
.getUser () ^
"@" ^ Config
.defaultDomain
), dl
)
153 val redirect_code
= fn (EVar
"temp", _
) => SOME
"temp"
154 |
(EVar
"permanent", _
) => SOME
"permanent"
155 |
(EVar
"seeother", _
) => SOME
"seeother"
156 |
(EVar
"redir300", _
) => SOME
"300"
157 |
(EVar
"redir301", _
) => SOME
"301"
158 |
(EVar
"redir302", _
) => SOME
"302"
159 |
(EVar
"redir303", _
) => SOME
"303"
160 |
(EVar
"redir304", _
) => SOME
"304"
161 |
(EVar
"redir305", _
) => SOME
"305"
162 |
(EVar
"redir307", _
) => SOME
"307"
165 val flag
= fn (EVar
"redirect", _
) => SOME
"R"
166 |
(EVar
"forbidden", _
) => SOME
"F"
167 |
(EVar
"gone", _
) => SOME
"G"
168 |
(EVar
"last", _
) => SOME
"L"
169 |
(EVar
"chain", _
) => SOME
"C"
170 |
(EVar
"nosubreq", _
) => SOME
"NS"
171 |
(EVar
"nocase", _
) => SOME
"NC"
172 |
(EVar
"qsappend", _
) => SOME
"QSA"
173 |
(EVar
"noescape", _
) => SOME
"NE"
174 |
(EVar
"passthrough", _
) => SOME
"PT"
175 |
(EApp ((EVar
"mimeType", _
), e
), _
) =>
176 Option
.map (fn s
=> "T=" ^ s
) (Env
.string e
)
177 |
(EApp ((EVar
"redirectWith", _
), e
), _
) =>
178 Option
.map (fn s
=> "R=" ^ s
) (redirect_code e
)
179 |
(EApp ((EVar
"skip", _
), e
), _
) =>
180 Option
.map (fn n
=> "S=" ^
Int.toString n
) (Env
.int e
)
181 |
(EApp ((EApp ((EVar
"env", _
), e1
), _
), e2
), _
) =>
182 (case Env
.string e1
of
184 | SOME s1
=> Option
.map (fn s2
=> "E=" ^ s1 ^
":" ^ s2
)
189 val cond_flag
= fn (EVar
"cond_nocase", _
) => SOME
"NC"
190 |
(EVar
"ornext", _
) => SOME
"OR"
193 val apache_option
= fn (EVar
"execCGI", _
) => SOME
"ExecCGI"
194 |
(EVar
"includesNOEXEC", _
) => SOME
"IncludesNOEXEC"
195 |
(EVar
"indexes", _
) => SOME
"Indexes"
196 |
(EVar
"followSymLinks", _
) => SOME
"FollowSymLinks"
197 |
(EVar
"multiViews", _
) => SOME
"MultiViews"
200 val autoindex_width
= fn (EVar
"autofit", _
) => SOME
"*"
201 |
(EApp ((EVar
"characters", _
), n
), _
) =>
202 Option
.map
Int.toString (Env
.int n
)
205 val autoindex_option
= fn (EApp ((EVar
"descriptionWidth", _
), w
), _
) =>
206 Option
.map (fn w
=> ("DescriptionWidth", SOME w
))
208 |
(EVar
"fancyIndexing", _
) => SOME ("FancyIndexing", NONE
)
209 |
(EVar
"foldersFirst", _
) => SOME ("FoldersFirst", NONE
)
210 |
(EVar
"htmlTable", _
) => SOME ("HTMLTable", NONE
)
211 |
(EVar
"iconsAreLinks", _
) => SOME ("IconsAreLinks", NONE
)
212 |
(EApp ((EVar
"iconHeight", _
), n
), _
) =>
213 Option
.map (fn w
=> ("IconHeight", SOME (Int.toString w
)))
215 |
(EApp ((EVar
"iconWidth", _
), n
), _
) =>
216 Option
.map (fn w
=> ("IconWidth", SOME (Int.toString w
)))
218 |
(EVar
"ignoreCase", _
) => SOME ("IgnoreCase", NONE
)
219 |
(EVar
"ignoreClient", _
) => SOME ("IgnoreClient", NONE
)
220 |
(EApp ((EVar
"nameWidth", _
), w
), _
) =>
221 Option
.map (fn w
=> ("NameWidth", SOME w
))
223 |
(EVar
"scanHtmlTitles", _
) => SOME ("ScanHTMLTitles", NONE
)
224 |
(EVar
"suppressColumnSorting", _
) => SOME ("SuppressColumnSorting", NONE
)
225 |
(EVar
"suppressDescription", _
) => SOME ("SuppressDescription", NONE
)
226 |
(EVar
"suppressHtmlPreamble", _
) => SOME ("SuppressHTMLPreamble", NONE
)
227 |
(EVar
"suppressIcon", _
) => SOME ("SuppressIcon", NONE
)
228 |
(EVar
"suppressLastModified", _
) => SOME ("SuppressLastModified", NONE
)
229 |
(EVar
"suppressRules", _
) => SOME ("SuppressRules", NONE
)
230 |
(EVar
"suppressSize", _
) => SOME ("SuppressSize", NONE
)
231 |
(EVar
"trackModified", _
) => SOME ("TrackModified", NONE
)
232 |
(EVar
"versionSort", _
) => SOME ("VersionSort", NONE
)
233 |
(EVar
"xhtml", _
) => SOME ("XHTML", NONE
)
237 val interval_base
= fn (EVar
"access", _
) => SOME
"access"
238 |
(EVar
"modification", _
) => SOME
"modification"
241 val interval
= fn (EVar
"years", _
) => SOME
"years"
242 |
(EVar
"months", _
) => SOME
"months"
243 |
(EVar
"weeks", _
) => SOME
"weeks"
244 |
(EVar
"days", _
) => SOME
"days"
245 |
(EVar
"hours", _
) => SOME
"hours"
246 |
(EVar
"minutes", _
) => SOME
"minutes"
247 |
(EVar
"seconds", _
) => SOME
"seconds"
250 val vhostsChanged
= ref
false
251 val logDeleted
= ref
false
252 val delayedLogMoves
= ref (fn () => ())
254 val () = Slave
.registerPreHandler
255 (fn () => (vhostsChanged
:= false;
257 delayedLogMoves
:= (fn () => print
"Executing delayed log moves/deletes.\n")))
259 fun findVhostUser fname
=
261 val inf
= TextIO.openIn fname
264 case TextIO.inputLine inf
of
267 if String.isPrefix
"# Owner: " line
then
268 case String.tokens
Char.isSpace line
of
269 [_
, _
, user
] => SOME user
275 before TextIO.closeIn inf
278 val webNodes_full
= Config
.Apache
.webNodes_all @ Config
.Apache
.webNodes_admin
280 fun isVersion1 node
=
281 List.exists (fn (n
, {version
= ConfigTypes
.APACHE_1_3
, ...}) => n
= node
282 | _
=> false) webNodes_full
284 fun imVersion1 () = isVersion1 (Slave
.hostname ())
287 List.exists (fn (n
, {auth
= ConfigTypes
.MOD_WAKLOG
, ...}) => n
= node
288 | _
=> false) webNodes_full
290 fun down () = if imVersion1 () then Config
.Apache
.down1
else Config
.Apache
.down
291 fun undown () = if imVersion1 () then Config
.Apache
.undown1
else Config
.Apache
.undown
292 fun reload () = if imVersion1 () then Config
.Apache
.reload1
else Config
.Apache
.reload
293 fun fixperms () = if imVersion1 () then Config
.Apache
.fixperms1
else Config
.Apache
.fixperms
295 fun logDir
{user
, node
, vhostId
} =
296 String.concat
[Config
.Apache
.logDirOf (isVersion1 node
) user
,
302 fun realLogDir
{user
, node
, vhostId
} =
303 String.concat
[Config
.Apache
.realLogDirOf user
,
309 val () = Slave
.registerFileHandler (fn fs
=>
311 val spl
= OS
.Path
.splitDirFile (#file fs
)
313 if String.isSuffix
".vhost" (#file spl
)
314 orelse String.isSuffix
".vhost_ssl" (#file spl
) then let
315 val realVhostFile
= OS
.Path
.joinDirFile
316 {dir
= Config
.Apache
.confDir
,
319 val user
= findVhostUser (#file fs
)
320 val oldUser
= case #action fs
of
321 Slave
.Delete
false => user
322 | _
=> findVhostUser realVhostFile
324 if (oldUser
= NONE
andalso #action fs
<> Slave
.Add
)
325 orelse (user
= NONE
andalso not (Slave
.isDelete (#action fs
))) then
326 print ("Can't find user in " ^ #file fs ^
" or " ^ realVhostFile ^
"! Taking no action.\n")
329 val vhostId
= if OS
.Path
.ext (#file spl
) = SOME
"vhost_ssl" then
330 OS
.Path
.base (#file spl
) ^
".ssl"
332 OS
.Path
.base (#file spl
)
334 fun realLogDir user
=
335 logDir
{user
= valOf user
,
336 node
= Slave
.hostname (),
341 {dir
= Config
.Apache
.backupLogDirOf
342 (isVersion1 (Slave
.hostname ())),
345 vhostsChanged
:= true;
349 val ldir
= realLogDir oldUser
350 val dlm
= !delayedLogMoves
355 ((*ignore (OS
.Process
.system (down ()));*)
356 ignore (OS
.Process
.system (fixperms ()));
358 ignore (OS
.Process
.system (Config
.rm
361 delayedLogMoves
:= (fn () => (dlm ();
362 Slave
.moveDirCreate
{from
= ldir
,
363 to
= backupLogs ()}))
367 val rld
= realLogDir user
369 ignore (OS
.Process
.system (Config
.cp
374 if Posix
.FileSys
.access (rld
, []) then
377 Slave
.moveDirCreate
{from
= backupLogs (),
382 (ignore (OS
.Process
.system (Config
.cp
387 if user
<> oldUser
then
389 val old
= realLogDir oldUser
390 val rld
= realLogDir user
392 val dlm
= !delayedLogMoves
397 ((*ignore (OS
.Process
.system (down ()));*)
399 delayedLogMoves
:= (fn () => (dlm ();
400 ignore (OS
.Process
.system (Config
.rm
402 ^ realLogDir oldUser
))));
403 if Posix
.FileSys
.access (rld
, []) then
416 val () = Slave
.registerPostHandler
418 (if !vhostsChanged
then
419 (Slave
.shellF ([reload ()],
420 fn cl
=> "Error reloading Apache with " ^ cl
);
421 if !logDeleted
then !delayedLogMoves () else ())
425 val vhostFiles
: (string * TextIO.outstream
) list ref
= ref
[]
426 fun write
' s
= app (fn (node
, file
) => TextIO.output (file
, s node
)) (!vhostFiles
)
427 fun write s
= app (fn (_
, file
) => TextIO.output (file
, s
)) (!vhostFiles
)
429 val rewriteEnabled
= ref
false
430 val localRewriteEnabled
= ref
false
431 val expiresEnabled
= ref
false
432 val localExpiresEnabled
= ref
false
433 val currentVhost
= ref
""
434 val currentVhostId
= ref
""
435 val sslEnabled
= ref
false
437 val pre
= ref (fn _
: {user
: string, nodes
: string list
, id
: string, hostname
: string} => ())
442 pre
:= (fn x
=> (old x
; f x
))
445 val post
= ref (fn () => ())
450 post
:= (fn () => (old (); f ()))
454 fun doPost () = !post ()
456 val aliaser
= ref (fn _
: string => ())
457 fun registerAliaser f
=
461 aliaser
:= (fn x
=> (old x
; f x
))
464 fun vhostPost () = (!post ();
465 write
"</VirtualHost>\n";
466 app (TextIO.closeOut
o #
2) (!vhostFiles
))
468 val php_version
= fn (EVar
"php5", _
) => SOME
5
471 fun vhostBody (env
, makeFullHost
) =
473 val places
= Env
.env (Env
.list webPlace
) (env
, "WebPlaces")
475 val ssl
= Env
.env
ssl (env
, "SSL")
476 val user
= Env
.env Env
.string (env
, "User")
477 val group
= Env
.env Env
.string (env
, "Group")
478 val docroot
= Env
.env Env
.string (env
, "DocumentRoot")
479 val sadmin
= Env
.env Env
.string (env
, "ServerAdmin")
480 val suexec
= Env
.env Env
.bool (env
, "SuExec")
481 val php
= Env
.env
php_version (env
, "PhpVersion")
483 val fullHost
= makeFullHost (Domain
.currentDomain ())
484 val vhostId
= fullHost ^
(if Option
.isSome ssl
then ".ssl" else "")
485 val confFile
= fullHost ^
(if Option
.isSome ssl
then ".vhost_ssl" else ".vhost")
487 currentVhost
:= fullHost
;
488 currentVhostId
:= vhostId
;
489 sslEnabled
:= Option
.isSome ssl
;
491 rewriteEnabled
:= false;
492 localRewriteEnabled
:= false;
493 expiresEnabled
:= false;
494 localExpiresEnabled
:= false;
495 vhostFiles
:= map (fn (node
, ip
) =>
497 val file
= Domain
.domainFile
{node
= node
,
500 val ld
= logDir
{user
= user
, node
= node
, vhostId
= vhostId
}
502 TextIO.output (file
, "# Owner: ");
503 TextIO.output (file
, user
);
504 TextIO.output (file
, "\n<VirtualHost ");
505 TextIO.output (file
, ip
);
506 TextIO.output (file
, ":");
507 TextIO.output (file
, case ssl
of
510 TextIO.output (file
, ">\n");
511 TextIO.output (file
, "\tErrorLog ");
512 TextIO.output (file
, ld
);
513 TextIO.output (file
, "/error.log\n\tCustomLog ");
514 TextIO.output (file
, ld
);
515 TextIO.output (file
, "/access.log combined\n");
516 TextIO.output (file
, "\tServerName ");
517 TextIO.output (file
, fullHost
);
519 (fn dom
=> (TextIO.output (file
, "\n\tServerAlias ");
520 TextIO.output (file
, makeFullHost dom
)))
521 (Domain
.currentAliasDomains ());
524 if isVersion1 node
then
525 (TextIO.output (file
, "\n\tUser ");
526 TextIO.output (file
, user
);
527 TextIO.output (file
, "\n\tGroup ");
528 TextIO.output (file
, group
))
530 (TextIO.output (file
, "\n\tSuexecUserGroup ");
531 TextIO.output (file
, user
);
532 TextIO.output (file
, " ");
533 TextIO.output (file
, group
);
534 TextIO.output (file
, "\n\tsuPHP_UserGroup ");
535 TextIO.output (file
, user
);
536 TextIO.output (file
, " ");
537 TextIO.output (file
, group
))
541 if isWaklog node
then
542 (TextIO.output (file
, "\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
543 TextIO.output (file
, user
);
544 TextIO.output (file
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
545 TextIO.output (file
, user
))
549 TextIO.output (file
, "\n\tDAVLockDB /var/lock/apache2/dav/");
550 TextIO.output (file
, user
);
551 TextIO.output (file
, "/DAVLock");
553 if php
<> Config
.Apache
.defaultPhpVersion
then
554 (TextIO.output (file
, "\n\tAddHandler x-httpd-php");
555 TextIO.output (file
, Int.toString php
);
556 TextIO.output (file
, " .php .phtml"))
563 write
"\n\tDocumentRoot ";
565 write
"\n\tServerAdmin ";
569 (write
"\n\tSSLEngine on\n\tSSLCertificateFile ";
573 !pre
{user
= user
, nodes
= map #
1 places
, id
= vhostId
, hostname
= fullHost
};
574 app (fn dom
=> !aliaser (makeFullHost dom
)) (Domain
.currentAliasDomains ())
577 val () = Env
.containerV_one
"vhost"
579 (fn (env
, host
) => vhostBody (env
, fn dom
=> host ^
"." ^ dom
),
582 val () = Env
.containerV_none
"vhostDefault"
583 (fn env
=> vhostBody (env
, fn dom
=> dom
),
586 val inLocal
= ref
false
588 val () = Env
.container_one
"location"
589 ("prefix", Env
.string)
591 (write
"\t<Location ";
595 fn () => (write
"\t</Location>\n";
597 localRewriteEnabled
:= false;
598 localExpiresEnabled
:= false))
600 val () = Env
.container_one
"directory"
601 ("directory", Env
.string)
603 (write
"\t<Directory ";
607 fn () => (write
"\t</Directory>\n";
609 localRewriteEnabled
:= false;
610 localExpiresEnabled
:= false))
612 val () = Env
.container_one
"filesMatch"
613 ("regexp", Env
.string)
615 (write
"\t<FilesMatch \"";
618 fn () => (write
"\t</FilesMatch>\n";
619 localRewriteEnabled
:= false;
620 localExpiresEnabled
:= false))
622 fun checkRewrite () =
624 if !localRewriteEnabled
then
627 (write
"\tRewriteEngine on\n";
628 localRewriteEnabled
:= true)
629 else if !rewriteEnabled
then
632 (write
"\tRewriteEngine on\n";
633 rewriteEnabled
:= true)
635 fun checkExpires () =
637 if !localExpiresEnabled
then
640 (write
"\tExpiresActive on\n";
641 localExpiresEnabled
:= true)
642 else if !expiresEnabled
then
645 (write
"\tExpiresActive on\n";
646 expiresEnabled
:= true)
648 val () = Env
.action_three
"localProxyRewrite"
649 ("from", Env
.string, "to", Env
.string, "port", Env
.int)
650 (fn (from
, to
, port
) =>
652 write
"\tRewriteRule\t\"";
654 write
"\"\thttp://localhost:";
655 write (Int.toString port
);
660 val () = Env
.action_four
"expiresByType"
661 ("mime", Env
.string, "base", interval_base
, "num", Env
.int, "inter", interval
)
662 (fn (mime
, base
, num
, inter
) =>
664 write
"\tExpiresByType\t\"";
671 write (Int.toString (~num
)))
673 write (Int.toString num
);
678 val () = Env
.action_two
"proxyPass"
679 ("from", Env
.string, "to", Env
.string)
681 (write
"\tProxyPass\t";
687 val () = Env
.action_two
"proxyPassReverse"
688 ("from", Env
.string, "to", Env
.string)
690 (write
"\tProxyPassReverse\t";
696 val () = Env
.action_one
"proxyPreserveHost"
699 (write
"\tProxyPreserveHost\t";
700 if enable
then write
"On" else write
"Off";
703 val () = Env
.action_three
"rewriteRule"
704 ("from", Env
.string, "to", Env
.string, "flags", Env
.list flag
)
705 (fn (from
, to
, flags
) =>
707 write
"\tRewriteRule\t\"";
714 | flag
::rest
=> (write
" [";
716 app (fn flag
=> (write
",";
721 val () = Env
.action_three
"rewriteCond"
722 ("test", Env
.string, "pattern", Env
.string, "flags", Env
.list cond_flag
)
723 (fn (from
, to
, flags
) =>
725 write
"\tRewriteCond\t\"";
732 | flag
::rest
=> (write
" [";
734 app (fn flag
=> (write
",";
739 val () = Env
.action_one
"rewriteBase"
740 ("prefix", Env
.string)
743 write
"\tRewriteBase\t\"";
747 val () = Env
.action_one
"rewriteLogLevel"
751 write
"\tRewriteLog ";
753 write
"/rewrite.log\n\tRewriteLogLevel ";
754 write (Int.toString level
);
757 val () = Env
.action_two
"alias"
758 ("from", Env
.string, "to", Env
.string)
766 val () = Env
.action_two
"scriptAlias"
767 ("from", Env
.string, "to", Env
.string)
769 (write
"\tScriptAlias\t";
775 val () = Env
.action_two
"errorDocument"
776 ("code", Env
.string, "handler", Env
.string)
777 (fn (code
, handler
) =>
779 val hasSpaces
= CharVector
.exists
Char.isSpace handler
787 write
"\tErrorDocument\t";
796 val () = Env
.action_one
"options"
797 ("options", Env
.list apache_option
)
801 | _
=> (write
"\tOptions";
802 app (fn opt
=> (write
" "; write opt
)) opts
;
805 val () = Env
.action_one
"set_options"
806 ("options", Env
.list apache_option
)
810 | _
=> (write
"\tOptions";
811 app (fn opt
=> (write
" +"; write opt
)) opts
;
814 val () = Env
.action_one
"unset_options"
815 ("options", Env
.list apache_option
)
819 | _
=> (write
"\tOptions";
820 app (fn opt
=> (write
" -"; write opt
)) opts
;
823 val () = Env
.action_one
"cgiExtension"
824 ("extension", Env
.string)
825 (fn ext
=> (write
"\tAddHandler cgi-script ";
829 val () = Env
.action_one
"directoryIndex"
830 ("filenames", Env
.list Env
.string)
832 (write
"\tDirectoryIndex";
833 app (fn opt
=> (write
" "; write opt
)) opts
;
836 val () = Env
.action_one
"serverAliasHost"
839 (write
"\tServerAlias ";
844 val () = Env
.action_one
"serverAlias"
850 val full
= host ^
"." ^ dom
852 write
"\tServerAlias ";
857 (Domain
.currentDomains ())))
859 val () = Env
.action_none
"serverAliasDefault"
863 (write
"\tServerAlias ";
867 (Domain
.currentDomains ())))
869 val authType
= fn (EVar
"basic", _
) => SOME
"basic"
870 |
(EVar
"digest", _
) => SOME
"digest"
871 |
(EVar
"kerberos", _
) => SOME
"kerberos"
874 fun allowAuthType
"kerberos" = !sslEnabled
875 | allowAuthType _
= true
877 val () = Env
.action_one
"authType"
880 if allowAuthType ty
then
881 (write
"\tAuthType ";
886 write
"\tKrbServiceName apache2\n\tKrb5Keytab /etc/keytabs/service/apache\n\tKrbMethodNegotiate on\n\tKrbMethodK5Passwd on\n\tKrbVerifyKDC on\n\tKrbAuthRealms HCOOP.NET\n\tKrbSaveCredentials on\n"
889 print
"WARNING: Skipped Kerberos authType because this isn't an SSL vhost.\n")
891 val () = Env
.action_one
"authName"
894 (write
"\tAuthName \"";
898 val () = Env
.action_one
"authUserFile"
901 (write
"\tAuthUserFile ";
905 val () = Env
.action_one
"authGroupFile"
908 (write
"\tAuthGroupFile ";
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 () = Env
.action_one
"sslCertificateChainFile"
1131 ("ssl_cacert_path", Env
.string)
1134 (write
"\tSSLCertificateChainFile \"";
1138 print
"WARNING: Skipped sslCertificateChainFile because this isn't an SSL vhost.\n")
1140 val () = Domain
.registerResetLocal (fn () =>
1141 ignore (OS
.Process
.system (Config
.rm ^
" -rf " ^ Config
.Apache
.confDir ^
"/*")))
1143 val () = Domain
.registerDescriber (Domain
.considerAll
1144 [Domain
.Extension
{extension
= "vhost",
1145 heading
= fn host
=> "Web vhost " ^ host ^
":"},
1146 Domain
.Extension
{extension
= "vhost_ssl",
1147 heading
= fn host
=> "SSL web vhost " ^ host ^
":"}])
1149 val () = Env
.action_none
"testNoHtaccess"
1150 (fn path
=> write
"\tAllowOverride None\n")
1152 fun writeWaklogUserFile () =
1154 val users
= Acl
.users ()
1155 val outf
= TextIO.openOut Config
.Apache
.waklogUserFile
1157 app (fn user
=> if String.isSuffix
"_admin" user
then
1160 (TextIO.output (outf
, "<Location /~");
1161 TextIO.output (outf
, user
);
1162 TextIO.output (outf
, ">\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
1163 TextIO.output (outf
, user
);
1164 TextIO.output (outf
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
1165 TextIO.output (outf
, user
);
1166 TextIO.output (outf
, "\n</Location>\n\n"))) users
;
1167 TextIO.closeOut outf
1170 val () = Domain
.registerOnUsersChange writeWaklogUserFile