Skip to content

Commit

Permalink
#992 REST route /ous/:ouid/labs/:labid/clients/:clntid/init:
Browse files Browse the repository at this point in the history
     Fixes that include global variables, required to add the operating system startup to the action queue.
     This route is defined in swagger.
  • Loading branch information
irinagomez committed Feb 23, 2021
1 parent f7e9f6f commit 69fd9c1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
29 changes: 29 additions & 0 deletions admin/WebConsole/rest/opengnsys-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,35 @@ paths:
- server
- client
- remotepc
/ous/{ouid}/labs/{labid}/clients/{clientid}/init:
post:
description: Send an init operation to a client with an image installed.
parameters:
- $ref: "#/parameters/ouParam"
- $ref: "#/parameters/labParam"
- $ref: "#/parameters/clientParam"
- name: data
in: body
description: Image identificator
required: true
schema:
type: object
properties:
image:
description: Operating System Image Identifier
type: integer
format: int64
minimum: 0
required: [ image ]
responses:
"200":
description: Successful response
security:
- apikey: []
tags:
- server
- client
- remotepc
/ous/{ouid}/labs/{labid}/clients/{clientid}/session:
post:
description: Record session data for a client
Expand Down
10 changes: 9 additions & 1 deletion admin/WebConsole/rest/remotepc.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,12 @@ function($ouid, $labid, $clntid) use ($app) {
function($ouid, $labid, $clntid) use ($app) {
global $cmd;
global $userid;
global $AMBITO_ORDENADORES;
global $EJECUCION_COMANDO;
global $ACCION_INICIADA;
global $ACCION_FINALIZADA;
global $ACCION_SINRESULTADO;
global $ACCION_FALLIDA;

if ($app->settings['debug'])
writeRemotepcLog("{$app->request()->getResourceUri()}: Init.");
Expand All @@ -587,6 +593,7 @@ function($ouid, $labid, $clntid) use ($app) {
// Reading POST parameters in JSON format.
$input = json_decode($app->request()->getBody());
$imageid = $input->image ?? 0;
$opts = Array('options' => Array('min_range' => 1)); // Check for int>0
if (filter_var($imageid, FILTER_VALIDATE_INT, $opts) === false) {
throw new Exception("Image id. must be positive integer");
}
Expand All @@ -601,7 +608,7 @@ function($ouid, $labid, $clntid) use ($app) {

// Select data to init a session.
$cmd->texto = <<<EOD
SELECT adm.idusuario, ordenadores.ip, ordenadores.mac, ordenadores.mascara, ordenadores.agentkey,
SELECT adm.idusuario, ordenadores.idordenador, ordenadores.ip, ordenadores.mac, ordenadores.mascara, ordenadores.agentkey,
par.numdisk, par.numpar, repo.ip AS repoip, repo.apikey AS repokey
FROM ordenadores
JOIN aulas USING(idaula)
Expand Down Expand Up @@ -652,6 +659,7 @@ function($ouid, $labid, $clntid) use ($app) {
$result = multiRequest($repo);
}
// Create an init session on opertions queue.
$timestamp = time();
$cmd->texto = <<<EOD
INSERT INTO acciones
SET tipoaccion=$EJECUCION_COMANDO,
Expand Down

0 comments on commit 69fd9c1

Please sign in to comment.