3 # © 2005 Heiko Schlittermann <hs@schlittermann.de> |
3 # © 2005 Heiko Schlittermann <hs@schlittermann.de> |
4 # $URL$ |
4 # $URL$ |
5 # $Id$ |
5 # $Id$ |
6 # |
6 # |
7 use constant USAGE => <<'#'; |
7 use constant USAGE => <<'#'; |
8 Usage: !ME! account|alias|group --add|--list|--modify|--delete [options] [user|alias|shared mbox] |
8 Usage: !ME! account|alias|group|acl --add|--list|--modify|--delete [options] [user|alias|shared mbox] |
9 * common options * |
9 * common options * |
10 --ldap_server=s LDAP-Server [!$Cf->ldap_server!] |
10 --ldap_server=s LDAP-Server [!$Cf->ldap_server!] |
11 --ldap_base=s LDAP-Basis [!$Cf->ldap_base!] |
11 --ldap_base=s LDAP-Base [!$Cf->ldap_base!] |
12 --ldap_admin=s LDAP BIND DN [!$Cf->ldap_admin!] |
12 --ldap_admin=s LDAP BIND DN [!$Cf->ldap_admin!] |
13 --ldap_password=s [!$Cf->ldap_password!] |
13 --ldap_password=s [!$Cf->ldap_password!] |
14 |
14 |
15 --imap_server=s IMAP Server [!$Cf->imap_server!] |
15 --imap_server=s IMAP Server [!$Cf->imap_server!] |
16 --imap_admin=s IMAP Server [!$Cf->imap_admin!] |
16 --imap_admin=s IMAP Server [!$Cf->imap_admin!] |
17 --imap_password=s [!$Cf->imap_password!] |
17 --imap_password=s [!$Cf->imap_password!] |
18 |
18 |
19 * account options * |
19 * account options * |
20 --default_domain Default Domain [!$Cf->default_domain!] |
20 --default_domain Default Domain [!$Cf->default_domain!] |
21 --[no]mbox Create MBox [!$Cf->mbox!] |
21 --[no]mbox Create MBox [!$Cf->mbox!] |
22 --imap_quota=i Mail Quota (MB) [!$Cf->imap_quota!] |
22 --imap_quota=i Mail Quota [!$Cf->imap_quota!] |
|
23 (Bytes) |
23 --address=s Primary Mail [!$Cf->address!] |
24 --address=s Primary Mail [!$Cf->address!] |
24 --other:s Alternative Mail addresses |
25 --other:s Alternative Mail addresses |
25 (comma sep.) [!$Cf->other!] |
26 (comma sep.) [!$Cf->other!] |
26 --group:s Mail Group(s) this account is member of |
27 --group:s Mail Group(s) this account is member of |
27 (comma sep.) [!$Cf->group!] |
28 (comma sep.) [!$Cf->group!] |
28 --forward:s Forwarding [!$Cf->forward!] |
29 --forward:s Forwarding [!$Cf->forward!] |
29 |
30 |
30 --fullname=s Real Name [!$Cf->fullname!] |
31 --fullname=s Real Name [!$Cf->fullname!] |
31 --password=s Passwort [!$Cf->password!] |
32 --password=s Password [!$Cf->password!] |
|
33 |
|
34 * acl options * |
|
35 --acl_admin=s ACL Admin [!$Cf->acl_admin!] |
|
36 --acl_password=s Pasword [!$Cf->acl_admin!] |
|
37 --folder:s@ Folder(s) [!join ',', @{$Cf->folder}!] |
|
38 --acl=s ACL list [!$Cf->acl!] |
|
39 --[no]recursive Rekursive [!$Cf->recursive!] |
32 |
40 |
33 * alias options * |
41 * alias options * |
34 --members=s List of Members [!$Cf->members!] |
42 --members=s List of Members [!$Cf->members!] |
35 |
43 |
36 * shared mailbox options * |
44 * shared mailbox options * |
37 |
45 |
|
46 [ currently not supported ] |
|
47 |
38 * group options * |
48 * group options * |
39 --members=s List of Members [!$Cf->members!] |
49 --members=s List of Members [!$Cf->members!] |
40 --description=s Descripton [!$Cf->description!] |
50 --description=s Descripton [!$Cf->description!] |
|
51 |
|
52 [ currently not supported ] |
41 |
53 |
42 Passwords for LDAP and IMAP can be read from environment LDAP_PASS resp. IMAP_PASS. |
54 Passwords for LDAP and IMAP can be read from environment LDAP_PASS resp. IMAP_PASS. |
43 Options can be read from config file named in $MA_CONF [!$ENV{MA_CONF}!]. |
55 Options can be read from config file named in $MA_CONF [!$ENV{MA_CONF}!]. |
44 |
56 |
45 $Id$ |
57 $Id$ |
50 |
62 |
51 use strict; |
63 use strict; |
52 use warnings; |
64 use warnings; |
53 |
65 |
54 use IO::File; |
66 use IO::File; |
55 use Cyrus::IMAP::Admin; |
|
56 use AppConfig qw(:expand); |
67 use AppConfig qw(:expand); |
57 use File::Basename; |
68 use File::Basename; |
58 use FindBin; |
69 use FindBin; |
59 use Carp; |
70 use Carp; |
60 |
71 |
61 use lib ("$FindBin::RealBin/..", "$FindBin::RealBin/../lib/ma"); |
72 use lib ( "$FindBin::RealBin/..", "$FindBin::RealBin/../lib/ma" ); |
62 use Common; |
73 use Common; |
63 use ldapBase; |
74 use ldapBase; |
64 |
75 |
65 use constant ME => basename $0; |
76 use constant ME => basename $0; |
66 our $Cf; |
77 our $Cf; |
67 |
78 |
68 sub help(); |
79 sub help(); |
69 |
80 |
70 my $Module = shift if @ARGV && $ARGV[0] !~ /^-/; |
81 my $Module = shift if @ARGV && $ARGV[0] !~ /^-/; |
71 $Module ||= "UNKNOWN"; |
82 $Module ||= "UNKNOWN"; |
72 |
83 |
73 |
84 $SIG{__DIE__} = sub { die "\n" . ME . ": ", @_ }; |
74 $SIG{__DIE__} = sub { die "\n".ME.": ", @_ }; |
|
75 |
|
76 |
85 |
77 MAIN: { |
86 MAIN: { |
78 |
87 |
79 $Cf = new AppConfig Common::CONFIG or die; |
88 $Cf = new AppConfig Common::CONFIG or die; |
80 |
89 |
81 if (exists $ENV{MA_CONF} and -f $ENV{MA_CONF}) { |
90 if ( exists $ENV{MA_CONF} and -f $ENV{MA_CONF} ) { |
82 my $f = $ENV{MA_CONF}; |
91 my $f = $ENV{MA_CONF}; |
83 die ": $f is group/world readable/writeable\n" if 077 & (stat _)[2]; |
92 die ": $f is group/world readable/writeable\n" if 077 & ( stat _ )[2]; |
84 $Cf->file($f) or die; |
93 $Cf->file($f) or die; |
85 } |
94 } |
86 $Cf->getopt(\@ARGV) or die "Bad Usage. Try --help.\n"; |
95 $Cf->getopt( \@ARGV ) or die "Bad Usage. Try --help.\n"; |
87 |
96 |
88 die "Need ldap base.\n" if not $Cf->ldap_base; |
97 die "Need ldap base.\n" if not $Cf->ldap_base; |
89 if ($Cf->ldap_admin !~ /\Q$Cf->ldap_base/) { |
98 if ( $Cf->ldap_admin !~ /\Q$Cf->ldap_base/ ) { |
90 $Cf->ldap_admin($Cf->ldap_admin . "," . $Cf->ldap_base); |
99 $Cf->ldap_admin( $Cf->ldap_admin . "," . $Cf->ldap_base ); |
91 } |
100 } |
92 |
101 |
93 if ($Cf->help) { |
102 if ( $Cf->help ) { |
94 if (-t STDOUT and -x "/usr/bin/less") { open(X, "|less -FX") } |
103 if ( -t STDOUT and -x "/usr/bin/less" ) { open( X, "|less -FX" ) } |
95 else { open(X, ">&STDOUT"); } |
104 else { open( X, ">&STDOUT" ); } |
96 print X help(); |
105 print X help(); |
97 exit 0; |
106 exit 0; |
98 } |
107 } |
99 |
108 |
100 @_ = grep { $_ =~ /^\Q$Module\E/ } qw/account alias shared group/; |
109 @_ = grep { $_ =~ /^\Q$Module\E/ } qw/account acl alias shared group/; |
101 die "Need module. Try --help\n" if @_ == 0; |
110 die "Need module. Try --help\n" if @_ == 0; |
102 die "Module ambigous. (@_)\n" if @_ > 1; |
111 die "Module ambigous. (@_)\n" if @_ > 1; |
103 |
112 |
104 if ($_[0] eq 'account') { |
113 if ( $_[0] eq 'account' ) { |
105 require account; |
114 require account; |
106 account::import($Cf); |
115 account::import($Cf); |
107 account::run(); |
116 account::run(); |
108 } elsif ($_[0] eq 'alias') { |
117 } elsif ( $_[0] eq 'acl' ) { |
109 require alias; |
118 require acl; |
110 alias::import($Cf); |
119 acl::import($Cf); |
111 alias::run(); |
120 acl::run(); |
112 } elsif ($_[0] eq 'shared') { |
121 } elsif ( $_[0] eq 'alias' ) { |
113 require shared; |
122 require alias; |
114 shared::import($Cf); |
123 alias::import($Cf); |
115 shared::run(); |
124 alias::run(); |
116 } elsif ($_[0] eq 'group') { |
125 } elsif ( $_[0] eq 'shared' ) { |
117 require group; |
126 die "Command '$_[0]' is currently not supported\n"; |
118 group::import($Cf); |
127 require shared; |
119 group::run(); |
128 shared::import($Cf); |
|
129 shared::run(); |
|
130 } elsif ( $_[0] eq 'group' ) { |
|
131 die "Command '$_[0]' is currently not supported\n"; |
|
132 require group; |
|
133 group::import($Cf); |
|
134 group::run(); |
120 } else { |
135 } else { |
121 die "Shit"; |
136 die "Shit"; |
122 } |
137 } |
123 |
138 |
124 } |
139 } |
125 |
140 |
126 sub verbose(@) { |
141 sub verbose(@) { |
127 print STDERR @_; |
142 print STDERR @_; |
128 } |
143 } |
129 |
144 |
130 sub help() { |
145 sub help() { |
131 ($_ = USAGE) =~ s/!(.*?)!/(eval $1) || ""/eg; |
146 ( $_ = USAGE ) =~ s/!(.*?)!/(eval $1) || ""/eg; |
132 return $_; |
147 return $_; |
133 } |
148 } |
134 |
149 |
135 # vim:sts=4 sw=4 aw ai sm nohlsearch incsearch: |
150 # vim:sts=4 sw=4 aw ai sm nohlsearch incsearch: |