[freeside-commits] freeside/FS/bin freeside-sqlradius-dedup-group, NONE, 1.1 freeside-sqlradius-reset, 1.9, 1.10
Jeff Finucane,420,,
jeff at wavetail.420.am
Sun May 6 23:35:58 PDT 2007
Update of /home/cvs/cvsroot/freeside/FS/bin
In directory wavetail:/home/jeff/freeside/FS/bin
Modified Files:
freeside-sqlradius-reset
Added Files:
freeside-sqlradius-dedup-group
Log Message:
sqlradius usergroup tools
Index: freeside-sqlradius-reset
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/bin/freeside-sqlradius-reset,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- freeside-sqlradius-reset 17 Oct 2005 06:46:02 -0000 1.9
+++ freeside-sqlradius-reset 7 May 2007 06:35:55 -0000 1.10
@@ -39,6 +39,7 @@
foreach my $export ( @exports ) {
#my @svcparts = map { $_->svcpart } $export->export_svc;
+ my $overlimit_groups = $export->option('overlimit_groups');
my @svc_acct =
map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) }
@@ -51,6 +52,12 @@
$svc_acct->check; #set any fixed usergroup so it'll export even if all
#svc_acct records don't have the group yet
+ if ($overlimit_groups && $svc_acct->overlimit) {
+ $svc_acct->usergroup( &{ $svc_acct->_fieldhandlers->{'usergroup'} }
+ ($svc_acct, $overlimit_groups)
+ );
+ }
+
#false laziness with FS::svc_acct::insert (like it matters)
my $error = $export->export_insert($svc_acct);
die $error if $error;
--- NEW FILE: freeside-sqlradius-dedup-group ---
#!/usr/bin/perl -w
use strict;
use vars qw( %seen @dups );
use Getopt::Std;
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearch qsearchs);
use FS::part_export;
my %allowed_types = map { $_ => 1 } qw ( sqlradius sqlradius_withdomain );
my $user = shift or die &usage;
adminsuidsetup $user;
my $export_x = shift;
my @part_export;
if ( !defined($export_x) ) {
@part_export = qsearch('part_export', {} );
} elsif ( $export_x =~ /^(\d+)$/ ) {
@part_export = qsearchs('part_export', { exportnum=>$1 } )
or die "exportnum $export_x not found\n";
} else {
@part_export = qsearch('part_export', { exporttype=>$export_x } )
or die "no exports of type $export_x found\n";
}
@part_export = grep { $allowed_types{$_->exporttype} } @part_export
or die "No sqlradius exports specified.";
foreach my $part_export ( @part_export ) {
my $dbh = DBI->connect( map $part_export->option($_),
qw ( datasrc username password ) );
my $sth = $dbh->prepare("SELECT id,username,groupname
FROM usergroup ORDER By username,groupname,id")
or die $dbh->errstr;
$sth->execute() or die $sth->errstr;
@dups = (); %seen = ();
while (my $row = $sth->fetchrow_arrayref ) {
my ($userid, $username, $groupname) = @$row;
unless ( exists($seen{$username}{$groupname}) ) {
$seen{$username}{$groupname} = $userid;
next;
}
push @dups, $userid;
}
$sth = $dbh->prepare("DELETE FROM usergroup WHERE id = ?")
or die $dbh->errstr;
foreach (@dups) {
$sth->execute($_) or die $sth->errstr;
}
}
sub usage {
die "Usage:\n\n freeside-sqlradius-dedup-group user [ exportnum|exporttype ]\n";
}
=head1 NAME
freeside-sqlradius-dedup-group - Command line tool to eliminate duplicate usergroup entries from radius tables
=head1 SYNOPSIS
freeside-sqlradius-dedup-group user [ exportnum|exporttype ]
=head1 DESCRIPTION
Removes all but one username groupname pair when duplicate entries exist
for the specified export (selected by exportnum or exporttype) or all
exports if none are specified.
=head1 SEE ALSO
L<freeside-reexport>, L<freeside-sqlradius-reset>, L<FS::part_export>
=cut
More information about the freeside-commits
mailing list