74 lines
2.0 KiB
Ruby
74 lines
2.0 KiB
Ruby
# = ildus/server/backend - generic server backend library
|
|
#
|
|
# Copyright (C) 2005 Paul van Tilburg <paul@luon.net>
|
|
#
|
|
# Ildus is free software; you can redistribute it and/or modify it under
|
|
# the terms of the GNU General Public License as published by the Free
|
|
# Software Foundation; either version 2 of the License, or (at your option)
|
|
# any later version.
|
|
|
|
require 'ldap'
|
|
|
|
module Ildus::Server::Backend
|
|
|
|
class LDAPv3 < Basic
|
|
|
|
def initialize(*args)
|
|
super
|
|
@ldap = LDAP::Conn.new(config['host'])
|
|
@ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
|
|
@ldap.simple_bind(config['user'], config['pass'])
|
|
end
|
|
|
|
def authenticate
|
|
## STUB
|
|
@auth = (@pass == "foo")
|
|
##
|
|
end
|
|
|
|
def hosts
|
|
entries = Hash.new { |h, k| h[k] = [[], []] }
|
|
|
|
all_entries.each do |entry|
|
|
assoc_dom, a_rr, aaaa_rr, cname_rr =
|
|
["associatedDomain", "aRecord",
|
|
"aAAArecord", "cNAMErecord"].map { |attr| entry[attr] }
|
|
host = assoc_dom.first.gsub(/\.#{config['domain']}$/, '')
|
|
|
|
entries[host].first.push(*a_rr) if a_rr
|
|
entries[host].first.push(*aaaa_rr) if aaaa_rr
|
|
if cname_rr
|
|
cname = cname_rr.first.gsub(/\.#{config['domain']}$/, '')
|
|
entries[cname].last << host
|
|
end
|
|
end # search
|
|
|
|
return entries
|
|
end # def hosts
|
|
|
|
def update_host(host, addr)
|
|
entry = all_entries.find do |entry|
|
|
entry['associatedDomain'][0] == host + "." + config['domain']
|
|
end
|
|
raise Handler::HostNotFoundError if entry.nil?
|
|
|
|
if addr.ipv4?
|
|
@ldap.modify(entry['dn'][0], {"aRecord" => [addr.to_s]})
|
|
elsif addr.ipv6?
|
|
@ldap.modify(entry['dn'][0], {"aAAARecord" => [addr.to_s]})
|
|
end
|
|
end
|
|
|
|
#########
|
|
private
|
|
#########
|
|
|
|
def all_entries
|
|
@ldap.search2(config['base'], LDAP::LDAP_SCOPE_SUBTREE,
|
|
"(&(objectClass=ildusRecord)(ildusOwner=#{user}))")
|
|
end
|
|
|
|
end # class LDAPv3
|
|
|
|
end # module Ildus::Server::Backend
|