use FS::part_export;
use FS::svc_acct;
use FS::export_svc;
+use Carp qw( cluck );
@ISA = qw(FS::part_export);
type => 'checkbox',
label => 'Show the Called-Station-ID on session reports',
},
- 'keep_password' => {
- type => 'checkbox',
- label => 'Do not change the password on suspend and unsuspend events',
- },
+ 'overlimit_groups' => { label => 'Radius groups to assign to svc_acct which has exceeded its bandwidth or time limit', } ,
'groups_susp_reason' => { label =>
- 'Radius group mapping to reason (via template user)',
+ 'Radius group mapping to reason (via template user) (svcnum|username|username@domain reasonnum|reason)',
type => 'textarea',
},
}
my @groups = $svc_acct->radius_groups;
if ( @groups ) {
+ cluck localtime(). ": queuing usergroup_insert for ". $svc_acct->svcnum.
+ " (". $self->export_username($svc_acct). " with ". join(", ", @groups)
+ if $DEBUG;
my $err_or_queue = $self->sqlradius_queue(
$svc_acct->svcnum, 'usergroup_insert',
$self->export_username($svc_acct), @groups );
sub _export_suspend {
my( $self, $svc_acct ) = (shift, shift);
- my $new = $self->option('keep_password') ? $svc_acct
- : $svc_acct->clone_suspended;
-
+ my $new = $svc_acct->clone_suspended;
+
local $SIG{HUP} = 'IGNORE';
local $SIG{INT} = 'IGNORE';
local $SIG{QUIT} = 'IGNORE';
my $dbh = sqlradius_connect(shift, shift, shift);
my( $username, @groups ) = @_;
+ my $s_sth = $dbh->prepare(
+ "SELECT COUNT(*) FROM usergroup WHERE UserName = ? AND GroupName = ?"
+ ) or die $dbh->errstr;
+
my $sth = $dbh->prepare(
"INSERT INTO usergroup ( UserName, GroupName ) VALUES ( ?, ? )"
) or die $dbh->errstr;
+
foreach my $group ( @groups ) {
+ $s_sth->execute( $username, $group ) or die $s_sth->errstr;
+ if ($s_sth->fetchrow_arrayref->[0]) {
+ warn localtime() . ": sqlradius_usergroup_insert attempted to reinsert " .
+ "$group for $username\n"
+ if $DEBUG;
+ next;
+ }
$sth->execute( $username, $group )
or die "can't insert into groupname table: ". $sth->errstr;
}
}
if ( @newgroups ) {
+ cluck localtime(). ": queuing usergroup_insert for $svcnum ($username) ".
+ "with ". join(", ", @newgroups)
+ if $DEBUG;
my $err_or_queue = $self->sqlradius_queue( $svcnum, 'usergroup_insert',
$username, @newgroups );
return $err_or_queue