VirtualNetworkSection.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Sections;
  3. use ModulesGarden\ProxmoxAddon\App\Models\VirtualNetwork;
  4. use ModulesGarden\ProxmoxAddon\App\Models\VmIpAddress;
  5. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  6. use ModulesGarden\ProxmoxAddon\App\Services\Ip\Ipv4Range;
  7. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  8. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Buttons\ButtonBase;
  9. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Select;
  10. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\BaseSection;
  11. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\BoxSection;
  12. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\HalfPageSection;
  13. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  14. class VirtualNetworkSection extends BaseSection implements ClientArea
  15. {
  16. use ProductService;
  17. public function initContent()
  18. {
  19. $this->initIds('virtualNetworkSection');
  20. $this->initFields();
  21. }
  22. public function initFields()
  23. {
  24. //virtualNetwork
  25. if($this->configuration()->isOrderPublicIp()){
  26. $this->customTplVars['virtualNetwork'] = ["public" => sl('lang')->abtr('Public')];
  27. }
  28. //ips
  29. $this->customTplVars['ips']=[];
  30. //Public
  31. $this->customTplVars['ipSelected'] =null;
  32. if($this->configuration()->isOrderPublicIp()){
  33. foreach (VmIpAddress::ofHostingId($this->getWhmcsParamByKey('serviceid'))->ofVmIdNull()->get() as $ip)
  34. {
  35. if(!$this->customTplVars['ipSelected'] ){
  36. $this->customTplVars['ipSelected'] = $ip->ip;
  37. }
  38. $this->customTplVars['ips'][] =[
  39. "networkId" => "public",
  40. "ip" => $ip->ip,
  41. "id" => $ip->id
  42. ];
  43. }
  44. }
  45. if(empty($this->customTplVars['ips'])){
  46. unset($this->customTplVars['virtualNetwork']['public']);
  47. }
  48. //private
  49. foreach (VirtualNetwork::ofHostingId($this->getWhmcsParamByKey('serviceid'))->get() as $vn)
  50. {
  51. $this->customTplVars['virtualNetwork'][$vn->id] = $vn->name;
  52. $ipRange = new Ipv4Range($vn->pool, $vn->cidr);
  53. $ipRange->setLimit(255);
  54. $ipRange->disableIpAddresses( $vn->virtualInterfaces->pluck('ip')->toArray());
  55. foreach ( $ipRange->get() as $ip ){
  56. $this->customTplVars['ips'][]=[
  57. "networkId" => $vn->id,
  58. "ip" => $ip,
  59. ];
  60. }
  61. }
  62. }
  63. }