-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subo avance de js, y mock de respuesta sel servidor de hashes inversos
- Loading branch information
1 parent
c796409
commit 34b9ce4
Showing
5 changed files
with
157 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(function () { | ||
$(document).ready(function () { | ||
$("#formulario").submit(function (evt) { | ||
evt.preventDefault(); | ||
var data = { | ||
hash: $("#txtHash").val().trim(), | ||
algoritmo: $("#slcAlgoritmos").val().trim(), | ||
}; | ||
$.ajax({ | ||
url: "src/cracker.php", | ||
type: "post", | ||
data: {} | ||
}).done(function (respuesta) { | ||
console.log(respuesta); | ||
}); | ||
}); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
require_once '../config.php'; | ||
|
||
// Funcion para hacer peticiones con cURL | ||
function hacer_peticion($url_recurso) { | ||
$datos = null; | ||
// Inicio curl | ||
$sesion = curl_init(); | ||
curl_setopt($sesion, CURLOPT_URL, $url_recurso); | ||
curl_setopt($sesion, CURLOPT_HTTPGET, true); | ||
curl_setopt($sesion, CURLOPT_HEADER, false); | ||
curl_setopt($sesion, CURLOPT_RETURNTRANSFER, true); | ||
|
||
// Ejecuto | ||
$resultado = curl_exec($sesion); | ||
|
||
// Cierro curl | ||
curl_close($sesion); | ||
|
||
// Proceso la respuesta | ||
if ($resultado === false) { | ||
throw new Exception("Error al hacer petición.", 0, null); | ||
} | ||
$resultado = json_decode($resultado); | ||
if (!property_exists($resultado, "estado")) { | ||
// Error... | ||
throw new Exception("Respuesta con formato no reconocido.", 0, null); | ||
} else { | ||
$estado = $resultado->estado; | ||
if ($estado === "ok") { | ||
$datos = $resultado->datos; | ||
} else { | ||
throw new Exception($resultado->error->descripcion, $resultado->error->id, null); | ||
} | ||
} | ||
return $datos; | ||
} | ||
|
||
// URL del recurso del Servidor de Hashes Inversos | ||
$url_recurso = "http://localhost/labsis_hash_cracker_web/src/mockup_respuesta_shi.php"; | ||
$respuesta = hacer_peticion($url_recurso); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
// Poner en true en caso de que no se produzco un error. | ||
$error = false; | ||
// Completar con los detalles del error ocurrido. | ||
$objeto_error = array("id" => -1, "descripcion" => ""); | ||
// Completar con los datos obtenidos de ejecutar el programa java. | ||
$objeto_datos = []; | ||
|
||
try { | ||
|
||
// Todo el procesamiento: ejecutar java y procesar respuesta aqui... | ||
// ... | ||
// Obtengo parametros de entrada: | ||
|
||
$hash = filter_input(INPUT_POST, "hash"); | ||
$algoritmo = filter_input(INPUT_POST, "algoritmo"); | ||
|
||
// Armo comando con parametros de entrada. | ||
$comando = "java ..."; | ||
exec($comando); | ||
// Fin del procesamiento. | ||
} catch (Exception $ex) { | ||
$error = true; | ||
$objeto_error = array("id" => 1, "descripcion" => "Error: " . $ex->getMessage()); | ||
} | ||
|
||
// Creo respuesta como array, al final sera convertida en json. | ||
$respuesta = array( | ||
"estado" => ($error === true) ? "error" : "ok" | ||
); | ||
|
||
if ($error === false) { | ||
$respuesta["datos"] = $objeto_datos; | ||
} else { | ||
$respuesta["error"] = $objeto_error; | ||
} | ||
|
||
echo json_encode($respuesta); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters