VirtualNetworkSection.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. $this->customTplVars['virtualNetwork'] = ["public" => sl('lang')->abtr('Public')];
  26. //ips
  27. $this->customTplVars['ips']=[];
  28. //Public
  29. $this->customTplVars['ipSelected'] =null;
  30. foreach (VmIpAddress::ofHostingId($this->getWhmcsParamByKey('serviceid'))->ofVmIdNull()->get() as $ip)
  31. {
  32. if(!$this->customTplVars['ipSelected'] ){
  33. $this->customTplVars['ipSelected'] = $ip->ip;
  34. }
  35. $this->customTplVars['ips'][] =[
  36. "networkId" => "public",
  37. "ip" => $ip->ip,
  38. "id" => $ip->id
  39. ];
  40. }
  41. if(empty($this->customTplVars['ips'])){
  42. unset($this->customTplVars['virtualNetwork']['public']);
  43. }
  44. //private
  45. foreach (VirtualNetwork::ofHostingId($this->getWhmcsParamByKey('serviceid'))->get() as $vn)
  46. {
  47. $this->customTplVars['virtualNetwork'][$vn->id] = $vn->name;
  48. $ipRange = new Ipv4Range($vn->pool, $vn->cidr);
  49. $ipRange->setLimit(255);
  50. $ipRange->disableIpAddresses( $vn->virtualInterfaces->pluck('ip')->toArray());
  51. foreach ( $ipRange->get() as $ip ){
  52. $this->customTplVars['ips'][]=[
  53. "networkId" => $vn->id,
  54. "ip" => $ip,
  55. ];
  56. }
  57. }
  58. }
  59. }