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"
163 |
(EVar
"notfound", _
) => SOME
"404"
166 val flag
= fn (EVar
"redirect", _
) => SOME
"R"
167 |
(EVar
"forbidden", _
) => SOME
"F"
168 |
(EVar
"gone", _
) => SOME
"G"
169 |
(EVar
"last", _
) => SOME
"L"
170 |
(EVar
"chain", _
) => SOME
"C"
171 |
(EVar
"nosubreq", _
) => SOME
"NS"
172 |
(EVar
"nocase", _
) => SOME
"NC"
173 |
(EVar
"qsappend", _
) => SOME
"QSA"
174 |
(EVar
"noescape", _
) => SOME
"NE"
175 |
(EVar
"passthrough", _
) => SOME
"PT"
176 |
(EApp ((EVar
"mimeType", _
), e
), _
) =>
177 Option
.map (fn s
=> "T=" ^ s
) (Env
.string e
)
178 |
(EApp ((EVar
"redirectWith", _
), e
), _
) =>
179 Option
.map (fn s
=> "R=" ^ s
) (redirect_code e
)
180 |
(EApp ((EVar
"skip", _
), e
), _
) =>
181 Option
.map (fn n
=> "S=" ^
Int.toString n
) (Env
.int e
)
182 |
(EApp ((EApp ((EVar
"env", _
), e1
), _
), e2
), _
) =>
183 (case Env
.string e1
of
185 | SOME s1
=> Option
.map (fn s2
=> "E=" ^ s1 ^
":" ^ s2
)
190 val cond_flag
= fn (EVar
"cond_nocase", _
) => SOME
"NC"
191 |
(EVar
"ornext", _
) => SOME
"OR"
194 val apache_option
= fn (EVar
"execCGI", _
) => SOME
"ExecCGI"
195 |
(EVar
"includesNOEXEC", _
) => SOME
"IncludesNOEXEC"
196 |
(EVar
"indexes", _
) => SOME
"Indexes"
197 |
(EVar
"followSymLinks", _
) => SOME
"FollowSymLinks"
198 |
(EVar
"multiViews", _
) => SOME
"MultiViews"
201 val autoindex_width
= fn (EVar
"autofit", _
) => SOME
"*"
202 |
(EApp ((EVar
"characters", _
), n
), _
) =>
203 Option
.map
Int.toString (Env
.int n
)
206 val autoindex_option
= fn (EApp ((EVar
"descriptionWidth", _
), w
), _
) =>
207 Option
.map (fn w
=> ("DescriptionWidth", SOME w
))
209 |
(EVar
"fancyIndexing", _
) => SOME ("FancyIndexing", NONE
)
210 |
(EVar
"foldersFirst", _
) => SOME ("FoldersFirst", NONE
)
211 |
(EVar
"htmlTable", _
) => SOME ("HTMLTable", NONE
)
212 |
(EVar
"iconsAreLinks", _
) => SOME ("IconsAreLinks", NONE
)
213 |
(EApp ((EVar
"iconHeight", _
), n
), _
) =>
214 Option
.map (fn w
=> ("IconHeight", SOME (Int.toString w
)))
216 |
(EApp ((EVar
"iconWidth", _
), n
), _
) =>
217 Option
.map (fn w
=> ("IconWidth", SOME (Int.toString w
)))
219 |
(EVar
"ignoreCase", _
) => SOME ("IgnoreCase", NONE
)
220 |
(EVar
"ignoreClient", _
) => SOME ("IgnoreClient", NONE
)
221 |
(EApp ((EVar
"nameWidth", _
), w
), _
) =>
222 Option
.map (fn w
=> ("NameWidth", SOME w
))
224 |
(EVar
"scanHtmlTitles", _
) => SOME ("ScanHTMLTitles", NONE
)
225 |
(EVar
"suppressColumnSorting", _
) => SOME ("SuppressColumnSorting", NONE
)
226 |
(EVar
"suppressDescription", _
) => SOME ("SuppressDescription", NONE
)
227 |
(EVar
"suppressHtmlPreamble", _
) => SOME ("SuppressHTMLPreamble", NONE
)
228 |
(EVar
"suppressIcon", _
) => SOME ("SuppressIcon", NONE
)
229 |
(EVar
"suppressLastModified", _
) => SOME ("SuppressLastModified", NONE
)
230 |
(EVar
"suppressRules", _
) => SOME ("SuppressRules", NONE
)
231 |
(EVar
"suppressSize", _
) => SOME ("SuppressSize", NONE
)
232 |
(EVar
"trackModified", _
) => SOME ("TrackModified", NONE
)
233 |
(EVar
"versionSort", _
) => SOME ("VersionSort", NONE
)
234 |
(EVar
"xhtml", _
) => SOME ("XHTML", NONE
)
238 val interval_base
= fn (EVar
"access", _
) => SOME
"access"
239 |
(EVar
"modification", _
) => SOME
"modification"
242 val interval
= fn (EVar
"years", _
) => SOME
"years"
243 |
(EVar
"months", _
) => SOME
"months"
244 |
(EVar
"weeks", _
) => SOME
"weeks"
245 |
(EVar
"days", _
) => SOME
"days"
246 |
(EVar
"hours", _
) => SOME
"hours"
247 |
(EVar
"minutes", _
) => SOME
"minutes"
248 |
(EVar
"seconds", _
) => SOME
"seconds"
251 val vhostsChanged
= ref
false
252 val logDeleted
= ref
false
253 val delayedLogMoves
= ref (fn () => ())
255 val () = Slave
.registerPreHandler
256 (fn () => (vhostsChanged
:= false;
258 delayedLogMoves
:= (fn () => print
"Executing delayed log moves/deletes.\n")))
260 fun findVhostUser fname
=
262 val inf
= TextIO.openIn fname
265 case TextIO.inputLine inf
of
268 if String.isPrefix
"# Owner: " line
then
269 case String.tokens
Char.isSpace line
of
270 [_
, _
, user
] => SOME user
276 before TextIO.closeIn inf
279 val webNodes_full
= Config
.Apache
.webNodes_all @ Config
.Apache
.webNodes_admin
281 fun isVersion1 node
=
282 List.exists (fn (n
, {version
= ConfigTypes
.APACHE_1_3
, ...}) => n
= node
283 | _
=> false) webNodes_full
285 fun imVersion1 () = isVersion1 (Slave
.hostname ())
288 List.exists (fn (n
, {auth
= ConfigTypes
.MOD_WAKLOG
, ...}) => n
= node
289 | _
=> false) webNodes_full
291 fun down () = if imVersion1 () then Config
.Apache
.down1
else Config
.Apache
.down
292 fun undown () = if imVersion1 () then Config
.Apache
.undown1
else Config
.Apache
.undown
293 fun reload () = if imVersion1 () then Config
.Apache
.reload1
else Config
.Apache
.reload
294 fun fixperms () = if imVersion1 () then Config
.Apache
.fixperms1
else Config
.Apache
.fixperms
296 fun logDir
{user
, node
, vhostId
} =
297 String.concat
[Config
.Apache
.logDirOf (isVersion1 node
) user
,
303 fun realLogDir
{user
, node
, vhostId
} =
304 String.concat
[Config
.Apache
.realLogDirOf user
,
310 val () = Slave
.registerFileHandler (fn fs
=>
312 val spl
= OS
.Path
.splitDirFile (#file fs
)
314 if String.isSuffix
".vhost" (#file spl
)
315 orelse String.isSuffix
".vhost_ssl" (#file spl
) then let
316 val realVhostFile
= OS
.Path
.joinDirFile
317 {dir
= Config
.Apache
.confDir
,
320 val user
= findVhostUser (#file fs
)
321 val oldUser
= case #action fs
of
322 Slave
.Delete
false => user
323 | _
=> findVhostUser realVhostFile
325 if (oldUser
= NONE
andalso #action fs
<> Slave
.Add
)
326 orelse (user
= NONE
andalso not (Slave
.isDelete (#action fs
))) then
327 print ("Can't find user in " ^ #file fs ^
" or " ^ realVhostFile ^
"! Taking no action.\n")
330 val vhostId
= if OS
.Path
.ext (#file spl
) = SOME
"vhost_ssl" then
331 OS
.Path
.base (#file spl
) ^
".ssl"
333 OS
.Path
.base (#file spl
)
335 fun realLogDir user
=
336 logDir
{user
= valOf user
,
337 node
= Slave
.hostname (),
342 {dir
= Config
.Apache
.backupLogDirOf
343 (isVersion1 (Slave
.hostname ())),
346 vhostsChanged
:= true;
350 val ldir
= realLogDir oldUser
351 val dlm
= !delayedLogMoves
356 ((*ignore (OS
.Process
.system (down ()));*)
357 ignore (OS
.Process
.system (fixperms ()));
359 ignore (OS
.Process
.system (Config
.rm
362 delayedLogMoves
:= (fn () => (dlm ();
363 Slave
.moveDirCreate
{from
= ldir
,
364 to
= backupLogs ()}))
368 val rld
= realLogDir user
370 ignore (OS
.Process
.system (Config
.cp
375 if Posix
.FileSys
.access (rld
, []) then
378 Slave
.moveDirCreate
{from
= backupLogs (),
383 (ignore (OS
.Process
.system (Config
.cp
388 if user
<> oldUser
then
390 val old
= realLogDir oldUser
391 val rld
= realLogDir user
393 val dlm
= !delayedLogMoves
398 ((*ignore (OS
.Process
.system (down ()));*)
400 delayedLogMoves
:= (fn () => (dlm ();
401 ignore (OS
.Process
.system (Config
.rm
403 ^ realLogDir oldUser
))));
404 if Posix
.FileSys
.access (rld
, []) then
417 val () = Slave
.registerPostHandler
419 (if !vhostsChanged
then
420 (Slave
.shellF ([reload ()],
421 fn cl
=> "Error reloading Apache with " ^ cl
);
422 if !logDeleted
then !delayedLogMoves () else ())
426 val vhostFiles
: (string * TextIO.outstream
) list ref
= ref
[]
427 fun write
' s
= app (fn (node
, file
) => TextIO.output (file
, s node
)) (!vhostFiles
)
428 fun write s
= app (fn (_
, file
) => TextIO.output (file
, s
)) (!vhostFiles
)
430 val rewriteEnabled
= ref
false
431 val localRewriteEnabled
= ref
false
432 val expiresEnabled
= ref
false
433 val localExpiresEnabled
= ref
false
434 val currentVhost
= ref
""
435 val currentVhostId
= ref
""
436 val sslEnabled
= ref
false
438 val pre
= ref (fn _
: {user
: string, nodes
: string list
, id
: string, hostname
: string} => ())
443 pre
:= (fn x
=> (old x
; f x
))
446 val post
= ref (fn () => ())
451 post
:= (fn () => (old (); f ()))
455 fun doPost () = !post ()
457 val aliaser
= ref (fn _
: string => ())
458 fun registerAliaser f
=
462 aliaser
:= (fn x
=> (old x
; f x
))
465 fun vhostPost () = (!post ();
466 write
"</VirtualHost>\n";
467 app (TextIO.closeOut
o #
2) (!vhostFiles
))
469 val php_version
= fn (EVar
"fast_php", _
) => SOME
6
472 fun vhostBody (env
, makeFullHost
) =
474 val places
= Env
.env (Env
.list webPlace
) (env
, "WebPlaces")
476 val ssl
= Env
.env
ssl (env
, "SSL")
477 val user
= Env
.env Env
.string (env
, "User")
478 val group
= Env
.env Env
.string (env
, "Group")
479 val docroot
= Env
.env Env
.string (env
, "DocumentRoot")
480 val sadmin
= Env
.env Env
.string (env
, "ServerAdmin")
481 val suexec
= Env
.env Env
.bool (env
, "SuExec")
482 val php
= Env
.env
php_version (env
, "PhpVersion")
484 val fullHost
= makeFullHost (Domain
.currentDomain ())
485 val vhostId
= fullHost ^
(if Option
.isSome ssl
then ".ssl" else "")
486 val confFile
= fullHost ^
(if Option
.isSome ssl
then ".vhost_ssl" else ".vhost")
488 currentVhost
:= fullHost
;
489 currentVhostId
:= vhostId
;
490 sslEnabled
:= Option
.isSome ssl
;
492 rewriteEnabled
:= false;
493 localRewriteEnabled
:= false;
494 expiresEnabled
:= false;
495 localExpiresEnabled
:= false;
496 vhostFiles
:= map (fn (node
, ip
) =>
498 val file
= Domain
.domainFile
{node
= node
,
501 val ld
= logDir
{user
= user
, node
= node
, vhostId
= vhostId
}
503 TextIO.output (file
, "# Owner: ");
504 TextIO.output (file
, user
);
505 TextIO.output (file
, "\n<VirtualHost ");
506 TextIO.output (file
, ip
);
507 TextIO.output (file
, ":");
508 TextIO.output (file
, case ssl
of
511 TextIO.output (file
, ">\n");
512 TextIO.output (file
, "\tErrorLog ");
513 TextIO.output (file
, ld
);
514 TextIO.output (file
, "/error.log\n\tCustomLog ");
515 TextIO.output (file
, ld
);
516 TextIO.output (file
, "/access.log combined\n");
517 TextIO.output (file
, "\tServerName ");
518 TextIO.output (file
, fullHost
);
520 (fn dom
=> (TextIO.output (file
, "\n\tServerAlias ");
521 TextIO.output (file
, makeFullHost dom
)))
522 (Domain
.currentAliasDomains ());
525 if isVersion1 node
then
526 (TextIO.output (file
, "\n\tUser ");
527 TextIO.output (file
, user
);
528 TextIO.output (file
, "\n\tGroup ");
529 TextIO.output (file
, group
))
531 (TextIO.output (file
, "\n\tSuexecUserGroup ");
532 TextIO.output (file
, user
);
533 TextIO.output (file
, " ");
534 TextIO.output (file
, group
))
538 if isWaklog node
then
539 (TextIO.output (file
, "\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
540 TextIO.output (file
, user
);
541 TextIO.output (file
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
542 TextIO.output (file
, user
))
546 TextIO.output (file
, "\n\tDAVLockDB /var/lock/apache2/dav/");
547 TextIO.output (file
, user
);
548 TextIO.output (file
, "/DAVLock");
552 (* fastcgi php
5.6, using version
6 since php6 doesn
't exist
*)
553 (TextIO.output (file
, "\n\tAddHandler fcgid-script .php .phtml");
554 map (fn ext
=> (TextIO.output (file
, "\n\tFcgidWrapper \"");
555 (* kerberos wrapper
, simulates waklog
+mod_cgi
*)
556 if isWaklog node
then
557 (TextIO.output (file
, Config
.Apache
.fastCgiWrapperOf user
);
558 TextIO.output (file
, " "))
561 TextIO.output (file
, Config
.Apache
.phpFastCgiWrapper
);
562 TextIO.output (file
, "\" ");
563 TextIO.output (file
, ext
)))
567 (TextIO.output (file
, "\n\tAddHandler x-httpd-php");
568 TextIO.output (file
, Int.toString php
);
569 TextIO.output (file
, " .php .phtml"));
573 write
"\n\tDocumentRoot ";
575 write
"\n\tServerAdmin ";
579 (write
"\n\tSSLEngine on\n\tSSLCertificateFile ";
583 !pre
{user
= user
, nodes
= map #
1 places
, id
= vhostId
, hostname
= fullHost
};
584 app (fn dom
=> !aliaser (makeFullHost dom
)) (Domain
.currentAliasDomains ())
587 val () = Env
.containerV_one
"vhost"
589 (fn (env
, host
) => vhostBody (env
, fn dom
=> host ^
"." ^ dom
),
592 val () = Env
.containerV_none
"vhostDefault"
593 (fn env
=> vhostBody (env
, fn dom
=> dom
),
596 val inLocal
= ref
false
598 val () = Env
.container_one
"location"
599 ("prefix", Env
.string)
601 (write
"\t<Location ";
605 fn () => (write
"\t</Location>\n";
607 localRewriteEnabled
:= false;
608 localExpiresEnabled
:= false))
610 val () = Env
.container_one
"directory"
611 ("directory", Env
.string)
613 (write
"\t<Directory ";
617 fn () => (write
"\t</Directory>\n";
619 localRewriteEnabled
:= false;
620 localExpiresEnabled
:= false))
622 val () = Env
.container_one
"filesMatch"
623 ("regexp", Env
.string)
625 (write
"\t<FilesMatch \"";
628 fn () => (write
"\t</FilesMatch>\n";
629 localRewriteEnabled
:= false;
630 localExpiresEnabled
:= false))
632 fun checkRewrite () =
634 if !localRewriteEnabled
then
637 (write
"\tRewriteEngine on\n";
638 localRewriteEnabled
:= true)
639 else if !rewriteEnabled
then
642 (write
"\tRewriteEngine on\n";
643 rewriteEnabled
:= true)
645 fun checkExpires () =
647 if !localExpiresEnabled
then
650 (write
"\tExpiresActive on\n";
651 localExpiresEnabled
:= true)
652 else if !expiresEnabled
then
655 (write
"\tExpiresActive on\n";
656 expiresEnabled
:= true)
658 val () = Env
.action_three
"localProxyRewrite"
659 ("from", Env
.string, "to", Env
.string, "port", Env
.int)
660 (fn (from
, to
, port
) =>
662 write
"\tRewriteRule\t\"";
664 write
"\"\thttp://localhost:";
665 write (Int.toString port
);
670 val () = Env
.action_four
"expiresByType"
671 ("mime", Env
.string, "base", interval_base
, "num", Env
.int, "inter", interval
)
672 (fn (mime
, base
, num
, inter
) =>
674 write
"\tExpiresByType\t\"";
681 write (Int.toString (~num
)))
683 write (Int.toString num
);
688 val () = Env
.action_two
"proxyPass"
689 ("from", Env
.string, "to", Env
.string)
691 (write
"\tProxyPass\t";
695 write
"\tretry=0\n"))
697 val () = Env
.action_two
"proxyPassReverse"
698 ("from", Env
.string, "to", Env
.string)
700 (write
"\tProxyPassReverse\t";
706 val () = Env
.action_one
"proxyPreserveHost"
709 (write
"\tProxyPreserveHost\t";
710 if enable
then write
"On" else write
"Off";
713 val () = Env
.action_three
"rewriteRule"
714 ("from", Env
.string, "to", Env
.string, "flags", Env
.list flag
)
715 (fn (from
, to
, flags
) =>
717 write
"\tRewriteRule\t\"";
724 | flag
::rest
=> (write
" [";
726 app (fn flag
=> (write
",";
731 val () = Env
.action_three
"rewriteCond"
732 ("test", Env
.string, "pattern", Env
.string, "flags", Env
.list cond_flag
)
733 (fn (from
, to
, flags
) =>
735 write
"\tRewriteCond\t\"";
742 | flag
::rest
=> (write
" [";
744 app (fn flag
=> (write
",";
749 val () = Env
.action_one
"rewriteBase"
750 ("prefix", Env
.string)
753 write
"\tRewriteBase\t\"";
757 val () = Env
.action_one
"rewriteLogLevel"
761 write
"\tRewriteLog ";
763 write
"/rewrite.log\n\tRewriteLogLevel ";
764 write (Int.toString level
);
767 val () = Env
.action_two
"alias"
768 ("from", Env
.string, "to", Env
.string)
776 val () = Env
.action_two
"scriptAlias"
777 ("from", Env
.string, "to", Env
.string)
779 (write
"\tScriptAlias\t";
785 val () = Env
.action_two
"fastScriptAlias"
786 ("from", Env
.string, "to", Env
.string)
789 (* mod_fcgid
+ kerberos limit this to working
with
790 individual fcgi programs
. assume the target path is a
791 file
and any trailing `
/' is just aliasing
792 syntax
. Directory
+File on the script is used to
793 activate fcgid instead
of Location on the alias to
794 limit
effects (alias
+location also match
in inverse
795 order causing pernicious side
-effects
*)
796 val fcgi_path
= if String.sub (to
, size to
- 1) = #
"/"
798 String.substring (to
, 0, size to
- 1)
801 val fcgi_dir
= OS
.Path
.dir fcgi_path
802 val fcgi_file
= OS
.Path
.file fcgi_path
804 write
"\tAlias\t"; write from
; write
" "; write to
; write
"\n";
806 write
"\t<Directory "; write fcgi_dir
; write
">\n";
807 write
"\t<Files "; write fcgi_file
; write
">\n";
808 write
"\tSetHandler fcgid-script\n";
810 (* FIXME
: only set kerberos wrapper
of waklog is on
*)
811 (* won
't be trivial
, since we don
't have access to node here
*)
812 write
"\tFcgidWrapper \"";
813 write (Config
.Apache
.fastCgiWrapperOf (Domain
.getUser ()));
818 write
"\t</Files>\n\t</Directory>\n"
821 val () = Env
.action_two
"errorDocument"
822 ("code", Env
.string, "handler", Env
.string)
823 (fn (code
, handler
) =>
825 val hasSpaces
= CharVector
.exists
Char.isSpace handler
833 write
"\tErrorDocument\t";
842 val () = Env
.action_one
"options"
843 ("options", Env
.list apache_option
)
847 | _
=> (write
"\tOptions";
848 app (fn opt
=> (write
" "; write opt
)) opts
;
851 val () = Env
.action_one
"set_options"
852 ("options", Env
.list apache_option
)
856 | _
=> (write
"\tOptions";
857 app (fn opt
=> (write
" +"; write opt
)) opts
;
860 val () = Env
.action_one
"unset_options"
861 ("options", Env
.list apache_option
)
865 | _
=> (write
"\tOptions";
866 app (fn opt
=> (write
" -"; write opt
)) opts
;
869 val () = Env
.action_one
"cgiExtension"
870 ("extension", Env
.string)
871 (fn ext
=> (write
"\tAddHandler cgi-script ";
875 val () = Env
.action_one
"directoryIndex"
876 ("filenames", Env
.list Env
.string)
878 (write
"\tDirectoryIndex";
879 app (fn opt
=> (write
" "; write opt
)) opts
;
882 val () = Env
.action_one
"serverAliasHost"
885 (write
"\tServerAlias ";
890 val () = Env
.action_one
"serverAlias"
896 val full
= host ^
"." ^ dom
898 write
"\tServerAlias ";
903 (Domain
.currentDomains ())))
905 val () = Env
.action_none
"serverAliasDefault"
909 (write
"\tServerAlias ";
913 (Domain
.currentDomains ())))
915 val authType
= fn (EVar
"basic", _
) => SOME
"basic"
916 |
(EVar
"digest", _
) => SOME
"digest"
917 |
(EVar
"kerberos", _
) => SOME
"kerberos"
920 fun allowAuthType
"kerberos" = !sslEnabled
921 | allowAuthType _
= true
923 val () = Env
.action_one
"authType"
926 if allowAuthType ty
then
927 (write
"\tAuthType ";
932 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"
935 print
"WARNING: Skipped Kerberos authType because this isn't an SSL vhost.\n")
937 val () = Env
.action_one
"authName"
940 (write
"\tAuthName \"";
944 val () = Env
.action_one
"authUserFile"
947 (write
"\tAuthUserFile ";
951 val () = Env
.action_one
"authGroupFile"
954 (write
"\tAuthGroupFile ";
958 val () = Env
.action_none
"requireValidUser"
959 (fn () => write
"\tRequire valid-user\n")
961 val () = Env
.action_one
"requireUser"
962 ("users", Env
.list Env
.string)
966 | _
=> (write
"\tRequire user";
967 app (fn name
=> (write
" "; write name
)) names
;
970 val () = Env
.action_one
"requireGroup"
971 ("groups", Env
.list Env
.string)
975 | _
=> (write
"\tRequire group";
976 app (fn name
=> (write
" "; write name
)) names
;
979 val () = Env
.action_none
"orderAllowDeny"
980 (fn () => write
"\tOrder allow,deny\n")
982 val () = Env
.action_none
"orderDenyAllow"
983 (fn () => write
"\tOrder deny,allow\n")
985 val () = Env
.action_none
"allowFromAll"
986 (fn () => write
"\tAllow from all\n")
988 val () = Env
.action_one
"allowFrom"
989 ("entries", Env
.list Env
.string)
993 | _
=> (write
"\tAllow from";
994 app (fn name
=> (write
" "; write name
)) names
;
997 val () = Env
.action_none
"denyFromAll"
998 (fn () => write
"\tDeny from all\n")
1000 val () = Env
.action_one
"denyFrom"
1001 ("entries", Env
.list Env
.string)
1005 | _
=> (write
"\tDeny from";
1006 app (fn name
=> (write
" "; write name
)) names
;
1009 val () = Env
.action_none
"satisfyAll"
1010 (fn () => write
"\tSatisfy all\n")
1012 val () = Env
.action_none
"satisfyAny"
1013 (fn () => write
"\tSatisfy any\n")
1015 val () = Env
.action_one
"forceType"
1016 ("type", Env
.string)
1017 (fn ty
=> (write
"\tForceType ";
1021 val () = Env
.action_none
"forceTypeOff"
1022 (fn () => write
"\tForceType None\n")
1024 val () = Env
.action_two
"action"
1025 ("what", Env
.string, "how", Env
.string)
1026 (fn (what
, how
) => (write
"\tAction ";
1032 val () = Env
.action_one
"addDefaultCharset"
1033 ("charset", Env
.string)
1034 (fn ty
=> (write
"\tAddDefaultCharset ";
1038 (*val () = Env
.action_one
"davSvn"
1039 ("path", Env
.string)
1040 (fn path
=> (write
"\tDAV svn\n\tSVNPath ";
1044 val () = Env
.action_one
"authzSvnAccessFile"
1045 ("path", Env
.string)
1046 (fn path
=> (write
"\tAuthzSVNAccessFile ";
1050 val () = Env
.action_none
"davFilesystem"
1051 (fn path
=> write
"\tDAV filesystem\n")
1053 val () = Env
.action_two
"addDescription"
1054 ("description", Env
.string, "patterns", Env
.list Env
.string)
1058 | _
=> (write
"\tAddDescription \"";
1059 write (String.toString desc
);
1061 app (fn pat
=> (write
" "; write pat
)) pats
;
1064 val () = Env
.action_two
"addIcon"
1065 ("icon", Env
.string, "patterns", Env
.list Env
.string)
1069 | _
=> (write
"\tAddIcon \"";
1072 app (fn pat
=> (write
" "; write pat
)) pats
;
1075 val () = Env
.action_one
"indexOptions"
1076 ("options", Env
.list autoindex_option
)
1080 | _
=> (write
"\tIndexOptions";
1081 app (fn (opt
, arg
) =>
1084 Option
.app (fn arg
=>
1085 (write
"="; write arg
)) arg
)) opts
;
1088 val () = Env
.action_one
"indexIgnore"
1089 ("patterns", Env
.list Env
.string)
1093 | _
=> (write
"\tIndexIgnore";
1094 app (fn pat
=> (write
" "; write pat
)) pats
;
1097 val () = Env
.action_one
"set_indexOptions"
1098 ("options", Env
.list autoindex_option
)
1102 | _
=> (write
"\tIndexOptions";
1103 app (fn (opt
, arg
) =>
1106 Option
.app (fn arg
=>
1107 (write
"="; write arg
)) arg
)) opts
;
1110 val () = Env
.action_one
"unset_indexOptions"
1111 ("options", Env
.list autoindex_option
)
1115 | _
=> (write
"\tIndexOptions";
1121 val () = Env
.action_one
"headerName"
1122 ("name", Env
.string)
1123 (fn name
=> (write
"\tHeaderName ";
1127 val () = Env
.action_one
"readmeName"
1128 ("name", Env
.string)
1129 (fn name
=> (write
"\tReadmeName ";
1133 val () = Env
.action_two
"setEnv"
1134 ("key", Env
.string, "value", Env
.string)
1135 (fn (key
, value
) => (write
"\tSetEnv \"";
1138 write (String.translate (fn #
"\"" => "\\\""
1139 | ch
=> str ch
) value
);
1142 val () = Env
.action_one
"diskCache"
1143 ("path", Env
.string)
1144 (fn path
=> (write
"\tCacheEnable disk \"";
1148 val () = Env
.action_one
"phpVersion"
1149 ("version", php_version
)
1150 (fn version
=> (if version
= 6
1152 (* fastcgi php
5.6 since
6 doesn
't exist
*)
1153 (write
"\tAddHandler fcgid-script .php .phtml\n";
1154 (* FIXME
: only set kerberos wrapper
of waklog is on
*)
1155 (* won
't be trivial
, since we don
't have access to node here
*)
1156 write
"\n\tFcgidWrapper \"";
1157 write (Config
.Apache
.fastCgiWrapperOf (Domain
.getUser ()));
1159 write Config
.Apache
.phpFastCgiWrapper
;
1160 write
"\" .php .phtml\n")
1162 (write
"\tAddHandler x-httpd-php";
1163 write (Int.toString version
);
1164 write
" .php .phtml\n")))
1166 val () = Env
.action_two
"addType"
1167 ("mime type", Env
.string, "extension", Env
.string)
1168 (fn (mt
, ext
) => (write
"\tAddType ";
1174 val filter
= fn (EVar
"includes", _
) => SOME
"INCLUDES"
1175 |
(EVar
"deflate", _
) => SOME
"DEFLATE"
1178 val () = Env
.action_two
"addOutputFilter"
1179 ("filters", Env
.list filter
, "extensions", Env
.list Env
.string)
1180 (fn (f
:: fs
, exts
as (_
:: _
)) =>
1181 (write
"\tAddOutputFilter ";
1183 app (fn f
=> (write
";"; write f
)) fs
;
1184 app (fn ext
=> (write
" "; write ext
)) exts
;
1188 val () = Env
.action_one
"sslCertificateChainFile"
1189 ("ssl_cacert_path", Env
.string)
1192 (write
"\tSSLCertificateChainFile \"";
1196 print
"WARNING: Skipped sslCertificateChainFile because this isn't an SSL vhost.\n")
1198 val () = Domain
.registerResetLocal (fn () =>
1199 ignore (OS
.Process
.system (Config
.rm ^
" -rf " ^ Config
.Apache
.confDir ^
"/*")))
1201 val () = Domain
.registerDescriber (Domain
.considerAll
1202 [Domain
.Extension
{extension
= "vhost",
1203 heading
= fn host
=> "Web vhost " ^ host ^
":"},
1204 Domain
.Extension
{extension
= "vhost_ssl",
1205 heading
= fn host
=> "SSL web vhost " ^ host ^
":"}])
1207 val () = Env
.action_one
"allowEncodedSlashes"
1208 ("enable", Env
.bool)
1209 (fn enable
=> (write
"\tAllowEncodedSlashes ";
1210 write (if enable
then "NoDecode" else "Off");
1212 val () = Env
.action_none
"testNoHtaccess"
1213 (fn path
=> write
"\tAllowOverride None\n")
1215 fun writeWaklogUserFile () =
1217 val users
= Acl
.users ()
1218 val outf
= TextIO.openOut Config
.Apache
.waklogUserFile
1220 app (fn user
=> if String.isSuffix
"_admin" user
then
1223 (TextIO.output (outf
, "<Location /~");
1224 TextIO.output (outf
, user
);
1225 TextIO.output (outf
, ">\n\tWaklogEnabled on\n\tWaklogLocationPrincipal ");
1226 TextIO.output (outf
, user
);
1227 TextIO.output (outf
, "/daemon@HCOOP.NET /etc/keytabs/user.daemon/");
1228 TextIO.output (outf
, user
);
1229 TextIO.output (outf
, "\n</Location>\n\n"))) users
;
1230 TextIO.closeOut outf
1233 val () = Domain
.registerOnUsersChange writeWaklogUserFile