MT#19113 CallRoutingVerify: add number/uri validation for caller/callee

Change-Id: I190cceceaa66ab00d44e5a273582001fd1fff1b9
changes/84/5784/2
Kirill Solomko 10 years ago
parent 779d300085
commit 63dd55e97b

@ -48,8 +48,11 @@ sub callroutingverify :Chained('/') :PathPart('callroutingverify') :Args(0) {
# TODO: relocate the logic to a common module that can be centralised and
# reused by other components
$data->{caller} =~ s/(^\s+|\s+$)//g;
$data->{callee} =~ s/(^\s+|\s+$)//g;
# caller/callee general parsing
# remove leading/trailing spaces
foreach my $type (qw(caller callee)) {
$data->{$type} =~ s/(^\s+|\s+$)//g;
}
# caller lookup
if ($data->{caller_subscriber_id}) {
@ -144,11 +147,11 @@ sub callroutingverify :Chained('/') :PathPart('callroutingverify') :Args(0) {
} @{$usr_prefs{allowed_clis}};
if ($match) {
push @log, sprintf
"caller %d is accepted as it matches subscriber's 'allowed_clis'",
"caller %s is accepted as it matches subscriber's 'allowed_clis'",
$data->{caller};
} else {
push @log, sprintf
"caller %d is rejected as it does not match subscriber's 'allowed_clis'",
"caller %s is rejected as it does not match subscriber's 'allowed_clis'",
$data->{caller};
if (defined $usr_prefs{allowed_clis_reject_policy}) {
SWITCH: for ($usr_prefs{allowed_clis_reject_policy}[0]) {
@ -164,7 +167,7 @@ sub callroutingverify :Chained('/') :PathPart('callroutingverify') :Args(0) {
foreach my $cli (qw(user_cli cli)) {
if (defined $usr_prefs{$cli}) {
$data->{caller} = $usr_prefs{$cli}[0];
$log[-1] .= sprintf ", taken from '$cli' %d",
$log[-1] .= sprintf ", taken from '$cli' %s",
$usr_prefs{$cli}[0];
last;
}
@ -314,7 +317,7 @@ sub callroutingverify :Chained('/') :PathPart('callroutingverify') :Args(0) {
$sub, $data->{callee_subscriber_id};
} else {
push @log,
sprintf "no callee subscriber found, performing a peer lookup with caller %d and callee %d",
sprintf "no callee subscriber found, performing a peer lookup with caller %s and callee %s",
@{$data}{qw(caller_in callee_in)};
$data->{callee_peers} =
NGCP::Panel::Utils::Peering::lookup(

@ -145,5 +145,21 @@ has_field 'verify' => (
label => '',
);
sub validate_caller {
my ($self, $field) = @_;
my $c = $self->form->ctx;
return unless $c;
NGCP::Panel::Utils::Form::validate_number_uri(c => $c, field => $field);
}
sub validate_callee {
my ($self, $field) = @_;
my $c = $self->form->ctx;
return unless $c;
NGCP::Panel::Utils::Form::validate_number_uri(c => $c, field => $field);
}
1;
# vim: set tabstop=4 expandtab:

@ -111,6 +111,17 @@ sub validate_entities {
return 1;
}
sub validate_number_uri {
my %params = @_;
my $c = $params{c};
my $field = $params{field};
my $val = $field->value;
unless ($val =~ /^\s*[\+\-_\w\d]+\@[\w\d\-_\.]+\s*$/ || $val =~ /^\s*\+*\d+\s*$/) {
$field->add_error($c->loc('Must be either a number or user@domain format.'));
}
}
1;
# vim: set tabstop=4 expandtab:

Loading…
Cancel
Save