diff options
author | Peter Palfrader <peter@palfrader.org> | 2009-12-23 09:42:48 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2009-12-23 09:42:48 +0000 |
commit | 7f7b77537cc4ce479b68fe510ffdd78bc7c45cad (patch) | |
tree | 580d9a4bb033ab1d00dc8f581be64f8b634865a0 /bin | |
parent | 95253d34969331bb99ea582f84b0224a063b6b86 (diff) |
Support multiple bind addresses
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@435 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/ldap2apache | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/bin/ldap2apache b/bin/ldap2apache index ef5a874..6085728 100755 --- a/bin/ldap2apache +++ b/bin/ldap2apache @@ -11,6 +11,7 @@ require "getoptlong" require "myldap" require "yaml" require "etc" +require 'ipaddr' @config = YAML::load( File.open( '/etc/noreply/config' ) ) ldap = MyLDAP.new(@config, "ldap2apache") @@ -48,6 +49,23 @@ def mkdir(dir, mode, uid, gid) end end +def make_vhostline(addresses, port) + line = [] + line << "<VirtualHost" + addresses.each do |addr| + ipaddr = IPAddr.new addr + if ipaddr.ipv4? + line << "#{ipaddr}:#{port}" + elsif ipaddr.ipv6? + line << "[#{ipaddr}]:#{port}" + else + throw "Unknown ip version/class" + end + end + line << ">" + return line.join(' ') +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]}" @@ -59,7 +77,8 @@ clients.each{ |c| mkdir(client_home+"/logs-for-stat", 02750, 0, gid) mkdir(client_home+"/pg" , 02750, @postgres_uid, gid) c['vhosts'].each{ |vhost| - bind = vhost['tnWebVHostBind'] ? vhost['tnWebVHostBind'][0] : @defaultbind + bind = vhost['tnWebVHostBind'] ? vhost['tnWebVHostBind'] : @defaultbind + bind = [ bind ] unless bind.kind_of?(Array) bindhttpport = vhost['tnWebVHostBindHTTPPort'] ? vhost['tnWebVHostBindHTTPPort'][0] : @defaultbindhttpport bindhttpsport = vhost['tnWebVHostBindHTTPSPort'] ? vhost['tnWebVHostBindHTTPSPort'][0] : @defaultbindhttpsport server_name = vhost['tnWebVHostServerName'][0] @@ -167,7 +186,7 @@ clients.each{ |c| STDERR.puts "Warning: #{crtfile} does not exist" unless FileTest.exists?(crtfile) STDERR.puts "Warning: #{keyfile} does not exist" unless FileTest.exists?(keyfile) - config << "<VirtualHost #{bind}:#{bindhttpsport}>" + config << make_vhostline(bind, bindhttpsport) config << " SSLEngine on" config << " SSLCertificateFile #{crtfile}" config << " SSLCertificateKeyFile #{keyfile}" @@ -177,7 +196,7 @@ clients.each{ |c| config << ' SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown' config << '' else - config << "<VirtualHost #{bind}:#{bindhttpport}>" + config << make_vhostline(bind, bindhttpport) end config << " ServerName #{server_name}" config << " ServerAlias #{server_aliases}" if server_aliases != "" @@ -328,7 +347,7 @@ clients.each{ |c| if ssl and http_ssl_upgrade config = [] - config << "<VirtualHost #{bind}:#{bindhttpport}>" + config << make_vhostline(bind, bindhttpport) config << " ServerName #{server_name}" config << " ServerAlias #{server_aliases}" if server_aliases != "" config << " ServerAdmin #{server_admin}" |