/[adm]/scripts/ml-migration/subscribers-migration
ViewVC logotype

Contents of /scripts/ml-migration/subscribers-migration

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3025 - (show annotations) (download)
Wed Apr 3 16:22:23 2013 UTC (11 years, 6 months ago) by boklm
File size: 2035 byte(s)
Add script to migrate zarb ml subscribers to new ml
1 #!/usr/bin/perl -w
2
3 # This script is used to migrate the list of subscribers on zarb mailing
4 # lists to a list of subscribers on new mageia mailing lists with an
5 # identity account.
6 #
7 # The script takes a list of emails in stdin, and output a list of
8 # subscribers with an identity account in file 'subscribe', and a list
9 # of subscribers without an identity account in file 'nosubscribe'.
10
11 use strict;
12 use Net::LDAP;
13 use File::Slurp;
14 use Data::Dump qw/dump/;
15
16 my $ldapserver = 'ldap.mageia.org';
17 my $binddn = 'uid=boklm,ou=People,dc=mageia,dc=org';
18 my $bindpw = read_file('/etc/mga-ldap.secret');
19 chomp $bindpw;
20
21 sub getldap {
22 my $ldap = Net::LDAP->new($ldapserver) or die "$@";
23 my $m;
24 $m = $ldap->start_tls(verify => 'none');
25 die $m->error if $m->is_error;
26 $m = $ldap->bind($binddn, password => $bindpw);
27 die $m->error if $m->is_error;
28 return $ldap;
29 }
30
31 my $ldap = getldap();
32
33 sub get_user_email {
34 my ($ldap, $user) = @_;
35 my $dn = "uid=$user,ou=People,dc=mageia,dc=org";
36 my $m = $ldap->search(
37 base => $dn,
38 scope => 'base',
39 filter => '(objectClass=inetOrgPerson)',
40 );
41 die $m->error if $m->is_error;
42 my $res = $m->as_struct;
43 if (exists $res->{$dn}) {
44 return $res->{$dn}->{mail}->[0];
45 }
46 }
47
48 sub find_email {
49 my ($ldap, $email) = @_;
50 my $dn = "ou=People,dc=mageia,dc=org";
51 my $m = $ldap->search(
52 base => $dn,
53 filter => "(&(objectClass=inetOrgPerson)(mail=$email))",
54 );
55 die $m->error if $m->is_error;
56 my $res = $m->as_struct;
57 my $k = keys %$res;
58 return $k;
59 }
60
61 my @subscribe;
62 my @nosubscribe;
63
64 my $email;
65 while ($email = <STDIN>) {
66 chomp $email;
67 if ($email =~ m/^(.+)\@mageia.org$/) {
68 push @subscribe, get_user_email($ldap, $1);
69 next;
70 }
71 if (find_email($ldap, $email)) {
72 push @subscribe, $email;
73 } else {
74 push @nosubscribe, $email;
75 }
76 }
77
78 write_file('subscribe', join("\n", @subscribe));
79 write_file('nosubscribe', join("\n", @nosubscribe));
80

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.30