| 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, Apache.logDir {user = user, node = node, vhostId = hostname}); |
| 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 |
| 45 | in |
| 46 | files := fds; |
| 47 | write := (fn s => app (fn fd => TextIO.output (fd, s)) fds); |
| 48 | !write "HostName\t"; |
| 49 | !write hostname; |
| 50 | !write "\nHideSite\t"; |
| 51 | !write hostname; |
| 52 | !write "\nHideReferrer\t"; |
| 53 | !write hostname; |
| 54 | !write "\n" |
| 55 | end) |
| 56 | |
| 57 | val () = Apache.registerPost |
| 58 | (fn () => app TextIO.closeOut (!files)) |
| 59 | |
| 60 | val () = Apache.registerAliaser |
| 61 | (fn hostname => |
| 62 | (!write "HideSite\t"; |
| 63 | !write hostname; |
| 64 | !write "\nHideReferrer\t"; |
| 65 | !write hostname; |
| 66 | !write "\n")) |
| 67 | |
| 68 | val () = 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"} => |
| 74 | (case #action fs of |
| 75 | Slave.Delete => |
| 76 | (ignore (OS.Process.system (Config.rm |
| 77 | ^ " -f " |
| 78 | ^ Config.Webalizer.configDir |
| 79 | ^ "/" |
| 80 | ^ Slave.hostname () |
| 81 | ^ "/" |
| 82 | ^ base |
| 83 | ^ ".conf")); |
| 84 | ignore (OS.Process.system (Config.rm |
| 85 | ^ " -rf " |
| 86 | ^ Config.Webalizer.outputDir |
| 87 | ^ "/" |
| 88 | ^ Slave.hostname () |
| 89 | ^ "/" |
| 90 | ^ base))) |
| 91 | | _ => |
| 92 | (ignore (OS.Process.system (Config.cp |
| 93 | ^ " " |
| 94 | ^ #file fs |
| 95 | ^ " " |
| 96 | ^ Config.Webalizer.configDir |
| 97 | ^ "/" |
| 98 | ^ Slave.hostname () |
| 99 | ^ "/" |
| 100 | ^ base |
| 101 | ^ ".conf")); |
| 102 | let |
| 103 | val dir = Config.Webalizer.outputDir ^ "/" ^ Slave.hostname () ^ "/" ^ base |
| 104 | in |
| 105 | if Posix.FileSys.access (dir, []) then |
| 106 | () |
| 107 | else |
| 108 | OS.FileSys.mkDir dir |
| 109 | end)) |
| 110 | | _ => () |
| 111 | end) |
| 112 | |
| 113 | val () = Domain.registerResetLocal (fn () => |
| 114 | app (fn (node, _) => |
| 115 | ignore (OS.Process.system (Config.rm ^ " -rf " |
| 116 | ^ Config.Webalizer.configDir ^ "/" |
| 117 | ^ node ^ "/*"))) Config.nodeIps) |
| 118 | |
| 119 | val () = Domain.registerDescriber (Domain.considerAll |
| 120 | [Domain.Extension {extension = "wbl", |
| 121 | heading = fn host => "Webalizer config for " ^ host}]) |
| 122 | |
| 123 | end |