From 18467405b0479d18143c17a9945da21180ee04c9 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Mon, 8 Sep 2014 18:21:58 +0200 Subject: [PATCH] MT#6969 Trigger device resync via SIP if online If we find a registration for the subscriber on the device, we trigger a resync via SIP. --- lib/NGCP/Panel/Controller/Customer.pm | 32 +++++++++++++++++++++++++-- ngcp_panel.conf | 4 ++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index fd16bafff4..1585b4d343 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -1289,7 +1289,36 @@ sub pbx_device_sync :Chained('pbx_device_base') :PathPart('sync') :Args(0) { my $form = NGCP::Panel::Form::Customer::PbxFieldDeviceSync->new; my $posted = ($c->req->method eq 'POST'); - # TODO: if registered, we could try taking the ip from location? + my $dev = $c->stash->{pbx_device}; + foreach my $line($dev->autoprov_field_device_lines->search({ + line_type => 'private', + })->all) { + + my $sub = $line->provisioning_voip_subscriber; + next unless($sub); + my $reg_rs = $c->model('DB')->resultset('location')->search({ + username => $sub->username, + }); + if($c->config->{features}->{multidomain}) { + $reg_rs = $reg_rs->search({ + domain => $sub->domain->domain, + }); + } + my $uri = $sub->username . '@' . $sub->domain->domain; + if($reg_rs->count) { + $c->log->debug("trigger device resync for $uri as it is registered"); + my @cmd_args = ($c->config->{cloudpbx}->{sync}, + $sub->username, $sub->domain->domain, + $sub->password); + my $out = capturex([0], "sh", @cmd_args); + $c->log->debug(">>>>>>>>>>>> got output:\n$out"); + } + $c->flash(messages => [{type => 'success', text => $c->loc('Successfully triggered config reload via SIP') }]); + NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/customer/details', [ $c->req->captures->[0] ])); + return; + } + + my $params = {}; $form->process( @@ -1302,7 +1331,6 @@ sub pbx_device_sync :Chained('pbx_device_base') :PathPart('sync') :Args(0) { $c->flash(messages => [{type => 'success', text => $c->loc('Successfully redirected request to device') }]); NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/customer/details', [ $c->req->captures->[0] ])); } - my $dev = $c->stash->{pbx_device}; my $schema = $c->config->{deviceprovisioning}->{secure} ? 'https' : 'http'; my $host = $c->config->{deviceprovisioning}->{host} // $c->req->uri->host; diff --git a/ngcp_panel.conf b/ngcp_panel.conf index 059d84f738..6109e16a27 100644 --- a/ngcp_panel.conf +++ b/ngcp_panel.conf @@ -36,6 +36,10 @@ log4perl.appender.Default.layout.ConversionPattern=%d{ISO8601} [%p] [%F +%L] %m{ ip 127.0.0.1 + + sync "sh /etc/ngcp-panel/check-sync/check-sync" + + element_order source element_order destination