MT#21293 API fix peer auth sems update

behaviour unified with webpanel controller

Change-Id: I21c4018dd2584e7a8934de0a2f339ca541f84838
changes/25/7025/3
Gerhard Jungwirth 9 years ago
parent 01c24b501d
commit c46f1c497c

@ -18,7 +18,6 @@ use NGCP::Panel::Utils::CallList;
use NGCP::Panel::Utils::Preferences;
use NGCP::Panel::Utils::Message;
use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Sems;
use NGCP::Panel::Utils::Fax;
use NGCP::Panel::Utils::Kamailio;
use NGCP::Panel::Utils::Events;
@ -876,24 +875,8 @@ sub preferences_edit :Chained('preferences_base') :PathPart('edit') :Args(0) {
$c, $prov_subscriber, $new_auth_prefs);
unless(compare($old_auth_prefs, $new_auth_prefs)) {
try {
if(!NGCP::Panel::Utils::Preferences::is_peer_auth_active($c, $old_auth_prefs) &&
NGCP::Panel::Utils::Preferences::is_peer_auth_active($c, $new_auth_prefs)) {
NGCP::Panel::Utils::Sems::create_peer_registration(
$c, $prov_subscriber, $new_auth_prefs);
} elsif(NGCP::Panel::Utils::Preferences::is_peer_auth_active($c, $old_auth_prefs) &&
!NGCP::Panel::Utils::Preferences::is_peer_auth_active($c, $new_auth_prefs)) {
NGCP::Panel::Utils::Sems::delete_peer_registration(
$c, $prov_subscriber, $old_auth_prefs);
} elsif(NGCP::Panel::Utils::Preferences::is_peer_auth_active($c, $old_auth_prefs) &&
NGCP::Panel::Utils::Preferences::is_peer_auth_active($c, $new_auth_prefs)){
NGCP::Panel::Utils::Sems::update_peer_registration(
$c, $prov_subscriber, $new_auth_prefs, $old_auth_prefs);
}
NGCP::Panel::Utils::Preferences::update_sems_peer_auth(
$c, $prov_subscriber, $old_auth_prefs, $new_auth_prefs);
} catch($e) {
NGCP::Panel::Utils::Message::error(
c => $c,

@ -13,8 +13,9 @@ use HTTP::Status qw(:constants);
use JSON::Types;
use Safe::Isa qw($_isa);
use Data::Validate::IP qw/is_ipv4 is_ipv6/;
use NGCP::Panel::Utils::XMLDispatcher;
use NGCP::Panel::Utils::Preferences;
use NGCP::Panel::Utils::Prosody;
use NGCP::Panel::Utils::XMLDispatcher;
sub get_form {
my ($self, $c) = @_;
@ -345,6 +346,7 @@ sub update_item {
my $pref_type;
my $reseller_id;
my $full_rs;
my $old_auth_prefs = {};
if($type eq "domains") {
delete $resource->{domain_id};
@ -402,6 +404,12 @@ sub update_item {
return;
}
if ($type eq "subscribers" && grep {/^peer_auth_/} keys %{ $resource }) {
$c->log->debug("Fetching old peer_auth_params for future comparison");
NGCP::Panel::Utils::Preferences::get_peer_auth_params(
$c, $elem, $old_auth_prefs);
};
# make sure to not clear any internal prefs, except for those defined
# in extra:
my $extra = [qw/
@ -659,6 +667,26 @@ sub update_item {
}
}
if($type eq "subscribers") {
if(keys %{ $old_auth_prefs }) {
my $new_auth_prefs = {};
my $prov_subscriber = $elem;
NGCP::Panel::Utils::Preferences::get_peer_auth_params(
$c, $prov_subscriber, $new_auth_prefs);
unless(compare($old_auth_prefs, $new_auth_prefs)) {
$c->log->debug("peer_auth_params changed. Updating sems.");
try {
NGCP::Panel::Utils::Preferences::update_sems_peer_auth(
$c, $prov_subscriber, $old_auth_prefs, $new_auth_prefs);
} catch($e) {
$c->log->error("Failed to set peer registration: $e");
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Internal Server Error."); # TODO?
return;
}
}
}
}
return $item;
}

@ -1,11 +1,11 @@
package NGCP::Panel::Utils::Preferences;
use strict;
use warnings;
use NGCP::Panel::Form::Preferences;
use NGCP::Panel::Utils::Generic qw(:all);
use Sipwise::Base;
use Data::Validate::IP qw/is_ipv4 is_ipv6/;
use NGCP::Panel::Form::Preferences;
use NGCP::Panel::Utils::Generic qw(:all);
use NGCP::Panel::Utils::Sems;
sub validate_ipnet {
my ($field) = @_;
@ -870,6 +870,28 @@ sub get_contract_preference_rs {
});
}
sub update_sems_peer_auth {
my ($c, $prov_subscriber, $old_auth_prefs, $new_auth_prefs) = @_;
if(!_is_peer_auth_active($c, $old_auth_prefs) &&
_is_peer_auth_active($c, $new_auth_prefs)) {
NGCP::Panel::Utils::Sems::create_peer_registration(
$c, $prov_subscriber, $new_auth_prefs);
} elsif( _is_peer_auth_active($c, $old_auth_prefs) &&
!_is_peer_auth_active($c, $new_auth_prefs)) {
NGCP::Panel::Utils::Sems::delete_peer_registration(
$c, $prov_subscriber, $old_auth_prefs);
} elsif(_is_peer_auth_active($c, $old_auth_prefs) &&
_is_peer_auth_active($c, $new_auth_prefs)){
NGCP::Panel::Utils::Sems::update_peer_registration(
$c, $prov_subscriber, $new_auth_prefs, $old_auth_prefs);
}
return;
}
sub get_peer_auth_params {
my ($c, $prov_subscriber, $prefs) = @_;
@ -885,7 +907,7 @@ sub get_peer_auth_params {
}
}
sub is_peer_auth_active {
sub _is_peer_auth_active {
my ($c, $prefs) = @_;
if(defined $prefs->{peer_auth_register} && $prefs->{peer_auth_register} == 1 &&
defined $prefs->{peer_auth_user} &&

@ -1024,9 +1024,7 @@ sub terminate {
);
my $auth_prefs = {};
NGCP::Panel::Utils::Preferences::get_peer_auth_params($c, $prov_subscriber, $auth_prefs);
if(NGCP::Panel::Utils::Preferences::is_peer_auth_active($c, $auth_prefs)){
NGCP::Panel::Utils::Sems::delete_peer_registration($c, $prov_subscriber, $auth_prefs);
}
NGCP::Panel::Utils::Preferences::update_sems_peer_auth($c, $prov_subscriber, $auth_prefs, {});
NGCP::Panel::Utils::Kamailio::delete_location($c, $prov_subscriber);
foreach my $pref(qw/allowed_ips_grp man_allowed_ips_grp/) {
my $aig_rs = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(

Loading…
Cancel
Save