TT#32011 Fix connect to Panasonic RPS

Change-Id: I5197ccc845a595dbc4298f05e591349b9eb26593
changes/40/18840/3
Irina Peshinskaya 8 years ago
parent 09eba509bd
commit 2f76c1b6e8

@ -10,6 +10,12 @@ use NGCP::Panel::Utils::DeviceBootstrap::Polycom;
use NGCP::Panel::Utils::DeviceBootstrap::Snom;
use NGCP::Panel::Utils::DeviceBootstrap::Grandstream;
my $redirect_processor;
sub get_cached_redirect_processor{
return $redirect_processor;
}
sub dispatch{
my($c, $action, $fdev, $old_identifier) = @_;
@ -25,6 +31,7 @@ sub dispatch{
};
return _dispatch($c, $action, $params);
}
sub dispatch_devmod{
my($c, $action, $devmod) = @_;
@ -36,23 +43,24 @@ sub dispatch_devmod{
my $params = get_devmod_params($c,$devmod);
return _dispatch($c, $action, $params);
}
sub _dispatch{
my($c, $action, $params) = @_;
my $redirect_processor = get_redirect_processor($params);
my $ret;
$redirect_processor = get_redirect_processor($params);
my $err;
if($redirect_processor){
$c->log->debug( "action=$action;" );
if($redirect_processor->can($action)){
$ret = $redirect_processor->$action();
$err = $redirect_processor->$action();
}else{
if( ('register' eq $action) && $params->{mac_old} && ( $params->{mac_old} ne $params->{mac} ) ){
$redirect_processor->redirect_server_call('unregister');
}
$ret = $redirect_processor->redirect_server_call($action);
$err = $redirect_processor->redirect_server_call($action);
}
$c->log->debug( "ret=$ret;" );
$c->log->debug( "err=$err;" );
}
return $ret;
return $err;
}
sub get_devmod_params{
my($c, $devmod) = @_;

@ -12,6 +12,7 @@ sub rpc_server_params{
host => 'provisioning.e-connecting.net',
port => '443',
path => '/redirect/xmlrpc',
realm => 'Please Enter Your Password',
};
$cfg->{headers} = { %{$self->get_basic_authorization($self->params->{credentials})} };
$self->{rpc_server_params} = $cfg;
@ -38,7 +39,7 @@ sub unregister_content {
<methodCall>
<methodName>ipredirect.unregisterPhone</methodName>
<params>
<param><value><string>".$self->content_params->{mac_old}."</string></value></param>
<param><value><string>".($self->content_params->{mac_old} // '')."</string></value></param>
</params>
</methodCall>";
return $self->{unregister_content};

@ -99,7 +99,7 @@ around 'parse_rpc_response' => sub {
my $c = $self->params->{c};
my $ret = 0;
my ($code,$message) = @{$rpc_response->{response}->{status}}{qw/ErrorCode ErrorMessage/};
if(0 != $code){
if($code){
$ret = $message;
}
#todo: configure log4perl (or override) to print out caller info and string

@ -44,7 +44,7 @@ sub unregister_content {
<methodName>redirect.deregisterPhone</methodName>
<params>
<param>
<value><string>".$self->content_params->{mac_old}."</string></value>
<value><string>".($self->content_params->{mac_old} // '')."</string></value>
</param>
</params>
</methodCall>";

@ -3,7 +3,8 @@ package NGCP::Panel::Utils::DeviceBootstrap::VendorRPC;
use strict;
use URI::Escape;
use MIME::Base64 qw/encode_base64/;
use Net::HTTPS::Any qw/https_post/;
use LWP::UserAgent;
use HTTP::Request::Common;
use RPC::XML::ParserFactory 'XML::LibXML';
use RPC::XML;
use Data::Dumper;
@ -18,6 +19,9 @@ has 'content_params' => (
is => 'rw',
isa => HashRef,
);
has 'response' => (
is => 'rw',
);
has 'rpc_server_params' => (
is => 'rw',
isa => HashRef,
@ -56,20 +60,28 @@ sub rpc_https_call{
my($self, $content, $cfg) = @_;
$cfg //= $self->rpc_server_params;
my $c = $self->params->{c};
$cfg->{query_string} //= '';
$c->log->debug( "rpc_https_call: host=$cfg->{host}; port=$cfg->{port}; path=$cfg->{path}; query_string=$cfg->{query_string}; content=$content;" );
#$c->log->debug( Dumper($cfg->{headers}) );
my( $page, $response_code, %reply_headers, $response_value );
my( $page, $response_code, $response_value, $reply_headers ) = ('','','',{});
eval {
local $SIG{ALRM} = sub { die "Connection timeout\n" };
alarm(25);
( $page, $response_code, %reply_headers ) = https_post({
'host' => $cfg->{host},
'port' => $cfg->{port},
'path' => $cfg->{path}.($cfg->{query_string}//''),
'headers' => $cfg->{headers},
'Content-Type' => $cfg->{content_type} // 'text/xml',
'content' => $content,
},);
my $ua = LWP::UserAgent->new;
$ua->credentials($cfg->{host}.':'.$cfg->{port}, $cfg->{realm} // '', @$cfg{qw/user password/});
$ua->ssl_opts(
verify_hostname => 0,
SSL_verify_mode => 0,
);
$cfg->{port} //= '';
my $uri = $cfg->{proto}.'://'.$cfg->{host}.($cfg->{port} ? ':' : '').$cfg->{port}.$cfg->{path};
my $request = POST $uri,
Content_Type => $cfg->{content_type} // 'text/xml',
%{$cfg->{headers}},
Content => $content;
my $response = $ua->request($request);
$self->response($response);
( $page, $response_code, $reply_headers ) = ($response->content,$response->code,$response->headers);
alarm(0);
};
alarm(0);
@ -105,7 +117,7 @@ sub extract_response_description{
if(('HASH' eq ref $response_value) && $response_value->{faultString}){
return $response_value->{faultString};
} else {
return;
return '';
}
}

@ -48,7 +48,7 @@ sub unregister_content {
<methodName>redirect.deRegisterDevice</methodName>
<params>
<param>
<value><string>".$self->content_params->{mac_old}."</string></value>
<value><string>".($self->content_params->{mac_old} // '')."</string></value>
</param>
</params>
</methodCall>";

Loading…
Cancel
Save