From c98b57cf26f5174f128602281eac7c496d254011 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 26 Aug 2006 21:45:03 +0000 Subject: [PATCH] Add Apache logging --- configDefault/apache.cfg | 2 ++ configDefault/apache.csg | 1 + lib/mod_rewrite.dtl | 3 +++ src/domain.sml | 5 +++-- src/plugins/apache.sml | 28 +++++++++++++++++++++++++++- tests/testApache.dtl | 4 ++++ 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/configDefault/apache.cfg b/configDefault/apache.cfg index 06ff92a..e657830 100644 --- a/configDefault/apache.cfg +++ b/configDefault/apache.cfg @@ -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 diff --git a/configDefault/apache.csg b/configDefault/apache.csg index dcf989c..148523a 100644 --- a/configDefault/apache.csg +++ b/configDefault/apache.csg @@ -3,6 +3,7 @@ signature APACHE_CONFIG = sig val reload : string val confDir : string + val logDir : string val webNodes : string list diff --git a/lib/mod_rewrite.dtl b/lib/mod_rewrite.dtl index c0b939c..9a6795a 100644 --- a/lib/mod_rewrite.dtl +++ b/lib/mod_rewrite.dtl @@ -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 Apache + documentation for RewriteLogLevel.}} diff --git a/src/domain.sml b/src/domain.sml index 4b4042f..55531d8 100644 --- a/src/domain.sml +++ b/src/domain.sml @@ -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 diff --git a/src/plugins/apache.sml b/src/plugins/apache.sml index 23f8dd3..3c29c8e 100644 --- a/src/plugins/apache.sml +++ b/src/plugins/apache.sml @@ -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 "\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) => diff --git a/tests/testApache.dtl b/tests/testApache.dtl index e637d69..eee8980 100644 --- a/tests/testApache.dtl +++ b/tests/testApache.dtl @@ -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 -- 2.20.1