From bc7694433b325a5a374b71d61c4bbc8ff6d43cf9 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Fri, 16 Jan 2015 17:54:28 +0100 Subject: [PATCH] MT#5173 Add polycom bootstrap and directory. Change-Id: Id33a1b2560298771bba26c0d36b05c123369b83b --- lib/NGCP/Panel/Controller/Device.pm | 8 ++- lib/NGCP/Panel/Controller/Pbx.pm | 103 ++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/lib/NGCP/Panel/Controller/Device.pm b/lib/NGCP/Panel/Controller/Device.pm index 4a377138ee..0a7d525635 100644 --- a/lib/NGCP/Panel/Controller/Device.pm +++ b/lib/NGCP/Panel/Controller/Device.pm @@ -1057,7 +1057,6 @@ sub dev_field_config :Chained('/') :PathPart('device/autoprov/config') :Args() { # however, we should do it on nginx, but we need a proper CA cert # from cisco for checking the client cert? $c->log->debug("SSL_CLIENT_M_DN: " . ($c->request->env->{SSL_CLIENT_M_DN} // "")); - $c->log->debug("SSL_CLIENT_CERT: " . ($c->request->env->{SSL_CLIENT_CERT} // "")); unless($id) { $c->response->content_type('text/plain'); @@ -1069,6 +1068,11 @@ sub dev_field_config :Chained('/') :PathPart('device/autoprov/config') :Args() { $c->response->status(404); return; } + if($id =~ /^([0-9a-f]{12})\-directory\.xml$/) { + $c->log->debug("identified bootstrap path part '$id' as polycom directory request"); + $c->res->redirect($c->uri_for_action("/pbx/polycom_directory_list", $id)); + return; + } $id =~ s/\.cfg$//; if($c->req->user_agent =~ /PolycomVVX/) { @@ -1297,11 +1301,13 @@ sub dev_field_bootstrap :Chained('/') :PathPart('device/autoprov/bootstrap') :Ar my $schema = $c->config->{deviceprovisioning}->{secure} ? 'https' : 'http'; my $host = $c->config->{deviceprovisioning}->{host} // $c->req->uri->host; my $port = $c->config->{deviceprovisioning}->{port} // 1444; + my $boot_port = $c->config->{deviceprovisioning}->{bootstrap_port} // 1445; my $vars = { config => { url => "$schema://$host:$port/device/autoprov/config/$id", baseurl => "$schema://$host:$port/device/autoprov/config/", + caurl => "http://$host:$boot_port/device/autoprov/cacert", mac => $id, bootstrap => 1, }, diff --git a/lib/NGCP/Panel/Controller/Pbx.pm b/lib/NGCP/Panel/Controller/Pbx.pm index cdbdb23008..3fc6a4bec1 100644 --- a/lib/NGCP/Panel/Controller/Pbx.pm +++ b/lib/NGCP/Panel/Controller/Pbx.pm @@ -340,6 +340,109 @@ sub yealink_directory_list :Chained('base') :PathPart('pbx/directory/yealink') : $c->response->body($data); } +sub polycom_directory_list :Chained('base') :PathPart('pbx/directory/polycom') :Args(1) { + my ($self, $c, $id) = @_; + + $id =~ s/\-directory\.xml$//; + my $q; + + unless($id) { + $c->response->content_type('text/plain'); + if($c->config->{features}->{debug}) { + $c->response->body("404 - device id not given"); + } else { + $c->response->body("404 - device not found"); + } + $c->response->status(404); + return; + } + + $id = lc $id; + my $dev = $c->model('DB')->resultset('autoprov_field_devices')->find({ + identifier => $id + }); + unless($dev) { + $c->response->content_type('text/plain'); + if($c->config->{features}->{debug}) { + $c->response->body("404 - device id '" . $id . "' not found"); + } else { + $c->response->body("404 - device not found"); + } + $c->response->status(404); + return; + } + + my $schema = $c->stash->{schema}; + my $host = $c->stash->{host}; + my $port = $c->stash->{port}; + + my $customer = $dev->contract; + + my $rs = $customer->voip_subscribers->search({ + 'status' => 'active', + 'provisioning_voip_subscriber.pbx_extension' => { '!=' => undef }, + 'voip_usr_preferences.value' => { '!=' => undef }, + 'attribute.attribute' => 'display_name', + defined $q ? ('voip_usr_preferences.value' => { like => "%$q%" }) : (), + },{ + join => { provisioning_voip_subscriber => { voip_usr_preferences => 'attribute' } }, + '+select' => [qw/voip_usr_preferences.value/], + '+as' => [qw/display_name/], + order_by => { '-asc' => 'voip_usr_preferences.value' }, + }); + + my @entries = (); + foreach my $sub($rs->all) { + my $prov_sub = $sub->provisioning_voip_subscriber; + next unless($prov_sub && $prov_sub->pbx_extension); + my $display_name = $sub->get_column('display_name'); + my ($fname, @rest) = split / +/, $display_name; + my $lname = join ' ', @rest; + push @entries, { fname => $fname, lname => $lname, ext => $prov_sub->pbx_extension }; + } + + my $data = +' + + +'; + +=pod +ln last name +fn first name +ct contact +sd speed-dial index +rt ring type +dc divert contact for auto divert +ad auto divert +ar auto reject +bw buddy watching +bb buddy block +=cut + + $data .= join '', map { + " + $$_{lname} + $$_{fname} + $$_{ext} + + + + 0 + 0 + 0 + 0 + + "} @entries; + $data .= ''; + + $c->log->debug("providing config to $id"); + $c->log->debug($data); + + $c->response->content_type('text/xml'); + $c->response->body($data); +} + __PACKAGE__->meta->make_immutable; 1; # vim: set tabstop=4 expandtab: