greylisting dis/enable

This commit is contained in:
2020-11-11 13:40:33 +01:00
parent 5821f4a0e5
commit 2e81445a4e
5 changed files with 141 additions and 10 deletions

View File

@@ -213,7 +213,9 @@ if ($page == 'overview') {
if (Settings::Get('catchall.catchall_enabled') != '1') {
unset($email_add_data['emails_add']['sections']['section_a']['fields']['iscatchall']);
}
if (Settings::Get('mail.greylist_enabled') != '1') {
unset($email_edit_data['emails_edit']['sections']['section_a']['fields']['mail_greylist']);
}
$email_add_form = \Froxlor\UI\HtmlForm::genHTMLForm($email_add_data);
$title = $email_add_data['emails_add']['title'];
@@ -261,7 +263,9 @@ if ($page == 'overview') {
if (Settings::Get('catchall.catchall_enabled') != '1') {
unset($email_edit_data['emails_edit']['sections']['section_a']['fields']['mail_catchall']);
}
if (Settings::Get('mail.greylist_enabled') != '1') {
unset($email_edit_data['emails_edit']['sections']['section_a']['fields']['mail_greylist']);
}
$email_edit_form = \Froxlor\UI\HtmlForm::genHTMLForm($email_edit_data);
$title = $email_edit_data['emails_edit']['title'];
@@ -282,7 +286,7 @@ if ($page == 'overview') {
try {
Emails::getLocal($userinfo, array(
'id' => $id,
'iscatchall' => ($result['iscatchall'] == '1' ? 0 : 1)
'iscatchall' => ($result['iscatchall'] == '1' ? 0 : 1),
))->update();
} catch (Exception $e) {
\Froxlor\UI\Response::dynamic_error($e->getMessage());
@@ -293,6 +297,30 @@ if ($page == 'overview') {
'id' => $id,
's' => $s
));
} elseif ($action == 'togglegreylist' && $id != 0) {
try {
$json_result = Emails::getLocal($userinfo, array(
'id' => $id
))->get();
} catch (Exception $e) {
\Froxlor\UI\Response::dynamic_error($e->getMessage());
}
$result = json_decode($json_result, true)['data'];
try {
Emails::getLocal($userinfo, array(
'id' => $id,
'disablegreylist' => ($result['disablegreylist'] == '1' ? 0 : 1)
))->update_greylist();
} catch (Exception $e) {
\Froxlor\UI\Response::dynamic_error($e->getMessage());
}
\Froxlor\UI\Response::redirectTo($filename, array(
'page' => $page,
'action' => 'edit',
'id' => $id,
's' => $s
));
}
} elseif ($page == 'accounts') {
if ($action == 'add' && $id != 0) {

View File

@@ -54,6 +54,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
// parameters
$iscatchall = $this->getBoolParam('iscatchall', true, 0);
$disablegreylist = $this->getBoolParam('disablegreylist', true, 0);
// validation
if (substr($domain, 0, 4) != 'xn--') {
@@ -72,6 +73,9 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
if (Settings::Get('catchall.catchall_enabled') != '1') {
$iscatchall = 0;
}
if (Settings::Get('mail.greylist_enabled') != '1') {
$disablegreylist = 1;
}
// check for catchall-flag
if ($iscatchall) {
@@ -120,6 +124,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
`email` = :email,
`email_full` = :email_full,
`iscatchall` = :iscatchall,
`disablegreylist` = :disablegreylist,
`domainid` = :domainid
");
$params = array(
@@ -127,6 +132,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
"email" => $email,
"email_full" => $email_full,
"iscatchall" => $iscatchall,
"disablegreylist" => $disablegreylist,
"domainid" => $domain_check['id']
);
Database::pexecute($stmt, $params, true, true);
@@ -166,7 +172,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
$customer_ids = $this->getAllowedCustomerIds('email');
$params['idea'] = ($id <= 0 ? $emailaddr : $id);
$result_stmt = Database::prepare("SELECT v.`id`, v.`email`, v.`email_full`, v.`iscatchall`, v.`destination`, v.`customerid`, v.`popaccountid`, v.`domainid`, u.`quota`
$result_stmt = Database::prepare("SELECT v.`id`, v.`email`, v.`email_full`, v.`iscatchall`, v.`destination`, v.`customerid`, v.`popaccountid`, v.`domainid`, u.`quota`, v.`disablegreylist`
FROM `" . TABLE_MAIL_VIRTUAL . "` v
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON v.`popaccountid` = u.`id`
WHERE v.`customerid` IN (" . implode(", ", $customer_ids) . ")
@@ -226,7 +232,6 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
// parameters
$iscatchall = $this->getBoolParam('iscatchall', true, $result['iscatchall']);
// get needed customer info to reduce the email-address-counter by one
$customer = $this->getCustomerData();
@@ -272,6 +277,96 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
));
return $this->response(200, "successfull", $result);
}
/**
* toggle greylist flag of given email address either by id or email-address
*
* @param int $id
* optional, the email-address-id
* @param string $emailaddr
* optional, the email-address
* @param int $customerid
* optional, admin-only, the customer-id
* @param string $loginname
* optional, admin-only, the loginname
* @param boolean $disablegreylist
* optional
*
* @access admin, customer
* @throws \Exception
* @return string json-encoded array
*/
public function update_greylist()
{
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new \Exception("You cannot access this resource", 405);
}
// if enabling catchall is not allowed by settings, we do not need
// to run update()
if (Settings::Get('mail.greylist_enabled') != '1') {
\Froxlor\UI\Response::standard_error(array(
'operationnotpermitted',
'featureisdisabled'
), 'catchall', true);
}
$id = $this->getParam('id', true, 0);
$ea_optional = ($id <= 0 ? false : true);
$emailaddr = $this->getParam('emailaddr', $ea_optional, '');
$result = $this->apiCall('Emails.get', array(
'id' => $id,
'emailaddr' => $emailaddr
));
$id = $result['id'];
// parameters
$disablegreylist = $this->getBoolParam('disablegreylist', true, $result['disablegreylist']);
// get needed customer info to reduce the email-address-counter by one
$customer = $this->getCustomerData();
// check for catchall-flag
if ($disablegreylist) {
$disablegreylist = '1';
$email_parts = explode('@', $result['email_full']);
$email = '@' . $email_parts[1];
// catchall check
$stmt = Database::prepare("
SELECT `email_full` FROM `" . TABLE_MAIL_VIRTUAL . "`
WHERE `email` = :email AND `customerid` = :cid AND `disablegreylist` = '1'
");
$params = array(
"email" => $email,
"cid" => $customer['customerid']
);
$email_check = Database::pexecute_first($stmt, $params, true, true);
if ($email_check) {
\Froxlor\UI\Response::standard_error('youhavealreadyacatchallforthisdomain', '', true);
}
} else {
$disablegreylist = '0';
$email = $result['email_full'];
}
$stmt = Database::prepare("
UPDATE `" . TABLE_MAIL_VIRTUAL . "`
SET `email` = :email , `disablegreylist` = :disablegreylist
WHERE `customerid`= :cid AND `id`= :id
");
$params = array(
"email" => $email,
"disablegreylist" => $disablegreylist,
"cid" => $customer['customerid'],
"id" => $id
);
Database::pexecute($stmt, $params, true, true);
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] toggled greylist-flag for email address '" . $result['email_full'] . "'");
$result = $this->apiCall('Emails.get', array(
'emailaddr' => $result['email_full']
));
return $this->response(200, "successfull", $result);
}
/**
* list all email addresses, if called from an admin, list all email addresses of all customers you are allowed to view, or specify id or loginname for one specific customer

View File

@@ -352,6 +352,12 @@ class Dns
$dmarc_record = new DnsEntry('_dmarc', 'TXT',$dmarc_txt );
array_unshift($zonerecords,$dmarc_record);
}
if ($domain['isemaildomain'] == '1') {
$dkim_txt = 'v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAosq0CmLqEzJJxIHkQwG1Xwk6CSyHHWSDXL9BHCKzY9lJXH7a23PogVlLvUBYaAgBtFOpsKuUCBl+/g6rOqgVXKg0OpYdpgTxZyz1i4NcubGFLifQGnF8ZKpIEDqIzmLI6SbH+9DKwYA319sXAR6feZI4g5bWqF07t/kzA5LN+2V5QnDQ3th++GPRl5rmWF6uoidIRD85UZVEX4s3J1hce0k6tRb2aEozCJaSXHUwyarmbbX/5rky467QQ+45Uy0q9CNaMMu1IX5eybhLRxYXK1k0TfIRJv4FH1UFLlq2QoGC7d+KvLrUabhzQ5wbdZkWuVgLFZ7CL2NegfzO6YeEcQIDAQAB';
$dkim_record = new DnsEntry('mx._domainkey', 'TXT', $dkim_txt);
array_unshift($zonerecords, $dkim_record);
}
$zone = new DnsZone((int) Settings::Get('system.defaultttl'), $domain['domain'], $domain['bindserial'], $zonerecords);
return $zone;

View File

@@ -1,5 +1,6 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
@@ -52,8 +53,8 @@ return array(
'values' => array(
array ('label' => $lng['panel']['yes'], 'value' => '1')
),
'visible' => (Settings::Get('mail.greylist_enabled') == '1' ? true : false),
'value' => array(Settings::Get('mail.greylist_disabled_default'))
'visible' => (\Froxlor\Settings::Get('mail.greylist_enabled') == '1' ? true : false),
'value' => array(\Froxlor\Settings::Get('mail.greylist_disabled_default'))
)
)
)

View File

@@ -53,6 +53,7 @@ return array(
'value' => ($result['iscatchall'] == 0 ? $lng['panel']['no'] : $lng['panel']['yes']) . ' [<a href="' . $filename . '?page=' . $page . '&amp;action=togglecatchall&amp;id=' . $result['id'] . '&amp;s=' . $s . '">' . $lng['panel']['toggle'] . '</a>]'
),
'mail_greylist' => array(
'visible' => (\Froxlor\Settings::Get('mail.greylist_enabled') == '1' ? true : false),
'label' => $lng['emails']['greylist'],
'type' => 'label',
'value' => ($result['disablegreylist'] == 0 ? $lng['panel']['no'] : $lng['panel']['yes']).' [<a href="'.$filename.'?page='.$page.'&amp;action=togglegreylist&amp;id='.$result['id'].'&amp;s='.$s.'">'.$lng['panel']['toggle'].'</a>]'