31
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-05-29 03:40:47 +00:00

adding GPL license check for PHP files

This commit is contained in:
Daniel Dimitrov 2013-04-11 15:23:19 +02:00
parent 444ee53e0d
commit 0f0be2ef2a
7 changed files with 151 additions and 11 deletions

View File

@ -58,7 +58,7 @@ class jedcheckerRulesEncoding extends JEDcheckerRule
// 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, 'COM_JEDCHECKER_ERROR_ENCODING');
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_ENCODING'));
}
}
}

View File

@ -0,0 +1,11 @@
; This is the configuration file of the GPL rule.
; ADD all compatible licenses with GPL here
;
; @author eaxs
; @date 07/06/2012
; @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
; @license GNU General Public License version 2 or later; see LICENSE
; The valid constants to search for
constants="BSD"

View File

@ -0,0 +1,125 @@
<?php
/**
* @author eaxs
* @date 07/06/2012
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('_JEXEC') or die('Restricted access');
// Include the rule base class
require_once(JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php');
/**
* This class searches all files for the _JEXEC check
* which prevents direct file access.
*
*/
class jedcheckerRulesGpl extends JEDcheckerRule
{
/**
* The formal ID of this rule. For example: SE1.
*
* @var string
*/
protected $id = 'PH1';
/**
* The title or caption of this rule.
*
* @var string
*/
protected $title = 'COM_JEDCHECKER_RULE_PH1';
/**
* The description of this rule.
*
* @var string
*/
protected $description = 'COM_JEDCHECKER_RULE_PH1_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 _JEXEC check 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_GPL_NOT_FOUND'));
}
}
}
/**
* Reads a file and searches for the _JEXEC statement
*
* @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 constants to look for
$licenses = $this->params->get('constants');
$licenses = explode(',', $licenses);
foreach ($content AS $key => $line)
{
// Search for GPL license
$gpl = stripos($line, 'GPL');
$gnu = stripos($line, 'GNU');
$gpl_long = stripos($line, 'general public license');
if ($gpl || $gnu || $gpl_long)
{
$this->report->addInfo($file,
JText::_('COM_JEDCHECKER_PH1_LICENSE_FOUND') .':' .'<strong>'.$line.'</strong>',
$key);
return true;
}
// Search for the constant name
foreach ($licenses AS $license)
{
$license = trim($license);
// Search for the license
$found = strpos($line, $license);
// Skip the line if the license is not found
if ($found === false)
{
continue;
}
else
{
$this->report->addInfo($file,
JText::_('COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND') . ':'. '<strong>'.$line.'</line>',
$key);
return true;
}
}
}
unset($content);
return false;
}
}

View File

@ -58,7 +58,7 @@ class jedcheckerRulesJexec extends JEDcheckerRule
// Try to find the _JEXEC check in the file
if(!$this->find($file)) {
// Add as error to the report if it was not found
$this->report->addError($file, 'COM_JEDCHECKER_ERROR_JEXEC_NOT_FOUND');
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_JEXEC_NOT_FOUND'));
}
}
}

View File

@ -83,7 +83,7 @@ class jedcheckerRulesXMLlicense extends JEDcheckerRule
// Check if there's a license tag
if (!isset($xml->license)) {
$this->report->addError($file, 'COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_FOUND');
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_FOUND'));
return false;
}
@ -91,7 +91,7 @@ class jedcheckerRulesXMLlicense extends JEDcheckerRule
if (stripos($xml->license, 'gpl') === false &&
stripos($xml->license, 'general public license') === false)
{
$this->report->addCompat($file, 'COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_GPL');
$this->report->addCompat($file, JText::_('COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_GPL'));
return false;
}

View File

@ -85,7 +85,7 @@ class JEDcheckerReport extends JObject
$item = new stdClass();
$item->location = $location;
$item->line = $line;
$item->text = (empty($text) ? '' : JText::_($text));
$item->text = $text;
$this->addItem($item, 'errors');
}
@ -105,7 +105,7 @@ class JEDcheckerReport extends JObject
$item = new stdClass();
$item->location = $location;
$item->line = $line;
$item->text = (empty($text) ? '' : JText::_($text));
$item->text = $text;
$this->addItem($item, 'info');
}
@ -126,7 +126,7 @@ class JEDcheckerReport extends JObject
$item = new stdClass();
$item->location = $location;
$item->line = $line;
$item->text = empty($text) ? NULL : JText::_($text);
$item->text = $text;
$this->addItem($item, 'compat');
}
@ -225,6 +225,7 @@ class JEDcheckerReport extends JObject
$html[] = '<li><p><strong>#'.str_pad($num, 3, '0', STR_PAD_LEFT).'</strong> ';
$html[] = $item->location;
// Add line information if given
if($item->line > 0) {
$html[] = ' '.JText::_('COM_JEDCHECKER_IN_LINE').': <strong>'.$item->line.'</strong>';

View File

@ -11,8 +11,6 @@ COM_JEDCHECKER_STEP3="Click on check and review the results"
COM_JEDCHECKER_WALL_OF_HONOR="Wall of honor"
COM_JEDCHECKER_PEOPLE_THAT_HAVE_HELPED_WITH_THE_DEVELOPMENT="People that have helped with the development of this component"
COM_JEDCHECKER_HOW_TO_INTERPRET_RESULTS="How to interpret the results?"
COM_JEDCHECKER_RULE_SE1="Extension is missing index.html file in all folders"
COM_JEDCHECKER_RULE_SE1_DESC="If you want your extension to be listed on the JED, then you should make sure that all your extension folders contain an index.html file. - Developers don't like this rule at all - it fills your package with index.html files, which in terms slows down the installation process etc. But index.html files provide protection for badly configured hosts (one could argue if we need to try to do anything for those), but as long the joomla CMS comes with those files the JED is going to require that extensions also have those."
COM_JEDCHECKER_RULE_PH2="PHP Files missing JEXEC security"
COM_JEDCHECKER_RULE_PH2_DESC="All the PHP files in your extension needs to have a defined('_JEXEC') or die(); statement in the beginning of each file. This ensures that the file cannot be opened outside of the joomla installation and this way increases the security of your site."
COM_JEDCHECKER_RULE_PH3="License tag missing or incorrect in XML install file"
@ -34,7 +32,12 @@ COM_JEDCHECKER_RULE_ENCODING_DESC="As developers we are fully aware that the bas
COM_JEDCHECKER_LEAVE_A_REVIEW_JED="If you use this component, please post a rating and a review at the <a href='%s' title='JED' target='_blank'>Joomla! Extensions Directory</a>."
COM_JEDCHECKER_INFO="Info"
COM_JEDCHECKER_INFO_XML="Just some info about the extension xml files"
COM_JEDCHECKER_INFO_XML_DESC="This is not a rule, just a convenience check. We go through the xml files and grab the value for the name tag. Useful information for the "filename and install as" fields in the jed submission form"
COM_JEDCHECKER_INFO_XML_DESC="This is not a rule, just a convenience check. We go through the xml files and grab the value for the name tag. Useful information for the &quot;filename and install as&quot; fields in the jed submission form"
COM_JEDCHECKER_INFO_XML_NAME_XML="The name tag in this file is: %s"
COM_JEDCHECKER_INFO_XML_VERSION_XML="Version tag has the value: %s"
COM_JEDCHECKER_INFO_XML_CREATIONDATE_XML="The creationDate tag has the value: %s"
COM_JEDCHECKER_INFO_XML_CREATIONDATE_XML="The creationDate tag has the value: %s"
COM_JEDCHECKER_RULE_PH1="PHP Headers missing GPL License Notice"
COM_JEDCHECKER_RULE_PH1_DESC="A notice is required on each PHP file stating that the file is licensed GPL (or other compatible accepted license). More info <a href='http://extensions.joomla.org/index.php?option=com_content&id=50' target='_blank'>here</a>"
COM_JEDCHECKER_ERROR_GPL_NOT_FOUND="GPL or compatible license was not found"
COM_JEDCHECKER_PH1_LICENSE_FOUND="GPL license was found"
COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND="GPL compatible license was found"