mail/postfix: add address rewriting (#1012)

This commit is contained in:
Michael
2018-11-24 10:33:52 +01:00
committed by Franco Fichtner
parent 820b89ecd2
commit bc39f26246
13 changed files with 311 additions and 2 deletions
+1 -2
View File
@@ -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
+9
View File
@@ -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/
@@ -0,0 +1,38 @@
<?php
/*
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
* 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');
}
}
@@ -0,0 +1,67 @@
<?php
/*
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
* 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);
}
}
@@ -0,0 +1,22 @@
<form>
<field>
<id>address.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>This will enable or disable the address rewriting setting.</help>
</field>
<field>
<id>address.from</id>
<label>Rewrite From</label>
<type>text</type>
<help>Set a pattern to match line user@example.com or @example.com</help>
</field>
<field>
<id>address.to</id>
<label>Rewrite To</label>
<style>tokenize</style>
<type>select_multiple</type>
<allownew>true</allownew>
<help>Set here how to rewrite the Rewrite From pattern.</help>
</field>
</form>
@@ -0,0 +1,30 @@
<?php
namespace OPNsense\Postfix;
use OPNsense\Base\BaseModel;
/*
Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
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
{
}
@@ -0,0 +1,21 @@
<model>
<mount>//OPNsense/postfix/address</mount>
<description>Postfix address rewrite configuration</description>
<version>1.0.0</version>
<items>
<addresses>
<address type="ArrayField">
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<from type="TextField">
<Required>Y</Required>
</from>
<to type="CSVListField">
<Required>Y</Required>
</to>
</address>
</addresses>
</items>
</model>
@@ -5,6 +5,7 @@
<Domains url="/ui/postfix/domain/index" order="20"/>
<Recipients url="/ui/postfix/recipient/index" order="30"/>
<Senders url="/ui/postfix/sender/index" order="40"/>
<Address VisibleName="Address Rewriting" url="/ui/postfix/address/index" order="50"/>
<LogFile VisibleName="Log File" order="50" url="/diag_logs_postfix.php"/>
</Postfix>
</Services>
@@ -0,0 +1,110 @@
{#
OPNsense® is Copyright © 2014 2017 by Deciso B.V.
Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
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.
#}
<script>
$( document ).ready(function() {
/*************************************************************************************************************
* link grid actions
*************************************************************************************************************/
$("#grid-addresses").UIBootgrid(
{ 'search':'/api/postfix/address/searchAddress',
'get':'/api/postfix/address/getAddress/',
'set':'/api/postfix/address/setAddress/',
'add':'/api/postfix/address/addAddress/',
'del':'/api/postfix/address/delAddress/',
'toggle':'/api/postfix/address/toggleAddress/'
}
);
/*************************************************************************************************************
* Commands
*************************************************************************************************************/
/**
* Reconfigure
*/
$("#reconfigureAct").click(function(){
$("#reconfigureAct_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall("/api/postfix/service/reconfigure", {}, function(data,status) {
// when done, disable progress animation.
$("#reconfigureAct_progress").removeClass("fa fa-spinner fa-pulse");
if (status != "success" || data['status'] != 'ok') {
BootstrapDialog.show({
type: BootstrapDialog.TYPE_WARNING,
title: "{{ lang._('Error reconfiguring Postfix') }}",
message: data['status'],
draggable: true
});
} else {
ajaxCall("/api/postfix/service/reconfigure", {});
}
});
});
});
</script>
<div class="tab-content content-box tab-content">
<div id="addresses" class="tab-pane fade in active">
<!-- tab page "addresses" -->
<table id="grid-addresses" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="dialogEditPostfixAddress">
<thead>
<tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="from" data-type="string" data-visible="true">{{ lang._('Rewrite From') }}</th>
<th data-column-id="to" data-type="string" data-visible="true">{{ lang._('Rewrite To') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th> </tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
</div>
<div class="col-md-12">
<hr/>
<button class="btn btn-primary" id="reconfigureAct" type="button"><b>{{ lang._('Apply') }}</b> <i id="reconfigureAct_progress" class=""></i></button>
<br/><br/>
</div>
</div>
{{ partial("layout_partials/base_dialog",['fields':formDialogEditPostfixAddress,'id':'dialogEditPostfixAddress','label':lang._('Edit Address Rewriting')])}}
@@ -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
@@ -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
@@ -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
##########################
@@ -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 %}