1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006-2009, Adam Chlipala
3 * Copyright (c
) 2013,2014,2015,2017,2018,2019 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
, Domain
.nodeIpv6 node
)
43 |
webPlace (EApp ((EApp ((EApp ((EVar
"web_place", _
), (EString node
, _
)), _
), (EString ip
, _
)), _
), (EString ipv6
, _
)), _
) =
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
.registerFunction ("web_place_to_ipv6",
62 fn [e
] => Option
.map (fn (_
, _
, ipv6
) => (EString ipv6
, dl
)) (webPlace e
)
65 val _
= Env
.type_one
"proxy_port"
69 fun validProxyTarget default s
=
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 s
)
90 val _
= Env
.type_one
"proxy_target"
92 (validProxyTarget (fn s
=> List.exists (fn s
' => s
= s
') (Config
.Apache
.proxyTargets @
["!"])))
94 val _
= Env
.type_one
"proxy_reverse_target"
96 (validProxyTarget (fn s
=> List.exists (fn s
' => s
= s
') Config
.Apache
.proxyTargets
))
98 val _
= Env
.type_one
"rewrite_arg"
100 (* #
":" is permitted here
, but really ought to be disallowed or escaped for E
=VAR
:VAL
*)
101 (CharVector
.all (fn ch
=> (Char.isGraph ch
) andalso not (List.exists (fn c
=> ch
= c
) [ #
"[", #
"]", #
",", #
"\"", #
"'", #
"=", #
"\\" ])))
103 val _
= Env
.type_one
"suexec_flag"
105 (fn b
=> b
orelse Domain
.hasPriv
"www")
107 val _
= Env
.type_one
"regexp"
111 fun validLocation s
=
112 size s
> 0 andalso size s
< 1000 andalso CharVector
.all
113 (fn ch
=> Char.isAlphaNum ch
120 val _
= Env
.type_one
"location"
124 fun validCert s
= Acl
.query
{user
= Domain
.getUser (),
128 fun validCaCert s
= Acl
.query
{user
= Domain
.getUser (),
132 val _
= Env
.type_one
"ssl_cert_path"
136 val _
= Env
.type_one
"ssl_cacert_path"
140 fun ssl e
= case e
of
141 (EVar
"no_ssl", _
) => SOME NONE
142 |
(EApp ((EVar
"use_cert", _
), s
), _
) => Option
.map
SOME (Env
.string s
)
145 fun validExtension s
=
148 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"_") s
150 val _
= Env
.type_one
"file_extension"
154 val _
= Env
.registerFunction ("defaultServerAdmin",
155 fn [] => SOME (EString (Domain
.getUser () ^
"@" ^ Config
.defaultDomain
), dl
)
158 val redirect_code
= fn (EVar
"temp", _
) => SOME
"temp"
159 |
(EVar
"permanent", _
) => SOME
"permanent"
160 |
(EVar
"seeother", _
) => SOME
"seeother"
161 |
(EVar
"redir300", _
) => SOME
"300"
162 |
(EVar
"redir301", _
) => SOME
"301"
163 |
(EVar
"redir302", _
) => SOME
"302"
164 |
(EVar
"redir303", _
) => SOME
"303"
165 |
(EVar
"redir304", _
) => SOME
"304"
166 |
(EVar
"redir305", _
) => SOME
"305"
167 |
(EVar
"redir307", _
) => SOME
"307"
168 |
(EVar
"notfound", _
) => SOME
"404"
171 val flag
= fn (EVar
"redirect", _
) => SOME
"R"
172 |
(EVar
"forbidden", _
) => SOME
"F"
173 |
(EVar
"gone", _
) => SOME
"G"
174 |
(EVar
"last", _
) => SOME
"L"
175 |
(EVar
"chain", _
) => SOME
"C"
176 |
(EVar
"nosubreq", _
) => SOME
"NS"
177 |
(EVar
"nocase", _
) => SOME
"NC"
178 |
(EVar
"qsappend", _
) => SOME
"QSA"
179 |
(EVar
"noescape", _
) => SOME
"NE"
180 |
(EVar
"passthrough", _
) => SOME
"PT"
181 |
(EApp ((EVar
"mimeType", _
), e
), _
) =>
182 Option
.map (fn s
=> "T=" ^ s
) (Env
.string e
)
183 |
(EApp ((EVar
"redirectWith", _
), e
), _
) =>
184 Option
.map (fn s
=> "R=" ^ s
) (redirect_code e
)
185 |
(EApp ((EVar
"skip", _
), e
), _
) =>
186 Option
.map (fn n
=> "S=" ^
Int.toString n
) (Env
.int e
)
187 |
(EApp ((EApp ((EVar
"env", _
), e1
), _
), e2
), _
) =>
188 (case Env
.string e1
of
190 | SOME s1
=> Option
.map (fn s2
=> "E=" ^ s1 ^
":" ^ s2
)
195 val cond_flag
= fn (EVar
"cond_nocase", _
) => SOME
"NC"
196 |
(EVar
"ornext", _
) => SOME
"OR"
199 val apache_option
= fn (EVar
"execCGI", _
) => SOME
"ExecCGI"
200 |
(EVar
"includesNOEXEC", _
) => SOME
"IncludesNOEXEC"
201 |
(EVar
"indexes", _
) => SOME
"Indexes"
202 |
(EVar
"followSymLinks", _
) => SOME
"FollowSymLinks"
203 |
(EVar
"multiViews", _
) => SOME
"MultiViews"
206 val autoindex_width
= fn (EVar
"autofit", _
) => SOME
"*"
207 |
(EApp ((EVar
"characters", _
), n
), _
) =>
208 Option
.map
Int.toString (Env
.int n
)
211 val autoindex_option
= fn (EApp ((EVar
"descriptionWidth", _
), w
), _
) =>
212 Option
.map (fn w
=> ("DescriptionWidth", SOME w
))
214 |
(EVar
"fancyIndexing", _
) => SOME ("FancyIndexing", NONE
)
215 |
(EVar
"foldersFirst", _
) => SOME ("FoldersFirst", NONE
)
216 |
(EVar
"htmlTable", _
) => SOME ("HTMLTable", NONE
)
217 |
(EVar
"iconsAreLinks", _
) => SOME ("IconsAreLinks", NONE
)
218 |
(EApp ((EVar
"iconHeight", _
), n
), _
) =>
219 Option
.map (fn w
=> ("IconHeight", SOME (Int.toString w
)))
221 |
(EApp ((EVar
"iconWidth", _
), n
), _
) =>
222 Option
.map (fn w
=> ("IconWidth", SOME (Int.toString w
)))
224 |
(EVar
"ignoreCase", _
) => SOME ("IgnoreCase", NONE
)
225 |
(EVar
"ignoreClient", _
) => SOME ("IgnoreClient", NONE
)
226 |
(EApp ((EVar
"nameWidth", _
), w
), _
) =>
227 Option
.map (fn w
=> ("NameWidth", SOME w
))
229 |
(EVar
"scanHtmlTitles", _
) => SOME ("ScanHTMLTitles", NONE
)
230 |
(EVar
"suppressColumnSorting", _
) => SOME ("SuppressColumnSorting", NONE
)
231 |
(EVar
"suppressDescription", _
) => SOME ("SuppressDescription", NONE
)
232 |
(EVar
"suppressHtmlPreamble", _
) => SOME ("SuppressHTMLPreamble", NONE
)
233 |
(EVar
"suppressIcon", _
) => SOME ("SuppressIcon", NONE
)
234 |
(EVar
"suppressLastModified", _
) => SOME ("SuppressLastModified", NONE
)
235 |
(EVar
"suppressRules", _
) => SOME ("SuppressRules", NONE
)
236 |
(EVar
"suppressSize", _
) => SOME ("SuppressSize", NONE
)
237 |
(EVar
"trackModified", _
) => SOME ("TrackModified", NONE
)
238 |
(EVar
"versionSort", _
) => SOME ("VersionSort", NONE
)
239 |
(EVar
"xhtml", _
) => SOME ("XHTML", NONE
)
243 val interval_base
= fn (EVar
"access", _
) => SOME
"access"
244 |
(EVar
"modification", _
) => SOME
"modification"
247 val interval
= fn (EVar
"years", _
) => SOME
"years"
248 |
(EVar
"months", _
) => SOME
"months"
249 |
(EVar
"weeks", _
) => SOME
"weeks"
250 |
(EVar
"days", _
) => SOME
"days"
251 |
(EVar
"hours", _
) => SOME
"hours"
252 |
(EVar
"minutes", _
) => SOME
"minutes"
253 |
(EVar
"seconds", _
) => SOME
"seconds"
256 val vhostsChanged
= ref
false
257 val logDeleted
= ref
false
258 val delayedLogMoves
= ref (fn () => ())
260 val () = Slave
.registerPreHandler
261 (fn () => (vhostsChanged
:= false;
263 delayedLogMoves
:= (fn () => print
"Executing delayed log moves/deletes.\n")))
265 fun findVhostUser fname
=
267 val inf
= TextIO.openIn fname
270 case TextIO.inputLine inf
of
273 if String.isPrefix
"# Owner: " line
then
274 case String.tokens
Char.isSpace line
of
275 [_
, _
, user
] => SOME user
281 before TextIO.closeIn inf
284 val webNodes_full
= Config
.Apache
.webNodes_all @ Config
.Apache
.webNodes_admin
286 fun isVersion1 node
=
287 List.exists (fn (n
, {version
= ConfigTypes
.APACHE_1_3
, ...}) => n
= node
288 | _
=> false) webNodes_full
290 fun imVersion1 () = isVersion1 (Slave
.hostname ())
293 List.exists (fn (n
, {auth
= ConfigTypes
.MOD_WAKLOG
, ...}) => n
= node
294 | _
=> false) webNodes_full
296 fun down () = if imVersion1 () then Config
.Apache
.down1
else Config
.Apache
.down
297 fun undown () = if imVersion1 () then Config
.Apache
.undown1
else Config
.Apache
.undown
298 fun reload () = if imVersion1 () then Config
.Apache
.reload1
else Config
.Apache
.reload
299 fun fixperms () = if imVersion1 () then Config
.Apache
.fixperms1
else Config
.Apache
.fixperms
301 fun logDir
{user
, node
, vhostId
} =
302 String.concat
[Config
.Apache
.logDirOf (isVersion1 node
) user
,
308 fun realLogDir
{user
, node
, vhostId
} =
309 String.concat
[Config
.Apache
.realLogDirOf user
,
315 val () = Slave
.registerFileHandler (fn fs
=>
317 val spl
= OS
.Path
.splitDirFile (#file fs
)
319 if String.isSuffix
".vhost" (#file spl
)
320 orelse String.isSuffix
".vhost_ssl" (#file spl
) then let
321 val realVhostFile
= OS
.Path
.joinDirFile
322 {dir
= Config
.Apache
.confDir
,
325 val user
= findVhostUser (#file fs
)
326 val oldUser
= case #action fs
of
327 Slave
.Delete
false => user
328 | _
=> findVhostUser realVhostFile
330 if (oldUser
= NONE
andalso #action fs
<> Slave
.Add
)
331 orelse (user
= NONE
andalso not (Slave
.isDelete (#action fs
))) then
332 print ("Can't find user in " ^ #file fs ^
" or " ^ realVhostFile ^
"! Taking no action.\n")
335 val vhostId
= if OS
.Path
.ext (#file spl
) = SOME
"vhost_ssl" then
336 OS
.Path
.base (#file spl
) ^
".ssl"
338 OS
.Path
.base (#file spl
)
340 fun realLogDir user
=
341 logDir
{user
= valOf user
,
342 node
= Slave
.hostname (),
347 {dir
= Config
.Apache
.backupLogDirOf
348 (isVersion1 (Slave
.hostname ())),
351 vhostsChanged
:= true;
355 val ldir
= realLogDir oldUser
356 val dlm
= !delayedLogMoves
361 ((*ignore (OS
.Process
.system (down ()));*)
362 ignore (OS
.Process
.system (fixperms ()));
364 ignore (OS
.Process
.system (Config
.rm
367 delayedLogMoves
:= (fn () => (dlm ();
368 Slave
.moveDirCreate
{from
= ldir
,
369 to
= backupLogs ()}))
373 val rld
= realLogDir user
375 ignore (OS
.Process
.system (Config
.cp
380 if Posix
.FileSys
.access (rld
, []) then
383 Slave
.moveDirCreate
{from
= backupLogs (),
388 (ignore (OS
.Process
.system (Config
.cp
393 if user
<> oldUser
then
395 val old
= realLogDir oldUser
396 val rld
= realLogDir user
398 val dlm
= !delayedLogMoves
403 ((*ignore (OS
.Process
.system (down ()));*)
405 delayedLogMoves
:= (fn () => (dlm ();
406 ignore (OS
.Process
.system (Config
.rm
408 ^ realLogDir oldUser
))));
409 if Posix
.FileSys
.access (rld
, []) then
422 val () = Slave
.registerPostHandler
424 (if !vhostsChanged
then
425 (Slave
.shellF ([reload ()],
426 fn cl
=> "Error reloading Apache with " ^ cl
);
427 if !logDeleted
then !delayedLogMoves () else ())
431 val vhostFiles
: (string * TextIO.outstream
) list ref
= ref
[]
432 fun write
' s
= app (fn (node
, file
) => TextIO.output (file
, s node
)) (!vhostFiles
)
433 fun write s
= app (fn (_
, file
) => TextIO.output (file
, s
)) (!vhostFiles
)
435 val rewriteEnabled
= ref
false
436 val localRewriteEnabled
= ref
false
437 val expiresEnabled
= ref
false
438 val localExpiresEnabled
= ref
false
439 val currentVhost
= ref
""
440 val currentVhostId
= ref
""
441 val sslEnabled
= ref
false
443 val pre
= ref (fn _
: {user
: string, nodes
: string list
, id
: string, hostname
: string} => ())
448 pre
:= (fn x
=> (old x
; f x
))
451 val post
= ref (fn () => ())
456 post
:= (fn () => (old (); f ()))
460 fun doPost () = !post ()
462 val aliaser
= ref (fn _
: string => ())
463 fun registerAliaser f
=
467 aliaser
:= (fn x
=> (old x
; f x
))
470 fun vhostPost () = (!post ();
471 write
"</VirtualHost>\n";
472 app (TextIO.closeOut
o #
2) (!vhostFiles
))
474 val php_version
= fn (EVar
"php56", _
) => SOME
56
475 |
(EVar
"php72", _
) => SOME
72
476 |
(EVar
"php73", _
) => SOME
73
479 fun vhostBody (env
, makeFullHost
) =
481 val places
= Env
.env (Env
.list webPlace
) (env
, "WebPlaces")
483 val ssl
= Env
.env
ssl (env
, "SSL")
484 val user
= Env
.env Env
.string (env
, "User")
485 val group
= Env
.env Env
.string (env
, "Group")
486 val docroot
= Env
.env Env
.string (env
, "DocumentRoot")
487 val sadmin
= Env
.env Env
.string (env
, "ServerAdmin")
488 val suexec
= Env
.env Env
.bool (env
, "SuExec")
489 val php
= Env
.env
php_version (env
, "PhpVersion")
491 val fullHost
= makeFullHost (Domain
.currentDomain ())
492 val vhostId
= fullHost ^
(if Option
.isSome ssl
then ".ssl" else "")
493 val confFile
= fullHost ^
(if Option
.isSome ssl
then ".vhost_ssl" else ".vhost")
495 currentVhost
:= fullHost
;
496 currentVhostId
:= vhostId
;
497 sslEnabled
:= Option
.isSome ssl
;
499 rewriteEnabled
:= false;
500 localRewriteEnabled
:= false;
501 expiresEnabled
:= false;
502 localExpiresEnabled
:= false;
503 vhostFiles
:= map (fn (node
, ip
, ipv6
) =>
505 val file
= Domain
.domainFile
{node
= node
,
508 val ld
= logDir
{user
= user
, node
= node
, vhostId
= vhostId
}
510 TextIO.output (file
, "# Owner: ");
511 TextIO.output (file
, user
);
512 TextIO.output (file
, "\n<VirtualHost ");
514 TextIO.output (file
, ip
);
515 TextIO.output (file
, ":");
516 TextIO.output (file
, case ssl
of
520 TextIO.output (file
, " [");
521 TextIO.output (file
, ipv6
);
522 TextIO.output (file
, "]");
523 TextIO.output (file
, ":");
524 TextIO.output (file
, case ssl
of
528 TextIO.output (file
, ">\n");
529 TextIO.output (file
, "\tErrorLog ");
530 TextIO.output (file
, ld
);
531 TextIO.output (file
, "/error.log\n\tCustomLog ");
532 TextIO.output (file
, ld
);
533 TextIO.output (file
, "/access.log combined\n");
534 TextIO.output (file
, "\tServerName ");
535 TextIO.output (file
, fullHost
);
537 (fn dom
=> (TextIO.output (file
, "\n\tServerAlias ");
538 TextIO.output (file
, makeFullHost dom
)))
539 (Domain
.currentAliasDomains ());
542 if isVersion1 node
then
543 (TextIO.output (file
, "\n\tUser ");
544 TextIO.output (file
, user
);
545 TextIO.output (file
, "\n\tGroup ");
546 TextIO.output (file
, group
))
548 (TextIO.output (file
, "\n\tSuexecUserGroup ");
549 TextIO.output (file
, user
);
550 TextIO.output (file
, " ");
551 TextIO.output (file
, group
))
555 if isWaklog node
then
556 (TextIO.output (file
, "\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
557 TextIO.output (file
, user
);
558 TextIO.output (file
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
559 TextIO.output (file
, user
))
563 TextIO.output (file
, "\n\tDAVLockDB /var/lock/apache2/dav/");
564 TextIO.output (file
, user
);
565 TextIO.output (file
, "/DAVLock");
567 TextIO.output (file
, "\n\tAddHandler fcgid-script .php .phtml");
568 map (fn ext
=> (TextIO.output (file
, "\n\tFcgidWrapper \"");
569 (* kerberos wrapper
, simulates waklog
+mod_cgi
*)
570 if isWaklog node
then
571 (TextIO.output (file
, Config
.Apache
.fastCgiWrapperOf user
);
572 TextIO.output (file
, " "))
575 TextIO.output (file
, Config
.Apache
.phpFastCgiWrapper php
);
576 TextIO.output (file
, "\" ");
577 TextIO.output (file
, ext
)))
582 write
"\n\tDocumentRoot ";
584 write
"\n\tServerAdmin ";
588 (write
"\n\tSSLEngine on\n\tSSLCertificateFile ";
592 !pre
{user
= user
, nodes
= map #
1 places
, id
= vhostId
, hostname
= fullHost
};
593 app (fn dom
=> !aliaser (makeFullHost dom
)) (Domain
.currentAliasDomains ())
596 val () = Env
.containerV_one
"vhost"
598 (fn (env
, host
) => vhostBody (env
, fn dom
=> host ^
"." ^ dom
),
601 val () = Env
.containerV_none
"vhostDefault"
602 (fn env
=> vhostBody (env
, fn dom
=> dom
),
605 val inLocal
= ref
false
607 val () = Env
.container_one
"location"
608 ("prefix", Env
.string)
610 (write
"\t<Location ";
614 fn () => (write
"\t</Location>\n";
616 localRewriteEnabled
:= false;
617 localExpiresEnabled
:= false))
619 val () = Env
.container_one
"directory"
620 ("directory", Env
.string)
622 (write
"\t<Directory ";
626 fn () => (write
"\t</Directory>\n";
628 localRewriteEnabled
:= false;
629 localExpiresEnabled
:= false))
631 val () = Env
.container_one
"filesMatch"
632 ("regexp", Env
.string)
634 (write
"\t<FilesMatch \"";
637 fn () => (write
"\t</FilesMatch>\n";
638 localRewriteEnabled
:= false;
639 localExpiresEnabled
:= false))
641 fun checkRewrite () =
643 if !localRewriteEnabled
then
646 (write
"\tRewriteEngine on\n";
647 localRewriteEnabled
:= true)
648 else if !rewriteEnabled
then
651 (write
"\tRewriteEngine on\n";
652 rewriteEnabled
:= true)
654 fun checkExpires () =
656 if !localExpiresEnabled
then
659 (write
"\tExpiresActive on\n";
660 localExpiresEnabled
:= true)
661 else if !expiresEnabled
then
664 (write
"\tExpiresActive on\n";
665 expiresEnabled
:= true)
667 val () = Env
.action_three
"localProxyRewrite"
668 ("from", Env
.string, "to", Env
.string, "port", Env
.int)
669 (fn (from
, to
, port
) =>
671 write
"\tRewriteRule\t\"";
673 write
"\"\thttp://localhost:";
674 write (Int.toString port
);
679 val () = Env
.action_four
"expiresByType"
680 ("mime", Env
.string, "base", interval_base
, "num", Env
.int, "inter", interval
)
681 (fn (mime
, base
, num
, inter
) =>
683 write
"\tExpiresByType\t\"";
690 write (Int.toString (~num
)))
692 write (Int.toString num
);
697 val () = Env
.action_two
"proxyPass"
698 ("from", Env
.string, "to", Env
.string)
700 (write
"\tProxyPass\t";
704 write
"\tretry=0\n"))
706 val () = Env
.action_two
"proxyPassReverse"
707 ("from", Env
.string, "to", Env
.string)
709 (write
"\tProxyPassReverse\t";
715 val () = Env
.action_one
"proxyPreserveHost"
718 (write
"\tProxyPreserveHost\t";
719 if enable
then write
"On" else write
"Off";
722 val () = Env
.action_three
"rewriteRule"
723 ("from", Env
.string, "to", Env
.string, "flags", Env
.list flag
)
724 (fn (from
, to
, flags
) =>
726 write
"\tRewriteRule\t\"";
733 | flag
::rest
=> (write
" [";
735 app (fn flag
=> (write
",";
740 val () = Env
.action_three
"rewriteCond"
741 ("test", Env
.string, "pattern", Env
.string, "flags", Env
.list cond_flag
)
742 (fn (from
, to
, flags
) =>
744 write
"\tRewriteCond\t\"";
751 | flag
::rest
=> (write
" [";
753 app (fn flag
=> (write
",";
758 val () = Env
.action_one
"rewriteBase"
759 ("prefix", Env
.string)
762 write
"\tRewriteBase\t\"";
766 val _
= Env
.type_one
"mod_rewrite_trace_level"
768 (fn n
=> n
> 0 andalso n
<= 8)
770 val () = Env
.action_one
"rewriteLogLevel"
774 write
"\tLogLevel rewrite:warn\n")
777 write
"\tLogLevel rewrite:trace";
778 write (Int.toString level
);
781 val () = Env
.action_two
"alias"
782 ("from", Env
.string, "to", Env
.string)
790 val () = Env
.action_two
"scriptAlias"
791 ("from", Env
.string, "to", Env
.string)
793 (write
"\tScriptAlias\t";
799 val () = Env
.action_two
"fastScriptAlias"
800 ("from", Env
.string, "to", Env
.string)
803 (* mod_fcgid
+ kerberos limit this to working
with
804 individual fcgi programs
. assume the target path is a
805 file
and any trailing `
/' is just aliasing
806 syntax
. Directory
+File on the script is used to
807 activate fcgid instead
of Location on the alias to
808 limit
effects (alias
+location also match
in inverse
809 order causing pernicious side
-effects
*)
810 val fcgi_path
= if String.sub (to
, size to
- 1) = #
"/"
812 String.substring (to
, 0, size to
- 1)
815 val fcgi_dir
= OS
.Path
.dir fcgi_path
816 val fcgi_file
= OS
.Path
.file fcgi_path
818 write
"\tAlias\t"; write from
; write
" "; write to
; write
"\n";
820 write
"\t<Directory "; write fcgi_dir
; write
">\n";
821 write
"\t<Files "; write fcgi_file
; write
">\n";
822 write
"\tSetHandler fcgid-script\n";
824 (* FIXME
: only set kerberos wrapper
of waklog is on
*)
825 (* won
't be trivial
, since we don
't have access to node here
*)
826 write
"\tFcgidWrapper \"";
827 write (Config
.Apache
.fastCgiWrapperOf (Domain
.getUser ()));
832 write
"\t</Files>\n\t</Directory>\n"
835 val () = Env
.action_two
"errorDocument"
836 ("code", Env
.string, "handler", Env
.string)
837 (fn (code
, handler
) =>
839 val hasSpaces
= CharVector
.exists
Char.isSpace handler
847 write
"\tErrorDocument\t";
856 val () = Env
.action_one
"options"
857 ("options", Env
.list apache_option
)
861 | _
=> (write
"\tOptions";
862 app (fn opt
=> (write
" "; write opt
)) opts
;
865 val () = Env
.action_one
"set_options"
866 ("options", Env
.list apache_option
)
870 | _
=> (write
"\tOptions";
871 app (fn opt
=> (write
" +"; write opt
)) opts
;
874 val () = Env
.action_one
"unset_options"
875 ("options", Env
.list apache_option
)
879 | _
=> (write
"\tOptions";
880 app (fn opt
=> (write
" -"; write opt
)) opts
;
883 val () = Env
.action_one
"cgiExtension"
884 ("extension", Env
.string)
885 (fn ext
=> (write
"\tAddHandler cgi-script ";
889 val () = Env
.action_one
"directoryIndex"
890 ("filenames", Env
.list Env
.string)
892 (write
"\tDirectoryIndex";
893 app (fn opt
=> (write
" "; write opt
)) opts
;
896 val () = Env
.action_one
"directorySlash"
899 (write
"\tDirectorySlash ";
900 if enable
then write
"On" else write
"Off";
903 val () = Env
.action_one
"serverAliasHost"
906 (write
"\tServerAlias ";
911 val () = Env
.action_one
"serverAlias"
917 val full
= host ^
"." ^ dom
919 write
"\tServerAlias ";
924 (Domain
.currentDomains ())))
926 val () = Env
.action_none
"serverAliasDefault"
930 (write
"\tServerAlias ";
934 (Domain
.currentDomains ())))
936 val authType
= fn (EVar
"basic", _
) => SOME
"basic"
937 |
(EVar
"digest", _
) => SOME
"digest"
938 |
(EVar
"kerberos", _
) => SOME
"kerberos"
941 fun allowAuthType
"kerberos" = !sslEnabled
942 | allowAuthType _
= true
944 val () = Env
.action_one
"authType"
947 if allowAuthType ty
then
948 (write
"\tAuthType ";
953 write
"\tKrbServiceName HTTP\n\tKrb5Keytab /etc/keytabs/service/apache\n\tKrbMethodNegotiate on\n\tKrbMethodK5Passwd on\n\tKrbVerifyKDC on\n\tKrbAuthRealms HCOOP.NET\n\tKrbSaveCredentials on\n"
956 print
"WARNING: Skipped Kerberos authType because this isn't an SSL vhost.\n")
958 val () = Env
.action_one
"authName"
961 (write
"\tAuthName \"";
965 val () = Env
.action_one
"authUserFile"
968 (write
"\tAuthUserFile ";
972 val () = Env
.action_one
"authGroupFile"
975 (write
"\tAuthGroupFile ";
979 val () = Env
.action_none
"requireValidUser"
980 (fn () => write
"\tRequire valid-user\n")
982 val () = Env
.action_one
"requireUser"
983 ("users", Env
.list Env
.string)
987 | _
=> (write
"\tRequire user";
988 app (fn name
=> (write
" "; write name
)) names
;
991 val () = Env
.action_one
"requireGroup"
992 ("groups", Env
.list Env
.string)
996 | _
=> (write
"\tRequire group";
997 app (fn name
=> (write
" "; write name
)) names
;
1000 val () = Env
.action_none
"orderAllowDeny"
1001 (fn () => write
"\tOrder allow,deny\n")
1003 val () = Env
.action_none
"orderDenyAllow"
1004 (fn () => write
"\tOrder deny,allow\n")
1006 val () = Env
.action_none
"allowFromAll"
1007 (fn () => write
"\tAllow from all\n")
1009 val () = Env
.action_one
"allowFrom"
1010 ("entries", Env
.list Env
.string)
1014 | _
=> (write
"\tAllow from";
1015 app (fn name
=> (write
" "; write name
)) names
;
1018 val () = Env
.action_none
"denyFromAll"
1019 (fn () => write
"\tDeny from all\n")
1021 val () = Env
.action_one
"denyFrom"
1022 ("entries", Env
.list Env
.string)
1026 | _
=> (write
"\tDeny from";
1027 app (fn name
=> (write
" "; write name
)) names
;
1030 val () = Env
.action_none
"satisfyAll"
1031 (fn () => write
"\tSatisfy all\n")
1033 val () = Env
.action_none
"satisfyAny"
1034 (fn () => write
"\tSatisfy any\n")
1036 val () = Env
.action_one
"forceType"
1037 ("type", Env
.string)
1038 (fn ty
=> (write
"\tForceType ";
1042 val () = Env
.action_none
"forceTypeOff"
1043 (fn () => write
"\tForceType None\n")
1045 val () = Env
.action_two
"action"
1046 ("what", Env
.string, "how", Env
.string)
1047 (fn (what
, how
) => (write
"\tAction ";
1053 val () = Env
.action_one
"addDefaultCharset"
1054 ("charset", Env
.string)
1055 (fn ty
=> (write
"\tAddDefaultCharset ";
1059 (*val () = Env
.action_one
"davSvn"
1060 ("path", Env
.string)
1061 (fn path
=> (write
"\tDAV svn\n\tSVNPath ";
1065 val () = Env
.action_one
"authzSvnAccessFile"
1066 ("path", Env
.string)
1067 (fn path
=> (write
"\tAuthzSVNAccessFile ";
1071 val () = Env
.action_none
"davFilesystem"
1072 (fn path
=> write
"\tDAV filesystem\n")
1074 val () = Env
.action_two
"addDescription"
1075 ("description", Env
.string, "patterns", Env
.list Env
.string)
1079 | _
=> (write
"\tAddDescription \"";
1080 write (String.toString desc
);
1082 app (fn pat
=> (write
" "; write pat
)) pats
;
1085 val () = Env
.action_two
"addIcon"
1086 ("icon", Env
.string, "patterns", Env
.list Env
.string)
1090 | _
=> (write
"\tAddIcon \"";
1093 app (fn pat
=> (write
" "; write pat
)) pats
;
1096 val () = Env
.action_one
"indexOptions"
1097 ("options", Env
.list autoindex_option
)
1101 | _
=> (write
"\tIndexOptions";
1102 app (fn (opt
, arg
) =>
1105 Option
.app (fn arg
=>
1106 (write
"="; write arg
)) arg
)) opts
;
1109 val () = Env
.action_one
"indexIgnore"
1110 ("patterns", Env
.list Env
.string)
1114 | _
=> (write
"\tIndexIgnore";
1115 app (fn pat
=> (write
" "; write pat
)) pats
;
1118 val () = Env
.action_one
"set_indexOptions"
1119 ("options", Env
.list autoindex_option
)
1123 | _
=> (write
"\tIndexOptions";
1124 app (fn (opt
, arg
) =>
1127 Option
.app (fn arg
=>
1128 (write
"="; write arg
)) arg
)) opts
;
1131 val () = Env
.action_one
"unset_indexOptions"
1132 ("options", Env
.list autoindex_option
)
1136 | _
=> (write
"\tIndexOptions";
1142 val () = Env
.action_one
"headerName"
1143 ("name", Env
.string)
1144 (fn name
=> (write
"\tHeaderName ";
1148 val () = Env
.action_one
"readmeName"
1149 ("name", Env
.string)
1150 (fn name
=> (write
"\tReadmeName ";
1154 val () = Env
.action_two
"setEnv"
1155 ("key", Env
.string, "value", Env
.string)
1156 (fn (key
, value
) => (write
"\tSetEnv \"";
1159 write (String.translate (fn #
"\"" => "\\\""
1160 | ch
=> str ch
) value
);
1163 val () = Env
.action_three
"setEnvIf"
1164 ("attribute", Env
.string, "match", Env
.string, "env_variables", Env
.list Env
.string)
1165 (fn (attribute
, match
, envs
) =>
1167 [] => (print
"WARNING: Skipped setEnvIf, no environment variables provided.\n")
1169 (write
"\tSetEnvIf\t\"";
1174 app (fn env
=> (write
"\t"; write env
)) envs
;
1177 val () = Env
.action_three
"setEnvIfNoCase"
1178 ("attribute", Env
.string, "match", Env
.string, "env_variables", Env
.list Env
.string)
1179 (fn (attribute
, match
, envs
) =>
1181 [] => (print
"WARNING: Skipped setEnvIfNoCase, no environment variables provided.\n")
1183 (write
"\tSetEnvIfNoCase\t\"";
1188 app (fn env
=> (write
"\t"; write env
)) envs
;
1191 val () = Env
.action_one
"diskCache"
1192 ("path", Env
.string)
1193 (fn path
=> (write
"\tCacheEnable disk \"";
1197 val () = Env
.action_one
"phpVersion"
1198 ("version", php_version
)
1199 (fn version
=> (write
"\tAddHandler fcgid-script .php .phtml\n";
1200 (* FIXME
: only set kerberos wrapper
of waklog is on
*)
1201 (* won
't be trivial
, since we don
't have access to node here
*)
1202 write
"\n\tFcgidWrapper \"";
1203 write (Config
.Apache
.fastCgiWrapperOf (Domain
.getUser ()));
1205 write (Config
.Apache
.phpFastCgiWrapper version
);
1206 write
"\" .php .phtml\n"))
1208 val () = Env
.action_two
"addType"
1209 ("mime type", Env
.string, "extension", Env
.string)
1210 (fn (mt
, ext
) => (write
"\tAddType ";
1216 val filter
= fn (EVar
"includes", _
) => SOME
"INCLUDES"
1217 |
(EVar
"deflate", _
) => SOME
"DEFLATE"
1220 val () = Env
.action_two
"addOutputFilter"
1221 ("filters", Env
.list filter
, "extensions", Env
.list Env
.string)
1222 (fn (f
:: fs
, exts
as (_
:: _
)) =>
1223 (write
"\tAddOutputFilter ";
1225 app (fn f
=> (write
";"; write f
)) fs
;
1226 app (fn ext
=> (write
" "; write ext
)) exts
;
1230 val () = Env
.action_one
"sslCertificateChainFile"
1231 ("ssl_cacert_path", Env
.string)
1234 (write
"\tSSLCertificateChainFile \"";
1238 print
"WARNING: Skipped sslCertificateChainFile because this isn't an SSL vhost.\n")
1240 val () = Domain
.registerResetLocal (fn () =>
1241 ignore (OS
.Process
.system (Config
.rm ^
" -rf " ^ Config
.Apache
.confDir ^
"/*")))
1243 val () = Domain
.registerDescriber (Domain
.considerAll
1244 [Domain
.Extension
{extension
= "vhost",
1245 heading
= fn host
=> "Web vhost " ^ host ^
":"},
1246 Domain
.Extension
{extension
= "vhost_ssl",
1247 heading
= fn host
=> "SSL web vhost " ^ host ^
":"}])
1249 val () = Env
.action_one
"allowEncodedSlashes"
1250 ("enable", Env
.bool)
1251 (fn enable
=> (write
"\tAllowEncodedSlashes ";
1252 write (if enable
then "NoDecode" else "Off");
1254 val () = Env
.action_none
"testNoHtaccess"
1255 (fn path
=> write
"\tAllowOverride None\n")
1257 fun writeWaklogUserFile () =
1259 val users
= Acl
.users ()
1260 val outf
= TextIO.openOut Config
.Apache
.waklogUserFile
1262 app (fn user
=> if String.isSuffix
"_admin" user
then
1265 (TextIO.output (outf
, "<Location /~");
1266 TextIO.output (outf
, user
);
1267 TextIO.output (outf
, ">\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
1268 TextIO.output (outf
, user
);
1269 TextIO.output (outf
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
1270 TextIO.output (outf
, user
);
1271 TextIO.output (outf
, "\n</Location>\n\n"))) users
;
1272 TextIO.closeOut outf
1275 val () = Domain
.registerOnUsersChange writeWaklogUserFile