From 7a588d8a3cce20348793ea8cccee570a34e9e141 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 18 Oct 2006 12:28:16 +0000 Subject: Add squat's ldap2awstats git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@194 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- bin/ldap2awstats | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 bin/ldap2awstats diff --git a/bin/ldap2awstats b/bin/ldap2awstats new file mode 100755 index 0000000..7883c54 --- /dev/null +++ b/bin/ldap2awstats @@ -0,0 +1,76 @@ +#!/usr/bin/ruby + +# +# Copyright (c) 2004,2005 Florian Reitmeir +# based on a script from Peter Palfrader +# +# All rights reserved. +# +# MIT license. +# + +require "ldap" +require "getoptlong" +require "myldap" +require "yaml" +require "fileutils" +require "optparse" + +# defaults +$force_rebuild = false + +def show_help(parser, code=0, io=STDOUT) + io.puts parser + exit(code) +end +ARGV.options do |opts| + opts.on_tail("-h", "--help", "Display this help screen") { show_help(opts) } + opts.on("-f", "--force" , String, "Force rebuilding the cachefiles") { $force_rebuild = true } + opts.parse! +end + +@config = YAML::load( File.open( '/etc/noreply/config' ) ) +ldap = MyLDAP.new(@config, "ldap2apache") +clients = ldap.conn.search2(@config['basedn'], LDAP::LDAP_SCOPE_SUBTREE, 'objectclass=tnClient') + +files = {} + +clients.each{ |c| + c['vhosts'] = ldap.conn.search2(c['dn'][0], LDAP::LDAP_SCOPE_SUBTREE, '(&(objectclass=tnWebVHost)(tnHost='+@config['thishost']+'))') + client_home = c['homeDirectory'][0] or throw "No home for #{d['dn'][0]}" + c['vhosts'].each{ |vhost| + server_name = vhost['tnWebVHostServerName'][0] + server_admin = vhost['tnWebVHostWebmaster'][0] + server_aliases = (vhost['tnWebVHostServerAlias'] or []).join(" ") + + config = [] + config << 'Include "/etc/awstats/awstats.conf"' + config << 'LogFile="zcat '+client_home+'/logs-archive/'+server_name+'-access*gz |"' + config << 'SiteDomain="'+server_name+'"' + config << 'HostAliases="'+server_aliases+' '+server_name+'"' + + files[ 'awstats.'+server_name+'.conf' ] = config.join("\n") + "\n" + } +} + +Dir.entries( '/etc/awstats/' ).each{ |e| + next if ((e =~ /^\./) != nil) + next if ((e =~ /^awstats.conf/) != nil) + + filename = '/etc/awstats/' + e + + unless files.has_key?(e) then + File.unlink(filename) + end +} + +files.each_pair{ |file, conf| + filename = '/etc/awstats/' + file + + on_disk = FileTest.exists?(filename) ? File.read(filename) : nil + next if on_disk == conf + f = File.new( filename, "w" ) + f.write(conf) + f.close + +} -- cgit v1.2.3