CreateAccount.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\Http\Actions;
  3. use ThurData\Servers\KerioEmail\App\Enums\Response;
  4. use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
  5. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  6. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain;
  7. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Traits\ProductManagerHandler;
  8. use ThurData\Servers\KerioEmail\App\Traits\ExtensionsCheckerTrait;
  9. use ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController;
  10. use ThurData\Servers\KerioEmail\App\Traits\HostingService;
  11. use \ThurData\Servers\KerioEmail\Core\UI\Traits\WhmcsParams;
  12. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  13. /**
  14. *
  15. * Created by PhpStorm.
  16. * User: ThurData
  17. * Date: 09.09.19
  18. * Time: 15:14
  19. * Class CreateAccount
  20. */
  21. class CreateAccount extends AddonController
  22. {
  23. use ExtensionsCheckerTrait;
  24. use HostingService;
  25. use WhmcsParams;
  26. /**
  27. * create domain in kerio
  28. *
  29. * @param null $params
  30. * @return string
  31. */
  32. public function execute($params = null)
  33. {
  34. try{
  35. /**
  36. * check if extensions are installed
  37. */
  38. $this->checkExtensionOrThrowError();
  39. //update domain
  40. if($params['customfields']['maildomain']){
  41. $params['domain'] = $params['customfields']['maildomain'];
  42. $this->hosting()->domain = $params['domain'];
  43. $this->hosting()->save();
  44. }
  45. /**
  46. * run kerio service
  47. */
  48. $result = $this->kerioRunService($params);
  49. return $result;
  50. }catch (\Exception $ex)
  51. {
  52. /**
  53. * return some crit error
  54. */
  55. return $ex->getMessage();
  56. }
  57. }
  58. /**
  59. * @param null $params
  60. * @return mixed|string
  61. */
  62. protected function kerioRunService($params = null)
  63. {
  64. $productManager = new ProductManager();
  65. $productManager->loadById($params['pid']);
  66. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  67. try {
  68. $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
  69. $result = $api->createDomain($params['domain']);
  70. $domainID = $result['result'][0]['id'];
  71. $api->logout();
  72. logModuleCall(
  73. 'kerioEmail',
  74. __FUNCTION__,
  75. $productManager,
  76. 'Debug ID',
  77. $productManager->get('acc_base')
  78. );
  79. } catch (KerioApiException $error) {
  80. logModuleCall(
  81. 'kerioEmail',
  82. __FUNCTION__,
  83. $error,
  84. 'Debug Error',
  85. $error->getMessage()
  86. );
  87. return ['error' => $error->getMessage()];
  88. }
  89. /**
  90. * return success response
  91. */
  92. return Response::SUCCESS;
  93. }
  94. }