summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2017-05-14 15:00:16 +0200
committerGuilhem Moulin <guilhem@fripost.org>2017-05-14 15:00:16 +0200
commit40eaa53a7bcfbf2f120ebff70e06a4657efcb8a7 (patch)
tree0ddddb9fef47bfe4f8e837da32d8270f2ee33c02
parent6824ec3da9785f51457b4eb2606b1f3d7c48a939 (diff)
IMAP: new script list-users.
-rwxr-xr-xroles/IMAP/files/usr/local/bin/list-users.pl45
-rw-r--r--roles/IMAP/tasks/imap.yml7
2 files changed, 52 insertions, 0 deletions
diff --git a/roles/IMAP/files/usr/local/bin/list-users.pl b/roles/IMAP/files/usr/local/bin/list-users.pl
new file mode 100755
index 0000000..1bcab35
--- /dev/null
+++ b/roles/IMAP/files/usr/local/bin/list-users.pl
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+
+# Copyright © 2017 Guilhem Moulin <guilhem@fripost.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+use warnings;
+use strict;
+use Net::LDAPI;
+use Net::LDAP::Util qw/ldap_explode_dn escape_dn_value/;
+use Authen::SASL;
+
+my $BASE = 'ou=virtual,dc=fripost,dc=org';
+
+my $LDAP = Net::LDAPI::->new();
+$LDAP->bind( undef, sasl => Authen::SASL::->new(mechanism => 'EXTERNAL') )
+ or die "Error: Couldn't bind";
+
+my $mesg = $LDAP->search( base => $BASE, scope => 'children', deref => 'never'
+ , filter => '(objectClass=FripostVirtualUser)'
+ , attrs => ['1.1']
+ );
+die $mesg->error if $mesg->code;
+
+while (defined (my $entry = $mesg->pop_entry())) {
+ my $dn = $entry->dn() // next;
+ $dn = ldap_explode_dn($dn, casefold => 'lower');
+ next unless defined $dn and $#$dn == 4;
+ my $l = $dn->[0]->{fvl} // next;
+ my $d = $dn->[1]->{fvd} // next;
+ printf "%s@%s\n", $l, $d;
+}
+
+$LDAP->unbind;
diff --git a/roles/IMAP/tasks/imap.yml b/roles/IMAP/tasks/imap.yml
index f4a23e4..fc171a3 100644
--- a/roles/IMAP/tasks/imap.yml
+++ b/roles/IMAP/tasks/imap.yml
@@ -9,6 +9,13 @@
- dovecot-managesieved
- dovecot-sieve
+# 7 5 * * * root users=$(mktemp --tmpdir) && sudo -u dovecot /usr/local/bin/list-members.pl && sudo -u vmail nice -n 19 /usr/bin/doveadm purge -F"$users"
+- name: Copy list-users.pl
+ copy: src=usr/local/bin/list-users.pl
+ dest=/usr/local/bin/list-users.pl
+ owner=root group=root
+ mode=0755
+
- name: Create a user 'vmail'
user: name=vmail system=yes
createhome=no