index_bypass.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 - No existe 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("../../include/util.php");
  20. require_once("../../include/nusoap/nusoap.php");
  21. session_start();
  22. $_SESSION = array();
  23. define("NAVIDAD", 2020);
  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 true;
  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_addo", 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 = $_POST["passwd"]; //trim(filter_input(INPUT_POST, "passwd"));//limpia texto
  56. $stmt = $pdo->prepare('Select * from fs_validaclaveulsa(:usr) AS "Usuario_id"');
  57. $stmt->bindParam(":usr", $usr_db);
  58. if(!$stmt->execute()){
  59. //print_r($stmt->errorInfo());
  60. header("Location: ../index.php?error=2");
  61. exit();
  62. }
  63. $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  64. $stmt->closeCursor(); // cierra conexion de resultado
  65. $stmt = null; // cierra conexion
  66. if($usr_rs["Usuario_id"] != ""){//Si existe el usuario
  67. $valido = validaUsuario($usr, $pass);//false = error, 0 = sin permiso, 1 = con permiso
  68. if($valido === false){
  69. header("Location: ../index.php?error=1&sgu=false");
  70. exit();
  71. }else if($valido == 1){
  72. $stmt = $pdo->prepare('Select * from fs_usuario(:id)');
  73. $stmt->bindParam(":id", $usr_rs["Usuario_id"]);
  74. if(!$stmt->execute()){
  75. //print_r($stmt->errorInfo());
  76. header("Location: ../index.php?error=2");
  77. exit();
  78. }
  79. $rs = $stmt->fetch();//Devuelve sólo 1 resultado
  80. $stmt->closeCursor(); // cierra conexion de resultado
  81. $stmt = null; // cierra conexion
  82. //Guarda resultado de autenticación en sesión
  83. $_SESSION["n_timeout"] = time();
  84. $_SESSION["n_usuario_id"] = $rs["Usuario_id"];
  85. $_SESSION["n_usuario_nombre"] = $rs["Usuario_nombre"];
  86. $_SESSION["n_usuario_apellidos"] = $rs["Usuario_apellidos"];
  87. $_SESSION["n_sgi_administrador"] = $rs["SGI_administrador"];
  88. $_SESSION["n_navidad"] = NAVIDAD;
  89. $stmt = $pdo->prepare('Select * from fs_navidadusuario(:id, '.NAVIDAD.', NULL)');
  90. $stmt->bindParam(":id", $_SESSION["n_usuario_id"]);
  91. if(!$stmt->execute()){
  92. //print_r($stmt->errorInfo());
  93. header("Location: ../index.php?error=2");
  94. exit();
  95. }
  96. $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  97. $stmt->closeCursor(); // cierra conexion de resultado
  98. $stmt = null; // cierra conexion
  99. if($usr_rs["NavidadUsuario_existe"]){
  100. if(!$usr_rs["NavidadUsuario_activo"]){
  101. $stmt = $pdo->prepare('Select * from fu_navidadusuario(:id, '.NAVIDAD.', true)');
  102. $stmt->bindParam(":id", $_SESSION["n_usuario_id"]);
  103. if(!$stmt->execute()){
  104. //print_r($stmt->errorInfo());
  105. header("Location: ../index.php?error=4");
  106. exit();
  107. }
  108. }
  109. }else{//no existe, darlo de alta
  110. $stmt = $pdo->prepare('Select * from fi_navidadusuario(:id, '.NAVIDAD.', true)');
  111. $stmt->bindParam(":id", $_SESSION["n_usuario_id"]);
  112. if(!$stmt->execute()){
  113. //print_r($stmt->errorInfo());
  114. header("Location: ../index.php?error=4");
  115. exit();
  116. }
  117. }
  118. header("Location: ../main.php");//todo OK manda a sellección del sistema
  119. exit();
  120. }else{//error de autenticación
  121. //echo "fallo autenticación";
  122. header("Location: ../index.php?error=1");
  123. exit();
  124. }
  125. }else{//no existe en la BD
  126. //echo "no existe en BD";
  127. header("Location: ../index.php?error=2");
  128. exit();
  129. }
  130. //Si no entró a ninguna, no tiene permisos
  131. //echo "No existe usuario"; exit();
  132. header("Location: ../index.php?error=3");
  133. $pdo = null;
  134. ?>