mirror of
https://github.com/opnsense/plugins.git
synced 2026-06-08 16:34:18 -04:00
mail/postfix: add version 1.1 from master
This commit is contained in:
parent
b36fce3da8
commit
543e51f7ee
11 changed files with 175 additions and 564 deletions
|
|
@ -1,5 +1,5 @@
|
|||
PLUGIN_NAME= postfix
|
||||
PLUGIN_VERSION= 1.0
|
||||
PLUGIN_VERSION= 1.1
|
||||
PLUGIN_COMMENT= SMTP mail relay
|
||||
PLUGIN_DEPENDS= postfix-sasl
|
||||
PLUGIN_MAINTAINER= m.muenz@gmail.com
|
||||
|
|
|
|||
|
|
@ -1,76 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 - 2017 Deciso B.V.
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
* Copyright (C) 2018 Fabian Franz
|
||||
* All rights reserved.
|
||||
*
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* 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\ApiControllerBase;
|
||||
use \OPNsense\Postfix\Antispam;
|
||||
use \OPNsense\Core\Config;
|
||||
use \OPNsense\Base\ApiMutableModelControllerBase;
|
||||
|
||||
class AntispamController extends ApiControllerBase
|
||||
class AntispamController extends ApiMutableModelControllerBase
|
||||
{
|
||||
public function getAction()
|
||||
{
|
||||
// define list of configurable settings
|
||||
$result = array();
|
||||
if ($this->request->isGet()) {
|
||||
$mdlAntispam = new Antispam();
|
||||
$result['antispam'] = $mdlAntispam->getNodes();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setAction()
|
||||
{
|
||||
$result = array("result"=>"failed");
|
||||
if ($this->request->isPost()) {
|
||||
// load model and update with provided data
|
||||
$mdlAntispam = new Antispam();
|
||||
$mdlAntispam->setNodes($this->request->getPost("antispam"));
|
||||
|
||||
// perform validation
|
||||
$valMsgs = $mdlAntispam->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
if (!array_key_exists("validations", $result)) {
|
||||
$result["validations"] = array();
|
||||
}
|
||||
$result["validations"]["antispam.".$msg->getField()] = $msg->getMessage();
|
||||
}
|
||||
|
||||
// serialize model to config and save
|
||||
if ($valMsgs->count() == 0) {
|
||||
$mdlAntispam->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result["result"] = "saved";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
static protected $internalModelName = 'antispam';
|
||||
static protected $internalModelClass = '\OPNsense\Postfix\Antispam';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,205 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 - 2017 Deciso B.V.
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
* Copyright (C) 2018 Fabian Franz
|
||||
* All rights reserved.
|
||||
*
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* 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\Postfix\Domain;
|
||||
use \OPNsense\Core\Config;
|
||||
use \OPNsense\Base\ApiMutableModelControllerBase;
|
||||
use \OPNsense\Base\UIModelGrid;
|
||||
|
||||
class DomainController extends ApiMutableModelControllerBase
|
||||
{
|
||||
static protected $internalModelName = 'Domain';
|
||||
static protected $internalModelName = 'domain';
|
||||
static protected $internalModelClass = '\OPNsense\Postfix\Domain';
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
// define list of configurable settings
|
||||
$result = array();
|
||||
if ($this->request->isGet()) {
|
||||
$mdlDomain = new Domain();
|
||||
$result['domain'] = $mdlDomain->getNodes();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setAction()
|
||||
{
|
||||
$result = array("result"=>"failed");
|
||||
if ($this->request->isPost()) {
|
||||
// load model and update with provided data
|
||||
$mdlDomain = new Domain();
|
||||
$mdlDomain->setNodes($this->request->getPost("domain"));
|
||||
// perform validation
|
||||
$valMsgs = $mdlDomain->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
if (!array_key_exists("validations", $result)) {
|
||||
$result["validations"] = array();
|
||||
}
|
||||
$result["validations"]["domain.".$msg->getField()] = $msg->getMessage();
|
||||
}
|
||||
// serialize model to config and save
|
||||
if ($valMsgs->count() == 0) {
|
||||
$mdlDomain->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result["result"] = "saved";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function searchDomainAction()
|
||||
{
|
||||
$this->sessionClose();
|
||||
$mdlDomain = $this->getModel();
|
||||
$grid = new UIModelGrid($mdlDomain->domains->domain);
|
||||
return $grid->fetchBindRequest(
|
||||
$this->request,
|
||||
array("enabled", "domainname", "destination" )
|
||||
);
|
||||
return $this->searchBase('domains.domain', array("enabled", "domainname", "destination"));
|
||||
}
|
||||
|
||||
public function getDomainAction($uuid = null)
|
||||
{
|
||||
$mdlDomain = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlDomain->getNodeByReference('domains.domain.' . $uuid);
|
||||
if ($node != null) {
|
||||
// return node
|
||||
return array("domain" => $node->getNodes());
|
||||
}
|
||||
} else {
|
||||
$node = $mdlDomain->domains->domain->add();
|
||||
return array("domain" => $node->getNodes());
|
||||
}
|
||||
return array();
|
||||
return $this->getBase('domain', 'domains.domain', $uuid);
|
||||
}
|
||||
|
||||
public function addDomainAction()
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost() && $this->request->hasPost("domain")) {
|
||||
$result = array("result" => "failed", "validations" => array());
|
||||
$mdlDomain = $this->getModel();
|
||||
$node = $mdlDomain->domains->domain->Add();
|
||||
$node->setNodes($this->request->getPost("domain"));
|
||||
$valMsgs = $mdlDomain->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, "domain", $msg->getField());
|
||||
$result["validations"][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
if (count($result['validations']) == 0) {
|
||||
unset($result['validations']);
|
||||
// save config if validated correctly
|
||||
$mdlDomain->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
unset($result['validations']);
|
||||
$result["result"] = "saved";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->addBase('domain', 'domains.domain');
|
||||
}
|
||||
|
||||
public function delDomainAction($uuid)
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost()) {
|
||||
$mdlDomain = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
if ($mdlDomain->domains->domain->del($uuid)) {
|
||||
$mdlDomain->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result['result'] = 'deleted';
|
||||
} else {
|
||||
$result['result'] = 'not found';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->delBase('domains.domain', $uuid);
|
||||
}
|
||||
|
||||
public function setDomainAction($uuid)
|
||||
{
|
||||
if ($this->request->isPost() && $this->request->hasPost("domain")) {
|
||||
$mdlSetting = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlSetting->getNodeByReference('domains.domain.' . $uuid);
|
||||
if ($node != null) {
|
||||
$result = array("result" => "failed", "validations" => array());
|
||||
$domainInfo = $this->request->getPost("domain");
|
||||
$node->setNodes($domainInfo);
|
||||
$valMsgs = $mdlSetting->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, "domain", $msg->getField());
|
||||
$result["validations"][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
if (count($result['validations']) == 0) {
|
||||
// save config if validated correctly
|
||||
$mdlSetting->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result = array("result" => "saved");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array("result" => "failed");
|
||||
}
|
||||
|
||||
public function toggle_handler($uuid, $elements, $element)
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost()) {
|
||||
$mdlSetting = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlSetting->getNodeByReference($elements . '.'. $element .'.' . $uuid);
|
||||
if ($node != null) {
|
||||
if ($node->enabled->__toString() == "1") {
|
||||
$result['result'] = "Disabled";
|
||||
$node->enabled = "0";
|
||||
} else {
|
||||
$result['result'] = "Enabled";
|
||||
$node->enabled = "1";
|
||||
}
|
||||
// if item has toggled, serialize to config and save
|
||||
$mdlSetting->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->setBase('domain', 'domains.domain', $uuid);
|
||||
}
|
||||
|
||||
public function toggleDomainAction($uuid)
|
||||
{
|
||||
return $this->toggle_handler($uuid, 'domains', 'domain');
|
||||
return $this->toggleBase('domains.domain', $uuid);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,205 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 - 2017 Deciso B.V.
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
* Copyright (C) 2018 Fabian Franz
|
||||
* All rights reserved.
|
||||
*
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* 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\Postfix\Recipient;
|
||||
use \OPNsense\Core\Config;
|
||||
use \OPNsense\Base\ApiMutableModelControllerBase;
|
||||
use \OPNsense\Base\UIModelGrid;
|
||||
|
||||
class RecipientController extends ApiMutableModelControllerBase
|
||||
{
|
||||
static protected $internalModelName = 'Recipient';
|
||||
static protected $internalModelName = 'recipient';
|
||||
static protected $internalModelClass = '\OPNsense\Postfix\Recipient';
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
// define list of configurable settings
|
||||
$result = array();
|
||||
if ($this->request->isGet()) {
|
||||
$mdlRecipient = new Recipient();
|
||||
$result['recipient'] = $mdlRecipient->getNodes();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setAction()
|
||||
{
|
||||
$result = array("result"=>"failed");
|
||||
if ($this->request->isPost()) {
|
||||
// load model and update with provided data
|
||||
$mdlRecipient = new Recipient();
|
||||
$mdlRecipient->setNodes($this->request->getPost("recipient"));
|
||||
// perform validation
|
||||
$valMsgs = $mdlRecipient->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
if (!array_key_exists("validations", $result)) {
|
||||
$result["validations"] = array();
|
||||
}
|
||||
$result["validations"]["recipient.".$msg->getField()] = $msg->getMessage();
|
||||
}
|
||||
// serialize model to config and save
|
||||
if ($valMsgs->count() == 0) {
|
||||
$mdlRecipient->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result["result"] = "saved";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function searchRecipientAction()
|
||||
{
|
||||
$this->sessionClose();
|
||||
$mdlRecipient = $this->getModel();
|
||||
$grid = new UIModelGrid($mdlRecipient->recipients->recipient);
|
||||
return $grid->fetchBindRequest(
|
||||
$this->request,
|
||||
array("enabled", "address", "action" )
|
||||
);
|
||||
return $this->searchBase('recipients.recipient', array("enabled", "address", "action"));
|
||||
}
|
||||
|
||||
public function getRecipientAction($uuid = null)
|
||||
{
|
||||
$mdlRecipient = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlRecipient->getNodeByReference('recipients.recipient.' . $uuid);
|
||||
if ($node != null) {
|
||||
// return node
|
||||
return array("recipient" => $node->getNodes());
|
||||
}
|
||||
} else {
|
||||
$node = $mdlRecipient->recipients->recipient->add();
|
||||
return array("recipient" => $node->getNodes());
|
||||
}
|
||||
return array();
|
||||
return $this->getBase('recipient', 'recipients.recipient', $uuid);
|
||||
}
|
||||
|
||||
public function addRecipientAction()
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost() && $this->request->hasPost("recipient")) {
|
||||
$result = array("result" => "failed", "validations" => array());
|
||||
$mdlRecipient = $this->getModel();
|
||||
$node = $mdlRecipient->recipients->recipient->Add();
|
||||
$node->setNodes($this->request->getPost("recipient"));
|
||||
$valMsgs = $mdlRecipient->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, "recipient", $msg->getField());
|
||||
$result["validations"][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
if (count($result['validations']) == 0) {
|
||||
unset($result['validations']);
|
||||
// save config if validated correctly
|
||||
$mdlRecipient->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
unset($result['validations']);
|
||||
$result["result"] = "saved";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->addBase('recipient', 'recipients.recipient');
|
||||
}
|
||||
|
||||
public function delRecipientAction($uuid)
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost()) {
|
||||
$mdlRecipient = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
if ($mdlRecipient->recipients->recipient->del($uuid)) {
|
||||
$mdlRecipient->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result['result'] = 'deleted';
|
||||
} else {
|
||||
$result['result'] = 'not found';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->delBase('recipients.recipient', $uuid);
|
||||
}
|
||||
|
||||
public function setRecipientAction($uuid)
|
||||
{
|
||||
if ($this->request->isPost() && $this->request->hasPost("recipient")) {
|
||||
$mdlSetting = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlSetting->getNodeByReference('recipients.recipient.' . $uuid);
|
||||
if ($node != null) {
|
||||
$result = array("result" => "failed", "validations" => array());
|
||||
$recipientInfo = $this->request->getPost("recipient");
|
||||
$node->setNodes($recipientInfo);
|
||||
$valMsgs = $mdlSetting->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, "recipient", $msg->getField());
|
||||
$result["validations"][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
if (count($result['validations']) == 0) {
|
||||
// save config if validated correctly
|
||||
$mdlSetting->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result = array("result" => "saved");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array("result" => "failed");
|
||||
}
|
||||
|
||||
public function toggle_handler($uuid, $elements, $element)
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost()) {
|
||||
$mdlSetting = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlSetting->getNodeByReference($elements . '.'. $element .'.' . $uuid);
|
||||
if ($node != null) {
|
||||
if ($node->enabled->__toString() == "1") {
|
||||
$result['result'] = "Disabled";
|
||||
$node->enabled = "0";
|
||||
} else {
|
||||
$result['result'] = "Enabled";
|
||||
$node->enabled = "1";
|
||||
}
|
||||
// if item has toggled, serialize to config and save
|
||||
$mdlSetting->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->setBase('recipient', 'recipients.recipient', $uuid);
|
||||
}
|
||||
|
||||
public function toggleRecipientAction($uuid)
|
||||
{
|
||||
return $this->toggle_handler($uuid, 'recipients', 'recipient');
|
||||
return $this->toggleBase('recipients.recipient', $uuid);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,205 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 - 2017 Deciso B.V.
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
* Copyright (C) 2018 Fabian Franz
|
||||
* All rights reserved.
|
||||
*
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* 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\Postfix\Sender;
|
||||
use \OPNsense\Core\Config;
|
||||
use \OPNsense\Base\ApiMutableModelControllerBase;
|
||||
use \OPNsense\Base\UIModelGrid;
|
||||
|
||||
class SenderController extends ApiMutableModelControllerBase
|
||||
{
|
||||
static protected $internalModelName = 'Sender';
|
||||
static protected $internalModelName = 'sender';
|
||||
static protected $internalModelClass = '\OPNsense\Postfix\Sender';
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
// define list of configurable settings
|
||||
$result = array();
|
||||
if ($this->request->isGet()) {
|
||||
$mdlSender = new Sender();
|
||||
$result['sender'] = $mdlSender->getNodes();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setAction()
|
||||
{
|
||||
$result = array("result"=>"failed");
|
||||
if ($this->request->isPost()) {
|
||||
// load model and update with provided data
|
||||
$mdlSender = new Sender();
|
||||
$mdlSender->setNodes($this->request->getPost("sender"));
|
||||
// perform validation
|
||||
$valMsgs = $mdlSender->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
if (!array_key_exists("validations", $result)) {
|
||||
$result["validations"] = array();
|
||||
}
|
||||
$result["validations"]["sender.".$msg->getField()] = $msg->getMessage();
|
||||
}
|
||||
// serialize model to config and save
|
||||
if ($valMsgs->count() == 0) {
|
||||
$mdlSender->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result["result"] = "saved";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function searchSenderAction()
|
||||
{
|
||||
$this->sessionClose();
|
||||
$mdlSender = $this->getModel();
|
||||
$grid = new UIModelGrid($mdlSender->senders->sender);
|
||||
return $grid->fetchBindRequest(
|
||||
$this->request,
|
||||
array("enabled", "address", "action" )
|
||||
);
|
||||
return $this->searchBase('senders.sender', array("enabled", "address", "action"));
|
||||
}
|
||||
|
||||
public function getSenderAction($uuid = null)
|
||||
{
|
||||
$mdlSender = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlSender->getNodeByReference('senders.sender.' . $uuid);
|
||||
if ($node != null) {
|
||||
// return node
|
||||
return array("sender" => $node->getNodes());
|
||||
}
|
||||
} else {
|
||||
$node = $mdlSender->senders->sender->add();
|
||||
return array("sender" => $node->getNodes());
|
||||
}
|
||||
return array();
|
||||
return $this->getBase('sender', 'senders.sender', $uuid);
|
||||
}
|
||||
|
||||
public function addSenderAction()
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost() && $this->request->hasPost("sender")) {
|
||||
$result = array("result" => "failed", "validations" => array());
|
||||
$mdlSender = $this->getModel();
|
||||
$node = $mdlSender->senders->sender->Add();
|
||||
$node->setNodes($this->request->getPost("sender"));
|
||||
$valMsgs = $mdlSender->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, "sender", $msg->getField());
|
||||
$result["validations"][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
if (count($result['validations']) == 0) {
|
||||
unset($result['validations']);
|
||||
// save config if validated correctly
|
||||
$mdlSender->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
unset($result['validations']);
|
||||
$result["result"] = "saved";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->addBase('sender', 'senders.sender');
|
||||
}
|
||||
|
||||
public function delSenderAction($uuid)
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost()) {
|
||||
$mdlSender = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
if ($mdlSender->senders->sender->del($uuid)) {
|
||||
$mdlSender->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result['result'] = 'deleted';
|
||||
} else {
|
||||
$result['result'] = 'not found';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->delBase('senders.sender', $uuid);
|
||||
}
|
||||
|
||||
public function setSenderAction($uuid)
|
||||
{
|
||||
if ($this->request->isPost() && $this->request->hasPost("sender")) {
|
||||
$mdlSetting = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlSetting->getNodeByReference('senders.sender.' . $uuid);
|
||||
if ($node != null) {
|
||||
$result = array("result" => "failed", "validations" => array());
|
||||
$senderInfo = $this->request->getPost("sender");
|
||||
$node->setNodes($senderInfo);
|
||||
$valMsgs = $mdlSetting->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, "sender", $msg->getField());
|
||||
$result["validations"][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
if (count($result['validations']) == 0) {
|
||||
// save config if validated correctly
|
||||
$mdlSetting->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result = array("result" => "saved");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array("result" => "failed");
|
||||
}
|
||||
|
||||
public function toggle_handler($uuid, $elements, $element)
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost()) {
|
||||
$mdlSetting = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlSetting->getNodeByReference($elements . '.'. $element .'.' . $uuid);
|
||||
if ($node != null) {
|
||||
if ($node->enabled->__toString() == "1") {
|
||||
$result['result'] = "Disabled";
|
||||
$node->enabled = "0";
|
||||
} else {
|
||||
$result['result'] = "Enabled";
|
||||
$node->enabled = "1";
|
||||
}
|
||||
// if item has toggled, serialize to config and save
|
||||
$mdlSetting->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->setBase('sender', 'senders.sender', $uuid);
|
||||
}
|
||||
|
||||
public function toggleSenderAction($uuid)
|
||||
{
|
||||
return $this->toggle_handler($uuid, 'senders', 'sender');
|
||||
return $this->toggleBase('senders.sender', $uuid);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,30 @@
|
|||
<type>dropdown</type>
|
||||
<help>Choose "none" to disable TLS for sending mail. Set encrypt to enforce TLS security, please do not use this for Internet wide communication as not every server supports TLS yet. Default is "may" which will use TLS when offered.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.relayhost</id>
|
||||
<label>Smart Host</label>
|
||||
<type>text</type>
|
||||
<help>Set the IP address or FQDN where all outgoung mails are sent to.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.smtpauth_enabled</id>
|
||||
<label>Enable SMTP Authentication</label>
|
||||
<type>checkbox</type>
|
||||
<help>Check this to enable authentication against your Smarthost.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.smtpauth_user</id>
|
||||
<label>Authentication Username</label>
|
||||
<type>text</type>
|
||||
<help>The username to use for SMTP authentication.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.smtpauth_password</id>
|
||||
<label>Authentication Password</label>
|
||||
<type>password</type>
|
||||
<help>The password to use for SMTP authentication.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.reject_unauth_pipelining</id>
|
||||
<label>Reject Unauthenticated Pipelining</label>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<model>
|
||||
<mount>//OPNsense/postfix/general</mount>
|
||||
<description>Postfix configuration</description>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.0</version>
|
||||
<items>
|
||||
<enabled type="BooleanField">
|
||||
<default>0</default>
|
||||
|
|
@ -60,6 +60,21 @@
|
|||
<encrypt>encrypt</encrypt>
|
||||
</OptionValues>
|
||||
</smtpclient_security>
|
||||
<relayhost type="HostnameField">
|
||||
<Required>N</Required>
|
||||
</relayhost>
|
||||
<smtpauth_enabled type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>Y</Required>
|
||||
</smtpauth_enabled>
|
||||
<smtpauth_user type="TextField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
</smtpauth_user>
|
||||
<smtpauth_password type="TextField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
</smtpauth_password>
|
||||
<reject_unauth_pipelining type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>Y</Required>
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ chown -R root:postfix /var/spool/postfix/pid
|
|||
postmap /usr/local/etc/postfix/transport
|
||||
postmap /usr/local/etc/postfix/recipient_access
|
||||
postmap /usr/local/etc/postfix/sender_access
|
||||
postmap /usr/local/etc/postfix/smtp_auth
|
||||
|
||||
# Check for aliases
|
||||
if [ -f /usr/local/etc/postfix/aliases ]; then
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ postfix:/etc/rc.conf.d/postfix
|
|||
transport:/usr/local/etc/postfix/transport
|
||||
recipient_access:/usr/local/etc/postfix/recipient_access
|
||||
sender_access:/usr/local/etc/postfix/sender_access
|
||||
smtp_auth:/usr/local/etc/postfix/smtp_auth
|
||||
|
|
|
|||
|
|
@ -88,6 +88,16 @@ smtpd_tls_cert_file = /usr/local/etc/postfix/cert_opn.pem
|
|||
smtpd_tls_CAfile = /usr/local/etc/postfix/ca_opn.pem
|
||||
{% endif %}
|
||||
|
||||
{% if helpers.exists('OPNsense.postfix.general.relayhost') and OPNsense.postfix.general.relayhost != '' %}
|
||||
relayhost = {{ OPNsense.postfix.general.relayhost }}
|
||||
{% endif %}
|
||||
|
||||
{% if helpers.exists('OPNsense.postfix.general.smtpauth_enabled') and OPNsense.postfix.general.smtpauth_enabled != '' %}
|
||||
smtp_sasl_auth_enable = yes
|
||||
smtp_sasl_password_maps = hash:/usr/local/etc/postfix/smtp_auth
|
||||
smtp_sasl_security_options =
|
||||
{% endif %}
|
||||
|
||||
{% if helpers.exists('OPNsense.postfix.antispam.enable_rspamd') and OPNsense.postfix.antispam.enable_rspamd == '1' %}
|
||||
smtpd_milters = inet:localhost:11332
|
||||
non_smtpd_milters = inet:localhost:11332
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
{% if helpers.exists('OPNsense.postfix.general.enabled') and OPNsense.postfix.general.enabled == '1' %}
|
||||
{% if helpers.exists('OPNsense.postfix.general.smtpauth_enabled') and OPNsense.postfix.general.smtpauth_enabled == '1' %}
|
||||
{% if helpers.exists('OPNsense.postfix.general.smtpauth_user') and OPNsense.postfix.general.smtpauth_user != '' %}
|
||||
{% if helpers.exists('OPNsense.postfix.general.smtpauth_password') and OPNsense.postfix.general.smtpauth_password != '' %}
|
||||
{{ OPNsense.postfix.general.relayhost }} {{ OPNsense.postfix.general.smtpauth_user }}:{{ OPNsense.postfix.general.smtpauth_password }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
Loading…
Reference in a new issue