basic internal ipv6 support
[hcoop/domtool2.git] / src / plugins / webalizer.sml
index 61d2b08..51e76c6 100644 (file)
@@ -32,10 +32,7 @@ val () = Apache.registerPre
                                                                   name = id ^ ".wbl"}
                                   in
                                       TextIO.output (fd, "LogFile\t");
                                                                   name = id ^ ".wbl"}
                                   in
                                       TextIO.output (fd, "LogFile\t");
-                                      TextIO.output (fd, Config.homeBase);
-                                      TextIO.output (fd, "/apache/log/");
-                                      TextIO.output (fd, node);
-                                      TextIO.output (fd, hostname);
+                                      TextIO.output (fd, Apache.realLogDir {user = user, node = node, vhostId = hostname});
                                       TextIO.output (fd, "/access.log\nOutputDir\t");
                                       TextIO.output (fd, Config.Webalizer.outputDir);
                                       TextIO.output (fd, "/");
                                       TextIO.output (fd, "/access.log\nOutputDir\t");
                                       TextIO.output (fd, Config.Webalizer.outputDir);
                                       TextIO.output (fd, "/");
@@ -48,7 +45,7 @@ val () = Apache.registerPre
             in
                 files := fds;
                 write := (fn s => app (fn fd => TextIO.output (fd, s)) fds);
             in
                 files := fds;
                 write := (fn s => app (fn fd => TextIO.output (fd, s)) fds);
-                !write "Hostname\t";
+                !write "HostName\t";
                 !write hostname;
                 !write "\nHideSite\t";
                 !write hostname;
                 !write hostname;
                 !write "\nHideSite\t";
                 !write hostname;
@@ -74,37 +71,59 @@ val () = Slave.registerFileHandler (fn fs =>
                                       in
                                           case OS.Path.splitBaseExt (#file spl) of
                                               {base, ext = SOME "wbl"} =>
                                       in
                                           case OS.Path.splitBaseExt (#file spl) of
                                               {base, ext = SOME "wbl"} =>
-                                              (case #action fs of
-                                                   Slave.Delete =>
-                                                   (ignore (OS.Process.system (Config.rm
-                                                                               ^ " -f "
-                                                                               ^ Config.Webalizer.configDir
-                                                                               ^ "/"
-                                                                               ^ base
-                                                                               ^ ".conf"));
-                                                    ignore (OS.Process.system (Config.rm
-                                                                               ^ " -rf "
-                                                                               ^ Config.Webalizer.outputDir
-                                                                               ^ "/"
-                                                                               ^ base)))
-                                                 | _ =>
-                                                   (ignore (OS.Process.system (Config.cp
-                                                                               ^ " "
-                                                                               ^ #file fs
-                                                                               ^ " "
-                                                                               ^ Config.Webalizer.configDir
-                                                                               ^ "/"
-                                                                               ^ base
-                                                                               ^ ".conf"));
-                                                    let
-                                                        val dir = Config.Webalizer.outputDir ^ "/" ^ base
-                                                    in
-                                                        if Posix.FileSys.access (dir, []) then
-                                                            ()
-                                                        else
-                                                            OS.FileSys.mkDir dir
-                                                    end))
+                                              let
+                                                  fun backupDir () = OS.Path.joinDirFile
+                                                                         {dir = Config.Webalizer.backupDir,
+                                                                          file = base}
+                                              in
+                                                  case #action fs of
+                                                      Slave.Delete _ =>
+                                                      (ignore (OS.Process.system (Config.rm
+                                                                                  ^ " -f "
+                                                                                  ^ Config.Webalizer.configDir
+                                                                                  ^ "/"
+                                                                                  ^ Slave.hostname ()
+                                                                                  ^ "/"
+                                                                                  ^ base
+                                                                                  ^ ".conf"));
+                                                       Slave.moveDirCreate {from = Config.Webalizer.outputDir
+                                                                                   ^ "/"
+                                                                                   ^ Slave.hostname ()
+                                                                                   ^ "/"
+                                                                                   ^ base,
+                                                                            to = backupDir ()})
+                                                    | _ =>
+                                                      (ignore (OS.Process.system (Config.cp
+                                                                                  ^ " "
+                                                                                  ^ #file fs
+                                                                                  ^ " "
+                                                                                  ^ Config.Webalizer.configDir
+                                                                                  ^ "/"
+                                                                                  ^ Slave.hostname ()
+                                                                                  ^ "/"
+                                                                                  ^ base
+                                                                                  ^ ".conf"));
+                                                       let
+                                                           val dir = Config.Webalizer.outputDir ^ "/" ^ Slave.hostname () ^ "/" ^ base
+                                                       in
+                                                           if Posix.FileSys.access (dir, []) then
+                                                               ()
+                                                           else
+                                                               Slave.moveDirCreate {from = backupDir (),
+                                                                                    to = dir}
+                                                       end)
+                                              end
                                             | _ => ()
                                       end)
 
                                             | _ => ()
                                       end)
 
+val () = Domain.registerResetLocal (fn () =>
+                                      app (fn (node, _, _) =>
+                                              ignore (OS.Process.system (Config.rm ^ " -rf "
+                                                                         ^ Config.Webalizer.configDir ^ "/"
+                                                                         ^ node ^ "/*"))) Config.nodeIps)
+
+val () = Domain.registerDescriber (Domain.considerAll
+                                  [Domain.Extension {extension = "wbl",
+                                                     heading = fn host => "Webalizer config for " ^ host ^ ":"}])
+
 end
 end