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