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.vhost | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 bin/ldap.add.vhost (limited to 'bin/ldap.add.vhost') diff --git a/bin/ldap.add.vhost b/bin/ldap.add.vhost new file mode 100755 index 0000000..e6c169b --- /dev/null +++ b/bin/ldap.add.vhost @@ -0,0 +1,63 @@ +#!/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' ) ) + +@hosts = [] +@alias = [] + +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("-h", "--hostname=HOSTNAME", String, "vhostname") { |@vhostname| } + opts.on("-a", "--alias=HOSTNAME" , String, "aliasname") { |val| @alias << val } + opts.on("-w", "--webmaster=EMAIL" , String, "email address of webmaster/mistress") { |@webmaster| } + 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("-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 @vhostname +show_help(ARGV.options, 1, STDERR) unless @webmaster +@hosts.push(config['defaulthost']) unless @hosts.length > 0 + +ldap = MyLDAP.new(config) +client = ldap.verify_client(@clientname) + +data = { + 'objectclass' => ['top', 'tnWebVHost'], + 'tnWebVHostServerName' => [ @vhostname ], + 'tnWebVHostHomeDirectory' => [ @vhostname ], + 'tnMagicDNS' => [ @no_magic_dns ? "no" : "yes" ], + 'tnWebVHostWebmaster' => [ @webmaster ], + 'tnHost' => @hosts +} +data['tnWebVHostServerAlias'] = @alias if @alias.length > 0 +data['description'] = [@description] if @description + + +dn = "tnWebVHostServerName=%s,ou=vhosts,o=%s,ou=hosting,%s"%[@vhostname, @clientname, config['basedn']] + +puts dn +puts data.to_yaml +puts + +ldap.add(dn, data) -- cgit v1.2.3