From d6257b15791f2108c6c366283bd8a3a70a7d9f07 Mon Sep 17 00:00:00 2001 From: Starkstromkonsument Date: Fri, 11 Sep 2020 09:28:12 +0200 Subject: [PATCH] mail/postfix: Add support for header_checks (#1897) --- mail/postfix/Makefile | 2 +- mail/postfix/pkg-descr | 4 + .../Postfix/Api/HeaderchecksController.php | 67 +++++++++++++++ .../Postfix/HeaderchecksController.php | 38 ++++++++ .../forms/dialogEditPostfixHeadercheck.xml | 21 +++++ .../models/OPNsense/Postfix/Headerchecks.php | 31 +++++++ .../models/OPNsense/Postfix/Headerchecks.xml | 25 ++++++ .../app/models/OPNsense/Postfix/Menu/Menu.xml | 1 + .../views/OPNsense/Postfix/headerchecks.volt | 86 +++++++++++++++++++ .../templates/OPNsense/Postfix/+TARGETS | 2 + .../OPNsense/Postfix/header_checks_delivering | 9 ++ .../OPNsense/Postfix/header_checks_receiving | 9 ++ .../templates/OPNsense/Postfix/main.cf | 2 + 13 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/HeaderchecksController.php create mode 100644 mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/HeaderchecksController.php create mode 100644 mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/forms/dialogEditPostfixHeadercheck.xml create mode 100644 mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.php create mode 100644 mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.xml create mode 100644 mail/postfix/src/opnsense/mvc/app/views/OPNsense/Postfix/headerchecks.volt create mode 100644 mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_delivering create mode 100644 mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_receiving diff --git a/mail/postfix/Makefile b/mail/postfix/Makefile index 51aede132..a87fa354d 100644 --- a/mail/postfix/Makefile +++ b/mail/postfix/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= postfix -PLUGIN_VERSION= 1.15 +PLUGIN_VERSION= 1.16 PLUGIN_COMMENT= SMTP mail relay PLUGIN_DEPENDS= postfix-sasl PLUGIN_MAINTAINER= m.muenz@gmail.com diff --git a/mail/postfix/pkg-descr b/mail/postfix/pkg-descr index 7ebc7a2d4..8188ee8b7 100644 --- a/mail/postfix/pkg-descr +++ b/mail/postfix/pkg-descr @@ -6,6 +6,10 @@ is completely different. Plugin Changelog ================ +1.16 + +* Add support for header_checks (Starkstromkonsument ) + 1.15 * Fix Log viewer diff --git a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/HeaderchecksController.php b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/HeaderchecksController.php new file mode 100644 index 000000000..0ff6e04f9 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/HeaderchecksController.php @@ -0,0 +1,67 @@ + + * 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\Postfix\Api; + +use OPNsense\Base\ApiMutableModelControllerBase; + +class HeaderchecksController extends ApiMutableModelControllerBase +{ + protected static $internalModelName = 'headerchecks'; + protected static $internalModelClass = '\OPNsense\Postfix\Headerchecks'; + + public function searchHeaderchecksAction() + { + return $this->searchBase('headerchecks.headercheck', array("enabled", "expression", "filter")); + } + + public function getHeadercheckAction($uuid = null) + { + return $this->getBase('headercheck', 'headerchecks.headercheck', $uuid); + } + + public function addHeadercheckAction() + { + return $this->addBase('headercheck', 'headerchecks.headercheck'); + } + + public function delHeadercheckAction($uuid) + { + return $this->delBase('headerchecks.headercheck', $uuid); + } + + public function setHeadercheckAction($uuid) + { + return $this->setBase('headercheck', 'headerchecks.headercheck', $uuid); + } + + public function toggleHeadercheckAction($uuid) + { + return $this->toggleBase('headerchecks.headercheck', $uuid); + } +} diff --git a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/HeaderchecksController.php b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/HeaderchecksController.php new file mode 100644 index 000000000..8c42454d1 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/HeaderchecksController.php @@ -0,0 +1,38 @@ + + * 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\Postfix; + +class HeaderchecksController extends \OPNsense\Base\IndexController +{ + public function indexAction() + { + $this->view->formDialogEditPostfixHeadercheck = $this->getForm("dialogEditPostfixHeadercheck"); + $this->view->pick('OPNsense/Postfix/headerchecks'); + } +} diff --git a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/forms/dialogEditPostfixHeadercheck.xml b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/forms/dialogEditPostfixHeadercheck.xml new file mode 100644 index 000000000..bde023d7d --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/forms/dialogEditPostfixHeadercheck.xml @@ -0,0 +1,21 @@ +
+ + headercheck.enabled + + checkbox + This will enable or disable the header_check rule. + + + headercheck.expression + + text + /^\s*User-Agent/ IGNORENote: The regexp is not validated by this form. Please test it carefully.]]> + + + headercheck.filter + + dropdown + See the Postfix manual about header_checks(5)]]> + RECEIVING = header_checks / DELIVERING = smtp_header_checks + +
diff --git a/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.php b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.php new file mode 100644 index 000000000..c55a4646b --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.php @@ -0,0 +1,31 @@ + + 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. +*/ + +class Headerchecks extends BaseModel +{ +} diff --git a/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.xml b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.xml new file mode 100644 index 000000000..8e8b48377 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.xml @@ -0,0 +1,25 @@ + + //OPNsense/postfix/headerchecks + Postfix header_checks configuration + 1.0.0 + + + + + 1 + Y + + + Y + + + Y + + while delivering mail + while receiving mail + + + + + + diff --git a/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Menu/Menu.xml b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Menu/Menu.xml index d8aa47989..9e88d86a1 100644 --- a/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Menu/Menu.xml +++ b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Menu/Menu.xml @@ -8,6 +8,7 @@ +
diff --git a/mail/postfix/src/opnsense/mvc/app/views/OPNsense/Postfix/headerchecks.volt b/mail/postfix/src/opnsense/mvc/app/views/OPNsense/Postfix/headerchecks.volt new file mode 100644 index 000000000..320fb4fa0 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/views/OPNsense/Postfix/headerchecks.volt @@ -0,0 +1,86 @@ +{# + +OPNsense® is Copyright © 2014 – 2017 by Deciso B.V. +Copyright (C) 2020 Starkstromkonsument +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. + +#} + + + +
+
+ + + + + + + + + + + + + + + + + + + +
{{ lang._('Enabled') }}{{ lang._('Expression') }}{{ lang._('Filter') }}{{ lang._('ID') }}{{ lang._('Commands') }}
+ + +
+
+
+ +

+
+
+
+ +{{ partial("layout_partials/base_dialog",['fields':formDialogEditPostfixHeadercheck,'id':'dialogEditPostfixHeadercheck','label':lang._('Edit header_check rule')])}} diff --git a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/+TARGETS b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/+TARGETS index 9d7dca3cd..a1de27fd6 100644 --- a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/+TARGETS +++ b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/+TARGETS @@ -9,3 +9,5 @@ senderbcc:/usr/local/etc/postfix/senderbcc recipientbcc:/usr/local/etc/postfix/recipientbcc smtp_auth:/usr/local/etc/postfix/smtp_auth sendercanonical:/usr/local/etc/postfix/sendercanonical +header_checks_delivering:/usr/local/etc/postfix/header_checks_delivering +header_checks_receiving:/usr/local/etc/postfix/header_checks_receiving diff --git a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_delivering b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_delivering new file mode 100644 index 000000000..0e53f977b --- /dev/null +++ b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_delivering @@ -0,0 +1,9 @@ +{% if helpers.exists('OPNsense.postfix.general.enabled') and OPNsense.postfix.general.enabled == '1' %} +{% if helpers.exists('OPNsense.postfix.headerchecks.headerchecks.headercheck') %} +{% for headercheck_list in helpers.toList('OPNsense.postfix.headerchecks.headerchecks.headercheck') %} +{% if headercheck_list.enabled == '1' and headercheck_list.filter == 'WHILE_DELIVERING' %} +{{ headercheck_list.expression }} +{% endif %} +{% endfor %} +{% endif %} +{% endif %} diff --git a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_receiving b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_receiving new file mode 100644 index 000000000..320e7300c --- /dev/null +++ b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_receiving @@ -0,0 +1,9 @@ +{% if helpers.exists('OPNsense.postfix.general.enabled') and OPNsense.postfix.general.enabled == '1' %} +{% if helpers.exists('OPNsense.postfix.headerchecks.headerchecks.headercheck') %} +{% for headercheck_list in helpers.toList('OPNsense.postfix.headerchecks.headerchecks.headercheck') %} +{% if headercheck_list.enabled == '1' and headercheck_list.filter == 'WHILE_RECEIVING' %} +{{ headercheck_list.expression }} +{% endif %} +{% endfor %} +{% endif %} +{% endif %} diff --git a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/main.cf b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/main.cf index d74434602..69f314b71 100644 --- a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/main.cf +++ b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/main.cf @@ -35,6 +35,8 @@ virtual_alias_maps = hash:/usr/local/etc/postfix/virtual sender_bcc_maps = hash:/usr/local/etc/postfix/senderbcc recipient_bcc_maps = hash:/usr/local/etc/postfix/recipientbcc sender_canonical_maps = regexp:/usr/local/etc/postfix/sendercanonical +header_checks = regexp:/usr/local/etc/postfix/header_checks_receiving +smtp_header_checks = regexp:/usr/local/etc/postfix/header_checks_delivering ########################## # END SYSTEM DEFAULTS ##########################