|
|
@@ -1,10 +1,6 @@
|
|
|
<?php
|
|
|
namespace ThurData\Servers\KerioEmail\App\UI\Client\EmailAlias\Providers;
|
|
|
-use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
|
|
|
-use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
|
|
|
-use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\AccountAlias;
|
|
|
-use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository;
|
|
|
-use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
|
|
|
+
|
|
|
use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
|
|
|
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
|
|
|
use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
|
|
|
@@ -22,24 +18,11 @@ class AddEmailAliasDataProvider extends BaseDataProvider
|
|
|
|
|
|
public function read()
|
|
|
{
|
|
|
- /**
|
|
|
- * hosting id
|
|
|
- */
|
|
|
- $hid = $this->getRequestValue('id');
|
|
|
-
|
|
|
- /**
|
|
|
- * hosting model
|
|
|
- */
|
|
|
- $hosting = Hosting::where('id', $hid)->first();
|
|
|
-
|
|
|
- /**
|
|
|
- * hosting domain
|
|
|
- */
|
|
|
- $this->data['domain'] = $hosting->domain;
|
|
|
+ $this->data['domain'] = $this->getWhmcsParamByKey('domain');
|
|
|
$api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
|
|
|
try {
|
|
|
$api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
|
|
|
- $domains = $api->getDomains(['id','name']);
|
|
|
+ $domainsID = $api->getDomainId($this->data['domain']);
|
|
|
} catch (KerioApiException $error) {
|
|
|
logModuleCall(
|
|
|
'kerioEmail',
|
|
|
@@ -50,19 +33,12 @@ class AddEmailAliasDataProvider extends BaseDataProvider
|
|
|
);
|
|
|
return ['error' => $error->getMessage()];
|
|
|
}
|
|
|
- foreach($domains as $maildomain) {
|
|
|
- if(($maildomain['name']) === $this->data['domain']){
|
|
|
- $this->maildomainID = $maildomain['id'];
|
|
|
- $this->maildomain = $maildomain['name'];
|
|
|
- }
|
|
|
- }
|
|
|
- $productManager = new ProductManager();
|
|
|
- $productManager->loadByHostingId($hosting->id);
|
|
|
+
|
|
|
$fields = array(
|
|
|
"id",
|
|
|
"loginName"
|
|
|
);
|
|
|
- $accounts = $api->getUsers($fields,$this->maildomainID);
|
|
|
+ $accounts = $api->getUsers($fields,$domainID);
|
|
|
$api->logout();
|
|
|
|
|
|
/**
|
|
|
@@ -70,28 +46,18 @@ class AddEmailAliasDataProvider extends BaseDataProvider
|
|
|
*/
|
|
|
foreach($accounts as $account)
|
|
|
{
|
|
|
- $this->availableValues['mailbox'][$account['loginName']] = $account['loginName'] . '@' . $this->maildomain;
|
|
|
+ $this->availableValues['mailbox'][$account['loginName']] = $account['loginName'] . '@' . $this->data['domain'];
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public function create()
|
|
|
{
|
|
|
- /**
|
|
|
- * hosting id
|
|
|
- */
|
|
|
- $hid = $this->request->get('id');
|
|
|
-
|
|
|
- /**
|
|
|
- * product manager allow to check product settings
|
|
|
- */
|
|
|
- $productManager = new ProductManager();
|
|
|
- $productManager->loadByHostingId($hid);
|
|
|
-
|
|
|
+ $domain = $this->getWhmcsParamByKey('domain');
|
|
|
$api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
|
|
|
try {
|
|
|
$api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
|
|
|
- $domains = $api->getDomains(['id','name']);
|
|
|
+ $domainID = $api->getDomainId($domain);
|
|
|
} catch (KerioApiException $error) {
|
|
|
logModuleCall(
|
|
|
'kerioEmail',
|
|
|
@@ -102,14 +68,8 @@ class AddEmailAliasDataProvider extends BaseDataProvider
|
|
|
);
|
|
|
return ['error' => $error->getMessage()];
|
|
|
}
|
|
|
- foreach($domains as $maildomain) {
|
|
|
- if(($maildomain['name']) === $this->formData['domain']){
|
|
|
- $this->maildomainID = $maildomain['id'];
|
|
|
- $this->maildomain = $maildomain['name'];
|
|
|
- }
|
|
|
- }
|
|
|
try {
|
|
|
- $result = $api->createAlias($this->maildomainID, $this->formData['aliasName'], $this->formData['mailbox'] . '@' . $this->maildomain);
|
|
|
+ $result = $api->createAlias($domainID, $this->formData['aliasName'], $this->formData['mailbox'] . '@' . $domain);
|
|
|
} catch (KerioApiException $error) {
|
|
|
logModuleCall(
|
|
|
'kerioEmail',
|