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;
45 foreach my $export ( @exports ) {
47 #my @svcparts = map { $_->svcpart } $export->export_svc;
48 my $overlimit_groups = $export->option('overlimit_groups');
52 map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
53 grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
56 foreach my $svc_x ( @svc_x ) {
58 $svc_x->check; #set any fixed usergroup so it'll export even if all
59 #svc_acct records don't have the group yet
61 if ($overlimit_groups && $svc_x->overlimit) {
62 $svc_x->usergroup( &{ $svc_x->_fieldhandlers->{'usergroup'} }
63 ($svc_x, $overlimit_groups)
67 #false laziness with FS::svc_acct::insert (like it matters)
68 my $error = $export->export_insert($svc_x);
75 die "Usage:\n\n freeside-sqlradius-reset user [ exportnum, ... ]\n";
80 freeside-sqlradius-reset - Command line interface to reset and recreate RADIUS SQL tables
84 freeside-sqlradius-reset [ -n ] username [ EXPORTNUM, ... ]
88 Deletes the radcheck, radreply and usergroup tables and repopulates them from
89 the Freeside database, for the specified exports, or, if no exports are
90 specified, for all sqlradius and sqlradius_withdomain exports.
92 B<username> is a username added by freeside-adduser.
94 The B<-n> option, if supplied, supresses the deletion of the existing data in
99 L<freeside-reexport>, L<FS::part_export>, L<FS::part_export::sqlradius>