projects
/
freeside.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
614af30
)
support part_pkg option input validation, check bytecounts and allow commas (closes...
author
jeff
<jeff>
Thu, 4 Oct 2007 02:07:30 +0000
(
02:07
+0000)
committer
jeff
<jeff>
Thu, 4 Oct 2007 02:07:30 +0000
(
02:07
+0000)
FS/FS/UI/bytecount.pm
patch
|
blob
|
history
FS/FS/part_pkg/flat.pm
patch
|
blob
|
history
FS/FS/part_pkg/prorate.pm
patch
|
blob
|
history
FS/FS/part_pkg/subscription.pm
patch
|
blob
|
history
httemplate/edit/process/part_pkg.cgi
patch
|
blob
|
history
diff --git
a/FS/FS/UI/bytecount.pm
b/FS/FS/UI/bytecount.pm
index
38aa1df
..
d278dbe
100644
(file)
--- a/
FS/FS/UI/bytecount.pm
+++ b/
FS/FS/UI/bytecount.pm
@@
-42,20
+42,21
@@
sub bytecount_unexact {
Accepts a number (digits and a decimal point) possibly followed by k, m, g, or
t (and an optional 'b') in either case. Returns a pure number representing
Accepts a number (digits and a decimal point) possibly followed by k, m, g, or
t (and an optional 'b') in either case. Returns a pure number representing
-the input or the input itself if unparsable.
+the input or the input itself if unparsable.
Discards commas as noise.
=cut
sub parse_bytecount {
my $bc = shift;
return $bc if (($bc =~ tr/.//) > 1);
=cut
sub parse_bytecount {
my $bc = shift;
return $bc if (($bc =~ tr/.//) > 1);
- $bc =~ /^\s*([\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
+ $bc =~ /^\s*([
,
\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
my $base = $1;
my $base = $1;
+ $base =~ tr/,//d;
return $bc unless length $base;
my $exponent = index ' kmgt', lc($2);
return $bc if ($exponent < 0 && $2);
$exponent = 0 if ($exponent < 0);
return $bc unless length $base;
my $exponent = index ' kmgt', lc($2);
return $bc if ($exponent < 0 && $2);
$exponent = 0 if ($exponent < 0);
- return
$base * 1024 ** $exponent;
+ return
int($base * 1024 ** $exponent); #bytecounts are integer values
}
=item display_bytecount AMOUNT
}
=item display_bytecount AMOUNT
diff --git
a/FS/FS/part_pkg/flat.pm
b/FS/FS/part_pkg/flat.pm
index
471f216
..
f5ccd01
100644
(file)
--- a/
FS/FS/part_pkg/flat.pm
+++ b/
FS/FS/part_pkg/flat.pm
@@
-26,40
+26,49
@@
use FS::part_pkg;
},
'seconds' => { 'name' => 'Time limit for this package',
'default' => '',
},
'seconds' => { 'name' => 'Time limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
},
'upbytes' => { 'name' => 'Upload limit for this package',
'default' => '',
},
'upbytes' => { 'name' => 'Upload limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'downbytes' => { 'name' => 'Download limit for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'downbytes' => { 'name' => 'Download limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'totalbytes' => { 'name' => 'Transfer limit for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'totalbytes' => { 'name' => 'Transfer limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_amount' => { 'name' => 'Cost of recharge for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_amount' => { 'name' => 'Cost of recharge for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*(\.\d{2})?$/ },
},
'recharge_seconds' => { 'name' => 'Recharge time for this package',
'default' => '',
},
'recharge_seconds' => { 'name' => 'Recharge time for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
},
'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
'default' => '',
},
'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_downbytes' => { 'name' => 'Recharge download for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_downbytes' => { 'name' => 'Recharge download for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
diff --git
a/FS/FS/part_pkg/prorate.pm
b/FS/FS/part_pkg/prorate.pm
index
6b7c615
..
967b1eb
100644
(file)
--- a/
FS/FS/part_pkg/prorate.pm
+++ b/
FS/FS/part_pkg/prorate.pm
@@
-26,38
+26,47
@@
use FS::part_pkg::flat;
},
'seconds' => { 'name' => 'Time limit for this package',
'default' => '',
},
'seconds' => { 'name' => 'Time limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
},
'upbytes' => { 'name' => 'Upload limit for this package',
'default' => '',
},
'upbytes' => { 'name' => 'Upload limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'downbytes' => { 'name' => 'Download limit for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'downbytes' => { 'name' => 'Download limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'totalbytes' => { 'name' => 'Transfer limit for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'totalbytes' => { 'name' => 'Transfer limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_amount' => { 'name' => 'Cost of recharge for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_amount' => { 'name' => 'Cost of recharge for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*(\.\d{2})?$/ },
},
'recharge_seconds' => { 'name' => 'Recharge time for this package',
'default' => '',
},
'recharge_seconds' => { 'name' => 'Recharge time for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
},
'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
'default' => '',
},
'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_downbytes' => { 'name' => 'Recharge download for this package', 'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_downbytes' => { 'name' => 'Recharge download for this package', 'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package', 'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package', 'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
diff --git
a/FS/FS/part_pkg/subscription.pm
b/FS/FS/part_pkg/subscription.pm
index
7f4dbca
..
3e5a416
100644
(file)
--- a/
FS/FS/part_pkg/subscription.pm
+++ b/
FS/FS/part_pkg/subscription.pm
@@
-22,38
+22,47
@@
use FS::part_pkg::flat;
},
'seconds' => { 'name' => 'Time limit for this package',
'default' => '',
},
'seconds' => { 'name' => 'Time limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
},
'upbytes' => { 'name' => 'Upload limit for this package',
'default' => '',
},
'upbytes' => { 'name' => 'Upload limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'downbytes' => { 'name' => 'Download limit for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'downbytes' => { 'name' => 'Download limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'totalbytes' => { 'name' => 'Transfer limit for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'totalbytes' => { 'name' => 'Transfer limit for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_amount' => { 'name' => 'Cost of recharge for this package',
'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_amount' => { 'name' => 'Cost of recharge for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*(\.\d{2})?$/ },
},
'recharge_seconds' => { 'name' => 'Recharge time for this package',
'default' => '',
},
'recharge_seconds' => { 'name' => 'Recharge time for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
},
'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
'default' => '',
},
'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_downbytes' => { 'name' => 'Recharge download for this package', 'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_downbytes' => { 'name' => 'Recharge download for this package', 'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package', 'default' => '',
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package', 'default' => '',
+ 'check' => sub { shift =~ /^\d*$/ },
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
diff --git
a/httemplate/edit/process/part_pkg.cgi
b/httemplate/edit/process/part_pkg.cgi
index
5fc59c1
..
fd7b175
100755
(executable)
--- a/
httemplate/edit/process/part_pkg.cgi
+++ b/
httemplate/edit/process/part_pkg.cgi
@@
-10,12
+10,19
@@
%my $href = $plans{$cgi->param('plan')}->{'fields'};
%
%#fixup plandata
%my $href = $plans{$cgi->param('plan')}->{'fields'};
%
%#fixup plandata
+%my $error;
%my $plandata = $cgi->param('plandata');
%my @plandata = split(',', $plandata);
%$cgi->param('plandata',
% join('', map { my $parser = sub { shift };
% $parser = $href->{$_}{parse} if exists($href->{$_}{parse});
%my $plandata = $cgi->param('plandata');
%my @plandata = split(',', $plandata);
%$cgi->param('plandata',
% join('', map { my $parser = sub { shift };
% $parser = $href->{$_}{parse} if exists($href->{$_}{parse});
-% "$_=". join(', ', &$parser($cgi->param($_))). "\n"
+% my $value = join(', ', &$parser($cgi->param($_)));
+% my $check = $href->{$_}{check};
+% if ( $check && ! &$check($value) ) {
+% $value = join(', ', $cgi->param($_));
+% $error ||= "Illegal ". ($href->{$_}{name}||$_). ": $value";
+% }
+% "$_=$value\n";
% } @plandata )
%);
%
% } @plandata )
%);
%
@@
-39,9
+46,12
@@
% map { $_->svcpart }
% qsearch('part_svc', {} );
%
% map { $_->svcpart }
% qsearch('part_svc', {} );
%
-%my $error;
%my $custnum = '';
%my $custnum = '';
-%if ( $cgi->param('taxclass') eq '(select)' ) {
+%if ( $error ) {
+%
+% # fall through
+%
+%} elsif ( $cgi->param('taxclass') eq '(select)' ) {
%
% $error = 'Must select a tax class';
%
%
% $error = 'Must select a tax class';
%