--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ma Fri Nov 04 06:29:26 2005 +0000
@@ -0,0 +1,163 @@
+#! /usr/bin/perl
+# Usage:
+# © 2005 Heiko Schlittermann <hs@schlittermann.de>
+# $URL$
+# $Id$
+#
+use constant USAGE => <<'#';
+Usage: !ME! account|alias --add|--list|--modify|--delete [options] [user|alias]
+ * common options *
+ --ldap_server=s LDAP-Server [!$Cf->ldap_server!]
+ --ldap_base=s LDAP-Basis [!$Cf->ldap_base!]
+ --ldap_admin=s LDAP BIND DN [!$Cf->ldap_admin!]
+ --ldap_password=s [!$Cf->ldap_password!]
+
+ --imap_server=s IMAP Server [!$Cf->imap_server!]
+ --imap_admin=s IMAP Server [!$Cf->imap_admin!]
+ --imap_password=s [!$Cf->imap_password!]
+
+ * account options *
+ --[no]mbox Create MBox [!$Cf->mbox!]
+ --imap_quota=i Mail Quota (MB) [!$Cf->imap_quota!]
+ --address=s Primary Mail [!$Cf->address!]
+ --other:s Alternative Mail addresses
+ (comma sep.) [!$Cf->other!]
+ --group:s Mail Group(s) this account is member of
+ (comma sep.) [!$Cf->group!]
+ --fullname=s Real Name [!$Cf->fullname!]
+ --password=s Passwort [!$Cf->password!]
+
+ * alias options *
+ --members=s List of Members [!$Cf->members!]
+
+Passwords for LDAP and IMAP can be read from environment LDAP_PASS resp. IMAP_PASS.
+Options can be read from config file named in $MA_CONF [!$ENV{MA_CONF}!].
+
+$Id$
+$URL$
+© 2005 Heiko Schlittermann <hs@schlittermann.de>
+
+#
+
+use strict;
+use warnings;
+
+use IO::File;
+use Cyrus::IMAP::Admin;
+use AppConfig qw(:expand);
+use File::Basename;
+use Carp;
+
+use lib qw(. /usr/local/lib/ma);
+use ldapBase;
+
+use constant ME => basename $0;
+use constant CONFIG => (
+ { CASE => 1 },
+ GLOBAL => { DEFAULT => undef },
+
+ # * common *
+ add => { ARGS => "!", ALIAS => [qw/new create/] },
+ list => { ARGS => "!", ALIAS => "ls" },
+ modify => { ARGS => "!", ALIAS => "change" },
+ delete => { ARGS => "!", ALIAS => "remove" },
+
+ ldap_base => { ARGS => "=s", DEFAULT => ldapBase(qw(/etc/openldap/ldap.conf /etc/ldap/ldap.conf)) },
+ ldap_server => { ARGS => "=s", DEFAULT => "localhost" },
+ ldap_bind_dn => { ARGS => "=s", DEFAULT => "cn=admin", ALIAS => "ldap_admin" },
+ ldap_password =>{ ARGS => "=s" },
+
+ help => { ARGS => "!" },
+ debug => { ARGS => "!" },
+
+
+ # * account *
+ imap_server => { ARGS => "=s", DEFAULT => "localhost" },
+ imap_admin => { ARGS => "=s", DEFAULT => $ENV{USER} },
+ imap_password =>{ ARGS => "=s" },
+ imap_quota => { ARGS => "=i", DEFAULT => 300, ALIAS => "quota" },
+
+ mbox => { ARGS => "!", DEFAULT => 1 },
+ password => { ARGS => "=s" },
+# internal => { ARGS => "!", DEFAULT => ":", ALIAS => "restricted" },
+
+ other => { ARGS => ":s" },
+ group => { ARGS => ":s" },
+ fullname => { ARGS => "=s", ALIAS => "realname" },
+ address => { ARGS => "=s", ALIAS => "primary" },
+
+ # * alias *
+ members => { ARGS => ":s" },
+
+ # * ldap intern *
+ ldap_ou_aliases => { ARGS => "=s", DEFAULT => "ou=MailAliases" },
+ ldap_ou_accounts => { ARGS => "=s", DEFAULT => "ou=MailAccounts" },
+
+ ldap_oc_alias => { ARGS => "=s", DEFAULT => "XXXmailAlias" },
+ ldap_oc_recipient => { ARGS => "=s", DEFAULT => "XXXmailRecipient" },
+
+ ldap_at_address => { ARGS => "=s", DEFAULT => "XXXmailAddress" },
+ ldap_at_group => { ARGS => "=s", DEFAULT => "XXXmailGroup" },
+ ldap_at_forwardingaddress =>
+ { ARGS => "=s", DEFAULT => "XXXmailForwardingAddress" },
+ ldap_at_primaryaddress =>
+ { ARGS => "=s", DEFAULT => "XXXmailPrimaryAddress" },
+
+);
+our $Cf;
+
+sub help();
+
+my $Module = shift if @ARGV && $ARGV[0] !~ /^-/;
+ $Module ||= "UNKNOWN";
+
+
+$SIG{__DIE__} = sub { die "\n".ME.": ", @_ };
+
+
+MAIN: {
+
+ $Cf = new AppConfig CONFIG or die;
+
+ if (exists $ENV{MA_CONF} and -f $ENV{MA_CONF}) {
+ my $f = $ENV{MA_CONF};
+ die ": $f is group/world readable/writeable\n" if 077 & (stat _)[2];
+ $Cf->file($f) or die;
+ }
+ $Cf->getopt(\@ARGV) or die "Bad Usage. Try --help.\n";
+
+ die "Need ldap base.\n" if not $Cf->ldap_base;
+ if ($Cf->ldap_admin !~ /\Q$Cf->ldap_base/) {
+ $Cf->ldap_admin($Cf->ldap_admin . "," . $Cf->ldap_base);
+ }
+
+ print help() and exit 0 if $Cf->help;
+
+ @_ = grep { $_ =~ /^\Q$Module\E/ } qw/account alias/;
+ die "Need module. Try --help\n" if @_ == 0;
+ die "Module ambigous. (@_)\n" if @_ > 1;
+
+ if ($_[0] eq 'account') {
+ require account;
+ account::import($Cf);
+ account::run();
+ } elsif ($_[0] eq 'alias') {
+ require alias;
+ alias::import($Cf);
+ alias::run();
+ } else {
+ die "Shit";
+ }
+
+}
+
+sub verbose(@) {
+ print STDERR @_;
+}
+
+sub help() {
+ ($_ = USAGE) =~ s/!(.*?)!/(eval $1) || ""/eg;
+ return $_;
+}
+
+# vim:sts=4 sw=4 aw ai sm nohlsearch incsearch: