diff options
Diffstat (limited to 'admin/WebConsole/rest')
-rw-r--r-- | admin/WebConsole/rest/common.php | 3 | ||||
-rw-r--r-- | admin/WebConsole/rest/index.php | 2 | ||||
-rw-r--r-- | admin/WebConsole/rest/ogagent.php | 4 | ||||
-rw-r--r-- | admin/WebConsole/rest/remotepc.php | 22 | ||||
-rw-r--r-- | admin/WebConsole/rest/repository.php | 33 |
5 files changed, 38 insertions, 26 deletions
diff --git a/admin/WebConsole/rest/common.php b/admin/WebConsole/rest/common.php index bc39ced9..d26acc4b 100644 --- a/admin/WebConsole/rest/common.php +++ b/admin/WebConsole/rest/common.php @@ -248,6 +248,7 @@ $app->hook('slim.after', function() use ($app) { * @return JSON object with basic server information (version, services, etc.) */ $app->get('/info', function() { + $hasOglive = false; $response = new \stdClass; // Reading version file. $data = json_decode(@file_get_contents(VERSION_FILE)); @@ -293,4 +294,4 @@ $app->get('/status', function() { jsonResponse(200, $response); } ); -?> + diff --git a/admin/WebConsole/rest/index.php b/admin/WebConsole/rest/index.php index 46957ab6..aa7cd483 100644 --- a/admin/WebConsole/rest/index.php +++ b/admin/WebConsole/rest/index.php @@ -72,4 +72,4 @@ $app->get('/', // Execute REST using Slim. $app->run(); -?> + diff --git a/admin/WebConsole/rest/ogagent.php b/admin/WebConsole/rest/ogagent.php index 6b87b098..be62a8d0 100644 --- a/admin/WebConsole/rest/ogagent.php +++ b/admin/WebConsole/rest/ogagent.php @@ -32,6 +32,7 @@ function writeLog($message = "") { $app->post('/ogagent/started', function() use ($app) { global $cmd; + $secret = ""; $osType = $osVersion = "none"; try { // Reading POST parameters in JSON format. @@ -131,6 +132,7 @@ $app->post('/ogagent/stopped', $app->post('/ogagent/loggedin', function() use ($app) { global $cmd; + $osType = $osVersion = "none"; $redirto = Array(); $result = Array(); @@ -269,4 +271,4 @@ EOD; } ); -?> + diff --git a/admin/WebConsole/rest/remotepc.php b/admin/WebConsole/rest/remotepc.php index 4bf7b6b5..a0d4ea10 100644 --- a/admin/WebConsole/rest/remotepc.php +++ b/admin/WebConsole/rest/remotepc.php @@ -41,6 +41,7 @@ $app->post('/ous/:ouid/images/:imageid/reserve(/)', 'validateApiKey', global $userid; $response = Array(); $ogagent = Array(); + $repo = Array(); if ($app->settings['debug']) writeRemotepcLog($app->request()->getResourceUri(). ": Init."); @@ -83,14 +84,15 @@ $app->post('/ous/:ouid/images/:imageid/reserve(/)', 'validateApiKey', $cmd->texto = <<<EOD SELECT adm.idusuario, entornos.ipserveradm, entornos.portserveradm, ordenadores.idordenador, ordenadores.nombreordenador, ordenadores.ip, - ordenadores.mac, ordenadores.agentkey, ordenadores_particiones.numdisk, - ordenadores_particiones.numpar, aulas.idaula, aulas.idcentro + ordenadores.mac, ordenadores.agentkey, par.numdisk, par.numpar, + aulas.idaula, aulas.idcentro, repo.ip AS repoip, repo.apikey AS repokey FROM entornos, ordenadores JOIN aulas USING(idaula) RIGHT JOIN administradores_centros AS adm USING(idcentro) RIGHT JOIN usuarios USING(idusuario) - RIGHT JOIN ordenadores_particiones USING(idordenador) + RIGHT JOIN ordenadores_particiones AS par USING(idordenador) RIGHT JOIN imagenes USING(idimagen) + RIGHT JOIN repositorios AS repo ON repo.idrepositorio = ordenadores.idrepositorio LEFT JOIN remotepc ON remotepc.id=ordenadores.idordenador WHERE adm.idusuario = '$userid' AND aulas.idcentro = '$ouid' AND aulas.idaula LIKE '$labid' AND aulas.inremotepc = 1 @@ -116,6 +118,8 @@ EOD; $part = $rs->campos["numpar"]; $labid = $rs->campos["idaula"]; $ouid = $rs->campos["idcentro"]; + $repoip = $rs->campos["repoip"]; + $repokey = $rs->campos["repokey"]; // Check client's status. $ogagent[$clntip]['url'] = "https://$clntip:8000/opengnsys/status"; if ($app->settings['debug']) @@ -132,6 +136,16 @@ EOD; if ($app->settings['debug']) writeRemotepcLog($app->request()->getResourceUri(). "Send Boot command to ogAdmClient, ido=$clntid,iph=$clntip,mac=$clntmac."); sendCommand($serverip, $serverport, $reqframe, $values); + // Send WOL command to client repository. + $repo[$repoip]['url'] = "https://$repoip/opengnsys/rest/repository/poweron"; + $repo[$repoip]['header'] = Array("Authorization: ".$repokey); + $repo[$repoip]['post'] = '{"macs": ["'.$clntmac.'"], "ips": ["'.$clntip.'"]}'; + if ($app->settings['debug']) + writeRemotepcLog($app->request()->getResourceUri(). "Send Boot command to repo: repo=$repoip, ip=$clntip,mac=$clntmac."); + $result = multiRequest($repo); + // ... (check response) + //if ($result[$repoip]['code'] != 200) { + // ... } else { // Client is on, send a rieboot command to its OGAgent. $ogagent[$clntip]['url'] = "https://$clntip:8000/opengnsys/reboot"; @@ -551,4 +565,4 @@ EOD; } ); -?> + diff --git a/admin/WebConsole/rest/repository.php b/admin/WebConsole/rest/repository.php index 7ac6e88e..736cc1c2 100644 --- a/admin/WebConsole/rest/repository.php +++ b/admin/WebConsole/rest/repository.php @@ -10,6 +10,7 @@ * @date 2016-04-06 */ + // Auxiliar functions. /** * @brief Validate API key included in "Authorization" HTTP header. @@ -23,8 +24,8 @@ function validateRepositoryApiKey() { @$apikey = htmlspecialchars(function_exists('apache_request_headers') ? apache_request_headers()['Authorization'] : $_SERVER['HTTP_AUTHORIZATION']); if (isset($apikey)) { // fetch repository token from ogAdmRepo.cfg configuration file. - @$confFile = parse_ini_file('../../etc/ogAdmRepo.cfg', 'r'); - if ($confFile) { + @$confFile = parse_ini_file(__DIR__ . '/../../etc/ogAdmRepo.cfg', 'r'); + if (isset($confFile)) { if(@strcmp($apikey, $confFile['ApiToken']) == 0) { // Credentials OK. return true; @@ -184,32 +185,26 @@ $app->get('/repository/image(/:ouname)/:imagename(/)', 'validateRepositoryApiKey */ $app->post('/repository/poweron', 'validateRepositoryApiKey', function() use($app) { - // Debe venir el parametro macs en el post (objeto JSON con array de MACs) + // The macs parameter must come in the post (JSON object with array of MACs) $data = json_decode($app->request()->getBody()); - if(empty($data->macs)){ + if (empty($data->macs)) { // Print error message. $response['message'] = 'Required param macs not found'; jsonResponse(400, $response); - } - else{ - $strMacs = ""; - foreach($data->macs as $mac){ - $strMacs .= " ".$mac; - } - // Ejecutar comando wakeonlan, debe estar disponible en el sistema operativo - if(commandExist("wakeonlan")){ - $response["output"] = "Executing wakeonlan ".trim($strMacs)."\n"; - $response["output"] .= shell_exec("wakeonlan ".trim($strMacs)); - // Comprobar si el comando se ejecutórrectamente - jsonResponse(200, $response); - } - else{ + } else { + // Execute local wakeonlan command (may be installed) + if(commandExist("wakeonlan")) { + $strMacs = trim(implode(' ', $data->macs)); + $response["output"] = "Executing wakeonlan ".$strMacs."\n"; + $response["output"] .= shell_exec("wakeonlan ".$strMacs); + jsonResponse(200, $response); + } else { // Print error message. $response['message'] = 'Wakeonlan command not found in this repository'; jsonResponse(404, $response); } } + $app->stop(); } ); -?> |