From: Adam Chlipala Date: Sat, 26 Aug 2006 23:32:36 +0000 (+0000) Subject: Webalizer X-Git-Tag: release_2010-11-19~358 X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/commitdiff_plain/7f75d83853b6dfe8b63ff78130b7107ce8af21a8 Webalizer --- diff --git a/configDefault/webalizer.cfg b/configDefault/webalizer.cfg new file mode 100644 index 0000000..256f8ff --- /dev/null +++ b/configDefault/webalizer.cfg @@ -0,0 +1,6 @@ +structure Webalizer :> WEBALIZER_CONFIG = struct + +val configDir = "/home/adamc/fake/webalizer" +val outputDir = "/home/adamc/fake/webalizerOut" + +end diff --git a/configDefault/webalizer.cfs b/configDefault/webalizer.cfs new file mode 100644 index 0000000..a76556e --- /dev/null +++ b/configDefault/webalizer.cfs @@ -0,0 +1 @@ +structure Webalizer : WEBALIZER_CONFIG diff --git a/configDefault/webalizer.csg b/configDefault/webalizer.csg new file mode 100644 index 0000000..360be67 --- /dev/null +++ b/configDefault/webalizer.csg @@ -0,0 +1,6 @@ +signature WEBALIZER_CONFIG = sig + + val configDir : string + val outputDir : string + +end diff --git a/src/domtool.cm b/src/domtool.cm index 7e4cb0a..1210624 100644 --- a/src/domtool.cm +++ b/src/domtool.cm @@ -62,6 +62,9 @@ plugins/bind.sml plugins/apache.sig plugins/apache.sml +plugins/webalizer.sig +plugins/webalizer.sml + order.sig order.sml diff --git a/src/plugins/apache.sig b/src/plugins/apache.sig index da69e65..f4142fd 100644 --- a/src/plugins/apache.sig +++ b/src/plugins/apache.sig @@ -20,4 +20,13 @@ signature APACHE = sig + val registerPre : ({nodes : string list, id : string, hostname : string} -> unit) -> unit + (* Register a callback for the beginning of a vhost block. *) + + val registerPost : (unit -> unit) -> unit + (* Register a callback for the end of a vhost block. *) + + val registerAliaser : (string -> unit) -> unit + (* Register a callback for an alternate hostname that is configured. *) + end diff --git a/src/plugins/apache.sml b/src/plugins/apache.sml index 1f61476..3550166 100644 --- a/src/plugins/apache.sml +++ b/src/plugins/apache.sml @@ -182,11 +182,18 @@ val () = Slave.registerFileHandler (fn fs => (vhostsChanged := true; case #action fs of Slave.Delete => - ignore (OS.Process.system (Config.rm - ^ " -rf " - ^ Config.Apache.confDir - ^ "/" - ^ #file spl)) + (ignore (OS.Process.system (Config.rm + ^ " -rf " + ^ Config.Apache.confDir + ^ "/" + ^ #file spl)); + ignore (OS.Process.system (Config.rm + ^ " -rf " + ^ Config.Apache.logDir + ^ "/" + ^ #base (OS.Path.splitBaseExt + (#file spl))))) + | _ => ignore (OS.Process.system (Config.cp ^ " " @@ -214,6 +221,30 @@ val rewriteEnabled = ref false val currentVhost = ref "" val currentVhostId = ref "" +val pre = ref (fn _ : {nodes : string list, id : string, hostname : string} => ()) +fun registerPre f = + let + val old = !pre + in + pre := (fn x => (old x; f x)) + end + +val post = ref (fn () => ()) +fun registerPost f = + let + val old = !post + in + post := (fn () => (old (); f ())) + end + +val aliaser = ref (fn _ : string => ()) +fun registerAliaser f = + let + val old = !aliaser + in + aliaser := (fn x => (old x; f x)) + end + val () = Env.containerV_one "vhost" ("host", Env.string) (fn (env, host) => @@ -268,9 +299,11 @@ val () = Env.containerV_one "vhost" write Config.Apache.logDir; write "/"; write vhostId; - write "/access.log combined\n" + write "/access.log combined\n"; + !pre {nodes = nodes, id = vhostId, hostname = fullHost} end, - fn () => (write "\n"; + fn () => (!post (); + write "\n"; app TextIO.closeOut (!vhostFiles))) val () = Env.container_one "location" @@ -438,7 +471,8 @@ val () = Env.action_one "serverAlias" (fn host => (write "\tServerAlias "; write host; - write "\n")) + write "\n"; + !aliaser host)) val authType = fn (EVar "basic", _) => SOME "basic" | (EVar "digest", _) => SOME "digest" diff --git a/src/plugins/webalizer.sig b/src/plugins/webalizer.sig new file mode 100644 index 0000000..25eb7b2 --- /dev/null +++ b/src/plugins/webalizer.sig @@ -0,0 +1,23 @@ +(* HCoop Domtool (http://hcoop.sourceforge.net/) + * Copyright (c) 2006, Adam Chlipala + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + *) + +(* Webalizer statistics tool handling *) + +signature WEBALIZER = sig + +end diff --git a/src/plugins/webalizer.sml b/src/plugins/webalizer.sml new file mode 100644 index 0000000..f88f2ff --- /dev/null +++ b/src/plugins/webalizer.sml @@ -0,0 +1,106 @@ +(* HCoop Domtool (http://hcoop.sourceforge.net/) + * Copyright (c) 2006, Adam Chlipala + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + *) + +(* Webalizer statistics tool handling *) + +structure Webalizer :> WEBALIZER = struct + +val files = ref ([] : TextIO.outstream list) +val write = ref (fn _ : string => ()) + +val () = Apache.registerPre + (fn {nodes, id, hostname} => + let + val fds = map (fn node => Domain.domainFile {node = node, + name = id ^ ".wbl"}) nodes + in + files := fds; + write := (fn s => app (fn fd => TextIO.output (fd, s)) fds); + !write "LogFile\t"; + !write Config.Apache.logDir; + !write "/"; + !write hostname; + !write "/access.log\nOutputDir\t"; + !write Config.Webalizer.outputDir; + !write "/"; + !write id; + !write "\nHostname\t"; + !write hostname; + !write "\nHideSite\t"; + !write hostname; + !write "\nHideReferrer\t"; + !write hostname; + !write "\n" + end) + +val () = Apache.registerPost + (fn () => app TextIO.closeOut (!files)) + +val () = Apache.registerAliaser + (fn hostname => + (!write "HideSite\t"; + !write hostname; + !write "\nHideReferrer\t"; + !write hostname; + !write "\n")) + +val () = Slave.registerFileHandler (fn fs => + let + val spl = OS.Path.splitDirFile (#file fs) + in + case OS.Path.splitBaseExt (#file spl) of + {base, ext = SOME "wbl"} => + (case #action fs of + Slave.Delete => + (ignore (OS.Process.system (Config.rm + ^ " -f " + ^ Config.Webalizer.configDir + ^ "/" + ^ base + ^ ".conf")); + ignore (OS.Process.system (Config.rm + ^ " -rf " + ^ Config.Webalizer.outputDir + ^ "/" + ^ base))) + | _ => + (ignore (OS.Process.system (Config.cp + ^ " " + ^ #file fs + ^ " " + ^ Config.Webalizer.configDir + ^ "/" + ^ base + ^ ".conf")); + let + val dir = Config.Webalizer.outputDir ^ "/" ^ base + in + if Posix.FileSys.access (dir, []) then + () + else + Posix.FileSys.mkdir (dir, Posix.FileSys.S.flags + [Posix.FileSys.S.iroth, + Posix.FileSys.S.ixoth, + Posix.FileSys.S.irwxu, + Posix.FileSys.S.irgrp, + Posix.FileSys.S.iwgrp]) + end)) + | _ => () + end) + +end