FirewallOption.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product 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\FirewallOption\Pages;
  20. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  21. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  22. use ModulesGarden\Servers\ProxmoxVps\App\UI\FirewallOption\Buttons\UpdateButton;
  23. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Builder\BaseContainer;
  24. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AjaxElementInterface;
  25. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
  26. use ModulesGarden\Servers\ProxmoxVps\Core\UI\ResponseTemplates\RawDataJsonResponse;
  27. use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
  28. /**
  29. * Class FirewallOption
  30. * @package ModulesGarden\Servers\ProxmoxVps\App\UI\FirewallOption\Pages
  31. * @todo - move html code to new class - new Label(some text, Label::DANGER)
  32. */
  33. class FirewallOption extends BaseContainer implements ClientArea, AjaxElementInterface
  34. {
  35. use ApiService;
  36. use ProductService;
  37. protected $id = 'firewallOption';
  38. protected $title = 'firewallOption';
  39. protected $vueComponent = true;
  40. protected $defaultVueComponentName = 'mg-firewallOption';
  41. public function initContent()
  42. {
  43. $this->addButton(new UpdateButton());
  44. }
  45. public function returnAjaxData()
  46. {
  47. $vars = ['enteries' => []];
  48. $lang = sl("lang");
  49. $allowed = ['log_level_in', 'log_level_out', 'policy_in', 'policy_out'];
  50. foreach ($this->vm()->firewallOptions()->read()->toArray() as $key => $value)
  51. {
  52. if(!in_array($key, $allowed) && !$this->acl()->hasFirewallOption($key)){
  53. continue;
  54. }
  55. if (is_numeric($value) && $value == 1)
  56. {
  57. $vars['enteries'][$lang->tr($key)] = '<span class="lu-label lu-label--success lu-label--status">' . sl('lang')->tr($value) . '</span>';
  58. }
  59. else
  60. {
  61. if (is_numeric($value) && $value == 0)
  62. {
  63. $vars['enteries'][$lang->tr($key)] = '<span class="lu-label lu-label--danger lu-label--status">' . sl('lang')->tr($value) . '</span>';
  64. }
  65. else
  66. {
  67. $vars['enteries'][$lang->tr($key)] = $lang->tr($value);
  68. }
  69. }
  70. }
  71. return (new RawDataJsonResponse(['data' => $vars]));
  72. }
  73. }