#!/usr/bin/ruby # # Copyright (c) 2004, 2006 Peter Palfrader # # All rights reserved. # require "ldap" require "optparse" require "myldap" require "yaml" config = YAML::load( File.open( '/etc/noreply/config' ) ) @password = [File.new("/dev/urandom").read(config['module']['uucp']['pwlen'])].pack("m").chomp.delete('=') @domainname = [] @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") { |val| @domainname << val } opts.on("-s", "--sysname=sysname" , String, "UUCP System Name") { |@sysname| } opts.on("-k", "--ssh-key=ssh-key" , String, "SSH Key") { |@sshkey| } 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("-p", "--password=PASSWORD" , String, "Password") { |@password| } 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.length > 0 show_help(ARGV.options, 1, STDERR) unless @sysname show_help(ARGV.options, 1, STDERR) unless @sshkey @hosts.push(config['defaulthost']) unless @hosts.length > 0 data = { 'objectclass' => ['top', 'tnUUCPSystem'], 'tnUUCPSysName' => [@sysname], 'tnUUCPPassword' => [@password], 'tnMagicDNS' => [ @no_magic_dns ? "no" : "yes" ], 'tnHost' => @hosts, 'tnMailDomainname' => @domainname, 'tnSSHKey' => [@sshkey], 'tnMailTransportDestination' => [ 'uucp:'+@sysname ] } data['description'] = [@description] if @description dn = "tnUUCPSysName=%s,ou=uucp,ou=mail,o=%s,ou=hosting,%s"%[@sysname, @clientname, config['basedn']] puts dn puts data.to_yaml puts ldap = MyLDAP.new(config) ldap.add(dn, data)