33
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-12-05 03:13:19 +00:00
jedchecker/administrator/components/com_jedchecker/libraries/rules/encoding.php

104 lines
2.2 KiB
PHP
Raw Normal View History

<?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
*/
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';
/**
2013-11-05 20:17:39 +00:00
* class JedcheckerRulesEncoding
*
2013-11-05 20:17:39 +00:00
* This class checks if base64 encoding is used in the files
*
* @since 1.0
*/
2013-11-05 20:17:39 +00:00
class JedcheckerRulesEncoding extends JEDcheckerRule
{
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';
/**
* Initiates the file search and check
*
* @return void
*/
public function check()
{
// Find all php files of the extension
$files = JFolder::files($this->basedir, '.php$', true, true);
// Iterate through all files
foreach ($files as $file)
{
// Try to find the base64 use in the file
if ($this->find($file))
{
// Add as error to the report if it was not found
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_ENCODING'));
}
}
}
/**
* 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)
{
$content = (array) file($file);
// Get the functions to look for
$encodings = explode(',', $this->params->get('encodings'));
foreach ($encodings as $encoding)
{
$encoding = trim($encoding);
foreach ($content AS $line)
{
// Search for "base64"
$pos_1 = stripos($line, $encoding);
if ($pos_1 !== false)
{
return true;
}
}
}
return false;
}
}