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