summaryrefslogtreecommitdiff
path: root/bin/ldap.add.dns.secondary
blob: 9a881c8209608f3d14065be4639fc307c71ff553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/ruby

#
# Copyright (c) 2004, 2006 Peter Palfrader <peter@palfrader.org>
#
# All rights reserved.
#

require "ldap"
require "getoptlong"
require "myldap"
require "yaml"
require 'optparse'

config = YAML::load( File.open( '/etc/noreply/config' ) )

@nss = []

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("-c", "--client=CLIENT"      , String, "Client Identifier")                            { |@clientname| }
  opts.on("-d", "--domain=domain"      , String, "Domain name")                                  { |@domainname| }
  opts.on("-m", "--master=master"      , String, "IP of Master")                                 { |@master| }
  opts.on("-n", "--ns=ns"              , String, "our Namservers that are slaves")               { |val| @nss << val }
  opts.on("-D", "--description=BLA"    , String, "description")                                  { |@description| }
  opts.parse!
end

show_help(ARGV.options, 1, STDERR) if ARGV.length > 0
show_help(ARGV.options, 1, STDERR) unless @clientname
show_help(ARGV.options, 1, STDERR) unless @domainname
show_help(ARGV.options, 1, STDERR) unless @master
@nss = config['module']['bind']['nameservers'] unless @nss.length > 0

ldap = MyLDAP.new(config)
client = ldap.verify_client(@clientname)

data = {
	'objectclass'			=> ['top', 'tnDNSsecondary'],
	'tnDNSdomainname'		=> [ @domainname ],
	'tnDNSprimary'			=> [ @master ],
	'tnDNSnameservers'		=> @nss
}
data['description'] = [@description] if @description


dn = "tnDNSdomainname=%s,ou=dns-slaves,o=%s,ou=hosting,%s"%[@domainname, @clientname, config['basedn']]

puts dn
puts data.to_yaml
puts

ldap.add(dn, data)