|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* The MIT License (MIT) |
|
6
|
|
|
* |
|
7
|
|
|
* Copyright (c) 2015 Daniel Popiniuc |
|
8
|
|
|
* |
|
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
11
|
|
|
* in the Software without restriction, including without limitation the rights |
|
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
14
|
|
|
* furnished to do so, subject to the following conditions: |
|
15
|
|
|
* |
|
16
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
17
|
|
|
* copies or substantial portions of the Software. |
|
18
|
|
|
* |
|
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
25
|
|
|
* SOFTWARE. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
namespace danielgp\informator; |
|
30
|
|
|
|
|
31
|
|
|
class Informator |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
use \danielgp\common_lib\CommonCode, |
|
35
|
|
|
InformatorDynamicFunctions, |
|
36
|
|
|
InformatorKnownLabels, |
|
37
|
|
|
InformatorServer; |
|
38
|
|
|
|
|
39
|
|
|
private $informatorInternalArray; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->informatorInternalArray['composerLockFile'] = realpath('../') . DIRECTORY_SEPARATOR . 'composer.lock'; |
|
44
|
|
|
$this->informatorInternalArray['knownLabels'] = $this->knownLabelsGlobal([ |
|
45
|
|
|
'composerLockFile' => $this->informatorInternalArray['composerLockFile'], |
|
46
|
|
|
'informatorFile' => __FILE__, |
|
47
|
|
|
]); |
|
48
|
|
|
ksort($this->informatorInternalArray['knownLabels']); |
|
49
|
|
|
$rqst = new \Symfony\Component\HttpFoundation\Request; |
|
50
|
|
|
$this->informatorInternalArray['superGlobals'] = $rqst->createFromGlobals(); |
|
51
|
|
|
echo $this->setInterface(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private function connectToMySqlForInformation() |
|
55
|
|
|
{ |
|
56
|
|
|
if (is_null($this->mySQLconnection)) { |
|
57
|
|
|
$this->connectToMySql([ |
|
58
|
|
|
'host' => MYSQL_HOST, |
|
59
|
|
|
'port' => MYSQL_PORT, |
|
60
|
|
|
'username' => MYSQL_USERNAME, |
|
61
|
|
|
'password' => MYSQL_PASSWORD, |
|
62
|
|
|
'database' => MYSQL_DATABASE, |
|
63
|
|
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function getApacheDetails() |
|
68
|
|
|
{ |
|
69
|
|
|
$srvSoftwareArray = explode(' ', $this->getServerSoftware()); |
|
70
|
|
|
$sInfo = []; |
|
71
|
|
|
$tmp = explode('/', $srvSoftwareArray[0]); |
|
72
|
|
|
if (strpos($srvSoftwareArray[0], 'Apache') !== false) { |
|
73
|
|
|
$sInfo['Apache'] = [ |
|
74
|
|
|
'Name' => $tmp[0], |
|
75
|
|
|
'Signature' => $this->getServerSoftware(), |
|
76
|
|
|
'Version' => $tmp[1] |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
$modulesToDisregard = [ |
|
80
|
|
|
$srvSoftwareArray[0], |
|
81
|
|
|
'(Win64)', |
|
82
|
|
|
]; |
|
83
|
|
|
$sInfo['Apache']['Modules'] = $this->getApacheModules(array_diff($srvSoftwareArray, $modulesToDisregard)); |
|
84
|
|
|
ksort($sInfo['Apache']); |
|
85
|
|
|
return $sInfo['Apache']; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
private function getApacheModules(array $srvSoftwareArray) |
|
89
|
|
|
{ |
|
90
|
|
|
$aReturn = []; |
|
91
|
|
|
foreach ($srvSoftwareArray as $value) { |
|
92
|
|
|
$tmp = explode('/', $value); |
|
93
|
|
|
$rootModule = strtolower(str_replace(['mod_', 'OpenSSL'], ['', 'SSL'], $tmp[0])); |
|
94
|
|
|
$aReturn[$rootModule] = [ |
|
95
|
|
|
'Name' => $tmp[0], |
|
96
|
|
|
'Version' => $tmp[1] |
|
97
|
|
|
]; |
|
98
|
|
|
} |
|
99
|
|
|
ksort($aReturn); |
|
100
|
|
|
return $aReturn; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
private function getClientBrowserDetailsForInformator() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->getClientBrowserDetails(['Browser', 'Device', 'OS'], $this->getDoctrineCaheFolder()); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
private function getMySQLinfo($returnType = ['Databases Client', 'Engines Active', 'General', 'Variables Global']) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->connectToMySqlForInformation(); |
|
111
|
|
|
$sInfo = []; |
|
112
|
|
|
$mLabels = $this->knownLabelsForMySql(); |
|
113
|
|
|
foreach ($returnType as $value) { |
|
114
|
|
|
$sInfo['MySQL'][$value] = $this->callDynamicFunctionToGetResults($mLabels[$value]); |
|
115
|
|
|
} |
|
116
|
|
|
ksort($sInfo['MySQL']); |
|
117
|
|
|
return $sInfo['MySQL']; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
private function getPhpDetails($returnType = ['General', 'INI Settings', 'Extensions Loaded', 'Temporary Folder']) |
|
121
|
|
|
{ |
|
122
|
|
|
$sInfo = []; |
|
123
|
|
|
foreach ($returnType as $value) { |
|
124
|
|
|
$sInfo['PHP'][$value] = $this->getPhpDetailsIndividually($value); |
|
125
|
|
|
} |
|
126
|
|
|
ksort($sInfo['PHP']); |
|
127
|
|
|
return $sInfo['PHP']; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
private function getPhpDetailsIndividually($value) |
|
131
|
|
|
{ |
|
132
|
|
|
switch ($value) { |
|
133
|
|
|
case 'General': |
|
134
|
|
|
$sInfo = [ |
|
135
|
|
|
'Version' => phpversion(), |
|
136
|
|
|
'Zend Engine Version' => zend_version(), |
|
137
|
|
|
]; |
|
138
|
|
|
break; |
|
139
|
|
|
case 'INI Settings': |
|
140
|
|
|
$sInfo = ini_get_all(null, false); |
|
141
|
|
|
break; |
|
142
|
|
|
default: |
|
143
|
|
|
$sInfo = $this->callDynamicFunctionToGetResults($this->knownLabelsForPhp()[$value]); |
|
144
|
|
|
break; |
|
145
|
|
|
} |
|
146
|
|
|
return $sInfo; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
private function getServerDetails() |
|
150
|
|
|
{ |
|
151
|
|
|
$hst = $this->informatorInternalArray['superGlobals']->getHttpHost(); |
|
152
|
|
|
$srvIp = filter_var(gethostbyname($hst), FILTER_VALIDATE_IP); |
|
153
|
|
|
$srvEvaluated = $this->getServerDetailsEvaluated($hst); |
|
154
|
|
|
return [ |
|
155
|
|
|
'OS' => php_uname(), |
|
156
|
|
|
'OS Architecture' => $srvEvaluated['serverMachineType'], |
|
157
|
|
|
'OS Date/time' => date('Y-m-d H:i:s'), |
|
158
|
|
|
'OS Ip' => $srvIp, |
|
159
|
|
|
'OS Ip type' => $this->checkIpIsPrivate($srvIp), |
|
160
|
|
|
'OS Ip v4/v6' => $this->checkIpIsV4OrV6($srvIp), |
|
161
|
|
|
'OS Name' => $srvEvaluated['serverInfo']['name'], |
|
162
|
|
|
'OS Host' => $srvEvaluated['serverInfo']['host'], |
|
163
|
|
|
'OS Release' => $srvEvaluated['serverInfo']['release'], |
|
164
|
|
|
'OS Version' => $srvEvaluated['serverInfo']['version'], |
|
165
|
|
|
]; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
private function getTomcatDetails() |
|
169
|
|
|
{ |
|
170
|
|
|
$sReturn = []; |
|
171
|
|
|
$sReturn['Tomcat'] = '---'; |
|
172
|
|
|
$url = 'http://' . $this->informatorInternalArray['superGlobals']->getHttpHost() |
|
173
|
|
|
. ':8080/informator.Tomcat/index.jsp'; |
|
174
|
|
|
$urlFeedback = $this->getContentFromUrlThroughCurlAsArrayIfJson($url); |
|
175
|
|
|
if (is_array($urlFeedback) && isset($urlFeedback['response'])) { |
|
176
|
|
|
$sReturn['Tomcat'] = $urlFeedback['response']; |
|
177
|
|
|
} |
|
178
|
|
|
return $sReturn; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
private function setInterface() |
|
182
|
|
|
{ |
|
183
|
|
|
$requestedLabel = $this->informatorInternalArray['superGlobals']->get('Label'); |
|
184
|
|
|
$showLabels = true; |
|
185
|
|
|
$feedback = '<span style="background-color:red;color:white;">Label not set...</span>'; |
|
186
|
|
|
$arToReturn = []; |
|
187
|
|
|
if (isset($requestedLabel)) { |
|
188
|
|
|
$feedback = '<span style="background-color:red;color:white;">' |
|
189
|
|
|
. 'Unknown label transmited...' |
|
190
|
|
|
. '</span>'; |
|
191
|
|
|
if (array_key_exists($requestedLabel, $this->informatorInternalArray['knownLabels'])) { |
|
192
|
|
|
$showLabels = false; |
|
193
|
|
|
$feedback = ''; |
|
194
|
|
|
$lblValue = $this->informatorInternalArray['knownLabels'][$requestedLabel]; |
|
195
|
|
|
$arToReturn = $this->performLabelDefinition($requestedLabel, $lblValue); |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
$outputArray = [ |
|
199
|
|
|
'showLabels' => $showLabels, |
|
200
|
|
|
'feedback' => $feedback, |
|
201
|
|
|
'arrayToReturn' => $arToReturn, |
|
202
|
|
|
]; |
|
203
|
|
|
return $this->setOutputInterface($outputArray); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
private function performLabelDefinition($requestedLabel, $lblValue) |
|
207
|
|
|
{ |
|
208
|
|
|
switch ($requestedLabel) { |
|
209
|
|
|
case '--- List of known labels': |
|
210
|
|
|
$arToReturn = array_keys($this->informatorInternalArray['knownLabels']); |
|
211
|
|
|
break; |
|
212
|
|
|
case 'Auto Dependencies File': |
|
213
|
|
|
$arToReturn = $lblValue; |
|
214
|
|
|
break; |
|
215
|
|
|
case 'System Info': |
|
216
|
|
|
$arToReturn = $this->systemInfo(); |
|
217
|
|
|
break; |
|
218
|
|
|
default: |
|
219
|
|
|
$arToReturn = $this->callDynamicFunctionToGetResults($lblValue); |
|
220
|
|
|
break; |
|
221
|
|
|
} |
|
222
|
|
|
return $arToReturn; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
private function setOutputInterface($inArray) |
|
226
|
|
|
{ |
|
227
|
|
|
if ($inArray['showLabels']) { |
|
228
|
|
|
$sReturn = []; |
|
229
|
|
|
$sReturn[] = $this->setHeaderCommon([ |
|
230
|
|
|
'lang' => 'en-US', |
|
231
|
|
|
'title' => 'Informator' |
|
232
|
|
|
]); |
|
233
|
|
|
$sReturn[] = $inArray['feedback'] . '<p style="background-color:green;color:white;">' |
|
234
|
|
|
. 'So you might want to choose one from the list below:</p>' |
|
235
|
|
|
. '<ul>'; |
|
236
|
|
|
$arToReturn = array_keys($this->informatorInternalArray['knownLabels']); |
|
237
|
|
|
foreach ($arToReturn as $value) { |
|
238
|
|
|
$sReturn[] = '<li>' |
|
239
|
|
|
. '<a href="?Label=' . urlencode($value) . '" target="_blank">' . $value . '</a>' |
|
240
|
|
|
. '</li>'; |
|
241
|
|
|
} |
|
242
|
|
|
$sReturn[] = '</ul>' . $this->setFooterCommon(); |
|
243
|
|
|
return implode('', $sReturn); |
|
244
|
|
|
} |
|
245
|
|
|
$this->setHeaderGZiped(); |
|
246
|
|
|
$this->setHeaderNoCache('application/json'); |
|
247
|
|
|
echo $this->setArrayToJson($inArray['arrayToReturn']); |
|
248
|
|
|
$this->setFooterGZiped(); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Builds an array with most important key aspects of LAMP/WAMP |
|
253
|
|
|
* @return array |
|
254
|
|
|
*/ |
|
255
|
|
|
private function systemInfo() |
|
256
|
|
|
{ |
|
257
|
|
|
$cFile = $this->informatorInternalArray['composerLockFile']; |
|
258
|
|
|
return [ |
|
259
|
|
|
'Apache' => $this->getApacheDetails(), |
|
260
|
|
|
'Auto Dependencies' => $this->getPackageDetailsFromGivenComposerLockFile($cFile), |
|
261
|
|
|
'Client' => $this->getClientBrowserDetailsForInformator(), |
|
262
|
|
|
'InfoCompareFile' => $this->getFileDetails(__FILE__), |
|
263
|
|
|
'MySQL' => $this->getMySQLinfo(), |
|
264
|
|
|
'PHP' => $this->getPhpDetails(), |
|
265
|
|
|
'Server' => $this->getServerDetails(), |
|
266
|
|
|
'Tomcat' => $this->getTomcatDetails()['Tomcat'], |
|
267
|
|
|
]; |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
|