diff --git a/lib/NGCP/Panel/Form/Device/Model.pm b/lib/NGCP/Panel/Form/Device/Model.pm index 76fa941746..f4f7537697 100644 --- a/lib/NGCP/Panel/Form/Device/Model.pm +++ b/lib/NGCP/Panel/Form/Device/Model.pm @@ -253,11 +253,12 @@ has_field 'bootstrap_method' => ( { label => 'Panasonic', value => 'redirect_panasonic' }, { label => 'Yealink', value => 'redirect_yealink' }, { label => 'Polycom', value => 'redirect_polycom' }, + { label => 'Snom', value => 'redirect_snom' }, ], default => 'http', element_attr => { rel => ['tooltip'], - title => ['Method to configure the provisioning server on the phone. One of http, redirect_panasonic, redirect_yealink, redirect_polycom.'], + title => ['Method to configure the provisioning server on the phone. One of http, redirect_panasonic, redirect_yealink, redirect_polycom, redirect_snom.'], javascript => ' onchange="bootstrapDynamicFields(this.options[this.selectedIndex].value);" ', }, ); @@ -267,7 +268,7 @@ has_field 'bootstrap_uri' => ( label => 'Bootstrap URI', default => '', #we don't show this field for polycom, because polycom doesn't support now any possibility to configure provisioning url via API - wrapper_class => [qw/ngcp-devicetype ngcp-devicetype-phone ngcp-bootstrap-config ngcp-bootstrap-config-http ngcp-bootstrap-config-redirect_panasonic ngcp-bootstrap-config-redirect_yealink/], + wrapper_class => [qw/ngcp-devicetype ngcp-devicetype-phone ngcp-bootstrap-config ngcp-bootstrap-config-http ngcp-bootstrap-config-redirect_panasonic ngcp-bootstrap-config-redirect_yealink ngcp-bootstrap-config-redirect_snom/], element_attr => { rel => ['tooltip'], title => ['Custom provisioning server URI.'], @@ -391,6 +392,28 @@ has_field 'bootstrap_config_redirect_polycom_profile' => ( title => ['Preliminary created in ZeroTouch Provisioning console Polycom ZTP profile. Refer to documentation.'], }, ); +has_field 'bootstrap_config_redirect_snom_user' => ( + type => 'Text', + required => 0, + label => 'Snom username', + default => '', + wrapper_class => [qw/ngcp-devicetype ngcp-devicetype-phone ngcp-bootstrap-config ngcp-bootstrap-config-redirect_snom/], + element_attr => { + rel => ['tooltip'], + title => ['Username used to configure bootstrap url on Snom redirect server. Obtained from Snom.'], + }, +); +has_field 'bootstrap_config_redirect_snom_password' => ( + type => 'Text', + required => 0, + label => 'Snom password', + default => '', + wrapper_class => [qw/ngcp-devicetype ngcp-devicetype-phone ngcp-bootstrap-config ngcp-bootstrap-config-redirect_snom/], + element_attr => { + rel => ['tooltip'], + title => ['Password used to configure bootstrap url on Snom redirect server. Obtained from Snom.'], + }, +); has_field 'save' => ( type => 'Submit', diff --git a/lib/NGCP/Panel/Form/Device/ModelAPI.pm b/lib/NGCP/Panel/Form/Device/ModelAPI.pm index 0c729fe367..83811fde4a 100644 --- a/lib/NGCP/Panel/Form/Device/ModelAPI.pm +++ b/lib/NGCP/Panel/Form/Device/ModelAPI.pm @@ -6,7 +6,7 @@ extends 'NGCP::Panel::Form::Device::ModelAdmin'; has_block 'fields' => ( tag => 'div', class => [qw/modal-body/], - render_list => [qw/reseller vendor model type extensions_num connectable_models linerange bootstrap_method bootstrap_uri bootstrap_config_http_sync_method bootstrap_config_http_sync_uri bootstrap_config_http_sync_params bootstrap_config_redirect_panasonic_user bootstrap_config_redirect_panasonic_password bootstrap_config_redirect_yealink_user bootstrap_config_redirect_yealink_password bootstrap_config_redirect_polycom_user bootstrap_config_redirect_polycom_password bootstrap_config_redirect_polycom_profile/], + render_list => [qw/reseller vendor model type extensions_num connectable_models linerange bootstrap_method bootstrap_uri bootstrap_config_http_sync_method bootstrap_config_http_sync_uri bootstrap_config_http_sync_params bootstrap_config_redirect_panasonic_user bootstrap_config_redirect_panasonic_password bootstrap_config_redirect_yealink_user bootstrap_config_redirect_yealink_password bootstrap_config_redirect_polycom_user bootstrap_config_redirect_polycom_password bootstrap_config_redirect_polycom_profile bootstrap_config_redirect_snom_user bootstrap_config_redirect_snom_password/], ); override 'field_list' => sub { diff --git a/lib/NGCP/Panel/Form/Device/ModelAdmin.pm b/lib/NGCP/Panel/Form/Device/ModelAdmin.pm index 5a5557c810..cc6b3d300c 100644 --- a/lib/NGCP/Panel/Form/Device/ModelAdmin.pm +++ b/lib/NGCP/Panel/Form/Device/ModelAdmin.pm @@ -29,7 +29,7 @@ has_field 'save' => ( has_block 'fields' => ( tag => 'div', class => [qw/modal-body/], - render_list => [qw/reseller vendor model type extensions_num connectable_models linerange linerange_add bootstrap_method bootstrap_uri bootstrap_config_http_sync_method bootstrap_config_http_sync_uri bootstrap_config_http_sync_params bootstrap_config_redirect_panasonic_user bootstrap_config_redirect_panasonic_password bootstrap_config_redirect_yealink_user bootstrap_config_redirect_yealink_password bootstrap_config_redirect_polycom_user bootstrap_config_redirect_polycom_password bootstrap_config_redirect_polycom_profile front_image mac_image/], + render_list => [qw/reseller vendor model type extensions_num connectable_models linerange linerange_add bootstrap_method bootstrap_uri bootstrap_config_http_sync_method bootstrap_config_http_sync_uri bootstrap_config_http_sync_params bootstrap_config_redirect_panasonic_user bootstrap_config_redirect_panasonic_password bootstrap_config_redirect_yealink_user bootstrap_config_redirect_yealink_password bootstrap_config_redirect_polycom_user bootstrap_config_redirect_polycom_password bootstrap_config_redirect_polycom_profile bootstrap_config_redirect_snom_user bootstrap_config_redirect_snom_password front_image mac_image/], ); has_block 'actions' => ( diff --git a/lib/NGCP/Panel/Utils/DeviceBootstrap.pm b/lib/NGCP/Panel/Utils/DeviceBootstrap.pm index 57a2e15b40..529b825835 100644 --- a/lib/NGCP/Panel/Utils/DeviceBootstrap.pm +++ b/lib/NGCP/Panel/Utils/DeviceBootstrap.pm @@ -7,6 +7,7 @@ use NGCP::Panel::Utils::DeviceBootstrap::VendorRPC; use NGCP::Panel::Utils::DeviceBootstrap::Panasonic; use NGCP::Panel::Utils::DeviceBootstrap::Yealink; use NGCP::Panel::Utils::DeviceBootstrap::Polycom; +use NGCP::Panel::Utils::DeviceBootstrap::Snom; sub dispatch{ my($c, $action, $fdev, $old_identifier) = @_; @@ -91,6 +92,8 @@ sub get_redirect_processor{ $redirect_processor = NGCP::Panel::Utils::DeviceBootstrap::Yealink->new( params => $params ); }elsif('redirect_polycom' eq $bootstrap_method){ $redirect_processor = NGCP::Panel::Utils::DeviceBootstrap::Polycom->new( params => $params ); + }elsif('redirect_snom' eq $bootstrap_method){ + $redirect_processor = NGCP::Panel::Utils::DeviceBootstrap::Snom->new( params => $params ); }elsif('http' eq $bootstrap_method){ #$ret = panasonic_bootstrap_register($params); } diff --git a/lib/NGCP/Panel/Utils/DeviceBootstrap/Snom.pm b/lib/NGCP/Panel/Utils/DeviceBootstrap/Snom.pm new file mode 100644 index 0000000000..a5f89e9157 --- /dev/null +++ b/lib/NGCP/Panel/Utils/DeviceBootstrap/Snom.pm @@ -0,0 +1,118 @@ +package NGCP::Panel::Utils::DeviceBootstrap::Snom; + +use strict; +use Moose; +use Data::Dumper; +extends 'NGCP::Panel::Utils::DeviceBootstrap::VendorRPC'; + +sub rpc_server_params{ + my $self = shift; + my $cfg = { + proto => 'https', + host => 'provisioning.snom.com', + port => '8083', + path => '/xmlrpc', + }; + $cfg->{headers} = { %{$self->get_basic_authorization($self->params->{credentials})} }; + $self->{rpc_server_params} = $cfg; + return $self->{rpc_server_params}; +} + +sub register_content { + my $self = shift; +#".URI::Escape::uri_escape($self->content_params->{uri})." +#http://fox.snom.com/prv2.php?mac={mac} + $self->{register_content} = " + + redirect.registerPhone + + + ".$self->content_params->{mac}." + + + ".$self->content_params->{uri}." + + +"; + return $self->{register_content}; +} + +sub unregister_content { + my $self = shift; + $self->{unregister_content} = " + + redirect.deregisterPhone + + + ".$self->content_params->{mac_old}." + + +"; + return $self->{unregister_content}; +} +override 'extract_response_description' => sub { + my($self,$rpc_value) = @_; + my $c = $self->params->{c}; + my $res = ''; + + if(ref $rpc_value eq 'ARRAY'){ + #1 - success; 0 - error, error string is a second param + if($rpc_value->[0] eq '1'){ + $res = '';#clear the error + }elsif($rpc_value->[0] eq '0'){ + return $rpc_value->[1]; + }else{ + $res = $self->unknown_error; + } + }else{ + $res = $self->unknown_error; + } + return $res; +}; + +override 'process_bootstrap_uri' => sub { + my($self,$uri) = @_; + $uri = super($uri); + $uri = $self->bootstrap_uri_mac($uri); + $self->content_params->{uri} = $uri; + return $self->content_params->{uri}; +}; + +override 'bootstrap_uri_mac' => sub { + my($self, $uri) = @_; + if ($uri !~/\{mac\}$/){ + if ($uri !~/\/$/){ + $uri .= '/' ; + } + $uri .= '?mac={mac}' ; + } + return $uri; +}; +1; + +=head1 NAME + +NGCP::Panel::Utils::DeviceBootstrap + +=head1 DESCRIPTION + +Make API requests to configure remote redirect servers for requested MAC with autorpov uri. +See http://wiki.snom.com/Category:HowTo:XMLRPC_Redirection. + +=head1 METHODS + +=head2 bootstrap + +Dispatch to proper vendor API call. + +=head1 AUTHOR + +Irina Peshinskaya C<< >> + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Utils/DeviceBootstrap/VendorRPC.pm b/lib/NGCP/Panel/Utils/DeviceBootstrap/VendorRPC.pm index b9b000d48c..3f5473bebe 100644 --- a/lib/NGCP/Panel/Utils/DeviceBootstrap/VendorRPC.pm +++ b/lib/NGCP/Panel/Utils/DeviceBootstrap/VendorRPC.pm @@ -176,6 +176,12 @@ sub bootstrap_uri_conf{ }; return $cfg; } + +sub unknown_error{ + my ($self) = @_; + my $c = $self->params->{c}; + return $c->loc('Unknown error'); +} 1; =head1 NAME diff --git a/t/api-rest/api-pbxdevicemodels.t b/t/api-rest/api-pbxdevicemodels.t index 88ddbf7fef..c19c3401c8 100644 --- a/t/api-rest/api-pbxdevicemodels.t +++ b/t/api-rest/api-pbxdevicemodels.t @@ -35,6 +35,8 @@ $fake_data->set_data_from_script({ bootstrap_config_redirect_polycom_user => "", bootstrap_config_redirect_yealink_password => "", bootstrap_config_redirect_yealink_user => "", + bootstrap_config_redirect_snom_password => "", + bootstrap_config_redirect_snom_user => "", #TODO:implement checking against this number in the controller and api #/3.7relative tests "linerange"=>[