fix(trunk): match PJSIP endpoint name to username in receive mode and auto-reload on trunk save
This commit is contained in:
1 parent
f429a48ad6
commit
db233f853c
2 files changed
+40
-34
No files matched your search
@@ -1279,6 +1279,12 @@ try {
|
|||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$generator->writeAllConfigs();
|
||||||
|
try {
|
||||||
|
$ami = AmiClient::fromDatabase($db);
|
||||||
|
$ami->reloadPjsipAndDialplan();
|
||||||
|
} catch (\Throwable $e) {}
|
||||||
|
|
||||||
$displayHost = $host !== '' ? "{$host}:{$port}" : "Passerelle locale / HT813";
|
$displayHost = $host !== '' ? "{$host}:{$port}" : "Passerelle locale / HT813";
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
@@ -1289,6 +1295,13 @@ try {
|
|||||||
case 'delete_trunk':
|
case 'delete_trunk':
|
||||||
$id = (int)($payload['id'] ?? 0);
|
$id = (int)($payload['id'] ?? 0);
|
||||||
$db->prepare('DELETE FROM trunks WHERE id = :id')->execute([':id' => $id]);
|
$db->prepare('DELETE FROM trunks WHERE id = :id')->execute([':id' => $id]);
|
||||||
|
|
||||||
|
$generator->writeAllConfigs();
|
||||||
|
try {
|
||||||
|
$ami = AmiClient::fromDatabase($db);
|
||||||
|
$ami->reloadPjsipAndDialplan();
|
||||||
|
} catch (\Throwable $e) {}
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'message' => 'Trunk SIP supprimé.',
|
'message' => 'Trunk SIP supprimé.',
|
||||||
|
|||||||
+27
-34
@@ -315,22 +315,22 @@ class ConfigGenerator
|
|||||||
|
|
||||||
$matchIpsRaw = trim((string)($trunk['match_ips'] ?? ''));
|
$matchIpsRaw = trim((string)($trunk['match_ips'] ?? ''));
|
||||||
|
|
||||||
|
$epName = ($regMode === 'receive' && $username !== '') ? $username : "trunk-{$slug}";
|
||||||
|
$authName = "{$epName}-auth";
|
||||||
|
$aorName = $epName;
|
||||||
|
|
||||||
$hostPortDisplay = $host !== '' ? "{$host}:{$port}" : "Passerelle Réception Dynamique";
|
$hostPortDisplay = $host !== '' ? "{$host}:{$port}" : "Passerelle Réception Dynamique";
|
||||||
$lines[] = "; --- Trunk : {$trunk['name']} ({$hostPortDisplay} [{$trProto}] - Mode: {$regMode}) ---";
|
$lines[] = "; --- Trunk : {$trunk['name']} ({$hostPortDisplay} [{$trProto}] - Mode: {$regMode}) ---";
|
||||||
$lines[] = "[trunk-{$slug}]";
|
$lines[] = "[{$epName}]";
|
||||||
$lines[] = "type = endpoint";
|
$lines[] = "type = endpoint";
|
||||||
$lines[] = "context = {$context}";
|
$lines[] = "context = {$context}";
|
||||||
$lines[] = "transport = {$transport}";
|
$lines[] = "transport = {$transport}";
|
||||||
|
|
||||||
if ($regMode === 'receive') {
|
if ($regMode === 'receive') {
|
||||||
// Passerelle locale (ex: Grandstream HT813, Livebox, ATA) s'enregistrant sur Asterisk
|
// Passerelle locale (ex: Grandstream HT813, Livebox, ATA) s'enregistrant sur Asterisk
|
||||||
$lines[] = "auth = trunk-{$slug}-auth";
|
$lines[] = "auth = {$authName}";
|
||||||
$lines[] = "outbound_auth = trunk-{$slug}-auth";
|
$lines[] = "outbound_auth = {$authName}";
|
||||||
if ($username !== '' && $username !== "trunk-{$slug}") {
|
$lines[] = "aors = {$aorName}";
|
||||||
$lines[] = "aors = trunk-{$slug},{$username}";
|
|
||||||
} else {
|
|
||||||
$lines[] = "aors = trunk-{$slug}";
|
|
||||||
}
|
|
||||||
if ($host !== '' || $matchIpsRaw !== '') {
|
if ($host !== '' || $matchIpsRaw !== '') {
|
||||||
$lines[] = "identify_by = auth_username,username,ip";
|
$lines[] = "identify_by = auth_username,username,ip";
|
||||||
} else {
|
} else {
|
||||||
@@ -338,9 +338,9 @@ class ConfigGenerator
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($hasAuth) {
|
if ($hasAuth) {
|
||||||
$lines[] = "outbound_auth = trunk-{$slug}-auth";
|
$lines[] = "outbound_auth = {$authName}";
|
||||||
}
|
}
|
||||||
$lines[] = "aors = trunk-{$slug}";
|
$lines[] = "aors = {$aorName}";
|
||||||
}
|
}
|
||||||
if ($outboundProxy !== '') {
|
if ($outboundProxy !== '') {
|
||||||
$lines[] = "outbound_proxy = {$outboundProxy}";
|
$lines[] = "outbound_proxy = {$outboundProxy}";
|
||||||
@@ -402,8 +402,8 @@ class ConfigGenerator
|
|||||||
}
|
}
|
||||||
$lines[] = "";
|
$lines[] = "";
|
||||||
|
|
||||||
// Section AOR du Trunk (nommée trunk-$slug et alias username si mode receive)
|
// Section AOR du Trunk
|
||||||
$lines[] = "[trunk-{$slug}]";
|
$lines[] = "[{$aorName}]";
|
||||||
$lines[] = "type = aor";
|
$lines[] = "type = aor";
|
||||||
if ($regMode === 'receive') {
|
if ($regMode === 'receive') {
|
||||||
// En mode réception, l'IP/port de la passerelle est découvert dynamiquement lors du REGISTER
|
// En mode réception, l'IP/port de la passerelle est découvert dynamiquement lors du REGISTER
|
||||||
@@ -427,22 +427,9 @@ class ConfigGenerator
|
|||||||
}
|
}
|
||||||
$lines[] = "";
|
$lines[] = "";
|
||||||
|
|
||||||
// AOR supplémentaire pour identifier l'enregistrement par identifiant/numéro (ex: 0494679572)
|
|
||||||
if ($regMode === 'receive' && $username !== '' && $username !== "trunk-{$slug}") {
|
|
||||||
$lines[] = "[{$username}]";
|
|
||||||
$lines[] = "type = aor";
|
|
||||||
$lines[] = "max_contacts = 1";
|
|
||||||
$lines[] = "remove_existing = yes";
|
|
||||||
$lines[] = "qualify_frequency = {$qualifyFreq}";
|
|
||||||
if ($outboundProxy !== '') {
|
|
||||||
$lines[] = "outbound_proxy = {$outboundProxy}";
|
|
||||||
}
|
|
||||||
$lines[] = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Section Auth du Trunk
|
// Section Auth du Trunk
|
||||||
if ($hasAuth || $regMode === 'receive') {
|
if ($hasAuth || $regMode === 'receive') {
|
||||||
$lines[] = "[trunk-{$slug}-auth]";
|
$lines[] = "[{$authName}]";
|
||||||
$lines[] = "type = auth";
|
$lines[] = "type = auth";
|
||||||
$lines[] = "auth_type = userpass";
|
$lines[] = "auth_type = userpass";
|
||||||
$lines[] = "username = {$authUsername}";
|
$lines[] = "username = {$authUsername}";
|
||||||
@@ -462,10 +449,10 @@ class ConfigGenerator
|
|||||||
$expiration = max(60, (int)($trunk['expiration'] ?? 3600));
|
$expiration = max(60, (int)($trunk['expiration'] ?? 3600));
|
||||||
$lineSupport = ((int)($trunk['line_support'] ?? 1) === 1);
|
$lineSupport = ((int)($trunk['line_support'] ?? 1) === 1);
|
||||||
|
|
||||||
$lines[] = "[trunk-{$slug}-reg]";
|
$lines[] = "[{$epName}-reg]";
|
||||||
$lines[] = "type = registration";
|
$lines[] = "type = registration";
|
||||||
$lines[] = "transport = {$transport}";
|
$lines[] = "transport = {$transport}";
|
||||||
$lines[] = "outbound_auth = trunk-{$slug}-auth";
|
$lines[] = "outbound_auth = {$authName}";
|
||||||
$lines[] = "server_uri = {$serverUri}";
|
$lines[] = "server_uri = {$serverUri}";
|
||||||
$lines[] = "client_uri = {$clientUri}";
|
$lines[] = "client_uri = {$clientUri}";
|
||||||
if ($contactUser !== '') {
|
if ($contactUser !== '') {
|
||||||
@@ -483,7 +470,7 @@ class ConfigGenerator
|
|||||||
$lines[] = "max_random_initial_delay = 0";
|
$lines[] = "max_random_initial_delay = 0";
|
||||||
if ($lineSupport) {
|
if ($lineSupport) {
|
||||||
$lines[] = "line = yes";
|
$lines[] = "line = yes";
|
||||||
$lines[] = "endpoint = trunk-{$slug}";
|
$lines[] = "endpoint = {$epName}";
|
||||||
}
|
}
|
||||||
$customReg = trim((string)($trunk['custom_reg_params'] ?? ''));
|
$customReg = trim((string)($trunk['custom_reg_params'] ?? ''));
|
||||||
if ($customReg !== '') {
|
if ($customReg !== '') {
|
||||||
@@ -504,9 +491,9 @@ class ConfigGenerator
|
|||||||
: ($host !== '' ? [$host] : []);
|
: ($host !== '' ? [$host] : []);
|
||||||
|
|
||||||
if (!empty($matchList)) {
|
if (!empty($matchList)) {
|
||||||
$lines[] = "[trunk-{$slug}-identify]";
|
$lines[] = "[{$epName}-identify]";
|
||||||
$lines[] = "type = identify";
|
$lines[] = "type = identify";
|
||||||
$lines[] = "endpoint = trunk-{$slug}";
|
$lines[] = "endpoint = {$epName}";
|
||||||
foreach ($matchList as $mIp) {
|
foreach ($matchList as $mIp) {
|
||||||
$lines[] = "match = {$mIp}";
|
$lines[] = "match = {$mIp}";
|
||||||
}
|
}
|
||||||
@@ -1061,6 +1048,9 @@ class ConfigGenerator
|
|||||||
foreach ($trunks as $t) {
|
foreach ($trunks as $t) {
|
||||||
$trunkByName[trim((string)$t['name'])] = $t;
|
$trunkByName[trim((string)$t['name'])] = $t;
|
||||||
$trunkByName['trunk-' . $this->slugify($t['name'])] = $t;
|
$trunkByName['trunk-' . $this->slugify($t['name'])] = $t;
|
||||||
|
if (!empty($t['username'])) {
|
||||||
|
$trunkByName[trim((string)$t['username'])] = $t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$patternDispatches = [];
|
$patternDispatches = [];
|
||||||
@@ -1181,10 +1171,13 @@ class ConfigGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$validTrunkCount++;
|
$validTrunkCount++;
|
||||||
$sub[] = " same => n,NoOp(Route [{$rName}] - Tentative Trunk #{$validTrunkCount} [trunk-{$tSlug}] vers \${OUTNUM})";
|
$tEpName = ($tObj && ($tObj['registration_mode'] ?? '') === 'receive' && !empty($tObj['username']))
|
||||||
$sub[] = " same => n,Dial(PJSIP/\${OUTNUM}@trunk-{$tSlug},60,tT)";
|
? $tObj['username']
|
||||||
|
: "trunk-{$tSlug}";
|
||||||
|
$sub[] = " same => n,NoOp(Route [{$rName}] - Tentative Trunk #{$validTrunkCount} [{$tEpName}] vers \${OUTNUM})";
|
||||||
|
$sub[] = " same => n,Dial(PJSIP/\${OUTNUM}@{$tEpName},60,tT)";
|
||||||
$sub[] = " same => n,GotoIf(\$[\"\${DIALSTATUS}\" = \"ANSWER\" | \"\${DIALSTATUS}\" = \"BUSY\" | \"\${DIALSTATUS}\" = \"NOANSWER\" | \"\${DIALSTATUS}\" = \"CANCEL\"]?call_done)";
|
$sub[] = " same => n,GotoIf(\$[\"\${DIALSTATUS}\" = \"ANSWER\" | \"\${DIALSTATUS}\" = \"BUSY\" | \"\${DIALSTATUS}\" = \"NOANSWER\" | \"\${DIALSTATUS}\" = \"CANCEL\"]?call_done)";
|
||||||
$sub[] = " same => n,NoOp(Trunk [trunk-{$tSlug}] indisponible [\${DIALSTATUS}] -> Passage au Trunk / Route suivant)";
|
$sub[] = " same => n,NoOp(Trunk [{$tEpName}] indisponible [\${DIALSTATUS}] -> Passage au Trunk / Route suivant)";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Si tous les Trunks de cette route sont indisponibles
|
// 5. Si tous les Trunks de cette route sont indisponibles
|
||||||
|
|||||||
Reference in new issue
Block a user