FirewallOptions.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS product developed. (2017-01-11)
  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 MGProvision\Proxmox\v2\models;
  20. use MGProvision\Proxmox\v2 as proxmox;
  21. /**
  22. * Description of FirewallOptions
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgarden.com>
  25. * @version 1.0.0
  26. */
  27. class FirewallOptions extends AbstractObject
  28. {
  29. protected $path;
  30. protected $enable;
  31. protected $ipfilter;
  32. protected $policy_in;
  33. protected $policy_out;
  34. protected $log_level_in;
  35. protected $log_level_out;
  36. protected $dhcp;
  37. protected $ndp;
  38. protected $macfilter;
  39. protected $radv;
  40. public function setPath($path)
  41. {
  42. if (!preg_match('/[0-9]\/firewall\/options$/', $path))
  43. {
  44. throw new proxmox\ProxmoxApiException(sprintf("Firewall Path ('%s') is not valid", $path));
  45. }
  46. $this->path = $path;
  47. return $this;
  48. }
  49. public function read()
  50. {
  51. if (empty($this->path))
  52. throw new proxmox\ProxmoxApiException('Path can\'t be blank');
  53. $attributes = $this->api()->get($this->path);
  54. if(!isset($attributes['dhcp'])){
  55. $attributes['dhcp'] = 1;
  56. }
  57. $this->setAttributes($attributes);
  58. return $this;
  59. }
  60. public function update()
  61. {
  62. if (empty($this->path))
  63. throw new proxmox\ProxmoxApiException('Path can\'t be blank');
  64. $attributes = array();
  65. if ($this->enable !== null)
  66. {
  67. $attributes['enable'] = $this->getEnable();
  68. }
  69. if ($this->dhcp !== null)
  70. {
  71. $attributes['dhcp'] = $this->getDhcp();
  72. }
  73. if ($this->ndp !== null)
  74. {
  75. $attributes['ndp'] = $this->getNdp();
  76. }
  77. if ($this->radv !== null)
  78. {
  79. $attributes['radv'] = $this->getRadv();
  80. }
  81. if ($this->macfilter !== null)
  82. {
  83. $attributes['macfilter'] = $this->getMacfilter();
  84. }
  85. if ($this->ipfilter !== null)
  86. {
  87. $attributes['ipfilter'] = $this->getIpfilter();
  88. }
  89. if ($this->log_level_in !== null)
  90. {
  91. $attributes['log_level_in'] = $this->getLog_level_in();
  92. }
  93. if ($this->log_level_out !== null)
  94. {
  95. $attributes['log_level_out'] = $this->getLog_level_out();
  96. }
  97. if ($this->policy_in !== null)
  98. {
  99. $attributes['policy_in'] = $this->getPolicy_in();
  100. }
  101. if ($this->policy_out !== null)
  102. {
  103. $attributes['policy_out'] = $this->getPolicy_out();
  104. }
  105. return $this->api()->put($this->path, $attributes);
  106. }
  107. public function getEnable()
  108. {
  109. return $this->enable;
  110. }
  111. public function getIpfilter()
  112. {
  113. return $this->ipfilter;
  114. }
  115. public function getPolicy_in()
  116. {
  117. return $this->policy_in;
  118. }
  119. public function getPolicy_out()
  120. {
  121. return $this->policy_out;
  122. }
  123. public function getLog_level_in()
  124. {
  125. return $this->log_level_in;
  126. }
  127. public function getLog_level_out()
  128. {
  129. return $this->log_level_out;
  130. }
  131. public function getDhcp()
  132. {
  133. return $this->dhcp;
  134. }
  135. public function getNdp()
  136. {
  137. return $this->ndp;
  138. }
  139. public function getMacfilter()
  140. {
  141. return $this->macfilter;
  142. }
  143. public function getRadv()
  144. {
  145. return $this->radv;
  146. }
  147. public function setEnable($enable)
  148. {
  149. $this->enable = $enable;
  150. return $this;
  151. }
  152. public function setIpfilter($ipfilter)
  153. {
  154. $this->ipfilter = $ipfilter;
  155. return $this;
  156. }
  157. public function setPolicy_in($policy_in)
  158. {
  159. $this->policy_in = $policy_in;
  160. return $this;
  161. }
  162. public function setPolicy_out($policy_out)
  163. {
  164. $this->policy_out = $policy_out;
  165. return $this;
  166. }
  167. public function setLog_level_in($log_level_in)
  168. {
  169. $this->log_level_in = $log_level_in;
  170. return $this;
  171. }
  172. public function setLog_level_out($log_level_out)
  173. {
  174. $this->log_level_out = $log_level_out;
  175. return $this;
  176. }
  177. public function setDhcp($dhcp)
  178. {
  179. $this->dhcp = $dhcp;
  180. return $this;
  181. }
  182. public function setNdp($ndp)
  183. {
  184. $this->ndp = $ndp;
  185. return $this;
  186. }
  187. public function setMacfilter($macfilter)
  188. {
  189. $this->macfilter = $macfilter;
  190. return $this;
  191. }
  192. public function setRadv($radv)
  193. {
  194. $this->radv = $radv;
  195. return $this;
  196. }
  197. public function getAttributes()
  198. {
  199. return [
  200. 'enable' => $this->getEnable() ? $this->getEnable() : 0 ,
  201. 'dhcp' => $this->getDhcp() ? $this->getDhcp() : 0,
  202. 'ndp' => is_null($this->ndp) || $this->ndp ? 1 :0,
  203. 'radv' => $this->getRadv() ? $this->getRadv() : 0,
  204. 'macfilter' => is_null($this->macfilter) || $this->macfilter ? 1 :0,
  205. 'ipfilter' => $this->getIpfilter() ? $this->getIpfilter() : 0,
  206. 'log_level_in' => $this->getLog_level_in() ? $this->getLog_level_in() : "nolog",
  207. 'log_level_out' => $this->getLog_level_out() ? $this->getLog_level_out() : "nolog",
  208. 'policy_in' => $this->getPolicy_in() ? $this->getPolicy_in() : "DROP",
  209. 'policy_out' => $this->getPolicy_out() ? $this->getPolicy_out() : "ACCEPT",
  210. ];
  211. }
  212. }