added EmailAccounts-ApiCommand

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2018-03-12 14:13:35 +01:00
parent 6fc8cce8f5
commit fa7bb53d58
3 changed files with 538 additions and 185 deletions

View File

@@ -138,58 +138,54 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
throw new Exception("You cannot access this resource", 405);
}
if ($this->getUserDetail('email_forwarders_used') < $this->getUserDetail('email_forwarders') || $this->getUserDetail('email_forwarders') == '-1') {
// parameter
$id = $this->getParam('id', true, 0);
$ea_optional = ($id <= 0 ? false : true);
$emailaddr = $this->getParam('emailaddr', $ea_optional, '');
$forwarderid = $this->getParam('forwarderid');
// validation
$result = $this->apiCall('Emails.get', array(
'id' => $id,
'emailaddr' => $emailaddr
));
$id = $result['id'];
$result['destination'] = explode(' ', $result['destination']);
if (isset($result['destination'][$forwarderid]) && $result['email'] != $result['destination'][$forwarderid]) {
// parameter
$id = $this->getParam('id', true, 0);
$ea_optional = ($id <= 0 ? false : true);
$emailaddr = $this->getParam('emailaddr', $ea_optional, '');
$forwarderid = $this->getParam('forwarderid');
// get needed customer info to reduce the email-forwarder-counter by one
$customer = $this->getCustomerData();
// unset it from array
unset($result['destination'][$forwarderid]);
// rebuild destination-string
$result['destination'] = implode(' ', $result['destination']);
// update in DB
$stmt = Database::prepare("
UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `destination` = :dest
WHERE `customerid`= :cid AND `id`= :id
");
$params = array(
"dest" => makeCorrectDestination($result['destination']),
"cid" => $customer['customerid'],
"id" => $id
);
Database::pexecute($stmt, $params, true, true);
// update customer usage
Customers::decreaseUsage($customer['customerid'], 'email_forwarders_used');
// update admin usage
Admins::decreaseUsage($customer['adminid'], 'email_forwarders_used');
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email forwarder for '" . $result['email_full'] . "'");
// validation
$result = $this->apiCall('Emails.get', array(
'id' => $id,
'emailaddr' => $emailaddr
'emailaddr' => $result['email_full']
));
$id = $result['id'];
$result['destination'] = explode(' ', $result['destination']);
if (isset($result['destination'][$forwarderid]) && $result['email'] != $result['destination'][$forwarderid]) {
// get needed customer info to reduce the email-forwarder-counter by one
$customer = $this->getCustomerData();
// unset it from array
unset($result['destination'][$forwarderid]);
// rebuild destination-string
$result['destination'] = implode(' ', $result['destination']);
// update in DB
$stmt = Database::prepare("
UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `destination` = :dest
WHERE `customerid`= :cid AND `id`= :id
");
$params = array(
"dest" => makeCorrectDestination($result['destination']),
"cid" => $customer['customerid'],
"id" => $id
);
Database::pexecute($stmt, $params, true, true);
// update customer usage
Customers::decreaseUsage($customer['customerid'], 'email_forwarders_used');
// update admin usage
Admins::decreaseUsage($customer['adminid'], 'email_forwarders_used');
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email forwarder for '" . $result['email_full'] . "'");
$result = $this->apiCall('Emails.get', array(
'emailaddr' => $result['email_full']
));
return $this->response(200, "successfull", $result);
}
throw new Exception("Unknown forwarder id", 404);
return $this->response(200, "successfull", $result);
}
throw new Exception("No more resources available", 406);
throw new Exception("Unknown forwarder id", 404);
}
}