| 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 {nodes, id, hostname} => |
| 28 | let |
| 29 | val fds = map (fn node => Domain.domainFile {node = node, |
| 30 | name = id ^ ".wbl"}) nodes |
| 31 | in |
| 32 | files := fds; |
| 33 | write := (fn s => app (fn fd => TextIO.output (fd, s)) fds); |
| 34 | !write "LogFile\t"; |
| 35 | !write Config.Apache.logDir; |
| 36 | !write "/"; |
| 37 | !write hostname; |
| 38 | !write "/access.log\nOutputDir\t"; |
| 39 | !write Config.Webalizer.outputDir; |
| 40 | !write "/"; |
| 41 | !write id; |
| 42 | !write "\nHostname\t"; |
| 43 | !write hostname; |
| 44 | !write "\nHideSite\t"; |
| 45 | !write hostname; |
| 46 | !write "\nHideReferrer\t"; |
| 47 | !write hostname; |
| 48 | !write "\n" |
| 49 | end) |
| 50 | |
| 51 | val () = Apache.registerPost |
| 52 | (fn () => app TextIO.closeOut (!files)) |
| 53 | |
| 54 | val () = Apache.registerAliaser |
| 55 | (fn hostname => |
| 56 | (!write "HideSite\t"; |
| 57 | !write hostname; |
| 58 | !write "\nHideReferrer\t"; |
| 59 | !write hostname; |
| 60 | !write "\n")) |
| 61 | |
| 62 | val () = Slave.registerFileHandler (fn fs => |
| 63 | let |
| 64 | val spl = OS.Path.splitDirFile (#file fs) |
| 65 | in |
| 66 | case OS.Path.splitBaseExt (#file spl) of |
| 67 | {base, ext = SOME "wbl"} => |
| 68 | (case #action fs of |
| 69 | Slave.Delete => |
| 70 | (ignore (OS.Process.system (Config.rm |
| 71 | ^ " -f " |
| 72 | ^ Config.Webalizer.configDir |
| 73 | ^ "/" |
| 74 | ^ base |
| 75 | ^ ".conf")); |
| 76 | ignore (OS.Process.system (Config.rm |
| 77 | ^ " -rf " |
| 78 | ^ Config.Webalizer.outputDir |
| 79 | ^ "/" |
| 80 | ^ base))) |
| 81 | | _ => |
| 82 | (ignore (OS.Process.system (Config.cp |
| 83 | ^ " " |
| 84 | ^ #file fs |
| 85 | ^ " " |
| 86 | ^ Config.Webalizer.configDir |
| 87 | ^ "/" |
| 88 | ^ base |
| 89 | ^ ".conf")); |
| 90 | let |
| 91 | val dir = Config.Webalizer.outputDir ^ "/" ^ base |
| 92 | in |
| 93 | if Posix.FileSys.access (dir, []) then |
| 94 | () |
| 95 | else |
| 96 | Posix.FileSys.mkdir (dir, Posix.FileSys.S.flags |
| 97 | [Posix.FileSys.S.iroth, |
| 98 | Posix.FileSys.S.ixoth, |
| 99 | Posix.FileSys.S.irwxu, |
| 100 | Posix.FileSys.S.irgrp, |
| 101 | Posix.FileSys.S.iwgrp]) |
| 102 | end)) |
| 103 | | _ => () |
| 104 | end) |
| 105 | |
| 106 | end |