2012-08-04 18:48:04 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2019-03-09 19:44:14 +00:00
|
|
|
* @package Joomla.JEDChecker
|
|
|
|
*
|
2019-03-10 16:09:42 +00:00
|
|
|
* @copyright Copyright (C) 2017 - 2019 Open Source Matters, Inc. All rights reserved.
|
|
|
|
* Copyright (C) 2008 - 2016 compojoom.com . All rights reserved.
|
2019-03-10 08:49:52 +00:00
|
|
|
* @author Daniel Dimitrov <daniel@compojoom.com>
|
|
|
|
* 02.06.12
|
|
|
|
*
|
2019-03-09 19:44:14 +00:00
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
2012-08-04 18:48:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
|
|
|
// Include the rule base class
|
2013-11-05 20:17:39 +00:00
|
|
|
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php';
|
2012-08-04 18:48:04 +00:00
|
|
|
|
2021-05-10 17:20:20 +00:00
|
|
|
// Include the helper class
|
|
|
|
require_once JPATH_COMPONENT_ADMINISTRATOR . '/libraries/helper.php';
|
|
|
|
|
2012-08-04 18:48:04 +00:00
|
|
|
/**
|
2013-11-05 20:17:39 +00:00
|
|
|
* class JedcheckerRulesEncoding
|
2012-08-04 18:48:04 +00:00
|
|
|
*
|
2013-11-05 20:17:39 +00:00
|
|
|
* This class checks if base64 encoding is used in the files
|
|
|
|
*
|
|
|
|
* @since 1.0
|
2012-08-04 18:48:04 +00:00
|
|
|
*/
|
2013-11-05 20:17:39 +00:00
|
|
|
class JedcheckerRulesEncoding extends JEDcheckerRule
|
2012-08-04 18:48:04 +00:00
|
|
|
{
|
2013-11-05 20:17:39 +00:00
|
|
|
/**
|
|
|
|
* The formal ID of this rule. For example: SE1.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $id = 'encoding';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The title or caption of this rule.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $title = 'COM_JEDCHECKER_RULE_ENCODING';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The description of this rule.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'COM_JEDCHECKER_RULE_ENCODING_DESC';
|
|
|
|
|
2021-05-10 17:20:20 +00:00
|
|
|
/**
|
|
|
|
* Regular expression to look for encoding functions.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $encodingsRegex;
|
|
|
|
|
2013-11-05 20:17:39 +00:00
|
|
|
/**
|
|
|
|
* Initiates the file search and check
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function check()
|
|
|
|
{
|
2021-05-10 17:20:20 +00:00
|
|
|
// Get the functions to look for
|
|
|
|
$encodings = explode(',', $this->params->get('encodings'));
|
|
|
|
|
|
|
|
// Prepare regex
|
|
|
|
foreach ($encodings as $i => $encoding)
|
|
|
|
{
|
|
|
|
$encodings[$i] = preg_quote(trim($encoding), '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->encodingsRegex = '/' . implode('|', $encodings) . '/i';
|
|
|
|
|
2013-11-05 20:17:39 +00:00
|
|
|
// Find all php files of the extension
|
2021-02-13 20:12:08 +00:00
|
|
|
$files = JFolder::files($this->basedir, '\.php$', true, true);
|
2013-11-05 20:17:39 +00:00
|
|
|
|
|
|
|
// Iterate through all files
|
|
|
|
foreach ($files as $file)
|
|
|
|
{
|
|
|
|
// Try to find the base64 use in the file
|
|
|
|
if ($this->find($file))
|
|
|
|
{
|
2021-02-23 20:07:27 +00:00
|
|
|
// The error has been added by the find() method
|
2013-11-05 20:17:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a file and searches for any encoding function defined in the params
|
|
|
|
* Not a very clever way of doing this, but it should be fine for now
|
|
|
|
*
|
|
|
|
* @param string $file The path to the file
|
|
|
|
*
|
|
|
|
* @return boolean True if the statement was found, otherwise False.
|
|
|
|
*/
|
|
|
|
protected function find($file)
|
|
|
|
{
|
2021-05-10 17:20:20 +00:00
|
|
|
$content = file_get_contents($file);
|
2013-11-05 20:17:39 +00:00
|
|
|
|
2021-05-10 17:20:20 +00:00
|
|
|
// Exclude comments
|
|
|
|
$content = JEDCheckerHelper::cleanPhpCode(
|
|
|
|
$content,
|
|
|
|
JEDCheckerHelper::CLEAN_HTML | JEDCheckerHelper::CLEAN_COMMENTS
|
|
|
|
);
|
|
|
|
$content = JEDCheckerHelper::splitLines($content);
|
2021-02-23 20:07:27 +00:00
|
|
|
|
|
|
|
$found = false;
|
2013-11-05 20:17:39 +00:00
|
|
|
|
2021-02-23 20:07:27 +00:00
|
|
|
foreach ($content as $i => $line)
|
|
|
|
{
|
2021-05-10 17:20:20 +00:00
|
|
|
if (preg_match($this->encodingsRegex, $line))
|
2013-11-05 20:17:39 +00:00
|
|
|
{
|
2021-05-10 17:20:20 +00:00
|
|
|
$found = true;
|
2021-07-31 14:21:45 +00:00
|
|
|
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_ENCODING'), $i + 1, $line);
|
2013-11-05 20:17:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:07:27 +00:00
|
|
|
return $found;
|
2013-11-05 20:17:39 +00:00
|
|
|
}
|
2012-08-04 18:48:04 +00:00
|
|
|
}
|