public function find($name, $value, $attr_name) { $this->bind(); $filter = "{$attr_name}={$value}"; $base_dn = $this->active_server['baseDn']; $this->log("Attempting to search for {$name}={$value} using basedn={$base_dn}"); try { $hm = $this->ldap->search($filter, $base_dn, $this->scope); $this->log("Raw Ldap Object: " . var_export($hm, true), 7); if ($hm->count() == 0) { $this->log("Could not find an account for {$name}={$value}", 5); return false; } elseif ($hm->count() > 1) { $this->log("Found more than one user account for {$name}={$value}", 1); return false; } $this->user = $hm->current(); $this->log("User entry response: " . var_export($this->user, true), 7); return $this->user; } catch (LdapException $exc) { return $exc->getMessage(); } }
private function findUnit(Identity $identity) { if (null === $this->unit) { $filter = Filter::equals('mail', $identity->mail); $baseDn = Dn::factory($this->ldap->getBaseDn())->prepend(['ou' => 'people']); $result = $this->ldap->search($filter, $baseDn, Ldap::SEARCH_SCOPE_ONE, ['l']); if (1 !== $result->count()) { return; } $result = $result->current(); $unitDn = $result['l'][0]; $this->unit = $this->ldap->getNode($unitDn); } return $this->unit; }
public function findById($id) { $this->bind(); $this->log("Attempting to search ldap by uidnumber for {$id} against the active ldap server"); try { $hm = $this->ldap->search("uidnumber={$id}", $this->active_server['baseDn'], ZendLdap::SEARCH_SCOPE_ONE); $this->log("Raw Ldap Object: " . var_export($hm, true), 7); foreach ($hm as $item) { $this->log($item); return $item; } return false; } catch (LdapException $exc) { $msg = $exc->getMessage(); $this->log($msg); } }
public function getComputers($computerService) { $domain = $this->options['accountDomainName']; $ldap = new Ldap($this->options); $ldap->bind(); $result = $ldap->search('(&(objectCategory=computer))', 'dc=wr,dc=local', Ldap::SEARCH_SCOPE_SUB); foreach ($result as $item) { if ($item['name'][0] != '') { $hostname = $item['name'][0]; $computer = $computerService->findByDNSName($hostname, $domain); if (!$computer) { $computer = new Computer(); $computerService->setType($computer, 'Computer'); $computerService->setStatus($computer, 'In Use'); $computerService->setManufacturer($computer, 'Dell'); $computer->setHostname($hostname)->setDomain($domain); } // Operating system if (array_key_exists('operatingsystem', $item)) { $computer->setOsName($item['operatingsystem'][0]); } // Operating system service pack if (array_key_exists('operatingsystemservicepack', $item)) { $computer->setOsServicePack($item['operatingsystemservicepack'][0]); } // Operating system version. if (array_key_exists('operatingsystemversion', $item)) { $computer->setOsVersion($item['operatingsystemversion'][0]); } // die(var_dump($computer->getStatus())); $computerService->persist($computer); } } }