1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006-2009, Adam Chlipala
4 * This program is free software
; you can redistribute it
and/or
5 * modify it under the terms
of the GNU General Public License
6 * as published by the Free Software Foundation
; either version
2
7 * of the License
, or (at your option
) any later version
.
9 * This program is distributed
in the hope that it will be useful
,
10 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
12 * GNU General Public License for more details
.
14 * You should have received a copy
of the GNU General Public License
15 * along
with this program
; if not
, write to the Free Software
16 * Foundation
, Inc
., 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA
.
19 (* Apache HTTPD handling
*)
21 structure Apache
:> APACHE
= struct
25 val dl
= ErrorMsg
.dummyLoc
28 List.exists (fn (x
, _
) => x
= node
) Config
.Apache
.webNodes_all
29 orelse (Domain
.hasPriv
"www"
30 andalso List.exists (fn (x
, _
) => x
= node
) Config
.Apache
.webNodes_admin
)
32 val _
= Env
.type_one
"web_node"
36 val _
= Env
.registerFunction ("web_node_to_node",
40 fun webPlace (EApp ((EVar
"web_place_default", _
), (EString node
, _
)), _
) =
41 SOME (node
, Domain
.nodeIp node
)
42 |
webPlace (EApp ((EApp ((EVar
"web_place", _
), (EString node
, _
)), _
), (EString ip
, _
)), _
) =
46 fun webPlaceDefault node
= (EApp ((EVar
"web_place_default", dl
), (EString node
, dl
)), dl
)
48 val _
= Env
.registerFunction ("web_place_to_web_node",
49 fn [e
] => Option
.map (fn (node
, _
) => (EString node
, dl
)) (webPlace e
)
52 val _
= Env
.registerFunction ("web_place_to_node",
53 fn [e
] => Option
.map (fn (node
, _
) => (EString node
, dl
)) (webPlace e
)
56 val _
= Env
.registerFunction ("web_place_to_ip",
57 fn [e
] => Option
.map (fn (_
, ip
) => (EString ip
, dl
)) (webPlace e
)
60 val _
= Env
.type_one
"proxy_port"
64 val _
= Env
.type_one
"proxy_target"
68 fun default () = List.exists (fn s
' => s
= s
') Config
.Apache
.proxyTargets
70 case String.fields (fn ch
=> ch
= #
":") s
of
71 "http" :: host
:: rest
=>
73 val rest
= String.concatWith
":" rest
75 if List.exists (fn h
' => host
= h
') (map (fn h
=> String.concat
["//", h
]) Config
.Apache
.proxyHosts
)
77 CharVector
.all (fn ch
=> Char.isPrint ch
andalso not (Char.isSpace ch
)
78 andalso ch
<> #
"\"" andalso ch
<> #
"'") rest
79 andalso case String.fields (fn ch
=> ch
= #
"/") rest
of
81 (case Int.fromString port
of
83 | SOME n
=> n
> 1024 orelse default ())
91 val _
= Env
.type_one
"rewrite_arg"
93 (CharVector
.all
Char.isAlphaNum
)
95 val _
= Env
.type_one
"suexec_flag"
97 (fn b
=> b
orelse Domain
.hasPriv
"www")
99 val _
= Env
.type_one
"regexp"
103 fun validLocation s
=
104 size s
> 0 andalso size s
< 1000 andalso CharVector
.all
105 (fn ch
=> Char.isAlphaNum ch
112 val _
= Env
.type_one
"location"
116 fun validCert s
= Acl
.query
{user
= Domain
.getUser (),
120 val _
= Env
.type_one
"ssl_cert_path"
124 fun ssl e
= case e
of
125 (EVar
"no_ssl", _
) => SOME NONE
126 |
(EApp ((EVar
"use_cert", _
), s
), _
) => Option
.map
SOME (Env
.string s
)
129 fun validExtension s
=
132 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"_") s
134 val _
= Env
.type_one
"file_extension"
138 val defaults
= [("WebPlaces",
139 (TList (TBase
"web_place", dl
), dl
),
140 (fn () => (EList (map webPlaceDefault Config
.Apache
.webNodes_default
), dl
))),
143 (fn () => (EVar
"no_ssl", dl
))),
145 (TBase
"your_user", dl
),
146 (fn () => (EString (Domain
.getUser ()), dl
))),
148 (TBase
"your_group", dl
),
149 (fn () => (EString
"nogroup", dl
))),
151 (TBase
"your_path", dl
),
152 (fn () => (EString (Domain
.homedir () ^
"/" ^ Config
.Apache
.public_html
), dl
))),
155 (fn () => (EString (Domain
.getUser () ^
"@" ^ Config
.defaultDomain
), dl
))),
157 (TBase
"suexec_flag", dl
),
158 (fn () => (EVar
"true", dl
))),
160 (TBase
"php_version", dl
),
161 (fn () => (EVar
"php4", dl
)))]
163 val () = app Defaults
.registerDefault defaults
165 val redirect_code
= fn (EVar
"temp", _
) => SOME
"temp"
166 |
(EVar
"permanent", _
) => SOME
"permanent"
167 |
(EVar
"seeother", _
) => SOME
"seeother"
168 |
(EVar
"redir300", _
) => SOME
"300"
169 |
(EVar
"redir301", _
) => SOME
"301"
170 |
(EVar
"redir302", _
) => SOME
"302"
171 |
(EVar
"redir303", _
) => SOME
"303"
172 |
(EVar
"redir304", _
) => SOME
"304"
173 |
(EVar
"redir305", _
) => SOME
"305"
174 |
(EVar
"redir307", _
) => SOME
"307"
177 val flag
= fn (EVar
"redirect", _
) => SOME
"R"
178 |
(EVar
"forbidden", _
) => SOME
"F"
179 |
(EVar
"gone", _
) => SOME
"G"
180 |
(EVar
"last", _
) => SOME
"L"
181 |
(EVar
"chain", _
) => SOME
"C"
182 |
(EVar
"nosubreq", _
) => SOME
"NS"
183 |
(EVar
"nocase", _
) => SOME
"NC"
184 |
(EVar
"qsappend", _
) => SOME
"QSA"
185 |
(EVar
"noescape", _
) => SOME
"NE"
186 |
(EVar
"passthrough", _
) => SOME
"PT"
187 |
(EApp ((EVar
"mimeType", _
), e
), _
) =>
188 Option
.map (fn s
=> "T=" ^ s
) (Env
.string e
)
189 |
(EApp ((EVar
"redirectWith", _
), e
), _
) =>
190 Option
.map (fn s
=> "R=" ^ s
) (redirect_code e
)
191 |
(EApp ((EVar
"skip", _
), e
), _
) =>
192 Option
.map (fn n
=> "S=" ^
Int.toString n
) (Env
.int e
)
193 |
(EApp ((EApp ((EVar
"env", _
), e1
), _
), e2
), _
) =>
194 (case Env
.string e1
of
196 | SOME s1
=> Option
.map (fn s2
=> "E=" ^ s1 ^
":" ^ s2
)
201 val cond_flag
= fn (EVar
"cond_nocase", _
) => SOME
"NC"
202 |
(EVar
"ornext", _
) => SOME
"OR"
205 val apache_option
= fn (EVar
"execCGI", _
) => SOME
"ExecCGI"
206 |
(EVar
"includesNOEXEC", _
) => SOME
"IncludesNOEXEC"
207 |
(EVar
"indexes", _
) => SOME
"Indexes"
208 |
(EVar
"followSymLinks", _
) => SOME
"FollowSymLinks"
211 val autoindex_width
= fn (EVar
"autofit", _
) => SOME
"*"
212 |
(EApp ((EVar
"characters", _
), n
), _
) =>
213 Option
.map
Int.toString (Env
.int n
)
216 val autoindex_option
= fn (EApp ((EVar
"descriptionWidth", _
), w
), _
) =>
217 Option
.map (fn w
=> ("DescriptionWidth", SOME w
))
219 |
(EVar
"fancyIndexing", _
) => SOME ("FancyIndexing", NONE
)
220 |
(EVar
"foldersFirst", _
) => SOME ("FoldersFirst", NONE
)
221 |
(EVar
"htmlTable", _
) => SOME ("HTMLTable", NONE
)
222 |
(EVar
"iconsAreLinks", _
) => SOME ("IconsAreLinks", NONE
)
223 |
(EApp ((EVar
"iconHeight", _
), n
), _
) =>
224 Option
.map (fn w
=> ("IconHeight", SOME (Int.toString w
)))
226 |
(EApp ((EVar
"iconWidth", _
), n
), _
) =>
227 Option
.map (fn w
=> ("IconWidth", SOME (Int.toString w
)))
229 |
(EVar
"ignoreCase", _
) => SOME ("IgnoreCase", NONE
)
230 |
(EVar
"ignoreClient", _
) => SOME ("IgnoreClient", NONE
)
231 |
(EApp ((EVar
"nameWidth", _
), w
), _
) =>
232 Option
.map (fn w
=> ("NameWidth", SOME w
))
234 |
(EVar
"scanHtmlTitles", _
) => SOME ("ScanHTMLTitles", NONE
)
235 |
(EVar
"suppressColumnSorting", _
) => SOME ("SuppressColumnSorting", NONE
)
236 |
(EVar
"suppressDescription", _
) => SOME ("SuppressDescription", NONE
)
237 |
(EVar
"suppressHtmlPreamble", _
) => SOME ("SuppressHTMLPreamble", NONE
)
238 |
(EVar
"suppressIcon", _
) => SOME ("SuppressIcon", NONE
)
239 |
(EVar
"suppressLastModified", _
) => SOME ("SuppressLastModified", NONE
)
240 |
(EVar
"suppressRules", _
) => SOME ("SuppressRules", NONE
)
241 |
(EVar
"suppressSize", _
) => SOME ("SuppressSize", NONE
)
242 |
(EVar
"trackModified", _
) => SOME ("TrackModified", NONE
)
243 |
(EVar
"versionSort", _
) => SOME ("VersionSort", NONE
)
244 |
(EVar
"xhtml", _
) => SOME ("XHTML", NONE
)
248 val interval_base
= fn (EVar
"access", _
) => SOME
"access"
249 |
(EVar
"modification", _
) => SOME
"modification"
252 val interval
= fn (EVar
"years", _
) => SOME
"years"
253 |
(EVar
"months", _
) => SOME
"months"
254 |
(EVar
"weeks", _
) => SOME
"weeks"
255 |
(EVar
"days", _
) => SOME
"days"
256 |
(EVar
"hours", _
) => SOME
"hours"
257 |
(EVar
"minutes", _
) => SOME
"minutes"
258 |
(EVar
"seconds", _
) => SOME
"seconds"
261 val vhostsChanged
= ref
false
262 val logDeleted
= ref
false
263 val delayedLogMoves
= ref (fn () => ())
265 val () = Slave
.registerPreHandler
266 (fn () => (vhostsChanged
:= false;
268 delayedLogMoves
:= (fn () => print
"Executing delayed log moves/deletes.\n")))
270 fun findVhostUser fname
=
272 val inf
= TextIO.openIn fname
275 case TextIO.inputLine inf
of
278 if String.isPrefix
"# Owner: " line
then
279 case String.tokens
Char.isSpace line
of
280 [_
, _
, user
] => SOME user
286 before TextIO.closeIn inf
289 val webNodes_full
= Config
.Apache
.webNodes_all @ Config
.Apache
.webNodes_admin
291 fun isVersion1 node
=
292 List.exists (fn (n
, {version
= ConfigTypes
.APACHE_1_3
, ...}) => n
= node
293 | _
=> false) webNodes_full
295 fun imVersion1 () = isVersion1 (Slave
.hostname ())
298 List.exists (fn (n
, {auth
= ConfigTypes
.MOD_WAKLOG
, ...}) => n
= node
299 | _
=> false) webNodes_full
301 fun down () = if imVersion1 () then Config
.Apache
.down1
else Config
.Apache
.down
302 fun undown () = if imVersion1 () then Config
.Apache
.undown1
else Config
.Apache
.undown
303 fun reload () = if imVersion1 () then Config
.Apache
.reload1
else Config
.Apache
.reload
304 fun fixperms () = if imVersion1 () then Config
.Apache
.fixperms1
else Config
.Apache
.fixperms
306 fun logDir
{user
, node
, vhostId
} =
307 String.concat
[Config
.Apache
.logDirOf (isVersion1 node
) user
,
313 fun realLogDir
{user
, node
, vhostId
} =
314 String.concat
[Config
.Apache
.realLogDirOf user
,
320 val () = Slave
.registerFileHandler (fn fs
=>
322 val spl
= OS
.Path
.splitDirFile (#file fs
)
324 if String.isSuffix
".vhost" (#file spl
)
325 orelse String.isSuffix
".vhost_ssl" (#file spl
) then let
326 val realVhostFile
= OS
.Path
.joinDirFile
327 {dir
= Config
.Apache
.confDir
,
330 val user
= findVhostUser (#file fs
)
331 val oldUser
= case #action fs
of
332 Slave
.Delete
false => user
333 | _
=> findVhostUser realVhostFile
335 if (oldUser
= NONE
andalso #action fs
<> Slave
.Add
)
336 orelse (user
= NONE
andalso not (Slave
.isDelete (#action fs
))) then
337 print ("Can't find user in " ^ #file fs ^
" or " ^ realVhostFile ^
"! Taking no action.\n")
340 val vhostId
= if OS
.Path
.ext (#file spl
) = SOME
"vhost_ssl" then
341 OS
.Path
.base (#file spl
) ^
".ssl"
343 OS
.Path
.base (#file spl
)
345 fun realLogDir user
=
346 logDir
{user
= valOf user
,
347 node
= Slave
.hostname (),
352 {dir
= Config
.Apache
.backupLogDirOf
353 (isVersion1 (Slave
.hostname ())),
356 vhostsChanged
:= true;
360 val ldir
= realLogDir oldUser
361 val dlm
= !delayedLogMoves
366 ((*ignore (OS
.Process
.system (down ()));*)
367 ignore (OS
.Process
.system (fixperms ()));
369 ignore (OS
.Process
.system (Config
.rm
372 delayedLogMoves
:= (fn () => (dlm ();
373 Slave
.moveDirCreate
{from
= ldir
,
374 to
= backupLogs ()}))
378 val rld
= realLogDir user
380 ignore (OS
.Process
.system (Config
.cp
385 if Posix
.FileSys
.access (rld
, []) then
388 Slave
.moveDirCreate
{from
= backupLogs (),
393 (ignore (OS
.Process
.system (Config
.cp
398 if user
<> oldUser
then
400 val old
= realLogDir oldUser
401 val rld
= realLogDir user
403 val dlm
= !delayedLogMoves
408 ((*ignore (OS
.Process
.system (down ()));*)
410 delayedLogMoves
:= (fn () => (dlm ();
411 ignore (OS
.Process
.system (Config
.rm
413 ^ realLogDir oldUser
))));
414 if Posix
.FileSys
.access (rld
, []) then
427 val () = Slave
.registerPostHandler
429 (if !vhostsChanged
then
430 (Slave
.shellF ([reload ()],
431 fn cl
=> "Error reloading Apache with " ^ cl
);
432 if !logDeleted
then !delayedLogMoves () else ())
436 val vhostFiles
: (string * TextIO.outstream
) list ref
= ref
[]
437 fun write
' s
= app (fn (node
, file
) => TextIO.output (file
, s node
)) (!vhostFiles
)
438 fun write s
= app (fn (_
, file
) => TextIO.output (file
, s
)) (!vhostFiles
)
440 val rewriteEnabled
= ref
false
441 val localRewriteEnabled
= ref
false
442 val expiresEnabled
= ref
false
443 val localExpiresEnabled
= ref
false
444 val currentVhost
= ref
""
445 val currentVhostId
= ref
""
446 val sslEnabled
= ref
false
448 val pre
= ref (fn _
: {user
: string, nodes
: string list
, id
: string, hostname
: string} => ())
453 pre
:= (fn x
=> (old x
; f x
))
456 val post
= ref (fn () => ())
461 post
:= (fn () => (old (); f ()))
465 fun doPost () = !post ()
467 val aliaser
= ref (fn _
: string => ())
468 fun registerAliaser f
=
472 aliaser
:= (fn x
=> (old x
; f x
))
475 fun vhostPost () = (!post ();
476 write
"</VirtualHost>\n";
477 app (TextIO.closeOut
o #
2) (!vhostFiles
))
479 val php_version
= fn (EVar
"php4", _
) => SOME
4
480 |
(EVar
"php5", _
) => SOME
5
483 fun vhostBody (env
, makeFullHost
) =
485 val places
= Env
.env (Env
.list webPlace
) (env
, "WebPlaces")
487 val ssl
= Env
.env
ssl (env
, "SSL")
488 val user
= Env
.env Env
.string (env
, "User")
489 val group
= Env
.env Env
.string (env
, "Group")
490 val docroot
= Env
.env Env
.string (env
, "DocumentRoot")
491 val sadmin
= Env
.env Env
.string (env
, "ServerAdmin")
492 val suexec
= Env
.env Env
.bool (env
, "SuExec")
493 val php
= Env
.env
php_version (env
, "PhpVersion")
495 val fullHost
= makeFullHost (Domain
.currentDomain ())
496 val vhostId
= fullHost ^
(if Option
.isSome ssl
then ".ssl" else "")
497 val confFile
= fullHost ^
(if Option
.isSome ssl
then ".vhost_ssl" else ".vhost")
499 currentVhost
:= fullHost
;
500 currentVhostId
:= vhostId
;
501 sslEnabled
:= Option
.isSome ssl
;
503 rewriteEnabled
:= false;
504 localRewriteEnabled
:= false;
505 expiresEnabled
:= false;
506 localExpiresEnabled
:= false;
507 vhostFiles
:= map (fn (node
, ip
) =>
509 val file
= Domain
.domainFile
{node
= node
,
512 val ld
= logDir
{user
= user
, node
= node
, vhostId
= vhostId
}
514 TextIO.output (file
, "# Owner: ");
515 TextIO.output (file
, user
);
516 TextIO.output (file
, "\n<VirtualHost ");
517 TextIO.output (file
, ip
);
518 TextIO.output (file
, ":");
519 TextIO.output (file
, case ssl
of
522 TextIO.output (file
, ">\n");
523 TextIO.output (file
, "\tErrorLog ");
524 TextIO.output (file
, ld
);
525 TextIO.output (file
, "/error.log\n\tCustomLog ");
526 TextIO.output (file
, ld
);
527 TextIO.output (file
, "/access.log combined\n");
528 TextIO.output (file
, "\tServerName ");
529 TextIO.output (file
, fullHost
);
531 (fn dom
=> (TextIO.output (file
, "\n\tServerAlias ");
532 TextIO.output (file
, makeFullHost dom
)))
533 (Domain
.currentAliasDomains ());
536 if isVersion1 node
then
537 (TextIO.output (file
, "\n\tUser ");
538 TextIO.output (file
, user
);
539 TextIO.output (file
, "\n\tGroup ");
540 TextIO.output (file
, group
))
542 (TextIO.output (file
, "\n\tSuexecUserGroup ");
543 TextIO.output (file
, user
);
544 TextIO.output (file
, " ");
545 TextIO.output (file
, group
);
546 TextIO.output (file
, "\n\tsuPHP_UserGroup ");
547 TextIO.output (file
, user
);
548 TextIO.output (file
, " ");
549 TextIO.output (file
, group
))
553 if isWaklog node
then
554 (TextIO.output (file
, "\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
555 TextIO.output (file
, user
);
556 TextIO.output (file
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
557 TextIO.output (file
, user
))
561 TextIO.output (file
, "\n\tDAVLockDB /var/lock/apache2/dav/");
562 TextIO.output (file
, user
);
563 TextIO.output (file
, "/DAVLock");
565 if php
<> Config
.Apache
.defaultPhpVersion
then
566 (TextIO.output (file
, "\n\tAddHandler x-httpd-php");
567 TextIO.output (file
, Int.toString php
);
568 TextIO.output (file
, " .php .phtml"))
575 write
"\n\tDocumentRoot ";
577 write
"\n\tServerAdmin ";
581 (write
"\n\tSSLEngine on\n\tSSLCertificateFile ";
585 !pre
{user
= user
, nodes
= map #
1 places
, id
= vhostId
, hostname
= fullHost
};
586 app (fn dom
=> !aliaser (makeFullHost dom
)) (Domain
.currentAliasDomains ())
589 val () = Env
.containerV_one
"vhost"
591 (fn (env
, host
) => vhostBody (env
, fn dom
=> host ^
"." ^ dom
),
594 val () = Env
.containerV_none
"vhostDefault"
595 (fn env
=> vhostBody (env
, fn dom
=> dom
),
598 val inLocal
= ref
false
600 val () = Env
.container_one
"location"
601 ("prefix", Env
.string)
603 (write
"\t<Location ";
607 fn () => (write
"\t</Location>\n";
609 localRewriteEnabled
:= false;
610 localExpiresEnabled
:= false))
612 val () = Env
.container_one
"directory"
613 ("directory", Env
.string)
615 (write
"\t<Directory ";
619 fn () => (write
"\t</Directory>\n";
621 localRewriteEnabled
:= false;
622 localExpiresEnabled
:= false))
624 val () = Env
.container_one
"filesMatch"
625 ("regexp", Env
.string)
627 (write
"\t<FilesMatch \"";
630 fn () => (write
"\t</FilesMatch>\n";
631 localRewriteEnabled
:= false;
632 localExpiresEnabled
:= false))
634 fun checkRewrite () =
636 if !localRewriteEnabled
then
639 (write
"\tRewriteEngine on\n";
640 localRewriteEnabled
:= true)
641 else if !rewriteEnabled
then
644 (write
"\tRewriteEngine on\n";
645 rewriteEnabled
:= true)
647 fun checkExpires () =
649 if !localExpiresEnabled
then
652 (write
"\tExpiresActive on\n";
653 localExpiresEnabled
:= true)
654 else if !expiresEnabled
then
657 (write
"\tExpiresActive on\n";
658 expiresEnabled
:= true)
660 val () = Env
.action_three
"localProxyRewrite"
661 ("from", Env
.string, "to", Env
.string, "port", Env
.int)
662 (fn (from
, to
, port
) =>
664 write
"\tRewriteRule\t\"";
666 write
"\"\thttp://localhost:";
667 write (Int.toString port
);
672 val () = Env
.action_four
"expiresByType"
673 ("mime", Env
.string, "base", interval_base
, "num", Env
.int, "inter", interval
)
674 (fn (mime
, base
, num
, inter
) =>
676 write
"\tExpiresByType\t\"";
683 write (Int.toString (~num
)))
685 write (Int.toString num
);
690 val () = Env
.action_two
"proxyPass"
691 ("from", Env
.string, "to", Env
.string)
693 (write
"\tProxyPass\t";
699 val () = Env
.action_two
"proxyPassReverse"
700 ("from", Env
.string, "to", Env
.string)
702 (write
"\tProxyPassReverse\t";
708 val () = Env
.action_three
"rewriteRule"
709 ("from", Env
.string, "to", Env
.string, "flags", Env
.list flag
)
710 (fn (from
, to
, flags
) =>
712 write
"\tRewriteRule\t\"";
719 | flag
::rest
=> (write
" [";
721 app (fn flag
=> (write
",";
726 val () = Env
.action_three
"rewriteCond"
727 ("test", Env
.string, "pattern", Env
.string, "flags", Env
.list cond_flag
)
728 (fn (from
, to
, flags
) =>
730 write
"\tRewriteCond\t\"";
737 | flag
::rest
=> (write
" [";
739 app (fn flag
=> (write
",";
744 val () = Env
.action_one
"rewriteBase"
745 ("prefix", Env
.string)
748 write
"\tRewriteBase\t\"";
752 val () = Env
.action_one
"rewriteLogLevel"
756 write
"\tRewriteLog ";
758 write
"/rewrite.log\n\tRewriteLogLevel ";
759 write (Int.toString level
);
762 val () = Env
.action_two
"alias"
763 ("from", Env
.string, "to", Env
.string)
771 val () = Env
.action_two
"scriptAlias"
772 ("from", Env
.string, "to", Env
.string)
774 (write
"\tScriptAlias\t";
780 val () = Env
.action_two
"errorDocument"
781 ("code", Env
.string, "handler", Env
.string)
782 (fn (code
, handler
) =>
784 val hasSpaces
= CharVector
.exists
Char.isSpace handler
792 write
"\tErrorDocument\t";
801 val () = Env
.action_one
"options"
802 ("options", Env
.list apache_option
)
806 | _
=> (write
"\tOptions";
807 app (fn opt
=> (write
" "; write opt
)) opts
;
810 val () = Env
.action_one
"set_options"
811 ("options", Env
.list apache_option
)
815 | _
=> (write
"\tOptions";
816 app (fn opt
=> (write
" +"; write opt
)) opts
;
819 val () = Env
.action_one
"unset_options"
820 ("options", Env
.list apache_option
)
824 | _
=> (write
"\tOptions";
825 app (fn opt
=> (write
" -"; write opt
)) opts
;
828 val () = Env
.action_one
"cgiExtension"
829 ("extension", Env
.string)
830 (fn ext
=> (write
"\tAddHandler cgi-script ";
834 val () = Env
.action_one
"directoryIndex"
835 ("filenames", Env
.list Env
.string)
837 (write
"\tDirectoryIndex";
838 app (fn opt
=> (write
" "; write opt
)) opts
;
841 val () = Env
.action_one
"serverAliasHost"
844 (write
"\tServerAlias ";
849 val () = Env
.action_one
"serverAlias"
855 val full
= host ^
"." ^ dom
857 write
"\tServerAlias ";
862 (Domain
.currentDomains ())))
864 val () = Env
.action_none
"serverAliasDefault"
868 (write
"\tServerAlias ";
872 (Domain
.currentDomains ())))
874 val authType
= fn (EVar
"basic", _
) => SOME
"basic"
875 |
(EVar
"digest", _
) => SOME
"digest"
876 |
(EVar
"kerberos", _
) => SOME
"kerberos"
879 fun allowAuthType
"kerberos" = !sslEnabled
880 | allowAuthType _
= true
882 val () = Env
.action_one
"authType"
885 if allowAuthType ty
then
886 (write
"\tAuthType ";
891 write
"\tKrbMethodNegotiate off\n\tKrbMethodK5Passwd on\n\tKrbVerifyKDC off\n\tKrbAuthRealms HCOOP.NET\n\tKrbSaveCredentials on\n"
894 print
"WARNING: Skipped Kerberos authType because this isn't an SSL vhost.\n")
896 val () = Env
.action_one
"authName"
899 (write
"\tAuthName \"";
903 val () = Env
.action_one
"authUserFile"
906 (write
"\tAuthUserFile ";
910 val () = Env
.action_none
"requireValidUser"
911 (fn () => write
"\tRequire valid-user\n")
913 val () = Env
.action_one
"requireUser"
914 ("users", Env
.list Env
.string)
918 | _
=> (write
"\tRequire user";
919 app (fn name
=> (write
" "; write name
)) names
;
922 val () = Env
.action_one
"requireGroup"
923 ("groups", Env
.list Env
.string)
927 | _
=> (write
"\tRequire group";
928 app (fn name
=> (write
" "; write name
)) names
;
931 val () = Env
.action_none
"orderAllowDeny"
932 (fn () => write
"\tOrder allow,deny\n")
934 val () = Env
.action_none
"orderDenyAllow"
935 (fn () => write
"\tOrder deny,allow\n")
937 val () = Env
.action_none
"allowFromAll"
938 (fn () => write
"\tAllow from all\n")
940 val () = Env
.action_one
"allowFrom"
941 ("entries", Env
.list Env
.string)
945 | _
=> (write
"\tAllow from";
946 app (fn name
=> (write
" "; write name
)) names
;
949 val () = Env
.action_none
"denyFromAll"
950 (fn () => write
"\tDeny from all\n")
952 val () = Env
.action_one
"denyFrom"
953 ("entries", Env
.list Env
.string)
957 | _
=> (write
"\tDeny from";
958 app (fn name
=> (write
" "; write name
)) names
;
961 val () = Env
.action_none
"satisfyAll"
962 (fn () => write
"\tSatisfy all\n")
964 val () = Env
.action_none
"satisfyAny"
965 (fn () => write
"\tSatisfy any\n")
967 val () = Env
.action_one
"forceType"
969 (fn ty
=> (write
"\tForceType ";
973 val () = Env
.action_none
"forceTypeOff"
974 (fn () => write
"\tForceType None\n")
976 val () = Env
.action_two
"action"
977 ("what", Env
.string, "how", Env
.string)
978 (fn (what
, how
) => (write
"\tAction ";
984 val () = Env
.action_one
"addDefaultCharset"
985 ("charset", Env
.string)
986 (fn ty
=> (write
"\tAddDefaultCharset ";
990 (*val () = Env
.action_one
"davSvn"
992 (fn path
=> (write
"\tDAV svn\n\tSVNPath ";
996 val () = Env
.action_one
"authzSvnAccessFile"
998 (fn path
=> (write
"\tAuthzSVNAccessFile ";
1002 val () = Env
.action_none
"davFilesystem"
1003 (fn path
=> write
"\tDAV filesystem\n")
1005 val () = Env
.action_two
"addDescription"
1006 ("description", Env
.string, "patterns", Env
.list Env
.string)
1010 | _
=> (write
"\tAddDescription \"";
1011 write (String.toString desc
);
1013 app (fn pat
=> (write
" "; write pat
)) pats
;
1016 val () = Env
.action_two
"addIcon"
1017 ("icon", Env
.string, "patterns", Env
.list Env
.string)
1021 | _
=> (write
"\tAddIcon \"";
1024 app (fn pat
=> (write
" "; write pat
)) pats
;
1027 val () = Env
.action_one
"indexOptions"
1028 ("options", Env
.list autoindex_option
)
1032 | _
=> (write
"\tIndexOptions";
1033 app (fn (opt
, arg
) =>
1036 Option
.app (fn arg
=>
1037 (write
"="; write arg
)) arg
)) opts
;
1040 val () = Env
.action_one
"indexIgnore"
1041 ("patterns", Env
.list Env
.string)
1045 | _
=> (write
"\tIndexIgnore";
1046 app (fn pat
=> (write
" "; write pat
)) pats
;
1049 val () = Env
.action_one
"set_indexOptions"
1050 ("options", Env
.list autoindex_option
)
1054 | _
=> (write
"\tIndexOptions";
1055 app (fn (opt
, arg
) =>
1058 Option
.app (fn arg
=>
1059 (write
"="; write arg
)) arg
)) opts
;
1062 val () = Env
.action_one
"unset_indexOptions"
1063 ("options", Env
.list autoindex_option
)
1067 | _
=> (write
"\tIndexOptions";
1073 val () = Env
.action_one
"headerName"
1074 ("name", Env
.string)
1075 (fn name
=> (write
"\tHeaderName ";
1079 val () = Env
.action_one
"readmeName"
1080 ("name", Env
.string)
1081 (fn name
=> (write
"\tReadmeName ";
1085 val () = Env
.action_two
"setEnv"
1086 ("key", Env
.string, "value", Env
.string)
1087 (fn (key
, value
) => (write
"\tSetEnv \"";
1090 write (String.translate (fn #
"\"" => "\\\""
1091 | ch
=> str ch
) value
);
1094 val () = Env
.action_one
"diskCache"
1095 ("path", Env
.string)
1096 (fn path
=> (write
"\tCacheEnable disk \"";
1100 val () = Env
.action_one
"phpVersion"
1101 ("version", php_version
)
1102 (fn version
=> (write
"\tAddHandler x-httpd-php";
1103 write (Int.toString version
);
1104 write
" .php .phtml\n"))
1106 val () = Env
.action_two
"addType"
1107 ("mime type", Env
.string, "extension", Env
.string)
1108 (fn (mt
, ext
) => (write
"\tAddType ";
1114 val filter
= fn (EVar
"includes", _
) => SOME
"INCLUDES"
1115 |
(EVar
"deflate", _
) => SOME
"DEFLATE"
1118 val () = Env
.action_two
"addOutputFilter"
1119 ("filters", Env
.list filter
, "extensions", Env
.list Env
.string)
1120 (fn (f
:: fs
, exts
as (_
:: _
)) =>
1121 (write
"\tAddOutputFilter ";
1123 app (fn f
=> (write
";"; write f
)) fs
;
1124 app (fn ext
=> (write
" "; write ext
)) exts
;
1128 val () = Domain
.registerResetLocal (fn () =>
1129 ignore (OS
.Process
.system (Config
.rm ^
" -rf /var/domtool/vhosts/*")))
1131 val () = Domain
.registerDescriber (Domain
.considerAll
1132 [Domain
.Extension
{extension
= "vhost",
1133 heading
= fn host
=> "Web vhost " ^ host ^
":"},
1134 Domain
.Extension
{extension
= "vhost_ssl",
1135 heading
= fn host
=> "SSL web vhost " ^ host ^
":"}])
1137 val () = Env
.action_none
"testNoHtaccess"
1138 (fn path
=> write
"\tAllowOverride None\n")
1140 fun writeWaklogUserFile () =
1142 val users
= Acl
.users ()
1143 val outf
= TextIO.openOut Config
.Apache
.waklogUserFile
1145 app (fn user
=> if String.isSuffix
"_admin" user
then
1148 (TextIO.output (outf
, "<Location /~");
1149 TextIO.output (outf
, user
);
1150 TextIO.output (outf
, ">\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
1151 TextIO.output (outf
, user
);
1152 TextIO.output (outf
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
1153 TextIO.output (outf
, user
);
1154 TextIO.output (outf
, "\n</Location>\n\n"))) users
;
1155 TextIO.closeOut outf
1158 val () = Domain
.registerOnUsersChange writeWaklogUserFile