CreateAccount.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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\Configuration\Addon\Update\AddonUpgradeService;
  21. use ModulesGarden\ProxmoxAddon\App\Models\ModuleSettings;
  22. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  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\Cloud\HostingService;
  27. use ModulesGarden\ProxmoxAddon\App\Enum\Cloud\CustomField;
  28. use ModulesGarden\ProxmoxAddon\App\Services\Utility;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\AppParams;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\ProxmoxAddonValidator;
  31. use ModulesGarden\Servers\ProxmoxCloudVps\Core\App\Controllers\Instances\AddonController;
  32. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\WhmcsParams;
  33. class CreateAccount extends AddonController
  34. {
  35. use WhmcsParams;
  36. use ProductService;
  37. use ApiService;
  38. use UserService;
  39. use HostingService;
  40. /**
  41. * @var AddonUpgradeService
  42. */
  43. private $addonUpgradeService;
  44. public function execute($params = null)
  45. {
  46. if(!ProxmoxAddonValidator::isInstalled()){
  47. return ProxmoxAddonValidator::failAsString();
  48. }
  49. try
  50. {
  51. (new AppParams())->initFromWhmcsParams();
  52. $this->addonUpgradeService = new AddonUpgradeService();
  53. $this->networkService = new NetworkService();
  54. $this->addonUpgradeService->run();
  55. if(!$this->configuration()->getTagFrom() || !$this->configuration()->getTagTo() && $this->configuration()->isPermissionVirtualNetwork()){
  56. throw new \Exception("Product configuration validator error: VLAN TAG Range Number is empty.");
  57. }
  58. //Bandwith limit
  59. $this->saveUsageLimit();
  60. //Assing ip
  61. if (!Utility::isIpManagerProxmoxCloudIntegration())
  62. {
  63. list($ip4, $ip6) = $this->networkService->getIpAddressesRequest();
  64. $this->networkService->addIp($ip4, $ip6, $this->getDefaultNodeIfSet());
  65. }
  66. if( $this->isUser()){
  67. return "success";
  68. }
  69. $this->userCreate();
  70. $this->customFieldUpdate(CustomField::AUTHENTICATION, $this->configuration()->getRealm());
  71. return "success";
  72. }
  73. catch (\Exception $ex)
  74. {
  75. if (ModuleSettings::isDebug())
  76. {
  77. logModuleCall(
  78. 'ProxmoxCloudVps',
  79. __CLASS__,
  80. [],
  81. null,
  82. $ex->getMessage() . " " . $ex->getTraceAsString()
  83. );
  84. }
  85. return $ex->getMessage();
  86. }
  87. }
  88. }