[freeside-commits] branch master updated. cc6bedada3c99e3e9ca4748546f3b4ab847c3cba
Ivan
ivan at 420.am
Tue Jun 12 16:13:05 PDT 2012
The branch, master has been updated
via cc6bedada3c99e3e9ca4748546f3b4ab847c3cba (commit)
from f0842371ad319e9423fba20ea5b013dbbf449525 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit cc6bedada3c99e3e9ca4748546f3b4ab847c3cba
Author: Ivan Kohler <ivan at freeside.biz>
Date: Tue Jun 12 16:13:04 2012 -0700
broadband_sqlradius.pm (svc_broadband RADIUS export) suspension, RT#18093
diff --git a/FS/FS/part_export/broadband_sqlradius.pm b/FS/FS/part_export/broadband_sqlradius.pm
index 29bd288..5806362 100644
--- a/FS/FS/part_export/broadband_sqlradius.pm
+++ b/FS/FS/part_export/broadband_sqlradius.pm
@@ -1,7 +1,7 @@
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 );
@@ -13,6 +13,8 @@ FS::UID->install_callback(sub { $conf = new FS::Conf });
$DEBUG = 0;
+ at pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '.', ',' );
+
tie %options, 'Tie::IxHash',
'datasrc' => { label=>'DBI data source ' },
'username' => { label=>'Database username' },
@@ -106,8 +108,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
diff --git a/FS/FS/part_export/sqlradius.pm b/FS/FS/part_export/sqlradius.pm
index 57bbdb4..c360c9e 100644
--- a/FS/FS/part_export/sqlradius.pm
+++ b/FS/FS/part_export/sqlradius.pm
@@ -111,6 +111,7 @@ END
'options' => \%options,
'nodomain' => 'Y',
'nas' => 'Y', # show export_nas selection in UI
+ 'default_svc_class' => 'Internet',
'notes' => $notes1.
'This export does not export RADIUS realms (see also '.
'sqlradius_withdomain). '.
@@ -250,6 +251,7 @@ sub _export_replace {
'';
}
+#false laziness w/broadband_sqlradius.pm
sub _export_suspend {
my( $self, $svc_acct ) = (shift, shift);
@@ -297,7 +299,7 @@ sub _export_suspend {
}
sub _export_unsuspend {
- my( $self, $svc_acct ) = (shift, shift);
+ my( $self, $svc_x ) = (shift, shift);
local $SIG{HUP} = 'IGNORE';
local $SIG{INT} = 'IGNORE';
@@ -310,21 +312,21 @@ sub _export_unsuspend {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- my $err_or_queue = $self->sqlradius_queue( $svc_acct->svcnum, 'insert',
- 'check', $self->export_username($svc_acct), $svc_acct->radius_check );
+ my $err_or_queue = $self->sqlradius_queue( $svc_x->svcnum, 'insert',
+ 'check', $self->export_username($svc_x), $self->radius_check($svc_x) );
unless ( ref($err_or_queue) ) {
$dbh->rollback if $oldAutoCommit;
return $err_or_queue;
}
my $error;
- my (@oldgroups) = $self->suspended_usergroups($svc_acct);
+ my (@oldgroups) = $self->suspended_usergroups($svc_x);
$error = $self->sqlreplace_usergroups(
- $svc_acct->svcnum,
- $self->export_username($svc_acct),
+ $svc_x->svcnum,
+ $self->export_username($svc_x),
'',
\@oldgroups,
- [ $svc_acct->radius_groups('hashref') ],
+ [ $svc_x->radius_groups('hashref') ],
);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
@@ -358,14 +360,16 @@ sub sqlradius_queue {
}
sub suspended_usergroups {
- my ($self, $svc_acct) = (shift, shift);
+ my ($self, $svc_x) = (shift, shift);
+
+ return () unless $svc_x;
- return () unless $svc_acct;
+ my $svc_table = $svc_x->table;
#false laziness with FS::part_export::shellcommands
#subclass part_export?
- my $r = $svc_acct->cust_svc->cust_pkg->last_reason('susp');
+ my $r = $svc_x->cust_svc->cust_pkg->last_reason('susp');
my %reasonmap = $self->_groups_susp_reason_map;
my $userspec = '';
if ($r) {
@@ -374,19 +378,19 @@ sub suspended_usergroups {
$userspec = $reasonmap{$r->reason}
if (!$userspec && exists($reasonmap{$r->reason}));
}
- my $suspend_user;
- if ($userspec =~ /^\d+$/ ){
- $suspend_user = qsearchs( 'svc_acct', { 'svcnum' => $userspec } );
- }elsif ($userspec =~ /^\S+\@\S+$/){
+ my $suspend_svc;
+ if ( $userspec =~ /^\d+$/ ){
+ $suspend_svc = qsearchs( $svc_table, { 'svcnum' => $userspec } );
+ } elsif ( $userspec =~ /^\S+\@\S+$/ && $svc_table eq 'svc_acct' ){
my ($username,$domain) = split(/\@/, $userspec);
for my $user (qsearch( 'svc_acct', { 'username' => $username } )){
- $suspend_user = $user if $userspec eq $user->email;
+ $suspend_svc = $user if $userspec eq $user->email;
}
- }elsif ($userspec){
- $suspend_user = qsearchs( 'svc_acct', { 'username' => $userspec } );
+ }elsif ( $userspec && $svc_table eq 'svc_acct' ){
+ $suspend_svc = qsearchs( 'svc_acct', { 'username' => $userspec } );
}
#esalf
- return $suspend_user->radius_groups('hashref') if $suspend_user;
+ return $suspend_svc->radius_groups('hashref') if $suspend_svc;
();
}
@@ -756,7 +760,7 @@ sub usage_sessions {
}
-=item update_svc_acct
+=item update_svc
=cut
-----------------------------------------------------------------------
Summary of changes:
FS/FS/part_export/broadband_sqlradius.pm | 65 ++++++++++++++++++++++++++++-
FS/FS/part_export/sqlradius.pm | 42 ++++++++++---------
2 files changed, 85 insertions(+), 22 deletions(-)
More information about the freeside-commits
mailing list