123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- define('INSTALLDIR', dirname(__DIR__));
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- $shortoptions = 'i:n:g:G:';
- $longoptions = array('id=', 'nickname=', 'group=', 'group-id=');
- $helptext = <<<END_OF_HELP
- leavegroup.php [options]
- Removes a local user from a local group.
- -i --id ID of user to remove
- -n --nickname nickname of the user to remove
- -g --group nickname or alias of group
- -G --group-id ID of group
- END_OF_HELP;
- require_once INSTALLDIR.'/scripts/commandline.inc';
- try {
- $user = getUser();
- $lgroup = null;
- if (have_option('G', 'group-id')) {
- $gid = get_option_value('G', 'group-id');
- $lgroup = Local_group::getKV('group_id', $gid);
- } else if (have_option('g', 'group')) {
- $gnick = get_option_value('g', 'group');
- $lgroup = Local_group::getKV('nickname', $gnick);
- }
- if (!$lgroup instanceof Local_group) {
- throw new Exception("No such local group: $gnick");
- }
- $group = User_group::getKV('id', $lgroup->group_id);
- $user->leaveGroup($group);
- print "OK\n";
- } catch (Exception $e) {
- print $e->getMessage()."\n";
- exit(1);
- }
|