From 825eafb9e8fd6dd24f7101d4a5ec94c371c1e387 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 10 Jan 2018 20:49:55 +0000 Subject: [PATCH] mail/postfix: add logging, some more stuff; closes #366 --- mail/postfix/Makefile | 2 +- .../src/etc/inc/plugins.inc.d/postfix.inc | 12 +++ .../Postfix/Api/GeneralController.php | 89 +++++------------ .../Postfix/Api/ServiceController.php | 96 +++---------------- .../OPNsense/Postfix/RecipientController.php | 45 +++++---- .../OPNsense/Postfix/SenderController.php | 44 +++++---- .../app/models/OPNsense/Postfix/Menu/Menu.xml | 1 + .../templates/OPNsense/Postfix/main.cf | 4 +- mail/postfix/src/www/diag_logs_postfix.php | 8 ++ 9 files changed, 110 insertions(+), 191 deletions(-) create mode 100644 mail/postfix/src/www/diag_logs_postfix.php diff --git a/mail/postfix/Makefile b/mail/postfix/Makefile index 34ae93dc2..1076d99a3 100644 --- a/mail/postfix/Makefile +++ b/mail/postfix/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= postfix -PLUGIN_VERSION= 0.3 +PLUGIN_VERSION= 0.4 PLUGIN_COMMENT= SMTP mail relay PLUGIN_DEPENDS= postfix-sasl PLUGIN_MAINTAINER= m.muenz@gmail.com diff --git a/mail/postfix/src/etc/inc/plugins.inc.d/postfix.inc b/mail/postfix/src/etc/inc/plugins.inc.d/postfix.inc index 0ff66f9de..d89be4e56 100644 --- a/mail/postfix/src/etc/inc/plugins.inc.d/postfix.inc +++ b/mail/postfix/src/etc/inc/plugins.inc.d/postfix.inc @@ -47,3 +47,15 @@ function postfix_services() return $services; } + +function postfix_syslog() +{ + $syslogconf = array(); + + $syslogconf['mail'] = array( + 'facility' => array('postfix'), + 'remote' => 'mail', + ); + + return $syslogconf; +} diff --git a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/GeneralController.php b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/GeneralController.php index b01f39fea..32da5db62 100644 --- a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/GeneralController.php +++ b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/GeneralController.php @@ -1,76 +1,37 @@ request->isGet()) { - $mdlGeneral = new General(); - $result['general'] = $mdlGeneral->getNodes(); - } - return $result; - } - - public function setAction() - { - $result = array("result"=>"failed"); - if ($this->request->isPost()) { - // load model and update with provided data - $mdlGeneral = new General(); - $mdlGeneral->setNodes($this->request->getPost("general")); - - // perform validation - $valMsgs = $mdlGeneral->performValidation(); - foreach ($valMsgs as $field => $msg) { - if (!array_key_exists("validations", $result)) { - $result["validations"] = array(); - } - $result["validations"]["general.".$msg->getField()] = $msg->getMessage(); - } - - // serialize model to config and save - if ($valMsgs->count() == 0) { - $mdlGeneral->serializeToConfig(); - Config::getInstance()->save(); - $result["result"] = "saved"; - } - } - return $result; - } + static protected $internalModelClass = '\OPNsense\Postfix\General'; + static protected $internalModelName = 'general'; } diff --git a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/ServiceController.php b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/ServiceController.php index 7d21f736f..5de97bf93 100644 --- a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/ServiceController.php +++ b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/Api/ServiceController.php @@ -1,8 +1,8 @@ request->isPost()) { - // close session for long running action - $this->sessionClose(); - $backend = new Backend(); - $response = $backend->configdRun('postfix start'); - return array("response" => $response); - } else { - return array("response" => array()); - } - } - - /** - * stop postfix service - * @return array - */ - public function stopAction() - { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); - $backend = new Backend(); - $response = $backend->configdRun("postfix stop"); - return array("response" => $response); - } else { - return array("response" => array()); - } - } - - /** - * restart postfix service - * @return array - */ - public function restartAction() - { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); - $backend = new Backend(); - $response = $backend->configdRun("postfix restart"); - return array("response" => $response); - } else { - return array("response" => array()); - } - } - - /** - * retrieve status of postfix - * @return array - * @throws \Exception - */ - public function statusAction() - { - $backend = new Backend(); - $mdlGeneral = new General(); - $response = $backend->configdRun("postfix status"); - - if (strpos($response, "not running") > 0) { - if ($mdlGeneral->enabled->__toString() == 1) { - $status = "stopped"; - } else { - $status = "disabled"; - } - } elseif (strpos($response, "is running") > 0) { - $status = "running"; - } elseif ($mdlGeneral->enabled->__toString() == 0) { - $status = "disabled"; - } else { - $status = "unkown"; - } - - return array("status" => $status); - } - /** * reconfigure postfix, generate config and reload + * + * XXX overwrites the base one for make-transport */ public function reconfigureAction() { diff --git a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/RecipientController.php b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/RecipientController.php index bab463df0..08c58893f 100644 --- a/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/RecipientController.php +++ b/mail/postfix/src/opnsense/mvc/app/controllers/OPNsense/Postfix/RecipientController.php @@ -1,25 +1,30 @@ + 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 e57c9cf6e..58721a9b2 100644 --- a/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/main.cf +++ b/mail/postfix/src/opnsense/service/templates/OPNsense/Postfix/main.cf @@ -138,7 +138,7 @@ smtpd_recipient_restrictions = {{ smtpd_recipient_restrictions | join(', ') }} smtpd_helo_required = yes -### Syslog tweak, will be removed before stable -syslog_facility = security +syslog_facility = mail +syslog_name = postfix {% endif %} diff --git a/mail/postfix/src/www/diag_logs_postfix.php b/mail/postfix/src/www/diag_logs_postfix.php new file mode 100644 index 000000000..208fe909f --- /dev/null +++ b/mail/postfix/src/www/diag_logs_postfix.php @@ -0,0 +1,8 @@ +