summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2006-10-18 12:22:51 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2006-10-18 12:22:51 +0000
commit9b6e1b33896a4fd5cfcfb42f3223e3e1b346f8b7 (patch)
tree8fb6eaf9f8fca98f12edd0150ec51c5731e99856
parente35019e3d0f3a0ad2e11e0eda79769b2f4f9dbfa (diff)
Add squat's ldap2analog.rb
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@192 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-rwxr-xr-xbin/ldap2analog.rb207
1 files changed, 207 insertions, 0 deletions
diff --git a/bin/ldap2analog.rb b/bin/ldap2analog.rb
new file mode 100755
index 0000000..5335360
--- /dev/null
+++ b/bin/ldap2analog.rb
@@ -0,0 +1,207 @@
+#!/usr/bin/ruby
+
+#
+# Copyright (c) 2004,2005 Florian Reitmeir <florian@reitmeir.org>
+# based on a script from Peter Palfrader <peter@palfrader.org>
+#
+# 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')
+@config_dir = @config['module']['analog']['config']
+@analog_dns = @config['module']['analog']['dns']
+@analog_caches = @config['module']['analog']['caches']
+@analog_output = @config['module']['analog']['output']
+@rmagic_dest = @config['module']['analog']['rmagic']
+
+@analog_common = <<EOF
+FILEEXCLUDE /web-stats/*
+FILEEXCLUDE /phpmyadmin/*
+ALL ON
+WARNINGS -MR
+TIMECOLS bRP
+WEEKCOLS bRP
+MONTHCOLS bRP
+WEEKCOLS bRP
+DAYREPCOLS bRP
+DAYSUMCOLS bRP
+HOURREPCOLS bRP
+HOURSUMCOLS bRP
+WEEKHOURCOLS bRP
+QUARTERREPCOLS bRP
+QUARTERSUMCOLS bRP
+FIVEREPCOLS bRP
+FIVESUMCOLS bRP
+HOSTCOLS DERSsPpQqBbCc
+ORGCOLS DERSsPpQqBbCc
+DOMCOLS NDERrSsPpQqBbCc
+DIRCOLS NDERrSsPpQqBbCc
+REFCOLS NDERrSsPpQqBbCc
+REFSITECOLS NDERrSsPpQqBbCc
+SEARCHQUERYCOLS NDERrSsPpQqBbCc
+SEARCHWORDCOLS NDERrSsPpQqBbCc
+INTSEARCHQUERYCOLS NDERrSsPpQqBbCc
+INTSEARCHWORDCOLS NDERrSsPpQqBbCc
+BROWREPCOLS NDERrSsPpQqBbCc
+BROWSUMCOLS NDERrSsPpQqBbCc
+OSCOLS NDERrSsPpQqBbCc
+VHOSTCOLS NDERrSsPpQqBbCc
+USERCOLS NDERrSsPpQqBbCc
+REQCOLS NDERrSspqBbCc
+TYPECOLS NDERrSsBbCc
+REDIRCOLS NDERrSs
+FAILCOLS NDERrSs
+REDIRHOSTCOLS NDERrSs
+FAILHOSTCOLS NDERrSs
+REDIRREFCOLS NDERrSs
+FAILREFCOLS NDERrSs
+REDIRVHOSTCOLS NDERrSs
+FAILVHOSTCOLS NDERrSs
+REDIRUSERCOLS NDERrSs
+FAILUSERCOLS NDERrSs
+STATUSCOLS DERrSs
+SIZECOLS DERrSsPpQqBbCc
+PROCTIMECOLS DERrSsPpQqBbCc
+EOF
+
+files = {}
+files['analog'] = {}
+files['rmagic'] = {}
+
+def mkdir(dir, mode, uid, gid)
+ Dir.mkdir(dir, mode) unless File.exists?(dir)
+# File.chown(uid, gid, dir) == 1 or throw "chown #{dir} failed"
+end
+
+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 << "LOGFILE none"
+ config << "LOGFILE " + client_home + "/logs-for-stat/" + server_name + "-access.*"
+
+ cache_file = @analog_caches + "/" + server_name + ".cache-%s"%(Time.now.strftime("%Y%m%d%S"))
+ cache_file_cur = @analog_caches + "/" + server_name + ".cache-current"
+ cache_file_old = @analog_caches + "/" + server_name + ".cache-old"
+ File.delete(cache_file_old) if File.exist?(cache_file_old)
+ File.rename(cache_file_cur, cache_file_old) if File.symlink?(cache_file_cur)
+ File.symlink(cache_file, cache_file_cur)
+
+ unless $force_rebuild then
+ config << "CACHEFILE " + cache_file_old
+ end
+ config << "CACHEOUTFILE " + cache_file
+ config << "HOSTNAME " + server_name
+ config << "HOSTURL " + "http://" + server_name + "/"
+ config << "OUTPUT COMPUTER"
+ config << "OUTFILE " + @analog_output + "/" + server_name + ".dat"
+ config << "DNS WRITE"
+ config << "DNSFILE " + @analog_dns + "/cachefile"
+
+ (vhost['tnWebVHostServerName']+(vhost['tnWebVHostServerAlias'] or [])).each { |host|
+ config << "REFREPEXCLUDE http://" + host + "/*"
+ }
+
+ (vhost['tnWebVHostServerAlias'] or []).each { |host|
+ config << "HOSTALIAS " + host + " " + server_name
+ }
+
+ config << "DNSLOCKFILE " + @analog_dns + "/cachefile.lock"
+ files['analog'][ server_name ] = config.join("\n") + "\n" + @analog_common
+
+ config = []
+ config << "[statistics]"
+ config << "File_In = " + @analog_output +"/"+ server_name + ".dat"
+ config << "Frame_File_Out = index.html"
+ config << "Reverse_Time = 1"
+ config << "Verbose=WE"
+ config << "Language=de"
+ config << ""
+ config << "[reports]"
+ config << "Active_Column=R"
+ #config << "GraphType = bar,pie"
+ config << "Font = Helvetica, sans-serif"
+ config << "Font = Helvetica, sans-serif"
+ config << "Font_Color = #000000"
+ config << "Title_Font = Helvetica"
+ config << "Title_BG_Color = #000000"
+ config << "Title_Font_Color = #FFFFFF"
+ config << "Data_Font = Helvetica"
+ config << "Data_Color_2=#EEEEEE"
+ config << "Data_Header_Color = #9999CC"
+ config << "Data_Total_Color = #CCCCCC"
+ config << "#--- "
+ config << "# Note how we use a directory (rather than a filename) to "
+ config << "# tell it to put each reports in a separate file."
+ config << "# (MAC: To use this change to ':manyfile:')"
+ config << "File_Out = " + @rmagic_dest +"/"+ server_name + "/"
+
+ config << ""
+ config << "[GENERAL]"
+ config << "Rows = ALL"
+ #config << "Rows = SR, PR, FL, RR, NF, NH, BT"
+
+ config << ""
+ config << "[navigation]"
+ config << "#Page_Font = Helvetica, sans-serif"
+ config << "#Page_Font_Color = #000000"
+ config << "#Page_BG_Color=#CCCCFF"
+ config << "File_Out = navfile.html"
+ config << ""
+ config << "[website]"
+ config << "Title = " + server_name + " Web Site Report"
+ config << "Webmaster = webmaster@multi24.com"
+ config << "Base_URL = http://" + server_name + "/"
+ files['rmagic'][ server_name ] = config.join("\n") + "\n"
+ }
+}
+
+Dir.entries( @rmagic_dest ).each{ |e|
+ next if ((e =~ /^\./) != nil)
+ next if files['rmagic'].has_key?( e )
+
+ FileUtils.rm Dir.glob(@rmagic_dest+'/'+e+'/*')
+ Dir.rmdir(@rmagic_dest+'/'+e)
+}
+%w(rmagic analog).each{ |tool|
+ Dir.entries( @config_dir + "/" + tool ).each{ |e|
+ next if ((e =~ /^\./) != nil)
+ next if files[tool].has_key?( e )
+ File.unlink( @config_dir + '/'+tool+'/' + e )
+ }
+
+ files[tool].each_pair{ |name, config|
+ filename = @config_dir + '/' +tool+ '/' + name
+ f = File.new( filename, "w" )
+ f.write(config)
+ f.close
+ }
+}