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 broadband_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 my $usergroup = $export->option('usergroup') || 'usergroup';
39 @attr_tables = qw( radgroupcheck radgroupreply )
40 if $export->option('export_attrs');
41 for my $table (qw( radcheck radreply ), $usergroup, @attr_tables) {
42 my $sth = $icradius_dbh->prepare("DELETE FROM $table");
43 $sth->execute or die "Can't reset $table table: ". $sth->errstr;
45 $icradius_dbh->disconnect;
50 $FS::svc_Common::overlimit_missing_cust_svc_nonfatal_kludge = 1;
51 $FS::svc_Common::overlimit_missing_cust_svc_nonfatal_kludge = 1;
53 # this is the same across all exports, for now
54 my @radius_attrs = qsearch('radius_attr', {});
56 foreach my $export ( @exports ) {
58 #my @svcparts = map { $_->svcpart } $export->export_svc;
59 my $overlimit_groups = $export->option('overlimit_groups');
63 #map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
64 #grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
65 # $export->export_svc;
67 grep { scalar( @{ $_->[1] } ) }
68 map { [ $_, [ qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) ] ] }
72 foreach my $svc_x ( @svc_x ) {
74 #$svc_x->check; #set any fixed usergroup so it'll export even if all
75 # #svc_acct records don't have the group yet
77 my $x = $svc_x->setfixed( $svc_x->_fieldhandlers);
79 warn "WARNING: can't set fixed usergroups for svcnum ". $svc_x->svcnum.
83 if ($overlimit_groups && $svc_x->overlimit) {
84 $svc_x->usergroup( &{ $svc_x->_fieldhandlers->{'usergroup'} }
85 ($svc_x, $overlimit_groups)
89 #false laziness with FS::svc_acct::insert (like it matters)
90 my $error = $export->export_insert($svc_x);
95 if ( $export->option('export_attrs') ) {
96 foreach my $attr (@radius_attrs) {
97 my $error = $export->export_attr_insert($attr);
104 die "Usage:\n\n freeside-sqlradius-reset user [ exportnum, ... ]\n";
109 freeside-sqlradius-reset - Command line interface to reset and recreate RADIUS SQL tables
113 freeside-sqlradius-reset [ -n ] username [ EXPORTNUM, ... ]
117 Deletes the radcheck, radreply and usergroup tables and repopulates them from
118 the Freeside database, for the specified exports, or, if no exports are
119 specified, for all sqlradius and sqlradius_withdomain exports.
121 B<username> is a username added by freeside-adduser.
123 The B<-n> option, if supplied, supresses the deletion of the existing data in
128 L<freeside-reexport>, L<FS::part_export>, L<FS::part_export::sqlradius>