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\Network\Providers; use ModulesGarden\ProxmoxAddon\App\Services\ApiService; use ModulesGarden\ProxmoxAddon\App\Services\Vps\IpSetIpFilterService; use ModulesGarden\ProxmoxAddon\App\Services\Vps\NetworkService; 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 NetworkProvider extends BaseDataProvider implements ClientArea { use ProductService; use ApiService; /** * @var NetworkService */ private $networkService; public function read() { if ($this->actionElementId) { $this->data['id'] = $this->actionElementId; } $this->data['bridge'] = $this->configuration()->getPrivateBridge(); } public function create() { if ($this->vm()->getNetworkDevices($this->configuration()->getPrivateBridge())) { return (new HtmlDataJsonResponse()) ->setStatusError() ->setMessageAndTranslate('Private network limit exceeded'); } $this->networkService = new NetworkService(); if (!$this->networkService->hasPrivateIpAddress()) { throw new \Exception("Private IP Addresses are not available."); } if ($this->configuration()->isLxc()) { $this->lxc(); } else { if ($this->configuration()->isQemu()) { $this->qemu(); } } if($this->configuration()->isIpsetIpFilter()){ $ipSetIpFilterService = new IpSetIpFilterService(); $ipSetIpFilterService->create(); } return (new HtmlDataJsonResponse()) ->setStatusSuccess() ->setMessageAndTranslate('The Network Device has been created successfully') ->addData('createButtonStatus', false) ->setCallBackFunction('pmToggleButton'); } private function lxc() { //Get Private IP Addresses $ip = $this->networkService->getPrivateIpAddress(); //Create network device $this->networkService->addPrivate([$ip]); } private function qemu() { //Get Private IP Addresses $ip = $this->networkService->getPrivateIpAddress(); //Create network device $this->networkService->addPrivate([$ip]); } public function update() { } public function delete() { if (!$this->vm()->getNetworkDevices($this->configuration()->getPrivateBridge())) { return (new HtmlDataJsonResponse()) ->setStatusError() ->setMessageAndTranslate('Private network device not found'); } $this->networkService = new NetworkService(); $this->networkService->deleteByNetworkId([$this->formData['id']]); if($this->configuration()->isIpsetIpFilter()){ $ipSetIpFilterService = new IpSetIpFilterService(); $ipSetIpFilterService->create(); } return (new HtmlDataJsonResponse()) ->setStatusSuccess() ->setMessageAndTranslate('The Network Device has been deleted successfully') ->addData('createButtonStatus', true) ->setCallBackFunction('pmToggleButton'); } }