Created
March 6, 2011 19:54
-
-
Save jvandijk/857588 to your computer and use it in GitHub Desktop.
Querying users using Zend_LDAP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servers = fetchAllServers(); | |
$users = fetchAllUsers(); | |
foreach ($servers as $server) { | |
$keys = 'superkey-string'; | |
$userSystems = fetchUserSystemsById($server->getId()) | |
foreach ($userSystems as $userSystem) { | |
$user = $users[$userSystem->getUid()); | |
if ($user['sshkey'] != '') { | |
$keys .= '\n' . $user['sshkey']; | |
} | |
} | |
$tmpfname = tempnam("/tmp", "FOO"); | |
$handle = fopen($tmpfname, "w"); | |
fwrite($handle, $keys); | |
$cmd = sprintf('scp -P %d -i %s %s %s@%s:~/.ssh/authorized_keys', | |
$server->getPort(), '/path/to/private/supersshkey', | |
$tmpfname, $server->getUser(), $server->getIpAddress()); | |
$output = exec($cmd, $returnData, $returnStatus); | |
fclose($handle); | |
unlink($tmpfname); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$options = array( | |
'host' => 'ldap.domain.com', | |
'username' => 'CN=guest,OU=users,DC=domain,DC=com', | |
'password' => 'secret', | |
); | |
$fields = array('displayname', 'uid', 'sshkey'); | |
$ldap = new Zend_Ldap($options); | |
$users = $ldap->search('(objectCategory=user)', | |
'OU=users,DC=domain,DC=com', | |
Zend_Ldap::SEARCH_SCOPE_SUB, | |
$fields); | |
foreach ($users as $user) { | |
var_dump($user); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment