From: levinse Date: Fri, 1 Jul 2011 06:54:03 +0000 (+0000) Subject: RADIUS group enhancements, overlimit_groups changes, etc. RT13432 X-Git-Tag: freeside_2_3_0~43 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=4665d5af02f915679207a369222472a25e137c9d RADIUS group enhancements, overlimit_groups changes, etc. RT13432 --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 170d88479..4ff3aa77a 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2856,8 +2856,21 @@ and customer address. Include units.', 'key' => 'overlimit_groups', 'section' => '', 'description' => 'RADIUS group (or comma-separated groups) to assign to svc_acct which has exceeded its bandwidth or time limit.', - 'type' => 'text', + 'type' => 'select-sub', 'per_agent' => 1, + 'multiple' => 1, + 'options_sub' => sub { require FS::Record; + require FS::radius_group; + map { $_->groupnum => $_->long_description } + FS::Record::qsearch('radius_group', {} ); + }, + 'option_sub' => sub { require FS::Record; + require FS::radius_group; + my $radius_group = FS::Record::qsearchs( + 'radius_group', { 'groupnum' => shift } + ); + $radius_group ? $radius_group->long_description : ''; + }, }, { diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index ca6036e5f..3ea554e4a 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -6,7 +6,7 @@ use Exporter; use Tie::IxHash; use FS::UID qw( dbh driver_name ); use FS::Conf; -use FS::Record qw(qsearchs str2time_sql); +use FS::Record qw(qsearchs qsearch str2time_sql); use FS::svc_domain; $FS::svc_domain::whois_hack = 1; @@ -47,6 +47,35 @@ sub upgrade_config { if $conf->exists('payment_receipt_email') || $conf->config('payment_receipt_msgnum'); + upgrade_overlimit_groups($conf); + map { upgrade_overlimit_groups($conf,$_->agentnum) } qsearch('agent', {}); + +} + +sub upgrade_overlimit_groups { + my $conf = shift; + my $agentnum = shift; + my @groups = $conf->config('overlimit_groups',$agentnum); + if(scalar(@groups)) { + my $groups = join(',',@groups); + my @groupnums; + my $error = ''; + if ( $groups !~ /^[\d,]+$/ ) { + foreach my $groupname ( @groups ) { + my $g = qsearchs('radius_group', { 'groupname' => $groupname } ); + unless ( $g ) { + $g = new FS::radius_group { + 'groupname' => $groupname, + 'description' => $groupname, + }; + $error = $g->insert; + die $error if $error; + } + push @groupnums, $g->groupnum; + } + $conf->set('overlimit_groups',join("\n",@groupnums),$agentnum); + } + } } =item upgrade @@ -194,6 +223,7 @@ sub upgrade_data { # migrate to radius_group and groupnum instead of groupname 'radius_usergroup' => [], 'part_svc' => [], + 'part_export' => [], ; diff --git a/FS/FS/part_export.pm b/FS/FS/part_export.pm index d3068df81..890c522f6 100644 --- a/FS/FS/part_export.pm +++ b/FS/FS/part_export.pm @@ -431,6 +431,34 @@ sub export_info { my $r = { map { %{$exports{$_}} } keys %exports }; } + +sub _upgrade_data { #class method + my ($class, %opts) = @_; + + my @part_export_option = qsearch('part_export_option', { 'optionname' => 'overlimit_groups' }); + foreach my $opt ( @part_export_option ) { + next if $opt->optionvalue =~ /^[\d\s]+$/ || !$opt->optionvalue; + my @groupnames = split(' ',$opt->optionvalue); + my @groupnums; + my $error = ''; + foreach my $groupname ( @groupnames ) { + my $g = qsearchs('radius_group', { 'groupname' => $groupname } ); + unless ( $g ) { + $g = new FS::radius_group { + 'groupname' => $groupname, + 'description' => $groupname, + }; + $error = $g->insert; + die $error if $error; + } + push @groupnums, $g->groupnum; + } + $opt->optionvalue(join(' ',@groupnums)); + $error = $opt->replace; + die $error if $error; + } +} + #=item exporttype2svcdb EXPORTTYPE # #Returns the applicable I for an I. diff --git a/FS/FS/part_export/phone_sqlradius.pm b/FS/FS/part_export/phone_sqlradius.pm index 24f784534..0816efab6 100644 --- a/FS/FS/part_export/phone_sqlradius.pm +++ b/FS/FS/part_export/phone_sqlradius.pm @@ -36,13 +36,6 @@ tie %options, 'Tie::IxHash', # label => 'Show the Called-Station-ID on session reports', #}, - #N/A - #'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) (svcnum|username|username@domain reasonnum|reason)', - # type => 'textarea', - # }, - ; %info = ( diff --git a/FS/FS/part_export/sqlradius.pm b/FS/FS/part_export/sqlradius.pm index d1663dcf5..4dea80e49 100644 --- a/FS/FS/part_export/sqlradius.pm +++ b/FS/FS/part_export/sqlradius.pm @@ -14,6 +14,7 @@ use Carp qw( cluck ); $DEBUG = 0; +my %groups; tie %options, 'Tie::IxHash', 'datasrc' => { label=>'DBI data source ' }, 'username' => { label=>'Database username' }, @@ -47,7 +48,21 @@ tie %options, 'Tie::IxHash', type => 'checkbox', label => 'Show the Called-Station-ID on session reports', }, - 'overlimit_groups' => { label => 'Radius groups to assign to svc_acct which has exceeded its bandwidth or time limit (if not overridden by overlimit_groups global or per-agent config)', } , + 'overlimit_groups' => { + label => 'Radius groups to assign to svc_acct which has exceeded its bandwidth or time limit (if not overridden by overlimit_groups global or per-agent config)', + type => 'select', + multi => 1, + option_label => sub { + $groups{$_[0]}; + }, + option_values => sub { + %groups = ( + map { $_->groupnum, $_->long_description } + qsearch('radius_group', {}), + ); + sort keys (%groups); + }, + } , 'groups_susp_reason' => { label => 'Radius group mapping to reason (via template user) (svcnum|username|username@domain reasonnum|reason)', type => 'textarea', diff --git a/FS/FS/radius_group.pm b/FS/FS/radius_group.pm index 96de2948a..eeb291b4b 100644 --- a/FS/FS/radius_group.pm +++ b/FS/FS/radius_group.pm @@ -112,6 +112,19 @@ sub check { $self->SUPER::check; } +=item long_description + +Returns a description for this group consisting of its description field, +if any, and the RADIUS group name. + +=cut + +sub long_description { + my $self = shift; + $self->description ? $self->description . " (". $self->groupname . ")" + : $self->groupname; +} + =back =head1 BUGS diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index e8c797afa..7ef8ed3aa 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -2227,20 +2227,19 @@ sub _op_overlimit { my $cust_pkg = $self->cust_svc->cust_pkg; - my $conf_overlimit = + my @conf_overlimit = $cust_pkg ? $conf->config('overlimit_groups', $cust_pkg->cust_main->agentnum ) : $conf->config('overlimit_groups'); foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { - my $groups = $conf_overlimit || $part_export->option('overlimit_groups'); - next unless $groups; - - my $gref = &{ $self->_fieldhandlers->{'usergroup'} }( $self, $groups ); + my @groups = scalar(@conf_overlimit) ? @conf_overlimit + : split(' ',$part_export->option('overlimit_groups')); + next unless scalar(@groups); my $other = new FS::svc_acct $self->hashref; - $other->usergroup( $gref ); + $other->usergroup(\@groups); my($new,$old); if ($action eq 'suspend') { diff --git a/httemplate/config/config-view.cgi b/httemplate/config/config-view.cgi index 4c90ebb8d..e7cadbe99 100644 --- a/httemplate/config/config-view.cgi +++ b/httemplate/config/config-view.cgi @@ -207,8 +207,16 @@ Click on a configuration value to change it. +% if ( $i->multiple ) { + <% join('
', + map { $_ . ": " . &{ $i->option_sub }($_) } + $conf->config($i->key,$agentnum) + ) + %> +% } else { <% $conf->config($i->key, $agentnum) %>: <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %> +% } diff --git a/httemplate/edit/svc_acct.cgi b/httemplate/edit/svc_acct.cgi index 8fda25033..66b58e2c7 100755 --- a/httemplate/edit/svc_acct.cgi +++ b/httemplate/edit/svc_acct.cgi @@ -452,7 +452,7 @@ my $part_svc_usergroup = $part_svc->part_svc_column('usergroup'); my @groupnames; # only used for display of Fixed RADIUS groups if ( $part_svc_usergroup->columnflag eq 'F' ) { @groups = split(',',$part_svc_usergroup->columnvalue); - @groupnames = map { $_->description . " (" . $_->groupname . ")" } + @groupnames = map { $_->long_description } qsearch({ 'table' => 'radius_group', 'extra_sql' => "where groupnum in (".$part_svc_usergroup->columnvalue.")", }) if length($part_svc_usergroup->columnvalue); diff --git a/httemplate/elements/select-radius_group.html b/httemplate/elements/select-radius_group.html index eeaf5ac55..e1e3c5980 100644 --- a/httemplate/elements/select-radius_group.html +++ b/httemplate/elements/select-radius_group.html @@ -10,7 +10,7 @@ my %opt = @_; -my %groups = map { $_->groupnum => $_->description . " (" . $_->groupname . ")" } +my %groups = map { $_->groupnum => $_->long_description } qsearch('radius_group', {}); my @sel_groups = split(/,/,$opt{'curr_value'});