CreateAccount.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. //update hostname
  70. if($params['customfields']['VDCName']){
  71. $this->hosting()->domain = $params['customfields']['VDCName'];
  72. $this->hosting()->save();
  73. }
  74. //throw errors
  75. if ($this->errors)
  76. {
  77. throw new \Exception(implode(", ", $this->errors));
  78. }
  79. if( $this->isUser()){
  80. return "success";
  81. }
  82. $this->userCreate();
  83. $this->customFieldUpdate(CustomField::AUTHENTICATION, $this->configuration()->getRealm());
  84. return "success";
  85. }
  86. catch (\Exception $ex)
  87. {
  88. if (ModuleSettings::isDebug())
  89. {
  90. logModuleCall(
  91. 'ProxmoxCloudVps',
  92. __CLASS__,
  93. [],
  94. null,
  95. $ex->getMessage() . " " . $ex->getTraceAsString()
  96. );
  97. }
  98. return $ex->getMessage();
  99. }
  100. }
  101. }