mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 01:54:49 +00:00
firmware: show license in packages/plugins; closes #1220
This commit is contained in:
parent
c3e8468518
commit
8b61365fa6
1
plist
1
plist
@ -556,6 +556,7 @@
|
||||
/usr/local/opnsense/scripts/firmware/hotfix.sh
|
||||
/usr/local/opnsense/scripts/firmware/install.sh
|
||||
/usr/local/opnsense/scripts/firmware/launcher.sh
|
||||
/usr/local/opnsense/scripts/firmware/license.sh
|
||||
/usr/local/opnsense/scripts/firmware/lock.sh
|
||||
/usr/local/opnsense/scripts/firmware/reinstall.sh
|
||||
/usr/local/opnsense/scripts/firmware/remove.sh
|
||||
|
||||
@ -183,6 +183,34 @@ class FirmwareController extends ApiControllerBase
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve specific license for package in text format
|
||||
* @param string $package package to retrieve
|
||||
* @return array with all possible licenses
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function licenseAction($package)
|
||||
{
|
||||
$this->sessionClose(); // long running action, close session
|
||||
$backend = new Backend();
|
||||
$response = array();
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
// sanitize package name
|
||||
$filter = new \Phalcon\Filter();
|
||||
$filter->add('scrub', function ($value) {
|
||||
return preg_replace('/[^0-9a-zA-Z]/', '', $value);
|
||||
});
|
||||
$package = $filter->sanitize($package, 'scrub');
|
||||
$text = trim($backend->configdRun(sprintf('firmware license %s', $package)));
|
||||
if (!empty($text)) {
|
||||
$response['license'] = $text;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* perform reboot
|
||||
* @return array status
|
||||
@ -428,7 +456,7 @@ class FirmwareController extends ApiControllerBase
|
||||
{
|
||||
$this->sessionClose(); // long running action, close session
|
||||
|
||||
$keys = array('name', 'version', 'comment', 'flatsize', 'locked');
|
||||
$keys = array('name', 'version', 'comment', 'flatsize', 'locked', 'license');
|
||||
$backend = new Backend();
|
||||
$response = array();
|
||||
|
||||
|
||||
@ -115,6 +115,30 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* read license from backend
|
||||
*/
|
||||
function license(package)
|
||||
{
|
||||
ajaxCall('/api/core/firmware/license/' + package, {}, function (data, status) {
|
||||
var license = "{{ lang._('Sorry, the package does not have an associated license file.') }}";
|
||||
if (data['license'] != undefined) {
|
||||
license = data['license'];
|
||||
}
|
||||
BootstrapDialog.show({
|
||||
type:BootstrapDialog.TYPE_INFO,
|
||||
title: "{{ lang._('License details') }}",
|
||||
message: license,
|
||||
buttons: [{
|
||||
label: "{{ lang._('Close') }}",
|
||||
action: function(dialogRef){
|
||||
dialogRef.close();
|
||||
}
|
||||
}]
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* read changelog from backend
|
||||
*/
|
||||
@ -246,10 +270,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
$("#packageslist").html("<tr><th>{{ lang._('Name') }}</th>" +
|
||||
"<th>{{ lang._('Version') }}</th><th>{{ lang._('Size') }}</th>" +
|
||||
"<th>{{ lang._('Comment') }}</th><th></th></tr>");
|
||||
"<th>{{ lang._('License') }}</th><th>{{ lang._('Comment') }}</th><th></th></tr>");
|
||||
$("#pluginlist").html("<tr><th>{{ lang._('Name') }}</th>" +
|
||||
"<th>{{ lang._('Version') }}</th><th>{{ lang._('Size') }}</th>" +
|
||||
"<th>{{ lang._('Comment') }}</th><th></th></tr>");
|
||||
"<th>{{ lang._('License') }}</th><th>{{ lang._('Comment') }}</th><th></th></tr>");
|
||||
|
||||
var local_count = 0;
|
||||
var remote_count = 0;
|
||||
@ -268,8 +292,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
'<td>' + row['name'] + '</td>' +
|
||||
'<td>' + row['version'] + '</td>' +
|
||||
'<td>' + row['flatsize'] + '</td>' +
|
||||
'<td>' + row['license'] + '</td>' +
|
||||
'<td>' + row['comment'] + '</td>' +
|
||||
'<td>' +
|
||||
'<button class="btn btn-default btn-xs act_license" data-package="' + row['name'] + '" ' +
|
||||
' data-toggle="tooltip" title="View ' + row['name'] + ' license">' +
|
||||
'<span class="fa fa-balance-scale"></span></button> ' +
|
||||
'<button class="btn btn-default btn-xs act_reinstall" data-package="' + row['name'] + '" ' +
|
||||
' data-toggle="tooltip" title="Reinstall ' + row['name'] + '">' +
|
||||
'<span class="fa fa-recycle"></span></button> ' + (row['locked'] === '1' ?
|
||||
@ -299,8 +327,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
'<tr>' + '<td>' + row['name'] + orphaned_text + '</td>' +
|
||||
'<td>' + row['version'] + '</td>' +
|
||||
'<td>' + row['flatsize'] + '</td>' +
|
||||
'<td>' + row['license'] + '</td>' +
|
||||
'<td>' + row['comment'] + '</td>' +
|
||||
'<td>' + (row['installed'] == "1" ?
|
||||
'<td><button class="btn btn-default btn-xs act_license" data-package="' + row['name'] + '" ' +
|
||||
' data-toggle="tooltip" title="View ' + row['name'] + ' license">' +
|
||||
'<span class="fa fa-balance-scale"></span></button> ' +
|
||||
(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">' +
|
||||
@ -373,6 +405,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
event.preventDefault();
|
||||
changelog($(this).data('version'));
|
||||
});
|
||||
$(".act_license").click(function(event) {
|
||||
event.preventDefault();
|
||||
license($(this).data('package'));
|
||||
});
|
||||
// attach tooltip to generated buttons
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
|
||||
37
src/opnsense/scripts/firmware/license.sh
Executable file
37
src/opnsense/scripts/firmware/license.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (c) 2016 Franco Fichtner <franco@opnsense.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
|
||||
LICENSEDIR="/usr/local/share/licenses"
|
||||
|
||||
PACKAGE=${1}
|
||||
|
||||
LICENSES=$(pkg query %L ${PACKAGE})
|
||||
VERSION=$(pkg query %v ${PACKAGE})
|
||||
|
||||
if [ -f "${LICENSEDIR}/${PACKAGE}-${VERSION}/${LICENSES}" ]; then
|
||||
cat "${LICENSEDIR}/${PACKAGE}-${VERSION}/${LICENSES}"
|
||||
fi
|
||||
@ -29,6 +29,12 @@ parameters:%s
|
||||
type:script_output
|
||||
message:Viewing changelog for version %s
|
||||
|
||||
[license]
|
||||
command:/usr/local/opnsense/scripts/firmware/license.sh
|
||||
parameters:%s
|
||||
type:script_output
|
||||
message:Viewing license for %s
|
||||
|
||||
[running]
|
||||
command:/usr/local/opnsense/scripts/firmware/running.sh
|
||||
parameters:
|
||||
@ -84,13 +90,13 @@ type:script_output
|
||||
message:retrieve upgrade progress status
|
||||
|
||||
[local]
|
||||
command:pkg query "%n|||%v|||%c|||%sh|||%k"
|
||||
command:pkg query "%n|||%v|||%c|||%sh|||%k|||%L"
|
||||
parameters:
|
||||
type:script_output
|
||||
message:view local packages
|
||||
|
||||
[remote]
|
||||
command: pkg rquery "%n|||%v|||%c|||%sh|||0"
|
||||
command: pkg rquery "%n|||%v|||%c|||%sh|||0|||%L"
|
||||
parameters:
|
||||
type:script_output
|
||||
message:view remote packages
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user