From 87f255507af9f14dfbccd37eefd71a148f9af344 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 30 Oct 2012 12:16:17 -0700 Subject: IP address management for svc_acct, #19567 --- httemplate/edit/process/svc_acct.cgi | 5 ++++ httemplate/edit/router.cgi | 10 +++++++- httemplate/edit/svc_acct.cgi | 28 +++++++++++++++------- httemplate/elements/tr-select-router_block_ip.html | 14 +++++++---- httemplate/view/svc_acct/basics.html | 26 +++++++++++++++----- 5 files changed, 63 insertions(+), 20 deletions(-) (limited to 'httemplate') diff --git a/httemplate/edit/process/svc_acct.cgi b/httemplate/edit/process/svc_acct.cgi index 41aca65ee..d4bcd35ed 100755 --- a/httemplate/edit/process/svc_acct.cgi +++ b/httemplate/edit/process/svc_acct.cgi @@ -31,6 +31,11 @@ foreach (map { $_,$_."_threshold" } qw( upbytes downbytes totalbytes )) { $cgi->param($_, FS::UI::bytecount::parse_bytecount($cgi->param($_)) ); } +#for slipip, convert '(automatic)' to null +my $ip_addr = $cgi->param('slipip'); +$ip_addr =~ s/[^\d\.]//g; +$cgi->param('slipip', $ip_addr); + #unmunge cgp_accessmodes (falze laziness-ish w/part_svc.pm::process &svc_domain) unless ( $cgi->param('cgp_accessmodes') ) { $cgi->param('cgp_accessmodes', diff --git a/httemplate/edit/router.cgi b/httemplate/edit/router.cgi index fdcd7b3b3..0df9b457e 100755 --- a/httemplate/edit/router.cgi +++ b/httemplate/edit/router.cgi @@ -29,8 +29,15 @@ die "access denied" unless $curuser->access_right('Broadband configuration') || $curuser->access_right('Broadband global configuration'); +my @svc_x = 'svc_broadband'; +if ( FS::Conf->new->exists('svc_acct-ip_addr') ) { + push @svc_x, 'svc_acct'; +} + my $callback = sub { my ($cgi, $object, $fields) = (shift, shift, shift); + + my $extra_sql = ' AND svcdb IN(' . join(',', map { "'$_'" } @svc_x) . ')'; unless ($object->svcnum) { push @{$fields}, { 'type' => 'tablebreak-tr-title', @@ -41,7 +48,8 @@ my $callback = sub { 'target_table' => 'part_svc', 'link_table' => 'part_svc_router', 'name_col' => 'svc', - 'hashref' => { 'svcdb' => 'svc_broadband', 'disabled' => '' }, + 'hashref' => { 'disabled' => '' }, + 'extra_sql' => $extra_sql, }; } }; diff --git a/httemplate/edit/svc_acct.cgi b/httemplate/edit/svc_acct.cgi index 142c11150..c1f74551d 100755 --- a/httemplate/edit/svc_acct.cgi +++ b/httemplate/edit/svc_acct.cgi @@ -276,14 +276,26 @@ function randomPass() { 'communigate' => $communigate, &> -% if ( $part_svc->part_svc_column('slipip')->columnflag =~ /^[FA]$/ ) { - -% } else { - - <% mt('IP') |h %> - - -% } +% if ( $conf->exists('svc_acct-ip_addr') ) { +% # router/block selection UI +% # (should we show this if slipip is fixed?) +<& /elements/tr-select-router_block_ip.html, + 'object' => $svc_acct, + 'ip_field' => 'slipip' +&> +% } else { +% # don't expose these to the user--they're only useful in the other case + + +% if ( $part_svc->part_svc_column('slipip')->columnflag =~ /^[FA]$/ ) { + +% } else { + + <% mt('IP') |h %> + + +% } +% } % my %label = ( seconds => 'Time', % upbytes => 'Upload bytes', diff --git a/httemplate/elements/tr-select-router_block_ip.html b/httemplate/elements/tr-select-router_block_ip.html index 95d1787b8..11f7c4831 100644 --- a/httemplate/elements/tr-select-router_block_ip.html +++ b/httemplate/elements/tr-select-router_block_ip.html @@ -58,12 +58,13 @@ function clearhint_ip_addr (what) { <& /elements/tr-td-label.html, label => 'IP address' &> -% if ( $fixed{'ip_addr'} ) { - <% $opt{'ip_addr'} || '' %> % } % else { - % } @@ -78,6 +79,7 @@ my $conf = FS::Conf->new; my $svc_x = $opt{'object'}; if ( $svc_x ) { + # $svc_x->ip_addr does work, even for non-svc_broadband. $opt{$_} = $svc_x->$_ foreach qw(routernum blocknum ip_addr svcpart); if ( $svc_x->svcnum ) { @@ -86,6 +88,8 @@ if ( $svc_x ) { } my $svcpart = $opt{'svcpart'} || ''; +my $ip_field = $opt{'ip_field'} || 'ip_addr'; + my %fixed; # which fields are fixed $svcpart =~ /^\d*$/ or die "invalid svcpart '$svcpart'"; if ( $svcpart ) { @@ -93,13 +97,13 @@ if ( $svcpart ) { # Traditionally, columnflag 'F' on IP address means that it MUST # be auto-assigned (or, if null IP addresses are allowed, that # it must be null). - foreach (qw(routernum blocknum ip_addr)) { + foreach (qw(routernum blocknum), $ip_field) { my $psc = $part_svc->part_svc_column($_); if ( $psc and $psc->columnflag eq 'F' ) { $fixed{$_} = $psc->columnvalue; } } - if ( $fixed{'routernum'} ) { + if ( exists $fixed{'routernum'} ) { @routers = (FS::router->by_key($fixed{'routernum'})) } else { diff --git a/httemplate/view/svc_acct/basics.html b/httemplate/view/svc_acct/basics.html index 1cdf77615..2d9953fcc 100644 --- a/httemplate/view/svc_acct/basics.html +++ b/httemplate/view/svc_acct/basics.html @@ -91,15 +91,29 @@ % } +<%perl> +# minor false laziness w/ view/svc_broadband.cgi +sub slipip { + my $svc_acct = shift; + my $out = $svc_acct->slipip or return ''; + if ( $out eq '0.0.0.0' or $out eq '0e0' ) { + return '('.mt('Dynamic').''; + } + $out .= ' ('. + include('/elements/popup_link-ping.html', ip => $svc_acct->slipip). + ')'; + if ( my $addr_block = $svc_acct->addr_block ) { + $out .= '
Netmask: ' . $addr_block->NetAddr->mask . + '
Gateway: ' . $addr_block->ip_gateway; + } + $out; +} + + % if ($svc_acct->slipip) { <& /view/elements/tr.html, label=>mt('IP address'), - value=> ( $svc_acct->slipip eq "0.0.0.0" || $svc_acct->slipip eq '0e0' ) - ? "(".mt('Dynamic').")" - : $svc_acct->slipip. ' '. - include('/elements/popup_link-ping.html', - 'ip'=>$svc_acct->slipip, - ) + value=> slipip($svc_acct) &> % } -- cgit v1.2.1