From e6ead8923cd03e608c0d72bd83f0c6437b2384e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Mon, 21 Mar 2022 16:14:29 +0100 Subject: [PATCH] Complete the API SIP message feature with more error logs and updated documentation --- flexiapi/README.md | 8 +++--- .../Controllers/Api/MessageController.php | 26 ++++++++++--------- flexisip-account-manager.spec | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/flexiapi/README.md b/flexiapi/README.md index d6625d0..45c7f0e 100644 --- a/flexiapi/README.md +++ b/flexiapi/README.md @@ -91,10 +91,10 @@ This binary will be executed under "web user" privileges. Ensure that all the re ### systemd restrictions -To retrieve the devices configuration, FlexiAPI connects to the UNIX socket opened by Flexisip. The socket is located in the `/tmp` directory. -If you have issues connecting to that socket, please ensure that your PHP process have access to it (user, rights). +To retrieve the devices configuration or send SIP messages, FlexiAPI connects to UNIX sockets opened by Flexisip and the `linphone-daemon`. The sockets are located in the `/tmp` directory. +If you have issues connecting to those sockets, please ensure that your PHP process have access to it (user, rights). -The systemd service [PrivateTmp](https://access.redhat.com/blogs/766093/posts/1976243) setting might restrict that access. +The systemd service [PrivateTmp](https://access.redhat.com/blogs/766093/posts/1976243) setting might also restrict that access. ### SELinux restrictions @@ -207,3 +207,5 @@ The `POST /api/messages` endpoint allows you to send messages on the SIP network 2. Configure the `.env` file to point to that UNIX socket APP_LINPHONE_DAEMON_UNIX_PATH=/tmp/ld + +If you have issues connecting to that socket check the [`systemd restrictions`](#systemd-restrictions) part of this document. \ No newline at end of file diff --git a/flexiapi/app/Http/Controllers/Api/MessageController.php b/flexiapi/app/Http/Controllers/Api/MessageController.php index c688143..5d3882d 100644 --- a/flexiapi/app/Http/Controllers/Api/MessageController.php +++ b/flexiapi/app/Http/Controllers/Api/MessageController.php @@ -3,9 +3,10 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; -use Illuminate\Http\Request; +use Illuminate\Http\Request; use Illuminate\Validation\ValidationException; +use Illuminate\Support\Facades\Log; class MessageController extends Controller { @@ -23,24 +24,25 @@ class MessageController extends Controller $connector->connect('unix://'.config('app.linphone_daemon_unix_pipe')) ->then(function (\React\Socket\Connection $connection) use ($request, &$returnedLines) { - - $connection->on('data', function ($message) use ($connection, &$returnedLines) { - foreach (preg_split("/\r\n|\n|\r/", $message) as $line) { - if(!empty($line) && false !== ($matches = explode(':', $line, 2))) { - $returnedLines["{$matches[0]}"] = trim($matches[1]); + $connection->on('data', function ($message) use ($connection, &$returnedLines) { + foreach (preg_split("/\r\n|\n|\r/", $message) as $line) { + if(!empty($line) && false !== ($matches = explode(':', $line, 2))) { + $returnedLines["{$matches[0]}"] = trim($matches[1]); + } } - } - $connection->close(); + $connection->close(); + }); + + $connection->write("message sip:".$request->get('to')." ".$request->get('body')."\n"); + }, function (\Exception $e) { + Log::error($e->getMessage()); }); - $connection->write("message sip:".$request->get('to')." ".$request->get('body')."\n"); - }); - $loop->run(); if (!array_key_exists('Status', $returnedLines)) { - throw ValidationException::withMessages(["The linphone-daemon UNIX socket cannot be requested properly"]); + throw ValidationException::withMessages(["The internal socket cannot be requested properly"]); } if ($returnedLines['Status'] == 'Error') { diff --git a/flexisip-account-manager.spec b/flexisip-account-manager.spec index 8c94e94..9df9609 100644 --- a/flexisip-account-manager.spec +++ b/flexisip-account-manager.spec @@ -8,7 +8,7 @@ #%define _datadir %{_datarootdir} #%define _docdir %{_datadir}/doc -%define build_number 133 +%define build_number 134 %define var_dir /var/opt/belledonne-communications %define opt_dir /opt/belledonne-communications/share/flexisip-account-manager