GeneralSection.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmUpdate\Sections\Lxc;
  3. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  4. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ResourceManager;
  5. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\CpulimitValidator;
  6. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\HostnameValidator;
  7. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\IpAddressValidator;
  8. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\NumberValidator;
  9. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\PasswordValidator;
  10. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmUpdate\Fields\IsoImageSelect;
  11. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmUpdate\Fields\OsTemplateSelect;
  12. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Range;
  13. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Text;
  14. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Textarea;
  15. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\BaseSection;
  16. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  17. class GeneralSection extends BaseSection
  18. {
  19. use ProductService;
  20. /**
  21. * @var ResourceManager
  22. */
  23. protected $resourceManager;
  24. public function initContent()
  25. {
  26. $this->initIds('generalSection');
  27. $this->unsetShowTitle();
  28. $this->resourceManager = new ResourceManager();
  29. $this->resourceManager->notVmIds([\ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->id]);
  30. $this->initFields();
  31. }
  32. public function initFields()
  33. {
  34. //ipv4
  35. if (!$this->configuration()->isOrderPublicIp() && $this->configuration()->isPermissionIpv4()) {
  36. $field = new Text('ipv4');
  37. $field->addValidator(
  38. new NumberValidator(
  39. $this->resourceManager->ipv4()->getMin(),
  40. $this->resourceManager->ipv4()->free(),
  41. $this->resourceManager->ipv4()->getMin() > 0
  42. )
  43. );
  44. $field->setDescription('description');
  45. $this->addField($field);
  46. }
  47. //ipv6
  48. if (!$this->configuration()->isOrderPublicIp() && $this->configuration()->isPermissionIpv6()) {
  49. $field = new Text('ipv6');
  50. $field->addValidator(
  51. new NumberValidator(
  52. $this->resourceManager->ipv6()->getMin(),
  53. $this->resourceManager->ipv6()->free(),
  54. $this->resourceManager->ipv6()->getMin() > 0
  55. )
  56. );
  57. $field->setDescription('description');
  58. $this->addField($field);
  59. }
  60. $cpuPrioryty = $this->configuration()->hasCpuPriority();
  61. //name
  62. $field = new Text('name');
  63. $field->addValidator(new HostnameValidator());
  64. $field->setDescription('description');
  65. $this->addField($field);
  66. //description
  67. $field = new Textarea('description');
  68. $field->setDescription('description');
  69. $this->addField($field);
  70. //password
  71. if($this->configuration()->isPermissionPassword()){
  72. $field = new Text('password');
  73. $field->addValidator(new PasswordValidator());
  74. $field->setDescription('description');
  75. if($this->configuration()->isLxc()){
  76. $field->addHtmlAttribute('readonly', "");
  77. $field->addClass('disabled');
  78. }
  79. $this->addField($field);
  80. }
  81. //cores
  82. if($this->configuration()->isPermissionCores()){
  83. $field = new Text('cores');
  84. $field->addValidator(new NumberValidator($this->resourceManager->cores()->getMin(), $this->resourceManager->cores()->free(),true));
  85. $field->setDescription('description');
  86. $this->addField($field);
  87. }
  88. //cpu priority
  89. if($cpuPrioryty){
  90. $field = new Range('cpuPriority', $this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free());
  91. $field->addValidator(new NumberValidator($this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free(),true));
  92. $field->setDescription('description');
  93. $field->addHtmlAttribute('data-label1', sl('lang')->abtr("Very Low"));
  94. $field->addHtmlAttribute('data-label2', sl('lang')->abtr("Low"));
  95. $field->addHtmlAttribute('data-label3', sl('lang')->abtr("Normal"));
  96. $field->addHtmlAttribute('data-label4', sl('lang')->abtr("High"));
  97. $field->addHtmlAttribute('data-label5', sl('lang')->abtr("Medium"));
  98. $this->addField($field);
  99. }
  100. //cpulimit
  101. if($this->configuration()->isPermissionCpuLimit() && !$cpuPrioryty){
  102. $field = new Text('cpulimit');
  103. $field->addValidator(new CpulimitValidator($this->resourceManager->cpulimit()->getMin(), $this->resourceManager->cpulimit()->free(),true));
  104. $field->setDescription('description');
  105. $this->addField($field);
  106. }
  107. //cpuunits
  108. if($this->configuration()->isPermissionCpuunits() && !$cpuPrioryty){
  109. $field = new Text('cpuunits');
  110. $field->addValidator(new NumberValidator($this->resourceManager->cpuunits()->getMin(), $this->resourceManager->cpuunits()->free(),true));
  111. $field->setDescription('description');
  112. $this->addField($field);
  113. }
  114. //memory
  115. $field = new Text('memory');
  116. $field->addValidator(new NumberValidator($this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free(),true));
  117. $field->setDescription('description');
  118. $this->addField($field);
  119. //swap lxc only
  120. if($this->configuration()->isPermissionSwap()){
  121. $field = new Text('swap');
  122. $field->addValidator(new NumberValidator($this->resourceManager->swap()->getMin(), $this->resourceManager->swap()->free(),true));
  123. $field->setDescription('description');
  124. $this->addField($field);
  125. }
  126. if($this->configuration()->isDetailsCombinedView()){
  127. //disk
  128. $field = new Text('disk');
  129. $field->addValidator(new NumberValidator($this->resourceManager->disk()->getMin(), $this->resourceManager->disk()->free(),true));
  130. $field->setDescription('description');
  131. $this->addField($field);
  132. }
  133. //dnsdomain
  134. if($this->configuration()->isPermissionSearchdomain()){
  135. $field = new Text('searchdomain');
  136. $field->addValidator(new HostnameValidator(false));
  137. $field->setDescription('description');
  138. $this->addField($field);
  139. }
  140. if($this->configuration()->isPermissionNameservers()){
  141. //ns1
  142. $field = new Text('nameserver[0]');
  143. $field->addValidator(new IpAddressValidator());
  144. $field->setDescription('description');
  145. $this->addField($field);
  146. //ns2
  147. $field = new Text('nameserver[1]');
  148. $field->addValidator(new IpAddressValidator());
  149. $field->setDescription('description');
  150. $this->addField($field);
  151. }
  152. }
  153. }