Created
January 28, 2015 15:00
-
-
Save blizzz/5747a97f9332c392a81c to your computer and use it in GitHub Desktop.
get fron and count users in a primary group
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
#!/usr/bin/php | |
<?php | |
use OCA\user_ldap\lib\FilesystemHelper; | |
use OCA\user_ldap\lib\LDAP; | |
use OCA\user_ldap\lib\LogWrapper; | |
use OCA\User_LDAP\lib\user\Manager; | |
use OCA\User_LDAP\lib\Access; | |
use OCA\User_LDAP\lib\Connection; | |
require_once 'lib/base.php'; | |
class PrimGrTest extends \OCA\User_LDAP\GROUP_LDAP { | |
protected $groupDN; | |
//protected $access; | |
public function __construct($groupDN, $configPrefix) { | |
$this->groupDN = $groupDN; | |
//$this->access = $this->getAccess($configPrefix); | |
parent::__construct($this->getAccess($configPrefix)); | |
} | |
public function run() { | |
$start = microtime(true); | |
$users = $this->getUsersInPrimaryGroup($this->groupDN, ''); | |
$time = microtime(true) - $start; | |
print("user list:" . PHP_EOL); | |
foreach($users as $user) { | |
print(" " . $user['displayname'] . '(' . $user['dn'] . PHP_EOL); | |
} | |
print("Number of users: " . count($users) . ' took: ' . $time . PHP_EOL); | |
$start = microtime(true); | |
$users = $this->countUsersInPrimaryGroup($this->groupDN, ''); | |
$time = microtime(true) - $start; | |
print("Number of users (counted): " . $users . ' took: ' . $time . PHP_EOL); | |
$start = microtime(true); | |
$users = $this->getUsersInPrimaryGroup($this->groupDN, 's'); | |
$time = microtime(true) - $start; | |
print(PHP_EOL . "user list 's…':" . PHP_EOL); | |
foreach($users as $user) { | |
print(" " . $user['displayname'] . '(' . $user['dn'] . ')' . PHP_EOL); | |
} | |
print("Number of users with 's…': " . count($users) . ' took: ' . $time . PHP_EOL); | |
$users = $this->countUsersInPrimaryGroup($this->groupDN, 's'); | |
print("Number of users with 's…' (counted): " . $users . ' took: ' . $time . PHP_EOL); | |
$gid = $this->access->dn2groupname($this->groupDN); | |
try { | |
$this->countUsersInGroup($gid); | |
} catch (\Exception $e) { | |
print($e->getMessage() . PHP_EOL); | |
} | |
} | |
private function getGroupMapper() { | |
$dbc = \OC::$server->getDatabaseConnection(); | |
return new \OCA\User_LDAP\mapping\GroupMapping($dbc); | |
} | |
/** | |
* @param string $configPrefix | |
* @return Access | |
*/ | |
private function getAccess($configPrefix) { | |
$ocConfig = \OC::$server->getConfig(); | |
$fs = new FilesystemHelper(); | |
$log = new LogWrapper(); | |
$db = \OC::$server->getDatabaseConnection(); | |
$avatarM = \OC::$server->getAvatarManager(); | |
$ldap = new LDAP(); | |
$userManager = | |
new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db); | |
$connector = new Connection($ldap, $configPrefix); | |
$access = new Access($connector, $ldap, $userManager); | |
$access->setGroupMapper($this->getGroupMapper()); | |
return $access; | |
} | |
} | |
if($argc < 2) { | |
print('Usage: php -f ' . $argv[0] . ' UserDN [ConfigPrefix]' . PHP_EOL); | |
die; | |
} | |
$userDN = $argv[1]; | |
$cfgPrf = isset($argv[2]) ? $argv[2] : ""; | |
$test = new PrimGrTest($userDN, $cfgPrf); | |
$test->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment