Changing Apache log and Webalizer stuff
[hcoop/domtool2.git] / src / plugins / webalizer.sml
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
21 structure Webalizer :> WEBALIZER = struct
22
23 val files = ref ([] : TextIO.outstream list)
24 val write = ref (fn _ : string => ())
25
26 val () = Apache.registerPre
27 (fn {user, nodes, id, hostname} =>
28 let
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);
36 TextIO.output (fd, "/apache/log/");
37 TextIO.output (fd, node);
38 TextIO.output (fd, hostname);
39 TextIO.output (fd, "/access.log\nOutputDir\t");
40 TextIO.output (fd, Config.Webalizer.outputDir);
41 TextIO.output (fd, "/");
42 TextIO.output (fd, node);
43 TextIO.output (fd, "/");
44 TextIO.output (fd, id);
45 TextIO.output (fd, "\n");
46 fd
47 end) nodes
48 in
49 files := fds;
50 write := (fn s => app (fn fd => TextIO.output (fd, s)) fds);
51 !write "Hostname\t";
52 !write hostname;
53 !write "\nHideSite\t";
54 !write hostname;
55 !write "\nHideReferrer\t";
56 !write hostname;
57 !write "\n"
58 end)
59
60 val () = Apache.registerPost
61 (fn () => app TextIO.closeOut (!files))
62
63 val () = Apache.registerAliaser
64 (fn hostname =>
65 (!write "HideSite\t";
66 !write hostname;
67 !write "\nHideReferrer\t";
68 !write hostname;
69 !write "\n"))
70
71 val () = Slave.registerFileHandler (fn fs =>
72 let
73 val spl = OS.Path.splitDirFile (#file fs)
74 in
75 case OS.Path.splitBaseExt (#file spl) of
76 {base, ext = SOME "wbl"} =>
77 (case #action fs of
78 Slave.Delete =>
79 (ignore (OS.Process.system (Config.rm
80 ^ " -f "
81 ^ Config.Webalizer.configDir
82 ^ "/"
83 ^ base
84 ^ ".conf"));
85 ignore (OS.Process.system (Config.rm
86 ^ " -rf "
87 ^ Config.Webalizer.outputDir
88 ^ "/"
89 ^ base)))
90 | _ =>
91 (ignore (OS.Process.system (Config.cp
92 ^ " "
93 ^ #file fs
94 ^ " "
95 ^ Config.Webalizer.configDir
96 ^ "/"
97 ^ base
98 ^ ".conf"));
99 let
100 val dir = Config.Webalizer.outputDir ^ "/" ^ base
101 in
102 if Posix.FileSys.access (dir, []) then
103 ()
104 else
105 Posix.FileSys.mkdir (dir, Posix.FileSys.S.flags
106 [Posix.FileSys.S.iroth,
107 Posix.FileSys.S.ixoth,
108 Posix.FileSys.S.irwxu,
109 Posix.FileSys.S.irgrp,
110 Posix.FileSys.S.iwgrp])
111 end))
112 | _ => ()
113 end)
114
115 end