summaryrefslogtreecommitdiffstats
path: root/admin/WebConsole/rest
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2019-01-28 10:22:57 +0100
committerRamón M. Gómez <ramongomez@us.es>2019-01-29 14:55:27 +0100
commit2b00219981fbc33f1131390a6a051e7d9f2e8295 (patch)
treed1969ea61651ab9dab45037fd4ffaa8decd0c2b9 /admin/WebConsole/rest
parent3f59ea6b3143ba850ce03161d08c2813d9f352f4 (diff)
#892: Use ogAdmServer Wake on Lan
* gestor_Comando.php only execute wakeonlan_repo.php when wake up command is called. * wakeonlan_repo.php send new needed parameters for ogAdmServer WoL. * repository.php use ogAdmServer WoL instead of wakeonlan perl script. * opengnsys_installer.sh and opengnsys_update.sh don't have wakeonlan perl script dependency anymore. # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Mon Jan 28 10:22:57 2019 +0100 # # On branch devel # Your branch is ahead of 'origin/devel' by 1 commit. # (use "git push" to publish your local commits) # # Changes to be committed: # modified: admin/WebConsole/comandos/gestores/gestor_Comandos.php # modified: admin/WebConsole/comandos/gestores/wakeonlan_repo.php # modified: admin/WebConsole/rest/repository.php # modified: installer/opengnsys_installer.sh # modified: installer/opengnsys_update.sh # # Untracked files: # 0001-892-Use-ogAdmServer-Wake-on-Lan.patch # 0001-892-Use-ogAdmServer-Wake-on-Lan.zip #
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();
}
}
}