forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.4 KiB
60 lines
2.4 KiB
<?php |
|
|
|
include "util/Crypt.php"; |
|
$crypt = new Crypt('#S1mpl3S_C0nn3ct@R00t'); |
|
|
|
$request = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS); |
|
$chatApi = $_SESSION["prm_chat_api"]; |
|
|
|
if ($request['selectqueue'] && $request['btConectar']) { |
|
if (loginQueue($chatApi, $request['selectqueue'])) { |
|
$expireToken = strtotime('+1 days', time()); |
|
$jsoninfo = '{"servidor": "%s", "websocket": "%s", "matricula": "%s", "fila": "%s", "api" : "%s" ,"expire": "%s"}'; |
|
$jsoninfo = sprintf($jsoninfo, $_SESSION['prm_chat_api'], $_SESSION['prm_sk_host_chat'], GetMatricula(), $request['selectqueue'], $_SESSION['prm_chat_api_supervisor'], $expireToken); |
|
$url = "http://sipcloud02.simplesip.com.br:8001/index.php?t=" . $crypt->encrypt($jsoninfo); |
|
$jsStartup[] = sprintf('window.open("%s", "popupWindow", "width=1450, height=950, resizable=NO,scrollbars=YES");', $url); |
|
} else { |
|
$jsStartup[] = "alert('Não foi possível conenctar ao Simples Chat! Verifique as informações antes de conectar.');"; |
|
} |
|
} |
|
|
|
$smarty->assign("options", getQueue($chatApi)); |
|
$smarty->assign("jsonApp", json_encode( |
|
[ |
|
'matricula' => GetMatricula(), |
|
'server_api' => $_SESSION['prm_chat_api'], |
|
'server_ws' => $_SESSION['prm_sk_host_chat'], |
|
'supervisor' => IsSupervisor($dbcon) |
|
] |
|
)); |
|
|
|
GetTemplate($smarty, 'simpleschat/connect.tpl'); |
|
|
|
function getQueue($chatApi) { |
|
$response = json_decode(request("{$chatApi}/integracao/media/api/agente/listarFilas")); |
|
$option = null; |
|
foreach ($response->data as $v) { |
|
$option .= "<option value='{$v->id}'>{$v->nome}</option>"; |
|
} |
|
return $option; |
|
} |
|
|
|
function loginQueue($chatApi, $dac) { |
|
$json = ['id_fila' => $dac, "matricula" => GetMatricula()]; |
|
$response = json_decode(request("{$chatApi}/integracao/media/api/agente/entrar", $json)); |
|
if ($response->status == 'success' || strpos($response->message, 'autenticado') !== false) { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
function request($url, $post = []) { |
|
$curl = "curl -s -k "; |
|
if ($post) { |
|
$curl .= sprintf(" -X POST -d '%s' ", json_encode($post)); |
|
} |
|
$curl .= $url; |
|
|
|
$response = shell_exec($curl); |
|
return $response; |
|
} |