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.
 
 
 
 
 
 

120 lines
3.8 KiB

<?php
include "config/includes.php";
use app\Provider\Crypt;
$files = getconfig('app')['FILES'];
$crypt = new Crypt('aes-256-cbc', getconfig('app')['PASSWORD']);
$geturl = bootstrap();
$post = is_postback();
$connected = false;
if ($geturl['t'] != 'gerar') {
$json = json_decode($crypt->decrypt(str_replace(' ', '+', $geturl['t'])), true);
$objs = [
'token' => $json['token'],
'id_number' => $json['id_number'],
'obj_server' => $json['servidor'],
'obj_queue' => $json['fila'],
'obj_ws' => $json['websocket'],
'session_uniqueid' => null,
'obj_notification' => null,
'obj_contact' => null,
'obj_status' => null,
'session_window' => null
];
foreach ($objs as $key => $val) {
$jsStartup[] = "localStorage.removeItem('{$key}')";
if ($val) {
$jsStartup[] = sprintf("localStorage.setItem('{$key}', '%s')", $val);
}
}
$connected = true;
}
if ($geturl['t'] == 'gerar' && isset($post['btnSend'])) {
$bearertoken = login($post['servidor'], $post['email'], $post['password']);
if (!$bearertoken) {
echo "Não foi possível gerar o token, confirme seu email e senha!";
exit;
}
$info = [
"token" => $bearertoken,
"id_number" => $post['id_number'],
"id_empresa" => $post['id_empresa'],
"servidor" => $post['servidor'],
"websocket" => "ws://192.168.115.244:8080",
"matricula" => $post['matricula'],
"fila" => $post['fila'],
"expire" => $expireToken
];
$token = $crypt->encrypt(json_encode($info, true));
echo "Token: <input type='text' value='{$token}' size='90'><br><br>";
echo "<a href='http://192.168.115.244:8001/?t=$token' target='_blank'><b>Ir para</b></a>";
//echo "<a href='http://127.0.0.1:8001/?t=$token' target='_blank'><b>Ir para</b></a>";
exit;
}
function login($url, $email, $password)
{
$json = ['email' => $email, "senha" => $password];
$url = "https://{$url}/access/login";
$response = request($url, $json);
$response = json_decode($response, true);
if ($response['status'] == 'success' || strpos($response['message'], 'sucesso') !== false) {
return $response['data']['token'];
}
return false;
}
function request($url, array $post = [])
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$response = curl_exec($ch);
if (curl_error($ch)) {
print_r(curl_error($ch, CURLINFO_HTTP_CODE));
}
curl_close($ch);
return $response;
}
?>
<!DOCTYPE html>
<html>
<?php include "app/view/header.php" ?>
<body>
<?php if ($geturl['t'] == 'gerar') { ?>
<form method="post">
<p>Email:</p>
<input type="text" name="email" placeholder="Informe o seu email de autenticacao"><br>
<p>Senha:</p>
<input type="password" name="password" placeholder="Informe a senha para autenticar"><br>
<hr>
<p>Informe o id do numero:</p>
<input type="number" name="id_number" placeholder="Informe o ID do numero"><br>
<p>Informe o Servidor:</p>
<input type="text" name="servidor" placeholder="Informe o IP/Host do servidor"><br>
<p>Informe a fila:</p>
<input type="number" name="fila" placeholder="Informe o numero da fila"><br>
<input type="submit" name="btnSend" value="Gerar Token">
</form>
<?php } else { ?>
<?php include "app/view/content.php" ?>
<?php } ?>
</body>
</html>