summaryrefslogtreecommitdiff
path: root/bin/ldap.add.mail.remoteperson
blob: 115b9e228e96702d6f9b7ed2f64e15e982d01145 (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
58
59
60
61
62
63
64
65
#!/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' ) )

@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)