-
Notifications
You must be signed in to change notification settings - Fork 0
/
addUsersLdap.php~
executable file
·72 lines (60 loc) · 2.03 KB
/
addUsersLdap.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
//definições padrão para conexão no sistema
ldap_set_option(NULL, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option(NULL, LDAP_OPT_REFERRALS,0);
$server = "localhost";
$dn = "dc=empresa,dc=com,dc=br";
if($ds = ldap_connect($server))
{
print "LDAP connected to:".$server."<br />";
}
else {
die("Could not connect to LDAP server.");
}
$uname = "cn=Manager,".$dn;
$pw = "tux";
//função para cadastro de pessoas
if($ds)
{
if(ldap_bind($ds, $uname, $pw))
{
print "Sucessfully logged in as:".$uname."<br />";
//Common Name / Last Name and FirstName
$adduserAD["cn"] = "Common Name";
$adduserAD["sn"] = "Last Name";
$adduserAD["givenName"] = "First Name" ;
$adduserAD["mail"] = "[email protected]";
$adduserAD["st"] = "RS";
$adduserAD["l"] = "Osório";
$adduserAD["mobile"] = "51.99999999";
$adduserAD["telephoneNumber"] = "51.99999999";
//id do grupo
$adduserAD["gidNumber"] = "500";
$adduserAD["homeDirectory"] = "/usr/usuario";
//id do usuario
$adduserAD["uidNumber"] = "3";
$adduserAD["o"] = "Empresa";
//nome de usuario e senha
$adduserAD["uid"] = "Login";
$adduserAD["userpassword"] = "{MD5}".base64_encode(pack("H*",md5("senha")));
//Classes de usuário
$adduserAD["objectclass"][0] = "person";
$adduserAD["objectclass"][1] = "inetOrgPerson";
$adduserAD["objectclass"][2] = "posixAccount";
// add data to directory
if(ldap_add($ds, "cn=Common Name,ou=People,dc=facos,dc=edu,dc=br", $adduserAD))
{
print "Added User: ".$adduserAD['cn']."<br />";
}
else
{
print "Failed to add user: ".$adduserAD['cn']."<br />";
//echo var_dump($adduserAD)."<br />";
}
}
}
} else
{
echo "erro de conexão do usuario<br />";
}
?>