#!/usr/bin/php -q getMessage()); WriteLog($log, $path); } } function RemoveAgenteRamal($socket, $dac, $agente, $ramal) { global $path; try { if (!RemFilaAmi($socket, $dac, $agente, $ramal)) { RaiseExcept("Nao foi possivel remover o Agente: {$agente} da Fila: {$dac} com Ramal: {$ramal}!"); } if (!LogoffAgenteAmi($socket, $agente, $ramal, $dac)) { RaiseExcept("Nao foi possivel fazer o logoff do Agente: {$agente} da Fila: {$dac} com Ramal: {$ramal}!"); } } catch (Exception $ex) { $log .= sprintf("Script: %s Data: %s Erro: %s \n", $argv[0], date("Y-m-d H:m:i"), $ex->getMessage()); WriteLog($log, $path); } } function GetAgenteRamal($socket) { $rand = rand(000000000, 9999999999); fwrite($socket, "Action: command\r\n"); fwrite($socket, "command: queue show\r\n"); fwrite($socket, "ActionID: {$rand}\r\n\r\n"); $i = 0; $filas = array(); $fila = ''; while (!feof($socket)) { $buffer = trim(@fgets($socket)); // ATENDIMENTO has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime, 0s talktime), W:0, C:0, A:0, SL:0.0% within 60s // Agent/1109 (Local/1401@app-callcenter/n from SIP/1401) (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet if (stristr($buffer, "calls") && stristr($buffer, "strategy")) { list($fila) = explode(" ", $buffer); } if (stristr($buffer, "Agent/") && $fila) { list($agente, $ramal) = explode(" ", $buffer); $agente = soNumero($agente); $ar = explode("@", $ramal); $ramal = soNumero($ar[0]); $filas[] = array($fila, $agente, $ramal); } if (stristr($buffer, "--END COMMAND--")) { return count($filas) ? $filas : false; } } return false; /* Action: command Channel: queue show ActionID: 1284279184 Response: Error Message: Missing action in request Action: command command: queue show ActionID: 1284279184 Response: Follows Privilege: Command ActionID: 1284279184 ATENDIMENTO has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime, 0s talktime), W:0, C:0, A:0, SL:0.0% within 60s Members: Agent/1109 (Local/1401@app-callcenter/n from SIP/1401) (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet Agent/1096 (Local/1402@app-callcenter/n from SIP/1402) (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet Agent/1086 (Local/1406@app-callcenter/n from SIP/1406) (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet Agent/1106 (Local/1403@app-callcenter/n from SIP/1403) (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet Agent/1102 (Local/1407@app-callcenter/n from SIP/1407) (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet Agent/1053 (Local/1410@app-callcenter/n from SIP/1410) (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet Agent/1048 (Local/1404@app-callcenter/n from SIP/1404) (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet Agent/1097 (Local/1408@app-callcenter/n from SIP/1408) (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet No Callers RECEPTIVO has 0 calls (max unlimited) in 'ringall' strategy (4s holdtime, 119s talktime), W:0, C:142, A:79, SL:96.5% within 60s Members: Agent/1023 (Local/1411@app-callcenter/n from SIP/1411) (ringinuse disabled) (dynamic) (Not in use) has taken 6 calls (last was 1910 secs ago) Agent/1035 (Local/1405@app-callcenter/n from SIP/1405) (ringinuse disabled) (dynamic) (Not in use) has taken 2 calls (last was 7764 secs ago) No Callers LOJA has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime, 0s talktime), W:0, C:0, A:0, SL:0.0% within 60s Members: Agent/1000 (Local/1530@app-callcenter/n from SIP/1530) (ringinuse disabled) (dynamic) (Unavailable) has taken no calls yet No Callers --END COMMAND-- */ } function RemoveChannelAgente($socket, $agentesOn) { $rand = rand(000000000, 9999999999); fwrite($socket, "Action: command\r\n"); fwrite($socket, "command: agent show online\r\n"); fwrite($socket, "ActionID: {$rand}\r\n\r\n"); $agentes = array(); $start = false; while (!feof($socket)) { $buffer = trim(@fgets($socket)); if (stristr($buffer, "Agent-ID") && stristr($buffer, "Channel")) { $start = true; } if (stristr($buffer, "Defined agents") && $start) { $start = false; } if ($start && $buffer) { list($agente, $login, $state, $channel) = explode(" ", preg_replace('/\s+/', ' ', $buffer)); if (array_search($agente, $agentesOn) !== false) { $agentes[$agente] = $channel; } } if (stristr($buffer, "--END COMMAND--")) { break; } } foreach ($agentes as $key => $value) { DesligarAmi($socket, $value); } /* action: command command: agent show online Response: Follows Privilege: Command Agent-ID Name State Channel Talking with 1000 admin NOT_INUSE SIP/4001-00000007 Defined agents: 17, Logged in: 1, Talking: 0 --END COMMAND-- */ }