summaryrefslogtreecommitdiffstats
path: root/admin/WebConsole
diff options
context:
space:
mode:
authorRamón M. Gómez <ramongomez@us.es>2019-05-30 10:49:13 +0200
committerRamón M. Gómez <ramongomez@us.es>2019-05-30 10:49:13 +0200
commite57b608e4e8176750fe25c9c8cebcc38adbca369 (patch)
treebeb06740282262c0632f196055c136332835fa8e /admin/WebConsole
parentd4e02b28f5455cc47dca40ed28ac03655653d61b (diff)
#891: Boot (wake) command is sent by both server and client repository.
Diffstat (limited to 'admin/WebConsole')
-rw-r--r--admin/WebConsole/comandos/gestores/gestor_Comandos.php18
-rw-r--r--admin/WebConsole/rest/repository.php64
2 files changed, 29 insertions, 53 deletions
diff --git a/admin/WebConsole/comandos/gestores/gestor_Comandos.php b/admin/WebConsole/comandos/gestores/gestor_Comandos.php
index dd83efd5..119ee878 100644
--- a/admin/WebConsole/comandos/gestores/gestor_Comandos.php
+++ b/admin/WebConsole/comandos/gestores/gestor_Comandos.php
@@ -21,8 +21,10 @@ include_once("../../includes/RecopilaIpesMacs.php");
include_once("../includes/capturaacciones.php");
//________________________________________________________________________________________________________
-define("IDCOMANDWAKEUP", 1);
-define("IDCOMANDSENDMESSAGE", 16);
+define("IDCOMMANDPOWEROFF", 2);
+define("IDCOMMANDREBOOT", 5);
+define("IDCOMMANDEXECSCRIPT", 8);
+define("IDCOMMANDSENDMESSAGE", 16);
// Recoge parametros de seguimiento
$sw_ejya="";
@@ -177,7 +179,7 @@ if($sw_ejya=='on' || $sw_ejprg=="on" ){
$ValorParametros=extrae_parametros($parametros,chr(13),'=');
$script=@urldecode($ValorParametros["scp"]);
if($sw_ejya=='on'){
- if ($idcomando != IDCOMANDSENDMESSAGE && $idcomando != IDCOMANDWAKEUP) {
+ if ($idcomando != IDCOMMANDSENDMESSAGE) {
// Envío al servidor
$shidra=new SockHidra($servidorhidra,$hidraport);
if ($shidra->conectar()){ // Se ha establecido la conexión con el servidor hidra
@@ -201,28 +203,28 @@ if($sw_ejya=='on' || $sw_ejprg=="on" ){
$resulhidra = 1;
}
- // Comprobamos si el comando es soportado por el nuevo ogAgent
+ // Comprobamos si el comando es soportado por el nuevo OGAgent
$numip=0;
$ogAgentNuevo = false;
switch ($idcomando) {
- case 2:
+ case IDCOMMANDPOWEROFF:
// Apagar
$urlcomando = 'poweroff';
$ogAgentNuevo = true;
break;
- case 5:
+ case IDCOMMANDREBOOT:
// Reiniciar
$urlcomando = 'reboot';
$ogAgentNuevo = true;
break;
- case 8:
+ case IDCOMMANDEXECSCRIPT:
// Ejecutar script
$urlcomando = 'script';
$ogAgentNuevo = true;
$client = (isset ($_POST['modoejecucion']) && $_POST['modoejecucion'] != '' ) ? $_POST['modoejecucion'] : 'true';
$paramsPost = '{"script":"'.base64_encode($script).'","client":"'.$client.'"}';
break;
- case 16:
+ case IDCOMMANDSENDMESSAGE:
// Enviar mensaje
$urlcomando = 'popup';
$ogAgentNuevo = true;
diff --git a/admin/WebConsole/rest/repository.php b/admin/WebConsole/rest/repository.php
index bc2fdec6..736cc1c2 100644
--- a/admin/WebConsole/rest/repository.php
+++ b/admin/WebConsole/rest/repository.php
@@ -10,12 +10,6 @@
* @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.
/**
@@ -30,8 +24,8 @@ function validateRepositoryApiKey() {
@$apikey = htmlspecialchars(function_exists('apache_request_headers') ? apache_request_headers()['Authorization'] : $_SERVER['HTTP_AUTHORIZATION']);
if (isset($apikey)) {
// fetch repository token from ogAdmRepo.cfg configuration file.
- @$confFile = parse_ini_file('../../etc/ogAdmRepo.cfg', 'r');
- if ($confFile) {
+ @$confFile = parse_ini_file(__DIR__ . '/../../etc/ogAdmRepo.cfg', 'r');
+ if (isset($confFile)) {
if(@strcmp($apikey, $confFile['ApiToken']) == 0) {
// Credentials OK.
return true;
@@ -191,46 +185,26 @@ $app->get('/repository/image(/:ouname)/:imagename(/)', 'validateRepositoryApiKey
*/
$app->post('/repository/poweron', 'validateRepositoryApiKey',
function() use($app) {
- // Fetch repository token from ogAdmServer.cfg configuration file.
- @$confFile = parse_ini_file('../../etc/ogAdmServer.cfg', 'r');
- if ($confFile) {
- // 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.
- $response['message'] = 'Required param macs not found';
- jsonResponse(400, $response);
+ // 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.
+ $response['message'] = 'Required param macs not found';
+ jsonResponse(400, $response);
+ } else {
+ // Execute local wakeonlan command (may be installed)
+ if(commandExist("wakeonlan")) {
+ $strMacs = trim(implode(' ', $data->macs));
+ $response["output"] = "Executing wakeonlan ".$strMacs."\n";
+ $response["output"] .= shell_exec("wakeonlan ".$strMacs);
+ jsonResponse(200, $response);
} else {
- // 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($confFile['ServidorAdm'], $confFile['PUERTO']);
- 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();
- }
+ // Print error message.
+ $response['message'] = 'Wakeonlan command not found in this repository';
+ jsonResponse(404, $response);
}
- } else {
- // Cannot access configuration file.
- $response['message'] = "An error occurred, please try again";
- jsonResponse(500, $response);
- $app->stop();
}
+ $app->stop();
}
);
-