mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 01:54:49 +00:00
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
This commit is contained in:
parent
64e47c0a3a
commit
99516c0713
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Deciso B.V.
|
||||
*
|
||||
@ -26,6 +27,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OPNsense\Core\Api;
|
||||
|
||||
use \OPNsense\Base\ApiControllerBase;
|
||||
@ -143,38 +145,26 @@ 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');
|
||||
$response = array();
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
/* 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['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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user