-#!/usr/bin/perl -Tw
+#!/usr/bin/perl -w
use strict;
use FS::UID qw(adminsuidsetup);
#my $machine = shift or die &usage;
-my @exports = qsearch('part_export', { 'exporttype' => 'sqlradius' } );
+my @exports = ();
+if ( @ARGV ) {
+ foreach my $exportnum ( @ARGV ) {
+ foreach my $exporttype (qw( sqlradius sqlradius_withdomain )) {
+ push @exports, qsearch('part_export', { exportnum => $exportnum,
+ exporttype => $exporttype, } );
+ }
+ }
+ } else {
+ @exports = qsearch('part_export', { exporttype=>'sqlradius' } );
+ push @exports, qsearch('part_export', { exporttype=>'sqlradius_withdomain' } );
+}
foreach my $export ( @exports ) {
my $icradius_dbh = DBI->connect(
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 } ) }
foreach my $svc_acct ( @svc_acct ) {
+ $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;
}
sub usage {
- #die "Usage:\n\n sqlradius_reset user machine\n";
- die "Usage:\n\n freeside-sqlradius-reset user\n";
+ die "Usage:\n\n freeside-sqlradius-reset user [ exportnum, ... ]\n";
}
=head1 NAME
=head1 SYNOPSIS
- freeside-sqlradius-reset username
+ freeside-sqlradius-reset username [ EXPORTNUM, ... ]
=head1 DESCRIPTION
Deletes the radcheck, radreply and usergroup tables and repopulates them from
-the Freeside database, for all sqlradius exports.
+the Freeside database, for the specified exports, or, if no exports are
+specified, for all sqlradius and sqlradius_withdomain exports.
B<username> is a username added by freeside-adduser.