summaryrefslogtreecommitdiff
path: root/bin/ldap.add.pg
diff options
context:
space:
mode:
Diffstat (limited to 'bin/ldap.add.pg')
-rwxr-xr-xbin/ldap.add.pg60
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/ldap.add.pg b/bin/ldap.add.pg
new file mode 100755
index 0000000..1d53510
--- /dev/null
+++ b/bin/ldap.add.pg
@@ -0,0 +1,60 @@
+#!/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' ) )
+
+@password = [File.new("/dev/urandom").read(config['module']['pg']['pwlen'])].pack("m").chomp.delete('=')
+@sshkeys = []
+@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("-a", "--accountname=NAME" , String, "Account (base)name") { |@accountname| }
+ opts.on("-p", "--password=PASSWORD", String, "Password") { |@password| }
+ opts.on("-H", "--host=HOST" , String, "active host") { |val| @hosts.push(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 @accountname
+@hosts.push(config['defaulthost']) unless @hosts.length > 0
+
+ldap = MyLDAP.new(config)
+client = ldap.verify_client(@clientname)
+
+@accountname = @clientname+'_'+@accountname
+
+data = {
+ 'objectclass' => ['top', 'uidObject', 'simpleSecurityObject', 'tnPostgreSQLuser'],
+ 'uid' => [ @accountname ],
+ 'userPassword' => [ @password ],
+ 'tnHost' => @hosts
+
+}
+data['description'] = [@description] if @description
+
+dn = "uid=%s,ou=postgresql,o=%s,ou=hosting,%s"%[@accountname, @clientname, config['basedn']]
+
+puts dn
+puts data.to_yaml
+puts
+
+ldap.add(dn, data)