FirewallOptionProvider.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\ProxmoxCloudVps\App\UI\FirewallOption\Providers;
  20. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  21. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\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. $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
  32. $this->data = $vm->firewallOptions()->read()->getAttributes();
  33. $this->data["enable"] = str_replace(["1", "0"], ["on", "off"], $this->data["enable"]);
  34. $this->data["dhcp"] = str_replace(["1", "0"], ["on", "off"], $this->data["dhcp"]);
  35. $this->data["ndp"] = str_replace(["1", "0"], ["on", "off"], $this->data["ndp"]);
  36. $this->data["radv"] = str_replace(["1", "0"], ["on", "off"], $this->data["radv"]);
  37. $this->data["macfilter"] = str_replace(["1", "0"], ["on", "off"], $this->data["macfilter"]);
  38. $this->data["ipfilter"] = str_replace(["1", "0"], ["on", "off"], $this->data["ipfilter"]);
  39. }
  40. public function update()
  41. {
  42. $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
  43. $attributes = $this->formData;
  44. $attributes["enable"] = str_replace(["on", "off"], ["1", "0"], $attributes["enable"]);
  45. if(!$this->acl()->hasFirewallOption("enable")){
  46. unset($attributes["enable"] );
  47. }
  48. $attributes["dhcp"] = str_replace(["on", "off"], ["1", "0"], $attributes["dhcp"]);
  49. if(!$this->acl()->hasFirewallOption("dhcp")){
  50. unset($attributes["dhcp"] );
  51. }
  52. $attributes["ndp"] = str_replace(["on", "off"], ["1", "0"], $attributes["ndp"]);
  53. if(!$this->acl()->hasFirewallOption("ndp")){
  54. unset($attributes["ndp"] );
  55. }
  56. $attributes["radv"] = str_replace(["on", "off"], ["1", "0"], $attributes["radv"]);
  57. if(!$this->acl()->hasFirewallOption("radv")){
  58. unset($attributes["radv"] );
  59. }
  60. $attributes["macfilter"] = str_replace(["on", "off"], ["1", "0"], $attributes["macfilter"]);
  61. if(!$this->acl()->hasFirewallOption("macfilter")){
  62. unset($attributes["macfilter"] );
  63. }
  64. $attributes["ipfilter"] = str_replace(["on", "off"], ["1", "0"], $attributes["ipfilter"]);
  65. if(!$this->acl()->hasFirewallOption("ipfilter")){
  66. unset($attributes["ipfilter"] );
  67. }
  68. $vm->firewallOptions()->setAttributes($attributes)->update();
  69. return (new HtmlDataJsonResponse())
  70. ->setStatusSuccess()
  71. ->setMessageAndTranslate('The firewall options has been updated successfully')
  72. ->setRefreshTargetIds(["firewallOption"]);
  73. }
  74. }