TerminateAccount.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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\VirtualNetwork;
  21. use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\Hosting;
  22. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  23. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  24. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\UserService;
  25. use ModulesGarden\ProxmoxAddon\App\Services\CloudService;
  26. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\HighAvailabilityClusterService;
  27. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\HostingService;
  28. use ModulesGarden\ProxmoxAddon\Core\Models\ModuleSettings\Model as ModuleSettings;
  29. use ModulesGarden\ProxmoxAddon\App\Enum\Cloud\CustomField;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\AppParams;
  31. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\ProxmoxAddonValidator;
  32. use ModulesGarden\Servers\ProxmoxCloudVps\Core\App\Controllers\Instances\AddonController;
  33. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\WhmcsParams;
  34. class TerminateAccount extends AddonController
  35. {
  36. use WhmcsParams;
  37. use ProductService;
  38. use ApiService;
  39. use UserService;
  40. use HostingService;
  41. /**
  42. * @var HighAvailabilityClusterService
  43. */
  44. private $highAvailabilityClusterService;
  45. public function __construct()
  46. {
  47. $this->highAvailabilityClusterService = new HighAvailabilityClusterService();
  48. }
  49. /**
  50. * @param null $params
  51. * @return string
  52. * @todo delete vms
  53. */
  54. public function execute($params = null)
  55. {
  56. (new AppParams())->initFromParams($params);
  57. if(!ProxmoxAddonValidator::isInstalled()){
  58. return ProxmoxAddonValidator::failAsString();
  59. }
  60. try
  61. {
  62. if (!$this->getWhmcsParamByKey('serviceid'))
  63. {
  64. throw new \InvalidArgumentException("The Service Id cannot be empty");
  65. }
  66. $serviceId = $this->getWhmcsParamByKey('serviceid');
  67. //User delete
  68. if ($this->isUser())
  69. {
  70. $this->deleteUser();
  71. }
  72. //virtual networks
  73. VirtualNetwork::ofHostingId($serviceId)->delete();
  74. //vms
  75. $cloudService = new CloudService();
  76. $cloudService->destroy();
  77. //Reset Custom Fields
  78. if ($this->getWhmcsCustomField(CustomField::TAG))
  79. {
  80. $this->customFieldUpdate(CustomField::TAG, "");
  81. }
  82. $this->customFieldUpdate(CustomField::AUTHENTICATION, "");
  83. //Cache
  84. ModuleSettings::where('setting', "LIKE", "%{$serviceId}_cacheData%")->delete();
  85. //ip addresses
  86. Hosting::where("id", $this->getWhmcsParamByKey('serviceid'))
  87. ->update(["dedicatedip" => "", "assignedips" => ""]);
  88. return "success";
  89. }
  90. catch (\Exception $ex)
  91. {
  92. if (\ModulesGarden\ProxmoxAddon\App\Models\ModuleSettings::isDebug())
  93. {
  94. logModuleCall(
  95. 'ProxmoxCloudVps',
  96. __CLASS__,
  97. [],
  98. null,
  99. $ex->getMessage() . " " . $ex->getTraceAsString()
  100. );
  101. }
  102. return $ex->getMessage();
  103. }
  104. }
  105. }