Add Apache logging
authorAdam Chlipala <adamc@hcoop.net>
Sat, 26 Aug 2006 21:45:03 +0000 (21:45 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sat, 26 Aug 2006 21:45:03 +0000 (21:45 +0000)
configDefault/apache.cfg
configDefault/apache.csg
lib/mod_rewrite.dtl
src/domain.sml
src/plugins/apache.sml
tests/testApache.dtl

index 06ff92a..e657830 100644 (file)
@@ -10,4 +10,6 @@ val webNodes = ["this"]
 val proxyTargets = ["http://hcoop.net/cgi-bin/mailman",
                    "http://hcoop.net/pipermail"]
 
+val logDir = "/home/adamc/fake/log"
+
 end
index dcf989c..148523a 100644 (file)
@@ -3,6 +3,7 @@ signature APACHE_CONFIG = sig
     val reload : string
 
     val confDir : string
+    val logDir : string
 
     val webNodes : string list
 
index c0b939c..9a6795a 100644 (file)
@@ -63,3 +63,6 @@ extern val localProxyRewrite : no_spaces -> no_spaces -> proxy_port -> [^Vhost];
   the new URI by substituting variables in the second argument as per Apache
   mod_rewrite.}}
 
+extern val rewriteLogLevel : int -> [Vhost];
+{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriteloglevel">Apache
+  documentation for <tt>RewriteLogLevel</tt></a>.}}
index 4b4042f..55531d8 100644 (file)
@@ -72,13 +72,14 @@ fun yourPath path =
     andalso SS.exists (fn s' => path = s' orelse String.isPrefix (s' ^ "/") path) (your_paths ())
 
 fun yourDomainHost s =
-    let
+    yourDomain s
+    orelse let
        val (pref, suf) = Substring.splitl (fn ch => ch <> #".") (Substring.full s)
     in
        Substring.size suf > 0
        andalso validHost (Substring.string pref)
        andalso yourDomain (Substring.string
-                              (Substring.slice (suf, 1, NONE)))
+                               (Substring.slice (suf, 1, NONE)))
     end
 
 fun validUser s = size s > 0 andalso size s < 20
index 23f8dd3..3c29c8e 100644 (file)
@@ -175,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)
@@ -189,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
@@ -218,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)))
@@ -310,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) =>
index e637d69..eee8980 100644 (file)
@@ -6,6 +6,7 @@ domain "hcoop.net" with
                DocumentRoot = "/home/adamc/html";
                ServerAdmin = "adamc@hcoop.net"
        with
+               serverAlias "hcoop.net";
                addDefaultCharset "mumbo-jumbo/incomprehensible"
        end;
 
@@ -16,6 +17,8 @@ domain "hcoop.net" with
                rewriteCond "hi" "there" [ornext];
                rewriteRule "^/foo.html" "/bar.html" [redirectWith redir300, nosubreq];
 
+               rewriteLogLevel 2;
+
                location "/theMorgue" with
                        rewriteRule "A" "B" [];
                end
@@ -43,6 +46,7 @@ domain "hcoop.net" with
 
        vhost "lists" with
                proxyPass "/mailman" "http://hcoop.net/cgi-bin/mailman";
+               proxyPass "/pipermail" "http://hcoop.net/pipermail";
                alias "/doc/mailman" "/home/adamc/mailman";
 
                location "/the-citadel" with