summaryrefslogtreecommitdiffstats
path: root/admin/WebConsole/rest/repository.php
diff options
context:
space:
mode:
Diffstat (limited to 'admin/WebConsole/rest/repository.php')
-rw-r--r--admin/WebConsole/rest/repository.php33
1 files changed, 14 insertions, 19 deletions
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();
}
);
-?>