1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22class CControllerProxyHostEnable extends CController { 23 24 protected function checkInput() { 25 $fields = [ 26 'proxyids' => 'required|array_db hosts.hostid' 27 ]; 28 29 $ret = $this->validateInput($fields); 30 31 if (!$ret) { 32 $this->setResponse(new CControllerResponseFatal()); 33 } 34 35 return $ret; 36 } 37 38 protected function checkPermissions() { 39 if (!$this->checkAccess(CRoleHelper::UI_ADMINISTRATION_PROXIES)) { 40 return false; 41 } 42 43 $proxies = API::Proxy()->get([ 44 'proxyids' => $this->getInput('proxyids'), 45 'countOutput' => true, 46 'editable' => true 47 ]); 48 49 return ($proxies == count($this->getInput('proxyids'))); 50 } 51 52 protected function doAction() { 53 $hosts = API::Host()->get([ 54 'output' => ['hostid'], 55 'filter' => [ 56 'proxy_hostid' => $this->getInput('proxyids'), 57 'status' => HOST_STATUS_NOT_MONITORED 58 ] 59 ]); 60 61 foreach ($hosts as &$host) { 62 $host['status'] = HOST_STATUS_MONITORED; 63 } 64 unset($host); 65 66 $result = $hosts ? (bool) API::Host()->update($hosts) : true; 67 68 $updated = count($hosts); 69 70 $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) 71 ->setArgument('action', 'proxy.list') 72 ->setArgument('page', CPagerHelper::loadPage('proxy.list', null)) 73 ); 74 75 if ($result) { 76 $response->setFormData(['uncheck' => '1']); 77 CMessageHelper::setSuccessTitle(_n('Host enabled', 'Hosts enabled', $updated)); 78 } 79 else { 80 CMessageHelper::setErrorTitle(_n('Cannot enable host', 'Cannot enable hosts', $updated)); 81 } 82 $this->setResponse($response); 83 } 84} 85