CreateAccount.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. $api = new KerioConnectApi('whmcsKerioEmail', 'Thurdata', '1.0');
  64. try {
  65. $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
  66. $result = $api->sendRequest('Domains.get');
  67. $api->logout();
  68. } catch (KerioApiException $error) {
  69. return ['error' => $error->getMessage()];
  70. }
  71. logModuleCall(
  72. 'kerioEmail',
  73. __FUNCTION__,
  74. $result,
  75. 'Debug Features & Attributes',
  76. $params
  77. );
  78. /**
  79. * return success response
  80. */
  81. return Response::SUCCESS;
  82. }
  83. }