FirewallOptionProvider.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (27.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\Providers;
  20. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  21. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  22. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
  23. use ModulesGarden\Servers\ProxmoxVps\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  24. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  25. class FirewallOptionProvider extends BaseDataProvider implements ClientArea
  26. {
  27. use ApiService;
  28. use ProductService;
  29. public function read()
  30. {
  31. $this->data = $this->vm()->firewallOptions()->read()->getAttributes();
  32. $this->data["enable"] = str_replace(["1", "0"], ["on", "off"], $this->data["enable"]);
  33. $this->data["dhcp"] = str_replace(["1", "0"], ["on", "off"], $this->data["dhcp"]);
  34. $this->data["ndp"] = str_replace(["1", "0"], ["on", "off"], $this->data["ndp"]);
  35. $this->data["radv"] = str_replace(["1", "0"], ["on", "off"], $this->data["radv"]);
  36. $this->data["macfilter"] = str_replace(["1", "0"], ["on", "off"], $this->data["macfilter"]);
  37. $this->data["ipfilter"] = str_replace(["1", "0"], ["on", "off"], $this->data["ipfilter"]);
  38. }
  39. public function update()
  40. {
  41. $attributes = $this->formData;
  42. $attributes["enable"] = str_replace(["on", "off"], ["1", "0"], $attributes["enable"]);
  43. if(!$this->acl()->hasFirewallOption("enable")){
  44. unset($attributes["enable"] );
  45. }
  46. $attributes["dhcp"] = str_replace(["on", "off"], ["1", "0"], $attributes["dhcp"]);
  47. if(!$this->acl()->hasFirewallOption("dhcp")){
  48. unset($attributes["dhcp"] );
  49. }
  50. $attributes["ndp"] = str_replace(["on", "off"], ["1", "0"], $attributes["ndp"]);
  51. if(!$this->acl()->hasFirewallOption("ndp")){
  52. unset($attributes["ndp"] );
  53. }
  54. $attributes["radv"] = str_replace(["on", "off"], ["1", "0"], $attributes["radv"]);
  55. if(!$this->acl()->hasFirewallOption("radv")){
  56. unset($attributes["radv"] );
  57. }
  58. $attributes["macfilter"] = str_replace(["on", "off"], ["1", "0"], $attributes["macfilter"]);
  59. if(!$this->acl()->hasFirewallOption("macfilter")){
  60. unset($attributes["macfilter"] );
  61. }
  62. $attributes["ipfilter"] = str_replace(["on", "off"], ["1", "0"], $attributes["ipfilter"]);
  63. if(!$this->acl()->hasFirewallOption("ipfilter")){
  64. unset($attributes["ipfilter"] );
  65. }
  66. $this->vm()->firewallOptions()->setAttributes($attributes)->update();
  67. return (new HtmlDataJsonResponse())
  68. ->setStatusSuccess()
  69. ->setMessageAndTranslate('The firewall options has been updated successfully')
  70. ->setRefreshTargetIds(["firewallOption"]);
  71. }
  72. }