Commit 99516c07 authored by Franco Fichtner's avatar Franco Fichtner

firmware: improve package info API output

o Convert pkg-info to pkg-query.
o Thin out unused fields.
o Add flatsize to GUI.
o Way faster.  :D
parent 64e47c0a
<?php <?php
/** /**
* Copyright (C) 2015 Deciso B.V. * Copyright (C) 2015 Deciso B.V.
* *
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
namespace OPNsense\Core\Api; namespace OPNsense\Core\Api;
use \OPNsense\Base\ApiControllerBase; use \OPNsense\Base\ApiControllerBase;
...@@ -143,38 +145,26 @@ class FirmwareController extends ApiControllerBase ...@@ -143,38 +145,26 @@ class FirmwareController extends ApiControllerBase
{ {
$this->sessionClose(); // long running action, close session $this->sessionClose(); // long running action, close session
$response = array('local' => array(), 'remote' => array()); $keys = array('name', 'version', 'comment', 'flatsize');
$backend = new Backend(); $backend = new Backend();
$remote = $backend->configdRun('firmware remote'); $response = array();
$local = $backend->configdRun('firmware local');
/* package infos are flat lists with 3 pipes as delimiter */
/* foreach (array('local', 'remote') as $type) {
* pkg(8) returns malformed json by simply outputting each $current = $backend->configdRun("firmware ${type}");
* indivudual package json block... fix it up for now. $current = explode("\n", trim($current));
*/ $response[$type] = array();
$local = str_replace("\n}\n", "\n},\n", trim($local)); foreach ($current as $line) {
$local = json_decode('[' . $local . ']', true); $expanded = explode('|||', $line);
if ($local != null) { $translated = array();
$keep = array('name', 'version', 'comment', 'www', 'flatsize', 'licenses', 'desc', 'categories'); $index = 0;
foreach ($local as $infos) { foreach ($keys as $key) {
$stripped = array(); $translated[$key] = $expanded[$index++];
foreach ($infos as $key => $info) {
if (in_array($key, $keep)) {
$stripped[$key] = $info;
}
} }
$response['local'][] = $stripped; $response[$type][] = $translated;
} }
} }
/* Remote packages are only a flat list */
$remote = explode("\n", trim($remote));
foreach ($remote as $name) {
/* keep layout compatible with the above */
$response['remote'][] = array('name' => $name);
}
return $response; return $response;
} }
} }
...@@ -174,10 +174,15 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -174,10 +174,15 @@ POSSIBILITY OF SUCH DAMAGE.
$('#packageslist').empty(); $('#packageslist').empty();
ajaxGet('/api/core/firmware/info', {}, function (data, status) { ajaxGet('/api/core/firmware/info', {}, function (data, status) {
$("#packageslist").html("<tr><th>{{ lang._('Name') }}</th>" + $("#packageslist").html("<tr><th>{{ lang._('Name') }}</th>" +
"<th>{{ lang._('Version') }}</th><th>{{ lang._('Comment') }}</th></tr>"); "<th>{{ lang._('Version') }}</th><th>{{ lang._('Size') }}</th>" +
"<th>{{ lang._('Comment') }}</th></tr>");
$.each(data['local'], function(index, row) { $.each(data['local'], function(index, row) {
$('#packageslist').append('<tr><td>'+row['name']+'</td>' + $('#packageslist').append('<tr>' +
"<td>"+row['version']+"</td><td>"+row['comment']+"</td></tr>"); '<td>' + row['name'] + '</td>' +
'<td>' + row['version'] + '</td>' +
'<td>' + row['flatsize'] + '</td>' +
'<td>' + row['comment'] + '</td>' +
'</tr>');
}); });
}); });
} }
......
...@@ -17,13 +17,13 @@ type:script_output ...@@ -17,13 +17,13 @@ type:script_output
message:retrieve upgrade progress status message:retrieve upgrade progress status
[local] [local]
command:pkg info --raw --raw-format json --all command:pkg query "%n|||%v|||%c|||%sh"
parameters: parameters:
type:script_output type:script_output
message:view local packages message:view local packages
[remote] [remote]
command: pkg rquery %n command: pkg rquery "%n|||%v|||%c|||%sh"
parameters: parameters:
type:script_output type:script_output
message:view remote packages message:view remote packages
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment