System: Settings: Tunables - refactor to MVC for https://github.com/opnsense/core/issues/7249 (work in progress)

This commit is contained in:
Ad Schellevis 2025-01-01 20:12:08 +01:00
parent 75144ff498
commit af2730dd36
10 changed files with 413 additions and 0 deletions

8
plist
View File

@ -249,6 +249,7 @@
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/ServiceController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/SnapshotsController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/SystemController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/TunablesController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/BackupController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/DashboardController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/FirmwareController.php
@ -260,8 +261,10 @@
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/RebootController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/ServiceController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/SnapshotsController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/TunablesController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/hasyncSettings.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/snapshot.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/tunable.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Cron/Api/ServiceController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Cron/Api/SettingsController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Cron/IndexController.php
@ -657,6 +660,7 @@
/usr/local/opnsense/mvc/app/models/OPNsense/Core/ACL.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Core/FieldTypes/TunableField.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Firmware.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Hasync.php
@ -666,6 +670,8 @@
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Migrations/M1_0_1.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Migrations/MHA1_0_0.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Migrations/MHA1_0_1.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Tunables.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Tunables.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Core/repositories/opnsense.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/ACL/ACL.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/Cron.php
@ -872,6 +878,7 @@
/usr/local/opnsense/mvc/app/views/OPNsense/Core/reboot.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Core/service.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Core/snapshot.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Core/tunables.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Cron/index.volt
/usr/local/opnsense/mvc/app/views/OPNsense/DHCPv4/leases.volt
/usr/local/opnsense/mvc/app/views/OPNsense/DHCPv6/leases.volt
@ -1275,6 +1282,7 @@
/usr/local/opnsense/scripts/system/status.php
/usr/local/opnsense/scripts/system/swapinfo.py
/usr/local/opnsense/scripts/system/sysctl.py
/usr/local/opnsense/scripts/system/sysctl_defaults.php
/usr/local/opnsense/scripts/system/tls_groups.py
/usr/local/opnsense/scripts/system/trigger_config_changed_events.py
/usr/local/opnsense/scripts/system/update-crl-fetch.py

View File

@ -0,0 +1,64 @@
<?php
/*
* Copyright (C) 2025 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\ApiMutableModelControllerBase;
use OPNsense\Core\Backend;
use OPNsense\Base\UserException;
class TunablesController extends ApiMutableModelControllerBase
{
protected static $internalModelName = 'sysctl';
protected static $internalModelClass = 'OPNsense\Core\Tunables';
public function searchAction()
{
return $this->searchBase("item", null, "sysctl");
}
public function setSubnetAction($uuid)
{
return $this->setBase("sysctl", "item", $uuid);
}
public function addSubnetAction()
{
return $this->addBase("sysctl", "item");
}
public function getSubnetAction($uuid = null)
{
return $this->getBase("sysctl", "item", $uuid);
}
public function delSubnetAction($uuid)
{
return $this->delBase("item", $uuid);
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
* Copyright (C) 2025 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 TunablesController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->pick('OPNsense/Core/tunables');
$this->view->formDialogTunable = $this->getForm('tunable');
}
}

View File

@ -0,0 +1,17 @@
<form>
<field>
<id>item.tunable</id>
<label>Tunable</label>
<type>text</type>
</field>
<field>
<id>item.value</id>
<label>Value</label>
<type>text</type>
</field>
<field>
<id>item.descr</id>
<label>Description</label>
<type>text</type>
</field>
</form>

View File

@ -0,0 +1,92 @@
<?php
/**
* Copyright (C) 2020 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\FieldTypes;
use OPNsense\Base\FieldTypes\ArrayField;
use OPNsense\Base\FieldTypes\TextField;
use OPNsense\Base\FieldTypes\IntegerField;
use OPNsense\Core\Backend;
use OPNsense\Core\Config;
class TunableField extends ArrayField
{
protected static $internalStaticChildren = [];
private static $default_values = null;
private static $static_entries = [];
/**
* {@inheritdoc}
*/
protected static function getStaticChildren()
{
$result = [];
foreach (self::$static_entries as $key => $item){
$result[] = [
'tunable' => $key,
'value' => $item['value'] ?? '',
'default_value' => $item['default'],
'descr' => $item['description'],
'type' => $item['type'] ?? '',
];
}
return $result;
}
protected function actionPostLoadingEvent()
{
if (self::$default_values === null) {
self::$default_values = json_decode((new Backend())->configdRun('system sysctl gather'), true) ?? [];
self::$static_entries = json_decode((new Backend())->configdRun('system sysctl defaults'), true) ?? [];
foreach (self::$static_entries as $key => $item) {
if (!empty(self::$default_values[$key])) {
self::$static_entries[$key]['type'] = self::$default_values[$key]['type'];
self::$static_entries[$key]['value'] = self::$default_values[$key]['value'];
self::$static_entries[$key]['descr'] = self::$default_values[$key]['description'];
}
}
}
foreach ($this->iterateItems() as $node) {
if (isset(self::$static_entries[(string)$node->tunable])) {
unset(self::$static_entries[(string)$node->tunable]);
}
if (isset(self::$default_values[(string)$node->tunable])) {
$node->default_value->setValue(self::$default_values[(string)$node->tunable]['value']);
$node->type->setValue(self::$default_values[(string)$node->tunable]['type']);
if (empty((string)$node->descr)) {
$node->descr->setValue(self::$default_values[(string)$node->tunable]['description']);
}
}
}
parent::actionPostLoadingEvent();
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
* Copyright (C) 2025 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;
use OPNsense\Base\BaseModel;
/**
* Class Tunables
* @package OPNsense\Core
*/
class Tunables extends BaseModel
{
}

View File

@ -0,0 +1,15 @@
<model>
<mount>//sysctl</mount>
<migration_prefix>TUN</migration_prefix>
<version>1.0.0</version>
<description>System Tunables</description>
<items>
<item type=".\TunableField">
<tunable type="TextField"/>
<value type="TextField"/>
<descr type="TextField"/>
<default_value type="TextField" volatile="true"/>
<type type="TextField" volatile="true"/>
</item>
</items>
</model>

View File

@ -0,0 +1,100 @@
{#
# Copyright (c) 2025 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>
$( document ).ready(function() {
$("#grid").UIBootgrid(
{ search:'/api/core/tunables/search/',
get:'/api/core/tunables/get/',
set:'/api/core/tunables/set/',
add:'/api/core/tunables/add/',
del:'/api/core/tunables/del/',
options: {
formatters: {
"tunable_type": function (column, row) {
let retval = "{{ lang._('environment')}}";
switch (row[column.id]) {
case 'w':
retval = "{{ lang._('runtime')}}";
break;
case 't':
retval = "{{ lang._('boot-time')}}";
break;
case 'y':
retval = "{{ lang._('read-only')}}";
break;
}
return retval;
}
}
}
}
);
$("#reconfigureAct").SimpleActionButton();
});
</script>
<div class="tab-content content-box">
<table id="grid" class="table table-condensed table-hover table-striped" data-editDialog="DialogTunable" data-editAlert="ChangeMessage">
<thead>
<tr>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="tunable" data-type="string">{{ lang._('Tunable') }}</th>
<th data-column-id="type" data-type="string" data-formatter="tunable_type">{{ lang._('Type') }}</th>
<th data-column-id="value" data-type="string">{{ lang._('Value') }}</th>
<th data-column-id="default_value" data-type="string">{{ lang._('Default') }}</th>
<th data-column-id="descr" data-type="string">{{ lang._('Description') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-primary"><span class="fa fa-fw fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-fw fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
<div class="col-md-12">
<div id="ChangeMessage" class="alert alert-info" style="display: none" role="alert">
{{ lang._('After changing settings, please remember to apply them with the button below') }}
</div>
<hr/>
<button class="btn btn-primary" id="reconfigureAct"
data-endpoint='/api/core/tunables/reconfigure'
data-label="{{ lang._('Apply') }}"
data-error-title="{{ lang._('Error reconfiguring Tunables') }}"
type="button"
></button>
<br/><br/>
</div>
</div>
{{ partial("layout_partials/base_dialog",['fields':formDialogTunable,'id':'DialogTunable','label':lang._('Edit Tunable')])}}

View File

@ -0,0 +1,33 @@
#!/usr/local/bin/php
<?php
/*
* Copyright (C) 2025 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.
*/
require_once("config.inc");
require_once("system.inc");
echo json_encode(system_sysctl_defaults());

View File

@ -46,6 +46,12 @@ parameters:--values %s
type:script_output
message:Get sysctl value(s)
[sysctl.defaults]
command:/usr/local/opnsense/scripts/system/sysctl_defaults.php
type:script_output
cache_ttl:300
message:Collect sysctl default values
[ssl.ciphers]
command:/usr/local/opnsense/scripts/system/ssl_ciphers.py
parameters: