#!/usr/bin/perl # # Script that try to migrate an LDAP ldif file from phpgroupware .14 to .16 # (C) Marco Gaiarin # under the GNU GPL Licence (copyleft) # NOTE THIS: # # + this script is a quick hack, but works. ;) # + i've chose to work on ldif file, so you have to do: # , for me /etc/init.d/slapd stop # slapcat > backup.ldif # , for me rm /var/lib/ldap/* # cat backup.ldif | ./migrate.pl > new.ldif # # slapadd < new.ldif # , for me /etc/init.d/slapd start # # + user and group repository are modified, CONTACTS ARE REMOVED, so # please dump the contacts in phpgw and reload before using this # + .14 if there's a user and a group with the same numerical ID works with # some strange result. .16 refuse to work, this script does not cure this # fix it by hand. # # we are interested only in user, group and contacts. # EDIS THESE ACCORDINGLY YOUR SETUP # $user_base = "ou=People,dc=sv,dc=lnf,dc=it"; $group_base = "ou=Group,dc=sv,dc=lnf,dc=it"; $contacts_base = "ou=Contacts,dc=sv,dc=lnf,dc=it"; # don't touch me ;) # $mode=""; # Start working... # while (<>) { # eat the \n at the end # chomp(); # lookup the interesting parts, saving some state # if ( /^dn: uid=\w+,$user_base/ ) { $mode = "user"; } elsif ( /^dn: cn=\w+,$group_base/ ) { $mode = "group"; } elsif ( /^dn: uid=.*,$contacts_base/ ) { $mode = "contacts"; } elsif ( /^dn: / ) { $mode = ""; } # ok, now we have to do some fiddling... # if ( $mode eq "user" ) { next if ( /^phpgwAccountType:/ ); next if ( /^phpgwAccountLastLogin:/ ); next if ( /^phpgwAccountLastLoginFrom:/ ); if ( /uidNumber: (\d+)/ ) { printf ("phpgwAccountID: %d\n", $1); } } if ( $mode eq "group" ) { next if ( /^phpgwAccountType:/ ); next if ( /^phpgwAccountLastLogin:/ ); next if ( /^phpgwAccountLastLoginFrom:/ ); next if ( /^phpgwAccountStatus:/ ); next if ( /^phpgwAccountExpires:/ ); if ( /objectClass: phpgwAccount/ ) { printf ("objectClass: phpgwGroup\n"); next; } if ( /gidNumber: (\d+)/ ) { printf ("phpgwGroupID: %d\n", $1); } } next if ( $mode eq "contacts"); #printf ("mode: %s\n", $mode); printf ("%s\n", $_); }