FirewallRule.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS product developed. (2016-12-13)
  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\ProxmoxApiException;
  21. /**
  22. * Description of FirewallRule
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgarden.com>
  25. * @version 1.0.0
  26. */
  27. class FirewallRule extends AbstractObject
  28. {
  29. protected $proto, $enable, $dport, $comment, $action, $iface, $type, $digest, $pos, $sport, $macro, $source, $dest;
  30. protected $path;
  31. public function __construct($proto=null, $enable=null, $dport=null, $comment=null, $action=null, $iface=null, $type=null, $digest=null, $pos=null, $sport=null, $macro=null, $source=null, $dest=null)
  32. {
  33. $this->proto = $proto;
  34. $this->enable = $enable;
  35. $this->dport = $dport;
  36. $this->comment = $comment;
  37. $this->action = $action;
  38. $this->iface = $iface;
  39. $this->type = $type;
  40. $this->digest = $digest;
  41. $this->pos = $pos;
  42. $this->sport = $sport;
  43. $this->macro = $macro;
  44. $this->source = $source;
  45. $this->dest = $dest;
  46. }
  47. public function getProto()
  48. {
  49. return $this->proto;
  50. }
  51. public function getEnable()
  52. {
  53. return $this->enable;
  54. }
  55. public function getDport()
  56. {
  57. return $this->dport;
  58. }
  59. public function getComment()
  60. {
  61. return $this->comment;
  62. }
  63. public function getAction()
  64. {
  65. return $this->action;
  66. }
  67. public function getIface()
  68. {
  69. return $this->iface;
  70. }
  71. public function getType()
  72. {
  73. return $this->type;
  74. }
  75. public function getDigest()
  76. {
  77. return $this->digest;
  78. }
  79. public function getPos()
  80. {
  81. return $this->pos;
  82. }
  83. public function getSport()
  84. {
  85. return $this->sport;
  86. }
  87. public function getMacro()
  88. {
  89. return $this->macro;
  90. }
  91. public function getSource()
  92. {
  93. return $this->source;
  94. }
  95. public function getDest()
  96. {
  97. return $this->dest;
  98. }
  99. public function getPath()
  100. {
  101. return $this->path;
  102. }
  103. public function setProto($proto)
  104. {
  105. $this->proto = $proto;
  106. return $this;
  107. }
  108. public function setEnable($enable)
  109. {
  110. $this->enable = $enable;
  111. return $this;
  112. }
  113. public function setDport($dport)
  114. {
  115. $this->dport = $dport;
  116. return $this;
  117. }
  118. public function setComment($comment)
  119. {
  120. $this->comment = $comment;
  121. return $this;
  122. }
  123. public function setAction($action)
  124. {
  125. $this->action = $action;
  126. return $this;
  127. }
  128. public function setIface($iface)
  129. {
  130. $this->iface = $iface;
  131. return $this;
  132. }
  133. public function setType($type)
  134. {
  135. $this->type = $type;
  136. return $this;
  137. }
  138. public function setDigest($digest)
  139. {
  140. $this->digest = $digest;
  141. return $this;
  142. }
  143. public function setPos($pos)
  144. {
  145. $this->pos = $pos;
  146. return $this;
  147. }
  148. public function setSport($sport)
  149. {
  150. $this->sport = $sport;
  151. return $this;
  152. }
  153. public function setMacro($macro)
  154. {
  155. $this->macro = $macro;
  156. return $this;
  157. }
  158. public function setSource($source)
  159. {
  160. $this->source = $source;
  161. return $this;
  162. }
  163. public function setDest($dest)
  164. {
  165. $this->dest = $dest;
  166. return $this;
  167. }
  168. public function setPath($path)
  169. {
  170. if (!preg_match('/\/rules\//', $path))
  171. {
  172. throw new proxmox\ProxmoxApiException(sprintf("Firewall Rule path('%s') is not valid", $path));
  173. }
  174. $this->path = $path;
  175. return $this;
  176. }
  177. public function delete()
  178. {
  179. if (empty($this->path))
  180. throw new ProxmoxApiException('Firewall Rule [path] - property is missing and it is not optional');
  181. return $this->api()->delete($this->path);
  182. }
  183. private function fill()
  184. {
  185. $fillable = ['proto', 'enable', 'dport', 'comment', 'action', 'iface', 'type', 'pos', 'sport', 'macro', 'source', 'dest'];
  186. $attrinutes = [];
  187. foreach ($fillable as $key) {
  188. if (!is_null($this->{$key})) {
  189. $attrinutes[$key] = $this->{$key};
  190. }
  191. }
  192. return $attrinutes;
  193. }
  194. public function create()
  195. {
  196. if (empty($this->path))
  197. throw new ProxmoxApiException('Firewall Rule [path] - property is missing and it is not optional');
  198. return $this->api()->post($this->path, $this->fill());
  199. }
  200. public function update()
  201. {
  202. if (empty($this->path))
  203. throw new ProxmoxApiException('Firewall Rule [path] - property is missing and it is not optional');
  204. return $this->api()->put($this->path, $this->fill());
  205. }
  206. public function moveto($newPos){
  207. if (empty($this->path))
  208. throw new ProxmoxApiException('Firewall Rule [path] - property is missing and it is not optional');
  209. return $this->api()->put($this->path, ['moveto'=> $newPos]);
  210. }
  211. }