Skip to content

Commit 0fde4b1

Browse files
committed
.
1 parent 5e98756 commit 0fde4b1

6 files changed

Lines changed: 40 additions & 30 deletions

File tree

src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,20 @@ public function poweroffAction()
461461
*/
462462
public function updateAction()
463463
{
464-
if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') {
465-
touch('/tmp/firmware_shutdown.flag');
466464
$backend = new Backend();
467465
$response = [];
468466
if ($this->request->isPost()) {
469467
$this->getLogger('audit')->notice(sprintf("[Firmware] User %s executed a firmware update", $this->getUserName()));
470468
$backend->configdRun('firmware flush');
471-
$response['msg_uuid'] = trim($backend->configdRun('firmware update', true));
469+
470+
$cmd = 'firmware update';
471+
if ($this->request->getPost('shutdown') === '1') {
472+
$cmd .= ' shutdown';
473+
}
474+
475+
$response['msg_uuid'] = trim($backend->configdRun($cmd, true));
472476
$response['status'] = 'ok';
473-
} else {
474-
$response['status'] = 'failure';
475477
}
476-
477478
return $response;
478479
}
479480

@@ -484,19 +485,20 @@ public function updateAction()
484485
*/
485486
public function upgradeAction()
486487
{
487-
if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') {
488-
touch('/tmp/firmware_shutdown.flag');
489488
$backend = new Backend();
490489
$response = [];
491490
if ($this->request->isPost()) {
492491
$this->getLogger('audit')->notice(sprintf("[Firmware] User %s executed a firmware upgrade", $this->getUserName()));
493492
$backend->configdRun('firmware flush');
494-
$response['msg_uuid'] = trim($backend->configdRun('firmware upgrade', true));
493+
494+
$cmd = 'firmware upgrade';
495+
if ($this->request->getPost('shutdown') === '1') {
496+
$cmd .= ' shutdown';
497+
}
498+
499+
$response['msg_uuid'] = trim($backend->configdRun($cmd, true));
495500
$response['status'] = 'ok';
496-
} else {
497-
$response['status'] = 'failure';
498501
}
499-
500502
return $response;
501503
}
502504

@@ -572,8 +574,6 @@ public function auditAction()
572574
*/
573575
public function reinstallAction($pkg_name)
574576
{
575-
if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') {
576-
touch('/tmp/firmware_shutdown.flag');
577577
$backend = new Backend();
578578
$response = [];
579579

@@ -775,7 +775,7 @@ public function upgradestatusAction()
775775
$result['status'] = 'done';
776776
} elseif (strpos($cmd_result, '***REBOOT***') !== false) {
777777
$result['status'] = 'reboot';
778-
} elseif (strpos($cmd_result, '***SHUTDOWN***') !== false) {
778+
} elseif (strpos($cmd_result, '***POWER OFF***') !== false) {
779779
$result['status'] = 'shutdown';
780780
}
781781

src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,14 @@
202202
// reboot required, inform the user.
203203
BootstrapDialog.show({
204204
type:BootstrapDialog.TYPE_WARNING,
205-
title: "{{ lang._('Reboot/ Power off required') }}",
206-
message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}" + '<br><br><label><input type="checkbox" id="reinstall_shutdown_cb"> ' + '{{ lang._("Power off instead of reboot") }}</label>',
205+
title: "{{ lang._('Reboot required') }}",
206+
message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}",
207207
buttons: [{
208208
label: "{{ lang._('OK') }}",
209209
cssClass: 'btn-warning',
210210
action: function(dialogRef){
211-
let doShutdown = $('#reinstall_shutdown_cb').is(':checked') ? '1' : '0';
212211
dialogRef.close();
213-
backend(pkg_act + "/" + pkg_name, {'shutdown': doShutdown});
212+
backend(pkg_act + "/" + pkg_name);
214213
}
215214
},{
216215
label: "{{ lang._('Cancel') }}",

src/opnsense/scripts/firmware/config.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,7 @@ output_done()
152152
output_restart_action()
153153
{
154154
KEEP_LOG=${1}
155-
PREFER_SHUTDOWN=0
156-
157-
if [ -f /tmp/firmware_shutdown.flag ]; then
158-
PREFER_SHUTDOWN=1
159-
rm -f /tmp/firmware_shutdown.flag
160-
fi
155+
PREFER_SHUTDOWN=${2:-0}
161156

162157
if [ "${PREFER_SHUTDOWN}" = "1" ]; then
163158
output_shutdown "${KEEP_LOG}"

src/opnsense/scripts/firmware/reinstall.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if [ "${PACKAGE}" = "base" ]; then
3535
if opnsense-update -Tb; then
3636
# force reinstall intended
3737
if output_cmd opnsense-update -bf; then
38-
output_restart_action
38+
output_reboot
3939
fi
4040
else
4141
# for locked message only
@@ -45,7 +45,7 @@ elif [ "${PACKAGE}" = "kernel" ]; then
4545
if opnsense-update -Tk; then
4646
# force reinstall intended
4747
if output_cmd opnsense-update -kf; then
48-
output_restart_action
48+
output_reboot
4949
fi
5050
else
5151
# for locked message only

src/opnsense/scripts/firmware/update.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ REQUEST="UPDATE"
2929

3030
. /usr/local/opnsense/scripts/firmware/config.sh
3131

32+
PREFER_SHUTDOWN=0
33+
for arg in "$@"; do
34+
if [ "$arg" = "shutdown" ]; then
35+
PREFER_SHUTDOWN=1
36+
break
37+
fi
38+
done
39+
3240
CMD=${1}
3341
FORCE=
3442

@@ -71,13 +79,13 @@ fi
7179
# if we can update base, we'll do that as well
7280
if opnsense-update ${FORCE} -bk -c; then
7381
if output_cmd opnsense-update ${FORCE} -bk; then
74-
output_restart_action keep-log
82+
output_restart_action keep-log ${PREFER_SHUTDOWN}
7583
fi
7684
fi
7785

7886
if [ "${ALWAYS_REBOOT}" = "1" ]; then
7987
if [ "${PKGS_HASH}" != "$(${PKG} query %n-%v 2> /dev/null | sha256)" ]; then
80-
output_restart_action keep-log
88+
output_restart_action keep-log ${PREFER_SHUTDOWN}
8189
fi
8290
fi
8391

src/opnsense/scripts/firmware/upgrade.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,21 @@ REQUEST="UPGRADE"
2929

3030
. /usr/local/opnsense/scripts/firmware/config.sh
3131

32+
PREFER_SHUTDOWN=0
33+
for arg in "$@"; do
34+
if [ "$arg" = "shutdown" ]; then
35+
PREFER_SHUTDOWN=1
36+
break
37+
fi
38+
done
39+
3240
if output_cmd opnsense-update -u; then
3341
if output_cmd /usr/local/etc/rc.syshook upgrade; then
3442
# pending kernel applies before reboot
3543
if output_cmd opnsense-update -K -c; then
3644
output_cmd opnsense-update -K
3745
fi
38-
output_restart_action keep-log
46+
output_restart_action keep-log ${PREFER_SHUTDOWN}
3947
fi
4048

4149
output_txt "The upgrade was aborted due to an error."

0 commit comments

Comments
 (0)