4 use FS::UID qw(adminsuidsetup);
5 use FS::Record qw(qsearch qsearchs);
10 my $user = shift or die &usage;
13 #my $machine = shift or die &usage;
17 foreach my $exportnum ( @ARGV ) {
18 foreach my $exporttype (qw( sqlradius sqlradius_withdomain )) {
19 push @exports, qsearch('part_export', { exportnum => $exportnum,
20 exporttype => $exporttype, } );
24 @exports = qsearch('part_export', { exporttype=>'sqlradius' } );
25 push @exports, qsearch('part_export', { exporttype=>'sqlradius_withdomain' } );
28 foreach my $export ( @exports ) {
29 my $icradius_dbh = DBI->connect(
30 map { $export->option($_) } qw( datasrc username password )
31 ) or die $DBI::errstr;
32 for my $table (qw( radcheck radreply usergroup )) {
33 my $sth = $icradius_dbh->prepare("DELETE FROM $table");
34 $sth->execute or die "Can't reset $table table: ". $sth->errstr;
36 $icradius_dbh->disconnect;
39 foreach my $export ( @exports ) {
41 #my @svcparts = map { $_->svcpart } $export->export_svc;
44 map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) }
45 map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
46 grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
49 foreach my $svc_acct ( @svc_acct ) {
51 $svc_acct->check; #set any fixed usergroup so it'll export even if all
52 #svc_acct records don't have the group yet
54 #false laziness with FS::svc_acct::insert (like it matters)
55 my $error = $export->export_insert($svc_acct);
62 die "Usage:\n\n freeside-sqlradius-reset user [ exportnum, ... ]\n";
67 freeside-sqlradius-reset - Command line interface to reset and recreate RADIUS SQL tables
71 freeside-sqlradius-reset username [ EXPORTNUM, ... ]
75 Deletes the radcheck, radreply and usergroup tables and repopulates them from
76 the Freeside database, for the specified exports, or, if no exports are
77 specified, for all sqlradius and sqlradius_withdomain exports.
79 B<username> is a username added by freeside-adduser.
83 L<freeside-reexport>, L<FS::part_export>, L<FS::part_export::sqlradius>