UnsuspendAccount.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\ProxmoxVps\App\Http\Actions;
  20. use MGProvision\Proxmox\v2\models\Kvm;
  21. use MGProvision\Proxmox\v2\models\User;
  22. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  23. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  24. use ModulesGarden\ProxmoxAddon\App\Services\Vps\UserService;
  25. use ModulesGarden\Servers\ProxmoxVps\App\Helpers\AppParams;
  26. use ModulesGarden\Servers\ProxmoxVps\App\Helpers\ProxmoxAddonValidator;
  27. use ModulesGarden\Servers\ProxmoxVps\Core\App\Controllers\Instances\AddonController;
  28. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Traits\WhmcsParams;
  29. class UnsuspendAccount extends AddonController
  30. {
  31. use ApiService;
  32. use UserService;
  33. use ProductService;
  34. use WhmcsParams;
  35. public function execute($params = null)
  36. {
  37. if(!ProxmoxAddonValidator::isInstalled()){
  38. return ProxmoxAddonValidator::failAsString();
  39. }
  40. (new AppParams())->initFromWhmcsParams();
  41. try
  42. {
  43. //User Unsuspend
  44. $user = $this->getUser();
  45. $userService = new User("{$user->username}@{$user->realm}");
  46. $userService->setApi($this->api());
  47. if ($userService->configuration()['enable'] == "0")
  48. {
  49. $userService->enable();
  50. }
  51. //VM Permission
  52. $permissions = $userService->permissions();
  53. $vmid = $params['customfields']['vmid'];
  54. foreach ($permissions as $p)
  55. {
  56. if ($p['path'] == "/vms/" . $vmid && $p['ugid'] == $userService->getUserid())
  57. {
  58. $userService->updatePermission($vmid, $p['roleid'], 1);
  59. }
  60. }
  61. $role = $this->configuration()->getUserRole() ? $this->configuration()->getUserRole() : 'PVEVMUser';
  62. $userService->updatePermission($vmid, $role);
  63. if ($this->configuration()->isOnboot())
  64. {
  65. $this->vm()->updateConfig(["onboot" => 1]);
  66. }
  67. $status = $this->vm()->status();
  68. if ($this->vm() instanceof Kvm && $status['qmpstatus'] == "paused")
  69. {
  70. $this->vm()->resume();
  71. }
  72. else
  73. {
  74. if ($status['status'] == "running")
  75. {
  76. return "success";
  77. }
  78. else
  79. {
  80. $this->vm()->start();
  81. }
  82. }
  83. return "success";
  84. }
  85. catch (\Exception $ex)
  86. {
  87. return $ex->getMessage();
  88. }
  89. }
  90. }