tcms-useradd 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env perl
  2. package tcms::useradd;
  3. use strict;
  4. use warnings;
  5. use FindBin::libs;
  6. use Getopt::Long;
  7. use Pod::Usage;
  8. use Trog::Auth;
  9. =head1 SYNOPSIS
  10. Add or edit a tCMS user. In the event of a user edit, every option save for user is optional.
  11. does not update user pages. Use this to reset user passwords or fix broken users.
  12. =head2 USAGE
  13. tcms-useradd --user foo --password bar --display_name baz --contact_email foo@bar.baz --acl fred --acl wilma
  14. =head2 OPTIONS
  15. =over 4
  16. =item --user
  17. Specify the user to add, or edit if the user already exists.
  18. =item --password
  19. Set a password for the user. Leave blank if you want to keep the password for an existing user.
  20. =item --display_name
  21. Set the display name for the user.
  22. =item --contact_email
  23. Set the contact email for the user.
  24. =item --acl
  25. Set an acl for this user. May be passed multiple times.
  26. Defaults to 'admin' acl.
  27. =item --help, --man
  28. Display this output.
  29. =back
  30. =cut
  31. sub main {
  32. my %options;
  33. Getopt::Long::GetOptionsFromArray(\@_,
  34. 'user=s' => \$options{user},
  35. 'display_name=s' => \$options{display_name},
  36. 'help|?' => \$options{help},
  37. 'password=s' => \$options{password},
  38. 'contact_email=s' => \$options{contact_email},
  39. 'acl=s@' => \$options{acl},
  40. );
  41. pod2usage(-exitval => 0, -verbose => 1) if $options{help};
  42. $options{acl} //= [];
  43. $options{acl} = [$options{acl}] if $options{acl} && ref $options{acl} ne 'ARRAY';
  44. $options{acl} = ['admin'] unless @{$options{acl}};
  45. Trog::Auth::killsession($options{user});
  46. Trog::Auth::useradd( $options{user}, $options{display_name}, $options{password}, $options{acl}, $options{contactemail} );
  47. return 0;
  48. }
  49. exit main(@ARGV) unless caller;
  50. 1;