summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2019-01-30 13:27:24 +0100
committerRamón M. Gómez <ramongomez@us.es>2019-01-30 13:57:27 +0100
commita5f7c304cead8b1fa98c6a8f84c0817213c318b5 (patch)
tree338aef2b9e3e18c1382279128bf811952be0d392
parent0ad92e4af4c88adffb01c9e3ff25cf07ec7e1319 (diff)
#892: extract ogAdmServer data from the configuration file
-rw-r--r--admin/WebConsole/rest/repository.php64
1 files changed, 36 insertions, 28 deletions
diff --git a/admin/WebConsole/rest/repository.php b/admin/WebConsole/rest/repository.php
index 062aae28..bc2fdec6 100644
--- a/admin/WebConsole/rest/repository.php
+++ b/admin/WebConsole/rest/repository.php
@@ -191,36 +191,44 @@ $app->get('/repository/image(/:ouname)/:imagename(/)', 'validateRepositoryApiKey
*/
$app->post('/repository/poweron', 'validateRepositoryApiKey',
function() use($app) {
- // The macs parameter must come in the post (JSON object with array of MACs)
- $data = json_decode($app->request()->getBody());
- if(empty($data->macs)){
- // Print error message.
- $response['message'] = 'Required param macs not found';
- jsonResponse(400, $response);
- }
- else{
- // Execute WakeOnLan command with ogAdmServer
- $strMacs = implode(';', $data->macs);
- $strMacs = str_replace(':', '', $strMacs);
- $strIps = implode(';', $data->ips);
- $params="nfn=Arrancar" . chr(13) . "mac=" . $strMacs . chr(13) . "iph=" . $strIps . chr(13) . "mar=" . $data->mar .
- chr(13);
- $shidra=new SockHidra("127.0.0.1", "2008");
- if ($shidra->conectar()) { // The connection to the hydra server has been established
- $resul=$shidra->envia_comando($params);
- if($resul) {
- $frame=$shidra->recibe_respuesta();
- $hlonprm=hexdec(substr($frame, LENHEAD, LENHEXPRM));
- $params=substr($frame, LENHEAD + LENHEXPRM, $hlonprm);
- $ParamsValue=extrae_parametros($params, chr(13), '=');
- $resul=$ParamsValue["res"];
- jsonResponse(200, $resul);
- } else {
- $response['message'] = 'Error in ogAdmServer';
- jsonResponse(404, $response);
+ // Fetch repository token from ogAdmServer.cfg configuration file.
+ @$confFile = parse_ini_file('../../etc/ogAdmServer.cfg', 'r');
+ if ($confFile) {
+ // The macs parameter must come in the post (JSON object with array of MACs)
+ $data = json_decode($app->request()->getBody());
+ if (empty($data->macs)) {
+ // Print error message.
+ $response['message'] = 'Required param macs not found';
+ jsonResponse(400, $response);
+ } else {
+ // Execute WakeOnLan command with ogAdmServer
+ $strMacs = implode(';', $data->macs);
+ $strMacs = str_replace(':', '', $strMacs);
+ $strIps = implode(';', $data->ips);
+ $params="nfn=Arrancar" . chr(13) . "mac=" . $strMacs . chr(13) . "iph=" . $strIps . chr(13) .
+ "mar=" . $data->mar . chr(13);
+ $shidra=new SockHidra($confFile['ServidorAdm'], $confFile['PUERTO']);
+ if ($shidra->conectar()) { // The connection to the hydra server has been established
+ $resul=$shidra->envia_comando($params);
+ if($resul) {
+ $frame=$shidra->recibe_respuesta();
+ $hlonprm=hexdec(substr($frame, LENHEAD, LENHEXPRM));
+ $params=substr($frame, LENHEAD + LENHEXPRM, $hlonprm);
+ $ParamsValue=extrae_parametros($params, chr(13), '=');
+ $resul=$ParamsValue["res"];
+ jsonResponse(200, $resul);
+ } else {
+ $response['message'] = 'Error in ogAdmServer';
+ jsonResponse(404, $response);
+ }
+ $shidra->desconectar();
}
- $shidra->desconectar();
}
+ } else {
+ // Cannot access configuration file.
+ $response['message'] = "An error occurred, please try again";
+ jsonResponse(500, $response);
+ $app->stop();
}
}
);