diff options
author | ramon <ramongomez@us.es> | 2017-10-23 08:46:05 +0000 |
---|---|---|
committer | ramon <ramongomez@us.es> | 2017-10-23 08:46:05 +0000 |
commit | e3682263fe9bbf5f64bcc611ee7cc1544cb8ee6e (patch) | |
tree | a051bdd80ad221cb1703d03473b2cfc0ee406cc2 /admin/WebConsole/rest | |
parent | bdee878a87445f8a49fc5a269a703f4255aaa9e4 (diff) |
#708: Nueva ruta REST {{{GET /repository/image/:uo/:imagen}}} para obtener datos de una imagen propia de una UO y adaptar la salida a la documentación.
git-svn-id: https://opengnsys.es/svn/branches/version1.1@5474 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'admin/WebConsole/rest')
-rw-r--r-- | admin/WebConsole/rest/repository.php | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/admin/WebConsole/rest/repository.php b/admin/WebConsole/rest/repository.php index e50c8bdf..fa4ebdc9 100644 --- a/admin/WebConsole/rest/repository.php +++ b/admin/WebConsole/rest/repository.php @@ -131,30 +131,43 @@ $app->get('/repository/images(/)', 'validateRepositoryApiKey', * @param no * @return JSON object with image data. */ -$app->get('/repository/image/:imagename(/)', 'validateRepositoryApiKey', - function($imagename) use ($app) { +$app->get('/repository/image(/:ouname)/:imagename(/)', 'validateRepositoryApiKey', + function($ouname="/", $imagename) use ($app) { + $images = array(); $response = array(); // Search image name in repository information file. $cfgFile = '/opt/opengnsys/etc/repoinfo.json'; $json = json_decode(@file_get_contents($cfgFile), true); $imgPath = @$json['directory']; - foreach ($json['images'] as $img) { + if (empty($ouname) or $ouname == "/") { + // Search in global directory. + $images = @$json['images']; + } else { + // Search in OU directory. + for ($i=0; $i<sizeof(@$json['ous']); $i++) { + if ($json['ous'][$i]['subdir'] == $ouname) { + $images = $json['ous'][$i]['images']; + } + } + } + // Search image. + foreach ($images as $img) { if ($img['name'] == $imagename) { - $response['image'] = $img; - $file = $imgPath."/".($img['type']==="dir" ? $img["name"] : $img["name"].".".$img["type"]); - $response['image']['size'] = @stat($file)['size']; - $response['image']['modified'] = date("Y-m-d H:i:s", @stat($file)['mtime']); - $response['image']['mode'] = substr(decoct(@stat($file)['mode']), -4); + $response = $img; + $file = "$imgPath/$ouname/" . ($img['type']==="dir" ? $img["name"] : $img["name"].".".$img["type"]); + $response['size'] = @stat($file)['size']; + $response['modified'] = date("Y-m-d H:i:s", @stat($file)['mtime']); + $response['mode'] = substr(decoct(@stat($file)['mode']), -4); $backupfile = $file.".ant"; if (file_exists($backupfile)) { - $response['image']['backedup'] = true; - $response['image']['backupsize'] = @stat($backupfile)['size']; + $response['backedup'] = true; + $response['backupsize'] = @stat($backupfile)['size']; } else { - $response['image']['backedup'] = false; + $response['backedup'] = false; } } } - if (isset ($response['image'])) { + if (isset ($response)) { // JSON response. jsonResponse(200, $response); } else { |