BxDolStudioDashboard.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentStudio Trident Studio
  7. * @{
  8. */
  9. bx_import('BxTemplStudioPage');
  10. bx_import('BxDolStudioDashboardQuery');
  11. class BxDolStudioDashboard extends BxTemplStudioPage
  12. {
  13. protected $aBlocks;
  14. protected $aItemsCache;
  15. protected $aItemsHTools;
  16. function __construct()
  17. {
  18. parent::__construct('dashboard');
  19. $this->oDb = new BxDolStudioDashboardQuery();
  20. $this->aBlocks = array(
  21. 'space' => 'serviceGetBlockSpace',
  22. 'htools' => 'serviceGetBlockHostTools',
  23. );
  24. $this->aItemsCache = array (
  25. array('name' => 'all'),
  26. array('name' => 'db'),
  27. array('name' => 'template'),
  28. array('name' => 'css'),
  29. array('name' => 'js')
  30. );
  31. $this->aItemsHTools = array (
  32. 'PHP' => 'requirementsPHP',
  33. 'MySQL' => 'requirementsMySQL',
  34. 'Web Server' => 'requirementsWebServer',
  35. );
  36. //--- Check actions ---//
  37. if(($sAction = bx_get('dbd_action')) !== false) {
  38. $sAction = bx_process_input($sAction);
  39. $aResult = array('code' => 1, 'message' => _t('_adm_err_cannot_process_action'));
  40. switch($sAction) {
  41. case 'get_block':
  42. $sValue = bx_get('dbd_value');
  43. if($sValue === false)
  44. break;
  45. $sValue = bx_process_input($sValue);
  46. if(!isset($this->aBlocks[$sValue]))
  47. break;
  48. $aBlock = $this->{$this->aBlocks[$sValue]}(false);
  49. if(!empty($aBlock['content']))
  50. $aResult = array('code' => 0, 'data' => $aBlock['content']);
  51. break;
  52. case 'check_for_upgrade':
  53. $aResult = array('code' => 0, 'data' => $this->getPageCodeVersionAvailable());
  54. break;
  55. case 'perform_upgrade':
  56. $oUpgrader = bx_instance('BxDolUpgrader');
  57. if(!$oUpgrader->prepare())
  58. $aResult = array('code' => 1, 'message' => $oUpgrader->getError());
  59. else
  60. $aResult = array('code' => 0, 'message' => _t('_adm_dbd_msg_upgrade_started'));
  61. break;
  62. case 'clear_cache':
  63. $sValue = bx_get('dbd_value');
  64. if($sValue === false)
  65. break;
  66. $sValue = bx_process_input($sValue);
  67. bx_import('BxDolCacheUtilities');
  68. $oCacheUtilities = BxDolCacheUtilities::getInstance();
  69. switch ($sValue) {
  70. case 'all':
  71. $aResult = false;
  72. foreach($this->aItemsCache as $aItem) {
  73. if($aItem['name'] == 'all')
  74. continue;
  75. $aResultClear = $oCacheUtilities->clear($aItem['name']);
  76. if($aResultClear === false)
  77. continue;
  78. $aResult = $aResultClear;
  79. if(isset($aResult['code']) && $aResult['code'] != 0)
  80. break;
  81. }
  82. break;
  83. case 'db':
  84. case 'template':
  85. case 'css':
  86. case 'js':
  87. $aResult = $oCacheUtilities->clear($sValue);
  88. break;
  89. default:
  90. $aResult = array('code' => 1, 'message' => _t('_Error Occured'));
  91. }
  92. if($aResult === false)
  93. $aResult['data'] = MsgBox(_t('_adm_dbd_msg_c_all_disabled'));
  94. else if(isset($aResult['code']) && $aResult['code'] == 0)
  95. $aResult['data'] = $this->getCacheChartData(false);
  96. break;
  97. case 'server_audit':
  98. bx_import('BxDolStudioToolsAudit');
  99. $oAudit = new BxDolStudioToolsAudit();
  100. echo $oAudit->generate();
  101. exit;
  102. }
  103. if(!empty($aResult['message'])) {
  104. bx_import('BxDolStudioTemplate');
  105. $aResult['message'] = BxDolStudioTemplate::getInstance()->parseHtmlByName('page_action_result.html', array('content' => $aResult['message']));
  106. bx_import('BxTemplStudioFunctions');
  107. $aResult['message'] = BxTemplStudioFunctions::getInstance()->transBox('', $aResult['message']);
  108. }
  109. echo json_encode($aResult);
  110. exit;
  111. }
  112. }
  113. protected function getDbSize()
  114. {
  115. $iTotalSize = 0;
  116. $oDb = BxDolDb::getInstance();
  117. $aTables = $oDb->getAll('SHOW TABLE STATUS');
  118. foreach($aTables as $aTable)
  119. $iTotalSize += $aTable['Data_length'] + $aTable['Index_length'];
  120. return $iTotalSize;
  121. }
  122. protected function getFolderSize($sPath)
  123. {
  124. $iTotalSize = 0;
  125. $aFiles = scandir($sPath);
  126. $sPath = rtrim($sPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
  127. foreach($aFiles as $sFile) {
  128. if(is_dir($sPath . $sFile))
  129. if($sFile != '.' && $sFile != '..')
  130. $iTotalSize += $this->getFolderSize($sPath . $sFile);
  131. else
  132. $iTotalSize += filesize($sPath . $sFile);
  133. }
  134. return $iTotalSize;
  135. }
  136. protected function getCacheChartData($bAsString = true)
  137. {
  138. bx_import('BxDolCacheUtilities');
  139. $oCacheUtilities = BxDolCacheUtilities::getInstance();
  140. $aChartData = array();
  141. foreach($this->aItemsCache as $aItem) {
  142. if($aItem['name'] == 'all')
  143. continue;
  144. $iSize = $oCacheUtilities->size($aItem['name']);
  145. if($iSize === false)
  146. continue;
  147. $aChartData[] = array(bx_js_string(_t('_adm_dbd_txt_c_' . $aItem['name']), BX_ESCAPE_STR_APOS), array('v' => $iSize, 'f' => bx_js_string(_t_format_size($iSize))));
  148. }
  149. if(empty($aChartData))
  150. return false;
  151. return $bAsString ? json_encode($aChartData) : $aChartData;
  152. }
  153. }
  154. /** @} */