From 1897803d1f8820cde8af05ec261c14e3f411f9bd Mon Sep 17 00:00:00 2001 From: Monviech <79600909+Monviech@users.noreply.github.com> Date: Mon, 22 Apr 2024 08:28:43 +0200 Subject: [PATCH] www/caddy: Create Migration script that fixes issue with Caddy not being able to start. (Regression in 1.5.4) (#3931) * Create M1_1_7.php This migration script empties out "on" and "none" options that were replaced with empty values by this pull request. It fixes the regression that Caddy will refuse to start because invalid values for AutoHttps and DnsProvider will remain stored in the config without a manual config change from the user. Compare to: https://github.com/opnsense/plugins/commit/a628ebfc0682c0f27ec59b6a605dbeff8bd52765 Issue was tracked multiple times: https://forum.opnsense.org/index.php?topic=40075.0 https://github.com/opnsense/plugins/pull/3930 https://github.com/opnsense/plugins/issues/3917#issuecomment-2064230068 * Bump Migration script and Model version to 1.1.8 --- www/caddy/Makefile | 1 + .../mvc/app/models/OPNsense/Caddy/Caddy.xml | 2 +- .../OPNsense/Caddy/Migrations/M1_1_8.php | 71 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Migrations/M1_1_8.php diff --git a/www/caddy/Makefile b/www/caddy/Makefile index a2694d60a..2623a7479 100644 --- a/www/caddy/Makefile +++ b/www/caddy/Makefile @@ -1,5 +1,6 @@ PLUGIN_NAME= caddy PLUGIN_VERSION= 1.5.4 +PLUGIN_REVISION= 1 PLUGIN_DEPENDS= caddy-custom PLUGIN_COMMENT= Easy to configure Reverse Proxy with Automatic HTTPS and Dynamic DNS PLUGIN_MAINTAINER= cedrik@pischem.com diff --git a/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.xml b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.xml index 843e60d75..af002c9ea 100644 --- a/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.xml +++ b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.xml @@ -1,7 +1,7 @@ //Pischem/caddy A GUI model for configuring a reverse proxy in the Caddy web server. - 1.1.7 + 1.1.8 diff --git a/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Migrations/M1_1_8.php b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Migrations/M1_1_8.php new file mode 100644 index 000000000..0687d49ab --- /dev/null +++ b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Migrations/M1_1_8.php @@ -0,0 +1,71 @@ +object(); + + // Read and migrate TlsAutoHttps setting if necessary + if (!empty($config->Pischem->caddy->general->TlsAutoHttps)) { + $tlsAutoHttpsValue = (string)$config->Pischem->caddy->general->TlsAutoHttps; + // Check if the current value is 'on' and needs to be migrated + if ($tlsAutoHttpsValue === 'on') { + // Locate the corresponding node in the model + $modelNode = $model->getNodeByReference('general.TlsAutoHttps'); + if ($modelNode != null) { + // Set to empty value in the model, migration from 'on' to '' + $modelNode->setValue(''); + } + } + } + + // Read and migrate TlsDnsProvider setting if necessary + if (!empty($config->Pischem->caddy->general->TlsDnsProvider)) { + $tlsDnsProviderValue = (string)$config->Pischem->caddy->general->TlsDnsProvider; + // Check if the current value is 'none' and needs to be migrated + if ($tlsDnsProviderValue === 'none') { + // Locate the corresponding node in the model + $modelNode = $model->getNodeByReference('general.TlsDnsProvider'); + if ($modelNode != null) { + // Set to empty value in the model, migration from 'none' to '' + $modelNode->setValue(''); + } + } + } + + // Model is saved by 'run_migrations.php' + } +}