Add Apache logging
[hcoop/domtool2.git] / src / plugins / apache.sml
index 4ea8f22..3c29c8e 100644 (file)
@@ -126,6 +126,11 @@ val cond_flag = fn (EVar "cond_nocase", _) => SOME "NC"
            | (EVar "ornext", _) => SOME "OR"
            | _ => NONE
 
+val apache_option = fn (EVar "execCGI", _) => SOME "ExecCGI"
+                    | (EVar "includesNOEXEC", _) => SOME "IncludesNOEXEC"
+                    | (EVar "indexes", _) => SOME "Indexes"
+                    | _ => NONE
+
 
 val vhostsChanged = ref false
 
@@ -170,6 +175,8 @@ val vhostFiles : TextIO.outstream list ref = ref []
 fun write s = app (fn file => TextIO.output (file, s)) (!vhostFiles)
 
 val rewriteEnabled = ref false
+val currentVhost = ref ""
+val currentVhostId = ref ""
 
 val () = Env.containerV_one "vhost"
         ("host", Env.string)
@@ -184,8 +191,12 @@ val () = Env.containerV_one "vhost"
                 val sadmin = Env.env Env.string (env, "ServerAdmin")
 
                 val fullHost = host ^ "." ^ Domain.currentDomain ()
+                val vhostId = fullHost ^ (if ssl then ".ssl" else "")
                 val confFile = fullHost ^ (if ssl then ".vhost_ssl" else ".vhost")
             in
+                currentVhost := fullHost;
+                currentVhostId := vhostId;
+
                 rewriteEnabled := false;
                 vhostFiles := map (fn node =>
                                       let
@@ -203,7 +214,9 @@ val () = Env.containerV_one "vhost"
                                           file
                                       end)
                                   nodes;
-                write "\tSuexecUserGroup ";
+                write "\tServerName ";
+                write fullHost;
+                write "\n\tSuexecUserGroup ";
                 write user;
                 write " ";
                 write group;
@@ -211,7 +224,15 @@ val () = Env.containerV_one "vhost"
                 write docroot;
                 write "\n\tServerAdmin ";
                 write sadmin;
-                write "\n"
+                write "\n\tErrorLog ";
+                write Config.Apache.logDir;
+                write "/";
+                write vhostId;
+                write "/error.log\n\tCustomLog ";
+                write Config.Apache.logDir;
+                write "/";
+                write vhostId;
+                write "/access.log combined\n"
             end,
          fn () => (write "</VirtualHost>\n";
                    app TextIO.closeOut (!vhostFiles)))
@@ -303,6 +324,18 @@ val () = Env.action_three "rewriteCond"
                                 write "]");
              write "\n"))
 
+val () = Env.action_one "rewriteLogLevel"
+        ("level", Env.int)
+        (fn level =>
+            (checkRewrite ();
+             write "\tRewriteLog ";
+             write Config.Apache.logDir;
+             write "/";
+             write (!currentVhostId);
+             write "/rewrite.log\n\tRewriteLogLevel ";
+             write (Int.toString level);
+             write "\n"))
+
 val () = Env.action_two "alias"
         ("from", Env.string, "to", Env.string)
         (fn (from, to) =>
@@ -330,5 +363,150 @@ val () = Env.action_two "errorDocument"
              write handler;
              write "\n"))
 
+val () = Env.action_one "options"
+        ("options", Env.list apache_option)
+        (fn opts =>
+            case opts of
+                [] => ()
+              | _ => (write "\tOptions";
+                      app (fn opt => (write " "; write opt)) opts;
+                      write "\n"))
+
+val () = Env.action_one "set_options"
+        ("options", Env.list apache_option)
+        (fn opts =>
+            case opts of
+                [] => ()
+              | _ => (write "\tOptions";
+                      app (fn opt => (write " +"; write opt)) opts;
+                      write "\n"))
+
+val () = Env.action_one "unset_options"
+        ("options", Env.list apache_option)
+        (fn opts =>
+            case opts of
+                [] => ()
+              | _ => (write "\tOptions";
+                      app (fn opt => (write " -"; write opt)) opts;
+                      write "\n"))
+
+val () = Env.action_one "directoryIndex"
+        ("filenames", Env.list Env.string)
+        (fn opts =>
+            (write "\tDirectoryIndex";
+             app (fn opt => (write " "; write opt)) opts;
+             write "\n"))
+
+val () = Env.action_one "serverAlias"
+        ("host", Env.string)
+        (fn host =>
+            (write "\tServerAlias ";
+             write host;
+             write "\n"))
+
+val authType = fn (EVar "basic", _) => SOME "basic"
+               | (EVar "digest", _) => SOME "digest"
+               | _ => NONE
+
+val () = Env.action_one "authType"
+        ("type", authType)
+        (fn ty =>
+            (write "\tAuthType ";
+             write ty;
+             write "\n"))
+
+val () = Env.action_one "authName"
+        ("name", Env.string)
+        (fn name =>
+            (write "\tAuthName \"";
+             write name;
+             write "\"\n"))
+
+val () = Env.action_one "authUserFile"
+        ("file", Env.string)
+        (fn name =>
+            (write "\tAuthUserFile ";
+             write name;
+             write "\n"))
+
+val () = Env.action_none "requireValidUser"
+        (fn () => write "\tRequire valid-user\n")
+
+val () = Env.action_one "requireUser"
+        ("users", Env.list Env.string)
+        (fn names =>
+            case names of
+                [] => ()
+              | _ => (write "\tRequire user";
+                      app (fn name => (write " "; write name)) names;
+                      write "\n"))
+
+val () = Env.action_one "requireGroup"
+        ("groups", Env.list Env.string)
+        (fn names =>
+            case names of
+                [] => ()
+              | _ => (write "\tRequire group";
+                      app (fn name => (write " "; write name)) names;
+                      write "\n"))
+
+val () = Env.action_none "orderAllowDeny"
+        (fn () => write "\tOrder allow,deny\n")
+
+val () = Env.action_none "orderDenyAllow"
+        (fn () => write "\tOrder deny,allow\n")
+
+val () = Env.action_none "allowFromAll"
+        (fn () => write "\tAllow from all\n")
+
+val () = Env.action_one "allowFrom"
+        ("entries", Env.list Env.string)
+        (fn names =>
+            case names of
+                [] => ()
+              | _ => (write "\tAllow from";
+                      app (fn name => (write " "; write name)) names;
+                      write "\n"))
+
+val () = Env.action_none "denyFromAll"
+        (fn () => write "\tDeny from all\n")
+
+val () = Env.action_one "denyFrom"
+        ("entries", Env.list Env.string)
+        (fn names =>
+            case names of
+                [] => ()
+              | _ => (write "\tDeny from";
+                      app (fn name => (write " "; write name)) names;
+                      write "\n"))
+
+val () = Env.action_none "satisfyAll"
+        (fn () => write "\tSatisfy all\n")
+
+val () = Env.action_none "satisfyAny"
+        (fn () => write "\tSatisfy any\n")
+
+val () = Env.action_one "forceType"
+        ("type", Env.string)
+        (fn ty => (write "\tForceType ";
+                   write ty;
+                   write "\n"))
+
+val () = Env.action_none "forceTypeOff"
+        (fn () => write "\tForceType None\n")
+
+val () = Env.action_two "action"
+        ("what", Env.string, "how", Env.string)
+        (fn (what, how) => (write "\tAction ";
+                            write what;
+                            write " ";
+                            write how;
+                            write "\n"))
+
+val () = Env.action_one "addDefaultCharset"
+        ("charset", Env.string)
+        (fn ty => (write "\tAddDefaultCharset ";
+                   write ty;
+                   write "\n"))
 
 end