1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mage Scan |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category MageScan |
8
|
|
|
* @package MageScan |
9
|
|
|
* @author Steve Robbins <[email protected]> |
10
|
|
|
* @copyright 2015 Steve Robbins |
11
|
|
|
* @license http://creativecommons.org/licenses/by/4.0/ CC BY 4.0 |
12
|
|
|
* @link https://github.com/steverobbins/magescan |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace MageScan\Check\Version; |
16
|
|
|
|
17
|
|
|
use GuzzleHttp\Psr7\Response; |
18
|
|
|
use MageScan\Check\AbstractCheck; |
19
|
|
|
use MageScan\Check\Version; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Scan for Magento edition and version via doc block style comment |
23
|
|
|
* |
24
|
|
|
* @category MageScan |
25
|
|
|
* @package MageScan |
26
|
|
|
* @author Steve Robbins <[email protected]> |
27
|
|
|
* @copyright 2015 Steve Robbins |
28
|
|
|
* @license http://creativecommons.org/licenses/by/4.0/ CC BY 4.0 |
29
|
|
|
* @link https://github.com/steverobbins/magescan |
30
|
|
|
*/ |
31
|
|
|
class DocComment extends AbstractCheck |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Guess magento edition and version |
35
|
|
|
* |
36
|
|
|
* @return array|boolean |
37
|
|
|
*/ |
38
|
|
|
public function getInfo() |
39
|
|
|
{ |
40
|
|
|
$response = $this->getRequest()->get('js/varien/product.js'); |
41
|
|
|
$edition = $this->getEdition($response); |
42
|
|
|
if ($edition) { |
43
|
|
|
$version = $this->getVersion($response, $edition); |
44
|
|
|
return [$edition, $version]; |
45
|
|
|
} |
46
|
|
|
return false; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Guess Magento edition from license in public file |
51
|
|
|
* |
52
|
|
|
* @param Response $response |
53
|
|
|
* |
54
|
|
|
* @return string|boolean |
55
|
|
|
*/ |
56
|
|
|
public function getEdition(Response $response) |
57
|
|
|
{ |
58
|
|
|
if ($response->getStatusCode() == 200) { |
59
|
|
|
preg_match('/@license.*/', $response->getBody(), $match); |
60
|
|
|
if (isset($match[0])) { |
61
|
|
|
if (strpos($match[0], 'enterprise') !== false) { |
62
|
|
|
return Version::EDITION_ENTERPRISE; |
63
|
|
|
} elseif (strpos($match[0], 'commercial') !== false) { |
64
|
|
|
return Version::EDITION_PROFESSIONAL; |
65
|
|
|
} |
66
|
|
|
return Version::EDITION_COMMUNITY; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Guess Magento version from copyright in public file |
74
|
|
|
* |
75
|
|
|
* @param Response $response |
76
|
|
|
* @param string|boolean $edition |
77
|
|
|
* |
78
|
|
|
* @return string|boolean |
79
|
|
|
*/ |
80
|
|
|
public function getVersion(Response $response, $edition) |
81
|
|
|
{ |
82
|
|
|
if ($response->getStatusCode() == 200 && $edition != false) { |
83
|
|
|
preg_match('/@copyright.*/', $response->getBody(), $match); |
84
|
|
|
if (isset($match[0]) |
85
|
|
|
&& preg_match('/[0-9-]{4,}/', $match[0], $match) |
86
|
|
|
&& isset($match[0]) |
87
|
|
|
) { |
88
|
|
|
return $this->getMagentoVersionByYear($match[0], $edition); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Guess Magento version from copyright year and edition |
96
|
|
|
* |
97
|
|
|
* @param string $year |
98
|
|
|
* @param string $edition |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
protected function getMagentoVersionByYear($year, $edition) |
103
|
|
|
{ |
104
|
|
|
switch ($year) { |
105
|
|
|
case '2006-2015': |
106
|
|
|
case '2006-2014': |
107
|
|
|
case '2014': |
108
|
|
|
return $edition == Version::EDITION_ENTERPRISE ? |
109
|
|
|
'1.14' : '1.9'; |
110
|
|
|
case 2013: |
111
|
|
|
return $edition == Version::EDITION_ENTERPRISE ? |
112
|
|
|
'1.13' : '1.8'; |
113
|
|
|
case 2012: |
114
|
|
|
return ($edition == Version::EDITION_ENTERPRISE || $edition == Version::EDITION_PROFESSIONAL) ? |
115
|
|
|
'1.12' : '1.7'; |
116
|
|
|
case 2011: |
117
|
|
|
return ($edition == Version::EDITION_ENTERPRISE || $edition == Version::EDITION_PROFESSIONAL) ? |
118
|
|
|
'1.11' : '1.6'; |
119
|
|
|
case 2010: |
120
|
|
|
return ($edition == Version::EDITION_ENTERPRISE || $edition == Version::EDITION_PROFESSIONAL) ? |
121
|
|
|
'1.9 - 1.10' : '1.4 - 1.5'; |
122
|
|
|
} |
123
|
|
|
return 'Unknown'; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|