summaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorramon <ramongomez@us.es>2017-10-19 16:31:41 +0000
committerramon <ramongomez@us.es>2017-10-19 16:31:41 +0000
commitbdee878a87445f8a49fc5a269a703f4255aaa9e4 (patch)
tree3c0dbef2fe566ba8c62833e801c409d11b5095c2 /admin
parent4b82beb20ef10c5f32ce28189711e045e779c9c5 (diff)
#810: Nueva ruta REST {{{GET /repository/image/:nombre}}} para obtener datos de una imagen almacenada en el repositorio.
git-svn-id: https://opengnsys.es/svn/branches/version1.1@5473 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'admin')
-rw-r--r--admin/WebConsole/rest/repository.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/admin/WebConsole/rest/repository.php b/admin/WebConsole/rest/repository.php
index c8288a98..e50c8bdf 100644
--- a/admin/WebConsole/rest/repository.php
+++ b/admin/WebConsole/rest/repository.php
@@ -126,6 +126,48 @@ $app->get('/repository/images(/)', 'validateRepositoryApiKey',
/**
+ * @brief List image data
+ * @note Route: /repository/image/:imagename, Method: GET
+ * @param no
+ * @return JSON object with image data.
+ */
+$app->get('/repository/image/:imagename(/)', 'validateRepositoryApiKey',
+ function($imagename) use ($app) {
+ $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 ($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);
+ $backupfile = $file.".ant";
+ if (file_exists($backupfile)) {
+ $response['image']['backedup'] = true;
+ $response['image']['backupsize'] = @stat($backupfile)['size'];
+ } else {
+ $response['image']['backedup'] = false;
+ }
+ }
+ }
+ if (isset ($response['image'])) {
+ // JSON response.
+ jsonResponse(200, $response);
+ } else {
+ // Print error message.
+ $response['message'] = 'Image not found';
+ jsonResponse(404, $response);
+ }
+ $app->stop();
+ }
+);
+
+
+/**
* @brief Power on a pc or group of pcs with the MAC specified in POST parameters
* @note Route: /poweron, Method: POST
* @param macs OU id.