greylisting 2.0
This commit is contained in:
@@ -299,6 +299,30 @@ if ($page == 'email_domain') {
|
|||||||
'action' => 'edit',
|
'action' => 'edit',
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
]);
|
]);
|
||||||
|
} elseif ($action == 'togglegreylist' && $id != 0) {
|
||||||
|
try {
|
||||||
|
$json_result = Emails::getLocal($userinfo, [
|
||||||
|
'id' => $id
|
||||||
|
])->get();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Response::dynamicError($e->getMessage());
|
||||||
|
}
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
Emails::getLocal($userinfo, [
|
||||||
|
'id' => $id,
|
||||||
|
'disablegreylist' => ($result['disablegreylist'] == '1' ? 0 : 1)
|
||||||
|
])->updateGreylist();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Response::dynamicError($e->getMessage());
|
||||||
|
}
|
||||||
|
Response::redirectTo($filename, [
|
||||||
|
'page' => $page,
|
||||||
|
'domainid' => $email_domainid,
|
||||||
|
'action' => 'edit',
|
||||||
|
'id' => $id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
} elseif ($page == 'accounts') {
|
} elseif ($page == 'accounts') {
|
||||||
$email_domainid = Request::any('domainid', 0);
|
$email_domainid = Request::any('domainid', 0);
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
|||||||
|
|
||||||
// parameters
|
// parameters
|
||||||
$iscatchall = $this->getBoolParam('iscatchall', true, 0);
|
$iscatchall = $this->getBoolParam('iscatchall', true, 0);
|
||||||
|
$disablegreylist = $this->getBoolParam('disablegreylist', true, 0);
|
||||||
$description = $this->getParam('description', true, '');
|
$description = $this->getParam('description', true, '');
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
@@ -118,7 +119,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
|||||||
|
|
||||||
// duplicate check
|
// duplicate check
|
||||||
$stmt = Database::prepare("
|
$stmt = Database::prepare("
|
||||||
SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid` FROM `" . TABLE_MAIL_VIRTUAL . "`
|
SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid`, `disablegreylist` FROM `" . TABLE_MAIL_VIRTUAL . "`
|
||||||
WHERE (`email` = :email OR `email_full` = :emailfull )
|
WHERE (`email` = :email OR `email_full` = :emailfull )
|
||||||
AND `customerid`= :cid
|
AND `customerid`= :cid
|
||||||
");
|
");
|
||||||
@@ -144,7 +145,8 @@ class Emails extends ApiCommand implements ResourceEntity
|
|||||||
`email_full` = :email_full,
|
`email_full` = :email_full,
|
||||||
`iscatchall` = :iscatchall,
|
`iscatchall` = :iscatchall,
|
||||||
`domainid` = :domainid,
|
`domainid` = :domainid,
|
||||||
`description` = :description
|
`description` = :description,
|
||||||
|
`disablegreylist` = :disablegreylist
|
||||||
");
|
");
|
||||||
$params = [
|
$params = [
|
||||||
"cid" => $customer['customerid'],
|
"cid" => $customer['customerid'],
|
||||||
@@ -152,7 +154,8 @@ class Emails extends ApiCommand implements ResourceEntity
|
|||||||
"email_full" => $email_full,
|
"email_full" => $email_full,
|
||||||
"iscatchall" => $iscatchall,
|
"iscatchall" => $iscatchall,
|
||||||
"domainid" => $domain_check['id'],
|
"domainid" => $domain_check['id'],
|
||||||
"description" => $description
|
"description" => $description,
|
||||||
|
"disablegreylist" => $disablegreylist
|
||||||
];
|
];
|
||||||
Database::pexecute($stmt, $params, true, true);
|
Database::pexecute($stmt, $params, true, true);
|
||||||
|
|
||||||
@@ -191,7 +194,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
|||||||
$customer_ids = $this->getAllowedCustomerIds('email');
|
$customer_ids = $this->getAllowedCustomerIds('email');
|
||||||
$params['idea'] = ($id <= 0 ? $emailaddr : $id);
|
$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`, v.`description`, u.`quota`, u.`imap`, u.`pop3`, u.`postfix`, u.`mboxsize`
|
$result_stmt = Database::prepare("SELECT v.`id`, v.`email`, v.`email_full`, v.`iscatchall`, v.`disablegreylist`, v.`destination`, v.`customerid`, v.`popaccountid`, v.`domainid`, v.`description`, u.`quota`, u.`imap`, u.`pop3`, u.`postfix`, u.`mboxsize`
|
||||||
FROM `" . TABLE_MAIL_VIRTUAL . "` v
|
FROM `" . TABLE_MAIL_VIRTUAL . "` v
|
||||||
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON v.`popaccountid` = u.`id`
|
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON v.`popaccountid` = u.`id`
|
||||||
WHERE v.`customerid` IN (" . implode(", ", $customer_ids) . ")
|
WHERE v.`customerid` IN (" . implode(", ", $customer_ids) . ")
|
||||||
@@ -302,6 +305,81 @@ class Emails extends ApiCommand implements ResourceEntity
|
|||||||
return $this->response($result);
|
return $this->response($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, required when called as admin (if $loginname is not specified)
|
||||||
|
* @param string $loginname
|
||||||
|
* optional, required when called as admin (if $customerid is not specified)
|
||||||
|
* @param boolean $greylist
|
||||||
|
* optional
|
||||||
|
* @param string $description
|
||||||
|
* optional custom description (currently not used/shown in the frontend), default empty
|
||||||
|
*
|
||||||
|
* @access admin, customer
|
||||||
|
* @return string json-encoded array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function updateGreylist()
|
||||||
|
{
|
||||||
|
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('catchall.catchall_enabled') != '1') {
|
||||||
|
Response::standardError([
|
||||||
|
'operationnotpermitted',
|
||||||
|
'featureisdisabled'
|
||||||
|
], 'catchall', true);
|
||||||
|
} */
|
||||||
|
|
||||||
|
$id = $this->getParam('id', true, 0);
|
||||||
|
$ea_optional = $id > 0;
|
||||||
|
$emailaddr = $this->getParam('emailaddr', $ea_optional, '');
|
||||||
|
|
||||||
|
$result = $this->apiCall('Emails.get', [
|
||||||
|
'id' => $id,
|
||||||
|
'emailaddr' => $emailaddr
|
||||||
|
]);
|
||||||
|
$id = $result['id'];
|
||||||
|
$email = $result['email'];
|
||||||
|
|
||||||
|
|
||||||
|
// parameters
|
||||||
|
$disablegreylist = $this->getBoolParam('disablegreylist', true, $result['disablegreylist']);
|
||||||
|
$description = $this->getParam('description', true, $result['description']);
|
||||||
|
|
||||||
|
// get needed customer info to reduce the email-address-counter by one
|
||||||
|
$customer = $this->getCustomerData();
|
||||||
|
|
||||||
|
// check for catchall-flag
|
||||||
|
$stmt = Database::prepare("
|
||||||
|
UPDATE `" . TABLE_MAIL_VIRTUAL . "`
|
||||||
|
SET `email` = :email , `disablegreylist` = :grflag, `description` = :description
|
||||||
|
WHERE `customerid`= :cid AND `id`= :id
|
||||||
|
");
|
||||||
|
$params = [
|
||||||
|
"email" => $email,
|
||||||
|
"grflag" => $disablegreylist,
|
||||||
|
"description" => $description,
|
||||||
|
"cid" => $customer['customerid'],
|
||||||
|
"id" => $id
|
||||||
|
];
|
||||||
|
Database::pexecute($stmt, $params, true, true);
|
||||||
|
$this->logger()->logAction($this->isAdmin() ? FroxlorLogger::ADM_ACTION : FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] toggled greylist-flag for email address '" . $result['email_full'] . "'");
|
||||||
|
|
||||||
|
$result = $this->apiCall('Emails.get', [
|
||||||
|
'emailaddr' => $result['email_full']
|
||||||
|
]);
|
||||||
|
return $this->response($result);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* list all email addresses, if called from an admin, list all email addresses of all customers you are allowed to
|
* 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, or specify id or loginname for one specific customer
|
||||||
@@ -331,7 +409,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
|||||||
$result = [];
|
$result = [];
|
||||||
$query_fields = [];
|
$query_fields = [];
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
SELECT m.`id`, m.`domainid`, m.`email`, m.`email_full`, m.`iscatchall`, m.`destination`, m.`popaccountid`, d.`domain`, u.`quota`, u.`imap`, u.`pop3`, u.`postfix`, u.`mboxsize`
|
SELECT m.`id`, m.`domainid`, m.`email`, m.`email_full`, m.`iscatchall`, m.`disablegreylist`, m.`destination`, m.`popaccountid`, d.`domain`, u.`quota`, u.`imap`, u.`pop3`, u.`postfix`, u.`mboxsize`
|
||||||
FROM `" . TABLE_MAIL_VIRTUAL . "` m
|
FROM `" . TABLE_MAIL_VIRTUAL . "` m
|
||||||
LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` d ON (m.`domainid` = d.`id`)
|
LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` d ON (m.`domainid` = d.`id`)
|
||||||
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON (m.`popaccountid` = u.`id`)
|
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON (m.`popaccountid` = u.`id`)
|
||||||
|
|||||||
@@ -52,7 +52,13 @@ return [
|
|||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'value' => '1',
|
'value' => '1',
|
||||||
'checked' => false
|
'checked' => false
|
||||||
]
|
],
|
||||||
|
'disablegreylist' => [
|
||||||
|
'label' => lng('emails.disablegreylist'),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'value' => '1',
|
||||||
|
'checked' => false
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -102,6 +102,19 @@ return [
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
'mail_disablegreylist' => [
|
||||||
|
'label' => lng('emails.greylist'),
|
||||||
|
'type' => 'label',
|
||||||
|
'value' => ((int)$result['disablegreylist'] == 0 ? lng('panel.no') : lng('panel.yes')),
|
||||||
|
'next_to' => [
|
||||||
|
'add_link' => [
|
||||||
|
'type' => 'link',
|
||||||
|
'href' => $filename . '?page=' . $page . '&domainid=' . $result['domainid'] . '&action=togglegreylist&id=' . $result['id'],
|
||||||
|
'label' => '<i class="fa-solid fa-arrow-right-arrow-left"></i> ' . lng('panel.toggle'),
|
||||||
|
'classes' => 'btn btn-sm btn-secondary'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
'mail_fwds' => [
|
'mail_fwds' => [
|
||||||
'label' => lng('emails.forwarders') . ' (' . $forwarders_count . ')',
|
'label' => lng('emails.forwarders') . ' (' . $forwarders_count . ')',
|
||||||
'type' => 'itemlist',
|
'type' => 'itemlist',
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ return [
|
|||||||
'callback' => [Text::class, 'boolean'],
|
'callback' => [Text::class, 'boolean'],
|
||||||
'visible' => Settings::Get('catchall.catchall_enabled') == '1'
|
'visible' => Settings::Get('catchall.catchall_enabled') == '1'
|
||||||
],
|
],
|
||||||
|
'm.disablegreylist' => [
|
||||||
|
'label' => lng('emails.greylist'),
|
||||||
|
'field' => 'disablegreylist',
|
||||||
|
'callback' => [Text::class, 'boolean'],
|
||||||
|
'#visible' => Settings::Get('greylist.greylist_enabled') == '1'
|
||||||
|
],
|
||||||
'u.quota' => [
|
'u.quota' => [
|
||||||
'label' => lng('emails.quota'),
|
'label' => lng('emails.quota'),
|
||||||
'field' => 'quota',
|
'field' => 'quota',
|
||||||
@@ -66,6 +72,7 @@ return [
|
|||||||
'm.destination',
|
'm.destination',
|
||||||
'm.popaccountid',
|
'm.popaccountid',
|
||||||
'm.iscatchall',
|
'm.iscatchall',
|
||||||
|
'm.disablegreylist',
|
||||||
'u.quota'
|
'u.quota'
|
||||||
]),
|
]),
|
||||||
'actions' => [
|
'actions' => [
|
||||||
|
|||||||
@@ -724,6 +724,8 @@ return [
|
|||||||
'back_to_overview' => 'Zurück zur Domain-Übersicht',
|
'back_to_overview' => 'Zurück zur Domain-Übersicht',
|
||||||
'accounts' => 'Konten',
|
'accounts' => 'Konten',
|
||||||
'emails' => 'Adressen',
|
'emails' => 'Adressen',
|
||||||
|
'disablegreylist' => 'Greylisting deaktivieren?',
|
||||||
|
'greylist' => 'Greylisting aus?'
|
||||||
],
|
],
|
||||||
'error' => [
|
'error' => [
|
||||||
'error' => 'Fehlermeldung',
|
'error' => 'Fehlermeldung',
|
||||||
|
|||||||
Reference in New Issue
Block a user