Fix problem noted by omry on original domtool; namely, bad handling of rewrites insid...
[hcoop/domtool2.git] / src / plugins / apache.sml
index 24b424e..91209af 100644 (file)
@@ -29,6 +29,10 @@ val _ = Env.type_one "web_node"
            orelse (Domain.hasPriv "www"
                    andalso List.exists (fn x => x = node) Config.Apache.webNodes_admin))
 
+val _ = Env.registerFunction ("web_node_to_node",
+                             fn [e] => SOME e
+                              | _ => NONE)
+
 val _ = Env.type_one "proxy_port"
        Env.int
        (fn n => n > 1024)
@@ -68,10 +72,6 @@ val _ = Env.type_one "location"
 
 val dl = ErrorMsg.dummyLoc
 
-val _ = Env.registerFunction ("web_node_to_node",
-                             fn [e] => SOME e
-                              | _ => NONE)
-
 val _ = Defaults.registerDefault ("WebNodes",
                                  (TList (TBase "web_node", dl), dl),
                                  (fn () => (EList (map (fn s => (EString s, dl)) Config.Apache.webNodes_default), dl)))
@@ -272,6 +272,7 @@ fun write' s = app (fn (node, file) => TextIO.output (file, s node)) (!vhostFile
 fun write s = app (fn (_, file) => TextIO.output (file, s)) (!vhostFiles)
 
 val rewriteEnabled = ref false
+val localRewriteEnabled = ref false
 val currentVhost = ref ""
 val currentVhostId = ref ""
 
@@ -319,6 +320,7 @@ val () = Env.containerV_one "vhost"
                 currentVhostId := vhostId;
 
                 rewriteEnabled := false;
+                localRewriteEnabled := false;
                 vhostFiles := map (fn node =>
                                       let
                                           val file = Domain.domainFile {node = node,
@@ -370,24 +372,38 @@ val () = Env.containerV_one "vhost"
                    write "</VirtualHost>\n";
                    app (TextIO.closeOut o #2) (!vhostFiles)))
 
+val inLocal = ref false
+
 val () = Env.container_one "location"
         ("prefix", Env.string)
         (fn prefix =>
             (write "\t<Location ";
              write prefix;
-             write ">\n"),
-         fn () => write "\t</Location>\n")
+             write ">\n";
+             inLocal := true),
+         fn () => (write "\t</Location>\n";
+                   inLocal := false;
+                   localRewriteEnabled := false))
 
 val () = Env.container_one "directory"
         ("directory", Env.string)
         (fn directory =>
             (write "\t<Directory ";
              write directory;
-             write ">\n"),
-         fn () => write "\t</Directory>\n")
+             write ">\n";
+             inLocal := true),
+         fn () => (write "\t</Directory>\n";
+                   inLocal := false;
+                   localRewriteEnabled := false))
 
 fun checkRewrite () =
-    if !rewriteEnabled then
+    if !inLocal then
+       if !rewriteEnabled orelse !localRewriteEnabled then
+           ()
+       else
+           (write "\tRewriteEngine on\n";
+            localRewriteEnabled := true)
+    else if !rewriteEnabled then
        ()
     else
        (write "\tRewriteEngine on\n";