use central LDAP search

This commit is contained in:
Roland Gruber 2010-02-06 13:38:13 +00:00
parent 7088240b45
commit 545d0a6517
4 changed files with 19 additions and 51 deletions

View File

@ -218,16 +218,8 @@ class asteriskAccount extends baseModule implements passwordService {
}
// check for duplicate caller ID
else if (!isset($this->orig['AstAccountCallerID'][0]) || (($this->orig['AstAccountCallerID'][0] != $this->attributes['AstAccountCallerID'][0]))) {
$searchroot = $_SESSION['config']->get_Suffix('user');
$filter = '(& (objectClass=AsteriskSIPUser) (AstAccountCallerID=' . $this->attributes['AstAccountCallerID'][0] .'))';
$ldapc = $_SESSION['ldap']->server();
$attributes = array("DN", "AstAccountCallerID");
$res = ldap_search($ldapc,$searchroot,$filter,$attributes,0,0,0,LDAP_DEREF_NEVER);
if (!$res) {
return array(array("ERROR", _("Unable to load LDAP entry:") . " " .$searchroot, ldap_error($_SESSION['ldap']->server())));
}
$count = ldap_count_entries($ldapc, $res);
if ($count > 0) {
$entries = searchLDAPByAttribute('AstAccountCallerID', $this->attributes['AstAccountCallerID'][0], 'AsteriskSIPUser', array('dn'), array('user'));
if (sizeof($entries) > 0) {
$errors[] = $this->messages['AstAccountCallerID'][2];
}
}

View File

@ -261,35 +261,24 @@ class asteriskExtension extends baseModule {
* @return array list of info/error messages
*/
function display_html_user() {
// load list with all users with objectClass AsteriskSIPUser
$searchroot = $_SESSION['config']->get_Suffix('user');
// load list with all potential owners
$searchScope = 'user';
if ($this->searchOwnersInTreeSuffix) {
$searchroot = $_SESSION['config']->get_Suffix('tree');
$searchScope = 'tree';
}
$searchClass = 'inetOrgPerson';
if ($this->filterOwnerForAsteriskAccounts) {
$filter = 'objectClass=AsteriskSIPUser';
$searchClass = 'AsteriskSIPUser';
}
else {
$filter = 'objectClass=inetOrgPerson';
}
$ldapc = $_SESSION['ldap']->server();
$attributes = array("DN", "cn");
$res = ldap_search($ldapc,$searchroot,$filter,$attributes,0,0,0,LDAP_DEREF_NEVER);
if (!$res) {
return array(array("ERROR", _("Unable to load LDAP entry:") . " " .$searchroot, ldap_error($_SESSION['ldap']->server())));
}
$count = ldap_count_entries($ldapc, $res);
$entry = ldap_first_entry($ldapc, $res);
$entries = searchLDAPByAttribute(null, null, $searchClass, array('dn'), array($searchScope));
$users_dn = array();
while ($entry) {
$dn = ldap_get_dn($ldapc, $entry);
if (isset($dn) && (!isset($this->attributes['member']) || !in_array($dn, $this->attributes['member']))) {
$users_dn[] = $dn;
}
$entry = ldap_next_entry($ldapc, $entry);
for ($i = 0; $i < sizeof($entries); $i++) {
$dn = $entries[$i]['dn'];
if (isset($dn) && (!isset($this->attributes['member']) || !in_array($dn, $this->attributes['member']))) {
$users_dn[] = $dn;
}
}
$members = $this->attributes['member'];
$return[] = array(array('kind' => 'table', 'value' => array(
array(
array('kind' => 'table', 'value' => array(
@ -392,18 +381,11 @@ class asteriskExtension extends baseModule {
}
if (!isset($this->orig['AstExtension']) || !isset($this->orig['AstPriority']) || ($this->orig['AstExtension'][0] != $this->attributes['AstExtension'][0])
|| ($this->orig['AstPriority'][0] != $this->attributes['AstPriority'][0])) {
$searchroot = $_SESSION['config']->get_Suffix($this->get_scope());
|| ($this->orig['AstPriority'][0] != $this->attributes['AstPriority'][0])) {
$filter = '(& (objectClass=AsteriskExtension) (AstExtension=' . $this->attributes['AstExtension'][0] .') (AstPriority=' . $this->attributes['AstPriority'][0] .') )';
$ldapc = $_SESSION['ldap']->server();
$attributes = array("DN");
$res = ldap_search($ldapc,$searchroot,$filter,$attributes,0,0,0,LDAP_DEREF_NEVER);
if (!$res) {
return array(array("ERROR", _("Unable to load LDAP entry:") . " " .$searchroot, ldap_error($_SESSION['ldap']->server())));
}
$count = ldap_count_entries($ldapc, $res);
if($count > 0) {
$errors[] = $this->messages['AstExtensionAstPriority'][0];
$entries = searchLDAPByFilter($filter, array('dn'), array($this->get_scope()));
if (sizeof($entries) > 0) {
$errors[] = $this->messages['AstExtensionAstPriority'][0];
}
}

View File

@ -187,7 +187,7 @@ class ddns extends baseModule {
$ldap = $_SESSION['ldap']->server();
$dn = $_SESSION['config']->get_suffix('dhcp');
$search = @ldap_search($ldap,$dn,"dhcpStatements=ddns-update-style interim", array(), 0, 0, 0, LDAP_DEREF_NEVER);
$search = @ldap_read($ldap,$dn,"dhcpStatements=ddns-update-style interim", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($search) {
$info = @ldap_get_entries($ldap,$search);
if ($info) {

View File

@ -191,11 +191,8 @@ class fixed_ip extends baseModule {
* @param array $attr list of attributes
*/
function load_attributes($attr) {
if ($this->getAccountContainer()->dn_orig!=$_SESSION['config']->get_suffix('dhcp')) {
$sr = @ldap_search($_SESSION['ldap']->server(),'cn='.$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0].','.$_SESSION['config']->get_suffix('dhcp'),
'(objectClass=dhcpHost)', array(), 0, 0, 0, LDAP_DEREF_NEVER);
$sr = @ldap_search($_SESSION['ldap']->server(),$this->getAccountContainer()->dn_orig, '(objectClass=dhcpHost)', array(), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) {
@ -352,9 +349,6 @@ class fixed_ip extends baseModule {
$pcs = array();
foreach($this->fixed_ip AS $id=>$arr) {
// pc name
$result = @ldap_search($_SESSION['ldap']->server(),"cn=".$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0].",".$_SESSION['config']->get_Suffix('dhcp'),
'(cn='.$_POST['pc_'.$id].')', array(), 0, 0, 0, LDAP_DEREF_NEVER);
$num = (@ldap_get_entries($_SESSION['ldap']->server(), $result)=="")?0:ldap_get_entries($_SESSION['ldap']->server(), $result);
$pcError = "";
if (!$this->processed) {
$pcError = "";