]> git.sur5r.net Git - contagged/blob - contrib/ldif2contagged.pl
contrib script for importing Thunderbird LDIF exports
[contagged] / contrib / ldif2contagged.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5
6 =head1 ldif to contagged
7
8 =head1 usage
9
10 ldif2contagged.pl < exported.addressbook.from.thunderbird.mozilla.ldif
11
12 cd split
13
14 for i in *;do ldapadd -w mypass -x -D "cn=Manager,dc=example,dc=com" -f $i -H ldap://ldap.server.example.com ;done
15
16 for i in *;do echo $i;ldapmodify -w mypass -x -D "cn=Manager,dc=example,dc=com" -f $i -H ldap://ldap.server.example.com ;done
17
18 =head1 modification made to contagged 
19
20
21 contagged/inc/lang/en.php :
22 -$lang['country']          = 'Land';
23 +$lang['country']          = 'Country';
24
25
26
27 contagged/inc/fields.php 
28 # added departement field, country
29 # street remapped to street
30
31 +    'department'   => 'ou',                           // aka. unit
32
33 -    'street'       => 'postalAddress',
34 +    'street'       => 'street',
35 +    'country'      => 'c',                           
36
37
38
39 =head1 modification made to ldap schemas
40
41 core.schema:
42 # to get longer country name (ie usa, canada instead of ca, us)
43
44  attributetype ( 2.5.4.6 NAME ( 'c' 'countryName' )
45         DESC 'RFC2256: ISO-3166 country 2-letter code'
46 -       SUP name SINGLE-VALUE )
47 +    EQUALITY caseIgnoreMatch
48 +    SUBSTR caseIgnoreSubstringsMatch
49 +    SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{128} )
50
51
52 # to get phones numbers with extensions, free writing
53
54  attributetype ( 2.5.4.20 NAME 'telephoneNumber'
55 -       DESC 'RFC2256: Telephone Number'
56 -       EQUALITY telephoneNumberMatch
57 -       SUBSTR telephoneNumberSubstringsMatch
58 -       SYNTAX 1.3.6.1.4.1.1466.115.121.1.50{32} )
59 +   DESC 'RFC2256: Telephone Number'
60 +   EQUALITY caseIgnoreMatch
61 +   SUBSTR caseIgnoreSubstringsMatch
62 +   SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
63
64
65 # add country to persons
66
67  objectclass ( 2.5.6.7 NAME 'organizationalPerson'
68         DESC 'RFC2256: an organizational person'
69         SUP person STRUCTURAL
70         MAY ( title $ x121Address $ registeredAddress $ destinationIndicator $
71                 preferredDeliveryMethod $ telexNumber $ teletexTerminalIdentifier $
72                telephoneNumber $ internationaliSDNNumber $ 
73                 facsimileTelephoneNumber $ street $ postOfficeBox $ postalCode $
74 -               postalAddress $ physicalDeliveryOfficeName $ ou $ st $ l ) )
75 +               postalAddress $ physicalDeliveryOfficeName $ ou $ st $ l $ c ) )
76
77
78
79 cosine.schema :
80 # to get phones numbers with extensions, free writing
81
82  attributetype ( 0.9.2342.19200300.100.1.20
83 -       DESC 'RFC1274: home telephone number'
84 -       NAME ( 'homePhone' 'homeTelephoneNumber' )
85 -       EQUALITY telephoneNumberMatch
86 -       SUBSTR telephoneNumberSubstringsMatch
87 -       SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )
88 +    NAME ( 'homePhone' 'homeTelephoneNumber' )
89 +    DESC 'RFC1274: home telephone number'
90 +   EQUALITY caseIgnoreMatch
91 +   SUBSTR caseIgnoreSubstringsMatch
92 +   SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
93
94
95
96
97 =head1 copyright
98
99 Copyright (c) 2004-2006 8D Technologies, Xavier Renaut
100 xavier blob ldif2contagged at pecos blob 8d blod com
101 http://labs.8d.com
102
103     This program is free software; you can redistribute it and/or
104     modify it under the terms of the GNU Lesser General Public
105     License as published by the Free Software Foundation; either
106     version 2.1 of the License, or (at your option) any later version.
107
108     This program is distributed in the hope that it will be useful,
109     but WITHOUT ANY WARRANTY; without even the implied warranty of
110     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
111     Lesser General Public License for more details.
112
113     You should have received a copy of the GNU Lesser General Public
114     License along with this program; if not, write to the Free Software
115     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
116
117
118 =cut
119
120 my $uid="1186058859";
121
122 my $count=0;
123
124 my @data;
125
126 my $dir="split";
127 mkdir "split";
128
129 my $sn="";
130 my      $cn_surname="";
131 my      $mail_surname="";
132 my      $sn_found=0;
133
134 while (<>)
135 {
136     
137     next if /^objectclass: (top|person|mozillaAbPersonAlpha)/;
138     next if /^modifytimestamp/;
139     next if /^$/;
140     if (/dn:\s*(.*)$/)
141     {
142
143         # flush old data
144         if (@data){
145         
146             unless ( $sn_found)
147             {
148                 if ($cn_surname ne ""){push @data,"sn: $cn_surname\n" }
149                 else {push @data,"sn: $mail_surname\n" }
150                 
151             }
152             print "\b\b\b\b$count";
153             my $file="$dir/$uid";
154             open (C,">$file") || die "cant open $file : $!";
155             print C @data  ;
156             
157             close C;
158         }
159         @data=();
160         $sn="";
161         $cn_surname="";
162         $sn_found=0;
163         $uid++;$count++;
164         #my $dn=$1;
165
166
167     }
168     # s/^(\w+)::/$1:/; # used for the accents
169
170     if (/sn: (\S+)/){ $sn=$1;$sn_found=1;}
171     if (/cn:.*\b(\w+?)\b.*?\s*$/i) { $cn_surname=$1;}
172     if (/mail: (\S+)@/i) { $mail_surname=$1;}
173
174
175     #s/^(company:\s*\w{30})\w+\s*$/$1\n/;
176     #s/^(\w+:\s*\w{30})[\w=]+\s*$/$1\n/; #there is no garbage, comment it
177     s/dn:\s*(.*)$/dn: uid=$uid,ou=centraladdressbook,dc=8d,dc=com\nuid: $uid/;
178     s/^company:/o:/;
179     s/^department:/ou:/;
180     s/^mozillaSecondEmail/mail/;
181     s/^mozillaCustom1/description/;
182
183
184     s/^mozillaWorkUrl/labeledURI/;
185     if (s/^mozillaWorkStreet2::? /, /)
186     {
187         my $street2=$1;
188         #foreach (@data) {if (s/street .*/
189         my @data2;
190         map {
191             if (/^street:/){chomp}
192             push @data2,$_;
193         } @data;
194         @data=@data2;
195
196     }
197     push @data,$_;
198     #print
199 }
200 print " entries created in $dir/\n";
201