CreateAccount.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. $domainParams = array(
  64. "query" => array(
  65. "fields" => array(
  66. "id",
  67. "name",
  68. "description",
  69. "aliasList",
  70. "userMaxCount",
  71. "outgoingMessageLimit",
  72. "isPrimary",
  73. "renameInfo",
  74. "forwardingOptions",
  75. "kerberosRealm",
  76. "winNtName",
  77. "ipAddressBind",
  78. "pamRealm",
  79. "keepForRecovery",
  80. "isDistributed"),
  81. "start" => 0,
  82. "limit" => -1,
  83. "orderBy" => array(array(
  84. "columnName" => "name",
  85. "direction" => "Asc"
  86. ))
  87. )
  88. );
  89. $api = new KerioConnectApi('whmcsKerioEmail', 'Thurdata', '1.0');
  90. try {
  91. $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
  92. $result = $api->sendRequest('Domains.get', $domainParams);
  93. logModuleCall(
  94. 'kerioEmail',
  95. __FUNCTION__,
  96. $api,
  97. 'Debug Features & Attributes',
  98. $result
  99. );
  100. $api->logout();
  101. } catch (KerioApiException $error) {
  102. logModuleCall(
  103. 'kerioEmail',
  104. __FUNCTION__,
  105. $error,
  106. 'Debug Error',
  107. $error->getMessage()
  108. );
  109. return ['error' => $error->getMessage()];
  110. }
  111. /**
  112. * return success response
  113. */
  114. return Response::SUCCESS;
  115. }
  116. }