summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2020-07-01 14:16:31 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-07-03 14:14:16 +0200
commita35b7c42ee20986414e61b254c22e82fb8619abe (patch)
tree472673c0f32c1d99b02efab8d541f196e76d6072
parent5249c5dfa0f478b2372ca19274c192cdf0dc3ced (diff)
#990 Use client broadcast address on WoL
Some universities have computers in a different subnet where the ogServer is, but ogServer WoL functionality only supported to send packet to its own subnets. This commit solves this. Now ogServer sends two WoL packets per client, one with the broadcast address of the interface indicated in the config file, the other with the broadcast address calculated with the address and netmask of the client. To ensure that the second WoL works correctly you must configure correctly the IP and netmask of the clients. Also, you have to configure the network of your organization to route WoL packet to the correct subnet.
-rw-r--r--admin/WebConsole/comandos/gestores/gestor_Comandos.php7
-rw-r--r--admin/WebConsole/comandos/gestores/wakeonlan_repo.php3
-rw-r--r--admin/WebConsole/includes/RecopilaIpesMacs.php19
-rw-r--r--admin/WebConsole/includes/restfunctions.php6
4 files changed, 29 insertions, 6 deletions
diff --git a/admin/WebConsole/comandos/gestores/gestor_Comandos.php b/admin/WebConsole/comandos/gestores/gestor_Comandos.php
index 64e159af..56b5a299 100644
--- a/admin/WebConsole/comandos/gestores/gestor_Comandos.php
+++ b/admin/WebConsole/comandos/gestores/gestor_Comandos.php
@@ -36,7 +36,8 @@ define('OG_CMD_ID_CREATE_INCREMENTAL_IMAGE', 14);
define('OG_CMD_ID_RESTORE_INCREMENTAL_IMAGE', 15);
define('OG_CMD_ID_SENDMESSAGE', 16);
-function run_command($idcomando, $cadenaip, $cadenamac, $atributos) {
+function run_command($idcomando, $cadenaip, $cadenamac, $netmasks_string,
+ $atributos) {
global $cmd;
switch ($idcomando) {
case OG_CMD_ID_WAKEUP:
@@ -150,12 +151,14 @@ $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
@@ -253,7 +256,7 @@ if($sw_ejya=='on' || $sw_ejprg=="on" ){
$when['map_am_pm'],
$when['map_minute']);
} else {
- run_command($idcomando, $cadenaip, $cadenamac, $atributos);
+ run_command($idcomando, $cadenaip, $cadenamac, $netmasks_string, $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 c1c5394f..14fef3db 100644
--- a/admin/WebConsole/comandos/gestores/wakeonlan_repo.php
+++ b/admin/WebConsole/comandos/gestores/wakeonlan_repo.php
@@ -17,8 +17,9 @@ 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);
+wol($matches[0][0], $macs, $ips, $netmasks);
// 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 2ded1775..4601a4a2 100644
--- a/admin/WebConsole/includes/RecopilaIpesMacs.php
+++ b/admin/WebConsole/includes/RecopilaIpesMacs.php
@@ -166,4 +166,21 @@ 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 81821ff9..88e486ac 100644
--- a/admin/WebConsole/includes/restfunctions.php
+++ b/admin/WebConsole/includes/restfunctions.php
@@ -35,6 +35,7 @@ define('OG_REST_CMD_GET_SCHEDULE', 'schedule/get');
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');
@@ -187,7 +188,7 @@ function clients($case, $ips) {
return $trama_notificacion;
}
-function wol($type_wol, $macs, $ips) {
+function wol($type_wol, $macs, $ips, $netmasks) {
switch ($type_wol) {
default:
@@ -202,7 +203,8 @@ function wol($type_wol, $macs, $ips) {
for($i=0; $i<count($macs); $i++) {
$clients[] = array(OG_REST_PARAM_ADDR => $ips[$i],
- OG_REST_PARAM_MAC => $macs[$i]);
+ OG_REST_PARAM_MAC => $macs[$i],
+ OG_REST_PARAM_NETMASK => $netmasks[$i]);
}
$data = array(OG_REST_PARAM_TYPE => $wol,