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 ModulesGarden\Servers\ProxmoxVps\App\UI\Firewall\Providers; use MGProvision\Proxmox\v2\models\FirewallRule; use ModulesGarden\ProxmoxAddon\App\Services\ApiService; use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService; use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea; use ModulesGarden\Servers\ProxmoxVps\Core\UI\ResponseTemplates\HtmlDataJsonResponse; use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\DataProviders\BaseDataProvider; class FirewallProvider extends BaseDataProvider implements ClientArea { use ProductService; use ApiService; public function read() { if ($this->actionElementId) { $this->data = json_decode(base64_decode($this->actionElementId), true); //enable $enable = $this->data['enable']; $this->data['enable'] = $enable == "1" ? "on" : "off"; } } public function create() { $this->acl()->firewall(); $this->resourceGuard()->firewallLimit(); $firewallRule = new FirewallRule(); $firewallRule->setApi($this->api()); $firewallRule->setPath($this->vm()->getPath() . "/firewall/rules/"); $attributes = $this->formData; $attributes['enable'] = $this->formData['enable'] == "on" ? 1 : 0; if ($attributes['proto'] == "0") { unset($attributes['proto']); } $firewallRule->setAttributes($attributes); $firewallRule->create(); return (new HtmlDataJsonResponse()) ->setStatusSuccess() ->setMessageAndTranslate('The firewall rule has been created successfully') ->addData('createButtonStatus', $this->resourceGuard()->hasfirewallLimit()) ->setCallBackFunction('pmToggleButton'); } public function update() { $this->acl()->firewall(); $firewallRule = new FirewallRule(); $firewallRule->setApi($this->api()); $pos = $this->formData['pos']; unset($this->formData['pos']); $firewallRule->setPath($this->vm()->getPath() . "/firewall/rules/{$pos}"); $attributes = $this->formData; $attributes['enable'] = $this->formData['enable'] == "on" ? 1 : 0; if ($attributes['proto'] == "0") { unset($attributes['proto']); } $firewallRule->setAttributes($attributes); $firewallRule->update(); return (new HtmlDataJsonResponse()) ->setStatusSuccess() ->setMessageAndTranslate('The firewall rule has been updated successfully'); } public function delete() { $this->acl()->firewall(); $firewallRule = new FirewallRule(); $firewallRule->setApi($this->api()); $pos = $this->formData['pos']; $firewallRule->setPath($this->vm()->getPath() . "/firewall/rules/{$pos}"); $firewallRule->delete(); return (new HtmlDataJsonResponse()) ->setStatusSuccess() ->setMessageAndTranslate('The firewall rule has been deleted successfully') ->addData('createButtonStatus', $this->resourceGuard()->hasfirewallLimit()) ->setCallBackFunction('pmToggleButton'); } }