basic internal ipv6 support
[hcoop/domtool2.git] / src / plugins / webalizer.sml
index f88f2ff..51e76c6 100644 (file)
@@ -24,22 +24,28 @@ val files = ref ([] : TextIO.outstream list)
 val write = ref (fn _ : string => ())
 
 val () = Apache.registerPre
 val write = ref (fn _ : string => ())
 
 val () = Apache.registerPre
-        (fn {nodes, id, hostname} =>
+        (fn {user, nodes, id, hostname} =>
             let
             let
-                val fds = map (fn node => Domain.domainFile {node = node,
-                                                             name = id ^ ".wbl"}) nodes
+                val fds = map (fn node =>
+                                  let
+                                      val fd = Domain.domainFile {node = node,
+                                                                  name = id ^ ".wbl"}
+                                  in
+                                      TextIO.output (fd, "LogFile\t");
+                                      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, node);
+                                      TextIO.output (fd, "/");
+                                      TextIO.output (fd, id);
+                                      TextIO.output (fd, "\n");
+                                      fd
+                                  end) nodes
             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 "LogFile\t";
-                !write Config.Apache.logDir;
-                !write "/";
-                !write hostname;
-                !write "/access.log\nOutputDir\t";
-                !write Config.Webalizer.outputDir;
-                !write "/";
-                !write id;
-                !write "\nHostname\t";
+                !write "HostName\t";
                 !write hostname;
                 !write "\nHideSite\t";
                 !write hostname;
                 !write hostname;
                 !write "\nHideSite\t";
                 !write hostname;
@@ -65,42 +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
-                                                            Posix.FileSys.mkdir (dir, Posix.FileSys.S.flags
-                                                                                          [Posix.FileSys.S.iroth,
-                                                                                           Posix.FileSys.S.ixoth,
-                                                                                           Posix.FileSys.S.irwxu,
-                                                                                           Posix.FileSys.S.irgrp,
-                                                                                           Posix.FileSys.S.iwgrp])
-                                                    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