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 * @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()); } }