CreateAccount.php 2.9 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\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. use ProductManagerHandler;
  27. /**
  28. * create domain in kerio
  29. *
  30. * @param null $params
  31. * @return string
  32. */
  33. public function execute($params = null)
  34. {
  35. try{
  36. /**
  37. * check if extensions are installed
  38. */
  39. $this->checkExtensionOrThrowError();
  40. //update domain
  41. if($params['customfields']['maildomain']){
  42. $params['domain'] = $params['customfields']['maildomain'];
  43. $this->hosting()->domain = $params['domain'];
  44. $this->hosting()->save();
  45. }
  46. /**
  47. * run kerio service
  48. */
  49. $result = $this->kerioRunService($params);
  50. return $result;
  51. }catch (\Exception $ex)
  52. {
  53. /**
  54. * return some crit error
  55. */
  56. return $ex->getMessage();
  57. }
  58. }
  59. /**
  60. * @param null $params
  61. * @return mixed|string
  62. */
  63. protected function kerioRunService($params = null)
  64. {
  65. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  66. try {
  67. $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
  68. $result = $api->createDomain($params['domain']);
  69. $domainID = $result['result'][0]['id'];
  70. $api->logout();
  71. logModuleCall(
  72. 'kerioEmail',
  73. __FUNCTION__,
  74. $params,
  75. 'Debug ID',
  76. $this->productManager->getProductManager()
  77. );
  78. } catch (KerioApiException $error) {
  79. logModuleCall(
  80. 'kerioEmail',
  81. __FUNCTION__,
  82. $error,
  83. 'Debug Error',
  84. $error->getMessage()
  85. );
  86. return ['error' => $error->getMessage()];
  87. }
  88. /**
  89. * return success response
  90. */
  91. return Response::SUCCESS;
  92. }
  93. }