SettingsContainer.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /* * ********************************************************************
  3. * Wordpress_Manager Product developed. (Dec 7, 2017)
  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\ProxmoxAddon\App\UI\Settings\Pages;
  20. use ModulesGarden\ProxmoxAddon as main;
  21. use ModulesGarden\ProxmoxAddon\App\UI\Settings\Providers\SettingProvider;
  22. use ModulesGarden\ProxmoxAddon\App\UI\Settings\Sections\CronSection;
  23. use ModulesGarden\ProxmoxAddon\App\UI\Settings\Sections\GeneralSection;
  24. use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea;
  25. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\BaseStandaloneFormExtSections;
  26. /**
  27. * SettingsContainer
  28. */
  29. class SettingsContainer extends BaseStandaloneFormExtSections implements AdminArea
  30. {
  31. protected $id = 'settings';
  32. protected $name = 'settings';
  33. protected $title = null;
  34. public function initContent()
  35. {
  36. //SettingProvider
  37. $this->setProvider(new SettingProvider());
  38. //alert
  39. $this->licenseAlert();
  40. //Crons
  41. $this->addSection(new CronSection('cron'));
  42. //General
  43. $general = new GeneralSection('general');
  44. //LoadBalancer
  45. $loadBalancer = new main\App\UI\Settings\Sections\LoadBalancerSection('loadBalancer');
  46. //Minimum VMID
  47. $field = new main\Core\UI\Widget\Forms\Fields\Text('proxmoxVPSMinimumVMID');
  48. $field->addValidator(new main\App\UI\Validators\NumberValidator(1, 100000000 * 100000000 * 100000000));
  49. $field->setLabelWidth(12);
  50. $field->setDefaultValue(100);
  51. $general->addField($field);
  52. //debug
  53. $field = new main\Core\UI\Widget\Forms\Fields\Switcher('debug');
  54. $field->setDescription('description');
  55. $general->addField($field);
  56. //Count VMs
  57. $field = new main\Core\UI\Widget\Forms\Fields\Text('vmsWeight');
  58. $field->addValidator(new main\App\UI\Validators\NumberValidator(1, null));
  59. $field->setLabelWidth(12);
  60. $field->setDescription('description');
  61. $field->setDefaultValue(1000);
  62. $loadBalancer->addField($field);
  63. //Weight CPU
  64. $field = new main\Core\UI\Widget\Forms\Fields\Text('cpuWeight');
  65. $field->addValidator(new main\App\UI\Validators\NumberValidator(1, null));
  66. $field->setLabelWidth(12);
  67. $field->setDescription('description');
  68. $field->setDefaultValue(1);
  69. $loadBalancer->addField($field);
  70. //Weight Disk
  71. $field = new main\Core\UI\Widget\Forms\Fields\Text('diskWeight');
  72. $field->addValidator(new main\App\UI\Validators\NumberValidator(1, null));
  73. $field->setLabelWidth(12);
  74. $field->setDescription('description');
  75. $field->setDefaultValue(1);
  76. $loadBalancer->addField($field);
  77. //Weight RAM
  78. $field = new main\Core\UI\Widget\Forms\Fields\Text('ramWeight');
  79. $field->addValidator(new main\App\UI\Validators\NumberValidator(1, null));
  80. $field->setLabelWidth(12);
  81. $field->setDescription('description');
  82. $field->setDefaultValue(1);
  83. $loadBalancer->addField($field);
  84. //Section
  85. $this->addSection($general);
  86. $this->addSection($loadBalancer);
  87. //console
  88. $consoleSection = new main\App\UI\Settings\Sections\ConsoleSection();
  89. $consoleSection->setMainContainer($this->mainContainer);
  90. $this->addSection($consoleSection);
  91. //adminArea
  92. $adminAreaSection = new main\App\UI\Settings\Sections\AdminAreaSection();
  93. $adminAreaSection->setMainContainer($this->mainContainer);
  94. $this->addSection($adminAreaSection);
  95. $this->loadDataToForm();
  96. }
  97. public function licenseAlert(){
  98. $vps = $this->isLicensePayingFullAnnuallyPrice('proxmoxVPS');
  99. $cloud = $this->isLicensePayingFullAnnuallyPrice('ProxmoxCloudVps');
  100. if((is_bool($vps) && !$vps) || (is_bool($cloud) && !$cloud) ){
  101. $this->addSection(new main\App\UI\Settings\Sections\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."));
  102. }
  103. }
  104. private function isLicensePayingFullAnnuallyPrice($module='proxmoxVPS'){
  105. $file = \ModulesGarden\ProxmoxAddon\Core\ModuleConstants::getFullPathWhmcs('modules', 'servers',$module) . DIRECTORY_SEPARATOR .$module. '.php';
  106. if(!file_exists($file))
  107. {
  108. return;
  109. }
  110. require_once $file;
  111. $moduleFunction = $module."_GetLicenseData";
  112. if(!function_exists($moduleFunction)){
  113. return true;
  114. }
  115. $licenseData = $moduleFunction(true);
  116. if(is_array($licenseData) && isset($licenseData['isPayingFullAnnuallyPrice']) && $licenseData['isPayingFullAnnuallyPrice'] !="1"){
  117. return false;
  118. }
  119. return true;
  120. }
  121. }