From 7aef2e455fe8a4722036f231ee8609ac63b2a9c9 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 10 Nov 2011 21:40:25 +0000 Subject: RADIUS groups for svc_broadband, #14695 --- httemplate/browse/part_svc.cgi | 6 +- httemplate/edit/process/svc_broadband.cgi | 14 +- httemplate/edit/svc_acct.cgi | 3 +- httemplate/edit/svc_broadband.cgi | 26 ++- httemplate/elements/select-radius_group.html | 23 +- httemplate/elements/tr-fixed.html | 12 +- httemplate/elements/tr-select-radius_group.html | 11 + httemplate/view/elements/svc_Common.html | 14 +- httemplate/view/svc_acct/basics.html | 2 +- httemplate/view/svc_broadband.cgi | 274 +++++------------------- 10 files changed, 132 insertions(+), 253 deletions(-) create mode 100644 httemplate/elements/tr-select-radius_group.html (limited to 'httemplate') diff --git a/httemplate/browse/part_svc.cgi b/httemplate/browse/part_svc.cgi index 4549e44dd..1cd0943bb 100755 --- a/httemplate/browse/part_svc.cgi +++ b/httemplate/browse/part_svc.cgi @@ -60,12 +60,14 @@ function part_export_areyousure(href) { Modifier - +% my $conf = FS::Conf->new; % foreach my $part_svc ( @part_svc ) { % my $svcdb = $part_svc->svcdb; % my $svc_x = "FS::$svcdb"->new( { svcpart => $part_svc->svcpart } ); % my @dfields = $svc_x->fields; -% push @dfields, 'usergroup' if $svcdb eq 'svc_acct'; #kludge +% push @dfields, 'usergroup' if $svcdb eq 'svc_acct' #double kludge +% or ($svcdb eq 'svc_broadband' +% and $conf->exists('svc_broadband-radius')); % my @fields = % grep { my $col = $part_svc->part_svc_column($_); % my $def = FS::part_svc->svc_table_fields($svcdb)->{$_}; diff --git a/httemplate/edit/process/svc_broadband.cgi b/httemplate/edit/process/svc_broadband.cgi index d5c9820bb..36c64d11a 100644 --- a/httemplate/edit/process/svc_broadband.cgi +++ b/httemplate/edit/process/svc_broadband.cgi @@ -1,8 +1,20 @@ -<% include('elements/svc_Common.html', 'table' => 'svc_broadband') %> +<& elements/svc_Common.html, + table => 'svc_broadband', + fields => [ fields('svc_broadband'), 'usergroup' ], + precheck_callback => \&precheck, +&> <%init> +# for historical reasons, process_m2m for usergroup tables is done +# in the svc_x::insert/replace/delete methods, not here my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" unless $curuser->access_right('Provision customer service'); #something else more specific? +sub precheck { + my $cgi = shift; + $cgi->param("usergroup", [ $cgi->param('usergroup') ]); + '' +} + diff --git a/httemplate/edit/svc_acct.cgi b/httemplate/edit/svc_acct.cgi index 61058aeb2..52fbd37af 100755 --- a/httemplate/edit/svc_acct.cgi +++ b/httemplate/edit/svc_acct.cgi @@ -312,7 +312,7 @@ function randomPass() { % } else { % my $radius_group_selected = ''; % if ( $svc_acct->svcnum ) { -% $radius_group_selected = join(',',$svc_acct->radius_groups('NUMBERS')); +% $radius_group_selected = join(',',$svc_acct->radius_groups('groupnum')); % } % elsif ( !$svc_acct->svcnum && $part_svc_usergroup->columnflag eq 'D' ) { % $radius_group_selected = $part_svc_usergroup->columnvalue; @@ -320,6 +320,7 @@ function randomPass() { <& /elements/select-radius_group.html, curr_value => $radius_group_selected, element_name => 'radius_usergroup', + multiple => 1, &> % } diff --git a/httemplate/edit/svc_broadband.cgi b/httemplate/edit/svc_broadband.cgi index a67f6f05a..d4baf35a0 100644 --- a/httemplate/edit/svc_broadband.cgi +++ b/httemplate/edit/svc_broadband.cgi @@ -1,4 +1,4 @@ -<% include('elements/svc_Common.html', +<& elements/svc_Common.html, 'post_url' => popurl(1). 'process/svc_broadband.cgi', 'name' => 'broadband service', 'table' => 'svc_broadband', @@ -7,8 +7,7 @@ 'dummy' => $cgi->query_string, 'onsubmit' => 'validate_coords', 'html_foot' => $js, - ) -%> +&> <%init> die "access denied" @@ -100,9 +99,19 @@ END my @fields = ( qw( description ip_addr speed_down speed_up blocknum ), { field=>'block_label', type=>'fixed' }, - qw( mac_addr latitude longitude altitude vlan_profile performance_profile authkey plan_id ) + qw( mac_addr latitude longitude altitude vlan_profile + performance_profile authkey plan_id ), ); +if ( $conf->exists('svc_broadband-radius') ) { + push @fields, + { field => 'usergroup', + type => 'select-radius_group', + multiple => 1, + } +} + + my $fixedblock = ''; my $callback = sub { @@ -116,10 +125,17 @@ my $callback = sub { my $columndef = $part_svc->part_svc_column($fieldref->{'field'}); if ($columndef->columnflag eq 'F') { - $fieldref->{'type'} = 'fixed'; + $fieldref->{'type'} = length($columndef->columnvalue) + ? 'fixed' + : 'hidden'; $fieldref->{'value'} = $columndef->columnvalue; $fixedblock = $fieldref->{value} if $fieldref->{field} eq 'blocknum'; + + if ( $fieldref->{field} eq 'usergroup' ) { + $fieldref->{'formatted_value'} = + [ $object->radius_groups('long_description') ]; + } } if ($object->svcnum) { diff --git a/httemplate/elements/select-radius_group.html b/httemplate/elements/select-radius_group.html index e1e3c5980..06972b522 100644 --- a/httemplate/elements/select-radius_group.html +++ b/httemplate/elements/select-radius_group.html @@ -1,17 +1,6 @@ - -<%init> - -my %opt = @_; - -my %groups = map { $_->groupnum => $_->long_description } - qsearch('radius_group', {}); -my @sel_groups = split(/,/,$opt{'curr_value'}); - - +<& /elements/select-table.html, + table => 'radius_group', + name_col => 'long_description', + order_by => 'groupname', # better idea? + @_ +&> diff --git a/httemplate/elements/tr-fixed.html b/httemplate/elements/tr-fixed.html index 095e1bce9..f358343dd 100644 --- a/httemplate/elements/tr-fixed.html +++ b/httemplate/elements/tr-fixed.html @@ -1,6 +1,6 @@ <% include('tr-td-label.html', @_ ) %> - ><% $opt{'formatted_value'} || $opt{'curr_value'} || $opt{'value'} |h %> + ><% $value %> @@ -12,4 +12,14 @@ my %opt = @_; my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : ''; +my $value = $opt{'formatted_value'} || $opt{'curr_value'} || $opt{'value'}; +#compatibility with select-table and friends +if ( $opt{'multiple'} ) { + $value = [ split(/\s*,\s*/, $value) ] if !ref $value; + $value = join('
', map {encode_entities($_)} @$value); +} +else { + $value = encode_entities($value) +} + diff --git a/httemplate/elements/tr-select-radius_group.html b/httemplate/elements/tr-select-radius_group.html new file mode 100644 index 000000000..299252755 --- /dev/null +++ b/httemplate/elements/tr-select-radius_group.html @@ -0,0 +1,11 @@ +<% include('tr-td-label.html', label => emt('RADIUS groups'), %opt ) %> + > + <% include( '/elements/select-radius_group.html', %opt ) %> + + +<%init> + +my( %opt ) = @_; +my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : ''; + + diff --git a/httemplate/view/elements/svc_Common.html b/httemplate/view/elements/svc_Common.html index 38fa90eb9..a822412bf 100644 --- a/httemplate/view/elements/svc_Common.html +++ b/httemplate/view/elements/svc_Common.html @@ -159,13 +159,13 @@ my($label, $value, $svcdb) = $cust_svc->label; my $part_svc = $cust_svc->part_svc; - #false laziness w/edit/svc_Common.html - #override default labels with service-definition labels if applicable - my $labels = $opt{labels}; #not -> here - foreach my $field ( keys %$labels ) { - my $col = $part_svc->part_svc_column($field); - $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\S*$/; - } +#false laziness w/edit/svc_Common.html +#override default labels with service-definition labels if applicable +my $labels = $opt{labels}; #not -> here +foreach my $field ( keys %$labels ) { + my $col = $part_svc->part_svc_column($field); + $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/; +} my $pkgnum = $cust_svc->pkgnum; diff --git a/httemplate/view/svc_acct/basics.html b/httemplate/view/svc_acct/basics.html index 6a0ed9260..a253e3bf7 100644 --- a/httemplate/view/svc_acct/basics.html +++ b/httemplate/view/svc_acct/basics.html @@ -100,7 +100,7 @@ % } <& /view/elements/tr.html, label=>mt('RADIUS groups'), - value=>join('
', $svc_acct->radius_groups('COMBINED')) &> + value=>join('
', $svc_acct->radius_groups('long_description')) &> %# Can this be abstracted further? Maybe a library function like %# widget('HTML', 'view', $svc_acct) ? It would definitely make UI diff --git a/httemplate/view/svc_broadband.cgi b/httemplate/view/svc_broadband.cgi index dead70b7f..627775992 100644 --- a/httemplate/view/svc_broadband.cgi +++ b/httemplate/view/svc_broadband.cgi @@ -1,225 +1,63 @@ -<%include("/elements/header.html",'Broadband Service View', menubar( - ( ( $custnum ) - ? ( "View this customer (#$display_custnum)" => "${p}view/cust_main.cgi?$custnum", - ) - : ( "Cancel this (unaudited) website" => - "${p}misc/cancel-unaudited.cgi?$svcnum" ) - ) -)) -%> - -<% include('/elements/init_overlib.html') %> - -<% include('/view/elements/svc_edit_link.html', 'svc'=>$svc_broadband) %> -
-<%ntable("#cccccc")%> - - - <%ntable("#cccccc",2)%> - - Service number - <%$svcnum%> - - - Description - <%$description%> - - -% if ( $router ) { - - Router - <%$router->routernum%>: <%$router->routername%> - -% } - - - Download Speed - <%$speed_down%> - - - Upload Speed - <%$speed_up%> - - -% if ( $ip_addr ) { - - IP Address - - <%$ip_addr%> - (<% include('/elements/popup_link-ping.html', 'ip'=>$ip_addr ) %>) - - - - IP Netmask - <%$addr_block->NetAddr->mask%> - - - IP Gateway - <%$addr_block->ip_gateway%> - -% } - - - MAC Address - <%$mac_addr%> - - - Latitude - <%$latitude%> - - - Longitude - <%$longitude%> - - - Altitude - <%$altitude%> - - - VLAN Profile - <%$vlan_profile%> - - - Authentication Key - <%$auth_key%> - - - Service Plan Id - <%$plan_id%> - - -% -%foreach (sort { $a cmp $b } $svc_broadband->virtual_fields) { -% print $svc_broadband->pvf($_)->widget('HTML', 'view', -% $svc_broadband->getfield($_)), "\n"; -%} -% -% - - - - - - -
-<%ntable("#cccccc", 2)%> -% -% my $sb_router = qsearchs('router', { svcnum => $svcnum }); -% if ($sb_router) { -% - - Router associated: <%$sb_router->routername%> - - (details) - -
-% my @sb_addr_block; -% if (@sb_addr_block = $sb_router->addr_block) { -% - - Address space - - (edit) - -
-% print ntable("#cccccc", 1); -% foreach (@sb_addr_block) { - - - <%$_->ip_gateway%>/<%$_->ip_netmask%> - -% } - - -% } else { - - No address space allocated. -% } - -
-% -% } else { -% - - -
- -Add router named - - -
-% -%} -% - - -
-<%joblisting({'svcnum'=>$svcnum}, 1)%> - -<% include('/elements/footer.html') %> +<& elements/svc_Common.html, + table => 'svc_broadband', + labels => \%labels, + fields => \@fields, +&> <%init> -die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('View customer services'); - -my($query) = $cgi->keywords; -$query =~ /^(\d+)$/; -my $svcnum = $1; -my $svc_broadband = qsearchs({ - 'select' => 'svc_broadband.*', - 'table' => 'svc_broadband', - 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '. - ' LEFT JOIN cust_pkg USING ( pkgnum ) '. - ' LEFT JOIN cust_main USING ( custnum ) ', - 'hashref' => { 'svcnum' => $svcnum }, - 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( - 'null_right' => 'View/link unlinked services' - ), -}) or die "svc_broadband: Unknown svcnum $svcnum"; - -#false laziness w/all svc_*.cgi -my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $svcnum } ); -my $pkgnum = $cust_svc->getfield('pkgnum'); -my($cust_pkg, $custnum, $display_custnum); -if ($pkgnum) { - $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $pkgnum } ); - $custnum = $cust_pkg->custnum; - $display_custnum = $cust_pkg->cust_main->display_custnum; -} else { - $cust_pkg = ''; - $custnum = ''; +my $conf = FS::Conf->new; +my $fields = FS::svc_broadband->table_info->{'fields'}; +my %labels = map { $_ => ( ref($fields->{$_}) + ? $fields->{$_}{'label'} + : $fields->{$_} + ); + } keys %$fields; + +$labels{'router'} = emt('Router'); +$labels{'usergroup'} = emt('RADIUS groups'); #? + +my @fields = ( + 'description', + { field => 'router', value => \&router }, + 'speed_down', + 'speed_up', + { field => 'ip_addr', value => \&ip_addr }, + 'mac_addr', + 'latitude', + 'longitude', + 'altitude', + 'vlan_profile', + 'authkey', + 'plan_id', +); + +push @fields, + { field => 'usergroup', value => \&usergroup } + if $conf->exists('svc_broadband-radius'); + +sub router { + my $svc = shift; + my $addr_block = $svc->addr_block or return ''; + my $router = $addr_block->router or return ''; + $router->routernum . ': ' . $router->routername; } -#eofalse -my $addr_block = $svc_broadband->addr_block; -my $router = $addr_block->router if $addr_block; - -#if (not $router) { die "Could not lookup router for svc_broadband (svcnum $svcnum)" }; +sub ip_addr { + my $svc = shift; + my $ip_addr = $svc->ip_addr; + my $out = $ip_addr . ' (' . + include('/elements/popup_link-ping.html', ip => $ip_addr) . ')'; + if ( my $addr_block = $svc->addr_block ) { + $out .= '
Netmask: ' . $addr_block->NetAddr->mask . + '
Gateway: ' . $addr_block->ip_gateway; + } + $out; +} -my ( - $speed_down, - $speed_up, - $ip_addr, - $mac_addr, - $latitude, - $longitude, - $altitude, - $vlan_profile, - $auth_key, - $description, - $plan_id, - ) = ( - $svc_broadband->getfield('speed_down'), - $svc_broadband->getfield('speed_up'), - $svc_broadband->getfield('ip_addr'), - $svc_broadband->mac_addr, - $svc_broadband->latitude, - $svc_broadband->longitude, - $svc_broadband->altitude, - $svc_broadband->vlan_profile, - $svc_broadband->auth_key, - $svc_broadband->description, - $svc_broadband->plan_id, - ); +sub usergroup { + my $svc = shift; + my $usergroup = $svc->usergroup; + join('
', $svc->radius_groups('long_description')); +} -- cgit v1.2.1