RADIUS group attributes, #15017
[freeside.git] / FS / bin / freeside-sqlradius-reset
index c8da60a..b04c640 100755 (executable)
@@ -19,7 +19,7 @@ adminsuidsetup $user;
 my @exports = ();
 if ( @ARGV ) {
   foreach my $exportnum ( @ARGV ) {
-    foreach my $exporttype (qw( sqlradius sqlradius_withdomain ohone_sqlradius broadband_sqlradius )) {
+    foreach my $exporttype (qw( sqlradius sqlradius_withdomain phone_sqlradius broadband_sqlradius )) {
     push @exports, qsearch('part_export', { exportnum  => $exportnum,
                                             exporttype => $exporttype, } );
     }
@@ -35,7 +35,10 @@ unless ( $opt_n ) {
       map { $export->option($_) } qw( datasrc username password )
     ) or die $DBI::errstr;
     my $usergroup = $export->option('usergroup') || 'usergroup';
-    for my $table (qw( radcheck radreply ), $usergroup) {
+    my @attr_tables;
+    @attr_tables = qw( radgroupcheck radgroupreply )
+      if $export->option('export_attrs');
+    for my $table (qw( radcheck radreply ), $usergroup, @attr_tables) {
       my $sth = $icradius_dbh->prepare("DELETE FROM $table");
       $sth->execute or die "Can't reset $table table: ". $sth->errstr;
     }
@@ -47,6 +50,9 @@ use FS::svc_Common;
 $FS::svc_Common::overlimit_missing_cust_svc_nonfatal_kludge = 1;
 $FS::svc_Common::overlimit_missing_cust_svc_nonfatal_kludge = 1;
 
+# this is the same across all exports, for now
+my @radius_attrs = qsearch('radius_attr', {});
+
 foreach my $export ( @exports ) {
 
   #my @svcparts = map { $_->svcpart } $export->export_svc;
@@ -85,6 +91,13 @@ foreach my $export ( @exports ) {
     die $error if $error;
 
   }
+
+  if ( $export->option('export_attrs') ) {
+    foreach my $attr (@radius_attrs) {
+      my $error = $export->export_attr_insert($attr);
+      die $error if $error;
+    }
+  }
 }
 
 sub usage {