summaryrefslogtreecommitdiff
path: root/bin/ldap2apache
diff options
context:
space:
mode:
Diffstat (limited to 'bin/ldap2apache')
-rwxr-xr-xbin/ldap2apache27
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}"