Hi Steve This isn't quite what you want, but should get you started, it takes a list of usernames and email addresses from a txt file in the form: - username:email. It does some checking of the addresses against whats in rt and then sets a new name, new email address, a new password, removes privileges and disables the account.
it runs from opt/rt3/local/bin Shout if you need anything explaining etc. regards Garry
#!/usr/bin/perl ################################################################# # # Script to deal with unprivileged users with cases. # This will allow us to reuse usernames # # v0.1 18/01/10 [email protected] ################################################################# use strict; use lib "/opt/rt3/lib"; use RT; use RT::Interface::CLI qw (CleanEnv GetCurrentUser); use Data::Dumper; CleanEnv(); RT::LoadConfig(); RT::Init(); use POSIX qw(strftime); #grab todays date to make the new mail address and name my $datestr= strftime("%Y%m%d", localtime); #open the text file and slurp the contents into a handle # file will be of the format username,email open (DELETIONS, "</tmp/lboro_users2.txt")|| die ("Cant open the list of deletions\n"); my $user = RT::User->new($RT::SystemUser); #loop through the lines in the deletions file, split each line on the comma and compare the e-mail address to the one rt has. #if the addresses match, check the user is not privileged, if ok rename, otherwise dump the error to a txt file while (my $line =<DELETIONS>) { #clear out any trailing \n chomp $line; #split the entry my @whoami = split(/,/,$line); #load the info from rt $user->Load($whoami[0]); my $rtmail = $user->EmailAddress; # we now have two mail addresses, we need to see if they match without case sensitivity $rtmail = lc($rtmail); my $mastermail = lc($whoami[1]); if ($mastermail eq $rtmail) #{ #check to see if the user is privileged. If they are, stop there and dump the data to a text file #my $priv = $user->Privileged; # if ($priv eq "1") # { # open (PRIVUSERS, ">>/tmp/privlist.txt")|| die ("Cant open priv users list\n"); # print PRIVUSERS "$whoami[0] is a privileged user, cannot delete - $datestr\n"; # close (PRIVUSERS); # } # #else create the new name and mail address # else { my $dis ="+disabled"; #split the mail at @ add in the date and dis and glue it back together my @mail = split(/@/,$mastermail); my $newmail = $mail[0].$datestr.$dis."@".$mail[1]; #get the username whoami[0] and append the date to it my $newname = $whoami[0].$datestr; #make the changes $user->SetName($newname); $user->SetEmailAddress($newmail); #if you want ot create new password you'll need to code something here, else everyone gets the same one $user->SetPassword("SOMEPASSWORD"); $user->SetDisabled("1"); $user->SetPrivileged("0"); #log the change open (MOVED, ">>/tmp/movedlist.txt")|| die ("Cant open moved users list\n"); print MOVED "$whoami[0] - $datestr\n"; close (MOVED); } # } else { open (ERRORS, ">>/tmp/delerrors.txt")|| die ("Cant open errors list\n"); print ERRORS "$whoami[0] masterfile address $mastermail, does not match rt address $rtmail\n"; close (ERRORS); } } close (DELETIONS); exit
-- Dr Garry Booth IT Services Loughborough University On 15 Sep 2011, at 20:44, Cena, Stephen (ext. 300) wrote: > I'm trying to write some scrips for RT, specifically one that will take a > requestors email address & see if they are a current user. If not, create a > password & allow the user to get in. Nothing I'm trying is working at all. My > Perl is a little rusty, but I'm having a hell of a time figuring out what to > call from where. The perldoc for the .pm files in the /lib/RT folder seems to > be the only reference. > > Is there something a little more detailed out there? > > Steve > -------- > RT Training Sessions (http://bestpractical.com/services/training.html) > * Chicago, IL, USA ˜ September 26 & 27, 2011 > * San Francisco, CA, USA ˜ October 18 & 19, 2011 > * Washington DC, USA ˜ October 31 & November 1, 2011 > * Melbourne VIC, Australia ˜ November 28 & 29, 2011 > * Barcelona, Spain ˜ November 28 & 29, 2011
-------- RT Training Sessions (http://bestpractical.com/services/training.html) * Chicago, IL, USA September 26 & 27, 2011 * San Francisco, CA, USA October 18 & 19, 2011 * Washington DC, USA October 31 & November 1, 2011 * Melbourne VIC, Australia November 28 & 29, 2011 * Barcelona, Spain November 28 & 29, 2011
