From c88bc35f1c88d9fbbba6706a4abaad24a1868c98 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 18 Oct 2006 11:33:32 +0000 Subject: Add hosting ldap git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@190 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- bin/ldap.add.mail.localperson | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 bin/ldap.add.mail.localperson (limited to 'bin/ldap.add.mail.localperson') diff --git a/bin/ldap.add.mail.localperson b/bin/ldap.add.mail.localperson new file mode 100755 index 0000000..053e4c9 --- /dev/null +++ b/bin/ldap.add.mail.localperson @@ -0,0 +1,70 @@ +#!/usr/bin/ruby + +# +# Copyright (c) 2004 Peter Palfrader +# +# All rights reserved. +# + +require "ldap" +require "getoptlong" +require "myldap" +require "yaml" +require 'optparse' + +config = YAML::load( File.open( '/etc/noreply/config' ) ) + +@local = [] +@hosts = [] +@password = [File.new("/dev/urandom").read(config['module']['mail']['pwlen'])].pack("m").chomp.delete('=') + +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("-a", "--accountname=name" , String, "Accountname (client.)") { |@accountname| } + 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 @realname +show_help(ARGV.options, 1, STDERR) unless @local.length > 0 +show_help(ARGV.options, 1, STDERR) unless @accountname +@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', 'tnMailAccount'], + 'cn' => [ @realname ], + 'tnMailLocalAddress' => @local, + 'tnHost' => @hosts, + + 'tnMailMailboxAccountname' => [ "mail." + @clientname +"." +@accountname ], + 'tnMailVirtualAddress' => [ "mail." + @clientname +"." +@accountname +'@' + config['module']['mail']['virtualdomain'] ], + 'tnMailMailboxHomedir' => [ config['module']['mail']['basedir'] ], + 'tnMailMailboxLocation' => [ @clientname + '/' + @accountname + '/' ], + 'tnMailMailboxUID' => client['uidNumber'], + 'tnMailMailboxGID' => client['gidNumber'], + 'userPassword' => [ @password ] +} +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) -- cgit v1.2.3