#!/usr/bin/perl -w # -- # bin/otrs.addUser2Group - Add User to a Group # Copyright (C) 2002 Atif Ghaffar # Copyright (C) 2001-2006 OTRS GmbH, http://otrs.org/ # -- # $Id: otrs.addUser2Group,v 1.12 2006/11/02 12:20:59 tr Exp $ # -- # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -- use File::Basename; use FindBin qw($RealBin); use lib dirname($RealBin); use lib dirname($RealBin)."/Kernel/cpan-lib"; use strict; use Kernel::Config; use Kernel::System::Log; use Kernel::System::DB; use Kernel::System::User; use Kernel::System::Group; my %Param = (); my %CommonObject = (); my %Opts = (); use Getopt::Std; getopt('guph', \%Opts); if ($Opts{h}) { print STDERR "Usage: bin/otrs.addUser2Group -g groupname -u username -p ro|rw\n"; exit; } if (!$Opts{g}) { print STDERR "ERROR: Need -g groupname\n"; exit 1; } if (!$Opts{u}) { print STDERR "ERROR: Need -u username\n"; exit 1; } if (!$Opts{p}) { print STDERR "ERROR: Need -p permission\n"; exit 1; } # create common objects $CommonObject{ConfigObject} = Kernel::Config->new(%CommonObject); $CommonObject{LogObject} = Kernel::System::Log->new(%CommonObject, LogPrefix => 'otrs.addUser2Group'); $CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject); $CommonObject{UserObject} = Kernel::System::User->new(%CommonObject); $CommonObject{GroupObject} = Kernel::System::Group->new(%CommonObject); # user id $Param{UserID}='1'; # valid id $Param{ValidID}='1'; $Param{Permission}->{$Opts{p}} = 1; $Param{UserLogin}=$Opts{u}; $Param{Group}=$Opts{g}; unless ($Param{UID}=$CommonObject{UserObject}->UserLookup(UserLogin => $Param{UserLogin})){ print STDERR "ERROR: Failed to get User ID. Perhaps non-existent user..\n"; exit 1; } unless ($Param{GID}=$CommonObject{GroupObject}->GetGroupIdByName(%Param)){ print STDERR "ERROR: Failed to get Group ID. Perhaps non-existent group..\n"; exit; } print "GID: $Param{Group}/$Param{GID} \n"; print "UID: $Param{User}/$Param{UID} \n"; print "Perrmission: $Opts{p} \n"; if (!$CommonObject{GroupObject}->GroupMemberAdd(%Param)) { print STDERR "ERROR: Can't add user to group\n"; exit 1; } else { exit (0); }