summaryrefslogtreecommitdiff
path: root/bin/obsolete
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2006-10-18 12:31:44 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2006-10-18 12:31:44 +0000
commite2e1056c07c051aa3bcb37338a96407802e73f88 (patch)
treed878e55584ec42c4a6e63befb32e6c9ecbf75d9f /bin/obsolete
parentae756695380b11c9e07446303c66acc5c39ba6b9 (diff)
Move ldap2analog* to obsolete
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@198 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'bin/obsolete')
-rwxr-xr-xbin/obsolete/ldap2analog178
-rwxr-xr-xbin/obsolete/ldap2analog.rb207
2 files changed, 385 insertions, 0 deletions
diff --git a/bin/obsolete/ldap2analog b/bin/obsolete/ldap2analog
new file mode 100755
index 0000000..15b2bc6
--- /dev/null
+++ b/bin/obsolete/ldap2analog
@@ -0,0 +1,178 @@
+#!/usr/bin/perl -wT
+#
+# vim:set ts=4:
+# vim:set shiftwidth=4:
+
+=pod
+
+=head1 NAME
+
+ldap2analog - create analog config files
+
+=head1 SYNOPSIS
+
+ldap2apache [-vnshf]
+
+=head1 DESCRIPTION
+
+ldap2apache reads the configuration from LDAP and writes
+config files for analog
+
+=head1 OPTIONS
+
+=over
+
+=item -v
+
+Be verbose.
+
+=back
+
+=head1 AUTHOR
+
+Peter Palfrader E<lt>pp@3node.com<gt>
+
+=head1 FILES
+
+/etc/3node/ldap2apache
+
+=head1 REQUIREMENTS
+
+libxml-parser-perl, libxml-dumper-perl, libnet-ldap-perl, libhtml-template-perl
+
+=head1 SEE ALSO
+
+Dokumentation fuer Webhosting.
+
+=cut
+
+use strict;
+use Net::LDAP;
+use XML::Parser;
+use XML::Dumper;
+use HTML::Template;
+use Getopt::Long;
+use English;
+use Carp qw{cluck};
+
+$ENV{'PATH'} = '/bin:/usr/bin';
+delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
+
+my $TEMP_DIR_MODE = 03775;
+my $TEMP_DIR_GROUP = getgrnam('www-data')
+ or die ("$PROGRAM_NAME: Cannot get gid of data");
+
+my $PROGNAME = $0;
+my $CONFIG;
+{
+ my $parser = new XML::Parser(Style => 'Tree');
+ my $tree = $parser->parsefile('/etc/3node/ldap2analog');
+ my $dump = new XML::Dumper;
+ $CONFIG = $dump->xml2pl($tree);
+}
+
+
+Getopt::Long::config('bundling');
+if (!GetOptions (
+ 'v' => \$CONFIG->{'verbose'},
+ 'h' => \$CONFIG->{'help'},
+ )) {
+ die ("Usage: $PROGNAME [-vshfn]\n");
+};
+if ($CONFIG->{'help'}) {
+ print ("Usage: $PROGNAME [-vshfn]\n");
+ exit 0;
+};
+
+
+
+
+my $ldap = Net::LDAP->new($CONFIG->{'ldapserver'}) or
+ die ("$PROGNAME: Cannot create LDAP object: $@");
+
+my $code;
+if ($CONFIG->{'binddn'} ne '') {
+ $code = $ldap->bind(
+ dn => $CONFIG->{'binddn'},
+ password => $CONFIG->{'bindpw'});
+} else {
+ $code = $ldap->bind();
+};
+die "$PROGNAME: can't connect to ldap server '$CONFIG->{'ldapserver'}': ".$code->error."\n" if ($code->code);
+
+
+$code = $ldap->search(
+ filter => "(objectclass=$CONFIG->{'client_objectclass'})",
+ base => $CONFIG->{'basedn'},
+ timelimit => $CONFIG->{'timeout'}
+);
+die "$PROGNAME: Problem to search '(objectclass=$CONFIG->{'client_objectclass'})' in $CONFIG->{'basedn'}: ".$code->error."\n" if ($code->code);
+
+
+my %FILELIST;
+my @entries = $code->entries;
+for my $client (@entries) {
+ $code = $ldap->search(
+ filter => "(&(objectclass=$CONFIG->{'webvhost_objectclass'})(tnHost=$CONFIG->{'thishost'}))",
+ base => $client->dn,
+ timelimit => $CONFIG->{'timeout'}
+ );
+ if ($code->code) {
+ warn "$PROGNAME: Problem to search '(&(objectclass=$CONFIG->{'webvhost_objectclass'})(tnHost=$CONFIG->{'thishost'}))' in $client->dn: ".$code->error."\n";
+ next;
+ };
+
+ my $home_base = $client->get_value('homeDirectory');
+ my @vhosts = $code->entries;
+ for my $entry (@vhosts) {
+ my $host;
+ # FIXME - check whether we serve this domain at this server
+
+ # *** ServerName
+ $host->{'ServerName'} = $entry->get_value('tnWebVHostServerName');
+
+ my $log_dir = $home_base . '/logs';
+ $log_dir =~ s,//+,/,g;
+
+ $host->{'CombinedLog'} = $log_dir.'/'.$host->{'ServerName'}.'-combined.log*';
+ $host->{'TransferLog'} = $log_dir.'/'.$host->{'ServerName'}.'-access.log*';
+ $host->{'RefererLog'} = $log_dir.'/'.$host->{'ServerName'}.'-referer.log*';
+ $host->{'AgentLog'} = $log_dir.'/'.$host->{'ServerName'}.'-agent.log*';
+
+ for my $tool (qw{analog rmagic}) {
+ printf STDERR "Doing template magic for $tool at host $host->{'ServerName'}.\n" if $CONFIG->{'verbose'};
+
+ my $tmpl = HTML::Template->new(
+ filename => $CONFIG->{$tool.'template'},
+ strict => 0,
+ die_on_bad_params => 0
+ );
+ $tmpl->param( %$host );
+ my $new_config = $tmpl->output();
+
+ my $filename = $CONFIG->{$tool.'confdir'}.'/'.$host->{'ServerName'};
+ open (F, '>'.$filename) or
+ die ("Cannot open $filename\n");
+ print F $new_config;
+ close (F);
+ };
+ $FILELIST{$host->{'ServerName'}} = 1;
+ };
+};
+
+
+
+
+# Get rid of old zonefiles
+for my $tool (qw{analog rmagic}) {
+ opendir(DIR, $CONFIG->{$tool.'confdir'}) || die ("$PROGNAME: Cannot open dir ".$CONFIG->{$tool.'confdir'}.": $!\n");
+ my @files = grep { ! /^\./ } readdir (DIR);
+ closedir(DIR);
+ @files = grep { ! $FILELIST{$_} } @files;
+ for my $file (@files) {
+ ($file) = $file =~ /(.*)/; #untaint
+ unlink ($CONFIG->{$tool.'confdir'}.'/'.$file) || warn ("Cannot unlink $file: $!\n");
+ };
+};
+
+$ldap->unbind;
diff --git a/bin/obsolete/ldap2analog.rb b/bin/obsolete/ldap2analog.rb
new file mode 100755
index 0000000..5335360
--- /dev/null
+++ b/bin/obsolete/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
+ }
+}