feat: add support for inbound trunk registration (Receive mode) for FXO gateways like Grandstream HT813 and analog Livebox integration

This commit is contained in:
sorcier committed 2026-11-03 19:07:19 +01:00
1 parent 981c650c7a
commit 8a4d7a0504
5 files changed
+285 -37

No files matched your search

+29 -8
View File
@@ -1086,7 +1086,15 @@ try {
$username = trim((string)($payload['username'] ?? ''));
$auth_username = trim((string)($payload['auth_username'] ?? ''));
$secret = trim((string)($payload['secret'] ?? ''));
$register = ($auth_mode === 'ip') ? 0 : (int)!empty($payload['register']);
$rawRegMode = strtolower(trim((string)($payload['registration_mode'] ?? '')));
if (in_array($rawRegMode, ['send', 'receive', 'none'], true)) {
$registration_mode = $rawRegMode;
} else {
$registration_mode = (!empty($payload['register']) && $auth_mode !== 'ip') ? 'send' : 'none';
}
$register = ($registration_mode === 'send') ? 1 : 0;
$server_uri = trim((string)($payload['server_uri'] ?? ''));
$client_uri = trim((string)($payload['client_uri'] ?? ''));
$contact_user = trim((string)($payload['contact_user'] ?? ''));
@@ -1130,8 +1138,17 @@ try {
$cleanDidRoutes = ConfigGenerator::normalizeInboundRoutes(json_encode($didRoutesRaw));
$did_routes_json = json_encode($cleanDidRoutes, JSON_UNESCAPED_UNICODE);
if ($name === '' || $host === '') {
throw new InvalidArgumentException("Le nom du Trunk et l'hôte SIP opérateur sont requis.");
if ($name === '') {
throw new InvalidArgumentException("Le nom du Trunk est requis.");
}
if ($registration_mode === 'receive') {
if ($username === '' || $secret === '') {
throw new InvalidArgumentException("En mode Réception (ex: passerelle Grandstream HT813 / Livebox), l'Identifiant (Username) et le Mot de passe SIP sont requis pour authentifier la passerelle.");
}
} else {
if ($host === '') {
throw new InvalidArgumentException("L'hôte SIP opérateur (Serveur SIP) est requis.");
}
}
$params = [
@@ -1144,6 +1161,7 @@ try {
':username' => $username,
':auth_username' => $auth_username,
':secret' => $secret,
':registration_mode' => $registration_mode,
':register' => $register,
':server_uri' => $server_uri,
':client_uri' => $client_uri,
@@ -1192,7 +1210,8 @@ try {
UPDATE trunks SET
name = :name, host = :host, port = :port, outbound_proxy = :outbound_proxy,
transport = :transport, auth_mode = :auth_mode, username = :username,
auth_username = :auth_username, secret = :secret, register = :register,
auth_username = :auth_username, secret = :secret,
registration_mode = :registration_mode, register = :register,
server_uri = :server_uri, client_uri = :client_uri, contact_user = :contact_user,
expiration = :expiration, retry_interval = :retry_interval,
max_retries = :max_retries, forbidden_retry_interval = :forbidden_retry_interval,
@@ -1217,7 +1236,7 @@ try {
$stmt = $db->prepare('
INSERT INTO trunks (
name, host, port, outbound_proxy, transport, auth_mode, username, auth_username, secret,
register, server_uri, client_uri, contact_user, expiration, retry_interval,
registration_mode, register, server_uri, client_uri, contact_user, expiration, retry_interval,
max_retries, forbidden_retry_interval, fatal_retry_interval, line_support,
from_user, from_domain, outbound_callerid, send_pai, send_rpid, send_diversion,
trust_id_inbound, codecs, dtmf_mode, media_encryption, nat_symmetric, direct_media,
@@ -1226,7 +1245,7 @@ try {
outbound_prefix, custom_endpoint_params, custom_reg_params, custom_aor_params, moh_sound_id, enabled
) VALUES (
:name, :host, :port, :outbound_proxy, :transport, :auth_mode, :username, :auth_username, :secret,
:register, :server_uri, :client_uri, :contact_user, :expiration, :retry_interval,
:registration_mode, :register, :server_uri, :client_uri, :contact_user, :expiration, :retry_interval,
:max_retries, :forbidden_retry_interval, :fatal_retry_interval, :line_support,
:from_user, :from_domain, :outbound_callerid, :send_pai, :send_rpid, :send_diversion,
:trust_id_inbound, :codecs, :dtmf_mode, :media_encryption, :nat_symmetric, :direct_media,
@@ -1237,7 +1256,8 @@ try {
ON CONFLICT(name) DO UPDATE SET
host = excluded.host, port = excluded.port, outbound_proxy = excluded.outbound_proxy,
transport = excluded.transport, auth_mode = excluded.auth_mode, username = excluded.username,
auth_username = excluded.auth_username, secret = excluded.secret, register = excluded.register,
auth_username = excluded.auth_username, secret = excluded.secret,
registration_mode = excluded.registration_mode, register = excluded.register,
server_uri = excluded.server_uri, client_uri = excluded.client_uri, contact_user = excluded.contact_user,
expiration = excluded.expiration, retry_interval = excluded.retry_interval,
max_retries = excluded.max_retries, forbidden_retry_interval = excluded.forbidden_retry_interval,
@@ -1259,9 +1279,10 @@ try {
$stmt->execute($params);
}
$displayHost = $host !== '' ? "{$host}:{$port}" : "Passerelle locale / HT813";
echo json_encode([
'success' => true,
'message' => "Trunk SIP « {$name} » ({$host}:{$port}) sauvegardé avec tous ses paramètres PJSIP.",
'message' => "Trunk SIP « {$name} » ({$displayHost}) sauvegardé avec tous ses paramètres PJSIP.",
]);
break;