GeneralSection.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. /**
  35. * @deprecated
  36. //ipv4
  37. if($this->configuration()->isPermissionIpv4()){
  38. $field = new Text('ipv4');
  39. $field->addValidator(new NumberValidator($this->resourceManager->ipv4()->getMin(), $this->resourceManager->ipv4()->free(),false));
  40. $field->setDescription('description');
  41. $this->addField($field);
  42. }
  43. //ipv6
  44. if($this->configuration()->isPermissionIpv6()){
  45. $field = new Text('ipv6');
  46. $field->addValidator(new NumberValidator($this->resourceManager->ipv6()->getMin(), $this->resourceManager->ipv6()->free(),false));
  47. $field->setDescription('description');
  48. $this->addField($field);
  49. }
  50. */
  51. $cpuPrioryty = $this->configuration()->hasCpuPriority();
  52. //name
  53. $field = new Text('name');
  54. $field->addValidator(new HostnameValidator());
  55. $field->setDescription('description');
  56. $this->addField($field);
  57. //description
  58. $field = new Textarea('description');
  59. $field->setDescription('description');
  60. $this->addField($field);
  61. //password
  62. if($this->configuration()->isPermissionPassword()){
  63. $field = new Text('password');
  64. $field->addValidator(new PasswordValidator());
  65. $field->setDescription('description');
  66. if($this->configuration()->isLxc()){
  67. $field->addHtmlAttribute('readonly', "");
  68. $field->addClass('disabled');
  69. }
  70. $this->addField($field);
  71. }
  72. //cores
  73. if($this->configuration()->isPermissionCores()){
  74. $field = new Text('cores');
  75. $field->addValidator(new NumberValidator($this->resourceManager->cores()->getMin(), $this->resourceManager->cores()->free(),true));
  76. $field->setDescription('description');
  77. $this->addField($field);
  78. }
  79. //cpu priority
  80. if($cpuPrioryty){
  81. $field = new Range('cpuPriority', $this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free());
  82. $field->addValidator(new NumberValidator($this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free(),true));
  83. $field->setDescription('description');
  84. $field->addHtmlAttribute('data-label1', sl('lang')->abtr("Very Low"));
  85. $field->addHtmlAttribute('data-label2', sl('lang')->abtr("Low"));
  86. $field->addHtmlAttribute('data-label3', sl('lang')->abtr("Normal"));
  87. $field->addHtmlAttribute('data-label4', sl('lang')->abtr("High"));
  88. $field->addHtmlAttribute('data-label5', sl('lang')->abtr("Medium"));
  89. $this->addField($field);
  90. }
  91. //cpulimit
  92. if($this->configuration()->isPermissionCpuLimit() && !$cpuPrioryty){
  93. $field = new Text('cpulimit');
  94. $field->addValidator(new CpulimitValidator($this->resourceManager->cpulimit()->getMin(), $this->resourceManager->cpulimit()->free(),true));
  95. $field->setDescription('description');
  96. $this->addField($field);
  97. }
  98. //cpuunits
  99. if($this->configuration()->isPermissionCpuunits() && !$cpuPrioryty){
  100. $field = new Text('cpuunits');
  101. $field->addValidator(new NumberValidator($this->resourceManager->cpuunits()->getMin(), $this->resourceManager->cpuunits()->free(),true));
  102. $field->setDescription('description');
  103. $this->addField($field);
  104. }
  105. //memory
  106. $field = new Text('memory');
  107. $field->addValidator(new NumberValidator($this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free(),true));
  108. $field->setDescription('description');
  109. $this->addField($field);
  110. //swap lxc only
  111. if($this->configuration()->isPermissionSwap()){
  112. $field = new Text('swap');
  113. $field->addValidator(new NumberValidator($this->resourceManager->swap()->getMin(), $this->resourceManager->swap()->free(),true));
  114. $field->setDescription('description');
  115. $this->addField($field);
  116. }
  117. if($this->configuration()->isDetailsCombinedView()){
  118. //disk
  119. $field = new Text('disk');
  120. $field->addValidator(new NumberValidator($this->resourceManager->disk()->getMin(), $this->resourceManager->disk()->free(),true));
  121. $field->setDescription('description');
  122. $this->addField($field);
  123. }
  124. //dnsdomain
  125. if($this->configuration()->isPermissionSearchdomain()){
  126. $field = new Text('searchdomain');
  127. $field->addValidator(new HostnameValidator(false));
  128. $field->setDescription('description');
  129. $this->addField($field);
  130. }
  131. if($this->configuration()->isPermissionNameservers()){
  132. //ns1
  133. $field = new Text('nameserver[0]');
  134. $field->addValidator(new IpAddressValidator());
  135. $field->setDescription('description');
  136. $this->addField($field);
  137. //ns2
  138. $field = new Text('nameserver[1]');
  139. $field->addValidator(new IpAddressValidator());
  140. $field->setDescription('description');
  141. $this->addField($field);
  142. }
  143. }
  144. }