From 92ff3e2bec95705f30360116558961f86d83be99 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Sun, 24 Jan 2021 20:11:17 +0300 Subject: [PATCH 01/10] Update gpl.ini Add most popular GPL-compatible licenses from https://www.gnu.org/licenses/license-list.en.html --- administrator/components/com_jedchecker/libraries/rules/gpl.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl.ini b/administrator/components/com_jedchecker/libraries/rules/gpl.ini index 2697061..936c902 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl.ini +++ b/administrator/components/com_jedchecker/libraries/rules/gpl.ini @@ -11,4 +11,4 @@ ; ; The valid constants to search for -constants="BSD" +constants="Apache,Artistic,BSD,CC0,Creative Commons Attribution,MIT,MPL" From 02ccd6fa65ef5e61ad701d9da1a64fa338224640 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Sun, 31 Jan 2021 11:52:32 +0300 Subject: [PATCH 02/10] move lists of GPL and compatible licenses to separate files --- .../com_jedchecker/libraries/rules/gpl.ini | 2 +- .../com_jedchecker/libraries/rules/gpl.php | 197 ++++++++++++------ .../libraries/rules/gpl_compat.txt | 169 +++++++++++++++ .../libraries/rules/gpl_gnu.txt | 38 ++++ 4 files changed, 341 insertions(+), 65 deletions(-) create mode 100644 administrator/components/com_jedchecker/libraries/rules/gpl_compat.txt create mode 100644 administrator/components/com_jedchecker/libraries/rules/gpl_gnu.txt diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl.ini b/administrator/components/com_jedchecker/libraries/rules/gpl.ini index 936c902..5056d65 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl.ini +++ b/administrator/components/com_jedchecker/libraries/rules/gpl.ini @@ -11,4 +11,4 @@ ; ; The valid constants to search for -constants="Apache,Artistic,BSD,CC0,Creative Commons Attribution,MIT,MPL" +constants="" diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl.php b/administrator/components/com_jedchecker/libraries/rules/gpl.php index cdd440b..c70e89e 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl.php +++ b/administrator/components/com_jedchecker/libraries/rules/gpl.php @@ -47,6 +47,20 @@ class JedcheckerRulesGpl extends JEDcheckerRule */ protected $description = 'COM_JEDCHECKER_RULE_PH1_DESC'; + /** + * Regular expression to match GPL licenses. + * + * @var string + */ + protected $regex_gpl_licenses; + + /** + * Regular expression to match GPL-compatible licenses. + * + * @var string + */ + protected $regex_compat_licenses; + /** * Initiates the file search and check * @@ -54,6 +68,9 @@ class JedcheckerRulesGpl extends JEDcheckerRule */ public function check() { + // Prepare regexp + $this->init(); + // Find all php files of the extension $files = JFolder::files($this->basedir, '.php$', true, true); @@ -70,7 +87,94 @@ class JedcheckerRulesGpl extends JEDcheckerRule } /** - * Reads a file and searches for the _JEXEC statement + * Initialization (prepare regular expressions) + */ + protected function init() + { + $gpl_licenses = (array) file(__DIR__ . '/gpl_gnu.txt'); + $this->regex_gpl_licenses = $this->generate_regexp($gpl_licenses); + + $compat_licenses = (array) file(__DIR__ . '/gpl_compat.txt'); + + $extra_licenses = $this->params->get('constants'); + $extra_licenses = explode(',', $extra_licenses); + + $compat_licenses = array_merge($compat_licenses, $extra_licenses); + + $this->regex_compat_licenses = $this->generate_regexp($compat_licenses); + } + + /** + * Generate regular expression to match the given list of license names + * @param $lines + * @return string + */ + protected function generate_regexp($lines) + { + $titles = array(); + $ids = array(); + + foreach ($lines as $line) + { + $line = trim($line); + if ($line === '' || $line[0] === '#') + { + // skip empty and commented lines + continue; + } + + $title = $line; + if (substr($line, -1, 1) === ')') + { + // extract identifier + $pos = strrpos($line, '('); + if ($pos !== false) + { + $title = trim(substr($line, 0, $pos)); + + $id = trim(substr($line, $pos + 1, -1)); + + if ($id !== '') + { + $id = preg_quote($id, '#'); + $ids[$id] = 1; + } + } + } + + if ($title !== '') + { + $title = preg_quote($title, '#'); + + // expand vN.N to different version formats + $title = preg_replace('/(?<=\S)\s+v(?=\d)/', ',?\s+(?:v\.?\s*|version\s+)?', $title); + + $title = preg_replace('/\s+/', '\s+', $title); + + $titles[$title] = 1; + } + } + + if (count($titles) === 0) + { + return null; + } + + $titles = implode('|', array_keys($titles)); + + if (count($ids)) + { + $ids = implode('|', array_keys($ids)); + $titles .= + '|\blicense\b.+?(?:' . $ids . ')' . + '|\b(?:' . $ids . ')\s+license\b'; + } + + return '#^.*?(?:' . $titles . ').*?$#im'; + } + + /** + * Reads a file and searches for its license * * @param string $file - The path to the file * @@ -78,72 +182,37 @@ class JedcheckerRulesGpl extends JEDcheckerRule */ protected function find($file) { - $content = (array) file($file); - - // Get the constants to look for - $licenses = $this->params->get('constants'); - $licenses = explode(',', $licenses); - - $hascode = 0; - - foreach ($content AS $key => $line) + // check the file is empty (i.e. comments-only) + $content = php_strip_whitespace($file); + if (preg_match('#^<\?php\s+$#', $content)) { - $tline = trim($line); - - if ($tline == '' || $tline == '') - { - continue; - } - - if ($tline['0'] != '/' && $tline['0'] != '*') - { - $hascode = 1; - } - - // 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') . ':' . '' . $line . '', - $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') . ':' . '' . $line . '', - $key - ); - - return true; - } - } + return true; } - unset($content); + $content = file_get_contents($file); - return $hascode ? false : true; + if (preg_match($this->regex_gpl_licenses, $content, $match, PREG_OFFSET_CAPTURE)) + { + $line_no = substr_count($content, "\n", 0, $match[0][1]) + 1; + $this->report->addInfo( + $file, + JText::_('COM_JEDCHECKER_PH1_LICENSE_FOUND') . ':' . '' . $match[0][0] . '', + $line_no + ); + return true; + } + + if (preg_match($this->regex_compat_licenses, $content, $match, PREG_OFFSET_CAPTURE)) + { + $line_no = substr_count($content, "\n", 0, $match[0][1]) + 1; + $this->report->addInfo( + $file, + JText::_('COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND') . ':' . '' . $match[0][0] . '', + $line_no + ); + return true; + } + + return false; } } diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl_compat.txt b/administrator/components/com_jedchecker/libraries/rules/gpl_compat.txt new file mode 100644 index 0000000..777bed6 --- /dev/null +++ b/administrator/components/com_jedchecker/libraries/rules/gpl_compat.txt @@ -0,0 +1,169 @@ +# Based on: +# https://www.gnu.org/licenses/license-list.en.html +# https://opensource.org/licenses/alphabetical +# https://spdx.org/licenses/ + +# Comments are marked with the "#" character in the first position of the line + +# Each line contains the full name of the license with the optional abbreviation in parenthesis + +# The version of the license (if presented) should be written in the form +# [space][the letter "v"][digit(s)] +# (see examples below) + + +# BSD Licenses +BSD License +0-clause BSD License (0BSD) +BSD Zero Clause License +Zero-Clause BSD / Free Public License v1.0.0 +1-clause BSD License (BSD-1-Clause) +BSD 1-Clause License +2-clause BSD License (BSD-2-Clause) +BSD 2-Clause "Simplified" License +BSD-2-Clause Plus Patent License (BSD-2-Clause-Patent) +BSD+Patent +FreeBSD License +3-clause BSD License (BSD-3-Clause) +BSD 3-Clause "New" or "Revised" License +Lawrence Berkeley National Labs BSD variant License (BSD-3-Clause-LBNL) +Modified BSD License +Clear BSD License + +# Other OSI Licenses +Academic Free License v1.1 (AFL-1.1) +Academic Free License v1.2 (AFL-1.2) +Academic Free License v2.0 (AFL-2.0) +Academic Free License v2.1 (AFL-2.1) +Academic Free License v3.0 (AFL-3.0) +Adaptive Public License (APL-1.0) +Apache License v1.1 (Apache-1.1) +Apache Software License v1.1 +Apache License v2.0 (Apache-2.0) +Apple Public Source License v1.0 (APSL-1.0) +Apple Public Source License v1.1 (APSL-1.1) +Apple Public Source License v1.2 (APSL-1.2) +Apple Public Source License v2.0 (APSL-2.0) +Apple Public Source License +Artistic License v1.0 (Artistic-1.0) +Artistic License +Artistic License v2.0 (Artistic-2.0) +Attribution Assurance License (AAL) +Berkeley Database License +Boost Software License (BSL-1.0) +CeCILL v2 +CeCILL License v2.1 (CECILL-2.1) +CeCILL Free Software License Agreement v2.1 +CERN Open Hardware Licence v2 - Permissive (CERN-OHL-P-2.0) +CERN Open Hardware Licence v2 - Weakly Reciprocal (CERN-OHL-W-2.0) +CERN Open Hardware Licence v2 - Strongly Reciprocal (CERN-OHL-S-2.0) +Clarified Artistic License +Common Development and Distribution License v1.0 (CDDL-1.0) +Common Public Attribution License v1.0 (CPAL-1.0) +Common Public License v1.0 (CPL-1.0) +Computer Associates Trusted Open Source License v1.1 (CATOSL-1.1) +Cryptix General License +Cryptographic Autonomy License v1.0 (CAL-1.0) +CUA Office Public License v1.0 (CUA-OPL-1.0) +Eclipse Public License v1.0 (EPL-1.0) +Eclipse Public License v2.0 (EPL-2.0) +eCos License v2.0 (eCos-2.0) +Educational Community License v1.0 (ECL-1.0) +Educational Community License v2.0 (ECL-2.0) +Eiffel Forum License v1.0 (EFL-1.0) +Eiffel Forum License v2.0 (EFL-2.0) +Entessa Public License (Entessa) +EU DataGrid Software License (EUDatagrid) +European Union Public License v1.1 (EUPL-1.1) +European Union Public License v1.2 (EUPL-1.2) +Expat License +Fair License (Fair) +Frameworx License (Frameworx-1.0) +Frameworx Open License v1.0 +Freetype Project License +Historical Permission Notice and Disclaimer (HPND) +IBM Public License v1.0 (IPL-1.0) +Independent JPEG Group License +Intel Open Source License (Intel) +IPA Font License (IPA) +ISC License (ISC) +Jabber Open Source License +LaTeX Project Public License v1.3c (LPPL-1.3c) +Licence Libre du Québec – Permissive (LiLiQ-P) v1.1 (LiliQ-P) +Licence Libre du Québec – Permissive v1.1 (LiLiQ-P-1.1) +Licence Libre du Québec – Réciprocité (LiLiQ-R) v1.1 (LiliQ-R) +Licence Libre du Québec – Réciprocité v1.1 (LiLiQ-R-1.1) +Licence Libre du Québec – Réciprocité forte (LiLiQ-R+) v1.1 (LiliQ-R+) +Licence Libre du Québec – Réciprocité forte v1.1 (LiLiQ-Rplus-1.1) +Lucent Public License ("Plan9") v1.0 (LPL-1.0) +Lucent Public License v1.0 +Lucent Public License v1.02 (LPL-1.02) +Microsoft Public License (MS-PL) +Microsoft Reciprocal License (MS-RL) +MirOS Licence (MirOS) +MIT License (MIT) +MIT No Attribution (MIT-0) +MITRE Collaborative Virtual Workspace License (CVW) +Motosoto License (Motosoto) +Mozilla Public License v1.0 (MPL-1.0) +Mozilla Public License v1.1 (MPL-1.1) +Mozilla Public License v2.0 (MPL-2.0) +Mulan Permissive Software License v2 (MulanPSL-2.0) +Multics License (Multics) +NASA Open Source Agreement v1.3 (NASA-1.3) +Naumen Public License (Naumen) +Nethack General Public License (NGPL) +Nokia Open Source License (Nokia) +Non-Profit Open Software License v3.0 (NPOSL-3.0) +NTP License (NTP) +OCLC Research Public License v2.0 (OCLC-2.0) +Open Group Test Suite License (OGTSL) +Open Software License v1.0 (OSL-1.0) +Open Software License v2.0 (OSL-2.0) +Open Software License v2.1 (OSL-2.1) +Open Software License v3.0 (OSL-3.0) +OpenLDAP License v2.7 +OpenLDAP Public License v2.8 (OLDAP-2.8) +Open LDAP Public License v2.8 +OSET Public License v2.1 (OSET-PL-2.1) +PHP License v3.0 (PHP-3.0) +PHP License v3.01 (PHP-3.01) +PostgreSQL License (PostgreSQL) +Python License (Python-2.0) +CNRI Python License (CNRI-Python) +Q Public License (QPL-1.0) +RealNetworks Public Source License v1.0 (RPSL-1.0) +Reciprocal Public License v1.1 (RPL-1.1) +Reciprocal Public License v1.5 (RPL-1.5) +Ricoh Source Code Public License (RSCPL) +SGI Free Software License B v2.0 +SIL Open Font License v1.1 (OFL-1.1) +Simple Public License v2.0 (SimPL-2.0) +Sleepycat License (Sleepycat) +Sleepycat Software Product License +Standard ML of New Jersey Copyright License +Sun Industry Standards Source License (SISSL) +Sun Public License v1.0 (SPL-1.0) +Sybase Open Watcom Public License v1.0 (Watcom-1.0) +Unicode Data Files and Software License (Unicode-DFS-2016) +Unicode License Agreement - Data Files and Software +Unicode, Inc. License Agreement for Data Files and Software +Universal Permissive License (UPL) +Universal Permissive License v1.0 (UPL-1.0) +University of Illinois/NCSA Open Source License (NCSA) +NCSA/University of Illinois Open Source License +Unlicense +Upstream Compatibility License v1.0 (UCL-1.0) +Vovida Software License v.1.0 (VSL-1.0) +W3C License (W3C) +W3C Software Notice and License +WTFPL v2 +WxWidgets Library License +wxWindows Library License (WXwindows) +X11 License +XFree86 v1.1 License +X.Net License (Xnet) +Zope Public License v2.0 (ZPL-2.0) +Zope Public License v2.1 +zlib/libpng License (Zlib) +zlib License diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl_gnu.txt b/administrator/components/com_jedchecker/libraries/rules/gpl_gnu.txt new file mode 100644 index 0000000..8e2979f --- /dev/null +++ b/administrator/components/com_jedchecker/libraries/rules/gpl_gnu.txt @@ -0,0 +1,38 @@ +# GPL Licenses + +# Based on: +# https://www.gnu.org/licenses/license-list.en.html +# https://opensource.org/licenses/alphabetical +# https://spdx.org/licenses/ + +# Comments are marked with the "#" character in the first position of the line + +# Each line contains the full name of the license with the optional abbreviation in parenthesis + +# The version of the license (if presented) should be written in the form +# [space][the letter "v"][digit(s)] +# (see examples below) + + +GNU General Public License +GNU GPL +GNU/GPL +GNU Lesser General Public License +GNU LGPL +GNU/LGPL + +GNU General Public License v2 (GPL-2.0) +//www.gnu.org/licenses/gpl-2.0.html + +GNU General Public License v3 (GPL-3.0) +//www.gnu.org/licenses/gpl-3.0.html + +GNU Affero General Public License v3 (AGPL-3.0) +GNU Affero General Public License (AGPL) v3 +GNU Library General Public License v2 (LGPL-2.0) +GNU Lesser General Public License v2.1 (LGPL-2.1) +GNU Lesser General Public License (LGPL) v2.1 +GNU Lesser General Public License v3 (LGPL-3.0) +GNU Lesser General Public License (LGPL) v3 + +GNU All-Permissive License From 53c5903fa0e3ce9c75145dd566ae464aa06c982e Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Tue, 23 Feb 2021 21:07:30 +0300 Subject: [PATCH 03/10] remove leading '*' character to deal with multi-line license names --- .../components/com_jedchecker/libraries/rules/gpl.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl.php b/administrator/components/com_jedchecker/libraries/rules/gpl.php index c70e89e..718f425 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl.php +++ b/administrator/components/com_jedchecker/libraries/rules/gpl.php @@ -191,6 +191,9 @@ class JedcheckerRulesGpl extends JEDcheckerRule $content = file_get_contents($file); + // Remove leading "*" characters from phpDoc-like comments + $content = preg_replace('/^\s*\*/m', '', $content); + if (preg_match($this->regex_gpl_licenses, $content, $match, PREG_OFFSET_CAPTURE)) { $line_no = substr_count($content, "\n", 0, $match[0][1]) + 1; From 7741b2b0ced6b0db971633bcc01367b885c36416 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Tue, 23 Feb 2021 21:10:16 +0300 Subject: [PATCH 04/10] move licenses list to gpl directory --- .../components/com_jedchecker/libraries/rules/gpl.php | 4 ++-- .../libraries/rules/{gpl_compat.txt => gpl/compat.txt} | 0 .../libraries/rules/{gpl_gnu.txt => gpl/gnu.txt} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename administrator/components/com_jedchecker/libraries/rules/{gpl_compat.txt => gpl/compat.txt} (100%) rename administrator/components/com_jedchecker/libraries/rules/{gpl_gnu.txt => gpl/gnu.txt} (100%) diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl.php b/administrator/components/com_jedchecker/libraries/rules/gpl.php index 718f425..046e538 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl.php +++ b/administrator/components/com_jedchecker/libraries/rules/gpl.php @@ -91,10 +91,10 @@ class JedcheckerRulesGpl extends JEDcheckerRule */ protected function init() { - $gpl_licenses = (array) file(__DIR__ . '/gpl_gnu.txt'); + $gpl_licenses = (array) file(__DIR__ . '/gpl/gnu.txt'); $this->regex_gpl_licenses = $this->generate_regexp($gpl_licenses); - $compat_licenses = (array) file(__DIR__ . '/gpl_compat.txt'); + $compat_licenses = (array) file(__DIR__ . '/gpl/compat.txt'); $extra_licenses = $this->params->get('constants'); $extra_licenses = explode(',', $extra_licenses); diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl_compat.txt b/administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt similarity index 100% rename from administrator/components/com_jedchecker/libraries/rules/gpl_compat.txt rename to administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl_gnu.txt b/administrator/components/com_jedchecker/libraries/rules/gpl/gnu.txt similarity index 100% rename from administrator/components/com_jedchecker/libraries/rules/gpl_gnu.txt rename to administrator/components/com_jedchecker/libraries/rules/gpl/gnu.txt From 2c28bafe4768c9d399037eb5113034401ee29ba8 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Tue, 23 Feb 2021 21:12:54 +0300 Subject: [PATCH 05/10] add extra names (BSD v2 and BSD v3) into licenses list --- .../components/com_jedchecker/libraries/rules/gpl/compat.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt b/administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt index 777bed6..694db2e 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt +++ b/administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt @@ -20,11 +20,13 @@ Zero-Clause BSD / Free Public License v1.0.0 1-clause BSD License (BSD-1-Clause) BSD 1-Clause License 2-clause BSD License (BSD-2-Clause) +BSD v2 (BSDv2) BSD 2-Clause "Simplified" License BSD-2-Clause Plus Patent License (BSD-2-Clause-Patent) BSD+Patent FreeBSD License 3-clause BSD License (BSD-3-Clause) +BSD v3 (BSDv3) BSD 3-Clause "New" or "Revised" License Lawrence Berkeley National Labs BSD variant License (BSD-3-Clause-LBNL) Modified BSD License From 2c2ea7da4688da4f7e9903377f43260b572ff456 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Wed, 24 Feb 2021 02:27:30 +0300 Subject: [PATCH 06/10] unify displayed code lines --- .../com_jedchecker/libraries/rules/gpl.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl.php b/administrator/components/com_jedchecker/libraries/rules/gpl.php index 046e538..d0d707a 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl.php +++ b/administrator/components/com_jedchecker/libraries/rules/gpl.php @@ -184,6 +184,7 @@ class JedcheckerRulesGpl extends JEDcheckerRule { // check the file is empty (i.e. comments-only) $content = php_strip_whitespace($file); + if (preg_match('#^<\?php\s+$#', $content)) { return true; @@ -199,9 +200,11 @@ class JedcheckerRulesGpl extends JEDcheckerRule $line_no = substr_count($content, "\n", 0, $match[0][1]) + 1; $this->report->addInfo( $file, - JText::_('COM_JEDCHECKER_PH1_LICENSE_FOUND') . ':' . '' . $match[0][0] . '', - $line_no + JText::_('COM_JEDCHECKER_PH1_LICENSE_FOUND'), + $line_no, + $match[0][0] ); + return true; } @@ -210,9 +213,11 @@ class JedcheckerRulesGpl extends JEDcheckerRule $line_no = substr_count($content, "\n", 0, $match[0][1]) + 1; $this->report->addInfo( $file, - JText::_('COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND') . ':' . '' . $match[0][0] . '', - $line_no + JText::_('COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND'), + $line_no, + $match[0][0] ); + return true; } From 40135deac7d9fa884cbc94a6840f380f24a08be1 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Sun, 4 Apr 2021 13:31:35 +0300 Subject: [PATCH 07/10] Joomla! code style fixes --- .../com_jedchecker/libraries/rules/gpl.php | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl.php b/administrator/components/com_jedchecker/libraries/rules/gpl.php index d0d707a..6f4f482 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl.php +++ b/administrator/components/com_jedchecker/libraries/rules/gpl.php @@ -13,14 +13,13 @@ defined('_JEXEC') or die('Restricted access'); // Include the rule base class -require_once(JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php'); +require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php'; /** * class JedcheckerRulesGpl * - * This class searches all files for the _JEXEC check - * which prevents direct file access. + * This class searches all files for the GPL/compatible licenses * * @since 1.0 */ @@ -52,14 +51,14 @@ class JedcheckerRulesGpl extends JEDcheckerRule * * @var string */ - protected $regex_gpl_licenses; + protected $regexGPLLicenses; /** * Regular expression to match GPL-compatible licenses. * * @var string */ - protected $regex_compat_licenses; + protected $regexCompatLicenses; /** * Initiates the file search and check @@ -88,28 +87,31 @@ class JedcheckerRulesGpl extends JEDcheckerRule /** * Initialization (prepare regular expressions) + * + * @return void */ protected function init() { - $gpl_licenses = (array) file(__DIR__ . '/gpl/gnu.txt'); - $this->regex_gpl_licenses = $this->generate_regexp($gpl_licenses); + $GPLLicenses = (array) file(__DIR__ . '/gpl/gnu.txt'); + $this->regexGPLLicenses = $this->generateRegexp($GPLLicenses); - $compat_licenses = (array) file(__DIR__ . '/gpl/compat.txt'); + $compatLicenses = (array) file(__DIR__ . '/gpl/compat.txt'); - $extra_licenses = $this->params->get('constants'); - $extra_licenses = explode(',', $extra_licenses); + $extraLicenses = $this->params->get('constants'); + $extraLicenses = explode(',', $extraLicenses); - $compat_licenses = array_merge($compat_licenses, $extra_licenses); + $compatLicenses = array_merge($compatLicenses, $extraLicenses); - $this->regex_compat_licenses = $this->generate_regexp($compat_licenses); + $this->regexCompatLicenses = $this->generateRegexp($compatLicenses); } /** * Generate regular expression to match the given list of license names - * @param $lines + * @param array $lines List of license names + * * @return string */ - protected function generate_regexp($lines) + protected function generateRegexp($lines) { $titles = array(); $ids = array(); @@ -117,17 +119,19 @@ class JedcheckerRulesGpl extends JEDcheckerRule foreach ($lines as $line) { $line = trim($line); + if ($line === '' || $line[0] === '#') { - // skip empty and commented lines + // Skip empty and commented lines continue; } $title = $line; if (substr($line, -1, 1) === ')') { - // extract identifier + // Extract identifier $pos = strrpos($line, '('); + if ($pos !== false) { $title = trim(substr($line, 0, $pos)); @@ -146,7 +150,7 @@ class JedcheckerRulesGpl extends JEDcheckerRule { $title = preg_quote($title, '#'); - // expand vN.N to different version formats + // Expand vN.N to different version formats $title = preg_replace('/(?<=\S)\s+v(?=\d)/', ',?\s+(?:v\.?\s*|version\s+)?', $title); $title = preg_replace('/\s+/', '\s+', $title); @@ -182,7 +186,7 @@ class JedcheckerRulesGpl extends JEDcheckerRule */ protected function find($file) { - // check the file is empty (i.e. comments-only) + // Check the file is empty (i.e. comments-only) $content = php_strip_whitespace($file); if (preg_match('#^<\?php\s+$#', $content)) @@ -195,26 +199,26 @@ class JedcheckerRulesGpl extends JEDcheckerRule // Remove leading "*" characters from phpDoc-like comments $content = preg_replace('/^\s*\*/m', '', $content); - if (preg_match($this->regex_gpl_licenses, $content, $match, PREG_OFFSET_CAPTURE)) + if (preg_match($this->regexGPLLicenses, $content, $match, PREG_OFFSET_CAPTURE)) { - $line_no = substr_count($content, "\n", 0, $match[0][1]) + 1; + $lineno = substr_count($content, "\n", 0, $match[0][1]) + 1; $this->report->addInfo( $file, JText::_('COM_JEDCHECKER_PH1_LICENSE_FOUND'), - $line_no, + $lineno, $match[0][0] ); return true; } - if (preg_match($this->regex_compat_licenses, $content, $match, PREG_OFFSET_CAPTURE)) + if (preg_match($this->regexCompatLicenses, $content, $match, PREG_OFFSET_CAPTURE)) { - $line_no = substr_count($content, "\n", 0, $match[0][1]) + 1; + $lineno = substr_count($content, "\n", 0, $match[0][1]) + 1; $this->report->addInfo( $file, JText::_('COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND'), - $line_no, + $lineno, $match[0][0] ); From f7d9cad01ade1a8fb770f63d3ca664f4b53a00a8 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Tue, 11 May 2021 14:43:39 +0300 Subject: [PATCH 08/10] skip nonexecutable files [starting with die() or exit()] in GPL rule --- .../components/com_jedchecker/libraries/rules/gpl.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl.php b/administrator/components/com_jedchecker/libraries/rules/gpl.php index 6f4f482..e93a45c 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl.php +++ b/administrator/components/com_jedchecker/libraries/rules/gpl.php @@ -186,14 +186,15 @@ class JedcheckerRulesGpl extends JEDcheckerRule */ protected function find($file) { - // Check the file is empty (i.e. comments-only) $content = php_strip_whitespace($file); - if (preg_match('#^<\?php\s+$#', $content)) + // Check the file is empty, comments-only, or nonexecutable + if (empty($content) || preg_match('#^<\?php\s+(?:$|(?:die|exit)(?:\(\))?;)#', $content)) { return true; } + // Reload file to preserve comments and line numbers $content = file_get_contents($file); // Remove leading "*" characters from phpDoc-like comments From 91c9d8234db858b3cee4a38b5c6cb2cc21150821 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Mon, 17 May 2021 22:42:12 +0300 Subject: [PATCH 09/10] remove GPL-incompatible licenses --- .../libraries/rules/gpl/compat.txt | 96 +------------------ 1 file changed, 3 insertions(+), 93 deletions(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt b/administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt index 694db2e..add378f 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt +++ b/administrator/components/com_jedchecker/libraries/rules/gpl/compat.txt @@ -13,7 +13,6 @@ # BSD Licenses -BSD License 0-clause BSD License (0BSD) BSD Zero Clause License Zero-Clause BSD / Free Public License v1.0.0 @@ -23,130 +22,44 @@ BSD 1-Clause License BSD v2 (BSDv2) BSD 2-Clause "Simplified" License BSD-2-Clause Plus Patent License (BSD-2-Clause-Patent) -BSD+Patent FreeBSD License 3-clause BSD License (BSD-3-Clause) BSD v3 (BSDv3) BSD 3-Clause "New" or "Revised" License -Lawrence Berkeley National Labs BSD variant License (BSD-3-Clause-LBNL) Modified BSD License Clear BSD License -# Other OSI Licenses -Academic Free License v1.1 (AFL-1.1) -Academic Free License v1.2 (AFL-1.2) -Academic Free License v2.0 (AFL-2.0) -Academic Free License v2.1 (AFL-2.1) -Academic Free License v3.0 (AFL-3.0) -Adaptive Public License (APL-1.0) -Apache License v1.1 (Apache-1.1) -Apache Software License v1.1 +# Other GPL-compatible Licenses Apache License v2.0 (Apache-2.0) -Apple Public Source License v1.0 (APSL-1.0) -Apple Public Source License v1.1 (APSL-1.1) -Apple Public Source License v1.2 (APSL-1.2) -Apple Public Source License v2.0 (APSL-2.0) -Apple Public Source License -Artistic License v1.0 (Artistic-1.0) -Artistic License Artistic License v2.0 (Artistic-2.0) -Attribution Assurance License (AAL) Berkeley Database License Boost Software License (BSL-1.0) CeCILL v2 CeCILL License v2.1 (CECILL-2.1) CeCILL Free Software License Agreement v2.1 -CERN Open Hardware Licence v2 - Permissive (CERN-OHL-P-2.0) -CERN Open Hardware Licence v2 - Weakly Reciprocal (CERN-OHL-W-2.0) -CERN Open Hardware Licence v2 - Strongly Reciprocal (CERN-OHL-S-2.0) Clarified Artistic License -Common Development and Distribution License v1.0 (CDDL-1.0) -Common Public Attribution License v1.0 (CPAL-1.0) -Common Public License v1.0 (CPL-1.0) -Computer Associates Trusted Open Source License v1.1 (CATOSL-1.1) Cryptix General License -Cryptographic Autonomy License v1.0 (CAL-1.0) -CUA Office Public License v1.0 (CUA-OPL-1.0) -Eclipse Public License v1.0 (EPL-1.0) -Eclipse Public License v2.0 (EPL-2.0) eCos License v2.0 (eCos-2.0) -Educational Community License v1.0 (ECL-1.0) Educational Community License v2.0 (ECL-2.0) -Eiffel Forum License v1.0 (EFL-1.0) Eiffel Forum License v2.0 (EFL-2.0) -Entessa Public License (Entessa) EU DataGrid Software License (EUDatagrid) -European Union Public License v1.1 (EUPL-1.1) -European Union Public License v1.2 (EUPL-1.2) Expat License -Fair License (Fair) -Frameworx License (Frameworx-1.0) -Frameworx Open License v1.0 Freetype Project License Historical Permission Notice and Disclaimer (HPND) -IBM Public License v1.0 (IPL-1.0) Independent JPEG Group License Intel Open Source License (Intel) -IPA Font License (IPA) ISC License (ISC) -Jabber Open Source License -LaTeX Project Public License v1.3c (LPPL-1.3c) -Licence Libre du Québec – Permissive (LiLiQ-P) v1.1 (LiliQ-P) -Licence Libre du Québec – Permissive v1.1 (LiLiQ-P-1.1) -Licence Libre du Québec – Réciprocité (LiLiQ-R) v1.1 (LiliQ-R) -Licence Libre du Québec – Réciprocité v1.1 (LiLiQ-R-1.1) -Licence Libre du Québec – Réciprocité forte (LiLiQ-R+) v1.1 (LiliQ-R+) -Licence Libre du Québec – Réciprocité forte v1.1 (LiLiQ-Rplus-1.1) -Lucent Public License ("Plan9") v1.0 (LPL-1.0) -Lucent Public License v1.0 -Lucent Public License v1.02 (LPL-1.02) -Microsoft Public License (MS-PL) -Microsoft Reciprocal License (MS-RL) -MirOS Licence (MirOS) MIT License (MIT) -MIT No Attribution (MIT-0) -MITRE Collaborative Virtual Workspace License (CVW) -Motosoto License (Motosoto) -Mozilla Public License v1.0 (MPL-1.0) -Mozilla Public License v1.1 (MPL-1.1) Mozilla Public License v2.0 (MPL-2.0) -Mulan Permissive Software License v2 (MulanPSL-2.0) -Multics License (Multics) -NASA Open Source Agreement v1.3 (NASA-1.3) -Naumen Public License (Naumen) -Nethack General Public License (NGPL) -Nokia Open Source License (Nokia) -Non-Profit Open Software License v3.0 (NPOSL-3.0) -NTP License (NTP) -OCLC Research Public License v2.0 (OCLC-2.0) -Open Group Test Suite License (OGTSL) -Open Software License v1.0 (OSL-1.0) -Open Software License v2.0 (OSL-2.0) -Open Software License v2.1 (OSL-2.1) -Open Software License v3.0 (OSL-3.0) OpenLDAP License v2.7 OpenLDAP Public License v2.8 (OLDAP-2.8) Open LDAP Public License v2.8 -OSET Public License v2.1 (OSET-PL-2.1) -PHP License v3.0 (PHP-3.0) -PHP License v3.01 (PHP-3.01) -PostgreSQL License (PostgreSQL) +Public Domain Python License (Python-2.0) -CNRI Python License (CNRI-Python) -Q Public License (QPL-1.0) -RealNetworks Public Source License v1.0 (RPSL-1.0) -Reciprocal Public License v1.1 (RPL-1.1) -Reciprocal Public License v1.5 (RPL-1.5) -Ricoh Source Code Public License (RSCPL) SGI Free Software License B v2.0 -SIL Open Font License v1.1 (OFL-1.1) -Simple Public License v2.0 (SimPL-2.0) Sleepycat License (Sleepycat) Sleepycat Software Product License Standard ML of New Jersey Copyright License -Sun Industry Standards Source License (SISSL) -Sun Public License v1.0 (SPL-1.0) -Sybase Open Watcom Public License v1.0 (Watcom-1.0) Unicode Data Files and Software License (Unicode-DFS-2016) Unicode License Agreement - Data Files and Software Unicode, Inc. License Agreement for Data Files and Software @@ -155,16 +68,13 @@ Universal Permissive License v1.0 (UPL-1.0) University of Illinois/NCSA Open Source License (NCSA) NCSA/University of Illinois Open Source License Unlicense -Upstream Compatibility License v1.0 (UCL-1.0) -Vovida Software License v.1.0 (VSL-1.0) -W3C License (W3C) +W3C License W3C Software Notice and License WTFPL v2 WxWidgets Library License wxWindows Library License (WXwindows) X11 License XFree86 v1.1 License -X.Net License (Xnet) Zope Public License v2.0 (ZPL-2.0) Zope Public License v2.1 zlib/libpng License (Zlib) From eed155ed6f8685126491660b734928b71dd6e899 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Fri, 30 Jul 2021 22:02:33 +0300 Subject: [PATCH 10/10] warning-level for GPL-compatible licenses --- administrator/components/com_jedchecker/libraries/rules/gpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/gpl.php b/administrator/components/com_jedchecker/libraries/rules/gpl.php index e93a45c..9a6832f 100644 --- a/administrator/components/com_jedchecker/libraries/rules/gpl.php +++ b/administrator/components/com_jedchecker/libraries/rules/gpl.php @@ -216,7 +216,7 @@ class JedcheckerRulesGpl extends JEDcheckerRule if (preg_match($this->regexCompatLicenses, $content, $match, PREG_OFFSET_CAPTURE)) { $lineno = substr_count($content, "\n", 0, $match[0][1]) + 1; - $this->report->addInfo( + $this->report->addWarning( $file, JText::_('COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND'), $lineno,