firmware: migrate old flavour entries #4881

While here tweak the GUI a little.
This commit is contained in:
Franco Fichtner 2023-03-08 09:45:34 +01:00
parent 8739747ddd
commit 9187fe78bf
7 changed files with 94 additions and 55 deletions

1
plist
View File

@ -553,6 +553,7 @@
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Menu/Menu.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Migrations/M1_0_0.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Migrations/M1_0_1.php
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/ACL/ACL.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/Cron.php
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/Cron.xml

View File

@ -857,7 +857,7 @@ class FirmwareController extends ApiControllerBase
/* package infos are flat lists with 3 pipes as delimiter */
foreach (array('remote', 'local') as $type) {
$current = $backend->configdRun("firmware ${type}");
$current = explode("\n", trim($current));
$current = explode("\n", trim($current ?? ''));
foreach ($current as $line) {
$expanded = explode('|||', $line);

View File

@ -98,14 +98,10 @@
</mirror>
</mirrors>
<flavours allow_custom="true">
<flavour>
<flavour has_subscription="true">
<name/>
<description>(default)</description>
</flavour>
<flavour has_subscription="true">
<name>latest</name>
<description>OpenSSL</description>
</flavour>
</flavours>
<families>
<family has_subscription="true">

View File

@ -1,6 +1,6 @@
<model>
<mount>//system/firmware</mount>
<version>1.0.0</version>
<version>1.0.1</version>
<description>
OPNsense Firmware settings
</description>

View File

@ -1,31 +1,29 @@
<?php
/**
* Copyright (C) 2021 Deciso B.V.
/*
* Copyright (C) 2021 Deciso B.V.
* All rights reserved.
*
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 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.
*
* 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.
* 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\Migrations;
@ -40,12 +38,11 @@ class M1_0_0 extends BaseModelMigration
*/
public function run($model)
{
if ((empty((string)$model->type) || (string)$model->type == "devel") && !empty((string)$model->mirror)) {
$is_business = stripos((string)$model->mirror, "opnsense-update.deciso.com") > 1;
if ((empty((string)$model->type) || (string)$model->type == 'devel') && !empty((string)$model->mirror)) {
$is_business = stripos((string)$model->mirror, 'opnsense-update.deciso.com') > 1;
if ($is_business) {
$model->type = "business";
$model->flavour = "latest";
$model->type = 'business';
$model->flavour = 'latest';
}
}
}

View File

@ -0,0 +1,45 @@
<?php
/*
* Copyright (C) 2023 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\Migrations;
use OPNsense\Base\BaseModelMigration;
class M1_0_1 extends BaseModelMigration
{
/**
* Migrate BE release type
* @param $model
*/
public function run($model)
{
if (in_array((string)$model->flavour, ['latest', 'libressl'])) {
$model->flavour = null;
}
}
}

View File

@ -655,12 +655,12 @@
// handle firmware config options
ajaxGet('/api/core/firmware/getFirmwareOptions', {}, function(firmwareoptions, status) {
ajaxGet('/api/core/firmware/getFirmwareConfig', {}, function(firmwareconfig, status) {
var other_selected = true;
var custom_selected = true;
$.each(firmwareoptions.mirrors, function(key, value) {
var selected = false;
if ((key != "" && firmwareconfig['mirror'].indexOf(key) != -1) || key == firmwareconfig['mirror']) {
selected = true;
other_selected = false;
custom_selected = false;
}
$("#firmware_mirror").append($("<option/>")
.attr("value",key)
@ -670,11 +670,11 @@
);
});
if (firmwareoptions['mirrors_allow_custom']) {
$("#firmware_mirror").prepend($("<option/>")
$("#firmware_mirror :first-child").after($("<option/>")
.attr("value", firmwareconfig['mirror'])
.text("(other)")
.data("other", 1)
.prop('selected', other_selected)
.text("(custom)")
.data("custom", 1)
.prop('selected', custom_selected)
);
}
@ -687,12 +687,12 @@
$("#firmware_mirror").selectpicker('refresh');
$("#firmware_mirror").change();
other_selected = true;
custom_selected = true;
$.each(firmwareoptions.flavours, function(key, value) {
var selected = false;
if (key == firmwareconfig['flavour']) {
selected = true;
other_selected = false;
custom_selected = false;
}
$("#firmware_flavour").append($("<option/>")
.attr("value",key)
@ -701,11 +701,11 @@
);
});
if (firmwareoptions['flavours_allow_custom']) {
$("#firmware_flavour").prepend($("<option/>")
$("#firmware_flavour :first-child").after($("<option/>")
.attr("value", firmwareconfig['flavour'])
.text("(other)")
.data("other", 1)
.prop('selected', other_selected)
.text("(custom)")
.data("custom", 1)
.prop('selected', custom_selected)
);
}
$("#firmware_flavour").selectpicker('refresh');
@ -729,18 +729,18 @@
$("#firmware_mirror").change(function(){
$("#firmware_mirror_value").val($(this).val());
if ($(this).find(':selected').data("other") == 1) {
$("#firmware_mirror_other").show();
if ($(this).find(':selected').data("custom") == 1) {
$("#firmware_mirror_custom").show();
} else {
$("#firmware_mirror_other").hide();
$("#firmware_mirror_custom").hide();
}
});
$("#firmware_flavour").change(function() {
$("#firmware_flavour_value").val($(this).val());
if ($(this).find(':selected').data("other") == 1) {
$("#firmware_flavour_other").show();
if ($(this).find(':selected').data("custom") == 1) {
$("#firmware_flavour_custom").show();
} else {
$("#firmware_flavour_other").hide();
$("#firmware_flavour_custom").hide();
}
});
@ -975,7 +975,7 @@
<td>
<select class="selectpicker" id="firmware_mirror" data-size="5" data-live-search="true">
</select>
<div style="display:none;" id="firmware_mirror_other">
<div style="display:none;" id="firmware_mirror_custom">
<input type="text" id="firmware_mirror_value">
</div>
<div class="hidden" data-for="help_for_mirror">
@ -990,11 +990,11 @@
<td>
<select class="selectpicker" id="firmware_flavour">
</select>
<div style="display:none;" id="firmware_flavour_other">
<div style="display:none;" id="firmware_flavour_custom">
<input type="text" id="firmware_flavour_value">
</div>
<div class="hidden" data-for="help_for_flavour">
{{ lang._('Select the firmware cryptography flavour.') }}
{{ lang._('Select an alternate firmware flavour.') }}
</div>
</td>
<td></td>