s/icradius/sqlradius/
[freeside.git] / bin / sqlradius_reset
1 #!/usr/bin/perl -Tw
2
3 use strict;
4 use FS::UID qw(adminsuidsetup);
5 use FS::part_export;
6
7 my $user = shift or die &usage;
8 adminsuidsetup $user;
9
10 #my $machine = shift or die &usage;
11
12 my @exports = qsearch('part_export', { 'exporttype' => 'sqlradius' } );
13
14 foreach my $export ( @exports ) {
15   my $icradius_dbh = DBI->connect(
16     map { $export->option($_) } qw( datasrc username password )
17   ) or die $DBI::errstr;
18   for my $table (qw( radcheck radreply usergroup )) {
19     my $sth = $icradius_dbh->prepare("DELETE FROM $table");
20     $sth->execute or die "Can't reset $table table: ". $sth->errstr;
21   }
22 }
23
24 foreach my $export ( @exports ) {
25   my @svc_acct =
26     map { qsearchs{'svc_acct', { 'svcnum' => $_->svcnum } ) }
27       qsearch('cust_svc', { 'svcpart' => $export->part_svc->svcpart } );
28   foreach my $svc_acct ( @svc_acct ) {
29
30     #flase laziness with FS::svc_acct::insert (like it matters)
31     my $error = $part_export->export_insert($self);
32     if ( $error ) {
33       $dbh->rollback if $oldAutoCommit;
34       return "exporting to ". $part_export->exporttype.
35              " (transaction rolled back): $error";
36     }
37
38   }
39 }
40
41 sub usage {
42   #die "Usage:\n\n  icradius_reset user machine\n";
43   die "Usage:\n\n  icradius_reset user\n";
44 }
45
46