OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
oxdiagnostics.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
17  protected $_sEdition = "";
18 
24  protected $_sVersion = "";
25 
31  protected $_sRevision = "";
32 
38  protected $_sShopLink = "";
39 
45  protected $_aFileCheckerPathList = array(
46  'bootstrap.php',
47  'index.php',
48  'oxid.php',
49  'oxseo.php',
50  'admin/',
51  'application/',
52  'bin/',
53  'core/',
54  'modules/',
55  );
56 
62  protected $_aFileCheckerExtensionList = array('php', 'tpl');
63 
69  public function setFileCheckerPathList($aPathList)
70  {
71  $this->_aFileCheckerPathList = $aPathList;
72  }
73 
79  public function getFileCheckerPathList()
80  {
82  }
83 
89  public function setFileCheckerExtensionList($aExtList)
90  {
91  $this->_aFileCheckerExtensionList = $aExtList;
92  }
93 
99  public function getFileCheckerExtensionList()
100  {
102  }
103 
104 
110  public function setVersion($sVersion)
111  {
112  if (!empty($sVersion)) {
113  $this->_sVersion = $sVersion;
114  }
115  }
116 
122  public function getVersion()
123  {
124  return $this->_sVersion;
125  }
126 
132  public function setEdition($sEdition)
133  {
134  if (!empty($sEdition)) {
135  $this->_sEdition = $sEdition;
136  }
137  }
138 
144  public function getEdition()
145  {
146  return $this->_sEdition;
147  }
148 
154  public function setRevision($sRevision)
155  {
156  if (!empty($sRevision)) {
157  $this->_sRevision = $sRevision;
158  }
159  }
160 
166  public function getRevision()
167  {
168  return $this->_sRevision;
169  }
170 
171 
177  public function setShopLink($sShopLink)
178  {
179  if (!empty($sShopLink)) {
180  $this->_sShopLink = $sShopLink;
181  }
182  }
183 
189  public function getShopLink()
190  {
191  return $this->_sShopLink;
192  }
193 
199  public function getShopDetails()
200  {
201  $aShopDetails = array(
202  'Date' => date(oxRegistry::getLang()->translateString('fullDateFormat'), time()),
203  'URL' => $this->getShopLink(),
204  'Edition' => $this->getEdition(),
205  'Version' => $this->getVersion(),
206  'Revision' => $this->getRevision(),
207  'Subshops (Total)' => $this->_countRows('oxshops', true),
208  'Subshops (Active)' => $this->_countRows('oxshops', false),
209  'Categories (Total)' => $this->_countRows('oxcategories', true),
210  'Categories (Active)' => $this->_countRows('oxcategories', false),
211  'Articles (Total)' => $this->_countRows('oxarticles', true),
212  'Articles (Active)' => $this->_countRows('oxarticles', false),
213  'Users (Total)' => $this->_countRows('oxuser', true),
214  );
215 
216  return $aShopDetails;
217  }
218 
227  protected function _countRows($sTable, $blMode)
228  {
229  $oDb = oxDb::getDb();
230  $sRequest = 'SELECT COUNT(*) FROM ' . $sTable;
231 
232  if ($blMode == false) {
233  $sRequest .= ' WHERE oxactive = 1';
234  }
235 
236  $aRes = $oDb->execute($sRequest)->fields(0);
237 
238  return $aRes[0];
239  }
240 
241 
247  public function getPhpSelection()
248  {
249  $aPhpIniParams = array(
250  'allow_url_fopen',
251  'display_errors',
252  'file_uploads',
253  'max_execution_time',
254  'memory_limit',
255  'post_max_size',
256  'register_globals',
257  'upload_max_filesize',
258  );
259 
260  $aPhpIniConf = array();
261 
262  foreach ($aPhpIniParams as $sParam) {
263  $sValue = ini_get($sParam);
264  $aPhpIniConf[$sParam] = $sValue;
265  }
266 
267  return $aPhpIniConf;
268  }
269 
270 
276  public function getPhpDecoder()
277  {
278  $sReturn = 'Zend ';
279 
280  if (function_exists('zend_optimizer_version')) {
281  $sReturn .= 'Optimizer';
282  }
283 
284  if (function_exists('zend_loader_enabled')) {
285  $sReturn .= 'Guard Loader';
286  }
287 
288  return $sReturn;
289  }
290 
291 
298  public function getServerInfo()
299  {
300  // init empty variables (can be filled if exec is allowed)
301  $iCpuAmnt = $iCpuMhz = $iBogo = $iMemTotal = $iMemFree = $sCpuModelName = $sCpuModel = $sCpuFreq = $iCpuCores = null;
302 
303  // fill, if exec is allowed
304  if ($this->isExecAllowed()) {
305  $iCpuAmnt = $this->_getCpuAmount();
306  $iCpuMhz = $this->_getCpuMhz();
307  $iBogo = $this->_getBogoMips();
308  $iMemTotal = $this->_getMemoryTotal();
309  $iMemFree = $this->_getMemoryFree();
310  $sCpuModelName = $this->_getCpuModel();
311  $sCpuModel = $iCpuAmnt . 'x ' . $sCpuModelName;
312  $sCpuFreq = $iCpuMhz . ' MHz';
313 
314  // prevent "division by zero" error
315  if ($iBogo && $iCpuMhz) {
316  $iCpuCores = $iBogo / $iCpuMhz;
317  }
318  }
319 
320  $aServerInfo = array(
321  'Server OS' => @php_uname('s'),
322  'VM' => $this->_getVirtualizationSystem(),
323  'PHP' => $this->_getPhpVersion(),
324  'MySQL' => $this->_getMySqlServerInfo(),
325  'Apache' => $this->_getApacheVersion(),
326  'Disk total' => $this->_getDiskTotalSpace(),
327  'Disk free' => $this->_getDiskFreeSpace(),
328  'Memory total' => $iMemTotal,
329  'Memory free' => $iMemFree,
330  'CPU Model' => $sCpuModel,
331  'CPU frequency' => $sCpuFreq,
332  'CPU cores' => round($iCpuCores, 0),
333  );
334 
335  return $aServerInfo;
336  }
337 
343  protected function _getApacheVersion()
344  {
345  if (function_exists('apache_get_version')) {
346  $sReturn = apache_get_version();
347  } else {
348  $sReturn = $_SERVER['SERVER_SOFTWARE'];
349  }
350 
351  return $sReturn;
352  }
353 
359  protected function _getVirtualizationSystem()
360  {
361  $sSystemType = '';
362 
363  if ($this->isExecAllowed()) {
364  //VMWare
365  @$sDeviceList = $this->_getDeviceList('vmware');
366  if ($sDeviceList) {
367  $sSystemType = 'VMWare';
368  unset($sDeviceList);
369  }
370 
371  //VirtualBox
372  @$sDeviceList = $this->_getDeviceList('VirtualBox');
373  if ($sDeviceList) {
374  $sSystemType = 'VirtualBox';
375  unset($sDeviceList);
376  }
377  }
378 
379  return $sSystemType;
380  }
381 
387  public function isExecAllowed()
388  {
389  return function_exists('exec');
390  }
391 
399  protected function _getDeviceList($sSystemType)
400  {
401  return exec('lspci | grep -i ' . $sSystemType);
402  }
403 
409  protected function _getCpuAmount()
410  {
411  // cat /proc/cpuinfo | grep "processor" | sort -u | cut -d: -f2');
412  return exec('cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l');
413  }
414 
420  protected function _getCpuMhz()
421  {
422  return round(exec('cat /proc/cpuinfo | grep "MHz" | sort -u | cut -d: -f2'), 0);
423  }
424 
430  protected function _getBogoMips()
431  {
432  return exec('cat /proc/cpuinfo | grep "bogomips" | sort -u | cut -d: -f2');
433  }
434 
440  protected function _getMemoryTotal()
441  {
442  return exec('cat /proc/meminfo | grep "MemTotal" | sort -u | cut -d: -f2');
443  }
444 
450  protected function _getMemoryFree()
451  {
452  return exec('cat /proc/meminfo | grep "MemFree" | sort -u | cut -d: -f2');
453  }
454 
460  protected function _getCpuModel()
461  {
462  return exec('cat /proc/cpuinfo | grep "model name" | sort -u | cut -d: -f2');
463  }
464 
470  protected function _getDiskTotalSpace()
471  {
472  return round(disk_total_space('/') / 1024 / 1024, 0) . ' GiB';
473  }
474 
480  protected function _getDiskFreeSpace()
481  {
482  return round(disk_free_space('/') / 1024 / 1024, 0) . ' GiB';
483  }
484 
490  protected function _getPhpVersion()
491  {
492  return phpversion();
493  }
494 
500  protected function _getMySqlServerInfo()
501  {
502  $aResult = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getRow("SHOW VARIABLES LIKE 'version'");
503 
504  return $aResult['Value'];
505  }
506 }