| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-12-13)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace MGProvision\Proxmox\v2\models;
- use MGProvision\Proxmox\v2\ProxmoxApiException;
- /**
- * Description of FirewallRule
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @version 1.0.0
- */
- class FirewallRule extends AbstractObject
- {
- protected $proto, $enable, $dport, $comment, $action, $iface, $type, $digest, $pos, $sport, $macro, $source, $dest;
- protected $path;
- 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)
- {
- $this->proto = $proto;
- $this->enable = $enable;
- $this->dport = $dport;
- $this->comment = $comment;
- $this->action = $action;
- $this->iface = $iface;
- $this->type = $type;
- $this->digest = $digest;
- $this->pos = $pos;
- $this->sport = $sport;
- $this->macro = $macro;
- $this->source = $source;
- $this->dest = $dest;
- }
- public function getProto()
- {
- return $this->proto;
- }
- public function getEnable()
- {
- return $this->enable;
- }
- public function getDport()
- {
- return $this->dport;
- }
- public function getComment()
- {
- return $this->comment;
- }
- public function getAction()
- {
- return $this->action;
- }
- public function getIface()
- {
- return $this->iface;
- }
- public function getType()
- {
- return $this->type;
- }
- public function getDigest()
- {
- return $this->digest;
- }
- public function getPos()
- {
- return $this->pos;
- }
- public function getSport()
- {
- return $this->sport;
- }
- public function getMacro()
- {
- return $this->macro;
- }
- public function getSource()
- {
- return $this->source;
- }
- public function getDest()
- {
- return $this->dest;
- }
- public function getPath()
- {
- return $this->path;
- }
- public function setProto($proto)
- {
- $this->proto = $proto;
- return $this;
- }
- public function setEnable($enable)
- {
- $this->enable = $enable;
- return $this;
- }
- public function setDport($dport)
- {
- $this->dport = $dport;
- return $this;
- }
- public function setComment($comment)
- {
- $this->comment = $comment;
- return $this;
- }
- public function setAction($action)
- {
- $this->action = $action;
- return $this;
- }
- public function setIface($iface)
- {
- $this->iface = $iface;
- return $this;
- }
- public function setType($type)
- {
- $this->type = $type;
- return $this;
- }
- public function setDigest($digest)
- {
- $this->digest = $digest;
- return $this;
- }
- public function setPos($pos)
- {
- $this->pos = $pos;
- return $this;
- }
- public function setSport($sport)
- {
- $this->sport = $sport;
- return $this;
- }
- public function setMacro($macro)
- {
- $this->macro = $macro;
- return $this;
- }
- public function setSource($source)
- {
- $this->source = $source;
- return $this;
- }
- public function setDest($dest)
- {
- $this->dest = $dest;
- return $this;
- }
- public function setPath($path)
- {
- if (!preg_match('/\/rules\//', $path))
- {
- throw new proxmox\ProxmoxApiException(sprintf("Firewall Rule path('%s') is not valid", $path));
- }
- $this->path = $path;
- return $this;
- }
- public function delete()
- {
- if (empty($this->path))
- throw new ProxmoxApiException('Firewall Rule [path] - property is missing and it is not optional');
- return $this->api()->delete($this->path);
- }
- private function fill()
- {
- $fillable = ['proto', 'enable', 'dport', 'comment', 'action', 'iface', 'type', 'pos', 'sport', 'macro', 'source', 'dest'];
- $attrinutes = [];
- foreach ($fillable as $key) {
- if (!is_null($this->{$key})) {
- $attrinutes[$key] = $this->{$key};
- }
- }
- return $attrinutes;
- }
- public function create()
- {
- if (empty($this->path))
- throw new ProxmoxApiException('Firewall Rule [path] - property is missing and it is not optional');
- return $this->api()->post($this->path, $this->fill());
- }
- public function update()
- {
- if (empty($this->path))
- throw new ProxmoxApiException('Firewall Rule [path] - property is missing and it is not optional');
- return $this->api()->put($this->path, $this->fill());
- }
- }
|