summaryrefslogtreecommitdiffstats
path: root/admin/WebConsole/rest
diff options
context:
space:
mode:
Diffstat (limited to 'admin/WebConsole/rest')
-rw-r--r--admin/WebConsole/rest/repository.php45
1 files changed, 29 insertions, 16 deletions
diff --git a/admin/WebConsole/rest/repository.php b/admin/WebConsole/rest/repository.php
index bf6359be..062aae28 100644
--- a/admin/WebConsole/rest/repository.php
+++ b/admin/WebConsole/rest/repository.php
@@ -10,6 +10,13 @@
* @date 2016-04-06
*/
+include_once("../clases/SockHidra.php");
+
+include_once("../includes/comunes.php");
+
+define("LENHEXPRM", 5); // Length of hexdecimal chain containing total frame length
+define("LENHEAD", 16); // Frame head length
+
// Auxiliar functions.
/**
* @brief Validate API key included in "Authorization" HTTP header.
@@ -184,7 +191,7 @@ $app->get('/repository/image(/:ouname)/:imagename(/)', 'validateRepositoryApiKey
*/
$app->post('/repository/poweron', 'validateRepositoryApiKey',
function() use($app) {
- // Debe venir el parametro macs en el post (objeto JSON con array de MACs)
+ // The macs parameter must come in the post (JSON object with array of MACs)
$data = json_decode($app->request()->getBody());
if(empty($data->macs)){
// Print error message.
@@ -192,21 +199,27 @@ $app->post('/repository/poweron', 'validateRepositoryApiKey',
jsonResponse(400, $response);
}
else{
- $strMacs = "";
- foreach($data->macs as $mac){
- $strMacs .= " ".$mac;
- }
- // Ejecutar comando wakeonlan, debe estar disponible en el sistema operativo
- if(commandExist("wakeonlan")){
- $response["output"] = "Executing wakeonlan ".trim($strMacs)."\n";
- $response["output"] .= shell_exec("wakeonlan ".trim($strMacs));
- // Comprobar si el comando se ejecutórrectamente
- jsonResponse(200, $response);
- }
- else{
- // Print error message.
- $response['message'] = 'Wakeonlan command not found in this repository';
- jsonResponse(404, $response);
+ // Execute WakeOnLan command with ogAdmServer
+ $strMacs = implode(';', $data->macs);
+ $strMacs = str_replace(':', '', $strMacs);
+ $strIps = implode(';', $data->ips);
+ $params="nfn=Arrancar" . chr(13) . "mac=" . $strMacs . chr(13) . "iph=" . $strIps . chr(13) . "mar=" . $data->mar .
+ chr(13);
+ $shidra=new SockHidra("127.0.0.1", "2008");
+ if ($shidra->conectar()) { // The connection to the hydra server has been established
+ $resul=$shidra->envia_comando($params);
+ if($resul) {
+ $frame=$shidra->recibe_respuesta();
+ $hlonprm=hexdec(substr($frame, LENHEAD, LENHEXPRM));
+ $params=substr($frame, LENHEAD + LENHEXPRM, $hlonprm);
+ $ParamsValue=extrae_parametros($params, chr(13), '=');
+ $resul=$ParamsValue["res"];
+ jsonResponse(200, $resul);
+ } else {
+ $response['message'] = 'Error in ogAdmServer';
+ jsonResponse(404, $response);
+ }
+ $shidra->desconectar();
}
}
}