From 1c952b3f7ca2baae8712fdee0fa23116f9fe6676 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 25 Mar 2020 15:14:08 +0100 Subject: [PATCH] os-firewall: move mountpoint for https://github.com/opnsense/plugins/issues/1749 It's probably better to keep (filter)rules and source nat rules combined, so we can stick to the same rollback pattern and guarantee a consistent set when performing a rollback. --- .../app/models/OPNsense/Firewall/Filter.xml | 4 +- .../OPNsense/Firewall/Migrations/MFP1_0_0.php | 57 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 net/firewall/src/opnsense/mvc/app/models/OPNsense/Firewall/Migrations/MFP1_0_0.php diff --git a/net/firewall/src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.xml b/net/firewall/src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.xml index 3e4ac83737..378926025b 100644 --- a/net/firewall/src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.xml +++ b/net/firewall/src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.xml @@ -1,5 +1,7 @@ - //OPNsense/Firewall/FilterRule + //OPNsense/Firewall/Filter + 1.0.0 + MFP OPNsense firewall filter rules diff --git a/net/firewall/src/opnsense/mvc/app/models/OPNsense/Firewall/Migrations/MFP1_0_0.php b/net/firewall/src/opnsense/mvc/app/models/OPNsense/Firewall/Migrations/MFP1_0_0.php new file mode 100644 index 0000000000..d6118f1e51 --- /dev/null +++ b/net/firewall/src/opnsense/mvc/app/models/OPNsense/Firewall/Migrations/MFP1_0_0.php @@ -0,0 +1,57 @@ +Firewall->FilterRule ---> OPNsense->Firewall->Filter + $cfgObj = Config::getInstance()->object(); + if (!empty($cfgObj->OPNsense) && !empty($cfgObj->OPNsense->Firewall) + && !empty($cfgObj->OPNsense->Firewall->FilterRule)) { + // model migration created a new, empty rules section + if (empty($cfgObj->OPNsense->Firewall->Filter->rules)) { + unset($cfgObj->OPNsense->Firewall->Filter->rules); + $targetdom = dom_import_simplexml($cfgObj->OPNsense->Firewall->Filter); + foreach ($cfgObj->OPNsense->Firewall->FilterRule->children() as $child) { + $sourcedom = dom_import_simplexml($child); + $targetdom->appendChild($sourcedom); + } + unset($cfgObj->OPNsense->Firewall->FilterRule); + Config::getInstance()->save(); + } + } + } +} \ No newline at end of file