6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
14 my $user = shift or die &usage;
17 #my $machine = shift or die &usage;
21 foreach my $exportnum ( @ARGV ) {
22 foreach my $exporttype (qw( sqlradius sqlradius_withdomain phone_sqlradius )) {
23 push @exports, qsearch('part_export', { exportnum => $exportnum,
24 exporttype => $exporttype, } );
28 @exports = qsearch('part_export', { exporttype=>'sqlradius' } );
29 push @exports, qsearch('part_export', { exporttype=>'sqlradius_withdomain' } );
33 foreach my $export ( @exports ) {
34 my $icradius_dbh = DBI->connect(
35 map { $export->option($_) } qw( datasrc username password )
36 ) or die $DBI::errstr;
37 for my $table (qw( radcheck radreply usergroup )) {
38 my $sth = $icradius_dbh->prepare("DELETE FROM $table");
39 $sth->execute or die "Can't reset $table table: ". $sth->errstr;
41 $icradius_dbh->disconnect;
46 $FS::svc_Common::overlimit_missing_cust_svc_nonfatal_kludge = 1;
47 $FS::svc_Common::overlimit_missing_cust_svc_nonfatal_kludge = 1;
49 foreach my $export ( @exports ) {
51 #my @svcparts = map { $_->svcpart } $export->export_svc;
52 my $overlimit_groups = $export->option('overlimit_groups');
56 #map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
57 #grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
58 # $export->export_svc;
60 grep { scalar( @{ $_->[1] } ) }
61 map { [ $_, [ qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) ] ] }
65 foreach my $svc_x ( @svc_x ) {
67 #$svc_x->check; #set any fixed usergroup so it'll export even if all
68 # #svc_acct records don't have the group yet
70 my $x = $svc_x->setfixed( $svc_x->_fieldhandlers);
72 warn "WARNING: can't set fixed usergroups for svcnum ". $svc_x->svcnum.
76 if ($overlimit_groups && $svc_x->overlimit) {
77 $svc_x->usergroup( &{ $svc_x->_fieldhandlers->{'usergroup'} }
78 ($svc_x, $overlimit_groups)
82 #false laziness with FS::svc_acct::insert (like it matters)
83 my $error = $export->export_insert($svc_x);
90 die "Usage:\n\n freeside-sqlradius-reset user [ exportnum, ... ]\n";
95 freeside-sqlradius-reset - Command line interface to reset and recreate RADIUS SQL tables
99 freeside-sqlradius-reset [ -n ] username [ EXPORTNUM, ... ]
103 Deletes the radcheck, radreply and usergroup tables and repopulates them from
104 the Freeside database, for the specified exports, or, if no exports are
105 specified, for all sqlradius and sqlradius_withdomain exports.
107 B<username> is a username added by freeside-adduser.
109 The B<-n> option, if supplied, supresses the deletion of the existing data in
114 L<freeside-reexport>, L<FS::part_export>, L<FS::part_export::sqlradius>