-
Notifications
You must be signed in to change notification settings - Fork 1
/
convertcsvtoldif.1.php
44 lines (40 loc) · 1.42 KB
/
convertcsvtoldif.1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$row = 1;
$limit = 120;
if (($handle = fopen("/home/tran/mock.csv", "r")) !== FALSE) {
$members = "";
while ((($data = fgetcsv($handle, 1000, ",")) !== FALSE) && ($row <= $limit)){
$num = count($data);
echo "# New entry \n";
echo "dn: uid=".$data[2].",ou=dev,ou=staff,ou=people,dc=example,dc=org\n";
echo "changetype: add\n";
echo "gidNumber: 0\n";
echo "objectClass: inetOrgPerson\n";
echo "objectClass: organizationalPerson\n";
echo "objectClass: person\n";
echo "objectClass: top\n";
echo "objectClass: posixAccount\n";
echo "uidNumber: $row\n";
echo "uid: ".$data[2]."\n";
echo "homeDirectory: /home/".$data[2]."\n";
echo "sn: ".$data[3]."\n";
echo "cn: ".$data[3]."\n";
echo "mail: ".$data[1]."\n";
echo "employeeType: ".$data[4]."\n";
echo "displayName: Name ".$data[3]."\n";
echo "userPassword:: UEBzc3cwcmQ=\n";
echo "\n";
if ($row < 1020) {
$members .= "member: uid=" . $data[2] . ",ou=dev,ou=staff,ou=people,dc=example,dc=org\n";
}
$row++;
}
fclose($handle);
echo "dn: cn=devs02,ou=pluriel,ou=groups,dc=example,dc=org\n";
echo "changetype: add\n";
echo "objectClass: groupOfNames\n";
echo "objectClass: top\n";
echo "cn: devs\n";
echo $members;
echo "description: Global group\n";
}