SuspendAccount.php 2.5 KB

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