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
/**
* Copyright (C) 2015 Deciso B.V.
*
......@@ -26,6 +27,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\Core\Api;
use \OPNsense\Base\ApiControllerBase;
......@@ -143,37 +145,25 @@ class FirmwareController extends ApiControllerBase
{
$this->sessionClose(); // long running action, close session
$response = array('local' => array(), 'remote' => array());
$keys = array('name', 'version', 'comment', 'flatsize');
$backend = new Backend();
$remote = $backend->configdRun('firmware remote');
$local = $backend->configdRun('firmware local');
/*
* pkg(8) returns malformed json by simply outputting each
* indivudual package json block... fix it up for now.
*/
$local = str_replace("\n}\n", "\n},\n", trim($local));
$local = json_decode('[' . $local . ']', true);
if ($local != null) {
$keep = array('name', 'version', 'comment', 'www', 'flatsize', 'licenses', 'desc', 'categories');
foreach ($local as $infos) {
$stripped = array();
foreach ($infos as $key => $info) {
if (in_array($key, $keep)) {
$stripped[$key] = $info;
$response = array();
/* package infos are flat lists with 3 pipes as delimiter */
foreach (array('local', 'remote') as $type) {
$current = $backend->configdRun("firmware ${type}");
$current = explode("\n", trim($current));
$response[$type] = array();
foreach ($current as $line) {
$expanded = explode('|||', $line);
$translated = array();
$index = 0;
foreach ($keys as $key) {
$translated[$key] = $expanded[$index++];
}
$response[$type][] = $translated;
}
}
$response['local'][] = $stripped;
}
}
/* 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;
}
......
......@@ -174,10 +174,15 @@ POSSIBILITY OF SUCH DAMAGE.
$('#packageslist').empty();
ajaxGet('/api/core/firmware/info', {}, function (data, status) {
$("#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) {
$('#packageslist').append('<tr><td>'+row['name']+'</td>' +
"<td>"+row['version']+"</td><td>"+row['comment']+"</td></tr>");
$('#packageslist').append('<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
message:retrieve upgrade progress status
[local]
command:pkg info --raw --raw-format json --all
command:pkg query "%n|||%v|||%c|||%sh"
parameters:
type:script_output
message:view local packages
[remote]
command: pkg rquery %n
command: pkg rquery "%n|||%v|||%c|||%sh"
parameters:
type:script_output
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