implemented all functions
This commit is contained in:
parent
8cb06bcf67
commit
6a47977c54
|
@ -29,6 +29,9 @@ class Ldap{
|
||||||
// object of Config to access preferences
|
// object of Config to access preferences
|
||||||
var $conf;
|
var $conf;
|
||||||
|
|
||||||
|
// server handle
|
||||||
|
var $server;
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
// $config has to be an object of Config (../config/config.php)
|
// $config has to be an object of Config (../config/config.php)
|
||||||
function Ldap($config) {
|
function Ldap($config) {
|
||||||
|
@ -39,26 +42,66 @@ class Ldap{
|
||||||
// returns an array of strings with the DN entries
|
// returns an array of strings with the DN entries
|
||||||
// $base is optional and specifies the root from where to search for entries
|
// $base is optional and specifies the root from where to search for entries
|
||||||
function getUsers($base = "") {
|
function getUsers($base = "") {
|
||||||
|
if ($base == "") $base = $this->conf->get_UserSuffix();
|
||||||
|
$filter = "(&(|(objectClass=posixAccount) (objectClass=sambaAccount)) (!(uid=*$)))";
|
||||||
|
$attrs = array();
|
||||||
|
$sr = ldap_search($this->server, $base, $filter, $attrs);
|
||||||
|
$info = ldap_get_entries($this->server, $sr);
|
||||||
|
$ret = array();
|
||||||
|
for ($i = 0; $i < $info["count"]; $i++) $ret[$i] = $info[$i]["dn"];
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns an array of strings with the DN entries
|
// returns an array of strings with the DN entries
|
||||||
// $base is optional and specifies the root from where to search for entries
|
// $base is optional and specifies the root from where to search for entries
|
||||||
function getGroups($base = "") {
|
function getGroups($base = "") {
|
||||||
|
if ($base == "") $base = $this->conf->get_GroupSuffix();
|
||||||
|
$filter = "(objectClass=posixGroup)";
|
||||||
|
$attrs = array();
|
||||||
|
$sr = ldap_search($this->server, $base, $filter, $attrs);
|
||||||
|
$info = ldap_get_entries($this->server, $sr);
|
||||||
|
$ret = array();
|
||||||
|
for ($i = 0; $i < $info["count"]; $i++) $ret[$i] = $info[$i]["dn"];
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns an array of strings with the DN entries
|
// returns an array of strings with the DN entries
|
||||||
// $base is optional and specifies the root from where to search for entries
|
// $base is optional and specifies the root from where to search for entries
|
||||||
function getMachines($base = "") {
|
function getMachines($base = "") {
|
||||||
|
if ($base == "") $base = $this->conf->get_HostSuffix();
|
||||||
|
$filter = "(&(objectClass=sambaAccount) (uid=*$))";
|
||||||
|
$attrs = array();
|
||||||
|
$sr = ldap_search($this->server, $base, $filter, $attrs);
|
||||||
|
$info = ldap_get_entries($this->server, $sr);
|
||||||
|
$ret = array();
|
||||||
|
for ($i = 0; $i < $info["count"]; $i++) $ret[$i] = $info[$i]["dn"];
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// connects to the server using the given username and password
|
// connects to the server using the given username and password
|
||||||
// $base is optional and specifies the root from where to search for entries
|
// $base is optional and specifies the root from where to search for entries
|
||||||
function connect($user, $passwd) {
|
function connect($user, $passwd) {
|
||||||
|
if ($this->conf->get_SSL() == "True") $this->server = ldap_connect("ldaps://" . $this->conf->get_Host(), $this->conf->get_Port());
|
||||||
|
else $this->server = ldap_connect("ldap://" . $this->conf->get_Host(), $this->conf->get_Port());
|
||||||
|
if ($this->server) {
|
||||||
|
if (ldap_bind($this->server, $user, $passwd)) {
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo _("Unable to bind to Server!");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo _("Unable to connect to Server!");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// closes connection to server
|
// closes connection to server
|
||||||
// $base is optional and specifies the root from where to search for entries
|
// $base is optional and specifies the root from where to search for entries
|
||||||
function close() {
|
function close() {
|
||||||
|
ldap_close($this->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue