#!/usr/bin/ruby # # Copyright (c) 2004, 2006 Peter Palfrader # # All rights reserved. # require "ldap" require "getoptlong" require "myldap" require "yaml" require 'optparse' config = YAML::load( File.open( '/etc/noreply/config' ) ) @local = [] @remote = [] @hosts = [] 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", "--no-magic-dns" , String, "Turn off Magic DNS") { @no_magic_dns = true } opts.on("-H", "--host=HOST" , String, "active host") { |val| @hosts << 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 @hosts.push(config['defaulthost']) unless @hosts.length > 0 @localaddresses = [] %w(postmaster hostmaster abuse security root).each{ |l| @localaddresses << l+"@"+@domainname } ldap = MyLDAP.new(config) client = ldap.verify_client(@clientname) data = { 'objectclass' => ['top', 'tnMailDomain', 'tnMailRemotePerson'], 'tnMailDomainname' => [ @domainname ], 'tnMagicDNS' => [ @no_magic_dns ? "no" : "yes" ], 'tnHost' => @hosts, 'tnMailLocalAddress' => @localaddresses, 'tnMailRemoteAddress' => ['roles'] } data['description'] = [@description] if @description dn = "tnMailDomainname=%s,ou=domains,ou=mail,o=%s,ou=hosting,%s"%[@domainname, @clientname, config['basedn']] puts dn puts data.to_yaml puts ldap.add(dn, data)