ChangePackage.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**********************************************************************
  3. * ProxmoxVPS developed. (26.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. **********************************************************************/
  19. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\Http\Actions;
  20. use ModulesGarden\ProxmoxAddon\App\Models\ModuleSettings;
  21. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\HostingService;
  23. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\NetworkService;
  24. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  25. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\UserService;
  26. use ModulesGarden\ProxmoxAddon\App\Services\Utility;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\AppParams;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\ProxmoxAddonValidator;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\Core\App\Controllers\Instances\AddonController;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\WhmcsParams;
  31. class ChangePackage extends AddonController
  32. {
  33. use ApiService;
  34. use UserService;
  35. use ProductService;
  36. use WhmcsParams;
  37. use HostingService;
  38. /**
  39. * @param null $params
  40. * @return bool|string
  41. * @todo Resources validation
  42. */
  43. public function execute($params = null)
  44. {
  45. try {
  46. if(!ProxmoxAddonValidator::isInstalled()){
  47. return ProxmoxAddonValidator::failAsString();
  48. }
  49. (new AppParams())->initFromWhmcsParams();
  50. $this->networkService = new NetworkService();
  51. //Bandwith limit
  52. $this->saveUsageLimit();
  53. //Assing ip
  54. if (!Utility::isIpManagerProxmoxCloudIntegration())
  55. {
  56. list($ip4, $ip6) = $this->networkService->getIpAddressesRequest();
  57. $this->networkService->addIp($ip4, $ip6, $this->getDefaultNodeIfSet());
  58. }
  59. return "success";
  60. }catch (\Exception $ex)
  61. {
  62. if (ModuleSettings::isDebug())
  63. {
  64. logModuleCall(
  65. 'ProxmoxCloudVps',
  66. __CLASS__,
  67. [],
  68. null,
  69. $ex->getMessage() . " " . $ex->getTraceAsString()
  70. );
  71. }
  72. return $ex->getMessage();
  73. }
  74. }
  75. }