From 3a9763d5273bbf65d2e13f3e017dad5b0980dae8 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sun, 10 Apr 2022 16:20:10 +0200 Subject: [PATCH] Services / Unbound - add missing alias descriptions (including migration). while here also make the migration a bit more resilient for hostname validation issues. closes https://github.com/opnsense/core/issues/5695 --- .../OPNsense/Unbound/Api/SettingsController.php | 2 +- .../OPNsense/Unbound/forms/dialogHostAlias.xml | 6 ++++++ .../models/OPNsense/Unbound/Migrations/M1_0_1.php | 13 ++++++++++--- .../mvc/app/models/OPNsense/Unbound/Unbound.xml | 5 +++++ .../mvc/app/views/OPNsense/Unbound/overrides.volt | 1 + 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php index 226d8592e..4296262e9 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php @@ -176,7 +176,7 @@ class SettingsController extends ApiMutableModelControllerBase } return $this->searchBase( 'aliases.alias', - ['enabled', 'host', 'hostname', 'domain'], + ['enabled', 'host', 'hostname', 'domain', 'description'], "sequence", $filter_func ); diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/dialogHostAlias.xml b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/dialogHostAlias.xml index a9b8ec874..48fa90a51 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/dialogHostAlias.xml +++ b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/dialogHostAlias.xml @@ -23,4 +23,10 @@ text Domain of the host, e.g. example.com + + alias.description + + text + You may enter a description here for your reference (not parsed) + diff --git a/src/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_1.php b/src/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_1.php index 6709222c7..6b6637526 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_1.php +++ b/src/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_1.php @@ -61,8 +61,14 @@ class M1_0_1 extends BaseModelMigration 'server' => $old_host->rr == 'A' || $old_host->rr == 'AAAA' ? $old_host->ip : null, 'mxprio' => $old_host->rr == 'MX' ? $old_host->mxprio : null, 'mx' => $old_host->rr == 'MX' ? $old_host->mx : null, - 'description' => !empty($old_host->descr) ? $old_host->descr : null + 'description' => !empty($old_host->descr) ? substr($old_host->descr, 0, 255) : null ]; + if (strpos($host_data['hostname'], '_') !== false) { + // legacy module accepted invalid hostnames with underscores. + $host_data['enabled'] = 0; + $host_data['hostname'] = str_replace('_', 'x', $host_data['hostname']); + $host_data['description'] = sprintf("disabled invalid record %s", $host_data['hostname']); + } $new_host->setNodes($host_data); @@ -77,7 +83,8 @@ class M1_0_1 extends BaseModelMigration 'enabled' => 1, 'host' => $uuid, 'domain' => !empty($old_alias->domain) ? $old_alias->domain : null, - 'hostname' => !empty($old_alias->host) ? $old_alias->host : null + 'hostname' => !empty($old_alias->host) ? $old_alias->host : null, + 'description' => !empty($old_alias->descr) ? substr($old_alias->descr, 0, 255) : null ]; $new_alias->setNodes($alias_data); } @@ -91,7 +98,7 @@ class M1_0_1 extends BaseModelMigration 'enabled' => 1, 'domain' => $old_domain->domain, 'server' => $old_domain->ip, - 'description' => !empty($old_domain->descr) ? $old_domain->descr : null + 'description' => !empty($old_domain->descr) ? substr($old_domain->descr, 0, 255) : null ]; $new_domain->setNodes($domain_data); } diff --git a/src/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml b/src/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml index 2de8d2e86..1cf57ff90 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml @@ -213,6 +213,11 @@ /^(?:(?:[a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*(?:[a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$/i A valid domain must be specified. + + N + /^(.){1,255}$/u + Description should be a string between 1 and 255 characters + diff --git a/src/opnsense/mvc/app/views/OPNsense/Unbound/overrides.volt b/src/opnsense/mvc/app/views/OPNsense/Unbound/overrides.volt index 8b0bac34e..032049bf4 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Unbound/overrides.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Unbound/overrides.volt @@ -246,6 +246,7 @@ $( document ).ready(function() { {{ lang._('Enabled') }} {{ lang._('Host') }} {{ lang._('Domain') }} + {{ lang._('Description') }} {{ lang._('Commands') }}