From bc39f262469c62e31916ca4a2476af931b643cb0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 24 Nov 2018 10:33:52 +0100 Subject: [PATCH] mail/postfix: add address rewriting (#1012) --- mail/postfix/Makefile | 3 +- mail/postfix/pkg-descr | 9 ++ .../OPNsense/Postfix/AddressController.php | 38 ++++++ .../Postfix/Api/AddressController.php | 67 +++++++++++ .../forms/dialogEditPostfixAddress.xml | 22 ++++ .../app/models/OPNsense/Postfix/Address.php | 30 +++++ .../app/models/OPNsense/Postfix/Address.xml | 21 ++++ .../app/models/OPNsense/Postfix/Menu/Menu.xml | 1 + .../app/views/OPNsense/Postfix/address.volt | 110 ++++++++++++++++++ .../scripts/OPNsense/Postfix/setup.sh | 1 + .../templates/OPNsense/Postfix/+TARGETS | 1 + .../templates/OPNsense/Postfix/main.cf | 1 + .../templates/OPNsense/Postfix/virtual | 9 ++ 13 files changed, 311 insertions(+), 2 deletions(-) create mode 100644 mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/AddressController.php create mode 100644 mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/AddressController.php create mode 100644 mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/forms/dialogEditPostfixAddress.xml create mode 100644 mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Address.php create mode 100644 mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Address.xml create mode 100644 mail/postfix/src/opnsense/mvc/app/views/OPNsense/Postfix/address.volt create mode 100644 mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/virtual diff --git a/mail/postfix/Makefile b/mail/postfix/Makefile index 53b7d6b24..961cd2ae7 100644 --- a/mail/postfix/Makefile +++ b/mail/postfix/Makefile @@ -1,6 +1,5 @@ PLUGIN_NAME= postfix -PLUGIN_VERSION= 1.6 -PLUGIN_REVISION= 1 +PLUGIN_VERSION= 1.7 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 1e96d0531..31d9213c7 100644 --- a/mail/postfix/pkg-descr +++ b/mail/postfix/pkg-descr @@ -2,4 +2,13 @@ Postfix attempts to be fast, easy to administer, and secure. The outside has a definite Sendmail-ish flavor, but the inside is completely different. + +Plugin Changelog +================ + +1.7 + +* Add Address Rewriting, allows to rewrite e.g. @example.com to @example.net. + + WWW: http://www.postfix.org/ diff --git a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/AddressController.php b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/AddressController.php new file mode 100644 index 000000000..668987631 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/AddressController.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 AddressController extends \OPNsense\Base\IndexController +{ + public function indexAction() + { + $this->view->formDialogEditPostfixAddress = $this->getForm("dialogEditPostfixAddress"); + $this->view->pick('OPNsense/Postfix/address'); + } +} diff --git a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/AddressController.php b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/AddressController.php new file mode 100644 index 000000000..6eb1739e5 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/AddressController.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 AddressController extends ApiMutableModelControllerBase +{ + static protected $internalModelName = 'address'; + static protected $internalModelClass = '\OPNsense\Postfix\Address'; + + public function searchAddressAction() + { + return $this->searchBase('addresses.address', array("enabled", "from", "to")); + } + + public function getAddressAction($uuid = null) + { + return $this->getBase('address', 'addresses.address', $uuid); + } + + public function addAddressAction() + { + return $this->addBase('address', 'addresses.address'); + } + + public function delAddressAction($uuid) + { + return $this->delBase('addresses.address', $uuid); + } + + public function setAddressAction($uuid) + { + return $this->setBase('address', 'addresses.address', $uuid); + } + + public function toggleAddressAction($uuid) + { + return $this->toggleBase('addresses.address', $uuid); + } +} diff --git a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/forms/dialogEditPostfixAddress.xml b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/forms/dialogEditPostfixAddress.xml new file mode 100644 index 000000000..735af7661 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/forms/dialogEditPostfixAddress.xml @@ -0,0 +1,22 @@ +
+ + address.enabled + + checkbox + This will enable or disable the address rewriting setting. + + + address.from + + text + Set a pattern to match line user@example.com or @example.com + + + address.to + + + select_multiple + true + Set here how to rewrite the Rewrite From pattern. + +
diff --git a/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Address.php b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Address.php new file mode 100644 index 000000000..688ae41d3 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Address.php @@ -0,0 +1,30 @@ + + 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 Address extends BaseModel +{ +} diff --git a/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Address.xml b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Address.xml new file mode 100644 index 000000000..ffaf8c949 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Address.xml @@ -0,0 +1,21 @@ + + //OPNsense/postfix/address + Postfix address rewrite configuration + 1.0.0 + + +
+ + 1 + Y + + + Y + + + Y + +
+
+
+
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 3634a132e..ff4e69047 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 @@ -5,6 +5,7 @@ +
diff --git a/mail/postfix/src/opnsense/mvc/app/views/OPNsense/Postfix/address.volt b/mail/postfix/src/opnsense/mvc/app/views/OPNsense/Postfix/address.volt new file mode 100644 index 000000000..39ba106e9 --- /dev/null +++ b/mail/postfix/src/opnsense/mvc/app/views/OPNsense/Postfix/address.volt @@ -0,0 +1,110 @@ +{# + +OPNsense® is Copyright © 2014 – 2017 by Deciso B.V. +Copyright (C) 2018 Michael Muenz +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._('Rewrite From') }}{{ lang._('Rewrite To') }}{{ lang._('ID') }}{{ lang._('Commands') }}
+ + +
+
+
+
+ +

+
+
+ +{{ partial("layout_partials/base_dialog",['fields':formDialogEditPostfixAddress,'id':'dialogEditPostfixAddress','label':lang._('Edit Address Rewriting')])}} diff --git a/mail/postfix/src/opnsense/scripts/OPNsense/Postfix/setup.sh b/mail/postfix/src/opnsense/scripts/OPNsense/Postfix/setup.sh index a907a1d71..3022bdf01 100755 --- a/mail/postfix/src/opnsense/scripts/OPNsense/Postfix/setup.sh +++ b/mail/postfix/src/opnsense/scripts/OPNsense/Postfix/setup.sh @@ -28,6 +28,7 @@ chown -R root:postfix /var/spool/postfix/pid # Create Transporttable postmap /usr/local/etc/postfix/transport +postmap /usr/local/etc/postfix/virtual postmap /usr/local/etc/postfix/recipient_access postmap /usr/local/etc/postfix/sender_access postmap /usr/local/etc/postfix/smtp_auth diff --git a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/+TARGETS b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/+TARGETS index dc01e21fd..3065898ab 100644 --- a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/+TARGETS +++ b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/+TARGETS @@ -2,6 +2,7 @@ main.cf:/usr/local/etc/postfix/main.cf master.cf:/usr/local/etc/postfix/master.cf postfix:/etc/rc.conf.d/postfix transport:/usr/local/etc/postfix/transport +virtual:/usr/local/etc/postfix/virtual recipient_access:/usr/local/etc/postfix/recipient_access sender_access:/usr/local/etc/postfix/sender_access smtp_auth:/usr/local/etc/postfix/smtp_auth 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 03f83f8d4..57e09c05e 100644 --- a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/main.cf +++ b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/main.cf @@ -31,6 +31,7 @@ meta_directory = /usr/local/libexec/postfix shlib_directory = /usr/local/lib/postfix relay_domains = hash:/usr/local/etc/postfix/transport transport_maps = hash:/usr/local/etc/postfix/transport +virtual_alias_maps = hash:/usr/local/etc/postfix/virtual ########################## # END SYSTEM DEFAULTS ########################## diff --git a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/virtual b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/virtual new file mode 100644 index 000000000..332ab933d --- /dev/null +++ b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/virtual @@ -0,0 +1,9 @@ +{% if helpers.exists('OPNsense.postfix.general.enabled') and OPNsense.postfix.general.enabled == '1' %} +{% if helpers.exists('OPNsense.postfix.address.addresses.address') %} +{% for address in helpers.toList('OPNsense.postfix.address.addresses.address') %} +{% if address.enabled == '1' %} +{{ address.from }} {{ address.to }} +{% endif %} +{% endfor %} +{% endif %} +{% endif %}