Commit edb7b97d authored by Franco Fichtner's avatar Franco Fichtner

firmware: plugin/package listing rework

o packages converted away from local/remote split (installed/provided)
o special plugins list to allow intelligent middle ware handling
o os(priv) on disk is shown even if not on remote (orphaned)
o -devel supports ospriv install from remote
parent 76986c0a
......@@ -442,11 +442,25 @@ class FirmwareController extends ApiControllerBase
$backend = new Backend();
$response = array();
/* allows us to select UI features based on product state */
$response['product_version'] = trim(file_get_contents('/usr/local/opnsense/version/opnsense'));
$response['product_name'] = trim(file_get_contents('/usr/local/opnsense/version/opnsense.name'));
$devel = explode('-', $response['product_name']);
$devel = count($devel) == 2 ? $devel[1] == 'devel' : false;
/* need both remote and local, create array earlier */
$packages = array();
$plugins = array();
/* package infos are flat lists with 3 pipes as delimiter */
foreach (array('local', 'remote') as $type) {
foreach (array('remote', 'local') as $type) {
$current = $backend->configdRun("firmware ${type}");
$current = explode("\n", trim($current));
/* XXX remove this when 17.1 is out */
$response[$type] = array();
foreach ($current as $line) {
$expanded = explode('|||', $line);
$translated = array();
......@@ -457,14 +471,53 @@ class FirmwareController extends ApiControllerBase
foreach ($keys as $key) {
$translated[$key] = $expanded[$index++];
}
/* XXX remove this when 17.1 is out */
$response[$type][] = $translated;
/* mark remote packages as "provided", local as "installed" */
$translated['provided'] = $type == 'remote' ? "1" : "0";
$translated['installed'] = $type == 'local' ? "1" : "0";
if (isset($packages[$translated['name']])) {
/* local iteration, mark package provided */
$translated['provided'] = "1";
}
$packages[$translated['name']] = $translated;
/* figure out local and remote plugins */
$plugin = explode('-', $translated['name']);
if (count($plugin)) {
if ($plugin[0] == 'os' || ($type == 'local' && $plugin[0] == 'ospriv') ||
($devel && $type == 'remote' && $plugin[0] == 'ospriv')) {
$plugins[$translated['name']] = $translated;
}
}
}
/* XXX remove this when 17.1 is out */
usort($response[$type], function ($a, $b) {
return strnatcasecmp($a['name'], $b['name']);
});
}
uksort($packages, function ($a, $b) {
return strnatcasecmp($a, $b);
});
$response['package'] = array();
foreach ($packages as $package) {
$response['package'][] = $package;
}
uksort($plugins, function ($a, $b) {
return strnatcasecmp($a, $b);
});
$response['plugin'] = array();
foreach ($plugins as $plugin) {
$response['plugin'][] = $plugin;
}
/* also pull in changelogs from here */
$changelogs = json_decode(trim($backend->configdRun('firmware changelog list')), true);
if ($changelogs == null) {
......@@ -483,9 +536,6 @@ class FirmwareController extends ApiControllerBase
$response['changelog'] = $changelogs;
/* allows us to match the version against the specific changelog */
$response['product_version'] = file_get_contents('/usr/local/opnsense/version/opnsense');
return $response;
}
......
......@@ -250,7 +250,18 @@ POSSIBILITY OF SUCH DAMAGE.
"<th>{{ lang._('Version') }}</th><th>{{ lang._('Size') }}</th>" +
"<th>{{ lang._('Comment') }}</th><th></th></tr>");
$.each(data['local'], function(index, row) {
var local_count = 0;
var remote_count = 0;
$.each(data['package'], function(index, row) {
if (row['provided'] == "1") {
remote_count += 1;
}
if (row['installed'] == "1") {
local_count += 1;
} else {
return 1;
}
$('#packageslist').append(
'<tr>' +
'<td>' + row['name'] + '</td>' +
......@@ -270,28 +281,25 @@ POSSIBILITY OF SUCH DAMAGE.
) + '</td>' +
'</tr>'
);
if (!row['name'].match(/^os-/g)) {
return 1;
}
installed[row['name']] = row;
});
if (!data['local'].length) {
if (local_count == 0) {
$('#packageslist').append(
'<tr><td colspan=5>{{ lang._('No packages were found on your system. Please call for help.') }}</td></tr>'
);
}
$.each(data['remote'], function(index, row) {
if (!row['name'].match(/^os-/g)) {
return 1;
$.each(data['plugin'], function(index, row) {
orphaned_text = '';
if (row['provided'] == "0") {
orphaned_text = ' ({{ lang._('orphaned') }})';
}
$('#pluginlist').append(
'<tr>' + '<td>' + row['name'] + '</td>' +
'<tr>' + '<td>' + row['name'] + orphaned_text + '</td>' +
'<td>' + row['version'] + '</td>' +
'<td>' + row['flatsize'] + '</td>' +
'<td>' + row['comment'] + '</td>' +
'<td>' + (row['name'] in installed ?
'<td>' + (row['installed'] == "1" ?
'<button class="btn btn-default btn-xs act_remove" data-package="' + row['name'] + '" '+
' data-toggle="tooltip" title="Remove ' + row['name'] + '">' +
'<span class="fa fa-trash">' +
......@@ -304,7 +312,7 @@ POSSIBILITY OF SUCH DAMAGE.
);
});
if (!data['remote'].length) {
if (remote_count == 0) {
$('#pluginlist').append(
'<tr><td colspan=5>{{ lang._('Check for updates to view available plugins.') }}</td></tr>'
);
......
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