mail/postfix: Add support for header_checks (#1897)

This commit is contained in:
Starkstromkonsument
2020-09-11 09:28:12 +02:00
committed by GitHub
parent 9078aea515
commit d6257b1579
13 changed files with 296 additions and 1 deletions
+1 -1
View File
@@ -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
+4
View File
@@ -6,6 +6,10 @@ is completely different.
Plugin Changelog
================
1.16
* Add support for header_checks (Starkstromkonsument <https://github.com/Starkstromkonsument>)
1.15
* Fix Log viewer
@@ -0,0 +1,67 @@
<?php
/*
* Copyright (C) 2020 Starkstromkonsument <https://github.com/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.
*/
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);
}
}
@@ -0,0 +1,38 @@
<?php
/*
* Copyright (C) 2020 Starkstromkonsument <https://github.com/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.
*/
namespace OPNsense\Postfix;
class HeaderchecksController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->formDialogEditPostfixHeadercheck = $this->getForm("dialogEditPostfixHeadercheck");
$this->view->pick('OPNsense/Postfix/headerchecks');
}
}
@@ -0,0 +1,21 @@
<form>
<field>
<id>headercheck.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>This will enable or disable the header_check rule.</help>
</field>
<field>
<id>headercheck.expression</id>
<label>Expression</label>
<type>text</type>
<help><![CDATA[Set a regexp (POSIX regular expression) and an action to process like <pre>/^\s*User-Agent/ IGNORE</pre>Note: The regexp is not validated by this form. Please test it carefully.]]></help>
</field>
<field>
<id>headercheck.filter</id>
<label>Process filter</label>
<type>dropdown</type>
<help><![CDATA[Set when the header_check should be processed.<br>See the <a href="http://www.postfix.org/header_checks.5.html" target="_blank">Postfix manual about header_checks(5)</a>]]></help>
<hint>RECEIVING = header_checks / DELIVERING = smtp_header_checks</hint>
</field>
</form>
@@ -0,0 +1,31 @@
<?php
namespace OPNsense\Postfix;
use OPNsense\Base\BaseModel;
/*
Copyright (C) 2020 Starkstromkonsument <https://github.com/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.
*/
class Headerchecks extends BaseModel
{
}
@@ -0,0 +1,25 @@
<model>
<mount>//OPNsense/postfix/headerchecks</mount>
<description>Postfix header_checks configuration</description>
<version>1.0.0</version>
<items>
<headerchecks>
<headercheck type="ArrayField">
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<expression type="TextField">
<Required>Y</Required>
</expression>
<filter type="OptionField">
<Required>Y</Required>
<OptionValues>
<WHILE_DELIVERING>while delivering mail</WHILE_DELIVERING>
<WHILE_RECEIVING>while receiving mail</WHILE_RECEIVING>
</OptionValues>
</filter>
</headercheck>
</headerchecks>
</items>
</model>
@@ -8,6 +8,7 @@
<Senders url="/ui/postfix/sender/index" order="40"/>
<Senderbcc VisibleName="Sender BCC" url="/ui/postfix/senderbcc/index" order="45"/>
<Sendercanonical VisibleName="Sender Canonical Rewriting" url="/ui/postfix/sendercanonical/index" order="48"/>
<Headerchecks VisibleName="Header Checks" url="/ui/postfix/headerchecks/index" order="49"/>
<Address VisibleName="Address Rewriting" url="/ui/postfix/address/index" order="50"/>
<LogFile VisibleName="Log File" order="50" url="/ui/diagnostics/log/core/postfix"/>
</Postfix>
@@ -0,0 +1,86 @@
{#
OPNsense® is Copyright © 2014 2017 by Deciso B.V.
Copyright (C) 2020 Starkstromkonsument <https://github.com/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.
#}
<script>
$( document ).ready(function() {
/*************************************************************************************************************
* link grid actions
*************************************************************************************************************/
$("#grid-headerchecks").UIBootgrid(
{ 'search':'/api/postfix/headerchecks/searchHeaderchecks',
'get':'/api/postfix/headerchecks/getHeadercheck/',
'set':'/api/postfix/headerchecks/setHeadercheck/',
'add':'/api/postfix/headerchecks/addHeadercheck/',
'del':'/api/postfix/headerchecks/delHeadercheck/',
'toggle':'/api/postfix/headerchecks/toggleHeadercheck/'
}
);
{% include 'OPNsense/Postfix/apply.volt' %}
});
</script>
<div class="tab-content content-box tab-content">
<div id="headerchecks" class="tab-pane fade in active">
<!-- tab page "headerchecks" -->
<table id="grid-headerchecks" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="dialogEditPostfixHeadercheck">
<thead>
<tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="expression" data-type="string" data-visible="true">{{ lang._('Expression') }}</th>
<th data-column-id="filter" data-type="string" data-visible="true">{{ lang._('Filter') }}</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 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>
</div>
{{ partial("layout_partials/base_dialog",['fields':formDialogEditPostfixHeadercheck,'id':'dialogEditPostfixHeadercheck','label':lang._('Edit header_check rule')])}}
@@ -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
@@ -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 %}
@@ -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 %}
@@ -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
##########################