feat(extensions): add Redémarrer action with call detection and confirmation modal
This commit is contained in:
1 parent
1908af5d13
commit
7fd75fbff4
4 files changed
+257
-3
No files matched your search
@@ -432,6 +432,82 @@ try {
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'check_extension_call_status':
|
||||
$extension = trim((string)($payload['extension'] ?? ''));
|
||||
if ($extension === '') {
|
||||
throw new InvalidArgumentException("Extension requise.");
|
||||
}
|
||||
|
||||
$inCall = false;
|
||||
$callDetails = '';
|
||||
try {
|
||||
$ami = AmiClient::fromDatabase($db);
|
||||
$rawChannels = $ami->runCommand("core show channels concise");
|
||||
$channelLines = array_filter(explode("\n", trim($rawChannels)));
|
||||
foreach ($channelLines as $cline) {
|
||||
$parts = explode('!', trim($cline));
|
||||
$chanName = $parts[0] ?? '';
|
||||
if (preg_match('#^PJSIP/' . preg_quote($extension, '#') . '[-/]#i', $chanName)) {
|
||||
$inCall = true;
|
||||
$state = $parts[4] ?? 'Up';
|
||||
$callerId = $parts[7] ?? '';
|
||||
$duration = $parts[10] ?? '';
|
||||
$callDetails = "Canal : {$chanName}";
|
||||
if ($callerId !== '') {
|
||||
$callDetails .= " • Interlocuteur : {$callerId}";
|
||||
}
|
||||
if ($duration !== '') {
|
||||
$callDetails .= " • Durée : {$duration}";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$inCall) {
|
||||
$rawHints = $ami->runCommand("core show hints {$extension}");
|
||||
if (preg_match('/' . preg_quote($extension, '/') . '@[^\n]*State:(InUse|Busy|Ringing)/i', $rawHints, $m)) {
|
||||
$inCall = true;
|
||||
$callDetails = "Ligne active : " . ($m[1] === 'Ringing' ? 'En sonnerie' : 'En communication');
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// AMI indisponible
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'extension' => $extension,
|
||||
'in_call' => $inCall,
|
||||
'call_details' => $callDetails,
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'reboot_extension':
|
||||
$extension = trim((string)($payload['extension'] ?? ''));
|
||||
if ($extension === '') {
|
||||
throw new InvalidArgumentException("Extension requise.");
|
||||
}
|
||||
|
||||
$stmt = $db->prepare('SELECT extension, name FROM extensions WHERE extension = :ext');
|
||||
$stmt->execute([':ext' => $extension]);
|
||||
$extRow = $stmt->fetch();
|
||||
if (!$extRow) {
|
||||
throw new InvalidArgumentException("Poste {$extension} introuvable.");
|
||||
}
|
||||
|
||||
try {
|
||||
$ami = AmiClient::fromDatabase($db);
|
||||
$cmdOutput = $ami->runCommand("pjsip send notify reboot endpoint " . escapeshellarg($extension));
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => "Ordre de redémarrage envoyé au poste {$extension} ({$extRow['name']}).",
|
||||
'details' => trim($cmdOutput),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
throw new RuntimeException("Erreur lors de l'envoi de la commande de redémarrage : " . $e->getMessage());
|
||||
}
|
||||
break;
|
||||
|
||||
case 'save_group':
|
||||
$id = isset($payload['id']) && $payload['id'] !== '' ? (int)$payload['id'] : null;
|
||||
$extension = trim((string)($payload['extension'] ?? ''));
|
||||
|
||||
Reference in new issue
Block a user