1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
- $shortoptions = 'i:n:g:G:';
- $longoptions = array('id=', 'nickname=', 'group=', 'group-id=');
- $helptext = <<<END_OF_HELP
- joingroup.php [options]
- Adds a local user to a local group.
- -i --id ID of user to add
- -n --nickname nickname of the user to add
- -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->joinGroup($group);
- print "OK\n";
- } catch (Exception $e) {
- print $e->getMessage()."\n";
- exit(1);
- }
|