summaryrefslogtreecommitdiffstats
path: root/ml-migration/subscribers-migration
diff options
context:
space:
mode:
authorNicolas Vigier <boklm@mageia.org>2013-04-03 16:22:23 +0000
committerNicolas Vigier <boklm@mageia.org>2013-04-03 16:22:23 +0000
commit9003f3d9ff5724b3709c40cb2425cc8f649cc7e9 (patch)
treed0a19f271e863e6f7cddde9333d38c76485dfb34 /ml-migration/subscribers-migration
downloadscripts-9003f3d9ff5724b3709c40cb2425cc8f649cc7e9.tar
scripts-9003f3d9ff5724b3709c40cb2425cc8f649cc7e9.tar.gz
scripts-9003f3d9ff5724b3709c40cb2425cc8f649cc7e9.tar.bz2
scripts-9003f3d9ff5724b3709c40cb2425cc8f649cc7e9.tar.xz
scripts-9003f3d9ff5724b3709c40cb2425cc8f649cc7e9.zip
Add script to migrate zarb ml subscribers to new mlHEADmaster
Diffstat (limited to 'ml-migration/subscribers-migration')
-rwxr-xr-xml-migration/subscribers-migration80
1 files changed, 80 insertions, 0 deletions
diff --git a/ml-migration/subscribers-migration b/ml-migration/subscribers-migration
new file mode 100755
index 0000000..0eb4942
--- /dev/null
+++ b/ml-migration/subscribers-migration
@@ -0,0 +1,80 @@
+#!/usr/bin/perl -w
+
+# This script is used to migrate the list of subscribers on zarb mailing
+# lists to a list of subscribers on new mageia mailing lists with an
+# identity account.
+#
+# The script takes a list of emails in stdin, and output a list of
+# subscribers with an identity account in file 'subscribe', and a list
+# of subscribers without an identity account in file 'nosubscribe'.
+
+use strict;
+use Net::LDAP;
+use File::Slurp;
+use Data::Dump qw/dump/;
+
+my $ldapserver = 'ldap.mageia.org';
+my $binddn = 'uid=boklm,ou=People,dc=mageia,dc=org';
+my $bindpw = read_file('/etc/mga-ldap.secret');
+chomp $bindpw;
+
+sub getldap {
+ my $ldap = Net::LDAP->new($ldapserver) or die "$@";
+ my $m;
+ $m = $ldap->start_tls(verify => 'none');
+ die $m->error if $m->is_error;
+ $m = $ldap->bind($binddn, password => $bindpw);
+ die $m->error if $m->is_error;
+ return $ldap;
+}
+
+my $ldap = getldap();
+
+sub get_user_email {
+ my ($ldap, $user) = @_;
+ my $dn = "uid=$user,ou=People,dc=mageia,dc=org";
+ my $m = $ldap->search(
+ base => $dn,
+ scope => 'base',
+ filter => '(objectClass=inetOrgPerson)',
+ );
+ die $m->error if $m->is_error;
+ my $res = $m->as_struct;
+ if (exists $res->{$dn}) {
+ return $res->{$dn}->{mail}->[0];
+ }
+}
+
+sub find_email {
+ my ($ldap, $email) = @_;
+ my $dn = "ou=People,dc=mageia,dc=org";
+ my $m = $ldap->search(
+ base => $dn,
+ filter => "(&(objectClass=inetOrgPerson)(mail=$email))",
+ );
+ die $m->error if $m->is_error;
+ my $res = $m->as_struct;
+ my $k = keys %$res;
+ return $k;
+}
+
+my @subscribe;
+my @nosubscribe;
+
+my $email;
+while ($email = <STDIN>) {
+ chomp $email;
+ if ($email =~ m/^(.+)\@mageia.org$/) {
+ push @subscribe, get_user_email($ldap, $1);
+ next;
+ }
+ if (find_email($ldap, $email)) {
+ push @subscribe, $email;
+ } else {
+ push @nosubscribe, $email;
+ }
+}
+
+write_file('subscribe', join("\n", @subscribe));
+write_file('nosubscribe', join("\n", @nosubscribe));
+