4 use vars qw( %seen @dups );
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
10 my %allowed_types = map { $_ => 1 } qw ( sqlradius sqlradius_withdomain );
12 my $user = shift or die &usage;
17 if ( !defined($export_x) ) {
18 @part_export = qsearch('part_export', {} );
19 } elsif ( $export_x =~ /^(\d+)$/ ) {
20 @part_export = qsearchs('part_export', { exportnum=>$1 } )
21 or die "exportnum $export_x not found\n";
23 @part_export = qsearch('part_export', { exporttype=>$export_x } )
24 or die "no exports of type $export_x found\n";
27 @part_export = grep { $allowed_types{$_->exporttype} } @part_export
28 or die "No sqlradius exports specified.";
30 foreach my $part_export ( @part_export ) {
31 my $dbh = DBI->connect( map $part_export->option($_),
32 qw ( datasrc username password ) );
34 my $sth = $dbh->prepare("SELECT id,username,groupname
35 FROM usergroup ORDER By username,groupname,id")
37 $sth->execute() or die $sth->errstr;
39 @dups = (); %seen = ();
40 while (my $row = $sth->fetchrow_arrayref ) {
41 my ($userid, $username, $groupname) = @$row;
42 unless ( exists($seen{$username}{$groupname}) ) {
43 $seen{$username}{$groupname} = $userid;
49 $sth = $dbh->prepare("DELETE FROM usergroup WHERE id = ?")
53 $sth->execute($_) or die $sth->errstr;
60 die "Usage:\n\n freeside-sqlradius-dedup-group user [ exportnum|exporttype ]\n";
65 freeside-sqlradius-dedup-group - Command line tool to eliminate duplicate usergroup entries from radius tables
69 freeside-sqlradius-dedup-group user [ exportnum|exporttype ]
73 Removes all but one username groupname pair when duplicate entries exist
74 for the specified export (selected by exportnum or exporttype) or all
75 exports if none are specified.
79 L<freeside-reexport>, L<freeside-sqlradius-reset>, L<FS::part_export>