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 // check for duplicate caller ID
else if (!isset($this->orig['AstAccountCallerID'][0]) || (($this->orig['AstAccountCallerID'][0] != $this->attributes['AstAccountCallerID'][0]))) { else if (!isset($this->orig['AstAccountCallerID'][0]) || (($this->orig['AstAccountCallerID'][0] != $this->attributes['AstAccountCallerID'][0]))) {
$searchroot = $_SESSION['config']->get_Suffix('user'); $entries = searchLDAPByAttribute('AstAccountCallerID', $this->attributes['AstAccountCallerID'][0], 'AsteriskSIPUser', array('dn'), array('user'));
$filter = '(& (objectClass=AsteriskSIPUser) (AstAccountCallerID=' . $this->attributes['AstAccountCallerID'][0] .'))'; if (sizeof($entries) > 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) {
$errors[] = $this->messages['AstAccountCallerID'][2]; $errors[] = $this->messages['AstAccountCallerID'][2];
} }
} }

View File

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

View File

@ -187,7 +187,7 @@ class ddns extends baseModule {
$ldap = $_SESSION['ldap']->server(); $ldap = $_SESSION['ldap']->server();
$dn = $_SESSION['config']->get_suffix('dhcp'); $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) { if ($search) {
$info = @ldap_get_entries($ldap,$search); $info = @ldap_get_entries($ldap,$search);
if ($info) { if ($info) {

View File

@ -191,11 +191,8 @@ class fixed_ip extends baseModule {
* @param array $attr list of attributes * @param array $attr list of attributes
*/ */
function load_attributes($attr) { function load_attributes($attr) {
if ($this->getAccountContainer()->dn_orig!=$_SESSION['config']->get_suffix('dhcp')) { if ($this->getAccountContainer()->dn_orig!=$_SESSION['config']->get_suffix('dhcp')) {
$sr = @ldap_search($_SESSION['ldap']->server(),$this->getAccountContainer()->dn_orig, '(objectClass=dhcpHost)', array(), 0, 0, 0, LDAP_DEREF_NEVER);
$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);
if ($sr) { if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr); $entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) { if ($entries) {
@ -352,9 +349,6 @@ class fixed_ip extends baseModule {
$pcs = array(); $pcs = array();
foreach($this->fixed_ip AS $id=>$arr) { foreach($this->fixed_ip AS $id=>$arr) {
// pc name // 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 = ""; $pcError = "";
if (!$this->processed) { if (!$this->processed) {
$pcError = ""; $pcError = "";