1
0

BxDolStudioDashboard.php 6.7 KB

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