|
1 #! /usr/bin/perl |
|
2 # Usage: |
|
3 # © 2005 Heiko Schlittermann <hs@schlittermann.de> |
|
4 # $URL$ |
|
5 # $Id$ |
|
6 # |
|
7 use constant USAGE => <<'#'; |
|
8 Usage: !ME! account|alias --add|--list|--modify|--delete [options] [user|alias] |
|
9 * common options * |
|
10 --ldap_server=s LDAP-Server [!$Cf->ldap_server!] |
|
11 --ldap_base=s LDAP-Basis [!$Cf->ldap_base!] |
|
12 --ldap_admin=s LDAP BIND DN [!$Cf->ldap_admin!] |
|
13 --ldap_password=s [!$Cf->ldap_password!] |
|
14 |
|
15 --imap_server=s IMAP Server [!$Cf->imap_server!] |
|
16 --imap_admin=s IMAP Server [!$Cf->imap_admin!] |
|
17 --imap_password=s [!$Cf->imap_password!] |
|
18 |
|
19 * account options * |
|
20 --[no]mbox Create MBox [!$Cf->mbox!] |
|
21 --imap_quota=i Mail Quota (MB) [!$Cf->imap_quota!] |
|
22 --address=s Primary Mail [!$Cf->address!] |
|
23 --other:s Alternative Mail addresses |
|
24 (comma sep.) [!$Cf->other!] |
|
25 --group:s Mail Group(s) this account is member of |
|
26 (comma sep.) [!$Cf->group!] |
|
27 --fullname=s Real Name [!$Cf->fullname!] |
|
28 --password=s Passwort [!$Cf->password!] |
|
29 |
|
30 * alias options * |
|
31 --members=s List of Members [!$Cf->members!] |
|
32 |
|
33 Passwords for LDAP and IMAP can be read from environment LDAP_PASS resp. IMAP_PASS. |
|
34 Options can be read from config file named in $MA_CONF [!$ENV{MA_CONF}!]. |
|
35 |
|
36 $Id$ |
|
37 $URL$ |
|
38 © 2005 Heiko Schlittermann <hs@schlittermann.de> |
|
39 |
|
40 # |
|
41 |
|
42 use strict; |
|
43 use warnings; |
|
44 |
|
45 use IO::File; |
|
46 use Cyrus::IMAP::Admin; |
|
47 use AppConfig qw(:expand); |
|
48 use File::Basename; |
|
49 use Carp; |
|
50 |
|
51 use lib qw(. /usr/local/lib/ma); |
|
52 use ldapBase; |
|
53 |
|
54 use constant ME => basename $0; |
|
55 use constant CONFIG => ( |
|
56 { CASE => 1 }, |
|
57 GLOBAL => { DEFAULT => undef }, |
|
58 |
|
59 # * common * |
|
60 add => { ARGS => "!", ALIAS => [qw/new create/] }, |
|
61 list => { ARGS => "!", ALIAS => "ls" }, |
|
62 modify => { ARGS => "!", ALIAS => "change" }, |
|
63 delete => { ARGS => "!", ALIAS => "remove" }, |
|
64 |
|
65 ldap_base => { ARGS => "=s", DEFAULT => ldapBase(qw(/etc/openldap/ldap.conf /etc/ldap/ldap.conf)) }, |
|
66 ldap_server => { ARGS => "=s", DEFAULT => "localhost" }, |
|
67 ldap_bind_dn => { ARGS => "=s", DEFAULT => "cn=admin", ALIAS => "ldap_admin" }, |
|
68 ldap_password =>{ ARGS => "=s" }, |
|
69 |
|
70 help => { ARGS => "!" }, |
|
71 debug => { ARGS => "!" }, |
|
72 |
|
73 |
|
74 # * account * |
|
75 imap_server => { ARGS => "=s", DEFAULT => "localhost" }, |
|
76 imap_admin => { ARGS => "=s", DEFAULT => $ENV{USER} }, |
|
77 imap_password =>{ ARGS => "=s" }, |
|
78 imap_quota => { ARGS => "=i", DEFAULT => 300, ALIAS => "quota" }, |
|
79 |
|
80 mbox => { ARGS => "!", DEFAULT => 1 }, |
|
81 password => { ARGS => "=s" }, |
|
82 # internal => { ARGS => "!", DEFAULT => ":", ALIAS => "restricted" }, |
|
83 |
|
84 other => { ARGS => ":s" }, |
|
85 group => { ARGS => ":s" }, |
|
86 fullname => { ARGS => "=s", ALIAS => "realname" }, |
|
87 address => { ARGS => "=s", ALIAS => "primary" }, |
|
88 |
|
89 # * alias * |
|
90 members => { ARGS => ":s" }, |
|
91 |
|
92 # * ldap intern * |
|
93 ldap_ou_aliases => { ARGS => "=s", DEFAULT => "ou=MailAliases" }, |
|
94 ldap_ou_accounts => { ARGS => "=s", DEFAULT => "ou=MailAccounts" }, |
|
95 |
|
96 ldap_oc_alias => { ARGS => "=s", DEFAULT => "XXXmailAlias" }, |
|
97 ldap_oc_recipient => { ARGS => "=s", DEFAULT => "XXXmailRecipient" }, |
|
98 |
|
99 ldap_at_address => { ARGS => "=s", DEFAULT => "XXXmailAddress" }, |
|
100 ldap_at_group => { ARGS => "=s", DEFAULT => "XXXmailGroup" }, |
|
101 ldap_at_forwardingaddress => |
|
102 { ARGS => "=s", DEFAULT => "XXXmailForwardingAddress" }, |
|
103 ldap_at_primaryaddress => |
|
104 { ARGS => "=s", DEFAULT => "XXXmailPrimaryAddress" }, |
|
105 |
|
106 ); |
|
107 our $Cf; |
|
108 |
|
109 sub help(); |
|
110 |
|
111 my $Module = shift if @ARGV && $ARGV[0] !~ /^-/; |
|
112 $Module ||= "UNKNOWN"; |
|
113 |
|
114 |
|
115 $SIG{__DIE__} = sub { die "\n".ME.": ", @_ }; |
|
116 |
|
117 |
|
118 MAIN: { |
|
119 |
|
120 $Cf = new AppConfig CONFIG or die; |
|
121 |
|
122 if (exists $ENV{MA_CONF} and -f $ENV{MA_CONF}) { |
|
123 my $f = $ENV{MA_CONF}; |
|
124 die ": $f is group/world readable/writeable\n" if 077 & (stat _)[2]; |
|
125 $Cf->file($f) or die; |
|
126 } |
|
127 $Cf->getopt(\@ARGV) or die "Bad Usage. Try --help.\n"; |
|
128 |
|
129 die "Need ldap base.\n" if not $Cf->ldap_base; |
|
130 if ($Cf->ldap_admin !~ /\Q$Cf->ldap_base/) { |
|
131 $Cf->ldap_admin($Cf->ldap_admin . "," . $Cf->ldap_base); |
|
132 } |
|
133 |
|
134 print help() and exit 0 if $Cf->help; |
|
135 |
|
136 @_ = grep { $_ =~ /^\Q$Module\E/ } qw/account alias/; |
|
137 die "Need module. Try --help\n" if @_ == 0; |
|
138 die "Module ambigous. (@_)\n" if @_ > 1; |
|
139 |
|
140 if ($_[0] eq 'account') { |
|
141 require account; |
|
142 account::import($Cf); |
|
143 account::run(); |
|
144 } elsif ($_[0] eq 'alias') { |
|
145 require alias; |
|
146 alias::import($Cf); |
|
147 alias::run(); |
|
148 } else { |
|
149 die "Shit"; |
|
150 } |
|
151 |
|
152 } |
|
153 |
|
154 sub verbose(@) { |
|
155 print STDERR @_; |
|
156 } |
|
157 |
|
158 sub help() { |
|
159 ($_ = USAGE) =~ s/!(.*?)!/(eval $1) || ""/eg; |
|
160 return $_; |
|
161 } |
|
162 |
|
163 # vim:sts=4 sw=4 aw ai sm nohlsearch incsearch: |