Complete the API SIP message feature with more error logs and updated documentation

This commit is contained in:
Timothée Jaussoin 2022-03-21 16:14:29 +01:00
parent 330073c167
commit e6ead8923c
3 changed files with 20 additions and 16 deletions

View file

@ -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.

View file

@ -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') {

View file

@ -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