Commit 569d0c33 authored by Franco Fichtner's avatar Franco Fichtner

firmware: complete plugin/package management feature

(cherry picked from commit bcc6d757)
parent 20a242ee
......@@ -100,7 +100,7 @@ class FirmwareController extends ApiControllerBase
public function upgradeAction()
{
$backend = new Backend();
$response =array();
$response = array();
if ($this->request->hasPost("upgrade")) {
$response['status'] = 'ok';
if ($this->request->getPost("upgrade") == "pkg") {
......@@ -125,7 +125,7 @@ class FirmwareController extends ApiControllerBase
public function reinstallAction($pkg_name)
{
$backend = new Backend();
$response =array();
$response = array();
if ($this->request->isPost()) {
$response['status'] = 'ok';
......@@ -144,6 +144,118 @@ class FirmwareController extends ApiControllerBase
return $response;
}
/**
* install package
* @param string $pkg_name package name to install
* @return array status
* @throws \Exception
*/
public function installAction($pkg_name)
{
$backend = new Backend();
$response = array();
if ($this->request->isPost()) {
$response['status'] = 'ok';
// sanitize package name
$filter = new \Phalcon\Filter();
$filter->add('pkgname', function($value) {
return preg_replace('/[^0-9a-zA-Z-_]/', '', $value);
});
$pkg_name = $filter->sanitize($pkg_name, "pkgname");
// execute action
$response['msg_uuid'] = trim($backend->configdpRun("firmware install", array($pkg_name), true));
} else {
$response['status'] = 'failure';
}
return $response;
}
/**
* remove package
* @param string $pkg_name package name to remove
* @return array status
* @throws \Exception
*/
public function removeAction($pkg_name)
{
$backend = new Backend();
$response =array();
if ($this->request->isPost()) {
$response['status'] = 'ok';
// sanitize package name
$filter = new \Phalcon\Filter();
$filter->add('pkgname', function($value) {
return preg_replace('/[^0-9a-zA-Z-_]/', '', $value);
});
$pkg_name = $filter->sanitize($pkg_name, "pkgname");
// execute action
$response['msg_uuid'] = trim($backend->configdpRun("firmware remove", array($pkg_name), true));
} else {
$response['status'] = 'failure';
}
return $response;
}
/**
* lock package
* @param string $pkg_name package name to lock
* @return array status
* @throws \Exception
*/
public function lockAction($pkg_name)
{
$backend = new Backend();
$response =array();
if ($this->request->isPost()) {
$response['status'] = 'ok';
// sanitize package name
$filter = new \Phalcon\Filter();
$filter->add('pkgname', function($value) {
return preg_replace('/[^0-9a-zA-Z-_]/', '', $value);
});
$pkg_name = $filter->sanitize($pkg_name, "pkgname");
// execute action
$response['msg_uuid'] = trim($backend->configdpRun("firmware lock", array($pkg_name), true));
} else {
$response['status'] = 'failure';
}
return $response;
}
/**
* unlock package
* @param string $pkg_name package name to unlock
* @return array status
* @throws \Exception
*/
public function unlockAction($pkg_name)
{
$backend = new Backend();
$response =array();
if ($this->request->isPost()) {
$response['status'] = 'ok';
// sanitize package name
$filter = new \Phalcon\Filter();
$filter->add('pkgname', function($value) {
return preg_replace('/[^0-9a-zA-Z-_]/', '', $value);
});
$pkg_name = $filter->sanitize($pkg_name, "pkgname");
// execute action
$response['msg_uuid'] = trim($backend->configdpRun("firmware unlock", array($pkg_name), true));
} else {
$response['status'] = 'failure';
}
return $response;
}
/**
* retrieve upgrade status (and log file of current process)
*/
......
......@@ -92,14 +92,14 @@ POSSIBILITY OF SUCH DAMAGE.
}
/**
* perform package reinstall, install poller to update status
* perform package action, install poller to update status
*/
function reinstall(pkg_name)
function action(pkg_act, pkg_name)
{
$('#progresstab > a').tab('show');
$('#updatestatus').html("{{ lang._('Reinstalling... (do not leave this page while reinstall is in progress)') }}");
$('#updatestatus').html("{{ lang._('Executing... (do not leave this page while execute is in progress)') }}");
ajaxCall('/api/core/firmware/reinstall/'+pkg_name,{},function() {
ajaxCall('/api/core/firmware/'+pkg_act+'/'+pkg_name,{},function() {
$('#updatelist').empty();
setTimeout(trackStatus, 500);
});
......@@ -192,10 +192,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>{{ lang._('Action') }}</th></tr>");
"<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>{{ lang._('Action') }}</th></tr>");
"<th>{{ lang._('Comment') }}</th><th></th></tr>");
$.each(data['local'], function(index, row) {
$('#packageslist').append(
......@@ -205,9 +205,16 @@ POSSIBILITY OF SUCH DAMAGE.
'<td>' + row['flatsize'] + '</td>' +
'<td>' + row['comment'] + '</td>' +
'<td>' +
'<button class="btn btn-default btn-xs act_reinstall" data-package="' + row['name'] + '">reinstall</button>'+
', ' + (row['locked'] === '1' ? 'unlock' : 'lock') +
'</td>' +
'<button class="btn btn-default btn-xs act_reinstall" data-package="' + row['name'] + '">' +
'<span data-toggle="tooltip" data-placement="left" title="Reinstall ' + row['name'] + '" class="fa fa-recycle">' +
'</span></button> ' + (row['locked'] === '1' ?
'<button class="btn btn-default btn-xs act_unlock" data-package="' + row['name'] + '">' +
'<span data-toggle="tooltip" data-placement="left" title="Unlock ' + row['name'] + '" class="fa fa-lock">' +
'</span></button>' :
'<button class="btn btn-default btn-xs act_lock" data-package="' + row['name'] + '">' +
'<span data-toggle="tooltip" data-placement="left" title="Lock ' + row['name'] + '" class="fa fa-unlock">' +
'</span></button>'
) + '</td>' +
'</tr>'
);
if (!row['name'].match(/^os-/g)) {
......@@ -216,32 +223,54 @@ POSSIBILITY OF SUCH DAMAGE.
installed[row['name']] = row;
});
// link reinstall buttons to action
$(".act_reinstall").click(function(event){
event.preventDefault();
reinstall($(this).data('package'));
});
$.each(data['remote'], function(index, row) {
if (!row['name'].match(/^os-/g)) {
return 1;
}
$('#pluginlist').append(
'<tr>' +
'<td>' + row['name'] + '</td>' +
'<tr>' + '<td>' + row['name'] + '</td>' +
'<td>' + row['version'] + '</td>' +
'<td>' + row['flatsize'] + '</td>' +
'<td>' + row['comment'] + '</td>' +
'<td>' + (row['name'] in installed ? 'deinstall' : 'install') + '</td>' +
'</tr>'
'<td>' + (row['name'] in installed ?
'<button class="btn btn-default btn-xs act_remove" data-package="' + row['name'] + '">' +
'<span data-toggle="tooltip" data-placement="left" title="Remove ' + row['name'] + '" class="fa fa-trash">' +
'</span></button>' :
'<button class="btn btn-default btn-xs act_install" data-package="' + row['name'] + '">' +
'<span data-toggle="tooltip" data-placement="left" title="Install ' + row['name'] + '" class="fa fa-plus">' +
'</span></button>'
) + '</td>' + '</tr>'
);
});
// XXX needs a bit more testing
//if (!data['remote'].length) {
// $('#pluginlist').append(
// '<tr><td colspan=5>{{ lang._('Fetch updates to view available plugins.') }}</td></tr>'
// );
//}
// link buttons to actions
$(".act_reinstall").click(function(event) {
event.preventDefault();
action('reinstall', $(this).data('package'));
});
$(".act_unlock").click(function(event) {
event.preventDefault();
action('unlock', $(this).data('package'));
});
$(".act_lock").click(function(event) {
event.preventDefault();
action('lock', $(this).data('package'));
});
$(".act_remove").click(function(event) {
event.preventDefault();
action('remove', $(this).data('package'));
});
$(".act_install").click(function(event) {
event.preventDefault();
action('install', $(this).data('package'));
});
});
}
......
#!/bin/sh
# Copyright (C) 2015-2016 Franco Fichtner <franco@opnsense.org>
# Copyright (C) 2014 Deciso B.V.
# All rights reserved.
#
# 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 ``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 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.
PKG_PROGRESS_FILE=/tmp/pkg_upgrade.progress
PACKAGE=$1
# Check if another pkg process is already running
if [ -n "$(pgrep pkg)" ]; then
exit 0
fi
# Truncate upgrade progress file
: > ${PKG_PROGRESS_FILE}
echo "***GOT REQUEST TO REINSTALL: $PACKAGE***" >> ${PKG_PROGRESS_FILE}
echo '***STARTING REINSTALL***' >> ${PKG_PROGRESS_FILE}
pkg install -y $PACKAGE >> ${PKG_PROGRESS_FILE}
pkg autoremove -y >> ${PKG_PROGRESS_FILE}
pkg clean -ya >> ${PKG_PROGRESS_FILE}
echo '***DONE***' >> ${PKG_PROGRESS_FILE}
#!/bin/sh
# Copyright (C) 2015-2016 Franco Fichtner <franco@opnsense.org>
# Copyright (C) 2014 Deciso B.V.
# All rights reserved.
#
# 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 ``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 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.
PKG_PROGRESS_FILE=/tmp/pkg_upgrade.progress
PACKAGE=$1
# Check if another pkg process is already running
if [ -n "$(pgrep pkg)" ]; then
exit 0
fi
# Truncate upgrade progress file
: > ${PKG_PROGRESS_FILE}
echo "***GOT REQUEST TO REINSTALL: $PACKAGE***" >> ${PKG_PROGRESS_FILE}
echo '***STARTING REINSTALL***' >> ${PKG_PROGRESS_FILE}
pkg remove -y $PACKAGE >> ${PKG_PROGRESS_FILE}
pkg autoremove -y >> ${PKG_PROGRESS_FILE}
pkg clean -ya >> ${PKG_PROGRESS_FILE}
echo '***DONE***' >> ${PKG_PROGRESS_FILE}
......@@ -28,6 +28,18 @@ parameters:%s
type:script
message: unlocking firmware package %s
[install]
command: /usr/sbin/daemon -f /usr/local/opnsense/scripts/firmware/install.sh
parameters:%s
type:script
message: installing firmware package %s
[remove]
command: /usr/sbin/daemon -f /usr/local/opnsense/scripts/firmware/remove.sh
parameters:%s
type:script
message: remove firmware package %s
[status]
command:cat /tmp/pkg_upgrade.progress 2>&1
parameters:
......
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