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
54e976fe
Commit
54e976fe
authored
May 15, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first step in migrating the firmware upgrade away from legacy code
parent
2f5f4b11
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
355 additions
and
0 deletions
+355
-0
FirmwareController.php
.../app/controllers/OPNsense/Core/Api/FirmwareController.php
+115
-0
FirmwareController.php
.../mvc/app/controllers/OPNsense/Core/FirmwareController.php
+46
-0
firmware.volt
src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt
+176
-0
actions_firmware.conf
src/opnsense/service/conf/actions.d/actions_firmware.conf
+18
-0
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php
0 → 100644
View file @
54e976fe
<?php
/**
* Copyright (C) 2015 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.
*
*/
namespace
OPNsense\Core\Api
;
use
\OPNsense\Base\ApiControllerBase
;
use
\OPNsense\Core\Backend
;
/**
* Class FirmwareController
* @package OPNsense\Core
*/
class
FirmwareController
extends
ApiControllerBase
{
/**
* retrieve available updates
* @return array
*/
public
function
statusAction
()
{
$backend
=
new
Backend
();
$response
=
json_decode
(
trim
(
$backend
->
configdRun
(
"firmware pkgstatus"
)),
true
);
if
(
$response
!=
null
)
{
if
(
array_key_exists
(
"connection"
,
$response
)
&&
$response
[
"connection"
]
==
"error"
)
{
$response
[
"status"
]
=
"error"
;
$response
[
"status_msg"
]
=
"Connection Error"
;
}
elseif
(
array_key_exists
(
"repository"
,
$response
)
&&
$response
[
"repository"
]
==
"error"
)
{
$response
[
"status"
]
=
"error"
;
$response
[
"status_msg"
]
=
"Repository Problem"
;
}
elseif
(
array_key_exists
(
"updates"
,
$response
)
&&
$response
[
'updates'
]
==
0
)
{
$response
[
"status"
]
=
"none"
;
$response
[
"status_msg"
]
=
"no updates found"
;
}
elseif
(
array_key_exists
(
"updates"
,
$response
)
&&
$response
[
"upgrade_packages"
][
0
][
"name"
]
==
"pkg"
)
{
$response
[
"status"
]
=
"ok"
;
$response
[
"status_msg"
]
=
"There is a mandatory update for the package manager."
.
"please install and check for updates again."
;
}
elseif
(
array_key_exists
(
"updates"
,
$response
))
{
$response
[
"status"
]
=
"ok"
;
$response
[
"status_msg"
]
=
sprintf
(
"A total of %s update(s) are available."
,
$response
[
"updates"
]);
}
}
else
{
$response
=
array
(
"status"
=>
"unknown"
,
"status_msg"
=>
"Current status is unknown"
);
}
return
$response
;
}
/**
* perform actual upgrade
* @return array status
* @throws \Exception
*/
public
function
upgradeAction
()
{
$backend
=
new
Backend
();
$response
=
array
();
if
(
$this
->
request
->
isPost
())
{
$response
[
'status'
]
=
'ok'
;
$response
[
'uuid'
]
=
trim
(
$backend
->
configdRun
(
"firmware upgrade"
,
true
));
}
else
{
$response
[
'status'
]
=
'failure'
;
}
return
$response
;
}
/**
* retrieve upgrade status (and log file of current process)
*/
public
function
upgradestatusAction
()
{
$backend
=
new
Backend
();
$result
=
array
(
"status"
=>
"running"
);
$cmd_result
=
trim
(
$backend
->
configdRun
(
"firmware upgrade_status"
));
$result
[
'log'
]
=
$cmd_result
;
if
(
trim
(
$cmd_result
)
==
"Execute error"
)
{
$result
[
"status"
]
=
"error"
;
}
elseif
(
strpos
(
$cmd_result
,
'***DONE***'
)
!==
false
)
{
$result
[
"status"
]
=
"done"
;
}
elseif
(
strpos
(
$cmd_result
,
'***REBOOT***'
)
!==
false
)
{
$result
[
"status"
]
=
"reboot"
;
}
return
$result
;
}
}
src/opnsense/mvc/app/controllers/OPNsense/Core/FirmwareController.php
0 → 100644
View file @
54e976fe
<?php
/**
* Copyright (C) 2015 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.
*
*/
namespace
OPNsense\Core
;
/**
* Class FirmwareController controller for firmware core actions
* @package OPNsense\Core
*/
class
FirmwareController
extends
\OPNsense\Base\IndexController
{
/**
* return to / for non existent actions
*/
public
function
indexAction
()
{
$this
->
view
->
title
=
"Firmware"
;
$this
->
view
->
pick
(
'OPNsense/Core/firmware'
);
return
;
}
}
src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt
0 → 100644
View file @
54e976fe
{#
OPNsense® is Copyright © 2014 – 2015 by 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.
#}
<script type="text/javascript">
/**
* retrieve update status from backend
*/
function updateStatus() {
$('#maintabs li:eq(0) a').tab('show');
$("#checkupdate_progress").addClass("fa fa-spinner fa-pulse");
$('#updatestatus').attr('class', 'text-info');
$('#updatestatus').html("{{ lang._('Updating.... (may take up to 30 seconds)') }}");
ajaxGet('/api/core/firmware/status',{},function(data,status){
if (data['status'] == 'unknown') {
$('#updatestatus').attr('class', 'text-warning');
} else if (data['status'] == 'error') {
$('#updatestatus').attr('class', 'text-danger');
} else if (data['status'] == 'none' || data['status'] == 'ok') {
$('#updatestatus').attr('class', 'text-info');
}
$('#updatestatus').html(data['status_msg']);
$("#checkupdate_progress").removeClass("fa fa-spinner fa-pulse");
if (data['status'] == "ok") {
// unhide upgrade button
$("#upgrade").attr("style","");
// show upgrade list
$("#updatelist").html("<tr><th>{{ lang._('Package Name') }}</th>" +
"<th>{{ lang._('Current Version') }}</th><th>{{ lang._('New Version') }}</th><th></th></tr>");
$.each(['upgrade_packages','new_packages','reinstall_packages'], function(type_idx,type_name){
$.each(data[type_name],function(index,row){
var txt_info = "" ;
if (type_name == "new_packages") {
txt_info = "<strong>{{ lang._('NEW') }}</strong>";
} else if (type_name == "reinstall_packages") {
txt_info = "<strong>{{ lang._('REINSTALL') }}</strong>";
}
$('#updatelist').append('<tr><td>'+row['name']+'</td>' +
'<td>'+row['current_version']+'</td><td>'+row['new_version']+'</td><td>'+txt_info+'</td></tr>');
});
});
}
});
}
/**
* perform upgrade, install poller to update status
*/
function upgrade(){
$('#maintabs li:eq(1) a').tab('show');
$("#upgrade_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall('/api/core/firmware/upgrade',{},function() {
$("#upgrade_progress").removeClass("fa fa-spinner fa-pulse");
setTimeout(trackStatus, 1000) ;
});
}
/**
* handle update status
*/
function trackStatus(){
ajaxGet('/api/core/firmware/upgradestatus',{},function(data, status) {
if (data['log'] != undefined) {
$('#update_status').html(data['log']);
$('#update_status').scrollTop($('#update_status')[0].scrollHeight);
}
if (data['status'] == 'running') {
// schedule next poll
setTimeout(trackStatus, 1000) ;
}else if (data['status'] == 'reboot') {
// reboot required, tell the user to wait until this is finished and redirect after 5 minutes
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: 'Upgrade',
message: "{{ lang._('The upgrade is finished and your device is being rebooted at the moment, please wait.') }}",
buttons: [{
label: "{{ lang._('Close') }}",
cssClass: 'btn-success',
autospin: true,
action: function(dialogRef){
dialogRef.enableButtons(false);
dialogRef.setClosable(false);
dialogRef.getModalBody().html("{{ lang._('You will be redirected to the login page in 5 minutes.') }}");
setTimeout(function(){
dialogRef.close();
$(location).attr('href',"/");
}, 60000 * 5);
}
}]
});
}
});
}
$( document ).ready(function() {
// link event handlers
$('#checkupdate').click(updateStatus);
$('#upgrade').click(upgrade);
});
</script>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<strong>{{ lang._('Current Firmware Status :')}}</strong>
<br/>
<span class="text-info" id="updatestatus">{{ lang._('Current status is unknown')}} </span>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class='btn btn-primary' id="checkupdate"><i id="checkupdate_progress" class=""></i> {{ lang._('Click to check now')}}</button>
<button class='btn btn-primary' id="upgrade" style="display:none"><i id="upgrade_progress" class=""></i> {{ lang._('Upgrade') }} </button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<br/>
</div>
</div>
<div class="row">
<div class="col-md-12" id="content">
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<li class="active"><a data-toggle="tab" href="#updates">{{ lang._('Updates') }}</a></li>
<li><a data-toggle="tab" href="#progress">{{ lang._('Progress') }}</a></li>
</ul>
<div class="tab-content">
<div id="updates" class="tab-pane fade in active">
<table class="table table-striped table-condensed table-responsive" id="updatelist">
</table>
</div>
<div id="progress" class="tab-pane fade in">
<textarea name="output" id="update_status" class="form-control" rows="10" wrap="hard" readonly style="max-width:100%;"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
</div>
</div>
</div>
src/opnsense/service/conf/actions.d/actions_firmware.conf
0 → 100644
View file @
54e976fe
[
pkgstatus
]
#command:echo '{"upgrade_packages": [{"name": "test","current_version":1,"new_version":2},{"name": "testX","current_version":1,"new_version":2}],"new_packages": [{"name": "testxx","current_version":1,"new_version":2},{"name": "testXxx","current_version":1,"new_version":2}],"reinstall_packages": [{"name": "testxx","current_version":1,"new_version":2},{"name": "testXxx","current_version":1,"new_version":2}], "updates": 10}'
command
:/
usr
/
local
/
opnsense
/
scripts
/
pkg_updatecheck
.
sh
parameters
:
type
:
script_output
message
:
retrieve
package
status
[
upgrade
]
command
: /
usr
/
sbin
/
daemon
-
f
/
usr
/
local
/
opnsense
/
scripts
/
pkg_upgrade
.
sh
parameters
:
type
:
script
message
:
perform
upgrade
[
upgrade_status
]
command
:
cat
/
tmp
/
pkg_upgrade
.
progress
2
>&
1
parameters
:
type
:
script_output
message
:
retrieve
upgrade
progress
status
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