<?php
/*
 * @package 	RSFirewall!
 * @copyright 	(c) 2009 - 2024 RSJoomla!
 * @link 		https://www.rsjoomla.com/joomla-extensions/joomla-security.html
 * @license 	GNU General Public License https://www.gnu.org/licenses/gpl-3.0.en.html
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;

class RSFirewallProtectionJce extends RSFirewallProtection
{
	protected $reason = 'COM_RSFIREWALL_UNAUTHORIZED_REQUEST_DETECTED';
	protected $code = 'JCE_INJECTION_ATTEMPT';

	public function isInjection()
	{
		if ($this->getOption() === 'com_jce' && isset($_REQUEST['task']))
		{
			$user = Factory::getUser();
			$task = strtolower($_REQUEST['task']);

			if (in_array($task, array('profiles.repair', 'profiles.copy', 'profiles.import', 'profiles.export')))
			{
				if (!$user->authorise('jce.profiles', 'com_jce'))
				{
					return true;
				}
			}

			if (in_array($task, array('profile.add', 'profile.edit', 'profile.reload', 'profile.apply', 'profile.save', 'profile.save2menu', 'profile.save2new', 'profile.save2copy', 'profile.editassociations')))
			{
				if (!$user->authorise('jce.profiles', 'com_jce'))
				{
					return true;
				}
			}

			if (in_array($task, array('config.add', 'config.edit', 'config.reload', 'config.apply', 'config.save', 'config.save2menu', 'config.save2new', 'config.save2copy', 'config.editassociations')))
			{
				if (!$user->authorise('jce.config', 'com_jce'))
				{
					return true;
				}
			}

			if (in_array($task, array('mediabox.add', 'mediabox.edit', 'mediabox.reload', 'mediabox.apply', 'mediabox.save', 'mediabox.save2menu', 'mediabox.save2new', 'mediabox.save2copy', 'mediabox.editassociations')))
			{
				if (!$user->authorise('jce.mediabox', 'com_jce'))
				{
					return true;
				}
			}

			if (strpos($task, 'editor.') === 0 && !in_array($task, array('editor.loadlanguages', 'editor.pack', 'editor.compileless')))
			{
				return true;
			}

			if ($task === 'cpanel.feed')
			{
				if (!$user->authorise('core.manage', 'com_jce'))
				{
					return true;
				}
			}
		}

		return false;
	}
}