CreateAccount.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\Traits\ExtensionsCheckerTrait;
  8. use ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController;
  9. use ThurData\Servers\KerioEmail\App\Traits\HostingService;
  10. use \ThurData\Servers\KerioEmail\Core\UI\Traits\WhmcsParams;
  11. use ThurData\Servers\KerioEmail\Api\KerioConnectApi;
  12. /**
  13. *
  14. * Created by PhpStorm.
  15. * User: ThurData
  16. * Date: 09.09.19
  17. * Time: 15:14
  18. * Class CreateAccount
  19. */
  20. class CreateAccount extends AddonController
  21. {
  22. use ExtensionsCheckerTrait;
  23. use HostingService;
  24. use WhmcsParams;
  25. /**
  26. * create domain in kerio
  27. *
  28. * @param null $params
  29. * @return string
  30. */
  31. public function execute($params = null)
  32. {
  33. try{
  34. /**
  35. * check if extensions are installed
  36. */
  37. $this->checkExtensionOrThrowError();
  38. //update domain
  39. if($params['customfields']['maildomain']){
  40. $params['domain'] = $params['customfields']['maildomain'];
  41. $this->hosting()->domain = $params['domain'];
  42. $this->hosting()->save();
  43. }
  44. /**
  45. * run kerio service
  46. */
  47. $result = $this->kerioRunService($params);
  48. return $result;
  49. }catch (\Exception $ex)
  50. {
  51. /**
  52. * return some crit error
  53. */
  54. return $ex->getMessage();
  55. }
  56. }
  57. /**
  58. * @param null $params
  59. * @return mixed|string
  60. */
  61. protected function kerioRunService($params = null)
  62. {
  63. $domains = array($params['domain']);
  64. $api = new KerioConnectApi('whmcsKerioEmail', 'Thurdata', '1.0');
  65. try {
  66. $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
  67. $result = $api->sendRequest('Domains.create', $domains);
  68. logModuleCall(
  69. 'kerioEmail',
  70. __FUNCTION__,
  71. $domains,
  72. 'Debug Features & Attributes',
  73. $result
  74. );
  75. $api->logout();
  76. } catch (KerioApiException $error) {
  77. logModuleCall(
  78. 'kerioEmail',
  79. __FUNCTION__,
  80. $error,
  81. 'Debug Error',
  82. $error->getMessage()
  83. );
  84. return ['error' => $error->getMessage()];
  85. }
  86. /**
  87. * return success response
  88. */
  89. return Response::SUCCESS;
  90. }
  91. }