From 3d1c5b579e95ed20ed7552f404eecd0d7763d112 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Mon, 15 Feb 2021 13:15:57 +0000 Subject: #990 restfunctions: wol: require clients and wol_type params only Webconsole is directly querying the database to build the payload for requesting the ogServer a Wake On Lan. ogServer is expected to query the database for the netmask and mac parameters. Do not require the client request to have such parameters. Adjust calls to the wol php method by other OpenGnsys components. Fixes: a35b7c4 ("#990 Use client broadcast address on WoL") --- .../WebConsole/comandos/gestores/gestor_Comandos.php | 7 ++----- admin/WebConsole/comandos/gestores/wakeonlan_repo.php | 3 +-- admin/WebConsole/includes/RecopilaIpesMacs.php | 19 ------------------- admin/WebConsole/includes/restfunctions.php | 13 ++----------- admin/WebConsole/rest/remotepc.php | 4 ++-- 5 files changed, 7 insertions(+), 39 deletions(-) diff --git a/admin/WebConsole/comandos/gestores/gestor_Comandos.php b/admin/WebConsole/comandos/gestores/gestor_Comandos.php index a90cde56..f8b283d4 100644 --- a/admin/WebConsole/comandos/gestores/gestor_Comandos.php +++ b/admin/WebConsole/comandos/gestores/gestor_Comandos.php @@ -48,8 +48,7 @@ function clean_shell_params($cmd_id, $params) { return $params; } -function run_command($idcomando, $cadenaip, $cadenamac, $netmasks_string, - $atributos) { +function run_command($idcomando, $cadenaip, $cadenamac, $atributos) { global $cmd; switch ($idcomando) { case OG_CMD_ID_WAKEUP: @@ -163,14 +162,12 @@ $cadenaid=""; $cadenaip=""; $cadenamac=""; $cadenaoga=""; // Clave de acceso a la API REST de OGAgent. -$netmasks_string=""; if(!empty($filtro)){ // Ambito restringido a un subconjuto de ordenadores if(substr($filtro,strlen($cadenaid)-1,1)==";") // Si el último caracter es una coma $filtro=substr($filtro,0,strlen($filtro)-1); // Quita la coma } RecopilaIpesMacs($cmd,$ambito,$idambito,$filtro); -get_netmasks($cmd, $cadenamac, $netmasks_string); /*-------------------------------------------------------------------------------------------------------------------- Creación de parametros para sentencias SQL @@ -269,7 +266,7 @@ if($sw_ejya=='on' || $sw_ejprg=="on" ){ $when['map_am_pm'], $when['map_minute']); } else { - run_command($idcomando, $cadenaip, $cadenamac, $netmasks_string, $atributos); + run_command($idcomando, $cadenaip, $cadenamac, $atributos); } // En agente nuevo devuelvo siempre correcto diff --git a/admin/WebConsole/comandos/gestores/wakeonlan_repo.php b/admin/WebConsole/comandos/gestores/wakeonlan_repo.php index 14fef3db..e71f1e51 100644 --- a/admin/WebConsole/comandos/gestores/wakeonlan_repo.php +++ b/admin/WebConsole/comandos/gestores/wakeonlan_repo.php @@ -17,9 +17,8 @@ preg_match_all('!\d{1}!', $atributos, $matches); // Capturamos todas las ids $macs = explode(";",$cadenamac); $ips = explode(';',$cadenaip); -$netmasks = explode(';', $netmasks_string); -wol($matches[0][0], $macs, $ips, $netmasks); +wol($matches[0][0], $ips); // Recorremos las ids y vemos cual es la ip del repositorio $repos = array(); diff --git a/admin/WebConsole/includes/RecopilaIpesMacs.php b/admin/WebConsole/includes/RecopilaIpesMacs.php index 4601a4a2..c41547dc 100644 --- a/admin/WebConsole/includes/RecopilaIpesMacs.php +++ b/admin/WebConsole/includes/RecopilaIpesMacs.php @@ -165,22 +165,3 @@ function RecorreOrdenadores($cmd){ } $rs->Cerrar(); } - -function get_netmasks($cmd, &$macs, &$netmasks){ - $macs = str_replace(";", "','", $macs); - $cmd->texto="SELECT mac, mascara - FROM ordenadores - WHERE mac IN ('".$macs."')"; - $rs=new Recordset; - $rs->Comando=&$cmd; - if (!$rs->Abrir()) return; - $macs = ""; - while (!$rs->EOF){ - $macs.=$rs->campos["mac"].";"; - $netmasks.=$rs->campos["mascara"].";"; - $rs->Siguiente(); - } - $rs->Cerrar(); - $macs = substr($macs, 0, -1); - $netmasks = substr($netmasks, 0, -1); -} diff --git a/admin/WebConsole/includes/restfunctions.php b/admin/WebConsole/includes/restfunctions.php index 138c2730..b0ae084e 100644 --- a/admin/WebConsole/includes/restfunctions.php +++ b/admin/WebConsole/includes/restfunctions.php @@ -36,7 +36,6 @@ define('OG_REST_CMD_MODE', 'mode'); define('OG_REST_PARAM_CLIENTS', 'clients'); define('OG_REST_PARAM_ADDR', 'addr'); define('OG_REST_PARAM_MAC', 'mac'); -define('OG_REST_PARAM_NETMASK', 'netmask'); define('OG_REST_PARAM_DISK', 'disk'); define('OG_REST_PARAM_PART', 'partition'); define('OG_REST_PARAM_RUN', 'run'); @@ -189,7 +188,7 @@ function clients($case, $ips) { return $trama_notificacion; } -function wol($type_wol, $macs, $ips, $netmasks) { +function wol($type_wol, $ips) { switch ($type_wol) { default: @@ -200,16 +199,8 @@ function wol($type_wol, $macs, $ips, $netmasks) { $wol = 'unicast'; } - $clients = array(); - - for($i=0; $i $ips[$i], - OG_REST_PARAM_MAC => $macs[$i], - OG_REST_PARAM_NETMASK => $netmasks[$i]); - } - $data = array(OG_REST_PARAM_TYPE => $wol, - OG_REST_PARAM_CLIENTS => $clients); + OG_REST_PARAM_CLIENTS => $ips); common_request(OG_REST_CMD_WOL, POST, $data); } diff --git a/admin/WebConsole/rest/remotepc.php b/admin/WebConsole/rest/remotepc.php index 0d8491c0..c3b4fe7c 100644 --- a/admin/WebConsole/rest/remotepc.php +++ b/admin/WebConsole/rest/remotepc.php @@ -129,7 +129,7 @@ EOD; // TODO: if client is busy????? if ($app->settings['debug']) writeRemotepcLog($app->request()->getResourceUri(). ": Send boot command through ogAdmServer: iph=$clntip,mac=$clntmac."); - wol(1, [$clntmac], [$clntip], [$clntnetmask]); + wol(1, [$clntip]); // Send WOL command to client repository. $repo = [['url' => "https://$repoip/opengnsys/rest/repository/poweron", 'header' => ["Authorization: $repokey"], @@ -642,7 +642,7 @@ EOD; // TODO: if client is busy????? if ($app->settings['debug']) writeRemotepcLog("{$app->request()->getResourceUri()}: Send boot command through ogAdmServer: iph=$clntip,mac=$clntmac."); - wol(1, [$clntmac], [$clntip], [$clntnetmask]); + wol(1, [$clntip]); // Send WOL command to client repository. $repo = [['url' => "https://$repoip/opengnsys/rest/repository/poweron", 'header' => ["Authorization: $repokey"], -- cgit v1.2.3-18-g5258