| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace ThurData\Servers\KerioEmail\App\Http\Actions;
- use ThurData\Servers\KerioEmail\App\Enums\Response;
- 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\Domain;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Traits\ProductManagerHandler;
- use ThurData\Servers\KerioEmail\App\Traits\ExtensionsCheckerTrait;
- use ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController;
- use ThurData\Servers\KerioEmail\App\Traits\HostingService;
- use \ThurData\Servers\KerioEmail\Core\UI\Traits\WhmcsParams;
- use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
- /**
- *
- * Created by PhpStorm.
- * User: ThurData
- * Date: 09.09.19
- * Time: 15:14
- * Class CreateAccount
- */
- class CreateAccount extends AddonController
- {
- use ExtensionsCheckerTrait;
- use HostingService;
- use WhmcsParams;
-
- /**
- * create domain in kerio
- *
- * @param null $params
- * @return string
- */
- public function execute($params = null)
- {
- try{
- /**
- * check if extensions are installed
- */
- $this->checkExtensionOrThrowError();
- //update domain
- if($params['customfields']['maildomain']){
- $params['domain'] = $params['customfields']['maildomain'];
- $this->hosting()->domain = $params['domain'];
- $this->hosting()->save();
- }
- /**
- * run kerio service
- */
- $result = $this->kerioRunService($params);
- return $result;
- }catch (\Exception $ex)
- {
- /**
- * return some crit error
- */
- return $ex->getMessage();
- }
- }
- /**
- * @param null $params
- * @return mixed|string
- */
- protected function kerioRunService($params = null)
- {
- $productManager = new ProductManager();
- $productManager->loadById($params['pid']);
- $acc_limit = $productManager->get('acc_limit');
- $accounts = $productManager->get('acc_base') + $params['configoptions']['acc_add'] + $params['configoptions']['acc_new'];
- if ($acc_limit >= 0) {
- if ($accounts > $acc_limit) {
- $accounts = $acc_limit;
- }
- }
- $domainMaxSize = $productManager->get('domainMaxSize');
- $domainSize = $productManager->get('domainBaseSize') + $params['configoptions']['domainAddSize'] + $params['configoptions']['domainNewSize'];
- if ($domainMaxSize >= 0) {
- if ($domainSize > $domainMaxSize) {
- $domainSize = $domainMaxSize;
- }
- }
- $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
- try {
- $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
- $result = $api->createDomain($params['domain']);
- $domainID = $result['result'][0]['id'];
- $api->logout();
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $accounts,
- 'Debug ID',
- $domainSize
- );
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
-
- return ['error' => $error->getMessage()];
- }
- /**
- * return success response
- */
- return Response::SUCCESS;
- }
- }
|