MainForm.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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\ProxmoxVps\App\UI\Admin\Product\Forms;
  20. use ModulesGarden\Servers\ProxmoxVps\App\Helpers\LicenseValidator;
  21. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Buttons\VirtualizationChangButton;
  22. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Providers\ProductProvider;
  23. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\AdminNotificationSection;
  24. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\AlertSection;
  25. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\BackupSection;
  26. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\ClientNotificationSection;
  27. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\ConsoleSection;
  28. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\FirewallOptionSection;
  29. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\FirewallSection;
  30. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\HighAvailabilityClusterSection;
  31. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\LoadBalancerSection;
  32. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\Lxc;
  33. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\MainSection;
  34. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\MiscellaneousSection;
  35. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\Qemu;
  36. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\UserSection;
  37. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AdminArea;
  38. use ModulesGarden\Servers\ProxmoxVps\Core\UI\MainContainer;
  39. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Switcher;
  40. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\FormIntegration;
  41. class MainForm extends FormIntegration implements AdminArea
  42. {
  43. use LicenseValidator;
  44. public function initContent()
  45. {
  46. /**
  47. *
  48. */
  49. $this->initIds('mainForm');
  50. $this->setProvider(new ProductProvider($this->getRequestValue('id')));
  51. $this->addSection(new VirtualizationChangButton());
  52. $this->dataProvider->initData();
  53. /**
  54. *
  55. */
  56. $isQemu = !$this->dataProvider->getValueById('customconfigoption[virtualization]') || $this->dataProvider->getValueById('customconfigoption[virtualization]') == "qemu";
  57. $this->licenseAlert();
  58. /**
  59. * Main Section
  60. */
  61. $section = new MainSection();
  62. $section->setMainContainer($this->mainContainer);
  63. $this->addSection($section);
  64. if ($isQemu)
  65. {
  66. // KVM
  67. $this->addSection((new Qemu\ContainerSection())->enableToggler())
  68. ->addSection((new Qemu\NetworkSection())->enableToggler())
  69. ->addSection((new Qemu\DiskSection())->enableToggler())
  70. ->addSection((new Qemu\DiskSpeedSection())->enableTogglerAndHide())
  71. ->addSection((new Qemu\AdditonalDisk())->enableToggler())
  72. ->addSection((new Qemu\AdditonalDiskSpeedSection())->enableToggler())
  73. ->addSection((new BackupSection())->enableToggler())
  74. ->addSection((new Qemu\BootSection())->enableTogglerAndHide())
  75. ->addSection((new FirewallSection())->enableTogglerAndHide())
  76. ->addSection((new FirewallOptionSection())->enableTogglerAndHide())
  77. ->addSection((new Qemu\CloudInitSection())->enableTogglerAndHide())
  78. ->addSection((new Qemu\GuestAgentSection())->enableTogglerAndHide())
  79. ->addSection((new UserSection())->enableTogglerAndHide())
  80. ->addSection((new MiscellaneousSection())->enableTogglerAndHide())
  81. ->addSection((new LoadBalancerSection())->enableTogglerAndHide())
  82. ->addSection((new Qemu\ConfigurationSection())->enableTogglerAndHide())
  83. ->addSection((new Qemu\AdvancedSection())->enableTogglerAndHide())
  84. ->addSection((new HighAvailabilityClusterSection())->enableTogglerAndHide())
  85. ->addSection((new ConsoleSection())->enableTogglerAndHide())
  86. ->addSection((new AdminNotificationSection())->enableTogglerAndHide())
  87. ->addSection((new ClientNotificationSection())->enableTogglerAndHide())
  88. ->addSection((new Qemu\ClientAreaSection())->enableToggler())
  89. ->addSection((new Qemu\ConfigurableOptionUnitsSection())->enableToggler());
  90. }
  91. else
  92. {
  93. //LXC
  94. $this->addSection((new Lxc\ContainerSection())->enableToggler())
  95. ->addSection((new Lxc\MountPointSection())->enableToggler())
  96. ->addSection((new BackupSection())->enableToggler())
  97. ->addSection((new Lxc\NetworkSection())->enableToggler())
  98. ->addSection((new FirewallSection())->enableTogglerAndHide())
  99. ->addSection((new FirewallOptionSection())->enableTogglerAndHide())
  100. ->addSection((new UserSection())->enableTogglerAndHide())
  101. ->addSection((new MiscellaneousSection())->enableTogglerAndHide())
  102. ->addSection((new LoadBalancerSection())->enableTogglerAndHide())
  103. ->addSection((new Lxc\ConfigurationSection())->enableTogglerAndHide())
  104. ->addSection((new HighAvailabilityClusterSection())->enableTogglerAndHide())
  105. ->addSection((new ConsoleSection())->enableTogglerAndHide())
  106. ->addSection((new AdminNotificationSection())->enableTogglerAndHide())
  107. ->addSection((new ClientNotificationSection())->enableTogglerAndHide())
  108. ->addSection((new Lxc\ClientAreaSection())->enableToggler())
  109. ->addSection((new Lxc\ConfigurableOptionUnitsSection())->enableToggler());
  110. }
  111. $this->loadDataToForm();
  112. }
  113. public function getSwitcherFields()
  114. {
  115. $this->setMainContainer(new MainContainer());
  116. $this->runInitContentProcess();
  117. $fieldNames = [];
  118. foreach ($this->getSections() as $section)
  119. {
  120. foreach ((array)$section->getSections() as $s)
  121. {
  122. foreach ($s->getFields() as $field)
  123. {
  124. if (!$field instanceof Switcher)
  125. {
  126. continue;
  127. }
  128. $name = str_replace(["customconfigoption[", "]"], ["", ""], $field->getName());
  129. $fieldNames[] = $name;
  130. }
  131. }
  132. }
  133. return array_unique($fieldNames);
  134. }
  135. public function licenseAlert(){
  136. if(!$this->isLicensePayingFullAnnuallyPrice(true)){
  137. $this->addSection(new AlertSection("You can use proxy for Proxmox console connections to increase the security of your infrastructure. Please contact <a href='https://www.modulesgarden.com/support/ticket/product-presales/Proxmox%20module%20upgrade%20request%20-%20Proxy%20console' target='_blank'>ModulesGarden support</a> to get more details and upgrade your module."));
  138. }
  139. }
  140. }