summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorramon <ramongomez@us.es>2016-10-13 12:12:36 +0000
committerramon <ramongomez@us.es>2016-10-13 12:12:36 +0000
commit69052958f68c72caecaf47ad2d7d638241755c57 (patch)
tree6a9257a46aac99f87afc3d9663d62db8c9501468
parentf6045a5a04a257ad5dba6f541032798fe6245b91 (diff)
#718: Usar clave de acceso a OGAgent en peticiones del servidor (por el momento usando método GET); soportar cabeceras y simplificar las llamadas a cURL.
git-svn-id: https://opengnsys.es/svn/branches/version1.1@5033 a21b9725-9963-47de-94b9-378ad31fedc9
-rw-r--r--admin/WebConsole/comandos/gestores/gestor_Comandos.php11
-rw-r--r--admin/WebConsole/includes/RecopilaIpesMacs.php25
-rw-r--r--admin/WebConsole/includes/restfunctions.php12
-rw-r--r--admin/WebConsole/principal/sondeo.php2
-rw-r--r--admin/WebConsole/rest/server.php2
5 files changed, 36 insertions, 16 deletions
diff --git a/admin/WebConsole/comandos/gestores/gestor_Comandos.php b/admin/WebConsole/comandos/gestores/gestor_Comandos.php
index 2f6c706c..35c6c671 100644
--- a/admin/WebConsole/comandos/gestores/gestor_Comandos.php
+++ b/admin/WebConsole/comandos/gestores/gestor_Comandos.php
@@ -83,6 +83,7 @@ $atributos=str_replace('$',chr(9),$atributos);
$cadenaid="";
$cadenaip="";
$cadenamac="";
+$cadenaoga=""; // Clave de acceso a la API REST de OGAgent.
if(!empty($filtro)){ // Ambito restringido a un subconjuto de ordenadores
if(substr($filtro,strlen($cadenaid)-1,1)==";") // Si el último caracter es una coma
@@ -208,11 +209,15 @@ if($sw_ejya=='on' || $sw_ejprg=="on" ){
$urls = array();
$ipsuccess = '';
// Compose array of REST URLs.
- foreach (explode (';', $cadenaip) as $ip) {
- $urls[$ip] = "https://$ip:8000/opengnsys/$urlcomando";
+ $auxIp = explode(';', $cadenaip);
+ $auxKey = explode(";", $cadenaoga);
+ $i = 0;
+ foreach ($auxIp as $ip) {
+ $urls[$ip] = "https://$ip:8000/opengnsys/$urlcomando?secret=".$auxKey[$i];
+ $i++;
}
// Launch concurrent requests.
- $responses = multiRequest($urls, array(CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false));
+ $responses = multiRequest($urls);
// Process responses array (IP as array index).
foreach ($responses as $ip => $data) {
if (isset($data)) {
diff --git a/admin/WebConsole/includes/RecopilaIpesMacs.php b/admin/WebConsole/includes/RecopilaIpesMacs.php
index f3caac06..70a7f8e3 100644
--- a/admin/WebConsole/includes/RecopilaIpesMacs.php
+++ b/admin/WebConsole/includes/RecopilaIpesMacs.php
@@ -1,4 +1,4 @@
-<?
+<?php
// *************************************************************************************************************************************************
// Aplicación WEB: ogAdmWebCon
// Autor: José Manuel Alonso (E.T.S.I.I.) Universidad de Sevilla
@@ -38,7 +38,9 @@ function RecopilaIpesMacs($cmd,$ambito,$idambito,$filtroip=""){
if(!empty($filtroip)){
$filtroip="'".str_replace(";","','",$filtroip)."'"; // Cambia caracter ; para consulta alfanumérica
- $cmd->texto="SELECT ip, mac, nombreordenador, idordenador FROM ordenadores WHERE ip IN (".$filtroip.")";
+ $cmd->texto="SELECT ip, mac, nombreordenador, idordenador, agentkey
+ FROM ordenadores
+ WHERE ip IN (".$filtroip.")";
RecorreOrdenadores($cmd);
}
else{
@@ -60,13 +62,16 @@ function RecopilaIpesMacs($cmd,$ambito,$idambito,$filtroip=""){
RecorreGruposOrdenadores($cmd);
break;
case $AMBITO_ORDENADORES :
- $cmd->texto="SELECT ip,mac,nombreordenador,idordenador FROM ordenadores WHERE idordenador=".$idambito;
+ $cmd->texto="SELECT ip, mac, nombreordenador, idordenador, agentkey
+ FROM ordenadores
+ WHERE idordenador=".$idambito;
RecorreOrdenadores($cmd);
break;
default: // Se trata de un conjunto aleatorio de ordenadores
- $cmd->texto="SELECT ip,mac,nombreordenador,idordenador FROM ordenadores WHERE idordenador IN (".$idambito.")";
+ $cmd->texto="SELECT ip, mac, nombreordenador, idordenador, agentkey
+ FROM ordenadores
+ WHERE idordenador IN (".$idambito.")";
RecorreOrdenadores($cmd);
-
}
}
$cadenaid=substr($cadenaid,0,strlen($cadenaid)-1); // Quita la coma
@@ -116,7 +121,9 @@ function RecorreAulas($cmd){
$idaula=$rs->campos["idaula"];
$cmd->texto="SELECT idgrupo,nombregrupoordenador FROM gruposordenadores WHERE idaula=".$idaula." AND grupoid=0";
RecorreGruposOrdenadores($cmd);
- $cmd->texto="SELECT ip,mac,nombreordenador,idordenador FROM ordenadores WHERE idaula=".$idaula." AND grupoid=0";
+ $cmd->texto="SELECT ip, mac, nombreordenador, idordenador, agentkey
+ FROM ordenadores
+ WHERE idaula=".$idaula." AND grupoid=0";
RecorreOrdenadores($cmd);
$rs->Siguiente();
}
@@ -132,7 +139,9 @@ function RecorreGruposOrdenadores($cmd){
$idgrupo=$rs->campos["idgrupo"];
$cmd->texto="SELECT idgrupo,nombregrupoordenador FROM gruposordenadores WHERE grupoid=".$idgrupo;
RecorreGruposOrdenadores($cmd);
- $cmd->texto="SELECT ip,mac,nombreordenador,idordenador FROM ordenadores WHERE grupoid=".$idgrupo;
+ $cmd->texto="SELECT ip, mac, nombreordenador, idordenador, agentkey
+ FROM ordenadores
+ WHERE grupoid=".$idgrupo;
RecorreOrdenadores($cmd);
$rs->Siguiente();
}
@@ -143,6 +152,7 @@ function RecorreOrdenadores($cmd){
global $cadenaid;
global $cadenaip;
global $cadenamac;
+ global $cadenaoga;
$rs=new Recordset;
$rs->Comando=&$cmd;
if (!$rs->Abrir()) return; // Error al abrir recordset
@@ -150,6 +160,7 @@ function RecorreOrdenadores($cmd){
$cadenaid.=$rs->campos["idordenador"].",";
$cadenaip.=$rs->campos["ip"].";";
$cadenamac.=$rs->campos["mac"].";";
+ $cadenaoga.=(is_null($rs->campos["agentkey"])?"":$rs->campos["agentkey"]).";";
$rs->Siguiente();
}
$rs->Cerrar();
diff --git a/admin/WebConsole/includes/restfunctions.php b/admin/WebConsole/includes/restfunctions.php
index f4084aa4..b8c1cb94 100644
--- a/admin/WebConsole/includes/restfunctions.php
+++ b/admin/WebConsole/includes/restfunctions.php
@@ -2,11 +2,11 @@
/*
* Function: multiRequest.
- * Params: urls array, cURL options array.
- * Returns: array with JSON requests.
+ * Params: URLs array, cURL options array.
+ * Returns: Array with JSON requests.
* Date: 2015-10-14
*/
-function multiRequest($data, $options = array()) {
+function multiRequest($data, $options=array(CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false)) {
// array of curl handles
$curly = array();
@@ -25,7 +25,11 @@ function multiRequest($data, $options = array()) {
$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
curl_setopt($curly[$id], CURLOPT_URL, $url);
- curl_setopt($curly[$id], CURLOPT_HEADER, 0);
+ if (is_array($d) && !empty($d['header'])) {
+ curl_setopt($curly[$id], CURLOPT_HEADER, $d['header']);
+ } else {
+ curl_setopt($curly[$id], CURLOPT_HEADER, 0);
+ }
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curly[$id], CURLOPT_TIMEOUT, 1);
diff --git a/admin/WebConsole/principal/sondeo.php b/admin/WebConsole/principal/sondeo.php
index ea11e6e5..793ecbd6 100644
--- a/admin/WebConsole/principal/sondeo.php
+++ b/admin/WebConsole/principal/sondeo.php
@@ -78,7 +78,7 @@
$urls[$ip] = "https://$ip:8000/opengnsys/status";
}
// Launch concurrent requests.
- $responses = multiRequest($urls, array(CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false));
+ $responses = multiRequest($urls);
// Process responses array (IP as array index).
foreach ($responses as $ip => $data) {
if (isset($data)) {
diff --git a/admin/WebConsole/rest/server.php b/admin/WebConsole/rest/server.php
index 056f680c..ab10bb06 100644
--- a/admin/WebConsole/rest/server.php
+++ b/admin/WebConsole/rest/server.php
@@ -636,7 +636,7 @@ EOD;
if (empty($stat[0]) or preg_match('/OFF/', $stat[0])) {
// If no data, check OGAgent API connection.
$url = "https://$clientip:8000/opengnsys/status";
- $result = multiRequest(Array($url), array(CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false));
+ $result = multiRequest(Array($url));
if (empty($result[0])) {
// Client is off.
$response['status'] = $status['OFF'];