First support for new Apache log scheme
[hcoop/domtool2.git] / src / plugins / apache.sml
index 4ea0389..31fda50 100644 (file)
@@ -228,14 +228,26 @@ fun findVhostUser fname =
 val webNodes_full = Config.Apache.webNodes_all @ Config.Apache.webNodes_admin
 
 fun isVersion1 node =
-    List.exists (fn x => x = (node, true)) webNodes_full
+    List.exists (fn (n, {version = ConfigTypes.APACHE_1_3, ...}) => n = node
+                 | _ => false) webNodes_full
 
 fun imVersion1 () = isVersion1 (Slave.hostname ())
 
+fun isWaklog node =
+    List.exists (fn (n, {auth = ConfigTypes.MOD_WAKLOG, ...}) => n = node
+                 | _ => false) webNodes_full
+
 fun down () = if imVersion1 () then Config.Apache.down1 else Config.Apache.down
 fun undown () = if imVersion1 () then Config.Apache.undown1 else Config.Apache.undown
 fun reload () = if imVersion1 () then Config.Apache.reload1 else Config.Apache.reload
 
+fun logDir {user, node, vhostId} =
+    String.concat [Config.Apache.logDirOf user,
+                  "/",
+                  node,
+                  "/",
+                  vhostId]
+
 val () = Slave.registerFileHandler (fn fs =>
                                       let
                                           val spl = OS.Path.splitDirFile (#file fs)
@@ -254,27 +266,15 @@ val () = Slave.registerFileHandler (fn fs =>
                                                       print ("Can't find user in " ^ #file fs ^ " or " ^ realVhostFile ^ "!  Taking no action.\n")
                                                   else
                                                       let
+                                                          val vhostId = if OS.Path.ext (#file spl) = SOME ".vhost_ssl" then
+                                                                            OS.Path.base (#file spl) ^ ".ssl"
+                                                                        else
+                                                                            OS.Path.base (#file spl)
+
                                                           fun realLogDir user =
-                                                              let
-                                                                  val realLogDir = Domain.homedirOf (valOf user)
-                                                                  val realLogDir = OS.Path.joinDirFile
-                                                                                       {dir = realLogDir,
-                                                                                        file = "apache"}
-                                                                  val realLogDir = OS.Path.joinDirFile
-                                                                                       {dir = realLogDir,
-                                                                                        file = "log"}
-                                                                  val realLogDir = OS.Path.joinDirFile
-                                                                                       {dir = realLogDir,
-                                                                                        file = Slave.hostname ()}
-                                                                  val {base, ...} = OS.Path.splitBaseExt (#file spl)
-
-                                                                  val realLogDir = OS.Path.concat (realLogDir, base)
-                                                              in
-                                                                  if String.isSuffix ".vhost_ssl" (#file spl) then
-                                                                      realLogDir ^ ".ssl"
-                                                                  else
-                                                                      realLogDir
-                                                              end
+                                                              logDir {user = valOf user,
+                                                                      node = Slave.hostname (),
+                                                                      vhostId = vhostId}
                                                       in
                                                           vhostsChanged := true;
                                                           case #action fs of
@@ -302,7 +302,7 @@ val () = Slave.registerFileHandler (fn fs =>
                                                                   if Posix.FileSys.access (rld, []) then
                                                                       ()
                                                                   else
-                                                                      OS.FileSys.mkDir rld
+                                                                      Slave.mkDirAll rld
                                                               end
                                                               
                                                             | _ =>
@@ -327,7 +327,7 @@ val () = Slave.registerFileHandler (fn fs =>
                                                                        if Posix.FileSys.access (rld, []) then
                                                                            ()
                                                                        else
-                                                                           OS.FileSys.mkDir rld
+                                                                           Slave.mkDirAll rld
                                                                    end
                                                                else
                                                                    ())
@@ -415,17 +415,9 @@ val () = Env.containerV_one "vhost"
                                                                  | NONE => "80");
                                           TextIO.output (file, ">\n");
                                           TextIO.output (file, "\tErrorLog ");
-                                          TextIO.output (file, Domain.homedirOf user);
-                                          TextIO.output (file, "/apache/log/");
-                                          TextIO.output (file, node);
-                                          TextIO.output (file, "/");
-                                          TextIO.output (file, vhostId);
+                                          TextIO.output (file, logDir {user = user, node = node, vhostId = vhostId});
                                           TextIO.output (file, "/error.log\n\tCustomLog ");
-                                          TextIO.output (file, Domain.homedirOf user);
-                                          TextIO.output (file, "/apache/log/");
-                                          TextIO.output (file, node);
-                                          TextIO.output (file, "/");
-                                          TextIO.output (file, vhostId);
+                                          TextIO.output (file, logDir {user = user, node = node, vhostId = vhostId});
                                           TextIO.output (file, "/access.log combined\n");
                                           TextIO.output (file, "\tServerName ");
                                           TextIO.output (file, fullHost);
@@ -442,8 +434,14 @@ val () = Env.containerV_one "vhost"
                                                    TextIO.output (file, group))
                                           else
                                               ();
-                                          (Domain.homedirOf user ^ "/apache/log/"
-                                           ^ node ^ "/" ^ vhostId, file)
+                                          if isWaklog node then
+                                              (TextIO.output (file, "\n\tWaklogProtected on\n\tWaklogPrincipal ");
+                                               TextIO.output (file, user);
+                                               TextIO.output (file, "/cgi@HCOOP.NET /etc/keytabs/cgi/");
+                                               TextIO.output (file, user))
+                                          else
+                                              ();
+                                          (logDir {user = user, node = node, vhostId = vhostId}, file)
                                       end)
                                   nodes;
                 write "\n\tDocumentRoot ";