Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
569d0c33
Commit
569d0c33
authored
Jan 03, 2016
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firmware: complete plugin/package management feature
(cherry picked from commit
bcc6d757
)
parent
20a242ee
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
262 additions
and
21 deletions
+262
-21
FirmwareController.php
.../app/controllers/OPNsense/Core/Api/FirmwareController.php
+114
-2
firmware.volt
src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt
+48
-19
install.sh
src/opnsense/scripts/firmware/install.sh
+44
-0
remove.sh
src/opnsense/scripts/firmware/remove.sh
+44
-0
actions_firmware.conf
src/opnsense/service/conf/actions.d/actions_firmware.conf
+12
-0
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php
View file @
569d0c33
...
@@ -100,7 +100,7 @@ class FirmwareController extends ApiControllerBase
...
@@ -100,7 +100,7 @@ class FirmwareController extends ApiControllerBase
public
function
upgradeAction
()
public
function
upgradeAction
()
{
{
$backend
=
new
Backend
();
$backend
=
new
Backend
();
$response
=
array
();
$response
=
array
();
if
(
$this
->
request
->
hasPost
(
"upgrade"
))
{
if
(
$this
->
request
->
hasPost
(
"upgrade"
))
{
$response
[
'status'
]
=
'ok'
;
$response
[
'status'
]
=
'ok'
;
if
(
$this
->
request
->
getPost
(
"upgrade"
)
==
"pkg"
)
{
if
(
$this
->
request
->
getPost
(
"upgrade"
)
==
"pkg"
)
{
...
@@ -125,7 +125,7 @@ class FirmwareController extends ApiControllerBase
...
@@ -125,7 +125,7 @@ class FirmwareController extends ApiControllerBase
public
function
reinstallAction
(
$pkg_name
)
public
function
reinstallAction
(
$pkg_name
)
{
{
$backend
=
new
Backend
();
$backend
=
new
Backend
();
$response
=
array
();
$response
=
array
();
if
(
$this
->
request
->
isPost
())
{
if
(
$this
->
request
->
isPost
())
{
$response
[
'status'
]
=
'ok'
;
$response
[
'status'
]
=
'ok'
;
...
@@ -144,6 +144,118 @@ class FirmwareController extends ApiControllerBase
...
@@ -144,6 +144,118 @@ class FirmwareController extends ApiControllerBase
return
$response
;
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)
* retrieve upgrade status (and log file of current process)
*/
*/
...
...
src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt
View file @
569d0c33
...
@@ -92,14 +92,14 @@ POSSIBILITY OF SUCH DAMAGE.
...
@@ -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');
$('#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();
$('#updatelist').empty();
setTimeout(trackStatus, 500);
setTimeout(trackStatus, 500);
});
});
...
@@ -192,10 +192,10 @@ POSSIBILITY OF SUCH DAMAGE.
...
@@ -192,10 +192,10 @@ POSSIBILITY OF SUCH DAMAGE.
$("#packageslist").html("<tr><th>{{ lang._('Name') }}</th>" +
$("#packageslist").html("<tr><th>{{ lang._('Name') }}</th>" +
"<th>{{ lang._('Version') }}</th><th>{{ lang._('Size') }}</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>" +
$("#pluginlist").html("<tr><th>{{ lang._('Name') }}</th>" +
"<th>{{ lang._('Version') }}</th><th>{{ lang._('Size') }}</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) {
$.each(data['local'], function(index, row) {
$('#packageslist').append(
$('#packageslist').append(
...
@@ -205,9 +205,16 @@ POSSIBILITY OF SUCH DAMAGE.
...
@@ -205,9 +205,16 @@ POSSIBILITY OF SUCH DAMAGE.
'<td>' + row['flatsize'] + '</td>' +
'<td>' + row['flatsize'] + '</td>' +
'<td>' + row['comment'] + '</td>' +
'<td>' + row['comment'] + '</td>' +
'<td>' +
'<td>' +
'<button class="btn btn-default btn-xs act_reinstall" data-package="' + row['name'] + '">reinstall</button>'+
'<button class="btn btn-default btn-xs act_reinstall" data-package="' + row['name'] + '">' +
', ' + (row['locked'] === '1' ? 'unlock' : 'lock') +
'<span data-toggle="tooltip" data-placement="left" title="Reinstall ' + row['name'] + '" class="fa fa-recycle">' +
'</td>' +
'</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>'
'</tr>'
);
);
if (!row['name'].match(/^os-/g)) {
if (!row['name'].match(/^os-/g)) {
...
@@ -216,32 +223,54 @@ POSSIBILITY OF SUCH DAMAGE.
...
@@ -216,32 +223,54 @@ POSSIBILITY OF SUCH DAMAGE.
installed[row['name']] = row;
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) {
$.each(data['remote'], function(index, row) {
if (!row['name'].match(/^os-/g)) {
if (!row['name'].match(/^os-/g)) {
return 1;
return 1;
}
}
$('#pluginlist').append(
$('#pluginlist').append(
'<tr>' +
'<tr>' + '<td>' + row['name'] + '</td>' +
'<td>' + row['name'] + '</td>' +
'<td>' + row['version'] + '</td>' +
'<td>' + row['version'] + '</td>' +
'<td>' + row['flatsize'] + '</td>' +
'<td>' + row['flatsize'] + '</td>' +
'<td>' + row['comment'] + '</td>' +
'<td>' + row['comment'] + '</td>' +
'<td>' + (row['name'] in installed ? 'deinstall' : 'install') + '</td>' +
'<td>' + (row['name'] in installed ?
'</tr>'
'<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
// XXX needs a bit more testing
//if (!data['remote'].length) {
//if (!data['remote'].length) {
// $('#pluginlist').append(
// $('#pluginlist').append(
// '<tr><td colspan=5>{{ lang._('Fetch updates to view available plugins.') }}</td></tr>'
// '<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'));
});
});
});
}
}
...
...
src/opnsense/scripts/firmware/install.sh
0 → 100755
View file @
569d0c33
#!/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
}
src/opnsense/scripts/firmware/remove.sh
0 → 100755
View file @
569d0c33
#!/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
}
src/opnsense/service/conf/actions.d/actions_firmware.conf
View file @
569d0c33
...
@@ -28,6 +28,18 @@ parameters:%s
...
@@ -28,6 +28,18 @@ parameters:%s
type
:
script
type
:
script
message
:
unlocking
firmware
package
%
s
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
]
[
status
]
command
:
cat
/
tmp
/
pkg_upgrade
.
progress
2
>&
1
command
:
cat
/
tmp
/
pkg_upgrade
.
progress
2
>&
1
parameters
:
parameters
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment