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 defaults
= [("WebPlaces",
148 (TList (TBase
"web_place", dl
), dl
),
149 (fn () => (EList (map webPlaceDefault Config
.Apache
.webNodes_default
), dl
))),
152 (fn () => (EVar
"no_ssl", dl
))),
154 (TBase
"your_user", dl
),
155 (fn () => (EString (Domain
.getUser ()), dl
))),
157 (TBase
"your_group", dl
),
158 (fn () => (EString
"nogroup", dl
))),
160 (TBase
"your_path", dl
),
161 (fn () => (EString (Domain
.homedir () ^
"/" ^ Config
.Apache
.public_html
), dl
))),
164 (fn () => (EString (Domain
.getUser () ^
"@" ^ Config
.defaultDomain
), dl
))),
166 (TBase
"suexec_flag", dl
),
167 (fn () => (EVar
"true", dl
))),
169 (TBase
"php_version", dl
),
170 (fn () => (EVar
"php5", dl
)))]
172 val () = app Defaults
.registerDefault defaults
174 val redirect_code
= fn (EVar
"temp", _
) => SOME
"temp"
175 |
(EVar
"permanent", _
) => SOME
"permanent"
176 |
(EVar
"seeother", _
) => SOME
"seeother"
177 |
(EVar
"redir300", _
) => SOME
"300"
178 |
(EVar
"redir301", _
) => SOME
"301"
179 |
(EVar
"redir302", _
) => SOME
"302"
180 |
(EVar
"redir303", _
) => SOME
"303"
181 |
(EVar
"redir304", _
) => SOME
"304"
182 |
(EVar
"redir305", _
) => SOME
"305"
183 |
(EVar
"redir307", _
) => SOME
"307"
186 val flag
= fn (EVar
"redirect", _
) => SOME
"R"
187 |
(EVar
"forbidden", _
) => SOME
"F"
188 |
(EVar
"gone", _
) => SOME
"G"
189 |
(EVar
"last", _
) => SOME
"L"
190 |
(EVar
"chain", _
) => SOME
"C"
191 |
(EVar
"nosubreq", _
) => SOME
"NS"
192 |
(EVar
"nocase", _
) => SOME
"NC"
193 |
(EVar
"qsappend", _
) => SOME
"QSA"
194 |
(EVar
"noescape", _
) => SOME
"NE"
195 |
(EVar
"passthrough", _
) => SOME
"PT"
196 |
(EApp ((EVar
"mimeType", _
), e
), _
) =>
197 Option
.map (fn s
=> "T=" ^ s
) (Env
.string e
)
198 |
(EApp ((EVar
"redirectWith", _
), e
), _
) =>
199 Option
.map (fn s
=> "R=" ^ s
) (redirect_code e
)
200 |
(EApp ((EVar
"skip", _
), e
), _
) =>
201 Option
.map (fn n
=> "S=" ^
Int.toString n
) (Env
.int e
)
202 |
(EApp ((EApp ((EVar
"env", _
), e1
), _
), e2
), _
) =>
203 (case Env
.string e1
of
205 | SOME s1
=> Option
.map (fn s2
=> "E=" ^ s1 ^
":" ^ s2
)
210 val cond_flag
= fn (EVar
"cond_nocase", _
) => SOME
"NC"
211 |
(EVar
"ornext", _
) => SOME
"OR"
214 val apache_option
= fn (EVar
"execCGI", _
) => SOME
"ExecCGI"
215 |
(EVar
"includesNOEXEC", _
) => SOME
"IncludesNOEXEC"
216 |
(EVar
"indexes", _
) => SOME
"Indexes"
217 |
(EVar
"followSymLinks", _
) => SOME
"FollowSymLinks"
218 |
(EVar
"multiViews", _
) => SOME
"MultiViews"
221 val autoindex_width
= fn (EVar
"autofit", _
) => SOME
"*"
222 |
(EApp ((EVar
"characters", _
), n
), _
) =>
223 Option
.map
Int.toString (Env
.int n
)
226 val autoindex_option
= fn (EApp ((EVar
"descriptionWidth", _
), w
), _
) =>
227 Option
.map (fn w
=> ("DescriptionWidth", SOME w
))
229 |
(EVar
"fancyIndexing", _
) => SOME ("FancyIndexing", NONE
)
230 |
(EVar
"foldersFirst", _
) => SOME ("FoldersFirst", NONE
)
231 |
(EVar
"htmlTable", _
) => SOME ("HTMLTable", NONE
)
232 |
(EVar
"iconsAreLinks", _
) => SOME ("IconsAreLinks", NONE
)
233 |
(EApp ((EVar
"iconHeight", _
), n
), _
) =>
234 Option
.map (fn w
=> ("IconHeight", SOME (Int.toString w
)))
236 |
(EApp ((EVar
"iconWidth", _
), n
), _
) =>
237 Option
.map (fn w
=> ("IconWidth", SOME (Int.toString w
)))
239 |
(EVar
"ignoreCase", _
) => SOME ("IgnoreCase", NONE
)
240 |
(EVar
"ignoreClient", _
) => SOME ("IgnoreClient", NONE
)
241 |
(EApp ((EVar
"nameWidth", _
), w
), _
) =>
242 Option
.map (fn w
=> ("NameWidth", SOME w
))
244 |
(EVar
"scanHtmlTitles", _
) => SOME ("ScanHTMLTitles", NONE
)
245 |
(EVar
"suppressColumnSorting", _
) => SOME ("SuppressColumnSorting", NONE
)
246 |
(EVar
"suppressDescription", _
) => SOME ("SuppressDescription", NONE
)
247 |
(EVar
"suppressHtmlPreamble", _
) => SOME ("SuppressHTMLPreamble", NONE
)
248 |
(EVar
"suppressIcon", _
) => SOME ("SuppressIcon", NONE
)
249 |
(EVar
"suppressLastModified", _
) => SOME ("SuppressLastModified", NONE
)
250 |
(EVar
"suppressRules", _
) => SOME ("SuppressRules", NONE
)
251 |
(EVar
"suppressSize", _
) => SOME ("SuppressSize", NONE
)
252 |
(EVar
"trackModified", _
) => SOME ("TrackModified", NONE
)
253 |
(EVar
"versionSort", _
) => SOME ("VersionSort", NONE
)
254 |
(EVar
"xhtml", _
) => SOME ("XHTML", NONE
)
258 val interval_base
= fn (EVar
"access", _
) => SOME
"access"
259 |
(EVar
"modification", _
) => SOME
"modification"
262 val interval
= fn (EVar
"years", _
) => SOME
"years"
263 |
(EVar
"months", _
) => SOME
"months"
264 |
(EVar
"weeks", _
) => SOME
"weeks"
265 |
(EVar
"days", _
) => SOME
"days"
266 |
(EVar
"hours", _
) => SOME
"hours"
267 |
(EVar
"minutes", _
) => SOME
"minutes"
268 |
(EVar
"seconds", _
) => SOME
"seconds"
271 val vhostsChanged
= ref
false
272 val logDeleted
= ref
false
273 val delayedLogMoves
= ref (fn () => ())
275 val () = Slave
.registerPreHandler
276 (fn () => (vhostsChanged
:= false;
278 delayedLogMoves
:= (fn () => print
"Executing delayed log moves/deletes.\n")))
280 fun findVhostUser fname
=
282 val inf
= TextIO.openIn fname
285 case TextIO.inputLine inf
of
288 if String.isPrefix
"# Owner: " line
then
289 case String.tokens
Char.isSpace line
of
290 [_
, _
, user
] => SOME user
296 before TextIO.closeIn inf
299 val webNodes_full
= Config
.Apache
.webNodes_all @ Config
.Apache
.webNodes_admin
301 fun isVersion1 node
=
302 List.exists (fn (n
, {version
= ConfigTypes
.APACHE_1_3
, ...}) => n
= node
303 | _
=> false) webNodes_full
305 fun imVersion1 () = isVersion1 (Slave
.hostname ())
308 List.exists (fn (n
, {auth
= ConfigTypes
.MOD_WAKLOG
, ...}) => n
= node
309 | _
=> false) webNodes_full
311 fun down () = if imVersion1 () then Config
.Apache
.down1
else Config
.Apache
.down
312 fun undown () = if imVersion1 () then Config
.Apache
.undown1
else Config
.Apache
.undown
313 fun reload () = if imVersion1 () then Config
.Apache
.reload1
else Config
.Apache
.reload
314 fun fixperms () = if imVersion1 () then Config
.Apache
.fixperms1
else Config
.Apache
.fixperms
316 fun logDir
{user
, node
, vhostId
} =
317 String.concat
[Config
.Apache
.logDirOf (isVersion1 node
) user
,
323 fun realLogDir
{user
, node
, vhostId
} =
324 String.concat
[Config
.Apache
.realLogDirOf user
,
330 val () = Slave
.registerFileHandler (fn fs
=>
332 val spl
= OS
.Path
.splitDirFile (#file fs
)
334 if String.isSuffix
".vhost" (#file spl
)
335 orelse String.isSuffix
".vhost_ssl" (#file spl
) then let
336 val realVhostFile
= OS
.Path
.joinDirFile
337 {dir
= Config
.Apache
.confDir
,
340 val user
= findVhostUser (#file fs
)
341 val oldUser
= case #action fs
of
342 Slave
.Delete
false => user
343 | _
=> findVhostUser realVhostFile
345 if (oldUser
= NONE
andalso #action fs
<> Slave
.Add
)
346 orelse (user
= NONE
andalso not (Slave
.isDelete (#action fs
))) then
347 print ("Can't find user in " ^ #file fs ^
" or " ^ realVhostFile ^
"! Taking no action.\n")
350 val vhostId
= if OS
.Path
.ext (#file spl
) = SOME
"vhost_ssl" then
351 OS
.Path
.base (#file spl
) ^
".ssl"
353 OS
.Path
.base (#file spl
)
355 fun realLogDir user
=
356 logDir
{user
= valOf user
,
357 node
= Slave
.hostname (),
362 {dir
= Config
.Apache
.backupLogDirOf
363 (isVersion1 (Slave
.hostname ())),
366 vhostsChanged
:= true;
370 val ldir
= realLogDir oldUser
371 val dlm
= !delayedLogMoves
376 ((*ignore (OS
.Process
.system (down ()));*)
377 ignore (OS
.Process
.system (fixperms ()));
379 ignore (OS
.Process
.system (Config
.rm
382 delayedLogMoves
:= (fn () => (dlm ();
383 Slave
.moveDirCreate
{from
= ldir
,
384 to
= backupLogs ()}))
388 val rld
= realLogDir user
390 ignore (OS
.Process
.system (Config
.cp
395 if Posix
.FileSys
.access (rld
, []) then
398 Slave
.moveDirCreate
{from
= backupLogs (),
403 (ignore (OS
.Process
.system (Config
.cp
408 if user
<> oldUser
then
410 val old
= realLogDir oldUser
411 val rld
= realLogDir user
413 val dlm
= !delayedLogMoves
418 ((*ignore (OS
.Process
.system (down ()));*)
420 delayedLogMoves
:= (fn () => (dlm ();
421 ignore (OS
.Process
.system (Config
.rm
423 ^ realLogDir oldUser
))));
424 if Posix
.FileSys
.access (rld
, []) then
437 val () = Slave
.registerPostHandler
439 (if !vhostsChanged
then
440 (Slave
.shellF ([reload ()],
441 fn cl
=> "Error reloading Apache with " ^ cl
);
442 if !logDeleted
then !delayedLogMoves () else ())
446 val vhostFiles
: (string * TextIO.outstream
) list ref
= ref
[]
447 fun write
' s
= app (fn (node
, file
) => TextIO.output (file
, s node
)) (!vhostFiles
)
448 fun write s
= app (fn (_
, file
) => TextIO.output (file
, s
)) (!vhostFiles
)
450 val rewriteEnabled
= ref
false
451 val localRewriteEnabled
= ref
false
452 val expiresEnabled
= ref
false
453 val localExpiresEnabled
= ref
false
454 val currentVhost
= ref
""
455 val currentVhostId
= ref
""
456 val sslEnabled
= ref
false
458 val pre
= ref (fn _
: {user
: string, nodes
: string list
, id
: string, hostname
: string} => ())
463 pre
:= (fn x
=> (old x
; f x
))
466 val post
= ref (fn () => ())
471 post
:= (fn () => (old (); f ()))
475 fun doPost () = !post ()
477 val aliaser
= ref (fn _
: string => ())
478 fun registerAliaser f
=
482 aliaser
:= (fn x
=> (old x
; f x
))
485 fun vhostPost () = (!post ();
486 write
"</VirtualHost>\n";
487 app (TextIO.closeOut
o #
2) (!vhostFiles
))
489 val php_version
= fn (EVar
"php5", _
) => SOME
5
492 fun vhostBody (env
, makeFullHost
) =
494 val places
= Env
.env (Env
.list webPlace
) (env
, "WebPlaces")
496 val ssl
= Env
.env
ssl (env
, "SSL")
497 val user
= Env
.env Env
.string (env
, "User")
498 val group
= Env
.env Env
.string (env
, "Group")
499 val docroot
= Env
.env Env
.string (env
, "DocumentRoot")
500 val sadmin
= Env
.env Env
.string (env
, "ServerAdmin")
501 val suexec
= Env
.env Env
.bool (env
, "SuExec")
502 val php
= Env
.env
php_version (env
, "PhpVersion")
504 val fullHost
= makeFullHost (Domain
.currentDomain ())
505 val vhostId
= fullHost ^
(if Option
.isSome ssl
then ".ssl" else "")
506 val confFile
= fullHost ^
(if Option
.isSome ssl
then ".vhost_ssl" else ".vhost")
508 currentVhost
:= fullHost
;
509 currentVhostId
:= vhostId
;
510 sslEnabled
:= Option
.isSome ssl
;
512 rewriteEnabled
:= false;
513 localRewriteEnabled
:= false;
514 expiresEnabled
:= false;
515 localExpiresEnabled
:= false;
516 vhostFiles
:= map (fn (node
, ip
) =>
518 val file
= Domain
.domainFile
{node
= node
,
521 val ld
= logDir
{user
= user
, node
= node
, vhostId
= vhostId
}
523 TextIO.output (file
, "# Owner: ");
524 TextIO.output (file
, user
);
525 TextIO.output (file
, "\n<VirtualHost ");
526 TextIO.output (file
, ip
);
527 TextIO.output (file
, ":");
528 TextIO.output (file
, case ssl
of
531 TextIO.output (file
, ">\n");
532 TextIO.output (file
, "\tErrorLog ");
533 TextIO.output (file
, ld
);
534 TextIO.output (file
, "/error.log\n\tCustomLog ");
535 TextIO.output (file
, ld
);
536 TextIO.output (file
, "/access.log combined\n");
537 TextIO.output (file
, "\tServerName ");
538 TextIO.output (file
, fullHost
);
540 (fn dom
=> (TextIO.output (file
, "\n\tServerAlias ");
541 TextIO.output (file
, makeFullHost dom
)))
542 (Domain
.currentAliasDomains ());
545 if isVersion1 node
then
546 (TextIO.output (file
, "\n\tUser ");
547 TextIO.output (file
, user
);
548 TextIO.output (file
, "\n\tGroup ");
549 TextIO.output (file
, group
))
551 (TextIO.output (file
, "\n\tSuexecUserGroup ");
552 TextIO.output (file
, user
);
553 TextIO.output (file
, " ");
554 TextIO.output (file
, group
);
555 TextIO.output (file
, "\n\tsuPHP_UserGroup ");
556 TextIO.output (file
, user
);
557 TextIO.output (file
, " ");
558 TextIO.output (file
, group
))
562 if isWaklog node
then
563 (TextIO.output (file
, "\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
564 TextIO.output (file
, user
);
565 TextIO.output (file
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
566 TextIO.output (file
, user
))
570 TextIO.output (file
, "\n\tDAVLockDB /var/lock/apache2/dav/");
571 TextIO.output (file
, user
);
572 TextIO.output (file
, "/DAVLock");
574 if php
<> Config
.Apache
.defaultPhpVersion
then
575 (TextIO.output (file
, "\n\tAddHandler x-httpd-php");
576 TextIO.output (file
, Int.toString php
);
577 TextIO.output (file
, " .php .phtml"))
584 write
"\n\tDocumentRoot ";
586 write
"\n\tServerAdmin ";
590 (write
"\n\tSSLEngine on\n\tSSLCertificateFile ";
594 !pre
{user
= user
, nodes
= map #
1 places
, id
= vhostId
, hostname
= fullHost
};
595 app (fn dom
=> !aliaser (makeFullHost dom
)) (Domain
.currentAliasDomains ())
598 val () = Env
.containerV_one
"vhost"
600 (fn (env
, host
) => vhostBody (env
, fn dom
=> host ^
"." ^ dom
),
603 val () = Env
.containerV_none
"vhostDefault"
604 (fn env
=> vhostBody (env
, fn dom
=> dom
),
607 val inLocal
= ref
false
609 val () = Env
.container_one
"location"
610 ("prefix", Env
.string)
612 (write
"\t<Location ";
616 fn () => (write
"\t</Location>\n";
618 localRewriteEnabled
:= false;
619 localExpiresEnabled
:= false))
621 val () = Env
.container_one
"directory"
622 ("directory", Env
.string)
624 (write
"\t<Directory ";
628 fn () => (write
"\t</Directory>\n";
630 localRewriteEnabled
:= false;
631 localExpiresEnabled
:= false))
633 val () = Env
.container_one
"filesMatch"
634 ("regexp", Env
.string)
636 (write
"\t<FilesMatch \"";
639 fn () => (write
"\t</FilesMatch>\n";
640 localRewriteEnabled
:= false;
641 localExpiresEnabled
:= false))
643 fun checkRewrite () =
645 if !localRewriteEnabled
then
648 (write
"\tRewriteEngine on\n";
649 localRewriteEnabled
:= true)
650 else if !rewriteEnabled
then
653 (write
"\tRewriteEngine on\n";
654 rewriteEnabled
:= true)
656 fun checkExpires () =
658 if !localExpiresEnabled
then
661 (write
"\tExpiresActive on\n";
662 localExpiresEnabled
:= true)
663 else if !expiresEnabled
then
666 (write
"\tExpiresActive on\n";
667 expiresEnabled
:= true)
669 val () = Env
.action_three
"localProxyRewrite"
670 ("from", Env
.string, "to", Env
.string, "port", Env
.int)
671 (fn (from
, to
, port
) =>
673 write
"\tRewriteRule\t\"";
675 write
"\"\thttp://localhost:";
676 write (Int.toString port
);
681 val () = Env
.action_four
"expiresByType"
682 ("mime", Env
.string, "base", interval_base
, "num", Env
.int, "inter", interval
)
683 (fn (mime
, base
, num
, inter
) =>
685 write
"\tExpiresByType\t\"";
692 write (Int.toString (~num
)))
694 write (Int.toString num
);
699 val () = Env
.action_two
"proxyPass"
700 ("from", Env
.string, "to", Env
.string)
702 (write
"\tProxyPass\t";
708 val () = Env
.action_two
"proxyPassReverse"
709 ("from", Env
.string, "to", Env
.string)
711 (write
"\tProxyPassReverse\t";
717 val () = Env
.action_three
"rewriteRule"
718 ("from", Env
.string, "to", Env
.string, "flags", Env
.list flag
)
719 (fn (from
, to
, flags
) =>
721 write
"\tRewriteRule\t\"";
728 | flag
::rest
=> (write
" [";
730 app (fn flag
=> (write
",";
735 val () = Env
.action_three
"rewriteCond"
736 ("test", Env
.string, "pattern", Env
.string, "flags", Env
.list cond_flag
)
737 (fn (from
, to
, flags
) =>
739 write
"\tRewriteCond\t\"";
746 | flag
::rest
=> (write
" [";
748 app (fn flag
=> (write
",";
753 val () = Env
.action_one
"rewriteBase"
754 ("prefix", Env
.string)
757 write
"\tRewriteBase\t\"";
761 val () = Env
.action_one
"rewriteLogLevel"
765 write
"\tRewriteLog ";
767 write
"/rewrite.log\n\tRewriteLogLevel ";
768 write (Int.toString level
);
771 val () = Env
.action_two
"alias"
772 ("from", Env
.string, "to", Env
.string)
780 val () = Env
.action_two
"scriptAlias"
781 ("from", Env
.string, "to", Env
.string)
783 (write
"\tScriptAlias\t";
789 val () = Env
.action_two
"errorDocument"
790 ("code", Env
.string, "handler", Env
.string)
791 (fn (code
, handler
) =>
793 val hasSpaces
= CharVector
.exists
Char.isSpace handler
801 write
"\tErrorDocument\t";
810 val () = Env
.action_one
"options"
811 ("options", Env
.list apache_option
)
815 | _
=> (write
"\tOptions";
816 app (fn opt
=> (write
" "; write opt
)) opts
;
819 val () = Env
.action_one
"set_options"
820 ("options", Env
.list apache_option
)
824 | _
=> (write
"\tOptions";
825 app (fn opt
=> (write
" +"; write opt
)) opts
;
828 val () = Env
.action_one
"unset_options"
829 ("options", Env
.list apache_option
)
833 | _
=> (write
"\tOptions";
834 app (fn opt
=> (write
" -"; write opt
)) opts
;
837 val () = Env
.action_one
"cgiExtension"
838 ("extension", Env
.string)
839 (fn ext
=> (write
"\tAddHandler cgi-script ";
843 val () = Env
.action_one
"directoryIndex"
844 ("filenames", Env
.list Env
.string)
846 (write
"\tDirectoryIndex";
847 app (fn opt
=> (write
" "; write opt
)) opts
;
850 val () = Env
.action_one
"serverAliasHost"
853 (write
"\tServerAlias ";
858 val () = Env
.action_one
"serverAlias"
864 val full
= host ^
"." ^ dom
866 write
"\tServerAlias ";
871 (Domain
.currentDomains ())))
873 val () = Env
.action_none
"serverAliasDefault"
877 (write
"\tServerAlias ";
881 (Domain
.currentDomains ())))
883 val authType
= fn (EVar
"basic", _
) => SOME
"basic"
884 |
(EVar
"digest", _
) => SOME
"digest"
885 |
(EVar
"kerberos", _
) => SOME
"kerberos"
888 fun allowAuthType
"kerberos" = !sslEnabled
889 | allowAuthType _
= true
891 val () = Env
.action_one
"authType"
894 if allowAuthType ty
then
895 (write
"\tAuthType ";
900 write
"\tKrbMethodNegotiate off\n\tKrbMethodK5Passwd on\n\tKrbVerifyKDC off\n\tKrbAuthRealms HCOOP.NET\n\tKrbSaveCredentials on\n"
903 print
"WARNING: Skipped Kerberos authType because this isn't an SSL vhost.\n")
905 val () = Env
.action_one
"authName"
908 (write
"\tAuthName \"";
912 val () = Env
.action_one
"authUserFile"
915 (write
"\tAuthUserFile ";
919 val () = Env
.action_one
"authGroupFile"
922 (write
"\tAuthGroupFile ";
926 val () = Env
.action_none
"requireValidUser"
927 (fn () => write
"\tRequire valid-user\n")
929 val () = Env
.action_one
"requireUser"
930 ("users", Env
.list Env
.string)
934 | _
=> (write
"\tRequire user";
935 app (fn name
=> (write
" "; write name
)) names
;
938 val () = Env
.action_one
"requireGroup"
939 ("groups", Env
.list Env
.string)
943 | _
=> (write
"\tRequire group";
944 app (fn name
=> (write
" "; write name
)) names
;
947 val () = Env
.action_none
"orderAllowDeny"
948 (fn () => write
"\tOrder allow,deny\n")
950 val () = Env
.action_none
"orderDenyAllow"
951 (fn () => write
"\tOrder deny,allow\n")
953 val () = Env
.action_none
"allowFromAll"
954 (fn () => write
"\tAllow from all\n")
956 val () = Env
.action_one
"allowFrom"
957 ("entries", Env
.list Env
.string)
961 | _
=> (write
"\tAllow from";
962 app (fn name
=> (write
" "; write name
)) names
;
965 val () = Env
.action_none
"denyFromAll"
966 (fn () => write
"\tDeny from all\n")
968 val () = Env
.action_one
"denyFrom"
969 ("entries", Env
.list Env
.string)
973 | _
=> (write
"\tDeny from";
974 app (fn name
=> (write
" "; write name
)) names
;
977 val () = Env
.action_none
"satisfyAll"
978 (fn () => write
"\tSatisfy all\n")
980 val () = Env
.action_none
"satisfyAny"
981 (fn () => write
"\tSatisfy any\n")
983 val () = Env
.action_one
"forceType"
985 (fn ty
=> (write
"\tForceType ";
989 val () = Env
.action_none
"forceTypeOff"
990 (fn () => write
"\tForceType None\n")
992 val () = Env
.action_two
"action"
993 ("what", Env
.string, "how", Env
.string)
994 (fn (what
, how
) => (write
"\tAction ";
1000 val () = Env
.action_one
"addDefaultCharset"
1001 ("charset", Env
.string)
1002 (fn ty
=> (write
"\tAddDefaultCharset ";
1006 (*val () = Env
.action_one
"davSvn"
1007 ("path", Env
.string)
1008 (fn path
=> (write
"\tDAV svn\n\tSVNPath ";
1012 val () = Env
.action_one
"authzSvnAccessFile"
1013 ("path", Env
.string)
1014 (fn path
=> (write
"\tAuthzSVNAccessFile ";
1018 val () = Env
.action_none
"davFilesystem"
1019 (fn path
=> write
"\tDAV filesystem\n")
1021 val () = Env
.action_two
"addDescription"
1022 ("description", Env
.string, "patterns", Env
.list Env
.string)
1026 | _
=> (write
"\tAddDescription \"";
1027 write (String.toString desc
);
1029 app (fn pat
=> (write
" "; write pat
)) pats
;
1032 val () = Env
.action_two
"addIcon"
1033 ("icon", Env
.string, "patterns", Env
.list Env
.string)
1037 | _
=> (write
"\tAddIcon \"";
1040 app (fn pat
=> (write
" "; write pat
)) pats
;
1043 val () = Env
.action_one
"indexOptions"
1044 ("options", Env
.list autoindex_option
)
1048 | _
=> (write
"\tIndexOptions";
1049 app (fn (opt
, arg
) =>
1052 Option
.app (fn arg
=>
1053 (write
"="; write arg
)) arg
)) opts
;
1056 val () = Env
.action_one
"indexIgnore"
1057 ("patterns", Env
.list Env
.string)
1061 | _
=> (write
"\tIndexIgnore";
1062 app (fn pat
=> (write
" "; write pat
)) pats
;
1065 val () = Env
.action_one
"set_indexOptions"
1066 ("options", Env
.list autoindex_option
)
1070 | _
=> (write
"\tIndexOptions";
1071 app (fn (opt
, arg
) =>
1074 Option
.app (fn arg
=>
1075 (write
"="; write arg
)) arg
)) opts
;
1078 val () = Env
.action_one
"unset_indexOptions"
1079 ("options", Env
.list autoindex_option
)
1083 | _
=> (write
"\tIndexOptions";
1089 val () = Env
.action_one
"headerName"
1090 ("name", Env
.string)
1091 (fn name
=> (write
"\tHeaderName ";
1095 val () = Env
.action_one
"readmeName"
1096 ("name", Env
.string)
1097 (fn name
=> (write
"\tReadmeName ";
1101 val () = Env
.action_two
"setEnv"
1102 ("key", Env
.string, "value", Env
.string)
1103 (fn (key
, value
) => (write
"\tSetEnv \"";
1106 write (String.translate (fn #
"\"" => "\\\""
1107 | ch
=> str ch
) value
);
1110 val () = Env
.action_one
"diskCache"
1111 ("path", Env
.string)
1112 (fn path
=> (write
"\tCacheEnable disk \"";
1116 val () = Env
.action_one
"phpVersion"
1117 ("version", php_version
)
1118 (fn version
=> (write
"\tAddHandler x-httpd-php";
1119 write (Int.toString version
);
1120 write
" .php .phtml\n"))
1122 val () = Env
.action_two
"addType"
1123 ("mime type", Env
.string, "extension", Env
.string)
1124 (fn (mt
, ext
) => (write
"\tAddType ";
1130 val filter
= fn (EVar
"includes", _
) => SOME
"INCLUDES"
1131 |
(EVar
"deflate", _
) => SOME
"DEFLATE"
1134 val () = Env
.action_two
"addOutputFilter"
1135 ("filters", Env
.list filter
, "extensions", Env
.list Env
.string)
1136 (fn (f
:: fs
, exts
as (_
:: _
)) =>
1137 (write
"\tAddOutputFilter ";
1139 app (fn f
=> (write
";"; write f
)) fs
;
1140 app (fn ext
=> (write
" "; write ext
)) exts
;
1144 val () = Env
.action_one
"sslCertificateChainFile"
1145 ("ssl_cacert_path", Env
.string)
1148 (write
"\tSSLCertificateChainFile \"";
1152 print
"WARNING: Skipped sslCertificateChainFile because this isn't an SSL vhost.\n")
1154 val () = Domain
.registerResetLocal (fn () =>
1155 ignore (OS
.Process
.system (Config
.rm ^
" -rf /var/domtool/vhosts/*")))
1157 val () = Domain
.registerDescriber (Domain
.considerAll
1158 [Domain
.Extension
{extension
= "vhost",
1159 heading
= fn host
=> "Web vhost " ^ host ^
":"},
1160 Domain
.Extension
{extension
= "vhost_ssl",
1161 heading
= fn host
=> "SSL web vhost " ^ host ^
":"}])
1163 val () = Env
.action_none
"testNoHtaccess"
1164 (fn path
=> write
"\tAllowOverride None\n")
1166 fun writeWaklogUserFile () =
1168 val users
= Acl
.users ()
1169 val outf
= TextIO.openOut Config
.Apache
.waklogUserFile
1171 app (fn user
=> if String.isSuffix
"_admin" user
then
1174 (TextIO.output (outf
, "<Location /~");
1175 TextIO.output (outf
, user
);
1176 TextIO.output (outf
, ">\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
1177 TextIO.output (outf
, user
);
1178 TextIO.output (outf
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
1179 TextIO.output (outf
, user
);
1180 TextIO.output (outf
, "\n</Location>\n\n"))) users
;
1181 TextIO.closeOut outf
1184 val () = Domain
.registerOnUsersChange writeWaklogUserFile