VirtualNetworkSection.php 2.8 KB

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