CreateAccount.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. if($this->configuration()->isOrderPublicIp()){
  64. list($ip4, $ip6) = $this->networkService->getIpAddressesRequest();
  65. $bridge = $this->configuration()->getBridge();
  66. $this->networkService->addIp($ip4, $ip6, $this->getDefaultNodeIfSet(), $bridge);
  67. }
  68. }
  69. if( $this->isUser()){
  70. return "success";
  71. }
  72. $this->userCreate();
  73. $this->customFieldUpdate(CustomField::AUTHENTICATION, $this->configuration()->getRealm());
  74. return "success";
  75. }
  76. catch (\Exception $ex)
  77. {
  78. if (ModuleSettings::isDebug())
  79. {
  80. logModuleCall(
  81. 'ProxmoxCloudVps',
  82. __CLASS__,
  83. [],
  84. null,
  85. $ex->getMessage() . " " . $ex->getTraceAsString()
  86. );
  87. }
  88. return $ex->getMessage();
  89. }
  90. }
  91. }