summaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorramon <ramongomez@us.es>2017-03-10 13:26:16 +0000
committerramon <ramongomez@us.es>2017-03-10 13:26:16 +0000
commit213a832eadaecd739e7a460f4ea768d21b1f4c31 (patch)
treea95229ba2df3dc76ab0195c3251b3cae0a6918eb /admin
parente80bab402c2ce402932824ad3f29792f9dca235e (diff)
#708: Nueva ruta {{{GET /ous/:ouid/labs/:labid/clients//status}}} para obtener el estado de todos los clientes de un aula; actualizar definición de la API REST y definir parámetros para evitar duplicados.
git-svn-id: https://opengnsys.es/svn/branches/version1.1@5227 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'admin')
-rw-r--r--admin/WebConsole/comandos/gestores/gestor_Comandos.php1
-rw-r--r--admin/WebConsole/rest/opengnsys-api.yml318
-rw-r--r--admin/WebConsole/rest/server.php119
3 files changed, 189 insertions, 249 deletions
diff --git a/admin/WebConsole/comandos/gestores/gestor_Comandos.php b/admin/WebConsole/comandos/gestores/gestor_Comandos.php
index 9304e8a5..069b94cb 100644
--- a/admin/WebConsole/comandos/gestores/gestor_Comandos.php
+++ b/admin/WebConsole/comandos/gestores/gestor_Comandos.php
@@ -174,7 +174,6 @@ if($sw_ejya=='on' || $sw_ejprg=="on" ){
if ($shidra->conectar()){ // Se ha establecido la conexión con el servidor hidra
$parametros.=$aplicacion;
$parametros.=$acciones;
- //die($parametros);
$resul=$shidra->envia_comando($parametros);
if($resul)
$trama=$shidra->recibe_respuesta();
diff --git a/admin/WebConsole/rest/opengnsys-api.yml b/admin/WebConsole/rest/opengnsys-api.yml
index 86696756..e4b76e12 100644
--- a/admin/WebConsole/rest/opengnsys-api.yml
+++ b/admin/WebConsole/rest/opengnsys-api.yml
@@ -183,11 +183,7 @@ paths:
get:
description: Get an `OU` object.
parameters:
- - name: ouid
- in: path
- description: Organization Unit identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
responses:
"200":
description: Successful response
@@ -213,11 +209,7 @@ paths:
get:
description: Get all group of labs defined in an `OU` object.
parameters:
- - name: ouid
- in: path
- description: Organization Unit identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
responses:
"200":
description: Successful response
@@ -257,11 +249,7 @@ paths:
get:
description: Get all `lab` objects defined in an `OU`.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
responses:
"200":
description: Successful response
@@ -304,16 +292,8 @@ paths:
get:
description: Get a `lab` object.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: labid
- in: path
- description: laboratory identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
responses:
"200":
description: Successful response
@@ -391,7 +371,7 @@ paths:
picture:
description: Lab's picture file
type: string
- required: [ id, name, location, description, inremotepc, capacity, defclients, projector, board, routerip, netmask, mcastmode, mcastip, mcastport, mcastspeed, p2pmode, p2ptime, image ]
+ required: [ id, name, location, description, inremotepc, capacity, defclients, projector, board, routerip, netmask, mcastmode, mcastip, mcastport, mcastspeed, p2pmode, p2ptime, picture ]
security:
- apikey: []
tags:
@@ -401,16 +381,8 @@ paths:
get:
description: Get all `client` objects defined in an `lab`.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: labid
- in: path
- description: Lab identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
responses:
"200":
description: Successful response
@@ -450,25 +422,31 @@ paths:
tags:
- server
- client
+ /ous/{ouid}/labs/{labid}/clients//status:
+ get:
+ description: Get execution status of all clients definied in a `lab`
+ parameters:
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
+ responses:
+ "200":
+ description: Successful response
+ schema:
+ type: array
+ items:
+ $ref: "#/definitions/StatusModel"
+ security:
+ - apikey: []
+ tags:
+ - server
+ - client
/ous/{ouid}/labs/{labid}/clients/{clientid}:
get:
description: Get a `client` object.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: labid
- in: path
- description: Lab identificator
- required: true
- type: integer
- - name: clientid
- in: path
- description: Client identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
+ - $ref: "#/parameters/clientParam"
responses:
"200":
description: Successful response
@@ -519,7 +497,7 @@ paths:
picture:
description: client's picture file
type: string
- required: [ id, name, serialno, netiface, netdriver, mac, ip, netmask, routerip, repo, validation, image ]
+ required: [ id, name, serialno, netiface, netdriver, mac, ip, netmask, routerip, repo, validation, picture ]
security:
- apikey: []
tags:
@@ -529,21 +507,9 @@ paths:
get:
description: Get the hardware definition of a `client` object.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: labid
- in: path
- description: Lab identificator
- required: true
- type: integer
- - name: clientid
- in: path
- description: Client identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
+ - $ref: "#/parameters/clientParam"
responses:
"200":
description: Successful response
@@ -580,21 +546,9 @@ paths:
get:
description: Get disks configuration of a `client`
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: labid
- in: path
- description: Lab identificator
- required: true
- type: integer
- - name: clientid
- in: path
- description: Client identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
+ - $ref: "#/parameters/clientParam"
responses:
"200":
description: Successful response
@@ -671,42 +625,14 @@ paths:
get:
description: Get execution status of a `client`
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: labid
- in: path
- description: Lab identificator
- required: true
- type: integer
- - name: clientid
- in: path
- description: Client identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
+ - $ref: "#/parameters/clientParam"
responses:
"200":
description: Successful response
schema:
- type: object
- properties:
- id:
- description: client id
- type: integer
- format: int32
- ip:
- description: client IP address
- type: string
- status:
- description: execution status
- type: string
- enum: [ "nodata", "off", "ogclient", "busy", "linux", "windows", "unknown" ]
- loggedin:
- description: flag to check if an user is logged in
- type: boolean
- required: [ id, ip, status, loggedin ]
+ $ref: "#/definitions/StatusModel"
security:
- apikey: []
tags:
@@ -716,21 +642,9 @@ paths:
post:
description: Store UDS server URLs to resend some events recieved from OGAgent.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: labid
- in: path
- description: Lab identificator
- required: true
- type: integer
- - name: clientid
- in: path
- description: Client identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
+ - $ref: "#/parameters/clientParam"
- name: data
in: body
description: Operation data
@@ -765,21 +679,9 @@ paths:
post:
description: Record session data for a client.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: labid
- in: path
- description: Lab identificator
- required: true
- type: integer
- - name: clientid
- in: path
- description: Client identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
+ - $ref: "#/parameters/clientParam"
- name: data
in: body
description: Session parameters
@@ -804,21 +706,9 @@ paths:
delete:
description: Unreserve a client, clear its session data and send a poweroff operation.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: labid
- in: path
- description: Lab identificator
- required: true
- type: integer
- - name: clientid
- in: path
- description: Client identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/labParam"
+ - $ref: "#/parameters/clientParam"
responses:
"200":
description: Successful response
@@ -832,11 +722,7 @@ paths:
get:
description: Get all `repo` objects defined in an `OU`.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
responses:
"200":
description: Successful response
@@ -866,16 +752,8 @@ paths:
get:
description: Get a `repo` object.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: repoid
- in: path
- description: repository identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/repoParam"
responses:
"200":
description: Successful response
@@ -905,11 +783,7 @@ paths:
get:
description: Get all `image` objects defined in an `OU`.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
responses:
"200":
description: Successful response
@@ -941,16 +815,8 @@ paths:
get:
description: Get an `image` object.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: imageid
- in: path
- description: image definition identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/imageParam"
responses:
"200":
description: Successful response
@@ -1020,16 +886,8 @@ paths:
get:
description: Get software inventory store into an `image`
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: imageid
- in: path
- description: image definition identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/imageParam"
responses:
"200":
description: Successful response
@@ -1067,16 +925,8 @@ paths:
Reserve a random client with an installed image and send a boot/reboot operation.
If `labid` is specified, then choose a `client` defined in this lab.
parameters:
- - name: ouid
- in: path
- description: OU identificator
- required: true
- type: integer
- - name: imageid
- in: path
- description: image definition identificator
- required: true
- type: integer
+ - $ref: "#/parameters/ouParam"
+ - $ref: "#/parameters/imageParam"
- name: labid
in: query
description: lab. identificator
@@ -1281,3 +1131,53 @@ paths:
tags:
- server
- agent
+parameters:
+ ouParam:
+ name: ouid
+ in: path
+ description: OU identificator
+ required: true
+ type: integer
+ labParam:
+ name: labid
+ in: path
+ description: Lab identificator
+ required: true
+ type: integer
+ clientParam:
+ name: clientid
+ in: path
+ description: Client identificator
+ required: true
+ type: integer
+ repoParam:
+ name: repoid
+ in: path
+ description: repository identificator
+ required: true
+ type: integer
+ imageParam:
+ name: imageid
+ in: path
+ description: image definition identificator
+ required: true
+ type: integer
+definitions:
+ StatusModel:
+ type: object
+ properties:
+ id:
+ description: client id
+ type: integer
+ format: int32
+ ip:
+ description: client IP address
+ type: string
+ status:
+ description: execution status
+ type: string
+ enum: [ "off", "ogclient", "busy", "linux", "windows", "macos", "unknown" ]
+ loggedin:
+ description: flag to check if an user is logged in
+ type: boolean
+ required: [ id, ip, status ]
diff --git a/admin/WebConsole/rest/server.php b/admin/WebConsole/rest/server.php
index b593241c..76254959 100644
--- a/admin/WebConsole/rest/server.php
+++ b/admin/WebConsole/rest/server.php
@@ -368,6 +368,7 @@ EOD;
}
);
+
/**
* @brief List all clients defined in a lab
* @note Route: /ous/id1/labs/id2/clients, Method: GET
@@ -628,55 +629,71 @@ EOD;
* @param id3 client id.
* @return JSON string with client status
*/
-$app->get('/ous/:ouid/labs/:labid/clients/:clntid/status(/)', 'validateApiKey',
- function($ouid, $labid, $clntid) {
+$app->get('/ous/:ouid/labs/:labid/clients//status(/)', 'validateApiKey', 'getStatus');
+$app->get('/ous/:ouid/labs/:labid/clients/:clntid/status(/)', 'validateApiKey', 'getStatus');
+function getStatus($ouid, $labid, $clntid=0) {
global $userid;
global $cmd;
global $LONCABECERA;
global $LONHEXPRM;
-
+ $app = \Slim\Slim::getInstance();
+ $clientid = $clientip = "";
+ $urls = Array();
// Status mapping.
$status = Array('OFF'=>"off",
'INI'=>"initializing",
'OPG'=>"ogclient",
'BSY'=>"busy",
'LNX'=>"linux",
- 'WIN'=>"windows");
+ 'OSX'=>"macos",
+ 'WIN'=>"windows",
+ 'UNK'=>"unknown");
// Parameters.
$ouid = htmlspecialchars($ouid);
$labid = htmlspecialchars($labid);
- $clntid = htmlspecialchars($clntid);
+ $single = is_numeric(explode("/", $app->request->getResourceUri())[6]);
// Database query.
$cmd->texto = <<<EOD
SELECT adm.idadministradorcentro, entornos.ipserveradm, entornos.portserveradm,
- ordenadores.idordenador, ordenadores.ip
+ aulas.idaula, ordenadores.idordenador, ordenadores.ip
FROM entornos, ordenadores
JOIN aulas USING(idaula)
RIGHT JOIN administradores_centros AS adm USING(idcentro)
WHERE adm.idadministradorcentro = '$userid'
AND adm.idcentro='$ouid'
AND aulas.idaula='$labid'
+EOD;
+ // Request for a single client.
+ if ($single) {
+ $clntid = htmlspecialchars($clntid);
+ $cmd->texto .= <<<EOD
AND ordenadores.idordenador='$clntid';
EOD;
+ } else {
+ $response = Array();
+ }
$rs=new Recordset;
$rs->Comando=&$cmd;
if (!$rs->Abrir()) return(false); // Error oppening recordset.
$rs->Primero();
- // Check if user is an UO admin and client exists.
- if (checkAdmin($rs->campos["idadministradorcentro"]) and checkParameter($rs->campos["idordenador"])) {
+ // Check if user is an UO admin and asset exists.
+ if (checkAdmin($rs->campos["idadministradorcentro"]) and (($single and checkParameter($rs->campos["idordenador"])) or (! $single and checkParameter($rs->campos["idaula"])))) {
// First, try to connect to ogAdmCleint service.
$serverip = $rs->campos["ipserveradm"];
$serverport = $rs->campos["portserveradm"];
- $clientid = $rs->campos["idordenador"];
- $clientip = $rs->campos["ip"];
-
+ while (!$rs->EOF) {
+ $id[$rs->campos["ip"]] = $rs->campos["idordenador"];
+ $stat[$rs->campos["ip"]] = $status['OFF'];
+ $rs->Siguiente();
+ }
// Connect to reset client's status.
+ $clientid = implode(",", $id);
+ $clientip = implode(";", array_keys($id));
$reqframe = "nfn=Sondeo\r".
"ido=$clientid\r".
"iph=$clientip\r";
$result = sendCommand($serverip, $serverport, $reqframe, $values);
-
// Connect to fetch client's status.
// Asuming client is off by default.
$values["tso"]="OFF";
@@ -692,40 +709,65 @@ EOD;
// Wait until next checking (0.1 ms).
usleep(100000);
}
-
// Parse status response.
if ($result) {
// Check status type.
if (checkParameter($values["tso"])) {
- // Compose JSON response.
- $response['id'] = $clientid;
- $response['ip'] = $clientip;
- $stat = Array();
- preg_match('/\/[A-Z]*;/', $values["tso"], $stat);
- // Check if data exists.
- 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));
- if (empty($result[0]['data'])) {
- // Client is off.
- $response['status'] = $status['OFF'];
- } else {
- // Get status and session data.
- $data = json_decode($result[0]['data']);
- if (isset($status[$data->status])) {
- $response['status'] = $status[$data->status];
- $response['loggedin'] = $data->loggedin;
+ foreach (explode(";", $values["tso"]) as $data) {
+ if (!empty($data)) {
+ list($clip, $clst) = explode("/", $data);
+ if ($clst != "OFF") {
+ // Update current status.
+ $stat[$clip] = $status[$clst];
}
}
- } else {
- $response['status'] = $status[substr($stat[0], 1, 3)];
}
- if (empty($response['status'])) {
- $response['status'] = "unknown";
+ }
+ // Prepare request to new OGAgent for OSes.
+ foreach ($stat as $ip => $st) {
+ if ($st == "off") {
+ $urls[$ip] = "https://$ip:8000/opengnsys/status";
+ }
+ }
+ // Send request to OGAgents.
+ if (isset($urls)) {
+ $result = multiRequest($urls);
+ }
+ // Parse responses.
+ reset($urls);
+ foreach ($result as $res) {
+ if (!empty($res['data'])) {
+ // Get status and session data.
+ $ip = key($urls);
+ $data = json_decode($res['data']);
+ if (@isset($status[$data->status])) {
+ $stat[$ip] = $status[$data->status];
+ $logged[$ip] = $data->loggedin;
+ } else {
+ $stat[$ip] = $status['UNK'];
+ }
+ }
+ unset($urls[$ip]);
+ }
+ // Compose JSON response.
+ if ($single) {
+ // Single response.
+ $response['id'] = reset($id);
+ $response['ip'] = key($id);
+ $response['status'] = $stat[$ip];
+ empty($logged[$ip]) || $response['loggedin'] = $logged[$ip];
+ } else {
+ // Multiple responses.
+ foreach ($stat as $ip => $st) {
+ $tmp = Array();
+ $tmp['id'] = $id[$ip];
+ $tmp['ip'] = $ip;
+ $tmp['status'] = $stat[$ip];
+ empty($logged[$ip]) || $tmp['loggedin'] = $logged[$ip];
+ array_push($response, $tmp);
}
- jsonResponse(200, $response);
}
+ jsonResponse(200, $response);
} else {
// Access error.
$response['message'] = "Cannot access to OpenGnsys server";
@@ -733,8 +775,7 @@ EOD;
}
}
$rs->Cerrar();
- }
-);
+}
/**