diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-09-28 16:40:41 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-09-28 16:40:41 (GMT) |
commit | bcd58fdfc6d8496d5fa250aa8d6e0d0d3a89d49d (patch) | |
tree | 8d3349a97488e9256ab105dc65e581d5b185e369 /utils/rd-group | |
parent | 222541ee6348f21a0b8107bebb3701422614ba88 (diff) |
add group membership functions
Diffstat (limited to 'utils/rd-group')
-rwxr-xr-x | utils/rd-group | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/utils/rd-group b/utils/rd-group index a221d9f..1717caf 100755 --- a/utils/rd-group +++ b/utils/rd-group @@ -23,10 +23,17 @@ use strict; use RHRD::rddb; +# this is ridiculous but makes it a little harder to create/remove users... +if ($> != 0 ) { + print STDERR "this must be run as root!\n"; + exit 1; +} + my $num_args = $#ARGV + 1; if ($num_args < 2) { - print STDERR "Usage: rd-group ( (check|remove|get-carts|get-reports) <groupname> |\n" . + print STDERR "Usage: rd-group ( (check|remove|get-members|get-carts|get-reports) <groupname> |\n" . " add <groupname> [ <description> ] |\n" . + " (add-member|remove-member|is-member) <groupname> <user> |\n" . " set-carts <groupname> [ <low> [ <high> [ <type> [ <enforce range> ]]] |\n" . " set-reports <groupname> [ <nownext> [ <traffic> [ <music> ]]] )\n"; exit 1; @@ -59,6 +66,41 @@ if(defined $dbh) { print int($href->{cnt}) . " " . $href->{name} . " deleted\n"; } } + } elsif($cmd eq "get-members") { + my @users = RHRD::rddb::get_group_members($dbh, $groupname); + if(!defined $users[0] && defined $users[1]) { + print "$users[2]\n"; + RHRD::rddb::closedb($dbh); + exit 1; + } + for my $user (sort @users) { + print "$user\n"; + } + } elsif($cmd eq "add-member") { + (my $cnt, undef, $errorstring) = RHRD::rddb::add_group_member($dbh, $groupname, $ARGV[2]); + unless(defined $cnt) { + print "$errorstring\n"; + RHRD::rddb::closedb($dbh); + exit 1; + } + print int($cnt) . " rows affected\n"; + } elsif($cmd eq "remove-member") { + (my $cnt, undef, $errorstring) = RHRD::rddb::remove_group_member($dbh, $groupname, $ARGV[2]); + unless(defined $cnt) { + print "$errorstring\n"; + RHRD::rddb::closedb($dbh); + exit 1; + } + print int($cnt) . " rows affected\n"; + } elsif($cmd eq "is-member") { + (my $cnt, undef, $errorstring) = RHRD::rddb::is_group_member($dbh, $groupname, $ARGV[2]); + RHRD::rddb::closedb($dbh); + unless(defined $cnt) { + print "$errorstring\n"; + exit 1; + } + print $ARGV[2] . " is" . (($cnt) ? "" : " not") . " a member\n"; + exit (($cnt) ? 0 : 1); } elsif($cmd eq "get-carts") { my ($low, $high, $type, $enforce_range) = RHRD::rddb::get_group_carts($dbh, $groupname); unless(defined $low) { |