Specifying encoding on database creation
[hcoop/domtool2.git] / src / plugins / webalizer.sml
index c6f8a17..50ca6a9 100644 (file)
@@ -32,11 +32,7 @@ val () = Apache.registerPre
                                                                   name = id ^ ".wbl"}
                                   in
                                       TextIO.output (fd, "LogFile\t");
-                                      TextIO.output (fd, Domain.homedirOf user);
-                                      TextIO.output (fd, "/apache/log/");
-                                      TextIO.output (fd, node);
-                                      TextIO.output (fd, "/");
-                                      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, "/");
@@ -49,7 +45,7 @@ val () = Apache.registerPre
             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;
@@ -75,42 +71,48 @@ val () = Slave.registerFileHandler (fn fs =>
                                       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
-                                                                               ^ "/"
-                                                                               ^ Slave.hostname ()
-                                                                               ^ "/"
-                                                                               ^ base
-                                                                               ^ ".conf"));
-                                                    ignore (OS.Process.system (Config.rm
-                                                                               ^ " -rf "
-                                                                               ^ Config.Webalizer.outputDir
-                                                                               ^ "/"
-                                                                               ^ Slave.hostname ()
-                                                                               ^ "/"
-                                                                               ^ base)))
-                                                 | _ =>
-                                                   (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
-                                                            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)
 
@@ -120,4 +122,8 @@ val () = Domain.registerResetLocal (fn () =>
                                                                          ^ Config.Webalizer.configDir ^ "/"
                                                                          ^ node ^ "/*"))) Config.nodeIps)
 
+val () = Domain.registerDescriber (Domain.considerAll
+                                  [Domain.Extension {extension = "wbl",
+                                                     heading = fn host => "Webalizer config for " ^ host ^ ":"}])
+
 end