@ -1,71 +1,55 @@
<?php
include "util/funcoesLicenca.php";
/**
* Conexao com banco de dados
*/
//coloca o focus no campo login
$setFocus = "document.getElementById('loginUser').focus();";
//define alinhamento no conteudo do master.tpl
$vAlineMaster = "middle";
/** DEFINE A QUANTIDADE DE ERROS DE AUTENTICACAO PARA BLOQUEIO */
$tentativaErro = 5;
$desabilitaLayout = 1;
$smarty->assign("desabilitaLayout", $desabilitaLayout);
/*
* Vefica se existem as configuracoes para recuperacao da senha.
*/
$smarty->assign("recuperaSenha", ValidaRecuperaSenha($dbcon));
include "login/api_banner.php";
include "util/funcoesLicenca.php";
/*
* usuario nao autenticado
*/
$tentativaErro = 5;
if (!isset($_POST["loginUser"])) {
$jsStartup[] = $setFocus;
DispLogin($smarty); // or $siteError->GetPhpError("Autentica Usuario", "", "Erro ao chamar funcao smarty!");
if (!isset($_POST['btLogin'])) {
echo "< script > console . log ( 'Bem Vindo' ) ; < / script > ";
} else {
$login = strtolower(substr($_POST["loginUser"], 0, 50));
// $login = isset($_POST['loginUser']) ? strtolower(substr($_POST['loginUser'], 0, 50)) : '';
// $senha = isset($_POST['loginPass']) ? substr($_POST['loginPass'], 0, 14) : '';
$senha = substr($_POST["loginPass"], 0, 14);
$validaTentativa = countTentativas($dbcon, $login, $tentativaErro);
if (!$validaTentativa & & ($_POST["loginUser"] != 'admin')) {
$jsStartup[] = "alert('Seu acesso foi bloqueado por inúmeras tentativas de acesso inválidos! Para o desbloqueio, realize a alteração de senha ou consulte seu Administrador.');";
$jsStartup[] = $setFocus;
DispLogin($smarty);
return;
} else if (!validarLicenca($dbcon) & & ($_POST["loginUser"] != 'admin')) {
$jsStartup[] = "alert('Sua licença é inválida por favor entre em contato com o suporte da Simples IP para ativar sua central!');";
DispLogin($smarty);
return;
}
$query = "select id, nome, apelido, matricula,
case when((select count(*)
from pbx_grupo_usuario a, pbx_grupo_funcoes b, pbx_funcoes c
where b.gp_id = a.gp_id
and c.fun_id = b.fun_id
and a.user_id = u.id
and c.fun_nome = 'mnSupervisor') > 0)then 1 else 0 end as supervisor,
cast( admin as int) as admin, case when(agente = true)then 1 else 0 end as agente,
def_senha,
senha_expira, senha_dias_expira,
senha_ult_atualiza,
senha_ult_atualiza + senha_dias_expira as senha_dt_expira,
case when((senha_ult_atualiza + senha_dias_expira) < CURRENT_DATE ) then 1 else 0 end as senha_expirada ,
penalidade, senha, termo_uso_privacidade
from pbx_usuarios u
where (u.check_vl = md5(%s) OR email = %s)
and coalesce(status, true) = true
and coalesce(delete_,0) = 0 ";
$result = pg_query($dbcon, sprintf($query, QuotedStr($login), QuotedStr($login)));
/*
* Faz autenticação do usuário.
*/
case when((select count(*)
from pbx_grupo_usuario a, pbx_grupo_funcoes b, pbx_funcoes c
where b.gp_id = a.gp_id
and c.fun_id = b.fun_id
and a.user_id = u.id
and c.fun_nome = 'mnSupervisor') > 0)then 1 else 0 end as supervisor,
cast( admin as int) as admin, case when(agente = true)then 1 else 0 end as agente,
def_senha,
senha_expira, senha_dias_expira,
senha_ult_atualiza,
senha_ult_atualiza + senha_dias_expira as senha_dt_expira,
case when((senha_ult_atualiza + senha_dias_expira) < CURRENT_DATE ) then 1 else 0 end as senha_expirada ,
penalidade, senha, termo_uso_privacidade
from pbx_usuarios u
where (u.check_vl = md5(%s) OR email = %s)
and coalesce(status, true) = true
and coalesce(delete_,0) = 0 ";
$query = sprintf($query, QuotedStr($login), QuotedStr($login));
$result = pg_query($dbcon, $query);
// Autentica usuário //
$senhaIsValid = false;
if (pg_num_rows( $result) ) {
if ($result) {
$row = pg_fetch_array($result);
$senhaUser = $row['senha'];
$senhaLogin = md5($senha);
@ -82,7 +66,7 @@ if (!isset($_POST["loginUser"])) {
$_SESSION["SSadmin"] = '0'; //$row['admin'];
$_SESSION["SSagente"] = '0'; //$row['agente'];
$_SESSION["SSagentePenalidade"] = $row['penalidade'];
$_SESSION["SSaut"] = "ok ";
$_SESSION["SSaut"] = "OK ";
$_SESSION[SS_SENHA_DEF] = $row["def_senha"];
$_SESSION["SSTermoUsoPrivacidade"] = $row["termo_uso_privacidade"];
@ -106,8 +90,8 @@ if (!isset($_POST["loginUser"])) {
GetCofigPadrao($dbcon);
/*
* expiracao de senha
*/
* expiracao de senha
*/
if ($row["senha_expira"]) {
$dataNow = date('Y-m-d');
@ -124,8 +108,8 @@ if (!isset($_POST["loginUser"])) {
}
/*
* Informações sobre dac padrao
*/
* Informações sobre dac padrao
*/
if (true) {
$dacParao = GetDacPadraoAgente($dbcon, false);
$_SESSION[SS_DAC_PADRAO] = $dacParao;
@ -133,10 +117,9 @@ if (!isset($_POST["loginUser"])) {
/*
* Vefifica Registros que precisam esta incluidos no banco de dados
*/
* Vefifica Registros que precisam esta incluidos no banco de dados
*/
VerificaDefaults($dbcon);
/*
* Captura a resolução do computador cliente.
*/
@ -152,21 +135,15 @@ if (!isset($_POST["loginUser"])) {
RegistraAcesso($_POST["loginUser"], ($row['id'] ? $row['id'] : '0'), '1');
GravaFull(0, '', 'Tentativa de login inválido', $_POST["loginUser"]);
$_SESSION["SSaut"] = "er";
//if(!$siteError->GetNumError())
$jsStartup[] = "alert('Usuário ou senha inválidos');";
$jsStartup[] = $setFocus;
DispLogin($smarty); // or $siteError->GetPhpError("Autentica Usuario");
echo '< script > alert ( "Usuário ou senha inválida!" ) ; < / script > ';
}
}
/**
* Captura tela de login
*/
function DispLogin($smarty)
{
$smarty->display('login.tpl');
if (isset($_POST['btLogin']) & & $_SESSION["SSaut"] === "OK") {
header('Location: ' . $_SERVER['PHP_SELF']);
}
}
function countTentativas($dbcon, $login, $tentativaErro)
{
$login = addslashes($login);
@ -186,4 +163,74 @@ function ValidaRecuperaSenha($dbcon)
$result = pg_query($dbcon, $query);
$res = pg_fetch_assoc($result);
return ($res ? true : false);
}
}
?>
<!DOCTYPE html>
< html >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title >
SimplesIp Login
< / title >
< style >
<?php
include 'css/login.css';
include "components/Footer/footer.css";
?>
< / style >
< link rel = "icon" href = "img/FOOTER_SIMPLES_IP.png" type = "image/png" >
< link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" >
< / head >
< body >
< div class = "container-home" >
< div class = "container-login" >
< div class = "login-content" >
< div class = "left" >
< img src = <?php echo $imagem ; ?> alt="Pessoa ao telefone " />
< / div >
< div class = "right" >
< div class = "right-content" >
< h1 > Bem Vindo< / h1 >
< h2 > login< / h2 >
< form id = "formulario-login" method = "post" accept-charset = "utf-8" action = "index.php" >
< div class = "user" >
< i class = "fa-solid fa-user" > < / i >
< input placeholder = "Insira seu email ou usuário" type = "text" maxlength = "50" name = "loginUser" id = "loginUser" / >
< / div >
< div class = "password" >
< i class = "fa-solid fa-key" > < / i >
< input type = "password" placeholder = "Insira sua senha" maxlength = "14" name = "loginPass" id = "loginPass" / >
< / div >
< div class = "esqueci-senha" >
< a href = "index.php?action=recovery_password" > Esqueci minha senha< / a >
< / div >
< / div >
< div class = 'bn-login' >
< input type = "submit" name = "btLogin" value = "Entrar" id = "btLogon" class = "bn632-hover bn24" / >
< / form >
< / div >
<?php include "components/Sociais/sociais.php" ; ?>
< / div >
< / div >
< / div >
< / div >
<?php
include "components/Footer/footer.php"; ?>
< script >
document.addEventListener('DOMContentLoaded', function() {
// Aguarde até que o DOM esteja completamente carregado
document.getElementById('loginUser').focus();
});
< / script >
< / body >
< / html >