fixup
[freeside.git] / FS / bin / freeside-radgroup
1 #!/usr/bin/perl -w
2
3 use strict;
4 use FS::UID qw(adminsuidsetup);
5 use FS::Record qw(qsearch);
6 use FS::cust_svc;
7 use FS::svc_acct;
8
9 &untaint_argv;  #what it sounds like  (eww)
10
11 my($user, $action, $groupname, $svcpart) = @ARGV;
12
13 adminsuidsetup $user;
14
15 my @svc_acct = map { $_->svc_x } qsearch('cust_svc', { svcpart => $svcpart } );
16
17 if ( lc($action) eq 'add' ) {
18   foreach my $svc_acct ( @svc_acct ) {
19     my @groups = $svc_acct->radius_groups;
20     next if grep { $_ eq $groupname } @groups;
21     push @groups, $groupname;
22     my %hash = $svc_acct->hash;
23     $hash{usergroup} = \@groups;
24     my $new = new FS::svc_acct \%hash;
25     my $error = $new->replace($svc_acct);
26     die $error if $error;
27   }
28 } else {
29   die &usage;
30 }
31
32 # subroutines
33
34 sub untaint_argv {
35   foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
36     $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
37     $ARGV[$_]=$1;
38   }
39 }
40
41 sub usage {
42   die "Usage:\n\n  freeside-radgroup user action groupname svcpart\n";
43 }
44
45 =head1 NAME
46
47 freeside-radgroup - Command line utility to manipulate radius groups
48
49 =head1 SYNOPSIS
50
51   freeside-addgroup user action groupname svcpart 
52
53 =head1 DESCRIPTION
54
55   B<user> is a freeside user as added with freeside-adduser.
56
57   B<command> is the action to take.  Available actions are: I<add>
58
59   B<groupname> is the group to add (or remove, etc.)
60
61   B<svcpart> specifies which accounts will be updated.
62
63 =head1 EXAMPLES
64
65 freeside-radgroup freesideuser add groupname 3
66
67 Adds I<groupname> to all accounts with service definition 3.
68
69 =head1 BUGS
70
71 =head1 SEE ALSO
72
73 L<freeside-adduser>, L<FS::svc_acct>, L<FS::part_svc>
74
75 =cut
76