Created
November 21, 2014 11:08
-
-
Save blizzz/736339dc4938a920e087 to your computer and use it in GitHub Desktop.
displays groups belonging to a specified user and users belonging to a specified 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
<?php | |
if($argc !== 3) { | |
print('Usage: php -f ' . $argv[0] . ' UID GID' . PHP_EOL); | |
die; | |
} | |
require_once 'lib/base.php'; | |
\OC_App::loadApps(array('authentication')); | |
$uid = $argv[1]; | |
$gid = $argv[2]; | |
$uM = \OC::$server->getUserManager(); | |
$user = $uM->get($uid); | |
if(!$user instanceof \OCP\IUser) { | |
die('Invalid UserID'); | |
} | |
$gM = \OC::$server->getGroupManager(); | |
$groups = $gM->getUserGroups($user); | |
print($user->getDisplayName() . ' is member of following groups:' . PHP_EOL); | |
if(empty($groups)) { | |
print('(none)' . PHP_EOL); | |
} else { | |
foreach($groups as $group) { | |
print($group->getGID() . PHP_EOL); | |
} | |
} | |
$group = $gM->get($gid); | |
if(!$group instanceof \OCP\IGroup) { | |
die('Invalid GroupID'); | |
} | |
$users = $gM->displayNamesInGroup($gid); | |
print(PHP_EOL); | |
print($group->getGID() . ' has following members:' . PHP_EOL); | |
if(empty($users)) { | |
print('(none)' . PHP_EOL); | |
} else { | |
foreach($users as $id => $user) { | |
print($user . ' (' . $id . ')' . PHP_EOL); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment