use vars qw(@ISA $DEBUG %info %options $notes1 $notes2);
use Tie::IxHash;
-use FS::Record qw( dbh qsearch qsearchs );
+use FS::Record qw( dbh qsearch qsearchs str2time_sql );
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',
},
sub export_username {
my($self, $svc_acct) = (shift, shift);
- warn "export_username called on $self with arg $svc_acct" if $DEBUG;
+ warn "export_username called on $self with arg $svc_acct" if $DEBUG > 1;
$svc_acct->username;
}
}
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
qw( datasrc username password ) );
#select a unix time conversion function based on database type
- my $str2time;
- if ( $dbh->{Driver}->{Name} =~ /^mysql(PP)?$/ ) {
- $str2time = 'UNIX_TIMESTAMP(';
- } elsif ( $dbh->{Driver}->{Name} eq 'Pg' ) {
- $str2time = 'EXTRACT( EPOCH FROM ';
- } else {
- warn "warning: unknown database type ". $dbh->{Driver}->{Name}.
- "; guessing how to convert to UNIX timestamps";
- $str2time = 'extract(epoch from ';
- }
+ my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
my @fields = (
qw( username realm framedipaddress
sub update_svc_acct {
my $self = shift;
+ my $conf = new FS::Conf;
+
my $dbh = sqlradius_connect( map $self->option($_),
qw( datasrc username password ) );
"$RadAcctId ($UserName\@$Realm for ${AcctSessionTime}s"
if $DEBUG;
+ $UserName = lc($UserName) unless $conf->exists('username-uppercase');
+
my %search = ( 'username' => $UserName );
+
my $extra_sql = '';
if ( ref($self) =~ /withdomain/ ) { #well...
$extra_sql = " AND '$Realm' = ( SELECT domain FROM svc_domain