From fe8347663a7ff2e438f069a2d1c2dd08417699a9 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 11 Dec 2017 21:13:18 +0000 Subject: [PATCH] firmware: allow to change release family from UI --- .../OPNsense/Core/Api/FirmwareController.php | 41 ++++++++++++++++++- .../mvc/app/views/OPNsense/Core/firmware.volt | 2 +- src/opnsense/scripts/firmware/check.sh | 1 + .../conf/actions.d/actions_firmware.conf | 8 +++- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php index 007d1c3ce..dd75624ec 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php @@ -63,9 +63,33 @@ class FirmwareController extends ApiControllerBase */ public function statusAction() { + $config = Config::getInstance()->object(); + $core_want = 'opnsense'; + if (!empty($config->system->firmware->family)) { + $core_want .= '-' . (string)$config->system->firmware->family; + } + $this->sessionClose(); // long running action, close session + $backend = new Backend(); + $core_have = trim($backend->configdRun('firmware core name')); $backend->configdRun('firmware changelog fetch'); + + if (!empty($core_have) && $core_have !== $core_want) { + $core_ver = trim($backend->configdRun('firmware core version ' . escapeshellarg($core_want))); + return array( + 'status_msg' => gettext('The release family requires an update.'), + 'all_packages' => array($core_want => array( + 'reason' => gettext('new'), + 'old' => gettext('N/A'), + 'name' => $core_want, + 'new' => $core_ver, + )), + 'status_upgrade_action' => 'rel', + 'status' => 'ok', + ); + } + $response = json_decode(trim($backend->configdRun('firmware check')), true); if ($response != null) { @@ -320,6 +344,11 @@ class FirmwareController extends ApiControllerBase */ public function upgradeAction() { + $config = Config::getInstance()->object(); + $core_want = 'opnsense'; + if (!empty($config->system->firmware->family)) { + $core_want .= '-' . (string)$config->system->firmware->family; + } $this->sessionClose(); // long running action, close session $backend = new Backend(); $response = array(); @@ -329,6 +358,8 @@ class FirmwareController extends ApiControllerBase $action = 'firmware upgrade pkg'; } elseif ($this->request->getPost('upgrade') == 'maj') { $action = 'firmware upgrade maj'; + } elseif ($this->request->getPost('upgrade') == 'rel') { + $action = 'firmware core switch ' . escapeshellarg($core_want); } else { $action = 'firmware upgrade all'; } @@ -782,23 +813,31 @@ class FirmwareController extends ApiControllerBase if (!isset($config->system->firmware->mirror)) { $config->system->firmware->addChild('mirror'); } - if (empty($selSubscription)) { $config->system->firmware->mirror = $selectedMirror; } else { // prepend subscription $config->system->firmware->mirror = $selectedMirror . '/' . $selSubscription; } + if (empty($config->system->firmware->mirror)) { + unset($config->system->firmware->mirror); + } if (!isset($config->system->firmware->flavour)) { $config->system->firmware->addChild('flavour'); } $config->system->firmware->flavour = $selectedFlavour; + if (empty($config->system->firmware->flavour)) { + unset($config->system->firmware->flavour); + } if (!isset($config->system->firmware->family)) { $config->system->firmware->addChild('family'); } $config->system->firmware->family = $selectedFamily; + if (empty($config->system->firmware->family)) { + unset($config->system->firmware->family); + } Config::getInstance()->save(); diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt index c2b26320e..9944df106 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt @@ -281,7 +281,7 @@ POSSIBILITY OF SUCH DAMAGE. if ($.upgrade_action == 'audit') { $('#updatestatus').html("{{ lang._('Audit done.') }}"); } else if ($.upgrade_action == 'action') { - $('#updatestatus').html("{{ lang._('Done.') }}"); + $('#updatestatus').html("{{ lang._('Action done.') }}"); } else { $('#updatestatus').html("{{ lang._('Upgrade done.') }}"); } diff --git a/src/opnsense/scripts/firmware/check.sh b/src/opnsense/scripts/firmware/check.sh index 0ab80cf41..38edf859c 100755 --- a/src/opnsense/scripts/firmware/check.sh +++ b/src/opnsense/scripts/firmware/check.sh @@ -33,6 +33,7 @@ # download_size: # new_packages: array with { name: , version: } # reinstall_packages: array with { name: , version: } +# downgrade_packages: array with { name: , current_version: , new_version: } # upgrade_packages: array with { name: , current_version: , new_version: } # TODO: Add object with items that will be removed diff --git a/src/opnsense/service/conf/actions.d/actions_firmware.conf b/src/opnsense/service/conf/actions.d/actions_firmware.conf index e19320a1b..dbb025ac3 100644 --- a/src/opnsense/service/conf/actions.d/actions_firmware.conf +++ b/src/opnsense/service/conf/actions.d/actions_firmware.conf @@ -35,12 +35,18 @@ parameters:%s type:script_output message:Viewing license for %s -[core.test] +[core.name] command:opnsense-update -T parameters: type:script_output message:Probing core package name +[core.version] +command:pkg rquery %v +parameters:%s +type:script_output +message:Probing core package version + [core.switch] command:/usr/sbin/daemon -f /usr/local/opnsense/scripts/firmware/launcher.sh core parameters:%s