setsa
[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");
35 TextIO.output (fd, Config.homeBase);
5e70d4e2
AC
36 TextIO.output (fd, "/");
37 TextIO.output (fd, user);
7a2b27f0
AC
38 TextIO.output (fd, "/apache/log/");
39 TextIO.output (fd, node);
613c338c 40 TextIO.output (fd, "/");
7a2b27f0
AC
41 TextIO.output (fd, hostname);
42 TextIO.output (fd, "/access.log\nOutputDir\t");
43 TextIO.output (fd, Config.Webalizer.outputDir);
44 TextIO.output (fd, "/");
45 TextIO.output (fd, node);
46 TextIO.output (fd, "/");
47 TextIO.output (fd, id);
48 TextIO.output (fd, "\n");
49 fd
50 end) nodes
7f75d838
AC
51 in
52 files := fds;
53 write := (fn s => app (fn fd => TextIO.output (fd, s)) fds);
7a2b27f0 54 !write "Hostname\t";
7f75d838
AC
55 !write hostname;
56 !write "\nHideSite\t";
57 !write hostname;
58 !write "\nHideReferrer\t";
59 !write hostname;
60 !write "\n"
61 end)
62
63val () = Apache.registerPost
64 (fn () => app TextIO.closeOut (!files))
65
66val () = Apache.registerAliaser
67 (fn hostname =>
68 (!write "HideSite\t";
69 !write hostname;
70 !write "\nHideReferrer\t";
71 !write hostname;
72 !write "\n"))
73
74val () = Slave.registerFileHandler (fn fs =>
75 let
76 val spl = OS.Path.splitDirFile (#file fs)
77 in
78 case OS.Path.splitBaseExt (#file spl) of
79 {base, ext = SOME "wbl"} =>
80 (case #action fs of
81 Slave.Delete =>
82 (ignore (OS.Process.system (Config.rm
83 ^ " -f "
84 ^ Config.Webalizer.configDir
85 ^ "/"
5e70d4e2
AC
86 ^ Slave.hostname ()
87 ^ "/"
7f75d838
AC
88 ^ base
89 ^ ".conf"));
90 ignore (OS.Process.system (Config.rm
91 ^ " -rf "
92 ^ Config.Webalizer.outputDir
93 ^ "/"
5e70d4e2
AC
94 ^ Slave.hostname ()
95 ^ "/"
7f75d838
AC
96 ^ base)))
97 | _ =>
98 (ignore (OS.Process.system (Config.cp
99 ^ " "
100 ^ #file fs
101 ^ " "
102 ^ Config.Webalizer.configDir
103 ^ "/"
5e70d4e2
AC
104 ^ Slave.hostname ()
105 ^ "/"
7f75d838
AC
106 ^ base
107 ^ ".conf"));
108 let
5e70d4e2 109 val dir = Config.Webalizer.outputDir ^ "/" ^ Slave.hostname () ^ "/" ^ base
7f75d838
AC
110 in
111 if Posix.FileSys.access (dir, []) then
112 ()
113 else
6bacfc5d 114 OS.FileSys.mkDir dir
7f75d838
AC
115 end))
116 | _ => ()
117 end)
118
71420f8b
AC
119val () = Domain.registerResetLocal (fn () =>
120 app (fn (node, _) =>
121 ignore (OS.Process.system (Config.rm ^ " -rf "
122 ^ Config.Webalizer.configDir ^ "/"
123 ^ node ^ "/*"))) Config.nodeIps)
124
7f75d838 125end