apache: improved fastScriptAlias
authorClinton Ebadi <clinton@unknownlamer.org>
Wed, 1 Feb 2017 02:22:16 +0000 (21:22 -0500)
committerClinton Ebadi <clinton@unknownlamer.org>
Wed, 1 Feb 2017 02:30:21 +0000 (21:30 -0500)
Implementation using Alias + <Location> proved unworkable -- Apache
has an obnoxious property wherein Aliases are first match and
Locations are last match, causing all sorts of exciting
side-effects (e.g. having to add a `<Location>SetHandler
None</Location>' afterward for any aliases that otherwise would have
matched).

A directory + file match however works and does not cause strange
alias behavior.

Also fix not stripping trailing `/' when setting up wrapper.

src/plugins/apache.sml

index b959219..6174110 100644 (file)
@@ -790,23 +790,37 @@ val () = Env.action_two "scriptAlias"
 val () = Env.action_two "fastScriptAlias"
         ("from", Env.string, "to", Env.string)
         (fn (from, to) =>
-            (write "\tAlias\t";
-             write from;
-             write " ";
-             write to;
-             write "\n";
+            let
+                (* mod_fcgid + kerberos limit this to working with
+                individual fcgi programs. assume the target path is a
+                file and any trailing `/' is just aliasing
+                syntax. Directory+File on the script is used to
+                activate fcgid instead of Location on the alias to
+                limit effects (alias+location also match in inverse
+                order causing pernicious side-effects *)
+                val fcgi_path = if String.sub (to, size to - 1) = #"/"
+                                then
+                                    String.substring (to, 0, size to - 1)
+                                else
+                                    to
+                val fcgi_dir = OS.Path.dir fcgi_path
+                val fcgi_file = OS.Path.file fcgi_path
+            in
+                write "\tAlias\t"; write from; write " "; write to;  write "\n";
 
-             write "\t<Location ";
-             write from;
-             write ">\n";
-             write "\t\tSetHandler fcgid-script\n";
-             (* FIXME: only set kerberos wrapper of waklog is on *)
-             write "\t\tFcgidWrapper \"";
-             write (Config.Apache.fastCgiWrapperOf (Domain.getUser ()));
-             write " ";
-             write to;
-             write "\"\n";
-             write "\t</Location>\n"))
+                write "\t<Directory "; write fcgi_dir;  write ">\n";
+                write "\t<Files "; write fcgi_file;  write ">\n";
+                write "\tSetHandler fcgid-script\n";
+
+                (* FIXME: only set kerberos wrapper of waklog is on *)
+                write "\tFcgidWrapper \"";
+                write (Config.Apache.fastCgiWrapperOf (Domain.getUser ()));
+                write " ";
+                write fcgi_path;
+                write "\"\n";
+
+                write "\t</Files>\n\t</Directory>\n"
+            end)
 
 val () = Env.action_two "errorDocument"
         ("code", Env.string, "handler", Env.string)