diff --git a/assets/linksys-spa5xx-configtemplate.tt b/assets/linksys-spa5xx-configtemplate.tt
index f6701c6170..8c161a935f 100644
--- a/assets/linksys-spa5xx-configtemplate.tt
+++ b/assets/linksys-spa5xx-configtemplate.tt
@@ -3,6 +3,8 @@
[% config.url %]
Yes
($SWVER < [% firmware.maxversion %])? [% firmware.baseurl %]/$MA/from/$SWVER/next
+ [% directory.name %]
+ [% directory.spaurl %]
[% phone.stationname %]
[% phone.stationname %]
RFC3265_4235
diff --git a/lib/NGCP/Panel/Controller/Device.pm b/lib/NGCP/Panel/Controller/Device.pm
index 844ddf2309..a06ddd147b 100644
--- a/lib/NGCP/Panel/Controller/Device.pm
+++ b/lib/NGCP/Panel/Controller/Device.pm
@@ -993,6 +993,10 @@ sub dev_field_config :Chained('/') :PathPart('device/autoprov/config') :Args() {
stationname => $dev->station_name,
lineranges => [],
},
+ directory => {
+ spaurl => 'http://' . $c->req->uri->host . ':' . ($c->config->{web}->{autoprov_plain_port} // '1444') . '/pbx/directory/spa/' . $id,
+ name => 'PBX Address Book',
+ }
};
$vars->{firmware}->{baseurl} = 'http://' . $c->req->uri->host . ':' .
diff --git a/lib/NGCP/Panel/Controller/Pbx.pm b/lib/NGCP/Panel/Controller/Pbx.pm
new file mode 100644
index 0000000000..61898522c7
--- /dev/null
+++ b/lib/NGCP/Panel/Controller/Pbx.pm
@@ -0,0 +1,158 @@
+package NGCP::Panel::Controller::Pbx;
+use Sipwise::Base;
+use namespace::sweep;
+BEGIN { extends 'Catalyst::Controller'; }
+
+use NGCP::Panel::Utils::Message;
+use NGCP::Panel::Utils::DateTime;
+use NGCP::Panel::Utils::Contract;
+use NGCP::Panel::Utils::InvoiceTemplate;
+use NGCP::Panel::Form::Invoice::Invoice;
+
+sub auto :Private {
+ my ($self, $c) = @_;
+ $c->log->debug(__PACKAGE__ . '::auto');
+ NGCP::Panel::Utils::Navigation::check_redirect_chain(c => $c);
+ return 1;
+}
+
+sub spa_directory_getsearch :Chained('/') :PathPart('pbx/directory/spasearch') :Args(1) {
+ my ($self, $c, $id) = @_;
+
+ my $baseuri = 'http://' . $c->req->uri->host . ':' . ($c->config->{web}->{autoprov_plain_port} // '1444') . '/pbx/directory/spa/' . $id;
+ my $data = '';
+
+ $data = <
+ Search User
+ Enter (part of) Name
+ $baseuri
+
+ q
+ A
+
+
+EOF
+
+ $c->log->debug("providing config to $id");
+ $c->log->debug($data);
+
+ $c->response->content_type('text/xml');
+ $c->response->body($data);
+ return;
+}
+
+sub spa_directory_list :Chained('/') :PathPart('pbx/directory/spa') :Args(1) {
+ my ($self, $c, $id) = @_;
+
+ 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 =~ s/^([^\=]+)\=0$/$1/;
+ $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 $baseuri = 'http://' . $c->req->uri->host . ':' . ($c->config->{web}->{autoprov_plain_port} // '1444') . '/device/autoprov/directory/spa/' . $id;
+ my $data = '';
+
+ my $delim = '?';
+ my $q;
+ if(exists $c->req->params->{q} && length($c->req->params->{q})) {
+ $q = $c->req->params->{q};
+ $baseuri .= "?q=$q";
+ $delim = '&';
+ }
+
+
+ my $customer = $dev->contract;
+
+ my $page = $c->req->params->{page} // 1;
+ my $rows = 1; # TODO: make it 30?
+
+ # TODO: search for display name instead of username!
+ my $rs = $customer->voip_subscribers->search({
+ 'status' => 'active',
+ 'provisioning_voip_subscriber.pbx_extension' => { '!=' => undef },
+ defined $q ? ('me.username' => { like => "%$q%" }) : (),
+ },{
+ join => 'provisioning_voip_subscriber',
+ });
+ my $total = $rs->count;
+ my ($nextpage, $prevpage);
+
+ if(($total / $rows) > $page ) {
+ $nextpage = $page + 1;
+ }
+ if($page > 1) {
+ $prevpage = $page - 1;
+ }
+
+ my @entries = ();
+ foreach my $sub($rs->search(undef,{page => $page, rows => $rows})->all) {
+ my $prov_sub = $sub->provisioning_voip_subscriber;
+ next unless($prov_sub && $prov_sub->pbx_extension);
+ my $display_name = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
+ c => $c,
+ prov_subscriber => $sub,
+ attribute => 'display_name',
+ );
+ if($display_name->first) {
+ $display_name = $display_name->first->value;
+ } else {
+ $display_name = $sub->username;
+ };
+
+ push @entries, { name => $display_name, ext => $prov_sub->pbx_extension };
+ }
+
+ my $nexturi = $baseuri . $delim . 'page='.($nextpage//0);
+ my $prevuri = $baseuri . $delim . 'page='.($prevpage//0);
+ my $searchuri = 'http://' . $c->req->uri->host . ':' . ($c->config->{web}->{autoprov_plain_port} // '1444') . '/pbx/directory/spasearch/' . $id;
+
+ $data = 'PBX Address BookSelect the User';
+ $data .= join '', map {"$$_{name}$$_{ext}"} @entries;
+ $data .= "DialSoftKey:Dial1";
+ if($prevpage) {
+ $data .= "Prev$prevuri2";
+ } else {
+ $data .= "Search$searchuri2";
+ }
+ $data .= "Next$nexturi3"
+ if($nextpage);
+ $data .= "CancelSoftKey:Exit4";
+ $data .= '';
+
+ $c->log->debug("providing config to $id");
+ $c->log->debug($data);
+
+ # to make the exit button really exit the xml application
+ $c->response->headers->header('Expires' => '-1');
+
+ $c->response->content_type('text/xml');
+ $c->response->body($data);
+}
+
+__PACKAGE__->meta->make_immutable;
+1;
+# vim: set tabstop=4 expandtab:
diff --git a/lib/NGCP/Panel/Controller/Root.pm b/lib/NGCP/Panel/Controller/Root.pm
index 8fe1a1ce14..397fdb23d1 100644
--- a/lib/NGCP/Panel/Controller/Root.pm
+++ b/lib/NGCP/Panel/Controller/Root.pm
@@ -44,6 +44,7 @@ sub auto :Private {
__PACKAGE__ eq $c->controller->catalyst_component_name
or 'NGCP::Panel::Controller::Login' eq $c->controller->catalyst_component_name
or $c->req->uri->path =~ m|^/device/autoprov/.+|
+ or $c->req->uri->path =~ m|^/pbx/directory/.+|
or $c->req->uri->path =~ m|^/recoverwebpassword/?$|
or $c->req->uri->path =~ m|^/resetwebpassword/?$|
) {
diff --git a/script/plain-server.sh b/script/plain-server.sh
new file mode 100755
index 0000000000..bc918f4bb0
--- /dev/null
+++ b/script/plain-server.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+CATALYST_DEBUG=1 DBIC_TRACE=1 DBIC_TRACE_PROFILE=console DEVEL_CONFESS_OPTIONS='objects builtin dump color source' perl -I ../data-hal/lib -I ../ngcp-schema/lib -I lib -I ../sipwise-base/lib/ script/ngcp_panel_server.pl --port 1444 -r