File Manager

Current Directory: /home/astoriaah/www/administrator/components/com_admintools/Controller
Viewing File: /home/astoriaah/www/administrator/components/com_admintools/Controller/SecurityExceptions.php
<?php /** * @package admintools * @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\AdminTools\Admin\Controller; defined('_JEXEC') || die; use Akeeba\AdminTools\Admin\Controller\Mixin\CustomACL; use Akeeba\AdminTools\Admin\Model\BlacklistedAddresses; use Exception; use FOF40\Controller\DataController; use FOF40\Controller\Exception\TaskNotFound; use Joomla\CMS\Language\Text; class SecurityExceptions extends DataController { use CustomACL; public function execute(string $task) { if ($task == 'default') { $task = $this->getCrudTask(); } $this->task = $task; if (!isset($this->taskMap[$task]) && !isset($this->taskMap['__default'])) { throw new TaskNotFound(Text::sprintf('JLIB_APPLICATION_ERROR_TASK_NOT_FOUND', $task), 404); } $result = $this->triggerEvent('onBeforeExecute', [&$task]); if ($result === false) { return false; } $eventName = 'onBefore' . ucfirst($task); $result = $this->triggerEvent($eventName); if ($result === false) { return false; } // Do not allow the display task to be directly called if (isset($this->taskMap[$task])) { $doTask = $this->taskMap[$task]; } elseif (isset($this->taskMap['__default'])) { $doTask = $this->taskMap['__default']; } else { $doTask = null; } // Record the actual task being fired $this->doTask = $doTask; $ret = $this->$doTask(); $eventName = 'onAfter' . ucfirst($task); $result = $this->triggerEvent($eventName); if ($result === false) { return false; } $result = $this->triggerEvent('onAfterExecute', [$task]); if ($result === false) { return false; } return $ret; } public function ban() { $this->csrfProtection(); $id = $this->input->getString('id', ''); if (empty($id)) { throw new Exception(Text::_('COM_ADMINTOOLS_ERR_SECURITYEXCEPTION_BAN_NOID'), 500); } /** @var \Akeeba\AdminTools\Admin\Model\SecurityExceptions $model */ $model = $this->getModel(); /** @var \Akeeba\AdminTools\Admin\Model\SecurityExceptions item */ $item = $model->find($id); /** @var BlacklistedAddresses $banModel */ $banModel = $this->container->factory->model('BlacklistedAddresses')->tmpInstance(); $data = [ 'id' => 0, 'ip' => $item->ip, 'description' => Text::_('COM_ADMINTOOLS_LBL_SECURITYEXCEPTION_REASON_' . strtoupper($item->reason)), ]; $banModel->save($data); $this->setRedirect('index.php?option=com_admintools&view=SecurityExceptions', Text::_('COM_ADMINTOOLS_LBL_BLACKLISTEDADDRESS_SAVED')); } public function unban() { $this->csrfProtection(); $id = $this->input->getString('id', ''); if (empty($id)) { throw new Exception(Text::_('COM_ADMINTOOLS_ERR_SECURITYEXCEPTION_BAN_NOID'), 500); } /** @var \Akeeba\AdminTools\Admin\Model\SecurityExceptions $model */ $model = $this->getModel(); /** @var \Akeeba\AdminTools\Admin\Model\SecurityExceptions item */ $item = $model->find($id); /** @var BlacklistedAddresses $banModel */ $banModel = $this->container->factory->model('BlacklistedAddresses')->tmpInstance(); $banModel->ip($item->ip); $items = $banModel->get(); foreach ($items as $banItem) { $banModel->delete($banItem->id); } $this->setRedirect('index.php?option=com_admintools&view=SecurityExceptions', Text::_('COM_ADMINTOOLS_LBL_BLACKLISTEDADDRESS_DELETED')); } }