forked from opnsense/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mail/postfix: Add support for header_checks (opnsense#1897)
- Loading branch information
1 parent
9078aea
commit d6257b1
Showing
13 changed files
with
296 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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= [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/HeaderchecksController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/HeaderchecksController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../src/opnsense/mvc/app/controllers/OPNsense/Postfix/forms/dialogEditPostfixHeadercheck.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
31 changes: 31 additions & 0 deletions
31
mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
} |
25 changes: 25 additions & 0 deletions
25
mail/postfix/src/opnsense/mvc/app/models/OPNsense/Postfix/Headerchecks.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
mail/postfix/src/opnsense/mvc/app/views/OPNsense/Postfix/headerchecks.volt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')])}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_delivering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} |
9 changes: 9 additions & 0 deletions
9
mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/header_checks_receiving
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters