basic internal ipv6 support
[hcoop/domtool2.git] / src / plugins / webalizer.sml
CommitLineData
7f75d838
AC
1(* HCoop Domtool (http://hcoop.sourceforge.net/)
2 * Copyright (c) 2006, Adam Chlipala
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *)
18
19(* Webalizer statistics tool handling *)
20
21structure Webalizer :> WEBALIZER = struct
22
23val files = ref ([] : TextIO.outstream list)
24val write = ref (fn _ : string => ())
25
26val () = Apache.registerPre
7a2b27f0 27 (fn {user, nodes, id, hostname} =>
7f75d838 28 let
7a2b27f0
AC
29 val fds = map (fn node =>
30 let
31 val fd = Domain.domainFile {node = node,
32 name = id ^ ".wbl"}
33 in
34 TextIO.output (fd, "LogFile\t");
f086616f 35 TextIO.output (fd, Apache.realLogDir {user = user, node = node, vhostId = hostname});
7a2b27f0
AC
36 TextIO.output (fd, "/access.log\nOutputDir\t");
37 TextIO.output (fd, Config.Webalizer.outputDir);
38 TextIO.output (fd, "/");
39 TextIO.output (fd, node);
40 TextIO.output (fd, "/");
41 TextIO.output (fd, id);
42 TextIO.output (fd, "\n");
43 fd
44 end) nodes
7f75d838
AC
45 in
46 files := fds;
47 write := (fn s => app (fn fd => TextIO.output (fd, s)) fds);
367eeec8 48 !write "HostName\t";
7f75d838
AC
49 !write hostname;
50 !write "\nHideSite\t";
51 !write hostname;
52 !write "\nHideReferrer\t";
53 !write hostname;
54 !write "\n"
55 end)
56
57val () = Apache.registerPost
58 (fn () => app TextIO.closeOut (!files))
59
60val () = Apache.registerAliaser
61 (fn hostname =>
62 (!write "HideSite\t";
63 !write hostname;
64 !write "\nHideReferrer\t";
65 !write hostname;
66 !write "\n"))
67
68val () = Slave.registerFileHandler (fn fs =>
69 let
70 val spl = OS.Path.splitDirFile (#file fs)
71 in
72 case OS.Path.splitBaseExt (#file spl) of
73 {base, ext = SOME "wbl"} =>
6c62564b
AC
74 let
75 fun backupDir () = OS.Path.joinDirFile
76 {dir = Config.Webalizer.backupDir,
77 file = base}
78 in
79 case #action fs of
1638d5a2 80 Slave.Delete _ =>
6c62564b
AC
81 (ignore (OS.Process.system (Config.rm
82 ^ " -f "
83 ^ Config.Webalizer.configDir
84 ^ "/"
85 ^ Slave.hostname ()
86 ^ "/"
87 ^ base
88 ^ ".conf"));
89 Slave.moveDirCreate {from = Config.Webalizer.outputDir
90 ^ "/"
91 ^ Slave.hostname ()
92 ^ "/"
93 ^ base,
94 to = backupDir ()})
95 | _ =>
96 (ignore (OS.Process.system (Config.cp
97 ^ " "
98 ^ #file fs
99 ^ " "
100 ^ Config.Webalizer.configDir
101 ^ "/"
102 ^ Slave.hostname ()
103 ^ "/"
104 ^ base
105 ^ ".conf"));
106 let
107 val dir = Config.Webalizer.outputDir ^ "/" ^ Slave.hostname () ^ "/" ^ base
108 in
109 if Posix.FileSys.access (dir, []) then
110 ()
111 else
112 Slave.moveDirCreate {from = backupDir (),
113 to = dir}
114 end)
115 end
7f75d838
AC
116 | _ => ()
117 end)
118
71420f8b 119val () = Domain.registerResetLocal (fn () =>
c23af445 120 app (fn (node, _, _) =>
71420f8b
AC
121 ignore (OS.Process.system (Config.rm ^ " -rf "
122 ^ Config.Webalizer.configDir ^ "/"
123 ^ node ^ "/*"))) Config.nodeIps)
124
d300166d
AC
125val () = Domain.registerDescriber (Domain.considerAll
126 [Domain.Extension {extension = "wbl",
d936cf4d 127 heading = fn host => "Webalizer config for " ^ host ^ ":"}])
d300166d 128
7f75d838 129end