FUNÇÃO
/*********************************************
Função de validação no AD via protocolo LDAP
como usar:
valida_ldap(“servidor”, “domínio\usuário”, “senha”);
*********************************************/
{
$ldap_server = $servidor;
$auth_user = $usuario;
$auth_pass = $senha;
// Tenta se conectar com o servidor
if (!($connect = @ldap_connect($ldap_server))) {
return FALSE;
}
// Tenta autenticar no servidor
if (!($bind = @ldap_bind($connect, $auth_user, $auth_pass))) {
// se não validar retorna false
return FALSE;
} else {
// se validar retorna true
return TRUE;
}
}
EVENTO VALIDATE
$slogin = sc_sql_injection({login});
$spswd = sc_sql_injection(md5({pswd}));
// Se LDAP estiver ATIVADO no usuario
if ({ldap} == ‘SIM’){
$servidor = {servidor};
$dominio = {dominio};
$usuario = {dominio}. '\\' .{login};
$senha = {pswd};
if (valida_ldap($servidor, $usuario, $senha)) {
$sql = "SELECT
priv_admin,
active,
name,
email
FROM seg_users
WHERE login = " . $slogin."";
sc_lookup(rs, $sql);
if(count({rs}) == 0)
{
sc_log_add('login Fail', {lang_login_fail} . {login});
sc_error_message({lang_error_login});
sc_error_exit();
}
else if({rs[0][1]} == 'Y')
{
$usr_login = {login};
$usr_priv_admin = ({rs[0][0]} == 'Y') ? TRUE : FALSE;
$usr_name = {rs[0][2]};
$usr_email = {rs[0][3]};
sc_set_global($usr_login);
sc_set_global($usr_priv_admin);
sc_set_global($usr_name);
sc_set_global($usr_email);
$sql = "SELECT
app_name,
priv_access,
priv_insert,
priv_delete,
priv_update,
priv_export,
priv_print
FROM seg_groups_apps
WHERE group_id IN
(SELECT
group_id
FROM
seg_users_groups
WHERE
login = '".{login} ."')";
sc_select(rs, $sql);
if ({rs} !== false)
{
while (!$rs->EOF)
{
if( $rs->fields[1] == 'Y' ||
$rs->fields[2] == 'Y' ||
$rs->fields[3] == 'Y' ||
$rs->fields[4] == 'Y' ||
$rs->fields[5] == 'Y' ||
$rs->fields[6] == 'Y')
{
sc_apl_status($rs->fields[0], 'on');
}
else
{
sc_apl_status($rs->fields[0], 'off');
}
sc_apl_conf($rs->fields[0], 'access', has_priv($rs->fields[1]));
sc_apl_conf($rs->fields[0], 'insert', has_priv($rs->fields[2]));
sc_apl_conf($rs->fields[0], 'delete', has_priv($rs->fields[3]));
sc_apl_conf($rs->fields[0], 'update', has_priv($rs->fields[4]));
//export
$export_permission = 'btn_display_'. has_priv($rs->fields[5]);
sc_apl_conf($rs->fields[0], $export_permission, 'xls');
sc_apl_conf($rs->fields[0], $export_permission, 'word');
sc_apl_conf($rs->fields[0], $export_permission, 'pdf');
sc_apl_conf($rs->fields[0], $export_permission, 'xml');
sc_apl_conf($rs->fields[0], $export_permission, 'csv');
sc_apl_conf($rs->fields[0], $export_permission, 'rtf');
//export
$export_permission = 'btn_display_'. has_priv($rs->fields[6]);
sc_apl_conf($rs->fields[0], $export_permission, 'print');
$rs->MoveNext();
}
$rs->Close();
$check_sql = "SELECT registro FROM seg_users WHERE login = '" . {login} . "'";
sc_lookup(rs, $check_sql);
if (isset({rs[0][0]})) // Row found
{
$var_global1_registro = {rs[0][0]};
}
if ( $var_global1_registro <> '')
{
$check_sql = "SELECT nome, registro, email, id, adm_chamado FROM pessoas WHERE registro = '" . $var_global1_registro . "'";
sc_lookup(rs, $check_sql);
if (isset({rs[0][0]})) // Row found
{
$var_global_nome = {rs[0][0]};
$var_global_registro = {rs[0][1]};
$var_global_email = {rs[0][2]};
$var_global_id = {rs[0][3]};
$var_global_adm_chamado = {rs[0][4]};
sc_set_global([var_global_nome], [var_global_registro], [var_global_email], [var_global_id], [var_global_adm_chamado]);
}
}else{
$var_global_nome = '----------';
$var_global_registro = '----------';
$var_global_email = '----------';
$var_global_id = '0';
$var_global_adm_chamado = 'SIM';
sc_set_global([var_global_nome], [var_global_registro], [var_global_email], [var_global_id], [var_global_adm_chamado]);
}
sc_redir({modulos});
}
}
else
{
sc_error_message({lang_error_not_active});
sc_error_exit();
}
} else {
sc_redir('Login_acesso_principal');
}
// Finaliza Laço do COM LDAP
//---------------------------------------------------------
}
// Se LDAP estiver DESATIVADO no usuario
if ({ldap} <> ‘SIM’){
$sql = "SELECT
priv_admin,
active,
name,
email
FROM seg_users
WHERE login = $slogin
AND pswd = ".$spswd."";
sc_lookup(rs, $sql);
if(count({rs}) == 0)
{
sc_log_add('login Fail', {lang_login_fail} . {login});
sc_error_message({lang_error_login});
sc_error_exit();
}
else if({rs[0][1]} == 'Y')
{
$usr_login = {login};
$usr_priv_admin = ({rs[0][0]} == 'Y') ? TRUE : FALSE;
$usr_name = {rs[0][2]};
$usr_email = {rs[0][3]};
sc_set_global($usr_login);
sc_set_global($usr_priv_admin);
sc_set_global($usr_name);
sc_set_global($usr_email);
$sql = "SELECT
app_name,
priv_access,
priv_insert,
priv_delete,
priv_update,
priv_export,
priv_print
FROM seg_groups_apps
WHERE group_id IN
(SELECT
group_id
FROM
seg_users_groups
WHERE
login = '".{login} ."')";
sc_select(rs, $sql);
if ({rs} !== false)
{
while (!$rs->EOF)
{
if( $rs->fields[1] == 'Y' ||
$rs->fields[2] == 'Y' ||
$rs->fields[3] == 'Y' ||
$rs->fields[4] == 'Y' ||
$rs->fields[5] == 'Y' ||
$rs->fields[6] == 'Y')
{
sc_apl_status($rs->fields[0], 'on');
}
else
{
sc_apl_status($rs->fields[0], 'off');
}
sc_apl_conf($rs->fields[0], 'access', has_priv($rs->fields[1]));
sc_apl_conf($rs->fields[0], 'insert', has_priv($rs->fields[2]));
sc_apl_conf($rs->fields[0], 'delete', has_priv($rs->fields[3]));
sc_apl_conf($rs->fields[0], 'update', has_priv($rs->fields[4]));
//export
$export_permission = 'btn_display_'. has_priv($rs->fields[5]);
sc_apl_conf($rs->fields[0], $export_permission, 'xls');
sc_apl_conf($rs->fields[0], $export_permission, 'word');
sc_apl_conf($rs->fields[0], $export_permission, 'pdf');
sc_apl_conf($rs->fields[0], $export_permission, 'xml');
sc_apl_conf($rs->fields[0], $export_permission, 'csv');
sc_apl_conf($rs->fields[0], $export_permission, 'rtf');
//export
$export_permission = 'btn_display_'. has_priv($rs->fields[6]);
sc_apl_conf($rs->fields[0], $export_permission, 'print');
$rs->MoveNext();
}
$rs->Close();
$check_sql = "SELECT registro FROM seg_users WHERE login = '" . {login} . "'";
sc_lookup(rs, $check_sql);
if (isset({rs[0][0]})) // Row found
{
$var_global1_registro = {rs[0][0]};
}
if ( $var_global1_registro <> '')
{
$check_sql = "SELECT nome, registro, email, id, adm_chamado FROM pessoas WHERE registro = '" . $var_global1_registro . "'";
sc_lookup(rs, $check_sql);
if (isset({rs[0][0]})) // Row found
{
$var_global_nome = {rs[0][0]};
$var_global_registro = {rs[0][1]};
$var_global_email = {rs[0][2]};
$var_global_id = {rs[0][3]};
$var_global_adm_chamado = {rs[0][4]};
sc_set_global([var_global_nome], [var_global_registro], [var_global_email], [var_global_id], [var_global_adm_chamado]);
}
}else{
$var_global_nome = '----------';
$var_global_registro = '----------';
$var_global_email = '----------';
$var_global_id = '0';
$var_global_adm_chamado = 'SIM';
sc_set_global([var_global_nome], [var_global_registro], [var_global_email], [var_global_id], [var_global_adm_chamado]);
}
sc_redir({modulos});
}
}
else
{
sc_error_message({lang_error_not_active});
sc_error_exit();
}
// Finaliza Laço do SEM LDAP
//---------------------------------------------------------
}