diff options
author | Peter Palfrader <peter@palfrader.org> | 2006-10-18 11:33:32 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2006-10-18 11:33:32 +0000 |
commit | c88bc35f1c88d9fbbba6706a4abaad24a1868c98 (patch) | |
tree | 487c31421b2f92e6e76bcf946500187b6b014e91 /bin/ldap.add.mail.remoteperson |
Add hosting ldap
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@190 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'bin/ldap.add.mail.remoteperson')
-rwxr-xr-x | bin/ldap.add.mail.remoteperson | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/bin/ldap.add.mail.remoteperson b/bin/ldap.add.mail.remoteperson new file mode 100755 index 0000000..5f3df3a --- /dev/null +++ b/bin/ldap.add.mail.remoteperson @@ -0,0 +1,65 @@ +#!/usr/bin/ruby + +# +# Copyright (c) 2004 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' ) ) + +@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("-n", "--name=Real Name" , String, "Person's full name") { |@realname| } + opts.on("-l", "--local=addr" , String, "Local Email Address (on this host)") { |val| @local << val } + opts.on("-r", "--remote=addr" , String, "Remote Email Address (where to forward to)") { |val| @remote << val } + 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 @realname +show_help(ARGV.options, 1, STDERR) unless @local.length > 0 +show_help(ARGV.options, 1, STDERR) unless @remote.length > 0 +@hosts.push(config['defaulthost']) unless @hosts.length > 0 + +ldap = MyLDAP.new(config) +client = ldap.verify_client(@clientname) +ldap.verify_local_domains_exist(@local) + +data = { + 'objectclass' => ['top', 'tnMailPerson', 'tnMailRemotePerson'], + 'cn' => [ @realname ], + 'tnMailLocalAddress' => @local, + 'tnHost' => @hosts, + + 'tnMailRemoteAddress' => @remote + +} +data['description'] = [@description] if @description + + +dn = "cn=%s,ou=people,ou=mail,o=%s,ou=hosting,%s"%[@realname, @clientname, config['basedn']] + +puts dn +puts data.to_yaml +puts + +ldap.add(dn, data) |