X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fbroadband_sqlradius.pm;h=e58c641cf11eb49c9ac4cb6ab53cc7a8cb06b634;hb=674cb2d9d7105f4cc2871539b2e9f7088cdaa750;hp=dc117b05c6d179239e5e89b09f8bc64ab09a7978;hpb=d8d63a28503d40743425dceda7e0b744739eeb2a;p=freeside.git diff --git a/FS/FS/part_export/broadband_sqlradius.pm b/FS/FS/part_export/broadband_sqlradius.pm index dc117b05c..e58c641cf 100644 --- a/FS/FS/part_export/broadband_sqlradius.pm +++ b/FS/FS/part_export/broadband_sqlradius.pm @@ -1,13 +1,20 @@ package FS::part_export::broadband_sqlradius; use strict; -use vars qw($DEBUG @ISA %options %info $conf); +use vars qw($DEBUG @ISA @pw_set %options %info $conf); use Tie::IxHash; use FS::Conf; use FS::Record qw( dbh str2time_sql ); #qsearch qsearchs ); use FS::part_export::sqlradius qw(sqlradius_connect); +use FS::Password_Mixin; +use NEXT; -FS::UID->install_callback(sub { $conf = new FS::Conf }); +FS::UID->install_callback( + sub { + $conf = new FS::Conf; + @pw_set = FS::Password_Mixin->pw_set; + } +); @ISA = qw(FS::part_export::sqlradius); @@ -26,6 +33,11 @@ tie %options, 'Tie::IxHash', # type => 'checkbox', # label => 'Hide IP address on session reports', # }, + 'mac_case' => { + label => 'Export MAC address as', + type => 'select', + options => [ qw(uppercase lowercase) ], + }, 'mac_delimiter' => { label => 'Separate MAC address octets with', default => '-', @@ -48,6 +60,7 @@ tie %options, 'Tie::IxHash', 'svc' => 'svc_broadband', 'desc' => 'Real-time export to SQL-backed RADIUS (such as FreeRadius) for broadband services', 'options' => \%options, + 'no_machine' => 1, 'nas' => 'Y', 'notes' => <radcheck, radreply, and usergroup @@ -73,13 +86,16 @@ sub rebless { shift; } sub export_username { my($self, $svc_broadband) = (shift, shift); - my $mac_addr = $svc_broadband->mac_addr; - join( ($self->option('mac_delimiter',1) || ''), $mac_addr =~ /../g ); + $svc_broadband->mac_addr_formatted( + $self->option('mac_case'), $self->option('mac_delimiter') + ); } sub radius_reply { my($self, $svc_broadband) = (shift, shift); - my %reply; + # start with attributes the service wants + my %reply = $self->NEXT::radius_reply($svc_broadband); + # add export-specific stuff if ( length($self->option('ip_addr_as',1)) and length($svc_broadband->ip_addr) ) { $reply{$self->option('ip_addr_as')} = $svc_broadband->ip_addr; @@ -89,12 +105,11 @@ sub radius_reply { sub radius_check { my($self, $svc_broadband) = (shift, shift); + + my %check = $self->SUPER::radius_check($svc_broadband); my $password_attrib = $conf->config('radius-password') || 'Password'; - my %check; if ( $self->option('mac_as_password') ) { - my $mac_addr = $svc_broadband->mac_addr; - $check{$password_attrib} = - join( ($self->option('mac_delimiter',1) || ''), $mac_addr =~ /../g ); + $check{$password_attrib} = $self->export_username($svc_broadband); } elsif ( length( $self->option('radius_password',1)) ) { $check{$password_attrib} = $self->option('radius_password'); @@ -102,8 +117,65 @@ sub radius_check { %check; } -sub _export_suspend {} -sub _export_unsuspend {} +sub radius_check_suspended { + my($self, $svc_broadband) = (shift, shift); + + return () unless $self->option('mac_as_password') + || length( $self->option('radius_password',1)); + + my $password_attrib = $conf->config('radius-password') || 'Password'; + ( + $password_attrib => join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) ) + ); +} + +#false laziness w/sqlradius.pm +sub _export_suspend { + my( $self, $svc_broadband ) = (shift, shift); + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my @newgroups = $self->suspended_usergroups($svc_broadband); + + unless (@newgroups) { #don't change password if assigning to a suspended group + + my $err_or_queue = $self->sqlradius_queue( + $svc_broadband->svcnum, 'insert', + 'check', $self->export_username($svc_broadband), + $self->radius_check_suspended($svc_broadband) + ); + unless ( ref($err_or_queue) ) { + $dbh->rollback if $oldAutoCommit; + return $err_or_queue; + } + + } + + my $error = + $self->sqlreplace_usergroups( + $svc_broadband->svcnum, + $self->export_username($svc_broadband), + '', + [ $svc_broadband->radius_groups('hashref') ], + \@newgroups, + ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; +} sub update_svc {} #do nothing